@classic-homes/maps-svelte 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,11 +45,7 @@ MapLibre 5 bundles its worker and needs none of this.
45
45
  </script>
46
46
 
47
47
  <MapContainer class="h-[500px]">
48
- <Map
49
- initialCenter={[-122.4, 37.8]}
50
- initialZoom={12}
51
- onClick={(e) => console.log('Clicked:', e.lngLat)}
52
- >
48
+ <Map center={[-122.4, 37.8]} zoom={12} onClick={(e) => console.log('Clicked:', e.lngLat)}>
53
49
  <Source id="lots" data={geojsonData}>
54
50
  <FillLayer id="lots-fill" fillColor="#22c55e" fillOpacity={0.7} />
55
51
  </Source>
@@ -97,23 +93,23 @@ MapLibre 5 bundles its worker and needs none of this.
97
93
  </script>
98
94
 
99
95
  <Map
100
- initialCenter={[-122.4, 37.8]}
101
- initialZoom={12}
102
- initialBearing={0}
103
- initialPitch={0}
96
+ center={[-122.4, 37.8]}
97
+ zoom={12}
98
+ bearing={0}
99
+ pitch={0}
104
100
  {bounds}
105
- fitBoundsOptions={{ padding: 50 }}
101
+ boundsPadding={50}
106
102
  style={lightBasicStyle}
107
103
  theme="light"
108
104
  interactive={true}
109
105
  scrollZoom={true}
110
106
  dragPan={true}
111
107
  onClick={handleClick}
112
- onHover={handleHover}
108
+ onMouseMove={handleMouseMove}
113
109
  onMove={handleMove}
114
110
  onLoad={handleLoad}
115
111
  >
116
- <slot />
112
+ {@render children?.()}
117
113
  </Map>
118
114
  ```
119
115
 
@@ -236,7 +232,7 @@ MapLibre 5 bundles its worker and needs none of this.
236
232
 
237
233
  <!-- Custom marker with popup -->
238
234
  <Marker
239
- lngLat={[-122.4, 37.8]}
235
+ coordinates={[-122.4, 37.8]}
240
236
  anchor="bottom"
241
237
  draggable={true}
242
238
  onClick={handleClick}
@@ -248,11 +244,9 @@ MapLibre 5 bundles its worker and needs none of this.
248
244
  </Marker>
249
245
 
250
246
  <!-- Popup with card styling -->
251
- <Popup lngLat={[-122.4, 37.8]} anchor="bottom" closeOnClick={false}>
247
+ <Popup coordinates={[-122.4, 37.8]} anchor="bottom" closeOnClick={false}>
252
248
  <PopupCard>
253
- <PopupHeader>
254
- <h3>Location Name</h3>
255
- </PopupHeader>
249
+ <PopupHeader title="Location Name" badge="New" />
256
250
  <PopupContent>
257
251
  <p>Description goes here</p>
258
252
  </PopupContent>
@@ -263,6 +257,29 @@ MapLibre 5 bundles its worker and needs none of this.
263
257
  </Popup>
264
258
  ```
265
259
 
260
+ ### Framing data that changes
261
+
262
+ `bounds` frames the map when it is created. To re-frame later, give `boundsKey`:
263
+ the map fits `bounds` again whenever the key changes (objects and arrays compare
264
+ by value). Pass the bounds themselves to follow every change, or a narrower key
265
+ so that only some changes move the camera.
266
+
267
+ ```svelte
268
+ <script lang="ts">
269
+ import { Map, FitBoundsControl } from '@classic-homes/maps-svelte';
270
+ import { boundsOfPositions, padBounds } from '@classic-homes/maps-core';
271
+
272
+ let { stops } = $props();
273
+ const raw = $derived(boundsOfPositions(stops.map((s) => [s.lng, s.lat])));
274
+ const bounds = $derived(raw ? padBounds(raw, { ratio: 0.1 }) : undefined);
275
+ </script>
276
+
277
+ <Map title="Route" {bounds} boundsKey={bounds} boundsPadding={48} boundsMaxZoom={16}>
278
+ <!-- "Show all" button: frames the bounds, north-up, honouring reduced motion -->
279
+ <FitBoundsControl {bounds} position="top-left" />
280
+ </Map>
281
+ ```
282
+
266
283
  ### Controls
267
284
 
268
285
  ```svelte
@@ -336,14 +353,15 @@ MapLibre 5 bundles its worker and needs none of this.
336
353
  <script lang="ts">
337
354
  import { useMapTheme } from '@classic-homes/maps-svelte';
338
355
 
339
- const { theme, style, isDark, toggleTheme } = useMapTheme();
356
+ let preference = $state<'light' | 'dark' | 'auto'>('auto');
357
+ const mapTheme = useMapTheme(() => preference);
340
358
  </script>
341
359
 
342
- <Map style={style.current} theme={theme.current}>
343
- <slot />
360
+ <Map title="Themed map" style={mapTheme.style}>
361
+ {@render children?.()}
344
362
  </Map>
345
- <button onclick={toggleTheme}>
346
- {isDark.current ? 'Light Mode' : 'Dark Mode'}
363
+ <button onclick={() => (preference = mapTheme.isDark ? 'light' : 'dark')}>
364
+ {mapTheme.isDark ? 'Light Mode' : 'Dark Mode'}
347
365
  </button>
348
366
  ```
349
367
 
@@ -1,28 +1,61 @@
1
+ <script lang="ts" module>
2
+ const WEBGL_FAILURE = /webgl|graphics context/i;
3
+
4
+ /** The line under the message: what a visitor can do about the failure */
5
+ export function mapErrorHint(message: string, detail?: string | null): string {
6
+ return WEBGL_FAILURE.test(`${message} ${detail ?? ''}`)
7
+ ? "This browser could not start the map's graphics. Try another browser."
8
+ : 'Check your connection and try again';
9
+ }
10
+ </script>
11
+
1
12
  <script lang="ts">
2
13
  import { cn } from '../../utils.js';
3
14
 
4
15
  interface Props {
5
16
  message?: string;
17
+ /** Line under the message; by default it tells a WebGL failure from a network one */
18
+ hint?: string;
19
+ /**
20
+ * The raw failure (MapLibre's own text is often a wall of JSON), shown only
21
+ * behind a "Technical details" disclosure
22
+ */
23
+ detail?: string | null;
6
24
  height?: number | string;
7
25
  onRetry?: () => void;
26
+ retryLabel?: string;
27
+ /** A way forward that does not need the map, e.g. "Switch to list view" */
28
+ actionLabel?: string;
29
+ onAction?: () => void;
8
30
  class?: string;
9
31
  }
10
32
 
11
- let { message = 'Failed to load map', height = 400, onRetry, class: className }: Props = $props();
33
+ let {
34
+ message = 'Failed to load map',
35
+ hint,
36
+ detail = null,
37
+ height = 400,
38
+ onRetry,
39
+ retryLabel = 'Retry',
40
+ actionLabel,
41
+ onAction,
42
+ class: className,
43
+ }: Props = $props();
12
44
 
