Bicycle and foot route profiles (Valhalla bicycle/pedestrian costing); hiking trail colours in the elevation profile; power, splits and best efforts in the profile; TCX import; FIT course export
This commit is contained in:
1 parent
4c704045c5
commit
f8755ea65a
21 files changed
+634
-40
No files matched your search
@@ -198,6 +198,25 @@ module Maptool
|
||||
halt 400, json(error: "invalid feature")
|
||||
end
|
||||
|
||||
# The node's first line as a FIT course (FitCourse), or nil. A route
|
||||
# planned for a bicycle/foot profile keeps that sport.
|
||||
def fit_course(geojson, name)
|
||||
feature = JSON.parse(geojson)["features"].find { |f| f.dig("geometry", "type").to_s.end_with?("LineString") }
|
||||
return unless feature
|
||||
|
||||
props = feature["properties"] || {}
|
||||
coordinates = feature["geometry"]["type"] == "LineString" ? feature["geometry"]["coordinates"] : feature["geometry"]["coordinates"].flatten(1)
|
||||
vehicle = props["vehicle"].is_a?(Hash) ? props["vehicle"] : {}
|
||||
sport = case vehicle["type"]
|
||||
when "bicycle" then "cycling"
|
||||
when "foot" then vehicle["speed"].to_f >= 7 ? "running" : "hiking"
|
||||
else props["activity_type"]
|
||||
end
|
||||
FitCourse.encode(coordinates, name: props["name"] || name, sport: sport, duration: props["duration_secs"])
|
||||
rescue ArgumentError
|
||||
nil
|
||||
end
|
||||
|
||||
def save_zip_entries(folder:, io:)
|
||||
paths = []
|
||||
Zip::File.open_buffer(io) do |zip|
|
||||
@@ -631,8 +650,17 @@ module Maptool
|
||||
halt 422, json(error: "could not parse file")
|
||||
end
|
||||
|
||||
name = params[:name].to_s.empty? ? "export" : File.basename(params[:name].to_s)
|
||||
if params[:download] == "fit"
|
||||
fit = fit_course(body, name)
|
||||
halt 422, json(error: "not a track or route") unless fit
|
||||
content_type "application/vnd.ant.fit"
|
||||
attachment "#{name}.fit"
|
||||
return fit
|
||||
end
|
||||
|
||||
content_type :json
|
||||
attachment "#{params[:name].to_s.empty? ? "export" : File.basename(params[:name].to_s)}.geojson" if params[:download]
|
||||
attachment "#{name}.geojson" if params[:download]
|
||||
body
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user