Files
maptool/lib/maptool/geojson.rb
T
randy b4f205667b
CI / check (push) Successful in 45s
CI / deploy (push) Successful in 15s
Support uploading .geojson files directly
A .geojson file needs no GPX/FIT conversion — it's already the shape
gpx.js expects — so GpxStore#geojson now just reads and returns it
as-is, no cache sidecar. save/tree/the upload dropzone and its zip
handling all pick it up through the existing TRACK_EXTENSIONS list.

Also fixes a bug the new "cached" tree icon would have shipped with:
a GPX/FIT's own .geojson cache sidecar (e.g. "ride.gpx.geojson") also
matches the new .geojson branch in list_children, which would have
listed it as a second, phantom tree entry — excluded explicitly, with
a regression test.
2026-09-07 22:48:58 +02:00

19 lines
760 B
Ruby

module Maptool
# A directly-uploaded .geojson file needs no conversion — GpxStore serves
# it straight from disk (see GpxStore#geojson) — so unlike Gpx/Fit there's
# no to_geojson here. Only kind-detection lives here, for the tree's badge
# icons, mirroring Gpx.kinds' cheap substring-search rather than a full
# JSON parse: a POI export can be tens of MB, geojson or not, and a full
# parse just to answer "does this have any points/lines" would cost the
# same either way.
module Geojson
def self.kinds(path)
content = File.read(path)
kinds = []
kinds << "waypoint" if content.include?('"Point"')
kinds << "track" if content.include?('"LineString"') # matches MultiLineString too
kinds
end
end
end