@classic-homes/maps-svelte 0.8.0 → 0.10.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 +40 -22
- package/dist/lib/components/base/MapError.svelte +69 -14
- package/dist/lib/components/base/MapError.svelte.d.ts +13 -0
- package/dist/lib/components/controls/CoordinateDisplay.svelte +31 -3
- package/dist/lib/components/controls/FitBoundsControl.svelte +98 -0
- package/dist/lib/components/controls/FitBoundsControl.svelte.d.ts +29 -0
- package/dist/lib/components/controls/LayerManager.svelte +30 -0
- package/dist/lib/components/controls/index.d.ts +1 -0
- package/dist/lib/components/controls/index.js +1 -0
- package/dist/lib/components/core/Map.svelte +83 -2
- package/dist/lib/components/core/Marker.svelte +28 -3
- package/dist/lib/components/core/Popup.svelte +93 -23
- package/dist/lib/components/index.d.ts +1 -1
- package/dist/lib/components/index.js +1 -1
- package/dist/lib/components/layers/CircleLayer.svelte +2 -0
- package/dist/lib/components/layers/FillExtrusionLayer.svelte +2 -0
- package/dist/lib/components/layers/FillLayer.svelte +2 -0
- package/dist/lib/components/layers/HeatmapLayer.svelte +2 -0
- package/dist/lib/components/layers/LineLayer.svelte +2 -0
- package/dist/lib/components/layers/SymbolLayer.svelte +2 -0
- package/dist/lib/components/layers/useLayer.svelte.js +16 -0
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/index.js +2 -2
- package/package.json +2 -2
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
center={[-122.4, 37.8]}
|
|
97
|
+
zoom={12}
|
|
98
|
+
bearing={0}
|
|
99
|
+
pitch={0}
|
|
104
100
|
{bounds}
|
|
105
|
-
|
|
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
|
-
|
|
108
|
+
onMouseMove={handleMouseMove}
|
|
113
109
|
onMove={handleMove}
|
|
114
110
|
onLoad={handleLoad}
|
|
115
111
|
>
|
|
116
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
356
|
+
let preference = $state<'light' | 'dark' | 'auto'>('auto');
|
|
357
|
+
const mapTheme = useMapTheme(() => preference);
|
|
340
358
|
</script>
|
|
341
359
|
|
|
342
|
-
<Map
|
|
343
|
-
|
|
360
|
+
<Map title="Themed map" style={mapTheme.style}>
|
|
361
|
+
{@render children?.()}
|
|
344
362
|
</Map>
|
|
345
|
-
<button onclick={
|
|
346
|
-
{isDark
|
|
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 {
|
|
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
|
-
|
|
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">
|
|
80
|
+
<p class="text-xs text-muted-foreground">{hintText}</p>
|
|
46
81
|
</div>
|
|
47
|
-
{#if onRetry}
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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, {}, "">;
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
// Generate unique ID for this control instance
|
|
28
28
|
const controlId = `coord-display-${Math.random().toString(36).slice(2, 9)}`;
|
|
29
29
|
|
|
30
|
-
//
|
|
31
|
-
|
|
30
|
+
// Width of MapLibre's own top-right controls (navigation, fullscreen …),
|
|
31
|
+
// measured: their size depends on the theme's touch-target CSS.
|
|
32
|
+
let topRightInset = $state(0);
|
|
32
33
|
|
|
33
34
|
let cursorLngLat: LngLat | null = $state(null);
|
|
34
35
|
let currentZoom = $state(0);
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
const adjustedStyle = $derived(() => {
|
|
58
59
|
if (position === 'top-right') {
|
|
59
60
|
// Position horizontally to the left of native controls
|
|
60
|
-
const rightOffset =
|
|
61
|
+
const rightOffset = topRightInset ? topRightInset + STACK_GAP : EDGE_MARGIN;
|
|
61
62
|
return `position: absolute; top: ${EDGE_MARGIN}px; right: ${rightOffset}px; z-index: 10;`;
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -87,6 +88,33 @@
|
|
|
87
88
|
return `${normalized.toFixed(0)}°`;
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
// Track the native top-right controls so a top-right display sits beside them
|
|
92
|
+
$effect(() => {
|
|
93
|
+
const { map, loaded } = mapContext;
|
|
94
|
+
if (!map || !loaded || position !== 'top-right') return;
|
|
95
|
+
const container = map.getContainer();
|
|
96
|
+
const corner = container.querySelector('.maplibregl-ctrl-top-right');
|
|
97
|
+
if (!corner) return;
|
|
98
|
+
const measure = () => {
|
|
99
|
+
const controls = [...corner.children].filter((el) => el !== controlElement);
|
|
100
|
+
if (controls.length === 0) {
|
|
101
|
+
topRightInset = 0;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const left = Math.min(...controls.map((el) => el.getBoundingClientRect().left));
|
|
105
|
+
topRightInset = Math.max(0, Math.round(container.getBoundingClientRect().right - left));
|
|
106
|
+
};
|
|
107
|
+
measure();
|
|
108
|
+
const resize = new ResizeObserver(measure);
|
|
109
|
+
resize.observe(corner);
|
|
110
|
+
const added = new MutationObserver(measure);
|
|
111
|
+
added.observe(corner, { childList: true });
|
|
112
|
+
return () => {
|
|
113
|
+
resize.disconnect();
|
|
114
|
+
added.disconnect();
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
|
|
90
118
|
// Setup event listeners
|
|
91
119
|
$effect(() => {
|
|
92
120
|
const { map, loaded } = mapContext;
|
|
@@ -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;
|
|
@@ -228,6 +228,32 @@
|
|
|
228
228
|
}
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Stack the managed layers in list order: the top of the list draws on top.
|
|
233
|
+
* Outlines sit right above their fill. Only managed layers move; they keep
|
|
234
|
+
* their place relative to the app's other layers.
|
|
235
|
+
*/
|
|
236
|
+
function applyDrawOrder(map: maplibregl.Map) {
|
|
237
|
+
const desired: string[] = []; // bottom to top
|
|
238
|
+
for (const state of getLayerStatesArray(layerStates).reverse()) {
|
|
239
|
+
const id = `lm-layer-${state.id}`;
|
|
240
|
+
if (map.getLayer(id)) desired.push(id);
|
|
241
|
+
if (map.getLayer(`${id}${OUTLINE_LAYER_SUFFIX}`))
|
|
242
|
+
desired.push(`${id}${OUTLINE_LAYER_SUFFIX}`);
|
|
243
|
+
}
|
|
244
|
+
if (desired.length < 2) return;
|
|
245
|
+
const all = map.getLayersOrder();
|
|
246
|
+
const managed = new Set(desired);
|
|
247
|
+
if (all.filter((id) => managed.has(id)).join('\n') === desired.join('\n')) return;
|
|
248
|
+
const top = Math.max(...desired.map((id) => all.indexOf(id)));
|
|
249
|
+
const before = all.slice(top + 1).find((id) => !managed.has(id));
|
|
250
|
+
try {
|
|
251
|
+
for (const id of desired) map.moveLayer(id, before);
|
|
252
|
+
} catch {
|
|
253
|
+
// The style changed underneath us; the next sync reapplies the order
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
231
257
|
// Track pending map update
|
|
232
258
|
let mapUpdateTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
233
259
|
// Theme each added layer's paint was last applied for
|
|
@@ -434,6 +460,8 @@
|
|
|
434
460
|
}
|
|
435
461
|
}
|
|
436
462
|
}
|
|
463
|
+
|
|
464
|
+
applyDrawOrder(map);
|
|
437
465
|
}, 0); // End of setTimeout callback
|
|
438
466
|
});
|
|
439
467
|
|
|
@@ -804,6 +832,7 @@
|
|
|
804
832
|
<Switch
|
|
805
833
|
checked={state.visible}
|
|
806
834
|
onchange={() => handleToggleLayer(layer.id)}
|
|
835
|
+
aria-label={`Toggle ${layer.name}`}
|
|
807
836
|
class="scale-75"
|
|
808
837
|
/>
|
|
809
838
|
|
|
@@ -926,6 +955,7 @@
|
|
|
926
955
|
<Switch
|
|
927
956
|
checked={state.visible}
|
|
928
957
|
onchange={() => handleToggleLayer(layer.id)}
|
|
958
|
+
aria-label={`Toggle ${layer.name}`}
|
|
929
959
|
class="scale-75"
|
|
930
960
|
/>
|
|
931
961
|
|
|
@@ -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';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { onMount, onDestroy, setContext } from 'svelte';
|
|
2
|
+
import { onMount, onDestroy, setContext, untrack } from 'svelte';
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import * as maplibregl from 'maplibre-gl';
|
|
5
5
|
import maplibreStyles from 'maplibre-gl/dist/maplibre-gl.css?inline';
|
|
@@ -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,
|
|
@@ -215,6 +217,7 @@
|
|
|
215
217
|
});
|
|
216
218
|
|
|
217
219
|
map = newMap;
|
|
220
|
+
appliedView = readViewProps();
|
|
218
221
|
|
|
219
222
|
// Track style changes for layer re-initialization
|
|
220
223
|
styleLoadHandler = () => {
|
|
@@ -348,8 +351,13 @@
|
|
|
348
351
|
mapLoaded = true;
|
|
349
352
|
|
|
350
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)) };
|
|
351
358
|
newMap.fitBounds(bounds as [[number, number], [number, number]], {
|
|
352
359
|
padding: boundsPadding as number | maplibregl.PaddingOptions | undefined,
|
|
360
|
+
maxZoom: boundsMaxZoom,
|
|
353
361
|
animate: animation && !reducedMotion.value,
|
|
354
362
|
});
|
|
355
363
|
}
|
|
@@ -500,6 +508,73 @@
|
|
|
500
508
|
}
|
|
501
509
|
});
|
|
502
510
|
|
|
511
|
+
// `center`, `zoom`, `bearing` and `pitch` follow the parent after mount. A
|
|
512
|
+
// prop that changed since the last run moves the map, and only where it
|
|
513
|
+
// differs from what the map already shows: a parent that mirrors onMove
|
|
514
|
+
// back into these props then never fights the user's own panning, and an
|
|
515
|
+
// unchanged prop never snaps back a view the user moved.
|
|
516
|
+
type ViewProps = { center: LngLat; zoom: number; bearing: number; pitch: number };
|
|
517
|
+
let appliedView: ViewProps | null = null;
|
|
518
|
+
function readViewProps(): ViewProps {
|
|
519
|
+
const [lng, lat] = center as LngLat;
|
|
520
|
+
return { center: [lng, lat], zoom, bearing, pitch };
|
|
521
|
+
}
|
|
522
|
+
const angleDelta = (a: number, b: number) => Math.abs(((((a - b) % 360) + 540) % 360) - 180);
|
|
523
|
+
|
|
524
|
+
$effect(() => {
|
|
525
|
+
// Read the props before any guard, so the effect tracks them from its first run
|
|
526
|
+
const next = readViewProps();
|
|
527
|
+
if (!map || !mapLoaded) return;
|
|
528
|
+
const target = map;
|
|
529
|
+
untrack(() => {
|
|
530
|
+
const prev = appliedView;
|
|
531
|
+
appliedView = next;
|
|
532
|
+
if (!prev) return;
|
|
533
|
+
const view: { center?: LngLat; zoom?: number; bearing?: number; pitch?: number } = {};
|
|
534
|
+
const shown = target.getCenter();
|
|
535
|
+
if (
|
|
536
|
+
(next.center[0] !== prev.center[0] || next.center[1] !== prev.center[1]) &&
|
|
537
|
+
(Math.abs(shown.lng - next.center[0]) > 1e-9 || Math.abs(shown.lat - next.center[1]) > 1e-9)
|
|
538
|
+
) {
|
|
539
|
+
view.center = next.center;
|
|
540
|
+
}
|
|
541
|
+
if (next.zoom !== prev.zoom && Math.abs(target.getZoom() - next.zoom) > 1e-6) {
|
|
542
|
+
view.zoom = next.zoom;
|
|
543
|
+
}
|
|
544
|
+
if (next.bearing !== prev.bearing && angleDelta(target.getBearing(), next.bearing) > 1e-6) {
|
|
545
|
+
view.bearing = next.bearing;
|
|
546
|
+
}
|
|
547
|
+
if (next.pitch !== prev.pitch && Math.abs(target.getPitch() - next.pitch) > 1e-6) {
|
|
548
|
+
view.pitch = next.pitch;
|
|
549
|
+
}
|
|
550
|
+
if (Object.keys(view).length === 0) return;
|
|
551
|
+
if (animation && !reducedMotion.value) target.easeTo(view);
|
|
552
|
+
else target.jumpTo(view);
|
|
553
|
+
});
|
|
554
|
+
});
|
|
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
|
+
|
|
503
578
|
// Clear programmatic override when customStyle prop changes
|
|
504
579
|
$effect(() => {
|
|
505
580
|
if (customStyle) {
|
|
@@ -573,7 +648,13 @@
|
|
|
573
648
|
>
|
|
574
649
|
{#snippet children()}
|
|
575
650
|
<!-- Map canvas container -->
|
|
576
|
-
|
|
651
|
+
<!-- Inline position: MapLibre's own `.maplibregl-map { position: relative }`
|
|
652
|
+
(injected after the app stylesheet) outranks the `absolute` utility,
|
|
653
|
+
which collapses the map to 0 px high. Inline style always wins. -->
|
|
654
|
+
<div
|
|
655
|
+
bind:this={containerElement}
|
|
656
|
+
style="position: absolute; top: 0; right: 0; bottom: 0; left: 0"
|
|
657
|
+
></div>
|
|
577
658
|
{#if resourceWarning && !combinedError}
|
|
578
659
|
<div
|
|
579
660
|
class="absolute bottom-8 inset-x-14 z-30 mx-auto max-w-sm rounded border bg-card p-2 text-xs text-foreground shadow"
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
applyMarkerChildProtection,
|
|
9
9
|
removeMarkerProtection,
|
|
10
10
|
markerColor,
|
|
11
|
+
applyMarkerAccessibility,
|
|
12
|
+
handleMarkerKeydown,
|
|
11
13
|
} from '@classic-homes/maps-core';
|
|
12
14
|
import type { MapContextValue } from '../../composables/useMapContext.svelte';
|
|
13
15
|
|
|
@@ -30,6 +32,7 @@
|
|
|
30
32
|
let {
|
|
31
33
|
id,
|
|
32
34
|
coordinates,
|
|
35
|
+
label,
|
|
33
36
|
color = markerColor,
|
|
34
37
|
anchor = 'bottom',
|
|
35
38
|
offset,
|
|
@@ -82,9 +85,15 @@
|
|
|
82
85
|
markerOptions.element = markerElement;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
const newMarker = new maplibregl.Marker(markerOptions)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
const newMarker = new maplibregl.Marker(markerOptions);
|
|
89
|
+
// Before addTo: MapLibre keeps a label and role that are already set
|
|
90
|
+
applyMarkerAccessibility(newMarker.getElement(), {
|
|
91
|
+
label,
|
|
92
|
+
clickable: Boolean(onClick),
|
|
93
|
+
draggable,
|
|
94
|
+
custom: Boolean(children),
|
|
95
|
+
});
|
|
96
|
+
newMarker.setLngLat(coordinates as [number, number]).addTo(map);
|
|
88
97
|
|
|
89
98
|
// Protect against CSS framework interference that causes marker sliding
|
|
90
99
|
const el = newMarker.getElement();
|
|
@@ -167,6 +176,22 @@
|
|
|
167
176
|
};
|
|
168
177
|
});
|
|
169
178
|
|
|
179
|
+
// Accessible name, role and focus follow label, onClick and draggable
|
|
180
|
+
$effect(() => {
|
|
181
|
+
if (!marker) return;
|
|
182
|
+
const element = marker.getElement();
|
|
183
|
+
applyMarkerAccessibility(element, {
|
|
184
|
+
label,
|
|
185
|
+
clickable: Boolean(onClick),
|
|
186
|
+
draggable,
|
|
187
|
+
custom: Boolean(children),
|
|
188
|
+
});
|
|
189
|
+
if (!onClick) return;
|
|
190
|
+
// Enter and Space activate a clickable marker, as for any button
|
|
191
|
+
element.addEventListener('keydown', handleMarkerKeydown);
|
|
192
|
+
return () => element.removeEventListener('keydown', handleMarkerKeydown);
|
|
193
|
+
});
|
|
194
|
+
|
|
170
195
|
// Update position when coordinates change
|
|
171
196
|
$effect(() => {
|
|
172
197
|
if (marker && coordinates) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { getContext, onDestroy,
|
|
2
|
+
import { getContext, onDestroy, untrack } from 'svelte';
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import * as maplibregl from 'maplibre-gl';
|
|
5
5
|
import type { PopupProps } from '@classic-homes/maps-core';
|
|
@@ -51,6 +51,8 @@
|
|
|
51
51
|
let containerElement: HTMLDivElement | null = $state(null);
|
|
52
52
|
let contentElement: HTMLDivElement | null = $state(null);
|
|
53
53
|
let autoPanRafHandle: number | null = null;
|
|
54
|
+
// Removes a fit waiting for the current camera move to end
|
|
55
|
+
let pendingAutoPan: (() => void) | null = null;
|
|
54
56
|
|
|
55
57
|
// Create container for content
|
|
56
58
|
$effect(() => {
|
|
@@ -60,27 +62,52 @@
|
|
|
60
62
|
}
|
|
61
63
|
});
|
|
62
64
|
|
|
65
|
+
// MapLibre reads these options only in its constructor, so a change
|
|
66
|
+
// rebuilds the popup (an open one reopens at once, without onClose/onOpen).
|
|
67
|
+
const optionsKey = $derived(
|
|
68
|
+
JSON.stringify([closeButton, closeOnMove, anchor, offset, maxWidth, focusAfterOpen])
|
|
69
|
+
);
|
|
70
|
+
// Where the popup is shown, as last applied; plain, read by the click guard
|
|
71
|
+
let shownKey = '';
|
|
72
|
+
// Set while an open popup is torn down for a rebuild
|
|
73
|
+
let rebuildingOpen = false;
|
|
74
|
+
const keyOf = (c: unknown) => (Array.isArray(c) ? c.join(',') : JSON.stringify(c));
|
|
75
|
+
|
|
63
76
|
// Create and manage popup
|
|
64
77
|
$effect(() => {
|
|
65
78
|
const { map, loaded } = mapContext;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
void optionsKey;
|
|
80
|
+
|
|
81
|
+
if (!map || !loaded || !containerElement) return;
|
|
82
|
+
|
|
83
|
+
const element = containerElement;
|
|
84
|
+
const newPopup = untrack(
|
|
85
|
+
() =>
|
|
86
|
+
new maplibregl.Popup({
|
|
87
|
+
closeButton,
|
|
88
|
+
// Map clicks are handled below, so a click that moves the popup to
|
|
89
|
+
// another feature does not also close it
|
|
90
|
+
closeOnClick: false,
|
|
91
|
+
closeOnMove,
|
|
92
|
+
anchor: anchor as Anchor | undefined,
|
|
93
|
+
offset: offset as number | maplibregl.PointLike | undefined,
|
|
94
|
+
maxWidth,
|
|
95
|
+
focusAfterOpen,
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
newPopup.setDOMContent(element);
|
|
100
|
+
// A rebuild of an open popup reopens it: not a new open for the caller
|
|
101
|
+
let silent = rebuildingOpen;
|
|
102
|
+
rebuildingOpen = false;
|
|
103
|
+
let tearingDown = false;
|
|
81
104
|
|
|
82
105
|
// Event handlers
|
|
83
106
|
newPopup.on('open', () => {
|
|
107
|
+
if (silent) {
|
|
108
|
+
silent = false;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
84
111
|
onOpen?.({
|
|
85
112
|
type: 'open',
|
|
86
113
|
lngLat: coordinates,
|
|
@@ -88,20 +115,52 @@
|
|
|
88
115
|
});
|
|
89
116
|
|
|
90
117
|
newPopup.on('close', () => {
|
|
118
|
+
if (tearingDown) return;
|
|
91
119
|
onClose?.({
|
|
92
120
|
type: 'close',
|
|
93
121
|
lngLat: coordinates,
|
|
94
122
|
});
|
|
95
123
|
});
|
|
124
|
+
|
|
125
|
+
popup = newPopup;
|
|
126
|
+
|
|
127
|
+
return () => {
|
|
128
|
+
tearingDown = true;
|
|
129
|
+
rebuildingOpen = newPopup.isOpen();
|
|
130
|
+
newPopup.remove();
|
|
131
|
+
if (untrack(() => popup) === newPopup) popup = null;
|
|
132
|
+
};
|
|
96
133
|
});
|
|
97
134
|
|
|
98
135
|
// Update popup position
|
|
99
136
|
$effect(() => {
|
|
100
137
|
if (popup && coordinates) {
|
|
101
138
|
popup.setLngLat(coordinates as [number, number]);
|
|
139
|
+
shownKey = keyOf(coordinates);
|
|
102
140
|
}
|
|
103
141
|
});
|
|
104
142
|
|
|
143
|
+
// closeOnClick: a map click closes the popup once the click's own handlers
|
|
144
|
+
// have run, unless one of them moved the popup (a click on another feature
|
|
145
|
+
// that the caller shows in this popup)
|
|
146
|
+
$effect(() => {
|
|
147
|
+
const { map } = mapContext;
|
|
148
|
+
const target = popup;
|
|
149
|
+
if (!map || !target || typeof map.on !== 'function') return;
|
|
150
|
+
const onMapClick = () => {
|
|
151
|
+
if (!closeOnClick || !target.isOpen()) return;
|
|
152
|
+
const before = shownKey;
|
|
153
|
+
setTimeout(() => {
|
|
154
|
+
if (popup !== target || !target.isOpen() || shownKey !== before) return;
|
|
155
|
+
target.remove();
|
|
156
|
+
}, 0);
|
|
157
|
+
};
|
|
158
|
+
map.on('click', onMapClick);
|
|
159
|
+
return () => {
|
|
160
|
+
map.off('click', onMapClick);
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
|
|
105
164
|
// Open/close popup
|
|
106
165
|
$effect(() => {
|
|
107
166
|
const { map } = mapContext;
|
|
@@ -110,6 +169,7 @@
|
|
|
110
169
|
|
|
111
170
|
if (open) {
|
|
112
171
|
popup.setLngLat(coordinates as [number, number]);
|
|
172
|
+
shownKey = keyOf(coordinates);
|
|
113
173
|
// addTo() removes an existing attachment and emits close. Coordinate or
|
|
114
174
|
// callback updates must move the current popup without clearing selection.
|
|
115
175
|
if (!popup.isOpen()) popup.addTo(map);
|
|
@@ -123,8 +183,21 @@
|
|
|
123
183
|
// Wait for popup to render before measuring
|
|
124
184
|
autoPanRafHandle = requestAnimationFrame(() => {
|
|
125
185
|
autoPanRafHandle = null;
|
|
126
|
-
|
|
127
|
-
|
|
186
|
+
const target = popup;
|
|
187
|
+
if (!target || !map) return;
|
|
188
|
+
const pan = () => {
|
|
189
|
+
if (popup === target && target.isOpen()) {
|
|
190
|
+
panToFitPopup(map, target, normalizePadding(autoPanPadding));
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
// A pan now would cancel a camera move already under way (the
|
|
194
|
+
// caller moving the map to the popup's spot): fit once it lands
|
|
195
|
+
if (typeof map.isMoving === 'function' && map.isMoving()) {
|
|
196
|
+
pendingAutoPan?.();
|
|
197
|
+
map.once('moveend', pan);
|
|
198
|
+
pendingAutoPan = () => map.off('moveend', pan);
|
|
199
|
+
} else {
|
|
200
|
+
pan();
|
|
128
201
|
}
|
|
129
202
|
});
|
|
130
203
|
}
|
|
@@ -149,11 +222,8 @@
|
|
|
149
222
|
cancelAnimationFrame(autoPanRafHandle);
|
|
150
223
|
autoPanRafHandle = null;
|
|
151
224
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
popup.remove();
|
|
155
|
-
popup = null;
|
|
156
|
-
}
|
|
225
|
+
pendingAutoPan?.();
|
|
226
|
+
pendingAutoPan = null;
|
|
157
227
|
});
|
|
158
228
|
</script>
|
|
159
229
|
|
|
@@ -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';
|
|
@@ -432,6 +432,18 @@ export function useLayer(getOptions) {
|
|
|
432
432
|
map.on('mousemove', id, handleMouseMove);
|
|
433
433
|
map.on('mouseleave', id, handleMouseLeave);
|
|
434
434
|
}
|
|
435
|
+
// A click-only layer still shows it is clickable
|
|
436
|
+
const pointerOn = () => {
|
|
437
|
+
map.getCanvas().style.cursor = 'pointer';
|
|
438
|
+
};
|
|
439
|
+
const pointerOff = () => {
|
|
440
|
+
map.getCanvas().style.cursor = '';
|
|
441
|
+
};
|
|
442
|
+
const clickOnly = Boolean(onClick) && !onHover;
|
|
443
|
+
if (clickOnly) {
|
|
444
|
+
map.on('mouseenter', id, pointerOn);
|
|
445
|
+
map.on('mouseleave', id, pointerOff);
|
|
446
|
+
}
|
|
435
447
|
// Return cleanup function to remove all handlers
|
|
436
448
|
return () => {
|
|
437
449
|
if (onClick) {
|
|
@@ -442,6 +454,10 @@ export function useLayer(getOptions) {
|
|
|
442
454
|
map.off('mousemove', id, handleMouseMove);
|
|
443
455
|
map.off('mouseleave', id, handleMouseLeave);
|
|
444
456
|
}
|
|
457
|
+
if (clickOnly) {
|
|
458
|
+
map.off('mouseenter', id, pointerOn);
|
|
459
|
+
map.off('mouseleave', id, pointerOff);
|
|
460
|
+
}
|
|
445
461
|
};
|
|
446
462
|
}
|
|
447
463
|
// Cleanup on destroy (the handler effect detaches its handlers itself)
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -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
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
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';
|
|
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
|
|
@@ -24,7 +24,7 @@ export { CATEGORY_META, SCHOOL_DISTRICTS, CITY_LIMITS, ZONING_DISTRICTS, PARKS,
|
|
|
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.
|
|
3
|
+
"version": "0.10.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.
|
|
40
|
+
"@classic-homes/maps-core": "^0.10.0",
|
|
41
41
|
"@classic-homes/theme-svelte": "*",
|
|
42
42
|
"@classic-homes/theme-tokens": "*",
|
|
43
43
|
"clsx": "^2.1.0",
|