-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a marker for the point tool (#7)
* WIP: Redesign the point tool to use a marker * Get double click working and rearrange how the marker is managed * Move escape key handler, call setPrecision * Rename vars
- Loading branch information
1 parent
764a0da
commit d57a27c
Showing
6 changed files
with
117 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,91 @@ | ||
<script lang="ts"> | ||
import { HelpButton } from "$lib/common"; | ||
import { SecondaryButton } from "govuk-svelte"; | ||
import { DefaultButton, SecondaryButton } from "govuk-svelte"; | ||
import FixedButtonGroup from "../FixedButtonGroup.svelte"; | ||
import { pointPosition } from "$lib/draw/stores"; | ||
import { MapEvents, Marker } from "svelte-maplibre"; | ||
import type { MapMouseEvent } from "maplibre-gl"; | ||
import { map } from "$lib/config"; | ||
import { onMount, onDestroy } from "svelte"; | ||
export let editingExisting: boolean; | ||
export let finish: () => void; | ||
export let cancel: () => void; | ||
onMount(() => { | ||
if ($map) { | ||
$map.doubleClickZoom.disable(); | ||
} | ||
}); | ||
onDestroy(() => { | ||
if ($map) { | ||
$map.doubleClickZoom.enable(); | ||
} | ||
}); | ||
function onClick(e: CustomEvent<MapMouseEvent>) { | ||
if (!$pointPosition) { | ||
$pointPosition = e.detail.lngLat.toArray(); | ||
} | ||
} | ||
function onDoubleClick() { | ||
finish(); | ||
} | ||
function keyDown(e: KeyboardEvent) { | ||
if (e.key === "Escape") { | ||
e.stopPropagation(); | ||
cancel(); | ||
} | ||
} | ||
</script> | ||
|
||
<svelte:window on:keydown={keyDown} /> | ||
|
||
<MapEvents on:click={onClick} on:dblclick={onDoubleClick} /> | ||
|
||
{#if $pointPosition} | ||
<Marker draggable bind:lngLat={$pointPosition}> | ||
<span class="dot" /> | ||
</Marker> | ||
{/if} | ||
|
||
<div style="float: right"> | ||
<FixedButtonGroup> | ||
<DefaultButton on:click={finish} style="margin-bottom: 0px"> | ||
Finish | ||
</DefaultButton> | ||
<SecondaryButton on:click={cancel} noBottomMargin>Cancel</SecondaryButton> | ||
|
||
<HelpButton> | ||
<ul> | ||
{#if editingExisting} | ||
<li>Click to move the point here</li> | ||
{#if $pointPosition} | ||
<li>Click and drag the point to move it</li> | ||
{:else} | ||
<li>Click to add a new point</li> | ||
<li>Click the map to add a point</li> | ||
{/if} | ||
<li> | ||
Press <b>Escape</b> | ||
<b>Double click</b> | ||
the map to finish or press | ||
<b>Escape</b> | ||
to cancel | ||
</li> | ||
</ul> | ||
</HelpButton> | ||
</FixedButtonGroup> | ||
</div> | ||
|
||
<style> | ||
.dot { | ||
width: 30px; | ||
height: 30px; | ||
border-radius: 50%; | ||
display: inline-block; | ||
background: red; | ||
} | ||
.dot:hover { | ||
border: 1px solid black; | ||
cursor: pointer; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters