@classic-homes/maps-svelte 0.1.1

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.
Files changed (72) hide show
  1. package/README.md +432 -0
  2. package/dist/lib/components/base/MapContainer.svelte +68 -0
  3. package/dist/lib/components/base/MapContainer.svelte.d.ts +18 -0
  4. package/dist/lib/components/base/MapEmpty.svelte +42 -0
  5. package/dist/lib/components/base/MapEmpty.svelte.d.ts +8 -0
  6. package/dist/lib/components/base/MapError.svelte +54 -0
  7. package/dist/lib/components/base/MapError.svelte.d.ts +9 -0
  8. package/dist/lib/components/base/MapSkeleton.svelte +45 -0
  9. package/dist/lib/components/base/MapSkeleton.svelte.d.ts +7 -0
  10. package/dist/lib/components/base/index.d.ts +4 -0
  11. package/dist/lib/components/base/index.js +4 -0
  12. package/dist/lib/components/controls/CoordinateDisplay.svelte +163 -0
  13. package/dist/lib/components/controls/CoordinateDisplay.svelte.d.ts +6 -0
  14. package/dist/lib/components/controls/Legend.svelte +179 -0
  15. package/dist/lib/components/controls/Legend.svelte.d.ts +6 -0
  16. package/dist/lib/components/controls/LegendGroup.svelte +216 -0
  17. package/dist/lib/components/controls/LegendGroup.svelte.d.ts +6 -0
  18. package/dist/lib/components/controls/index.d.ts +3 -0
  19. package/dist/lib/components/controls/index.js +3 -0
  20. package/dist/lib/components/core/Map.svelte +434 -0
  21. package/dist/lib/components/core/Map.svelte.d.ts +11 -0
  22. package/dist/lib/components/core/Marker.svelte +185 -0
  23. package/dist/lib/components/core/Marker.svelte.d.ts +9 -0
  24. package/dist/lib/components/core/Popup.svelte +205 -0
  25. package/dist/lib/components/core/Popup.svelte.d.ts +11 -0
  26. package/dist/lib/components/core/PopupCard.svelte +17 -0
  27. package/dist/lib/components/core/PopupCard.svelte.d.ts +10 -0
  28. package/dist/lib/components/core/PopupContent.svelte +17 -0
  29. package/dist/lib/components/core/PopupContent.svelte.d.ts +10 -0
  30. package/dist/lib/components/core/PopupFooter.svelte +22 -0
  31. package/dist/lib/components/core/PopupFooter.svelte.d.ts +10 -0
  32. package/dist/lib/components/core/PopupHeader.svelte +45 -0
  33. package/dist/lib/components/core/PopupHeader.svelte.d.ts +14 -0
  34. package/dist/lib/components/core/Source.svelte +326 -0
  35. package/dist/lib/components/core/Source.svelte.d.ts +59 -0
  36. package/dist/lib/components/core/index.d.ts +8 -0
  37. package/dist/lib/components/core/index.js +8 -0
  38. package/dist/lib/components/deck/DeckOverlay.svelte +135 -0
  39. package/dist/lib/components/deck/DeckOverlay.svelte.d.ts +25 -0
  40. package/dist/lib/components/deck/index.d.ts +1 -0
  41. package/dist/lib/components/deck/index.js +1 -0
  42. package/dist/lib/components/index.d.ts +5 -0
  43. package/dist/lib/components/index.js +10 -0
  44. package/dist/lib/components/layers/CircleLayer.svelte +78 -0
  45. package/dist/lib/components/layers/CircleLayer.svelte.d.ts +11 -0
  46. package/dist/lib/components/layers/FillExtrusionLayer.svelte +75 -0
  47. package/dist/lib/components/layers/FillExtrusionLayer.svelte.d.ts +11 -0
  48. package/dist/lib/components/layers/FillLayer.svelte +70 -0
  49. package/dist/lib/components/layers/FillLayer.svelte.d.ts +11 -0
  50. package/dist/lib/components/layers/HeatmapLayer.svelte +68 -0
  51. package/dist/lib/components/layers/HeatmapLayer.svelte.d.ts +11 -0
  52. package/dist/lib/components/layers/LineLayer.svelte +81 -0
  53. package/dist/lib/components/layers/LineLayer.svelte.d.ts +11 -0
  54. package/dist/lib/components/layers/SymbolLayer.svelte +108 -0
  55. package/dist/lib/components/layers/SymbolLayer.svelte.d.ts +11 -0
  56. package/dist/lib/components/layers/index.d.ts +7 -0
  57. package/dist/lib/components/layers/index.js +6 -0
  58. package/dist/lib/components/layers/useLayer.svelte.d.ts +38 -0
  59. package/dist/lib/components/layers/useLayer.svelte.js +286 -0
  60. package/dist/lib/composables/index.d.ts +3 -0
  61. package/dist/lib/composables/index.js +3 -0
  62. package/dist/lib/composables/useMapContext.svelte.d.ts +62 -0
  63. package/dist/lib/composables/useMapContext.svelte.js +58 -0
  64. package/dist/lib/composables/useMapTheme.svelte.d.ts +11 -0
  65. package/dist/lib/composables/useMapTheme.svelte.js +66 -0
  66. package/dist/lib/composables/useReducedMotion.svelte.d.ts +6 -0
  67. package/dist/lib/composables/useReducedMotion.svelte.js +26 -0
  68. package/dist/lib/index.d.ts +12 -0
  69. package/dist/lib/index.js +29 -0
  70. package/dist/lib/utils.d.ts +2 -0
  71. package/dist/lib/utils.js +5 -0
  72. package/package.json +75 -0
