Let a cached file's GeoJSON be downloaded by clicking its tree name
Once a .gpx/.fit is cached, the tree shows it under its converted name
("ride.gpx" -> "ride.gpx.geojson", matching the real cache file next
to it on disk) instead of still reading as un-converted -- the
GeoJSON is what's actually on the map from that point on, and the
original is never deleted, just not re-shown as itself. The name is
now a real link (GET /api/gpx/file/<path>?download=1) instead of
plain text, the only way to get that converted form out of the app.
Verified in a real browser that an <a> nested in a <label> claims its
own click rather than the label forwarding it to the checkbox, so
downloading and toggling visibility don't fight over the same click.
This commit is contained in:
1 parent
b4f205667b
commit
cd92dadf6a
5 files changed
+70
-4
No files matched your search
@@ -191,6 +191,10 @@ module Maptool
|
||||
json paths: paths, tree: GPX_STORE.tree
|
||||
end
|
||||
|
||||
# ?download=1 exports the file's GeoJSON as an attachment instead of
|
||||
# rendering it on the map — the only way to get a .gpx/.fit's converted
|
||||
# form out of the app, since GpxStore#geojson's cache is otherwise an
|
||||
# internal implementation detail with no filename of its own to expose.
|
||||
get "/api/gpx/file/*" do
|
||||
begin
|
||||
body = GPX_STORE.geojson(params[:splat].first)
|
||||
@@ -203,6 +207,15 @@ module Maptool
|
||||
end
|
||||
|
||||
content_type :json
|
||||
if params[:download]
|
||||
# Matches the tree's own display name for a cached .gpx/.fit
|
||||
# (public/js/gpx.js's _renderFile) — "ride.gpx" downloads as
|
||||
# "ride.gpx.geojson", not "ride.geojson", so the two never disagree.
|
||||
# A .geojson source is already named right and is left alone.
|
||||
original_name = File.basename(params[:splat].first)
|
||||
download_name = original_name.downcase.end_with?(".geojson") ? original_name : "#{original_name}.geojson"
|
||||
attachment download_name
|
||||
end
|
||||
body
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user