13
45
  const heightStyle = $derived(typeof height === 'number' ? `${height}px` : height);
46
+ const hintText = $derived(hint ?? mapErrorHint(message, detail));
47
+ const buttonClass =
48
+ 'min-h-[44px] rounded-md px-4 py-2 text-sm font-medium shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2';
14
49
  </script>
15
50
 
16
51
  <div
17
52
  class={cn(
18
- 'flex flex-col items-center justify-center rounded-lg border border-destructive bg-background',
53
+ 'flex flex-col items-center justify-center overflow-y-auto rounded-lg border border-destructive bg-background p-4',
19
54
  className
20
55
  )}
21
56
  style:height={heightStyle}
22
- role="alert"
23
- aria-live="polite"
24
57
  >
25
- <div class="flex flex-col items-center gap-3 text-center">
58
+ <div class="flex max-w-md flex-col items-center gap-3 text-center">
26
59
  <svg
27
60
  class="h-10 w-10 text-destructive"
28
61
  xmlns="http://www.w3.org/2000/svg"
@@ -40,17 +73,39 @@
40
73
  d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
41
74
  />
42
75
  </svg>
43
- <div class="space-y-1">
76
+ <!-- The live region holds the message only: wrapping the buttons and the
77
+ disclosure would re-announce them on any change inside -->
78
+ <div class="space-y-1" role="alert" aria-live="polite">
44
79
  <p class="text-sm font-medium text-destructive">{message}</p>
45
- <p class="text-xs text-muted-foreground">Check your connection and try again</p>
80
+ <p class="text-xs text-muted-foreground">{hintText}</p>
46
81
  </div>
