maplibrex-svelte 0.1.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/LICENSE +21 -0
- package/README.md +300 -0
- package/dist/components/MapLibre.svelte +258 -0
- package/dist/components/MapLibre.svelte.d.ts +42 -0
- package/dist/components/controls/AttributionControl.svelte +21 -0
- package/dist/components/controls/AttributionControl.svelte.d.ts +11 -0
- package/dist/components/controls/Control.svelte +58 -0
- package/dist/components/controls/Control.svelte.d.ts +33 -0
- package/dist/components/controls/CustomControl.svelte +46 -0
- package/dist/components/controls/CustomControl.svelte.d.ts +13 -0
- package/dist/components/controls/FullscreenControl.svelte +32 -0
- package/dist/components/controls/FullscreenControl.svelte.d.ts +12 -0
- package/dist/components/controls/GeolocateControl.svelte +32 -0
- package/dist/components/controls/GeolocateControl.svelte.d.ts +12 -0
- package/dist/components/controls/GlobeControl.svelte +16 -0
- package/dist/components/controls/GlobeControl.svelte.d.ts +11 -0
- package/dist/components/controls/LogoControl.svelte +21 -0
- package/dist/components/controls/LogoControl.svelte.d.ts +11 -0
- package/dist/components/controls/NavigationControl.svelte +21 -0
- package/dist/components/controls/NavigationControl.svelte.d.ts +11 -0
- package/dist/components/controls/ScaleControl.svelte +21 -0
- package/dist/components/controls/ScaleControl.svelte.d.ts +11 -0
- package/dist/components/controls/TerrainControl.svelte +21 -0
- package/dist/components/controls/TerrainControl.svelte.d.ts +11 -0
- package/dist/components/data/FeatureState.svelte +56 -0
- package/dist/components/data/FeatureState.svelte.d.ts +13 -0
- package/dist/components/data/Protocol.svelte +24 -0
- package/dist/components/data/Protocol.svelte.d.ts +9 -0
- package/dist/components/layers/BackgroundLayer.svelte +21 -0
- package/dist/components/layers/BackgroundLayer.svelte.d.ts +17 -0
- package/dist/components/layers/CircleLayer.svelte +25 -0
- package/dist/components/layers/CircleLayer.svelte.d.ts +21 -0
- package/dist/components/layers/ColorReliefLayer.svelte +25 -0
- package/dist/components/layers/ColorReliefLayer.svelte.d.ts +21 -0
- package/dist/components/layers/CustomLayer.svelte +35 -0
- package/dist/components/layers/CustomLayer.svelte.d.ts +13 -0
- package/dist/components/layers/FillExtrusionLayer.svelte +25 -0
- package/dist/components/layers/FillExtrusionLayer.svelte.d.ts +21 -0
- package/dist/components/layers/FillLayer.svelte +25 -0
- package/dist/components/layers/FillLayer.svelte.d.ts +21 -0
- package/dist/components/layers/HeatmapLayer.svelte +25 -0
- package/dist/components/layers/HeatmapLayer.svelte.d.ts +21 -0
- package/dist/components/layers/HillshadeLayer.svelte +25 -0
- package/dist/components/layers/HillshadeLayer.svelte.d.ts +21 -0
- package/dist/components/layers/Layer.svelte +204 -0
- package/dist/components/layers/Layer.svelte.d.ts +29 -0
- package/dist/components/layers/LineLayer.svelte +25 -0
- package/dist/components/layers/LineLayer.svelte.d.ts +21 -0
- package/dist/components/layers/RasterLayer.svelte +25 -0
- package/dist/components/layers/RasterLayer.svelte.d.ts +21 -0
- package/dist/components/layers/SymbolLayer.svelte +25 -0
- package/dist/components/layers/SymbolLayer.svelte.d.ts +21 -0
- package/dist/components/overlays/Marker.svelte +204 -0
- package/dist/components/overlays/Marker.svelte.d.ts +27 -0
- package/dist/components/overlays/Popup.svelte +184 -0
- package/dist/components/overlays/Popup.svelte.d.ts +24 -0
- package/dist/components/sources/CanvasSource.svelte +16 -0
- package/dist/components/sources/CanvasSource.svelte.d.ts +13 -0
- package/dist/components/sources/GeoJSONSource.svelte +16 -0
- package/dist/components/sources/GeoJSONSource.svelte.d.ts +13 -0
- package/dist/components/sources/ImageSource.svelte +16 -0
- package/dist/components/sources/ImageSource.svelte.d.ts +13 -0
- package/dist/components/sources/RasterDEMSource.svelte +16 -0
- package/dist/components/sources/RasterDEMSource.svelte.d.ts +13 -0
- package/dist/components/sources/RasterSource.svelte +16 -0
- package/dist/components/sources/RasterSource.svelte.d.ts +13 -0
- package/dist/components/sources/Source.svelte +88 -0
- package/dist/components/sources/Source.svelte.d.ts +14 -0
- package/dist/components/sources/VectorSource.svelte +16 -0
- package/dist/components/sources/VectorSource.svelte.d.ts +13 -0
- package/dist/components/sources/VideoSource.svelte +16 -0
- package/dist/components/sources/VideoSource.svelte.d.ts +13 -0
- package/dist/components/style/GlobalState.svelte +67 -0
- package/dist/components/style/GlobalState.svelte.d.ts +8 -0
- package/dist/components/style/Image.svelte +92 -0
- package/dist/components/style/Image.svelte.d.ts +14 -0
- package/dist/components/style/Light.svelte +31 -0
- package/dist/components/style/Light.svelte.d.ts +4 -0
- package/dist/components/style/Projection.svelte +31 -0
- package/dist/components/style/Projection.svelte.d.ts +4 -0
- package/dist/components/style/Sky.svelte +31 -0
- package/dist/components/style/Sky.svelte.d.ts +4 -0
- package/dist/components/style/Terrain.svelte +50 -0
- package/dist/components/style/Terrain.svelte.d.ts +9 -0
- package/dist/context.d.ts +41 -0
- package/dist/context.js +31 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +48 -0
- package/dist/internal/bind-events.svelte.d.ts +26 -0
- package/dist/internal/bind-events.svelte.js +49 -0
- package/dist/internal/camera.d.ts +15 -0
- package/dist/internal/camera.js +33 -0
- package/dist/internal/deep-equal.d.ts +6 -0
- package/dist/internal/deep-equal.js +25 -0
- package/dist/internal/diff.d.ts +15 -0
- package/dist/internal/diff.js +29 -0
- package/dist/internal/events.d.ts +22 -0
- package/dist/internal/events.js +40 -0
- package/dist/internal/interactions.d.ts +22 -0
- package/dist/internal/interactions.js +36 -0
- package/dist/internal/source.d.ts +25 -0
- package/dist/internal/source.js +25 -0
- package/dist/internal/stable-key.d.ts +9 -0
- package/dist/internal/stable-key.js +17 -0
- package/dist/internal/style-ops.d.ts +26 -0
- package/dist/internal/style-ops.js +56 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.js +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Marker as MapLibreMarker } from 'maplibre-gl';
|
|
3
|
+
import type { LngLatLike, MarkerOptions } from 'maplibre-gl';
|
|
4
|
+
import { untrack, type Snippet } from 'svelte';
|
|
5
|
+
import { getMapContext, setMarkerContext } from '../../context.js';
|
|
6
|
+
import { bindEvents } from '../../internal/bind-events.svelte.js';
|
|
7
|
+
import { sameLngLat, sameNumber } from '../../internal/camera.js';
|
|
8
|
+
import { stableKey } from '../../internal/stable-key.js';
|
|
9
|
+
import type { MarkerEventProps } from '../../types.js';
|
|
10
|
+
|
|
11
|
+
type Props = MarkerEventProps &
|
|
12
|
+
Omit<MarkerOptions, 'element'> & {
|
|
13
|
+
/** Two-way while `draggable`: the drag writes the new position back. */
|
|
14
|
+
lngLat: LngLatLike;
|
|
15
|
+
/** Applied to the custom element wrapper when `content` is given. */
|
|
16
|
+
class?: string;
|
|
17
|
+
/** Read-only binding to the underlying marker. */
|
|
18
|
+
marker?: MapLibreMarker | null;
|
|
19
|
+
/**
|
|
20
|
+
* Replaces the default pin with your own markup. Only this snippet
|
|
21
|
+
* becomes the marker element.
|
|
22
|
+
*/
|
|
23
|
+
content?: Snippet<[{ marker: MapLibreMarker }]>;
|
|
24
|
+
/**
|
|
25
|
+
* Components that attach to this marker, such as a nested `<Popup>`.
|
|
26
|
+
* They render no marker DOM, so the default pin survives.
|
|
27
|
+
*/
|
|
28
|
+
children?: Snippet;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
lngLat = $bindable(),
|
|
33
|
+
class: className,
|
|
34
|
+
marker = $bindable(null),
|
|
35
|
+
content,
|
|
36
|
+
children,
|
|
37
|
+
offset,
|
|
38
|
+
draggable,
|
|
39
|
+
rotation,
|
|
40
|
+
rotationAlignment,
|
|
41
|
+
pitchAlignment,
|
|
42
|
+
opacity,
|
|
43
|
+
opacityWhenCovered,
|
|
44
|
+
subpixelPositioning,
|
|
45
|
+
...rest
|
|
46
|
+
}: Props = $props();
|
|
47
|
+
|
|
48
|
+
const context = getMapContext();
|
|
49
|
+
|
|
50
|
+
// Split by capability: these have no setter on Marker, so a change to any of
|
|
51
|
+
// them can only be honoured by building a new marker.
|
|
52
|
+
const constructorOnly = $derived({
|
|
53
|
+
color: rest.color,
|
|
54
|
+
scale: rest.scale,
|
|
55
|
+
anchor: rest.anchor,
|
|
56
|
+
className: rest.className,
|
|
57
|
+
clickTolerance: rest.clickTolerance
|
|
58
|
+
});
|
|
59
|
+
const recreateKey = $derived(stableKey(constructorOnly));
|
|
60
|
+
|
|
61
|
+
let contentNode = $state<HTMLDivElement | null>(null);
|
|
62
|
+
|
|
63
|
+
// Decided by the `content` snippet alone. Keying this on `children` made a
|
|
64
|
+
// nested <Popup> count as marker markup, which replaced the default pin with
|
|
65
|
+
// an empty element and produced an invisible 0x0 marker.
|
|
66
|
+
const usesCustomElement = $derived(content !== undefined);
|
|
67
|
+
|
|
68
|
+
setMarkerContext({
|
|
69
|
+
get marker() {
|
|
70
|
+
return marker;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
$effect(() => {
|
|
75
|
+
const map = context.map;
|
|
76
|
+
const element = contentNode;
|
|
77
|
+
void recreateKey;
|
|
78
|
+
|
|
79
|
+
if (!map) return;
|
|
80
|
+
if (usesCustomElement && !element) return;
|
|
81
|
+
|
|
82
|
+
const instance = untrack(() => {
|
|
83
|
+
const created = new MapLibreMarker({
|
|
84
|
+
...constructorOnly,
|
|
85
|
+
...(element ? { element } : {}),
|
|
86
|
+
...(offset !== undefined ? { offset } : {}),
|
|
87
|
+
...(draggable !== undefined ? { draggable } : {}),
|
|
88
|
+
...(rotation !== undefined ? { rotation } : {}),
|
|
89
|
+
...(rotationAlignment !== undefined ? { rotationAlignment } : {}),
|
|
90
|
+
...(pitchAlignment !== undefined ? { pitchAlignment } : {}),
|
|
91
|
+
...(opacity !== undefined ? { opacity } : {}),
|
|
92
|
+
...(opacityWhenCovered !== undefined ? { opacityWhenCovered } : {}),
|
|
93
|
+
...(subpixelPositioning !== undefined ? { subpixelPositioning } : {})
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return created.setLngLat(lngLat).addTo(map);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
marker = instance;
|
|
100
|
+
|
|
101
|
+
return () => {
|
|
102
|
+
marker = null;
|
|
103
|
+
instance.remove();
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Position: props to marker, guarded so the drag write-back below cannot
|
|
108
|
+
// bounce back and fight the pointer.
|
|
109
|
+
$effect(() => {
|
|
110
|
+
const instance = marker;
|
|
111
|
+
const next = lngLat;
|
|
112
|
+
if (!instance) return;
|
|
113
|
+
if (sameLngLat(instance.getLngLat(), next)) return;
|
|
114
|
+
|
|
115
|
+
untrack(() => instance.setLngLat(next));
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Position: marker to props, so `bind:lngLat` reflects a drag.
|
|
119
|
+
$effect(() => {
|
|
120
|
+
const instance = marker;
|
|
121
|
+
if (!instance) return;
|
|
122
|
+
|
|
123
|
+
const sync = () => {
|
|
124
|
+
const next = instance.getLngLat();
|
|
125
|
+
if (!sameLngLat(lngLat, next)) lngLat = [next.lng, next.lat];
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const subscriptions = [instance.on('drag', sync), instance.on('dragend', sync)];
|
|
129
|
+
|
|
130
|
+
return () => {
|
|
131
|
+
for (const subscription of subscriptions) subscription.unsubscribe();
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Everything MapLibre exposes a setter for is updated in place.
|
|
136
|
+
$effect(() => {
|
|
137
|
+
const instance = marker;
|
|
138
|
+
const next = offset;
|
|
139
|
+
if (!instance || next === undefined) return;
|
|
140
|
+
untrack(() => instance.setOffset(next));
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
$effect(() => {
|
|
144
|
+
const instance = marker;
|
|
145
|
+
const next = draggable;
|
|
146
|
+
if (!instance || next === undefined) return;
|
|
147
|
+
untrack(() => instance.setDraggable(next));
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
$effect(() => {
|
|
151
|
+
const instance = marker;
|
|
152
|
+
const next = rotation;
|
|
153
|
+
if (!instance || next === undefined) return;
|
|
154
|
+
if (sameNumber(instance.getRotation(), next)) return;
|
|
155
|
+
untrack(() => instance.setRotation(next));
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
$effect(() => {
|
|
159
|
+
const instance = marker;
|
|
160
|
+
const next = rotationAlignment;
|
|
161
|
+
if (!instance || next === undefined) return;
|
|
162
|
+
untrack(() => instance.setRotationAlignment(next));
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
$effect(() => {
|
|
166
|
+
const instance = marker;
|
|
167
|
+
const next = pitchAlignment;
|
|
168
|
+
if (!instance || next === undefined) return;
|
|
169
|
+
untrack(() => instance.setPitchAlignment(next));
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
$effect(() => {
|
|
173
|
+
const instance = marker;
|
|
174
|
+
const next = { opacity, opacityWhenCovered };
|
|
175
|
+
if (!instance || (next.opacity === undefined && next.opacityWhenCovered === undefined)) return;
|
|
176
|
+
untrack(() => instance.setOpacity(next.opacity, next.opacityWhenCovered));
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
$effect(() => {
|
|
180
|
+
const instance = marker;
|
|
181
|
+
const next = subpixelPositioning;
|
|
182
|
+
if (!instance || next === undefined) return;
|
|
183
|
+
untrack(() => instance.setSubpixelPositioning(next));
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
bindEvents(
|
|
187
|
+
() => marker,
|
|
188
|
+
() => rest
|
|
189
|
+
);
|
|
190
|
+
</script>
|
|
191
|
+
|
|
192
|
+
{#if usesCustomElement}
|
|
193
|
+
<div style="display: none" aria-hidden="true">
|
|
194
|
+
<div bind:this={contentNode} class={className}>
|
|
195
|
+
{#if marker}
|
|
196
|
+
{@render content?.({ marker })}
|
|
197
|
+
{/if}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
{/if}
|
|
201
|
+
|
|
202
|
+
{#if marker}
|
|
203
|
+
{@render children?.()}
|
|
204
|
+
{/if}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Marker as MapLibreMarker } from 'maplibre-gl';
|
|
2
|
+
import type { LngLatLike, MarkerOptions } from 'maplibre-gl';
|
|
3
|
+
import { type Snippet } from 'svelte';
|
|
4
|
+
import type { MarkerEventProps } from '../../types.js';
|
|
5
|
+
type Props = MarkerEventProps & Omit<MarkerOptions, 'element'> & {
|
|
6
|
+
/** Two-way while `draggable`: the drag writes the new position back. */
|
|
7
|
+
lngLat: LngLatLike;
|
|
8
|
+
/** Applied to the custom element wrapper when `content` is given. */
|
|
9
|
+
class?: string;
|
|
10
|
+
/** Read-only binding to the underlying marker. */
|
|
11
|
+
marker?: MapLibreMarker | null;
|
|
12
|
+
/**
|
|
13
|
+
* Replaces the default pin with your own markup. Only this snippet
|
|
14
|
+
* becomes the marker element.
|
|
15
|
+
*/
|
|
16
|
+
content?: Snippet<[{
|
|
17
|
+
marker: MapLibreMarker;
|
|
18
|
+
}]>;
|
|
19
|
+
/**
|
|
20
|
+
* Components that attach to this marker, such as a nested `<Popup>`.
|
|
21
|
+
* They render no marker DOM, so the default pin survives.
|
|
22
|
+
*/
|
|
23
|
+
children?: Snippet;
|
|
24
|
+
};
|
|
25
|
+
declare const Marker: import("svelte").Component<Props, {}, "lngLat" | "marker">;
|
|
26
|
+
type Marker = ReturnType<typeof Marker>;
|
|
27
|
+
export default Marker;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Popup as MapLibrePopup } from 'maplibre-gl';
|
|
3
|
+
import type { LngLatLike, PopupOptions } from 'maplibre-gl';
|
|
4
|
+
import { untrack, type Snippet } from 'svelte';
|
|
5
|
+
import { getMapContext, getMarkerContext } from '../../context.js';
|
|
6
|
+
import { bindEvents } from '../../internal/bind-events.svelte.js';
|
|
7
|
+
import { sameLngLat } from '../../internal/camera.js';
|
|
8
|
+
import { stableKey } from '../../internal/stable-key.js';
|
|
9
|
+
import type { PopupEventProps } from '../../types.js';
|
|
10
|
+
|
|
11
|
+
type Props = PopupEventProps &
|
|
12
|
+
PopupOptions & {
|
|
13
|
+
/**
|
|
14
|
+
* Where the popup anchors. Ignored when nested inside a `<Marker>`,
|
|
15
|
+
* which supplies the position itself.
|
|
16
|
+
*/
|
|
17
|
+
lngLat?: LngLatLike;
|
|
18
|
+
/**
|
|
19
|
+
* Two-way. Standalone popups are opened and closed by this prop;
|
|
20
|
+
* marker-attached popups report their state through it.
|
|
21
|
+
*/
|
|
22
|
+
open?: boolean;
|
|
23
|
+
/** Read-only binding to the underlying popup. */
|
|
24
|
+
popup?: MapLibrePopup | null;
|
|
25
|
+
children?: Snippet<[{ popup: MapLibrePopup }]>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
let {
|
|
29
|
+
lngLat,
|
|
30
|
+
open = $bindable(false),
|
|
31
|
+
popup = $bindable(null),
|
|
32
|
+
children,
|
|
33
|
+
maxWidth,
|
|
34
|
+
offset,
|
|
35
|
+
padding,
|
|
36
|
+
subpixelPositioning,
|
|
37
|
+
...rest
|
|
38
|
+
}: Props = $props();
|
|
39
|
+
|
|
40
|
+
const context = getMapContext();
|
|
41
|
+
const markerContext = getMarkerContext();
|
|
42
|
+
const attachedToMarker = markerContext !== null;
|
|
43
|
+
|
|
44
|
+
// No setters exist for these, so a change means a new popup.
|
|
45
|
+
const constructorOnly = $derived({
|
|
46
|
+
closeButton: rest.closeButton,
|
|
47
|
+
closeOnClick: rest.closeOnClick,
|
|
48
|
+
closeOnMove: rest.closeOnMove,
|
|
49
|
+
focusAfterOpen: rest.focusAfterOpen,
|
|
50
|
+
anchor: rest.anchor,
|
|
51
|
+
className: rest.className,
|
|
52
|
+
locationOccludedOpacity: rest.locationOccludedOpacity
|
|
53
|
+
});
|
|
54
|
+
const recreateKey = $derived(stableKey(constructorOnly));
|
|
55
|
+
|
|
56
|
+
let content = $state<HTMLDivElement | null>(null);
|
|
57
|
+
|
|
58
|
+
$effect(() => {
|
|
59
|
+
const map = context.map;
|
|
60
|
+
const node = content;
|
|
61
|
+
void recreateKey;
|
|
62
|
+
|
|
63
|
+
if (!map || !node) return;
|
|
64
|
+
|
|
65
|
+
const instance = untrack(() => {
|
|
66
|
+
const created = new MapLibrePopup({
|
|
67
|
+
...constructorOnly,
|
|
68
|
+
...(maxWidth !== undefined ? { maxWidth } : {}),
|
|
69
|
+
...(offset !== undefined ? { offset } : {}),
|
|
70
|
+
...(padding !== undefined ? { padding } : {}),
|
|
71
|
+
...(subpixelPositioning !== undefined ? { subpixelPositioning } : {})
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
created.setDOMContent(node);
|
|
75
|
+
if (lngLat !== undefined) created.setLngLat(lngLat);
|
|
76
|
+
|
|
77
|
+
return created;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
popup = instance;
|
|
81
|
+
|
|
82
|
+
return () => {
|
|
83
|
+
popup = null;
|
|
84
|
+
instance.remove();
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Attaching to a marker delegates open/close to the marker's own click
|
|
89
|
+
// handling, which is why the two modes are wired differently below.
|
|
90
|
+
$effect(() => {
|
|
91
|
+
const marker = markerContext?.marker;
|
|
92
|
+
const instance = popup;
|
|
93
|
+
if (!marker || !instance) return;
|
|
94
|
+
|
|
95
|
+
marker.setPopup(instance);
|
|
96
|
+
|
|
97
|
+
return () => marker.setPopup(null);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
$effect(() => {
|
|
101
|
+
const instance = popup;
|
|
102
|
+
const next = lngLat;
|
|
103
|
+
if (!instance || next === undefined) return;
|
|
104
|
+
if (instance.isOpen() && sameLngLat(instance.getLngLat(), next)) return;
|
|
105
|
+
|
|
106
|
+
untrack(() => instance.setLngLat(next));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Standalone open/close is driven by the prop.
|
|
110
|
+
$effect(() => {
|
|
111
|
+
const map = context.map;
|
|
112
|
+
const instance = popup;
|
|
113
|
+
const shouldOpen = open;
|
|
114
|
+
|
|
115
|
+
if (!map || !instance || attachedToMarker) return;
|
|
116
|
+
if (shouldOpen === instance.isOpen()) return;
|
|
117
|
+
|
|
118
|
+
untrack(() => {
|
|
119
|
+
if (shouldOpen) instance.addTo(map);
|
|
120
|
+
else instance.remove();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Both modes report their real state back, so `bind:open` stays truthful
|
|
125
|
+
// after a close button click or a `closeOnClick`.
|
|
126
|
+
$effect(() => {
|
|
127
|
+
const instance = popup;
|
|
128
|
+
if (!instance) return;
|
|
129
|
+
|
|
130
|
+
const subscriptions = [
|
|
131
|
+
instance.on('open', () => {
|
|
132
|
+
open = true;
|
|
133
|
+
}),
|
|
134
|
+
instance.on('close', () => {
|
|
135
|
+
open = false;
|
|
136
|
+
})
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
return () => {
|
|
140
|
+
for (const subscription of subscriptions) subscription.unsubscribe();
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
$effect(() => {
|
|
145
|
+
const instance = popup;
|
|
146
|
+
const next = maxWidth;
|
|
147
|
+
if (!instance || next === undefined) return;
|
|
148
|
+
untrack(() => instance.setMaxWidth(next));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
$effect(() => {
|
|
152
|
+
const instance = popup;
|
|
153
|
+
const next = offset;
|
|
154
|
+
if (!instance || next === undefined) return;
|
|
155
|
+
untrack(() => instance.setOffset(next));
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
$effect(() => {
|
|
159
|
+
const instance = popup;
|
|
160
|
+
const next = padding;
|
|
161
|
+
if (!instance || next === undefined) return;
|
|
162
|
+
untrack(() => instance.setPadding(next));
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
$effect(() => {
|
|
166
|
+
const instance = popup;
|
|
167
|
+
const next = subpixelPositioning;
|
|
168
|
+
if (!instance || next === undefined) return;
|
|
169
|
+
untrack(() => instance.setSubpixelPositioning(next));
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
bindEvents(
|
|
173
|
+
() => popup,
|
|
174
|
+
() => rest
|
|
175
|
+
);
|
|
176
|
+
</script>
|
|
177
|
+
|
|
178
|
+
<div style="display: none" aria-hidden="true">
|
|
179
|
+
<div bind:this={content}>
|
|
180
|
+
{#if popup}
|
|
181
|
+
{@render children?.({ popup })}
|
|
182
|
+
{/if}
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Popup as MapLibrePopup } from 'maplibre-gl';
|
|
2
|
+
import type { LngLatLike, PopupOptions } from 'maplibre-gl';
|
|
3
|
+
import { type Snippet } from 'svelte';
|
|
4
|
+
import type { PopupEventProps } from '../../types.js';
|
|
5
|
+
type Props = PopupEventProps & PopupOptions & {
|
|
6
|
+
/**
|
|
7
|
+
* Where the popup anchors. Ignored when nested inside a `<Marker>`,
|
|
8
|
+
* which supplies the position itself.
|
|
9
|
+
*/
|
|
10
|
+
lngLat?: LngLatLike;
|
|
11
|
+
/**
|
|
12
|
+
* Two-way. Standalone popups are opened and closed by this prop;
|
|
13
|
+
* marker-attached popups report their state through it.
|
|
14
|
+
*/
|
|
15
|
+
open?: boolean;
|
|
16
|
+
/** Read-only binding to the underlying popup. */
|
|
17
|
+
popup?: MapLibrePopup | null;
|
|
18
|
+
children?: Snippet<[{
|
|
19
|
+
popup: MapLibrePopup;
|
|
20
|
+
}]>;
|
|
21
|
+
};
|
|
22
|
+
declare const Popup: import("svelte").Component<Props, {}, "open" | "popup">;
|
|
23
|
+
type Popup = ReturnType<typeof Popup>;
|
|
24
|
+
export default Popup;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { CanvasSourceSpecification } from 'maplibre-gl';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import Source from './Source.svelte';
|
|
5
|
+
|
|
6
|
+
type Props = Omit<CanvasSourceSpecification, 'type'> & {
|
|
7
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Layers nested here inherit this source id automatically. */
|
|
10
|
+
children?: Snippet<[{ id: string }]>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let { id, children, ...spec }: Props = $props();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<Source {id} spec={{ type: 'canvas', ...spec }} {children} />
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CanvasSourceSpecification } from 'maplibre-gl';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type Props = Omit<CanvasSourceSpecification, 'type'> & {
|
|
4
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Layers nested here inherit this source id automatically. */
|
|
7
|
+
children?: Snippet<[{
|
|
8
|
+
id: string;
|
|
9
|
+
}]>;
|
|
10
|
+
};
|
|
11
|
+
declare const CanvasSource: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type CanvasSource = ReturnType<typeof CanvasSource>;
|
|
13
|
+
export default CanvasSource;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { GeoJSONSourceSpecification } from 'maplibre-gl';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import Source from './Source.svelte';
|
|
5
|
+
|
|
6
|
+
type Props = Omit<GeoJSONSourceSpecification, 'type'> & {
|
|
7
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Layers nested here inherit this source id automatically. */
|
|
10
|
+
children?: Snippet<[{ id: string }]>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let { id, children, ...spec }: Props = $props();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<Source {id} spec={{ type: 'geojson', ...spec }} {children} />
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GeoJSONSourceSpecification } from 'maplibre-gl';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type Props = Omit<GeoJSONSourceSpecification, 'type'> & {
|
|
4
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Layers nested here inherit this source id automatically. */
|
|
7
|
+
children?: Snippet<[{
|
|
8
|
+
id: string;
|
|
9
|
+
}]>;
|
|
10
|
+
};
|
|
11
|
+
declare const GeoJSONSource: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type GeoJSONSource = ReturnType<typeof GeoJSONSource>;
|
|
13
|
+
export default GeoJSONSource;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ImageSourceSpecification } from 'maplibre-gl';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import Source from './Source.svelte';
|
|
5
|
+
|
|
6
|
+
type Props = Omit<ImageSourceSpecification, 'type'> & {
|
|
7
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Layers nested here inherit this source id automatically. */
|
|
10
|
+
children?: Snippet<[{ id: string }]>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let { id, children, ...spec }: Props = $props();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<Source {id} spec={{ type: 'image', ...spec }} {children} />
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ImageSourceSpecification } from 'maplibre-gl';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type Props = Omit<ImageSourceSpecification, 'type'> & {
|
|
4
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Layers nested here inherit this source id automatically. */
|
|
7
|
+
children?: Snippet<[{
|
|
8
|
+
id: string;
|
|
9
|
+
}]>;
|
|
10
|
+
};
|
|
11
|
+
declare const ImageSource: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type ImageSource = ReturnType<typeof ImageSource>;
|
|
13
|
+
export default ImageSource;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { RasterDEMSourceSpecification } from 'maplibre-gl';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import Source from './Source.svelte';
|
|
5
|
+
|
|
6
|
+
type Props = Omit<RasterDEMSourceSpecification, 'type'> & {
|
|
7
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Layers nested here inherit this source id automatically. */
|
|
10
|
+
children?: Snippet<[{ id: string }]>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let { id, children, ...spec }: Props = $props();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<Source {id} spec={{ type: 'raster-dem', ...spec }} {children} />
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RasterDEMSourceSpecification } from 'maplibre-gl';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type Props = Omit<RasterDEMSourceSpecification, 'type'> & {
|
|
4
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Layers nested here inherit this source id automatically. */
|
|
7
|
+
children?: Snippet<[{
|
|
8
|
+
id: string;
|
|
9
|
+
}]>;
|
|
10
|
+
};
|
|
11
|
+
declare const RasterDEMSource: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type RasterDEMSource = ReturnType<typeof RasterDEMSource>;
|
|
13
|
+
export default RasterDEMSource;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { RasterSourceSpecification } from 'maplibre-gl';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import Source from './Source.svelte';
|
|
5
|
+
|
|
6
|
+
type Props = Omit<RasterSourceSpecification, 'type'> & {
|
|
7
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** Layers nested here inherit this source id automatically. */
|
|
10
|
+
children?: Snippet<[{ id: string }]>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let { id, children, ...spec }: Props = $props();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<Source {id} spec={{ type: 'raster', ...spec }} {children} />
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RasterSourceSpecification } from 'maplibre-gl';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
type Props = Omit<RasterSourceSpecification, 'type'> & {
|
|
4
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Layers nested here inherit this source id automatically. */
|
|
7
|
+
children?: Snippet<[{
|
|
8
|
+
id: string;
|
|
9
|
+
}]>;
|
|
10
|
+
};
|
|
11
|
+
declare const RasterSource: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type RasterSource = ReturnType<typeof RasterSource>;
|
|
13
|
+
export default RasterSource;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { GeoJSONSource } from 'maplibre-gl';
|
|
3
|
+
import { untrack, type Snippet } from 'svelte';
|
|
4
|
+
import { getMapContext, setSourceContext } from '../../context.js';
|
|
5
|
+
import { planSourceUpdate, type AnySourceSpecification } from '../../internal/source.js';
|
|
6
|
+
import { removeLayersUsingSource, removeSourceIfPresent } from '../../internal/style-ops.js';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
/** Unique within the style. Changing it recreates the source. */
|
|
10
|
+
id: string;
|
|
11
|
+
spec: AnySourceSpecification;
|
|
12
|
+
/** Layers nested here inherit this source id automatically. */
|
|
13
|
+
children?: Snippet<[{ id: string }]>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
let { id, spec, children }: Props = $props();
|
|
17
|
+
|
|
18
|
+
const context = getMapContext();
|
|
19
|
+
|
|
20
|
+
let epoch = $state(0);
|
|
21
|
+
let mounted = $state(false);
|
|
22
|
+
let applied = $state<AnySourceSpecification | undefined>();
|
|
23
|
+
|
|
24
|
+
setSourceContext({
|
|
25
|
+
get id() {
|
|
26
|
+
return id;
|
|
27
|
+
},
|
|
28
|
+
get epoch() {
|
|
29
|
+
return epoch;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Add and remove. Re-runs when the map appears, when the style is replaced
|
|
34
|
+
// (which wipes user-added sources), and when the id itself changes.
|
|
35
|
+
$effect(() => {
|
|
36
|
+
const map = context.map;
|
|
37
|
+
const ready = context.ready;
|
|
38
|
+
void context.styleEpoch;
|
|
39
|
+
const sourceId = id;
|
|
40
|
+
|
|
41
|
+
if (!map || !ready) return;
|
|
42
|
+
|
|
43
|
+
untrack(() => {
|
|
44
|
+
map.addSource(sourceId, spec);
|
|
45
|
+
applied = spec;
|
|
46
|
+
mounted = true;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return () => {
|
|
50
|
+
mounted = false;
|
|
51
|
+
applied = undefined;
|
|
52
|
+
removeSourceIfPresent(map, sourceId);
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Update in place. GeoJSON data is the hot path and survives via `setData`;
|
|
57
|
+
// anything else has no setter in MapLibre and forces a recreate.
|
|
58
|
+
$effect(() => {
|
|
59
|
+
const map = context.map;
|
|
60
|
+
const nextSpec = spec;
|
|
61
|
+
if (!map || !mounted) return;
|
|
62
|
+
|
|
63
|
+
const plan = planSourceUpdate(
|
|
64
|
+
untrack(() => applied),
|
|
65
|
+
nextSpec
|
|
66
|
+
);
|
|
67
|
+
if (plan.kind === 'noop' || plan.kind === 'create') return;
|
|
68
|
+
|
|
69
|
+
untrack(() => {
|
|
70
|
+
if (plan.kind === 'set-data') {
|
|
71
|
+
const source = map.getSource(id) as GeoJSONSource | undefined;
|
|
72
|
+
source?.setData(plan.data as Parameters<GeoJSONSource['setData']>[0]);
|
|
73
|
+
applied = nextSpec;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
removeLayersUsingSource(map, id);
|
|
78
|
+
removeSourceIfPresent(map, id);
|
|
79
|
+
map.addSource(id, nextSpec);
|
|
80
|
+
applied = nextSpec;
|
|
81
|
+
epoch += 1;
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
{#if mounted}
|
|
87
|
+
{@render children?.({ id })}
|
|
88
|
+
{/if}
|