Skip to content

Commit

Permalink
Make some alternate ways to toggle snapping mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Feb 19, 2024
1 parent fb935b7 commit fbf3e78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/lib/draw/route/RouteControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
function undo() {
$routeTool!.undo();
}
function toggleSnap() {
$routeTool!.toggleSnapMode();
}
</script>

<SecondaryButton disabled={$undoLength == 0} on:click={undo}>
Expand All @@ -31,13 +35,15 @@
{#if $snapMode}
<p style="background: red; color: white; padding: 8px;">
Snapping to existing roads. Press <b>s</b>
to draw anywhere
or click below to draw anywhere
</p>
<SecondaryButton on:click={toggleSnap}>Draw anywhere</SecondaryButton>
{:else}
<p style="background: blue; color: white; padding: 8px;">
Drawing points anywhere. Press <b>s</b>
to snap to roads
or click below to snap to roads
</p>
<SecondaryButton on:click={toggleSnap}>Snap to roads</SecondaryButton>
{/if}

<ul>
Expand Down
7 changes: 6 additions & 1 deletion src/lib/draw/route/route_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class RouteTool {
if (e.key == "Enter") {
e.stopPropagation();
this.finish();
} else if (e.key == "s") {
} else if (e.key == "s" || e.key == "S") {
e.stopPropagation();
this.inner.toggleSnapMode();
this.redraw();
Expand Down Expand Up @@ -292,6 +292,11 @@ export class RouteTool {
this.redraw();
}

toggleSnapMode() {
this.inner.toggleSnapMode();
this.redraw();
}

private redraw() {
let gj = JSON.parse(this.inner.renderGeojson());
routeToolGj.set(gj);
Expand Down

0 comments on commit fbf3e78

Please sign in to comment.