Files
maptool/Rakefile
T
randy 2a22906a68
CI / check (push) Successful in 40s
CI / deploy (push) Successful in 12s
Fix Edit/Delete on notes saved before properties.id existed
The earliest notes (saved before the previous commit added id
tracking) have no properties.id — update/delete target a feature by
that id, so offering Edit/Delete for one without it just 404s
("Could not delete/save the note", the generic fetch-failure alert).

The popup no longer offers Edit/Delete without an id. New
rake gpx:backfill_note_ids assigns one to any pre-existing Note
feature missing it, so already-saved notes become editable again too
— run once against wherever data/gpx actually lives (e.g. inside the
deployed container).
2026-09-09 12:58:19 +02:00

56 lines
2.1 KiB
Ruby

require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test" << "lib"
t.test_files = FileList["test/test_*.rb"]
end
task default: :test
namespace :overpass do
desc "Fetch camper-relevant POIs (water, dump stations, LPG, toilets, laundry, shops, springs) " \
"for a bbox from Overpass and write GeoJSON. Usage: rake overpass:pois[south,west,north,east,out.geojson]"
task :pois, [:south, :west, :north, :east, :out] do |_t, args|
%i[south west north east out].each { |key| abort("usage: rake overpass:pois[south,west,north,east,out.geojson]") unless args[key] }
require_relative "lib/maptool/overpass_pois"
bbox = [args[:south], args[:west], args[:north], args[:east]].map(&:to_f)
puts "Querying Overpass for #{bbox.join(",")}..."
response = Maptool::OverpassPois.fetch(bbox)
geojson = Maptool::OverpassPois.to_geojson(response)
File.write(args[:out], JSON.generate(geojson))
puts "Wrote #{geojson["features"].size} POIs to #{args[:out]}"
end
end
namespace :gpx do
desc "Backfill properties.id on Note-category features saved before edit/delete (and its id targeting) existed"
task :backfill_note_ids do
require "json"
require "securerandom"
data_dir = ENV.fetch("MAPTOOL_DATA_DIR") { File.join(__dir__, "data") }
count = 0
Dir.glob(File.join(data_dir, "gpx", "**", "*.geojson")).each do |file|
# ".gpx.geojson"/".fit.geojson" are GpxStore's own cache sidecars for
# an uploaded GPX/FIT (regenerated from the source on demand, see
# GpxStore#geojson) — never hand-drawn notes, not worth touching.
next if file.end_with?(".gpx.geojson", ".fit.geojson")
collection = JSON.parse(File.read(file))
changed = false
(collection["features"] || []).each do |feature|
properties = (feature["properties"] ||= {})
next unless properties["category"] == "Note" && !properties["id"]
properties["id"] = SecureRandom.uuid
changed = true
count += 1
end
File.write(file, JSON.generate(collection)) if changed
end
puts "Backfilled #{count} note id(s)"
end
end