Show track properties (distance, elevation gain, duration)
Maptool::TrackStats computes these once, shared by Gpx and Fit so both track feature shapes carry the same properties regardless of source format. Hovering a track line (not clicking — these describe the whole line, not one point) shows them in a popup, same mechanism GPX waypoints already use.
This commit is contained in:
1 parent
fc174d4267
commit
a3c31ace06
5 files changed
+172
-21
No files matched your search
+19
-2
@@ -1,4 +1,6 @@
|
||||
require "rexml/document"
|
||||
require "time"
|
||||
require_relative "track_stats"
|
||||
|
||||
module Maptool
|
||||
# Converts a GPX file to a GeoJSON FeatureCollection: waypoints (<wpt>)
|
||||
@@ -50,20 +52,35 @@ module Maptool
|
||||
|
||||
def self.track_feature(trk)
|
||||
lines = []
|
||||
all_points = []
|
||||
times = []
|
||||
trk.each_element("trkseg") do |seg|
|
||||
points = []
|
||||
seg.each_element("trkpt") { |pt| points << coordinate(pt) }
|
||||
seg.each_element("trkpt") do |pt|
|
||||
point = coordinate(pt)
|
||||
points << point
|
||||
all_points << point
|
||||
times << parse_time(child_text(pt, "time"))
|
||||
end
|
||||
lines << points unless points.empty?
|
||||
end
|
||||
|
||||
{
|
||||
"type" => "Feature",
|
||||
"geometry" => { "type" => "MultiLineString", "coordinates" => lines },
|
||||
"properties" => { "kind" => "track", "name" => child_text(trk, "name") },
|
||||
"properties" => { "kind" => "track", "name" => child_text(trk, "name") }
|
||||
.merge(TrackStats.compute(all_points, times: times)),
|
||||
}
|
||||
end
|
||||
private_class_method :track_feature
|
||||
|
||||
def self.parse_time(text)
|
||||
text && Time.parse(text)
|
||||
rescue ArgumentError
|
||||
nil
|
||||
end
|
||||
private_class_method :parse_time
|
||||
|
||||
def self.coordinate(point_el)
|
||||
lat = point_el.attributes["lat"].to_f
|
||||
lon = point_el.attributes["lon"].to_f
|
||||
|
||||
Reference in new issue
Block a user