47
- {#if onRetry}
48
- <button
49
- onclick={onRetry}
50
- class="mt-2 rounded-md border border-input bg-background px-4 py-2 text-sm font-medium shadow-sm hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
51
- >
52
- Retry
53
- </button>
82
+ {#if (onAction && actionLabel) || onRetry}
83
+ <div class="mt-2 flex flex-wrap items-center justify-center gap-2">
84
+ {#if onAction && actionLabel}
85
+ <button
86
+ type="button"
87
+ onclick={onAction}
88
+ class={cn(buttonClass, 'bg-primary text-primary-foreground hover:bg-primary/90')}
89
+ >
90
+ {actionLabel}
91
+ </button>
92
+ {/if}
93
+ {#if onRetry}
94
+ <button
95
+ type="button"
96
+ onclick={onRetry}
97
+ class={cn(buttonClass, 'border border-input bg-background hover:bg-muted')}
98
+ >
99
+ {retryLabel}
100
+ </button>
101
+ {/if}
102
+ </div>
103
+ {/if}
104
+ {#if detail}
105
+ <details class="w-full text-left">
106
+ <summary class="cursor-pointer text-xs text-muted-foreground">Technical details</summary>
107
+ <p class="mt-1 max-h-24 overflow-auto break-all text-xs text-muted-foreground">{detail}</p>
108
+ </details>
54
109
  {/if}
55
110
  </div>
56
111
  </div>
@@ -1,7 +1,20 @@
1
+ /** The line under the message: what a visitor can do about the failure */
2
+ export declare function mapErrorHint(message: string, detail?: string | null): string;
1
3
  interface Props {
2
4
  message?: string;
5
+ /** Line under the message; by default it tells a WebGL failure from a network one */
6
+ hint?: string;
7
+ /**
8
+ * The raw failure (MapLibre's own text is often a wall of JSON), shown only
9
+ * behind a "Technical details" disclosure
10
+ */
11
+ detail?: string | null;
3
12
  height?: number | string;
4
13
  onRetry?: () => void;
14
+ retryLabel?: string;
15
+ /** A way forward that does not need the map, e.g. "Switch to list view" */
16
+ actionLabel?: string;
17
+ onAction?: () => void;
5
18
  class?: string;
6
19
  }
7
20
  declare const MapError: import("svelte").Component<Props, {}, "">;
@@ -0,0 +1,98 @@
1
+ <script lang="ts" module>
2
+ import type { BoundsArray, ExtendedControlPosition } from '@classic-homes/maps-core';
3
+
4
+ export interface FitBoundsControlProps {
5
+ /** What to frame; the button is disabled while this is undefined */
6
+ bounds?: BoundsArray | null;
7
+ /**
8
+ * Padding in pixels. Default: a fifth of the map's height, held between
9
+ * 12 and 60, so a short phone map is not framed into a sliver.
10
+ */
11
+ padding?: number | { top: number; right: number; bottom: number; left: number };
12
+ /** Highest zoom the fit may reach (default 17) */
13
+ maxZoom?: number;
14
+ /** Also turn the map back to north-up (default true) */
15
+ resetBearing?: boolean;
16
+ /** Control position (default top-right) */
17
+ position?: ExtendedControlPosition;
18
+ /** Accessible name and tooltip (default "Show all results") */
19
+ label?: string;
20
+ /** Called before the map moves, e.g. to clear a selection */
21
+ onFit?: () => void;
22
+ class?: string;
23
+ }
24
+ </script>
25
+
26
+ <script lang="ts">
27
+ /**
28
+ * A map button that frames given bounds: "zoom back out to everything".
29
+ * Matches the other on-map buttons (44px, card surface) and honours reduced
30
+ * motion.
31
+ */
32
+ import type * as maplibregl from 'maplibre-gl';
33
+ import CustomControl from './CustomControl.svelte';
34
+ import { useMapContext } from '../../composables/useMapContext.svelte.js';
35
+ import { useReducedMotion } from '../../composables/useReducedMotion.svelte.js';
36
+ import { cn } from '../../utils.js';
37
+
38
+ let {
39
+ bounds,
40
+ padding,
41
+ maxZoom = 17,
42
+ resetBearing = true,
43
+ position = 'top-right',
44
+ label = 'Show all results',
45
+ onFit,
46
+ class: className,
47
+ }: FitBoundsControlProps = $props();
48
+
49
+ const ctx = useMapContext();
50
+ const reducedMotion = useReducedMotion();
51
+
52
+ function fit() {
53
+ const map = ctx.map;
54
+ if (!map || !bounds) return;
55
+ onFit?.();
56
+ const auto = Math.min(60, Math.max(12, map.getContainer().clientHeight / 5));
57
+ map.fitBounds(bounds as [[number, number], [number, number]], {
58
+ padding: (padding ?? auto) as number | maplibregl.PaddingOptions,
59
+ maxZoom,
60
+ ...(resetBearing ? { bearing: 0 } : {}),
61
+ animate: !reducedMotion.value,
62
+ });
63
+ }
64
+ </script>
65
+
66
+ <CustomControl {position} priority="normal">
67
+ <button
68
+ type="button"
69
+ class={cn(
70
+ 'w-[44px] h-[44px] flex items-center justify-center',
71
+ 'bg-card rounded shadow-lg border border-border',
72
+ 'hover:bg-muted cursor-pointer text-foreground',
73
+ 'disabled:cursor-not-allowed disabled:opacity-50',
74
+ className
75
+ )}
76
+ aria-label={label}
77
+ title={label}
78
+ disabled={!bounds}
79
+ onclick={fit}
80
+ >
81
+ <svg
82
+ width="20"
83
+ height="20"
84
+ viewBox="0 0 24 24"
85
+ fill="none"
86
+ stroke="currentColor"
87
+ stroke-width="2"
88
+ stroke-linecap="round"
89
+ stroke-linejoin="round"
90
+ aria-hidden="true"
91
+ >
92
+ <path d="M8 3H5a2 2 0 0 0-2 2v3" />
93
+ <path d="M21 8V5a2 2 0 0 0-2-2h-3" />
94
+ <path d="M3 16v3a2 2 0 0 0 2 2h3" />
95
+ <path d="M16 21h3a2 2 0 0 0 2-2v-3" />
96
+ </svg>
97
+ </button>
98
+ </CustomControl>
@@ -0,0 +1,29 @@
1
+ import type { BoundsArray, ExtendedControlPosition } from '@classic-homes/maps-core';
2
+ export interface FitBoundsControlProps {
3
+ /** What to frame; the button is disabled while this is undefined */
4
+ bounds?: BoundsArray | null;
5
+ /**
6
+ * Padding in pixels. Default: a fifth of the map's height, held between
7
+ * 12 and 60, so a short phone map is not framed into a sliver.
8
+ */
9
+ padding?: number | {
10
+ top: number;
11
+ right: number;
12
+ bottom: number;
13
+ left: number;
14
+ };
15
+ /** Highest zoom the fit may reach (default 17) */
16
+ maxZoom?: number;
17
+ /** Also turn the map back to north-up (default true) */
18
+ resetBearing?: boolean;
19
+ /** Control position (default top-right) */
20
+ position?: ExtendedControlPosition;
21
+ /** Accessible name and tooltip (default "Show all results") */
22
+ label?: string;
23
+ /** Called before the map moves, e.g. to clear a selection */
24
+ onFit?: () => void;
25
+ class?: string;
26
+ }
27
+ declare const FitBoundsControl: import("svelte").Component<FitBoundsControlProps, {}, "">;
28
+ type FitBoundsControl = ReturnType<typeof FitBoundsControl>;
29
+ export default FitBoundsControl;
@@ -2,6 +2,7 @@
2
2
  import { getContext, onDestroy, untrack } from 'svelte';
3
3
  import type {
4
4
  LayerManagerProps,
5
+ LayerManagerEntry,
5
6
  OverlayLayerDefinition,
6
7
  OverlayLayerState,
7
8
  OverlayLayerCategory,
@@ -14,6 +15,7 @@
14
15
  searchLayers,
15
16
  getLayerCategories,
16
17
  groupLayersByCategory,
18
+ groupLayersByHeading,
17
19
  getLayerStatesArray,
18
20
  resolveLayerSourceUrl,
19
21
  } from '@classic-homes/maps-core';
@@ -31,6 +33,11 @@
31
33
 
32
34
  interface Props extends LayerManagerProps {}
33
35
 
36
+ type ListLayer = OverlayLayerDefinition | LayerManagerEntry;
37
+ /** A layer LayerManager can draw: one with a source and a style */
38
+ const isDrawable = (layer: ListLayer): layer is OverlayLayerDefinition =>
39
+ 'source' in layer && 'style' in layer;
40
+
34
41
  let {
35
42
  layers,
36
43
  apiKeys,
@@ -41,10 +48,37 @@
41
48
  allowReorder = false,
42
49
  showOpacity = false,
43
50
  collapsible = true,
51
+ manageLayers = true,
52
+ layerStates: controlledStates,
53
+ title = 'Layers',
54
+ buttonLabel = 'Toggle layer manager',
55
+ buttonClass,
56
+ priority = 'high',
44
57
  onLayerChange,
45
58
  class: className,
46
59
  }: Props = $props();
47
60
 
61
+ /**
62
+ * A layer's state: the app's (`layerStates`, controlled) when given, else
63
+ * LayerManager's own. Controlled rows default to off, idle and opaque.
64
+ */
65
+ function stateOf(id: string): OverlayLayerState | undefined {
66
+ if (controlledStates) {
67
+ const order = layers.findIndex((l) => l.id === id);
68
+ if (order === -1) return undefined;
69
+ return {
70
+ id,
71
+ visible: false,
72
+ opacity: 1,
73
+ loading: false,
74
+ error: null,
75
+ order,
76
+ ...controlledStates[id],
77
+ };
78
+ }
79
+ return layerStates.get(id);
80
+ }
81
+
48
82
  const mapContext = getContext<MapContext>('maplibre-map');
49
83
  const managerId = `layer-manager-${Math.random().toString(36).slice(2, 9)}`;
50
84
 
@@ -135,7 +169,7 @@
135
169
  id: managerId,
136
170
  type: 'layer-manager',
137
171
  position: position as 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right',
138
- priority: 'high',
172
+ priority,
139
173
  zLayer: 'interactive',
140
174
  hasExpandedState: true,
141
175
  })
@@ -194,8 +228,8 @@
194
228
 
195
229
  // Sort by state order for drag-to-reorder support
196
230
  return [...result].sort((a, b) => {
197
- const orderA = layerStates.get(a.id)?.order ?? 0;
198
- const orderB = layerStates.get(b.id)?.order ?? 0;
231
+ const orderA = stateOf(a.id)?.order ?? 0;
232
+ const orderB = stateOf(b.id)?.order ?? 0;
199
233
  return orderA - orderB;
200
234
  });
201
235
  });
@@ -205,10 +239,33 @@
205
239
  showCategories ? groupLayersByCategory(filteredLayers) : null
206
240
  );
207
241
 
242
+ // Free-text headings: any layer with a `group` lists the panel by heading
243
+ const headingGroups = $derived(
244
+ layers.some((l) => l.group) ? groupLayersByHeading(filteredLayers) : null
245
+ );
246
+
247
+ // Loading and failures of switched-on layers, for screen readers
248
+ const statusText = $derived(
249
+ layers
250
+ .flatMap((layer) => {
251
+ const state = stateOf(layer.id);
252
+ if (!state?.visible) return [];
253
+ if (state.error) return [`${layer.name}: ${state.error}`];
254
+ return state.loading ? [`${layer.name} loading`] : [];
255
+ })
256
+ .join('. ')
257
+ );
258
+
208
259
  // Get visible layer states
209
260
  // Depend on stateVersion to recalculate when visibility or opacity changes
210
261
  const visibleLayerStates = $derived.by(() => {
211
262
  void stateVersion;
263
+ if (controlledStates) {
264
+ return layers.flatMap((l) => {
265
+ const state = stateOf(l.id);
266
+ return state?.visible ? [state] : [];
267
+ });
268
+ }
212
269
  return getLayerStatesArray(layerStates).filter((s) => s.visible);
213
270
  });
214
271
 
@@ -262,6 +319,8 @@
262
319
  // Manage sources and layers on the map
