Tracks and routes as containers of points: listed (collapsed) under them in the tree, added via a point's popup, a new note or the route planner's navigation pins, and written as course points into the FIT course
This commit is contained in:
1 parent
6aa7b34f92
commit
4265421457
10 files changed
+354
-20
No files matched your search
+24
-4
@@ -133,13 +133,14 @@ module Maptool
|
||||
[db.execute("SELECT id, parent_id, name FROM folders WHERE deleted_at IS NULL ORDER BY name COLLATE NOCASE"),
|
||||
db.execute(<<~SQL)]
|
||||
SELECT id, folder_id, parent_id, type, name, source_path,
|
||||
CASE WHEN type IN ('layer', 'track', 'route') THEN properties END
|
||||
CASE WHEN type IN ('layer', 'track', 'route') THEN properties END,
|
||||
CASE WHEN parent_id IS NOT NULL THEN geometry END
|
||||
FROM items WHERE deleted_at IS NULL ORDER BY name COLLATE NOCASE
|
||||
SQL
|
||||
end
|
||||
children_of = folders.group_by { |f| f[1] }
|
||||
items_in = items.group_by { |i| i[1] }
|
||||
has_children = items.filter_map { |i| i[2] }.to_set
|
||||
children = items.select { |i| i[2] && i[3] == "point" }.group_by { |i| i[2] }
|
||||
build = lambda do |id, path|
|
||||
subfolders = (children_of[id] || []).map do |fid, _, name|
|
||||
sub = path.empty? ? name : "#{path}/#{name}"
|
||||
@@ -148,9 +149,11 @@ module Maptool
|
||||
own = items_in[id] || []
|
||||
nodes = own.select { |i| %w[track route layer].include?(i[3]) }.map do |iid, _, _, type, name, source, props|
|
||||
props = JSON.parse(props)
|
||||
kinds = type == "layer" ? props["kinds"] || [] : [type, *("waypoint" if has_children.include?(iid))]
|
||||
points = (children[iid] || []).map { |pid, *, pname, _, _, geometry| { "id" => pid, "name" => pname.to_s.empty? ? "Point" : pname, "coordinates" => JSON.parse(geometry)["coordinates"] } }
|
||||
kinds = type == "layer" ? props["kinds"] || [] : [type, *("waypoint" if points.any?)]
|
||||
{ "type" => "file", "path" => "item:#{iid}", "name" => name.to_s.empty? ? type.capitalize : name,
|
||||
"kinds" => kinds, "original" => !source.nil?, "layer" => type == "layer", "color" => props["color"] }.compact
|
||||
"kinds" => kinds, "original" => !source.nil?, "layer" => type == "layer", "color" => props["color"],
|
||||
"points" => (points if points.any?) }.compact
|
||||
end
|
||||
loose = own.count { |i| %w[point shape].include?(i[3]) && i[2].nil? }
|
||||
if loose.positive?
|
||||
@@ -237,6 +240,23 @@ module Maptool
|
||||
File.basename(source, ".*")
|
||||
end
|
||||
|
||||
# A point into a track/route (`key` "item:<id>"), kept with it like a
|
||||
# GPX's own waypoints: shown, moved, deleted and exported together.
|
||||
def add_point(key, feature)
|
||||
kind, id = key.to_s.split(":", 2)
|
||||
raise NotFound unless kind == "item"
|
||||
raise InvalidValue unless feature.dig("geometry", "type") == "Point"
|
||||
|
||||
props = (feature["properties"] || {}).except("id").compact
|
||||
write do |db, rev, now|
|
||||
folder = db.get_first_row("SELECT folder_id FROM items WHERE id = ? AND type IN ('track', 'route') AND deleted_at IS NULL", [id]) or raise NotFound
|
||||
point = SecureRandom.uuid
|
||||
db.execute("INSERT INTO items VALUES (?, ?, ?, 'point', ?, ?, ?, ?, NULL, ?, ?, NULL, ?)",
|
||||
[point, folder[0], id, props["name"], JSON.generate(feature["geometry"]), JSON.generate(props), point, now, now, rev])
|
||||
point
|
||||
end
|
||||
end
|
||||
|
||||
# One hand-drawn note (notes.js) into `folder`; returns its node key.
|
||||
def add_note(feature, folder)
|
||||
add_features([feature], folder).first
|
||||
|
||||
Reference in new issue
Block a user