From c407fe8c67417ab583a45cd95eb9e8d8324a20fc Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Fri, 12 Jun 2026 18:31:32 +0200 Subject: [PATCH 1/5] implement feature --- components/src/maplibre/Map/Map.svelte | 50 +++++++++++++++++--------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/components/src/maplibre/Map/Map.svelte b/components/src/maplibre/Map/Map.svelte index 24a4cd75..5cdfc28b 100644 --- a/components/src/maplibre/Map/Map.svelte +++ b/components/src/maplibre/Map/Map.svelte @@ -31,6 +31,7 @@ center?: maplibre.LngLat; pitch?: number; bearing?: number; + bounds?: LngLatBounds; loading?: boolean; projection?: ProjectionSpecification; showDebug?: boolean; @@ -59,6 +60,7 @@ center = $bindable(), pitch = $bindable(0), bearing = $bindable(0), + bounds = $bindable(), loading = $bindable(true), projection = { type: 'mercator' }, allowPan = true, @@ -85,7 +87,7 @@ // 2. initialLocation prop // 3. initialLocation context (notably set by ) - let contextLocation: Location = getContext('initialLocation'); + let contextLocation: Partial = getContext('initialLocation'); let initialLocation = $derived({ lat: 51.3, @@ -119,6 +121,7 @@ center = mapContext.map?.getCenter(); pitch = mapContext.map?.getPitch() || 0; bearing = mapContext.map?.getBearing() || 0; + bounds = mapContext.map?.getBounds(); }); mapContext.map.on('moveend', () => { @@ -126,6 +129,7 @@ center = mapContext.map?.getCenter(); pitch = mapContext.map?.getPitch() || 0; bearing = mapContext.map?.getBearing() || 0; + bounds = mapContext.map?.getBounds(); }); if (onmoveend) { @@ -178,7 +182,9 @@ } }); - const debugValues = $derived(Object.entries({ zoom, pitch, bearing, allowZoom, allowPan, allowRotation })); + const debugValues = $derived( + Object.entries({ zoom, pitch, bearing, allowZoom, allowPan, allowRotation }) + ); const handleDebugValueClick = (e: MouseEvent) => { if (e.target) { const t = e.target as HTMLElement; @@ -192,6 +198,12 @@ navigator.clipboard.writeText(s); } }; + const handleDebugCopyBoundsClick = (e: MouseEvent) => { + if (e.target) { + const s = JSON.stringify(bounds.toArray()); + navigator.clipboard.writeText(s); + } + };
@@ -201,19 +213,24 @@ {/if} {/if} {#if showDebug} -
    -
  • - [{center?.lat.toFixed(2)}, {center?.lng.toFixed(2)}] -
  • - {#each debugValues as [key, value]} +
    +
    • - {key}= + [{center?.lat.toFixed(2)}, {center?.lng.toFixed(2)}]
    • - {/each} -
    • -
    + {#each debugValues as [key, value]} +
  • + {key}= +
  • + {/each} +
+
    +
  • +
  • +
+
{/if} @@ -227,17 +244,16 @@ position: absolute; top: 0; background: rgba(0, 0, 0, 0.75); - color: white; + color: #eee; z-index: 1000; - padding: 2px; + padding: 4px; font-size: 10px; font-family: monospace; display: flex; flex-flow: column; @media (min-width: 600px) { - gap: 1em; + gap: 0.5em; right: 0; - flex-flow: row; } li { list-style: none; From 5d800acfd6afc479d8ddf7382e856ccddf836696 Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Fri, 12 Jun 2026 18:46:11 +0200 Subject: [PATCH 2/5] Add tests --- .../src/maplibre/Map/Map.stories.svelte | 58 ++++++++++++++++++- components/src/maplibre/Map/Map.svelte | 4 +- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/components/src/maplibre/Map/Map.stories.svelte b/components/src/maplibre/Map/Map.stories.svelte index dc4001fc..1019b484 100644 --- a/components/src/maplibre/Map/Map.stories.svelte +++ b/components/src/maplibre/Map/Map.stories.svelte @@ -1,6 +1,6 @@