263
320
  // Use setTimeout to debounce updates and break reactive chains
264
321
  $effect(() => {
322
+ // The app draws its own layers: never touch the map
323
+ if (!manageLayers) return;
265
324
  // Read visibleLayerStates to establish dependency
266
325
  const states = visibleLayerStates;
267
326
  // Also re-sync after a style reload (setStyle drops our sources/layers),
@@ -294,7 +353,7 @@
294
353
  // (we already react to layer changes via visibleLayerStates)
295
354
  for (const state of states) {
296
355
  const layer = untrack(() => layers.find((l) => l.id === state.id));
297
- if (!layer) continue;
356
+ if (!layer || !isDrawable(layer)) continue;
298
357
 
299
358
  const sourceId = `lm-source-${layer.id}`;
300
359
  const layerId = `lm-layer-${layer.id}`;
@@ -523,6 +582,7 @@
523
582
  if (e.key === 'Escape') {
524
583
  isOpen = false;
525
584
  controlPosition.setExpanded(false);
585
+ toggleButton?.focus();
526
586
  }
527
587
  };
528
588
 
@@ -534,11 +594,17 @@
534
594
  });
535
595
 
536
596
  function handleToggleLayer(layerId: string) {
537
- const currentState = layerStates.get(layerId);
597
+ const currentState = stateOf(layerId);
538
598
  if (!currentState) return;
539
599
 
540
600
  const newVisible = !currentState.visible;
541
601
 
602
+ // Controlled: the app applies the change and passes the state back
603
+ if (controlledStates) {
604
+ onLayerChange?.(layerId, { ...currentState, visible: newVisible });
605
+ return;
606
+ }
607
+
542
608
  // Directly update the state map
543
609
  const newStates = new Map(layerStates);
544
610
  newStates.set(layerId, { ...currentState, visible: newVisible });
@@ -551,9 +617,14 @@
551
617
  }
552
618
 
553
619
  function handleOpacityChange(layerId: string, opacity: number) {
554
- const currentState = layerStates.get(layerId);
620
+ const currentState = stateOf(layerId);
555
621
  if (!currentState) return;
556
622
 
623
+ if (controlledStates) {
624
+ onLayerChange?.(layerId, { ...currentState, opacity });
625
+ return;
626
+ }
627
+
557
628
  // Directly update the state map
558
629
  const newStates = new Map(layerStates);
559
630
  newStates.set(layerId, { ...currentState, opacity });
@@ -695,8 +766,150 @@
695
766
  }
696
767
 
697
768
  const isTop = $derived(position.startsWith('top'));
769
+
770
+ let toggleButton = $state<HTMLButtonElement>();
771
+
772
+ // Fit the open panel to the map it opens over: from the button down to the
773
+ // map's visible edge (or up, for a bottom position), so the list scrolls
774
+ // inside the map instead of running off a phone screen. Re-measured on
775
+ // resize and when a mobile toolbar collapses (visualViewport).
776
+ let panelMaxHeight = $state<number | null>(null);
777
+ $effect(() => {
778
+ if (!isOpen || !toggleButton) return;
779
+ const button = toggleButton;
780
+ const measure = () => {
781
+ const area = button.closest<HTMLElement>('.maplibregl-map')?.getBoundingClientRect();
782
+ const vv = window.visualViewport;
783
+ const viewTop = vv ? vv.offsetTop : 0;
784
+ const viewBottom = vv ? vv.offsetTop + vv.height : window.innerHeight;
785
+ const top = Math.max(area?.top ?? viewTop, viewTop);
786
+ const bottom = Math.min(area?.bottom ?? viewBottom, viewBottom);
787
+ const rect = button.getBoundingClientRect();
788
+ // 4px gap to the button, 8px clear of the map edge
789
+ const room = isTop ? bottom - rect.bottom - 12 : rect.top - top - 12;
790
+ panelMaxHeight = Math.max(120, Math.floor(room));
791
+ };
792
+ measure();
793
+ window.addEventListener('resize', measure);
794
+ window.visualViewport?.addEventListener('resize', measure);
795
+ return () => {
796
+ window.removeEventListener('resize', measure);
797
+ window.visualViewport?.removeEventListener('resize', measure);
798
+ };
799
+ });
698
800
  </script>
699
801
 
