Skip to content

Commit 1a16c0e

Browse files
committed
Optionally show snappable nodes when drawing areas. #57
1 parent 4e26063 commit 1a16c0e

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed

web/src/common/snapper/RouteSnapperLayer.svelte

+17-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
isPoint,
88
isPolygon,
99
} from "svelte-utils/map";
10-
import { routeToolGj } from "./stores";
10+
import { routeToolGj, showAllNodes, showAllNodesGj } from "./stores";
1111
1212
const circleRadiusPixels = 10;
1313
</script>
@@ -50,3 +50,19 @@
5050
}}
5151
/>
5252
</GeoJSON>
53+
54+
<GeoJSON data={$showAllNodesGj}>
55+
<CircleLayer
56+
{...layerId("route-debug-nodes")}
57+
paint={{
58+
"circle-opacity": 0,
59+
"circle-radius": 5,
60+
"circle-stroke-color": "black",
61+
"circle-stroke-width": 1,
62+
}}
63+
layout={{
64+
visibility: $showAllNodes ? "visible" : "none",
65+
}}
66+
minzoom={14}
67+
/>
68+
</GeoJSON>

web/src/common/snapper/SnapPolygonControls.svelte

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
<script lang="ts">
2+
import type { FeatureCollection } from "geojson";
23
import { RouteTool } from "route-snapper-ts";
3-
import { undoLength } from "./stores";
4+
import { undoLength, showAllNodes, showAllNodesGj } from "./stores";
45
56
export let route_tool: RouteTool;
7+
8+
function loadNodes(show: boolean) {
9+
// TODO Different API for just the nodes
10+
let gj: FeatureCollection = JSON.parse(route_tool.inner.debugRenderGraph());
11+
gj.features = gj.features.filter((f) => f.geometry.type == "Point");
12+
$showAllNodesGj = gj;
13+
}
14+
$: loadNodes($showAllNodes);
615
</script>
716

817
<button
@@ -17,6 +26,11 @@
1726
{/if}
1827
</button>
1928

29+
<label>
30+
<input type="checkbox" bind:checked={$showAllNodes} />
31+
Show all snappable points
32+
</label>
33+
2034
<ul>
2135
<li>
2236
<b>Click</b>

web/src/common/snapper/stores.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ export const routeToolGj: Writable<GeoJSON> = writable({
99
});
1010
export const snapMode: Writable<boolean> = writable(true);
1111
export const undoLength: Writable<number> = writable(0);
12+
export const showAllNodes: Writable<boolean> = writable(false);
13+
export const showAllNodesGj: Writable<GeoJSON> = writable({
14+
type: "FeatureCollection",
15+
features: [],
16+
});

web/src/common/zorder.ts

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const layerZorder = [
8282
// MapTiler basemap
8383
"Building",
8484

85+
"route-debug-nodes",
8586
"route-points",
8687
"route-lines",
8788
"route-polygons",

web/src/title/loader.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { LTN } from "backend";
44
import type { Feature } from "geojson";
55
import { overpassQueryForPolygon } from "svelte-utils/overpass";
66
import { RouteTool } from "route-snapper-ts";
7-
import { routeToolGj, snapMode, undoLength } from "../common/snapper/stores";
7+
import {
8+
routeToolGj,
9+
snapMode,
10+
undoLength,
11+
showAllNodes,
12+
showAllNodesGj,
13+
} from "../common/snapper/stores";
814
import {
915
app,
1016
projectName,
@@ -71,6 +77,8 @@ export function afterProjectLoaded() {
7177
undoLength,
7278
),
7379
);
80+
showAllNodes.set(false);
81+
showAllNodesGj.set({ type: "FeatureCollection", features: [] });
7482
get(map)!.fitBounds(
7583
Array.from(get(app)!.getBounds()) as [number, number, number, number],
7684
{ animate: false },

0 commit comments

Comments
 (0)