@@ -0,0 +1,434 @@
1
+ <script lang="ts">
2
+ import { onMount, onDestroy, setContext } from 'svelte';
3
+ import type { Snippet } from 'svelte';
4
+ import maplibregl from 'maplibre-gl';
5
+ import 'maplibre-gl/dist/maplibre-gl.css';
6
+ import '@classic-homes/maps-core/styles/controls.css';
7
+
8
+ import type {
9
+ MapProps,
10
+ MapClickEventParams,
11
+ MapHoverEventParams,
12
+ MapMoveEventParams,
13
+ LngLat,
14
+ } from '@classic-homes/maps-core';
15
+ import { generateMapDescription } from '@classic-homes/maps-core';
16
+
17
+ import { cn } from '../../utils.js';
18
+ import { useMapTheme } from '../../composables/useMapTheme.svelte.js';
19
+ import { useReducedMotion } from '../../composables/useReducedMotion.svelte.js';
20
+ import MapContainer from '../base/MapContainer.svelte';
21
+
22
+ interface Props extends Omit<MapProps, 'class'> {
23
+ class?: string;
24
+ children?: Snippet;
25
+ }
26
+
27
+ let {
28
+ // Base props
29
+ title,
30
+ description,
31
+ width,
32
+ height = 400,
33
+ loading,
34
+ error,
35
+ emptyMessage,
36
+ theme: themePref = 'auto',
37
+ animation = true,
38
+ class: className,
39
+ children,
40
+
41
+ // Map props
42
+ style: customStyle,
43
+ center = [0, 0],
44
+ zoom = 2,
45
+ bearing = 0,
46
+ pitch = 0,
47
+ bounds,
48
+ boundsPadding,
49
+ minZoom,
50
+ maxZoom,
51
+ maxBounds,
52
+ interactive = true,
53
+ scrollZoom = true,
54
+ dragPan = true,
55
+ dragRotate = true,
56
+ doubleClickZoom = true,
57
+ touchZoomRotate = true,
58
+ keyboard = true,
59
+ attributionControl = true,
60
+ customAttribution,
61
+ navigationControl = true,
62
+ navigationControlPosition = 'top-right',
63
+ scaleControl = false,
64
+ scaleControlPosition = 'bottom-left',
65
+ fullscreenControl = false,
66
+ fullscreenControlPosition = 'top-right',
67
+ geolocateControl = false,
68
+ geolocateControlPosition = 'top-right',
69
+
70
+ // Callbacks
71
+ onLoad,
72
+ onClick,
73
+ onDblClick,
74
+ onContextMenu,
75
+ onMouseMove,
76
+ onMove,
77
+ onMoveStart,
78
+ onMoveEnd,
79
+ onZoom,
80
+ onError,
81
+ }: Props = $props();
82
+
83
+ let containerElement: HTMLDivElement;
84
+ let map: maplibregl.Map | null = $state(null);
85
+ let mapLoaded = $state(false);
86
+ let mapError = $state<string | null>(null);
87
+
88
+ // Registry for custom controls to coordinate positioning
89
+ // Each entry tracks controls at a position with their heights
90
+ type ControlEntry = { id: string; height: number };
91
+ const customControlRegistry = $state<Record<string, ControlEntry[]>>({
92
+ 'top-left': [],
93
+ 'top-right': [],
94
+ 'bottom-left': [],
95
+ 'bottom-right': [],
96
+ });
97
+
98
+ // Register a custom control and return its vertical offset
99
+ function registerControl(id: string, position: string, height: number): number {
100
+ const positionControls = customControlRegistry[position] || [];
101
+
102
+ // Check if already registered
103
+ const existingIndex = positionControls.findIndex((c) => c.id === id);
104
+ if (existingIndex >= 0) {
105
+ positionControls[existingIndex].height = height;
106
+ } else {
107
+ positionControls.push({ id, height });
108
+ }
109
+ customControlRegistry[position] = positionControls;
110
+
111
+ // Calculate offset (sum of heights of controls before this one)
112
+ let offset = 0;
113
+ for (const control of positionControls) {
114
+ if (control.id === id) break;
115
+ offset += control.height + 8; // 8px gap between controls
116
+ }
117
+ return offset;
118
+ }
119
+
120
+ // Unregister a custom control
121
+ function unregisterControl(id: string, position: string): void {
122
+ const positionControls = customControlRegistry[position] || [];
123
+ customControlRegistry[position] = positionControls.filter((c) => c.id !== id);
124
+ }
125
+
126
+ // Get offset for a control at a position
127
+ function getCustomControlOffset(id: string, position: string): number {
128
+ const positionControls = customControlRegistry[position] || [];
129
+ let offset = 0;
130
+ for (const control of positionControls) {
131
+ if (control.id === id) break;
132
+ offset += control.height + 8;
133
+ }
134
+ return offset;
135
+ }
136
+
137
+ const reducedMotion = useReducedMotion();
138
+ const themeState = useMapTheme(() => themePref);
139
+
140
+ // Use custom style or theme style
141
+ const mapStyle = $derived(customStyle || themeState.style);
142
+
143
+ // Generate accessible description if not provided
144
+ const accessibleDescription = $derived(
145
+ description ||
146
+ generateMapDescription(title, {
147
+ center: center as LngLat,
148
+ zoom,
149
+ })
150
+ );
151
+
152
+ // Calculate control offsets for each position
153
+ // MapLibre controls are ~29px per button with ~5px margin
154
+ const controlOffsets = $derived(() => {
155
+ const offsets: Record<string, number> = {
156
+ 'top-left': 0,
157
+ 'top-right': 0,
158
+ 'bottom-left': 0,
159
+ 'bottom-right': 0,
160
+ };
161
+
162
+ // Navigation control is ~91px (3 buttons)
163
+ if (navigationControl) {
164
+ offsets[navigationControlPosition] += 100;
165
+ }
166
+
167
+ // Scale control is ~28px
168
+ if (scaleControl) {
169
+ offsets[scaleControlPosition] += 28;
170
+ }
171
+
172
+ // Fullscreen control is ~29px
173
+ if (fullscreenControl) {
174
+ offsets[fullscreenControlPosition] += 38;
175
+ }
176
+
177
+ // Geolocate control is ~29px
178
+ if (geolocateControl) {
179
+ offsets[geolocateControlPosition] += 38;
180
+ }
181
+
182
+ return offsets;
183
+ });
184
+
185
+ // Set context for child components
186
+ setContext('maplibre-map', {
187
+ get map() {
188
+ return map;
189
+ },
190
+ get loaded() {
191
+ return mapLoaded;
192
+ },
193
+ get controlOffsets() {
194
+ return controlOffsets();
195
+ },
196
+ registerControl,
197
+ unregisterControl,
198
+ getCustomControlOffset,
199
+ });
200
+
201
+ const combinedError = $derived(error || mapError);
202
+
203
+ onMount(() => {
204
+ if (!containerElement) return;
205
+
206
+ try {
207
+ const newMap = new maplibregl.Map({
208
+ container: containerElement,
209
+ style: mapStyle as maplibregl.StyleSpecification | string,
210
+ center: center as [number, number],
211
+ zoom,
212
+ bearing,
213
+ pitch,
214
+ minZoom,
215
+ maxZoom,
216
+ maxBounds: maxBounds as [[number, number], [number, number]] | undefined,
217
+ interactive,
218
+ scrollZoom,
219
+ dragPan,
220
+ dragRotate,
221
+ doubleClickZoom,
222
+ touchZoomRotate,
223
+ keyboard,
224
+ attributionControl: attributionControl ? { customAttribution } : false,
225
+ });
226
+
227
+ map = newMap;
228
+
229
+ // Add controls
230
+ if (navigationControl) {
231
+ newMap.addControl(
232
+ new maplibregl.NavigationControl({
233
+ showCompass: true,
234
+ showZoom: true,
235
+ visualizePitch: true,
236
+ }),
237
+ navigationControlPosition
238
+ );
239
+ }
240
+
241
+ if (scaleControl) {
242
+ newMap.addControl(new maplibregl.ScaleControl({ unit: 'metric' }), scaleControlPosition);
243
+ }
244
+
245
+ if (fullscreenControl) {
246
+ newMap.addControl(new maplibregl.FullscreenControl(), fullscreenControlPosition);
247
+ }
248
+
249
+ if (geolocateControl) {
250
+ newMap.addControl(
251
+ new maplibregl.GeolocateControl({
252
+ positionOptions: { enableHighAccuracy: true },
253
+ trackUserLocation: true,
254
+ }),
255
+ geolocateControlPosition
256
+ );
257
+ }
258
+
259
+ // Map load handler
260
+ newMap.on('load', () => {
261
+ mapLoaded = true;
262
+
263
+ if (bounds) {
264
+ newMap.fitBounds(bounds as [[number, number], [number, number]], {
265
+ padding: boundsPadding as number | maplibregl.PaddingOptions | undefined,
266
+ animate: animation && !reducedMotion.value,
267
+ });
268
+ }
269
+
270
+ onLoad?.({ type: 'load', loaded: true });
271
+ });
272
+
273
+ // Error handler
274
+ newMap.on('error', (e) => {
275
+ const errorMessage = e.error?.message || 'Map error';
276
+ mapError = errorMessage;
277
+ onError?.({ type: 'error', message: errorMessage, error: e.error });
278
+ });
279
+
280
+ // Event helpers
281
+ const createEventParams = (e: maplibregl.MapMouseEvent) => ({
282
+ lngLat: [e.lngLat.lng, e.lngLat.lat] as LngLat,
283
+ point: [e.point.x, e.point.y] as [number, number],
284
+ originalEvent: e.originalEvent,
285
+ });
286
+
287
+ const createMoveParams = () => {
288
+ const mapBounds = newMap.getBounds();
289
+ return {
290
+ center: [newMap.getCenter().lng, newMap.getCenter().lat] as LngLat,
291
+ zoom: newMap.getZoom(),
292
+ bearing: newMap.getBearing(),
293
+ pitch: newMap.getPitch(),
294
+ bounds: {
295
+ southwest: [mapBounds.getSouthWest().lng, mapBounds.getSouthWest().lat] as LngLat,
296
+ northeast: [mapBounds.getNorthEast().lng, mapBounds.getNorthEast().lat] as LngLat,
297
+ },
298
+ };
299
+ };
300
+
301
+ // Click handlers
302
+ if (onClick) {
303
+ newMap.on('click', (e) => {
304
+ onClick({
305
+ type: 'click',
306
+ ...createEventParams(e),
307
+ features: newMap.queryRenderedFeatures(
308
+ e.point
309
+ ) as unknown as MapClickEventParams['features'],
310
+ });
311
+ });
312
+ }
313
+
314
+ if (onDblClick) {
315
+ newMap.on('dblclick', (e) => {
316
+ onDblClick({
317
+ type: 'dblclick',
318
+ ...createEventParams(e),
319
+ features: newMap.queryRenderedFeatures(
320
+ e.point
321
+ ) as unknown as MapClickEventParams['features'],
322
+ });
323
+ });
324
+ }
325
+
326
+ if (onContextMenu) {
327
+ newMap.on('contextmenu', (e) => {
328
+ onContextMenu({
329
+ type: 'contextmenu',
330
+ ...createEventParams(e),
331
+ features: newMap.queryRenderedFeatures(
332
+ e.point
333
+ ) as unknown as MapClickEventParams['features'],
334
+ });
335
+ });
336
+ }
337
+
338
+ if (onMouseMove) {
339
+ newMap.on('mousemove', (e) => {
340
+ onMouseMove({
341
+ type: 'mousemove',
342
+ ...createEventParams(e),
343
+ features: newMap.queryRenderedFeatures(
344
+ e.point
345
+ ) as unknown as MapHoverEventParams['features'],
346
+ });
347
+ });
348
+ }
349
+
350
+ if (onMove) {
351
+ newMap.on('move', () => {
352
+ onMove({ type: 'move', ...createMoveParams() } as MapMoveEventParams);
353
+ });
354
+ }
355
+
356
+ if (onMoveStart) {
357
+ newMap.on('movestart', () => {
358
+ onMoveStart({ type: 'movestart', ...createMoveParams() } as MapMoveEventParams);
359
+ });
360
+ }
361
+
362
+ if (onMoveEnd) {
363
+ newMap.on('moveend', () => {
364
+ onMoveEnd({ type: 'moveend', ...createMoveParams() } as MapMoveEventParams);
365
+ });
366
+ }
367
+
368
+ if (onZoom) {
369
+ newMap.on('zoom', () => {
370
+ onZoom({ type: 'zoom', ...createMoveParams() } as MapMoveEventParams);
371
+ });
372
+ }
373
+ } catch (err) {
374
+ const errorMessage = err instanceof Error ? err.message : 'Failed to initialize map';
375
+ mapError = errorMessage;
376
+ onError?.({ type: 'error', message: errorMessage, error: err as Error });
377
+ }
378
+ });
379
+
380
+ // Track initial style to avoid unnecessary setStyle calls
381
+ let initialStyleApplied = $state(false);
382
+ let lastAppliedStyle: string | null = $state(null);
383
+
384
+ // Update style when theme changes (but not on initial load)
385
+ $effect(() => {
386
+ if (!map || !mapLoaded || !mapStyle) return;
387
+
388
+ // Get a comparable string representation of the style
389
+ const styleKey = typeof mapStyle === 'string' ? mapStyle : JSON.stringify(mapStyle);
390
+
391
+ // Skip if this is the initial style application (already applied via constructor)
392
+ if (!initialStyleApplied) {
393
+ initialStyleApplied = true;
394
+ lastAppliedStyle = styleKey;
395
+ return;
396
+ }
397
+
398
+ // Only update if style actually changed
399
+ if (styleKey !== lastAppliedStyle) {
400
+ lastAppliedStyle = styleKey;
401
+ map.setStyle(mapStyle as maplibregl.StyleSpecification | string);
402
+ }
403
+ });
404
+
405
+ onDestroy(() => {
406
+ if (map) {
407
+ map.remove();
408
+ map = null;
409
+ mapLoaded = false;
410
+ }
411
+ });
412
+ </script>
413
+
414
+ <MapContainer
415
+ {title}
416
+ description={accessibleDescription}
417
+ {height}
418
+ {width}
419
+ {loading}
420
+ error={combinedError}
421
+ {emptyMessage}
422
+ class={className}
423
+ >
424
+ {#snippet children()}
425
+ <!-- Map canvas container -->
426
+ <div bind:this={containerElement} class="absolute inset-0"></div>
427
+ <!-- Custom controls overlay - positioned above map canvas -->
428
+ {#if mapLoaded && children}
429
+ <div class="absolute inset-0 pointer-events-none [&>*]:pointer-events-auto">
430
+ {@render children()}
431
+ </div>
432
+ {/if}
433
+ {/snippet}
434
+ </MapContainer>
@@ -0,0 +1,11 @@
1
+ import type { Snippet } from 'svelte';
2
+ import 'maplibre-gl/dist/maplibre-gl.css';
3
+ import '@classic-homes/maps-core/styles/controls.css';
4
+ import type { MapProps } from '@classic-homes/maps-core';
5
+ interface Props extends Omit<MapProps, 'class'> {
6
+ class?: string;
7
+ children?: Snippet;
8
+ }
9
+ declare const Map: import("svelte").Component<Props, {}, "">;
10
+ type Map = ReturnType<typeof Map>;
11
+ export default Map;
@@ -0,0 +1,185 @@
1
+ <script lang="ts">
2
+ import { getContext, onDestroy } from 'svelte';
3
+ import type { Snippet } from 'svelte';
4
+ import maplibregl from 'maplibre-gl';
5
+ import type { MarkerProps, LngLat } from '@classic-homes/maps-core';
6
+
7
+ type Anchor =
8
+ | 'center'
9
+ | 'top'
10
+ | 'bottom'
11
+ | 'left'
12
+ | 'right'
13
+ | 'top-left'
14
+ | 'top-right'
15
+ | 'bottom-left'
16
+ | 'bottom-right';
17
+
18
+ interface MapContext {
19
+ readonly map: maplibregl.Map | null;
20
+ readonly loaded: boolean;
21
+ }
22
+
23
+ interface Props extends MarkerProps {
24
+ /** Custom marker content */
25
+ children?: Snippet;
26
+ }
27
+
28
+ let {
29
+ id,
30
+ coordinates,
31
+ color = '#3ba4a7',
32
+ anchor = 'bottom',
33
+ offset,
34
+ rotation,
35
+ draggable = false,
36
+ scale = 1,
37
+ onClick,
38
+ onDrag,
39
+ onDragEnd,
40
+ children,
41
+ }: Props = $props();
42
+
43
+ const mapContext = getContext<MapContext>('maplibre-map');
44
+
45
+ let marker: maplibregl.Marker | null = $state(null);
46
+ let markerElement: HTMLDivElement | null = $state(null);
47
+ let contentRef: HTMLDivElement | null = $state(null);
48
+ let originalLngLat: LngLat | undefined;
49
+ let clickHandler: ((e: MouseEvent) => void) | null = null;
50
+
51
+ // Create custom element for children
52
+ $effect(() => {
53
+ if (children && !markerElement) {
54
+ markerElement = document.createElement('div');
55
+ }
56
+ });
57
+
58
+ // Create and add marker
59
+ $effect(() => {
60
+ const { map, loaded } = mapContext;
61
+
62
+ if (!map || !loaded || marker) return;
63
+
64
+ const markerOptions: maplibregl.MarkerOptions = {
65
+ color: children ? undefined : color,
66
+ anchor: anchor as Anchor,
67
+ draggable,
68
+ scale,
69
+ };
70
+
71
+ if (offset) {
72
+ markerOptions.offset = offset;
73
+ }
74
+
75
+ if (rotation !== undefined) {
76
+ markerOptions.rotation = rotation;
77
+ }
78
+
79
+ if (children && markerElement) {
80
+ markerOptions.element = markerElement;
81
+ }
82
+
83
+ const newMarker = new maplibregl.Marker(markerOptions)
84
+ .setLngLat(coordinates as [number, number])
85
+ .addTo(map);
86
+
87
+ marker = newMarker;
88
+
89
+ // Click handler
90
+ if (onClick) {
91
+ const element = newMarker.getElement();
92
+ clickHandler = (e: MouseEvent) => {
93
+ e.stopPropagation();
94
+ const lngLat = newMarker.getLngLat();
95
+ onClick({
96
+ type: 'click',
97
+ markerId: id || '',
98
+ lngLat: [lngLat.lng, lngLat.lat] as LngLat,
99
+ originalEvent: e,
100
+ });
101
+ };
102
+ element.addEventListener('click', clickHandler);
103
+ }
104
+
105
+ // Drag handlers
106
+ if (draggable) {
107
+ newMarker.on('dragstart', () => {
108
+ const lngLat = newMarker.getLngLat();
109
+ originalLngLat = [lngLat.lng, lngLat.lat] as LngLat;
110
+ });
111
+
112
+ newMarker.on('drag', () => {
113
+ if (onDrag) {
114
+ const lngLat = newMarker.getLngLat();
115
+ onDrag({
116
+ type: 'drag',
117
+ markerId: id || '',
118
+ lngLat: [lngLat.lng, lngLat.lat] as LngLat,
119
+ originalLngLat,
120
+ });
121
+ }
122
+ });
123
+
124
+ newMarker.on('dragend', () => {
125
+ if (onDragEnd) {
126
+ const lngLat = newMarker.getLngLat();
127
+ onDragEnd({
128
+ type: 'dragend',
129
+ markerId: id || '',
130
+ lngLat: [lngLat.lng, lngLat.lat] as LngLat,
131
+ originalLngLat,
132
+ });
133
+ }
134
+ });
135
+ }
136
+ });
137
+
138
+ // Update position when coordinates change
139
+ $effect(() => {
140
+ if (marker && coordinates) {
141
+ marker.setLngLat(coordinates as [number, number]);
142
+ }
143
+ });
144
+
145
+ // Update draggable state
146
+ $effect(() => {
147
+ if (marker) {
148
+ marker.setDraggable(draggable);
149
+ }
150
+ });
151
+
152
+ // Update rotation
153
+ $effect(() => {
154
+ if (marker && rotation !== undefined) {
155
+ marker.setRotation(rotation);
156
+ }
157
+ });
158
+
159
+ // Move rendered children content into markerElement for MapLibre
160
+ $effect(() => {
161
+ if (contentRef && markerElement && children) {
162
+ // Move content into the marker element that MapLibre uses
163
+ markerElement.replaceChildren(contentRef);
164
+ }
165
+ });
166
+
167
+ // Cleanup on destroy
168
+ onDestroy(() => {
169
+ if (marker) {
170
+ // Remove click handler to prevent memory leaks
171
+ if (clickHandler) {
172
+ marker.getElement().removeEventListener('click', clickHandler);
173
+ clickHandler = null;
174
+ }
175
+ marker.remove();
176
+ marker = null;
177
+ }
178
+ });
179
+ </script>
180
+
181
+ {#if children && markerElement}
182
+ <div bind:this={contentRef} style="display: contents;">
183
+ {@render children()}
184
+ </div>
185
+ {/if}
@@ -0,0 +1,9 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { MarkerProps } from '@classic-homes/maps-core';
3
+ interface Props extends MarkerProps {
4
+ /** Custom marker content */
5
+ children?: Snippet;
6
+ }
7
+ declare const Marker: import("svelte").Component<Props, {}, "">;
8
+ type Marker = ReturnType<typeof Marker>;
9
+ export default Marker;