-
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.
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
packages/frontend/src/lib/components/GoToCoordsControl.svelte
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts"> | ||
import { mapContext, DefaultMarker } from "svelte-maplibre" | ||
import type { LngLatLike } from "svelte-maplibre/types.svelte" | ||
const map = mapContext().map | ||
let value: string = "" | ||
let markerPos: LngLatLike | undefined | ||
function submit() { | ||
markerPos = undefined | ||
const coords = value.split(",").map((coord) => parseFloat(coord)) | ||
if (coords[1] < -85 || coords[1] > 85) { | ||
coords.reverse() | ||
} | ||
if (coords.length !== 2 || coords.some((coord) => isNaN(coord))) { | ||
return | ||
} | ||
markerPos = [coords[0], coords[1]] | ||
$map?.flyTo({ center: markerPos, zoom: 15 }) | ||
value = "" | ||
} | ||
</script> | ||
|
||
<div class="go-to-coords-control"> | ||
<input | ||
type="text" | ||
placeholder="Jump to coordinates" | ||
bind:value | ||
on:keydown={(e) => e.key === "Enter" && submit()} | ||
/> | ||
</div> | ||
|
||
{#if markerPos} | ||
<DefaultMarker lngLat={markerPos} offset={[0, -20]} /> | ||
{/if} | ||
|
||
<style> | ||
input { | ||
width: 100%; | ||
padding: 0.25rem; | ||
font-size: 0.8rem; | ||
border: 1px solid #ccc; | ||
border-radius: 0.25rem; | ||
outline: none; | ||
} | ||
</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 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