802
+ {#snippet layerRow(layer: ListLayer)}
803
+ {@const state = stateOf(layer.id)}
804
+ {#if state}
805
+ <div
806
+ class="classic-layer-item"
807
+ role={allowReorder ? 'listitem' : undefined}
808
+ draggable={allowReorder}
809
+ ondragstart={allowReorder ? (e: DragEvent) => handleDragStart(e, layer.id) : undefined}
810
+ ondragover={allowReorder ? (e: DragEvent) => handleDragOver(e, layer.id) : undefined}
811
+ ondragleave={allowReorder ? handleDragLeave : undefined}
812
+ ondragend={allowReorder ? handleDragEnd : undefined}
813
+ ondrop={allowReorder ? (e: DragEvent) => handleDrop(e, layer.id) : undefined}
814
+ data-dragging={draggedId === layer.id || undefined}
815
+ data-drag-over={dragOver?.id === layer.id ? dragOver.position : undefined}
816
+ >
817
+ {#if allowReorder}
818
+ <span class="classic-layer-drag-handle text-muted-foreground">
819
+ <svg
820
+ width="12"
821
+ height="12"
822
+ viewBox="0 0 24 24"
823
+ fill="none"
824
+ stroke="currentColor"
825
+ stroke-width="2"
826
+ >
827
+ <circle cx="9" cy="6" r="1" fill="currentColor" />
828
+ <circle cx="15" cy="6" r="1" fill="currentColor" />
829
+ <circle cx="9" cy="12" r="1" fill="currentColor" />
830
+ <circle cx="15" cy="12" r="1" fill="currentColor" />
831
+ <circle cx="9" cy="18" r="1" fill="currentColor" />
832
+ <circle cx="15" cy="18" r="1" fill="currentColor" />
833
+ </svg>
834
+ </span>
835
+ {/if}
836
+
837
+ <Switch
838
+ checked={state.visible}
839
+ onchange={() => handleToggleLayer(layer.id)}
840
+ aria-label={`Toggle ${layer.name}`}
841
+ class="scale-75"
842
+ />
843
+
844
+ <div class="flex-1 min-w-0">
845
+ <div class="flex items-center gap-1">
846
+ <span class="text-sm text-foreground truncate">{layer.name}</span>
847
+ {#if state.loading}
848
+ <svg
849
+ class="classic-layer-loading w-3 h-3 text-muted-foreground"
850
+ viewBox="0 0 24 24"
851
+ fill="none"
852
+ stroke="currentColor"
853
+ stroke-width="2"
854
+ >
855
+ <path
856
+ d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"
857
+ />
858
+ </svg>
859
+ {/if}
860
+ </div>
861
+ {#if state.error}
862
+ <span class="classic-layer-error">{state.error}</span>
863
+ {/if}
864
+ </div>
865
+
866
+ {#if showOpacity && state.visible}
867
+ <button
868
+ type="button"
869
+ class="text-muted-foreground hover:text-foreground p-1"
870
+ onclick={() => (expandedOpacity = expandedOpacity === layer.id ? null : layer.id)}
871
+ aria-label={`Adjust ${layer.name} opacity`}
872
+ aria-expanded={expandedOpacity === layer.id}
873
+ >
874
+ <svg
875
+ width="14"
876
+ height="14"
877
+ viewBox="0 0 24 24"
878
+ fill="none"
879
+ stroke="currentColor"
880
+ stroke-width="2"
881
+ >
882
+ <circle cx="12" cy="12" r="10" />
883
+ <path d="M12 2a10 10 0 0 1 0 20" fill="currentColor" opacity="0.3" />
884
+ </svg>
885
+ </button>
886
+ {/if}
887
+ </div>
888
+
889
+ {#if expandedOpacity === layer.id}
890
+ <div class="px-3 pb-2">
891
+ <div class="flex items-center gap-2">
892
+ <span class="text-xs text-muted-foreground w-12">Opacity</span>
893
+ <input
894
+ type="range"
895
+ min="0"
896
+ max="100"
897
+ value={state.opacity * 100}
898
+ aria-label={`${layer.name} opacity`}
899
+ aria-valuetext={`${Math.round(state.opacity * 100)}%`}
900
+ oninput={(e) =>
901
+ handleOpacityChange(layer.id, Number((e.target as HTMLInputElement).value) / 100)}
902
+ class="classic-layer-opacity-slider flex-1"
903
+ />
904
+ <span class="text-xs text-muted-foreground w-8 text-right">
905
+ {Math.round(state.opacity * 100)}%
906
+ </span>
907
+ </div>
908
+ </div>
909
+ {/if}
910
+ {/if}
911
+ {/snippet}
912
+
700
913
  <div
701
914
  bind:this={containerElement}
702
915
  class={cn('absolute', !controlPosition.visible && 'invisible', className)}
@@ -708,14 +921,15 @@
708
921
  class={cn(
709
922
  'absolute classic-layer-panel-enter',
710
923
  'bg-card rounded-lg shadow-lg border border-border',
711
- 'w-64',
924
+ 'flex w-64 max-w-[calc(100vw-4rem)] flex-col',
712
925
  isTop ? 'top-full mt-1' : 'bottom-full mb-1',
713
926
  position.includes('right') ? 'right-0' : 'left-0'
714
927
  )}
928
+ style:max-height={panelMaxHeight === null ? undefined : `${panelMaxHeight}px`}
715
929
  >
716
930
  <!-- Header -->
717
931
  <div class="flex items-center justify-between p-3 border-b border-border">
718
- <span class="text-sm font-medium text-foreground">Layers</span>
932
+ <span class="text-sm font-medium text-foreground">{title}</span>
719
933
  {#if collapsible}
720
934
  <button
721
935
  type="button"
@@ -778,8 +992,25 @@
778
992
  {/if}
779
993
 
780
994
  <!-- Layer list -->
781
- <div class="max-h-64 overflow-y-auto">
782
- {#if showCategories && layerGroups && activeCategory === 'all'}
995
+ <div class="min-h-0 flex-1 overflow-y-auto overscroll-contain">
996
+ {#if headingGroups}
997
+ {#each headingGroups as [heading, headingLayers] (heading)}
998
+ <div>
999
+ <div
1000
+ class="px-3 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider"
1001
+ >
1002
+ {heading}
1003
+ </div>
1004
+ {#each headingLayers as layer (layer.id)}
1005
+ {@render layerRow(layer)}
1006
+ {/each}
1007
+ </div>
1008
+ {/each}
1009
+
1010
+ {#if filteredLayers.length === 0}
1011
+ <div class="p-4 text-center text-sm text-muted-foreground">No layers found</div>
1012
+ {/if}
1013
+ {:else if showCategories && layerGroups && activeCategory === 'all'}
783
1014
  <!-- Grouped by category -->
784
1015
  {#each categories as cat (cat)}
785
1016
  {@const catLayers = layerGroups![cat]}
@@ -791,122 +1022,7 @@
791
1022
  {CATEGORY_META[cat].label}
792
1023
  </div>
793
1024
  {#each catLayers as layer (layer.id)}
794
- {@const state = layerStates.get(layer.id)}
795
- {#if state}
796
- <div
797
- class="classic-layer-item"
798
- role={allowReorder ? 'listitem' : undefined}
799
- draggable={allowReorder}
800
- ondragstart={allowReorder
801
- ? (e: DragEvent) => handleDragStart(e, layer.id)
802
- : undefined}
803
- ondragover={allowReorder
804
- ? (e: DragEvent) => handleDragOver(e, layer.id)
805
- : undefined}
806
- ondragleave={allowReorder ? handleDragLeave : undefined}
807
- ondragend={allowReorder ? handleDragEnd : undefined}
808
- ondrop={allowReorder ? (e: DragEvent) => handleDrop(e, layer.id) : undefined}
809
- data-dragging={draggedId === layer.id || undefined}
810
- data-drag-over={dragOver?.id === layer.id ? dragOver.position : undefined}
811
- >
812
- {#if allowReorder}
813
- <span class="classic-layer-drag-handle text-muted-foreground">
814
- <svg
815
- width="12"
816
- height="12"
817
- viewBox="0 0 24 24"
818
- fill="none"
819
- stroke="currentColor"
820
- stroke-width="2"
821
- >
822
- <circle cx="9" cy="6" r="1" fill="currentColor" />
823
- <circle cx="15" cy="6" r="1" fill="currentColor" />
824
- <circle cx="9" cy="12" r="1" fill="currentColor" />
825
- <circle cx="15" cy="12" r="1" fill="currentColor" />
826
- <circle cx="9" cy="18" r="1" fill="currentColor" />
827
- <circle cx="15" cy="18" r="1" fill="currentColor" />
828
- </svg>
829
- </span>
830
- {/if}
831
-
832
- <Switch
833
- checked={state.visible}
834
- onchange={() => handleToggleLayer(layer.id)}
835
- aria-label={`Toggle ${layer.name}`}
836
- class="scale-75"
837
- />
838
-
839
- <div class="flex-1 min-w-0">
840
- <div class="flex items-center gap-1">
841
- <span class="text-sm text-foreground truncate">{layer.name}</span>
842
- {#if state.loading}
843
- <svg
844
- class="classic-layer-loading w-3 h-3 text-muted-foreground"
845
- viewBox="0 0 24 24"
846
- fill="none"
847
- stroke="currentColor"
848
- stroke-width="2"
849
- >
850
- <path
851
- d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"
852
- />
853
- </svg>
854
- {/if}
855
- </div>
856
- {#if state.error}
857
- <span class="classic-layer-error">{state.error}</span>
858
- {/if}
859
- </div>
860
-
861
- {#if showOpacity && state.visible}
862
- <button
863
- type="button"
864
- class="text-muted-foreground hover:text-foreground p-1"
865
- onclick={() =>
866
- (expandedOpacity = expandedOpacity === layer.id ? null : layer.id)}
867
- aria-label={`Adjust ${layer.name} opacity`}
868
- aria-expanded={expandedOpacity === layer.id}
869
- >
870
- <svg
871
- width="14"
872
- height="14"
873
- viewBox="0 0 24 24"
874
- fill="none"
875
- stroke="currentColor"
876
- stroke-width="2"
877
- >
878
- <circle cx="12" cy="12" r="10" />
879
- <path d="M12 2a10 10 0 0 1 0 20" fill="currentColor" opacity="0.3" />
880
- </svg>
881
- </button>
882
- {/if}
883
- </div>
884
-
885
- {#if expandedOpacity === layer.id}
886
- <div class="px-3 pb-2">
887
- <div class="flex items-center gap-2">
888
- <span class="text-xs text-muted-foreground w-12">Opacity</span>
889
- <input
890
- type="range"
891
- min="0"
892
- max="100"
893
- value={state.opacity * 100}
894
- aria-label={`${layer.name} opacity`}
895
- aria-valuetext={`${Math.round(state.opacity * 100)}%`}
896
- oninput={(e) =>
897
- handleOpacityChange(
898
- layer.id,
899
- Number((e.target as HTMLInputElement).value) / 100
900
- )}
901
- class="classic-layer-opacity-slider flex-1"
902
- />
903
- <span class="text-xs text-muted-foreground w-8 text-right">
904
- {Math.round(state.opacity * 100)}%
905
- </span>
906
- </div>
907
- </div>
908
- {/if}
909
- {/if}
1025
+ {@render layerRow(layer)}
910
1026
  {/each}
911
1027
  </div>
912
1028
  {/if}
@@ -914,122 +1030,7 @@
914
1030
  {:else}
915
1031
  <!-- Flat list -->
916
1032
  {#each filteredLayers as layer (layer.id)}
917
- {@const state = layerStates.get(layer.id)}
918
- {#if state}
919
- <div
920
- class="classic-layer-item"
921
- role={allowReorder ? 'listitem' : undefined}
922
- draggable={allowReorder}
923
- ondragstart={allowReorder
924
- ? (e: DragEvent) => handleDragStart(e, layer.id)
925
- : undefined}
926
- ondragover={allowReorder
927
- ? (e: DragEvent) => handleDragOver(e, layer.id)
928
- : undefined}
929
- ondragleave={allowReorder ? handleDragLeave : undefined}
930
- ondragend={allowReorder ? handleDragEnd : undefined}
931
- ondrop={allowReorder ? (e: DragEvent) => handleDrop(e, layer.id) : undefined}
932
- data-dragging={draggedId === layer.id || undefined}
933
- data-drag-over={dragOver?.id === layer.id ? dragOver.position : undefined}
934
- >
935
- {#if allowReorder}
936
- <span class="classic-layer-drag-handle text-muted-foreground">
937
- <svg
938
- width="12"
939
- height="12"
940
- viewBox="0 0 24 24"
941
- fill="none"
942
- stroke="currentColor"
943
- stroke-width="2"
944
- >
945
- <circle cx="9" cy="6" r="1" fill="currentColor" />
946
- <circle cx="15" cy="6" r="1" fill="currentColor" />
947
- <circle cx="9" cy="12" r="1" fill="currentColor" />
948
- <circle cx="15" cy="12" r="1" fill="currentColor" />
949
- <circle cx="9" cy="18" r="1" fill="currentColor" />
950
- <circle cx="15" cy="18" r="1" fill="currentColor" />
951
- </svg>
952
- </span>
953
- {/if}
954
-
955
- <Switch
956
- checked={state.visible}
957
- onchange={() => handleToggleLayer(layer.id)}
958
- aria-label={`Toggle ${layer.name}`}
959
- class="scale-75"
960
- />
961
-
962
- <div class="flex-1 min-w-0">
963
- <div class="flex items-center gap-1">
964
- <span class="text-sm text-foreground truncate">{layer.name}</span>
965
- {#if state.loading}
966
- <svg
967
- class="classic-layer-loading w-3 h-3 text-muted-foreground"
968
- viewBox="0 0 24 24"
969
- fill="none"
970
- stroke="currentColor"
971
- stroke-width="2"
972
- >
973
- <path
974
- d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"
975
- />
976
- </svg>
977
- {/if}
978
- </div>
979
- {#if state.error}
980
- <span class="classic-layer-error">{state.error}</span>
981
- {/if}
982
- </div>
983
-
984
- {#if showOpacity && state.visible}
985
- <button
986
- type="button"
987
- class="text-muted-foreground hover:text-foreground p-1"
988
- onclick={() =>
989
- (expandedOpacity = expandedOpacity === layer.id ? null : layer.id)}
990
- aria-label={`Adjust ${layer.name} opacity`}
991
- aria-expanded={expandedOpacity === layer.id}
992
- >
993
- <svg
994
- width="14"
995
- height="14"
996
- viewBox="0 0 24 24"
997
- fill="none"
998
- stroke="currentColor"
999
- stroke-width="2"
1000
- >
1001
- <circle cx="12" cy="12" r="10" />
1002
- <path d="M12 2a10 10 0 0 1 0 20" fill="currentColor" opacity="0.3" />
1003
- </svg>
1004
- </button>
1005
- {/if}
1006
- </div>
1007
-
1008
- {#if expandedOpacity === layer.id}
1009
- <div class="px-3 pb-2">
1010
- <div class="flex items-center gap-2">
1011
- <span class="text-xs text-muted-foreground w-12">Opacity</span>
1012
- <input
1013
- type="range"
1014
- min="0"
1015
- max="100"
1016
- value={state.opacity * 100}
1017
- aria-label={`${layer.name} opacity`}
1018
- aria-valuetext={`${Math.round(state.opacity * 100)}%`}
1019
- oninput={(e) =>
1020
- handleOpacityChange(
1021
- layer.id,
1022
- Number((e.target as HTMLInputElement).value) / 100
1023
- )}
1024
- class="classic-layer-opacity-slider flex-1"
1025
- />
1026
- <span class="text-xs text-muted-foreground w-8 text-right">
1027
- {Math.round(state.opacity * 100)}%
1028
- </span>
1029
- </div>
1030
- </div>
1031
- {/if}
1032
- {/if}
1033
+ {@render layerRow(layer)}
1033
1034
  {/each}
1034
1035
 
1035
1036
  {#if filteredLayers.length === 0}
@@ -1042,15 +1043,17 @@
1042
1043
 
1043
1044
  <!-- Toggle button -->
1044
1045
  <button
1046
+ bind:this={toggleButton}
1045
1047
  type="button"
1046
1048
  class={cn(
1047
1049
  'w-[40px] h-[40px] flex items-center justify-center',
1048
1050
  'bg-card rounded shadow-lg border border-border',
1049
1051
  'hover:bg-muted cursor-pointer',
1050
- 'text-foreground'
1052
+ 'text-foreground',
1053
+ buttonClass
1051
1054
  )}
1052
1055
  onclick={handleToggle}
1053
- aria-label="Toggle layer manager"
1056
+ aria-label={buttonLabel}
1054
1057
  aria-expanded={isOpen}
1055
1058
  aria-haspopup="true"
1056
1059
  >
@@ -1071,4 +1074,5 @@
1071
1074
  <line x1="12" y1="22.76" x2="12" y2="11" />
1072
1075
  </svg>
1073
1076
  </button>
1077
+ <p class="sr-only" aria-live="polite">{statusText}</p>
1074
1078
  </div>
@@ -4,3 +4,4 @@ export { default as CoordinateDisplay } from './CoordinateDisplay.svelte';
4
4
  export { default as BasemapSwitcher } from './BasemapSwitcher.svelte';
5
5
  export { default as LayerManager } from './LayerManager.svelte';
6
6
  export { default as CustomControl, type CustomControlProps } from './CustomControl.svelte';
7
+ export { default as FitBoundsControl, type FitBoundsControlProps } from './FitBoundsControl.svelte';
@@ -4,3 +4,4 @@ export { default as CoordinateDisplay } from './CoordinateDisplay.svelte';
4
4
  export { default as BasemapSwitcher } from './BasemapSwitcher.svelte';
5
5
  export { default as LayerManager } from './LayerManager.svelte';
6
6
  export { default as CustomControl } from './CustomControl.svelte';
7
+ export { default as FitBoundsControl } from './FitBoundsControl.svelte';
@@ -53,6 +53,8 @@
53
53
  pitch = 0,
54
54
  bounds,
55
55
  boundsPadding,
56
+ boundsMaxZoom,
57
+ boundsKey,
56
58
  minZoom,
57
59
  maxZoom,
58
60
  maxBounds,
@@ -349,8 +351,13 @@
349
351
  mapLoaded = true;
350
352
 
351
353
  if (bounds) {
354
+ // The container may have been sized after the map was created (a
355
+ // layout that measures itself on mount), so fit at its real size
356
+ newMap.resize();
357
+ framedKey = { key: keyOf(untrack(() => boundsKey)) };
352
358
  newMap.fitBounds(bounds as [[number, number], [number, number]], {
353
359
  padding: boundsPadding as number | maplibregl.PaddingOptions | undefined,
360
+ maxZoom: boundsMaxZoom,
354
361
  animate: animation && !reducedMotion.value,
355
362
  });
356
363
  }
@@ -546,6 +553,28 @@
546
553
  });
547
554
  });
548
555
 
556
+ // `boundsKey`: a change after load re-frames the map to `bounds`. The load
557
+ // handler's own fit counts as applying the key in force at that moment.
558
+ const keyOf = (value: unknown) =>
559
+ value !== null && typeof value === 'object' ? JSON.stringify(value) : value;
560
+ let framedKey: { key: unknown } | null = null;
561
+ $effect(() => {
562
+ const key = keyOf(boundsKey);
563
+ const target = bounds;
564
+ if (!map || !mapLoaded || boundsKey === undefined || !target) return;
565
+ const live = map;
566
+ untrack(() => {
567
+ if (framedKey && framedKey.key === key) return;
568
+ framedKey = { key };
569
+ live.resize();
570
+ live.fitBounds(target as [[number, number], [number, number]], {
571
+ padding: boundsPadding as number | maplibregl.PaddingOptions | undefined,
572
+ maxZoom: boundsMaxZoom,
573
+ animate: animation && !reducedMotion.value,
574
+ });
575
+ });
576
+ });
577
+
549
578
  // Clear programmatic override when customStyle prop changes
550
579
  $effect(() => {
551
580
  if (customStyle) {
@@ -2,4 +2,4 @@ export { MapContainer, MapSkeleton, MapError, MapEmpty } from './base/index.js';
2
2
  export { Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter, } from './core/index.js';
3
3
  export { FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer, useLayer, type UseLayerOptions, type SvelteFeatureClickEventParams, type SvelteFeatureHoverEventParams, } from './layers/index.js';
4
4
  export { DeckOverlay } from './deck/index.js';
5
- export { Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, type CustomControlProps, } from './controls/index.js';
5
+ export { Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, type CustomControlProps, FitBoundsControl, type FitBoundsControlProps, } from './controls/index.js';
@@ -7,4 +7,4 @@ export { FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, Hea
7
7
  // Deck.gl components
8
8
  export { DeckOverlay } from './deck/index.js';
9
9
  // Control components
10
- export { Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, } from './controls/index.js';
10
+ export { Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, FitBoundsControl, } from './controls/index.js';
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * Svelte MapLibre components for the Classic Theme design system
5
5
  */
6
- export { MapContainer, MapSkeleton, MapError, MapEmpty, Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter, useLayer, type UseLayerOptions, FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer, Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, type CustomControlProps, DeckOverlay, type SvelteFeatureClickEventParams, type SvelteFeatureHoverEventParams, } from './components/index.js';
6
+ export { MapContainer, MapSkeleton, MapError, MapEmpty, Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter, useLayer, type UseLayerOptions, FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer, Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, type CustomControlProps, FitBoundsControl, type FitBoundsControlProps, DeckOverlay, type SvelteFeatureClickEventParams, type SvelteFeatureHoverEventParams, } from './components/index.js';
7
7
  export { useMapTheme, useReducedMotion, useMapContext, tryUseMapContext, useMapInstance, useControlPosition, type MapContextValue, type UseControlPositionOptions, type UseControlPositionResult, } from './composables/index.js';
8
8
  export { cn } from './utils.js';
9
- export type { LngLat, MapBounds, BoundsArray, MapViewport, GeoJSONFeature, GeoJSONFeatureCollection, MarkerData, MapClickEventParams, MapHoverEventParams, FeatureClickEventParams, FeatureHoverEventParams, MarkerClickEventParams, MarkerDragEventParams, MapMoveEventParams, BaseMapProps, MapProps, SourceProps, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, MarkerProps, PopupProps, LegendItem, GradientStop, LegendProps, CoordinateDisplayProps, LegendConfig, LegendGroupProps, BasemapProvider, BasemapCategory, BasemapDefinition, BasemapApiKeys, BasemapSwitcherProps, OverlayLayerCategory, OverlayLayerDefinition, OverlayLayerState, OverlayApiKeys, LayerManagerProps, ExtendedControlPosition, ControlPriority, ZIndexLayer, ControlType, ControlOffset, } from '@classic-homes/maps-core';
10
- export { CATEGORY_META, SCHOOL_DISTRICTS, CITY_LIMITS, ZONING_DISTRICTS, PARKS, TRAILS, SPORTS_FACILITIES, TRANSIT_ROUTES, BIKE_LANES, FLOOD_ZONES, WATERSHEDS, BUILTIN_OVERLAY_LAYERS, resolveLayerSourceUrl, getLayerStyleForTheme, searchLayers, getLayersByCategory, groupLayersByCategory, getLayerCategories, createInitialLayerStates, toggleLayerVisibility, setLayerOpacity, } from '@classic-homes/maps-core';
11
- export { THEME_LIGHT, THEME_DARK, lightTheme, darkTheme, lightBasicStyle, darkBasicStyle, generateMapDescription, formatCoordinates, formatDistance, formatArea, createHoverExpression, createSelectionExpression, getHighlightStyle, getSelectionStyle, calculateBounds, extendBounds, combineBounds, isValidBounds, loadGeoJSON, validateGeoJSON, calculateCentroid, countFeaturesByType, filterByGeometryType, DEFAULT_BASEMAP, SATELLITE_BASEMAP, TOPO_BASEMAP, PRIMARY_BASEMAPS, BUILTIN_BASEMAPS, FREE_BASEMAPS, OSM_STANDARD, resolveBasemapStyle, getAvailableBasemaps, } from '@classic-homes/maps-core';
9
+ export type { LngLat, MapBounds, BoundsArray, MapViewport, GeoJSONFeature, GeoJSONFeatureCollection, MarkerData, MapClickEventParams, MapHoverEventParams, FeatureClickEventParams, FeatureHoverEventParams, MarkerClickEventParams, MarkerDragEventParams, MapMoveEventParams, BaseMapProps, MapProps, SourceProps, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, MarkerProps, PopupProps, LegendItem, GradientStop, LegendProps, CoordinateDisplayProps, LegendConfig, LegendGroupProps, BasemapProvider, BasemapCategory, BasemapDefinition, BasemapApiKeys, BasemapSwitcherProps, OverlayLayerCategory, OverlayLayerDefinition, OverlayLayerState, OverlayApiKeys, LayerManagerProps, LayerManagerEntry, LayerManagerLayerState, ExtendedControlPosition, ControlPriority, ZIndexLayer, ControlType, ControlOffset, } from '@classic-homes/maps-core';
10
+ export { CATEGORY_META, SCHOOL_DISTRICTS, CITY_LIMITS, ZONING_DISTRICTS, PARKS, TRAILS, SPORTS_FACILITIES, TRANSIT_ROUTES, BIKE_LANES, FLOOD_ZONES, WATERSHEDS, BUILTIN_OVERLAY_LAYERS, resolveLayerSourceUrl, getLayerStyleForTheme, searchLayers, getLayersByCategory, groupLayersByCategory, groupLayersByHeading, getLayerCategories, createInitialLayerStates, toggleLayerVisibility, setLayerOpacity, } from '@classic-homes/maps-core';
11
+ export { THEME_LIGHT, THEME_DARK, lightTheme, darkTheme, lightBasicStyle, darkBasicStyle, generateMapDescription, formatCoordinates, formatDistance, formatArea, createHoverExpression, createSelectionExpression, getHighlightStyle, getSelectionStyle, calculateBounds, extendBounds, combineBounds, isValidBounds, boundsOfPositions, padBounds, loadGeoJSON, validateGeoJSON, calculateCentroid, countFeaturesByType, filterByGeometryType, DEFAULT_BASEMAP, SATELLITE_BASEMAP, TOPO_BASEMAP, PRIMARY_BASEMAPS, BUILTIN_BASEMAPS, FREE_BASEMAPS, OSM_STANDARD, resolveBasemapStyle, getAvailableBasemaps, } from '@classic-homes/maps-core';
12
12
  export type { LoadGeoJSONOptions, LoadGeoJSONResult, ValidationResult, ClusterFeatureProperties, ClusterExpandOptions, } from '@classic-homes/maps-core';
13
13
  export { isClusterFeature, getClusterExpansionZoom, getClusterChildren, getClusterLeaves, expandCluster, getClusterBounds, expandClusterToBounds, createClusterStyles, createClusterCirclePaint, createClusterTextLayout, } from '@classic-homes/maps-core';
14
14
  export type { ClusterCircleStyleOptions, ClusterTextStyleOptions, UnclusteredPointStyleOptions, ClusterLayerStyles, } from '@classic-homes/maps-core';
package/dist/lib/index.js CHANGED
@@ -12,7 +12,7 @@ Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter,
12
12
  // Layers
13
13
  useLayer, FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer,
14
14
  // Controls
15
- Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl,
15
+ Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, FitBoundsControl,
16
16
  // Deck.gl
17
17
  DeckOverlay, } from './components/index.js';
18
18
  // Composables
@@ -20,11 +20,11 @@ export { useMapTheme, useReducedMotion, useMapContext, tryUseMapContext, useMapI
20
20
  // Utils
21
21
  export { cn } from './utils.js';
22
22
  // Re-export layer presets and utilities from maps-core
23
- export { CATEGORY_META, SCHOOL_DISTRICTS, CITY_LIMITS, ZONING_DISTRICTS, PARKS, TRAILS, SPORTS_FACILITIES, TRANSIT_ROUTES, BIKE_LANES, FLOOD_ZONES, WATERSHEDS, BUILTIN_OVERLAY_LAYERS, resolveLayerSourceUrl, getLayerStyleForTheme, searchLayers, getLayersByCategory, groupLayersByCategory, getLayerCategories, createInitialLayerStates, toggleLayerVisibility, setLayerOpacity, } from '@classic-homes/maps-core';
23
+ export { CATEGORY_META, SCHOOL_DISTRICTS, CITY_LIMITS, ZONING_DISTRICTS, PARKS, TRAILS, SPORTS_FACILITIES, TRANSIT_ROUTES, BIKE_LANES, FLOOD_ZONES, WATERSHEDS, BUILTIN_OVERLAY_LAYERS, resolveLayerSourceUrl, getLayerStyleForTheme, searchLayers, getLayersByCategory, groupLayersByCategory, groupLayersByHeading, getLayerCategories, createInitialLayerStates, toggleLayerVisibility, setLayerOpacity, } from '@classic-homes/maps-core';
24
24
  // Re-export theme and utilities from maps-core
25
25
  export { THEME_LIGHT, THEME_DARK, lightTheme, darkTheme, lightBasicStyle, darkBasicStyle, generateMapDescription, formatCoordinates, formatDistance, formatArea, createHoverExpression, createSelectionExpression, getHighlightStyle, getSelectionStyle,
26
26
  // Bounds utilities
27
- calculateBounds, extendBounds, combineBounds, isValidBounds,
27
+ calculateBounds, extendBounds, combineBounds, isValidBounds, boundsOfPositions, padBounds,
28
28
  // Data utilities
29
29
  loadGeoJSON, validateGeoJSON, calculateCentroid, countFeaturesByType, filterByGeometryType,
30
30
  // Basemap utilities
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/maps-svelte",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Svelte MapLibre components for Classic Theme",
5
5
  "keywords": [
6
6
  "maps",
@@ -37,7 +37,7 @@
37
37
  "test": "vitest run"
38
38
  },
39
39
  "dependencies": {
40
- "@classic-homes/maps-core": "^0.9.0",
40
+ "@classic-homes/maps-core": "^0.11.0",
41
41
  "@classic-homes/theme-svelte": "*",
42
42
  "@classic-homes/theme-tokens": "*",
43
43
  "clsx": "^2.1.0",