@radiofrance/svelte-leaflet 0.1.0-alpha.9 → 1.0.0-next.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 +12 -7
- package/dist/DivIcon.svelte +64 -0
- package/dist/DivIcon.svelte.d.ts +27 -0
- package/dist/Icon.svelte +56 -0
- package/dist/Icon.svelte.d.ts +31 -0
- package/dist/LocateControl.svelte +57 -0
- package/dist/LocateControl.svelte.d.ts +9 -0
- package/dist/Map.svelte +128 -77
- package/dist/Map.svelte.d.ts +15 -64
- package/dist/Marker.svelte +68 -70
- package/dist/Marker.svelte.d.ts +11 -34
- package/dist/MarkerClusterGroup.svelte +73 -42
- package/dist/MarkerClusterGroup.svelte.d.ts +69 -21
- package/dist/Polygon.svelte +43 -0
- package/dist/Polygon.svelte.d.ts +9 -0
- package/dist/Polyline.svelte +42 -25
- package/dist/Polyline.svelte.d.ts +9 -22
- package/dist/Popup.svelte +69 -44
- package/dist/Popup.svelte.d.ts +10 -19
- package/dist/contexts.d.ts +4 -0
- package/dist/contexts.js +4 -0
- package/dist/events.d.ts +11 -0
- package/dist/events.js +31 -0
- package/dist/index.d.ts +18 -53
- package/dist/index.js +13 -53
- package/dist/map.svelte.d.ts +10 -0
- package/dist/map.svelte.js +117 -0
- package/dist/marker.svelte.d.ts +5 -0
- package/dist/marker.svelte.js +61 -0
- package/dist/markerClusterGroup.svelte.d.ts +9 -0
- package/dist/markerClusterGroup.svelte.js +7 -0
- package/dist/polygon.svelte.d.ts +1 -0
- package/dist/polygon.svelte.js +1 -0
- package/dist/polyline.svelte.d.ts +6 -0
- package/dist/polyline.svelte.js +56 -0
- package/dist/popup.svelte.d.ts +10 -0
- package/dist/popup.svelte.js +50 -0
- package/dist/private/GeolocationButton.svelte +36 -0
- package/dist/private/GeolocationButton.svelte.d.ts +18 -0
- package/dist/private/GeolocationIcon.svelte +25 -0
- package/dist/private/GeolocationIcon.svelte.d.ts +4 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +10 -0
- package/package.json +43 -59
- package/dist/Circle.svelte +0 -41
- package/dist/Circle.svelte.d.ts +0 -36
package/dist/Popup.svelte
CHANGED
|
@@ -1,48 +1,73 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
LatLngExpression,
|
|
4
|
+
PopupOptions,
|
|
5
|
+
LayerGroup,
|
|
6
|
+
Popup as LeafletPopup,
|
|
7
|
+
Map as LeafletMap,
|
|
8
|
+
Marker as LeafletMarker,
|
|
9
|
+
} from 'leaflet';
|
|
10
|
+
import { getContext, onDestroy, onMount, type Snippet } from 'svelte';
|
|
11
|
+
import { bindEvents } from './index.js';
|
|
12
|
+
import { popupEvents, updatePopupProps, type PopupEvents } from './popup.svelte.js';
|
|
13
|
+
import { LAYERGROUP, MAP, MARKER } from './contexts.js';
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
latlng?: LatLngExpression;
|
|
17
|
+
options?: PopupOptions;
|
|
18
|
+
instance?: LeafletPopup;
|
|
19
|
+
children?: Snippet;
|
|
20
|
+
} & PopupEvents;
|
|
21
|
+
|
|
22
|
+
let {
|
|
23
|
+
latlng,
|
|
24
|
+
options = $bindable({}),
|
|
25
|
+
instance = $bindable(),
|
|
26
|
+
children,
|
|
27
|
+
...restProps
|
|
28
|
+
}: Props = $props();
|
|
29
|
+
|
|
30
|
+
let popupContent: HTMLElement | undefined = $state();
|
|
31
|
+
|
|
32
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
33
|
+
const getLayerGroup = getContext<() => LayerGroup>(LAYERGROUP);
|
|
34
|
+
const getMarker = getContext<() => LeafletMarker>(MARKER);
|
|
35
|
+
|
|
36
|
+
onMount(() => {
|
|
37
|
+
const map = getMap?.();
|
|
38
|
+
const layerGroup = getLayerGroup?.();
|
|
39
|
+
const marker = getMarker?.();
|
|
40
|
+
const context = layerGroup || map;
|
|
41
|
+
instance = window.L.popup(options);
|
|
42
|
+
if (latlng) instance.setLatLng(latlng);
|
|
43
|
+
bindEvents(instance, restProps, popupEvents);
|
|
44
|
+
if (marker) marker.bindPopup(instance);
|
|
45
|
+
else if (map) instance.openOn(map);
|
|
46
|
+
else instance.addTo(context);
|
|
47
|
+
if (popupContent) instance.setContent(popupContent);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
onDestroy(() => {
|
|
51
|
+
instance?.remove();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
$effect(() => {
|
|
55
|
+
if (instance && options) {
|
|
56
|
+
updatePopupProps(instance, options);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
42
59
|
</script>
|
|
43
60
|
|
|
44
|
-
<div
|
|
45
|
-
{#if
|
|
46
|
-
<
|
|
61
|
+
<div class="container">
|
|
62
|
+
{#if children}
|
|
63
|
+
<div bind:this={popupContent} class="PopupChildrenContainer">
|
|
64
|
+
{@render children()}
|
|
65
|
+
</div>
|
|
47
66
|
{/if}
|
|
48
67
|
</div>
|
|
68
|
+
|
|
69
|
+
<style>
|
|
70
|
+
.container {
|
|
71
|
+
display: none;
|
|
72
|
+
}
|
|
73
|
+
</style>
|
package/dist/Popup.svelte.d.ts
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
default: {};
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export type PopupProps = typeof __propDef.props;
|
|
15
|
-
export type PopupEvents = typeof __propDef.events;
|
|
16
|
-
export type PopupSlots = typeof __propDef.slots;
|
|
17
|
-
export default class Popup extends SvelteComponent<PopupProps, PopupEvents, PopupSlots> {
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
1
|
+
import type { LatLngExpression, PopupOptions, Popup as LeafletPopup } from 'leaflet';
|
|
2
|
+
import { type Snippet } from 'svelte';
|
|
3
|
+
import { type PopupEvents } from './popup.svelte.js';
|
|
4
|
+
declare const Popup: import("svelte").Component<{
|
|
5
|
+
latlng?: LatLngExpression;
|
|
6
|
+
options?: PopupOptions;
|
|
7
|
+
instance?: LeafletPopup;
|
|
8
|
+
children?: Snippet;
|
|
9
|
+
} & PopupEvents, {}, "instance" | "options">;
|
|
10
|
+
export default Popup;
|
package/dist/contexts.js
ADDED
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const interactiveLayerEvents: readonly ["click", "dblclick", "mousedown", "mouseup", "mouseover", "mouseout", "contextmenu"];
|
|
2
|
+
export declare const draggingEvents: readonly ["dragstart", "movestart", "drag", "dragend", "moveend"];
|
|
3
|
+
export declare const keyboardEvents: readonly ["keypress", "keydown", "keyup"];
|
|
4
|
+
export declare const locationEvents: readonly ["locationfound", "locationerror"];
|
|
5
|
+
export declare const leafletMouseEvents: readonly ["click", "dblclick", "mousedown", "mouseup", "mouseover", "mouseout", "contextmenu", "mousemove", "preclick"];
|
|
6
|
+
export declare const layerEvents: readonly ["add", "remove"];
|
|
7
|
+
export declare const popupSpecificEvents: readonly ["popupopen", "popupclose"];
|
|
8
|
+
export declare const tooltipEvents: readonly ["tooltipopen", "tooltipclose"];
|
|
9
|
+
export declare const layerGroupEvents: readonly ["layeradd", "layerremove"];
|
|
10
|
+
export declare const layersControlEvents: readonly ["baselayerchange", "overlayadd", "overlayremove"];
|
|
11
|
+
export declare const mapStateChangeEvents: readonly ["load", "move", "moveend", "movestart", "unload", "viewreset", "zoom", "zoomend", "zoomlevelschange", "zoomstart", "resize"];
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const interactiveLayerEvents = [
|
|
2
|
+
'click',
|
|
3
|
+
'dblclick',
|
|
4
|
+
'mousedown',
|
|
5
|
+
'mouseup',
|
|
6
|
+
'mouseover',
|
|
7
|
+
'mouseout',
|
|
8
|
+
'contextmenu',
|
|
9
|
+
];
|
|
10
|
+
export const draggingEvents = ['dragstart', 'movestart', 'drag', 'dragend', 'moveend'];
|
|
11
|
+
export const keyboardEvents = ['keypress', 'keydown', 'keyup'];
|
|
12
|
+
export const locationEvents = ['locationfound', 'locationerror'];
|
|
13
|
+
export const leafletMouseEvents = [...interactiveLayerEvents, 'mousemove', 'preclick'];
|
|
14
|
+
export const layerEvents = ['add', 'remove'];
|
|
15
|
+
export const popupSpecificEvents = ['popupopen', 'popupclose'];
|
|
16
|
+
export const tooltipEvents = ['tooltipopen', 'tooltipclose'];
|
|
17
|
+
export const layerGroupEvents = ['layeradd', 'layerremove'];
|
|
18
|
+
export const layersControlEvents = ['baselayerchange', 'overlayadd', 'overlayremove'];
|
|
19
|
+
const leafletEvents = [
|
|
20
|
+
'load',
|
|
21
|
+
'move',
|
|
22
|
+
'moveend',
|
|
23
|
+
'movestart',
|
|
24
|
+
'unload',
|
|
25
|
+
'viewreset',
|
|
26
|
+
'zoom',
|
|
27
|
+
'zoomend',
|
|
28
|
+
'zoomlevelschange',
|
|
29
|
+
'zoomstart',
|
|
30
|
+
];
|
|
31
|
+
export const mapStateChangeEvents = [...leafletEvents, 'resize'];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
export type { Circle as LeafletCircle, CircleOptions, DragEndEvent, ErrorEvent, LatLngExpression, LatLngLiteral, LatLngTuple, LayerEvent, LayersControlEvent, LeafletEvent, LeafletKeyboardEvent, LeafletMouseEvent, LocationEvent, Map as LeafletMap, MapOptions, MarkerOptions, PathOptions, PopupEvent, PopupOptions, ResizeEvent, TooltipEvent } from 'leaflet';
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export declare
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export declare const layerGroupEvents: readonly ["layeradd", "layerremove"];
|
|
20
|
-
export declare const layersControlEvents: readonly ["baselayerchange", "overlayadd", "overlayremove"];
|
|
21
|
-
declare const leafletEvents: readonly ["load", "move", "moveend", "movestart", "unload", "viewreset", "zoom", "zoomend", "zoomlevelschange", "zoomstart"];
|
|
22
|
-
export declare const mapStateChangeEvents: readonly ["load", "move", "moveend", "movestart", "unload", "viewreset", "zoom", "zoomend", "zoomlevelschange", "zoomstart", "resize"];
|
|
23
|
-
type LeafletEventTypes = {
|
|
24
|
-
resize: ResizeEvent;
|
|
25
|
-
locationerror: ErrorEvent;
|
|
26
|
-
locationfound: LocationEvent;
|
|
27
|
-
add: LeafletEvent;
|
|
28
|
-
remove: LeafletEvent;
|
|
29
|
-
dragend: DragEndEvent;
|
|
30
|
-
} & LeafletEvents & LayersControlEvents & MouseEvents & PopupEvents & TooltipEvents & LayerGroupEvents & KeyboardEvents;
|
|
31
|
-
type LeafletEvents = {
|
|
32
|
-
[K in (typeof leafletEvents)[number]]: LeafletEvent;
|
|
33
|
-
};
|
|
34
|
-
type LayersControlEvents = {
|
|
35
|
-
[K in (typeof layersControlEvents)[number]]: LayersControlEvent;
|
|
36
|
-
};
|
|
37
|
-
type MouseEvents = {
|
|
38
|
-
[K in (typeof leafletMouseEvents)[number]]: LeafletMouseEvent;
|
|
39
|
-
};
|
|
40
|
-
type PopupEvents = {
|
|
41
|
-
[K in (typeof popupEvents)[number]]: PopupEvent;
|
|
42
|
-
};
|
|
43
|
-
type TooltipEvents = {
|
|
44
|
-
[K in (typeof tooltipEvents)[number]]: TooltipEvent;
|
|
45
|
-
};
|
|
46
|
-
type LayerGroupEvents = {
|
|
47
|
-
[K in (typeof layerGroupEvents)[number]]: LayerEvent;
|
|
48
|
-
};
|
|
49
|
-
type KeyboardEvents = {
|
|
50
|
-
[K in (typeof keyboardEvents)[number]]: LeafletKeyboardEvent;
|
|
51
|
-
};
|
|
52
|
-
export type LeafletEventsRecord<T extends readonly string[]> = {
|
|
53
|
-
[K in T[number]]: K extends keyof LeafletEventTypes ? LeafletEventTypes[K] : LeafletEvent;
|
|
1
|
+
import type { ControlPosition, Evented, LatLngExpression, LeafletEventHandlerFnMap, LocateOptions } from 'leaflet';
|
|
2
|
+
import DivIcon from './DivIcon.svelte';
|
|
3
|
+
import Map from './Map.svelte';
|
|
4
|
+
import Marker from './Marker.svelte';
|
|
5
|
+
import MarkerClusterGroup from './MarkerClusterGroup.svelte';
|
|
6
|
+
import Popup from './Popup.svelte';
|
|
7
|
+
import Polygon from './Polygon.svelte';
|
|
8
|
+
import LocateControl from './LocateControl.svelte';
|
|
9
|
+
export { DivIcon, Map, Marker, MarkerClusterGroup, Popup, Polygon, LocateControl };
|
|
10
|
+
export type { Circle as LeafletCircle, CircleOptions, DragEndEvent, ErrorEvent, LatLngBoundsLiteral, LatLngExpression, LatLngLiteral, LatLngTuple, LayerEvent, LayersControlEvent, LeafletEvent, LeafletKeyboardEvent, LeafletMouseEvent, LocationEvent, Map as LeafletMap, MapOptions, MarkerOptions, PathOptions, PopupEvent, PopupOptions, ResizeEvent, TooltipEvent, } from 'leaflet';
|
|
11
|
+
export type Latlngs<D = 2> = 2 extends D ? LatLngExpression[] | LatLngExpression[][] : 3 extends D ? LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][] : never;
|
|
12
|
+
export type PrefixedLeafletEventHandlerFnMap = {
|
|
13
|
+
[K in keyof LeafletEventHandlerFnMap as `on${K}`]: LeafletEventHandlerFnMap[K];
|
|
14
|
+
};
|
|
15
|
+
export declare function bindEvents(instance: Evented, eventsProps: PrefixedLeafletEventHandlerFnMap, events: readonly (keyof LeafletEventHandlerFnMap)[]): void;
|
|
16
|
+
export type LocateControlOptions = {
|
|
17
|
+
position?: ControlPosition;
|
|
18
|
+
options?: LocateOptions;
|
|
54
19
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,57 +1,17 @@
|
|
|
1
1
|
// Reexport your entry components here
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import DivIcon from './DivIcon.svelte';
|
|
3
|
+
import Map from './Map.svelte';
|
|
4
|
+
import Marker from './Marker.svelte';
|
|
5
|
+
import MarkerClusterGroup from './MarkerClusterGroup.svelte';
|
|
6
|
+
import Popup from './Popup.svelte';
|
|
7
|
+
import Polygon from './Polygon.svelte';
|
|
8
|
+
import LocateControl from './LocateControl.svelte';
|
|
9
|
+
export { DivIcon, Map, Marker, MarkerClusterGroup, Popup, Polygon, LocateControl };
|
|
10
|
+
export function bindEvents(instance, eventsProps, events) {
|
|
9
11
|
events.forEach((event) => {
|
|
10
|
-
|
|
12
|
+
const eventCallback = eventsProps[`on${event}`];
|
|
13
|
+
if (typeof eventCallback !== 'function')
|
|
14
|
+
return;
|
|
15
|
+
instance.on(event, (e) => eventCallback(e));
|
|
11
16
|
});
|
|
12
17
|
}
|
|
13
|
-
// export const leafletEvents = [
|
|
14
|
-
// 'dragstart',
|
|
15
|
-
// 'drag',
|
|
16
|
-
// 'add',
|
|
17
|
-
// 'remove',
|
|
18
|
-
// 'loading',
|
|
19
|
-
// 'error',
|
|
20
|
-
// 'update',
|
|
21
|
-
// 'down',
|
|
22
|
-
// 'predrag'
|
|
23
|
-
// ] as const;
|
|
24
|
-
// export const resizeEvents = ['resize'] as const;
|
|
25
|
-
// export const zoomAnimEvents = ['zoomanim'] as const;
|
|
26
|
-
// export const tileEvents = ['tileunload', 'tileloadstart', 'tileload', 'tileabort'] as const;
|
|
27
|
-
// export const tileErrorEvents = ['tileerror'] as const;
|
|
28
|
-
export const interactiveLayerEvents = [
|
|
29
|
-
'click',
|
|
30
|
-
'dblclick',
|
|
31
|
-
'mousedown',
|
|
32
|
-
'mouseup',
|
|
33
|
-
'mouseover',
|
|
34
|
-
'mouseout',
|
|
35
|
-
'contextmenu'
|
|
36
|
-
];
|
|
37
|
-
export const keyboardEvents = ['keypress', 'keydown', 'keyup'];
|
|
38
|
-
export const locationEvents = ['locationfound', 'locationerror'];
|
|
39
|
-
export const leafletMouseEvents = [...interactiveLayerEvents, 'mousemove', 'preclick'];
|
|
40
|
-
export const layerEvents = ['add', 'remove'];
|
|
41
|
-
export const popupEvents = ['popupopen', 'popupclose'];
|
|
42
|
-
export const tooltipEvents = ['tooltipopen', 'tooltipclose'];
|
|
43
|
-
export const layerGroupEvents = ['layeradd', 'layerremove'];
|
|
44
|
-
export const layersControlEvents = ['baselayerchange', 'overlayadd', 'overlayremove'];
|
|
45
|
-
const leafletEvents = [
|
|
46
|
-
'load',
|
|
47
|
-
'move',
|
|
48
|
-
'moveend',
|
|
49
|
-
'movestart',
|
|
50
|
-
'unload',
|
|
51
|
-
'viewreset',
|
|
52
|
-
'zoom',
|
|
53
|
-
'zoomend',
|
|
54
|
-
'zoomlevelschange',
|
|
55
|
-
'zoomstart'
|
|
56
|
-
];
|
|
57
|
-
export const mapStateChangeEvents = [...leafletEvents, 'resize'];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Map as LeafletMap, MapOptions } from 'leaflet';
|
|
2
|
+
import { type CreateSvelteEventsMap } from './utils.js';
|
|
3
|
+
export declare function updateMapProps(instance: LeafletMap, newProps: MapOptions): void;
|
|
4
|
+
export declare const mapEvents: readonly ["keypress", "keydown", "keyup", "layeradd", "layerremove", "baselayerchange", "overlayadd", "overlayremove", "click", "dblclick", "mousedown", "mouseup", "mouseover", "mouseout", "contextmenu", "mousemove", "preclick", "locationfound", "locationerror", "load", "move", "moveend", "movestart", "unload", "viewreset", "zoom", "zoomend", "zoomlevelschange", "zoomstart", "resize", "popupopen", "popupclose", "tooltipopen", "tooltipclose", "autopanstart", "zoomanim"];
|
|
5
|
+
export type MapEvents = CreateSvelteEventsMap<typeof mapEvents, LeafletMap>;
|
|
6
|
+
declare module 'leaflet' {
|
|
7
|
+
interface Handler {
|
|
8
|
+
_setPanDelta(delta: number): void;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { capitalize } from './utils.js';
|
|
2
|
+
import { keyboardEvents, layerGroupEvents, layersControlEvents, leafletMouseEvents, locationEvents, mapStateChangeEvents, popupSpecificEvents, tooltipEvents, } from './events.js';
|
|
3
|
+
// stores the function bound to the event listener so it can be removed later
|
|
4
|
+
let boundInvalidateMapSize = null;
|
|
5
|
+
function invalidateMapSize(map) {
|
|
6
|
+
map.invalidateSize({
|
|
7
|
+
// TODO : add a way to customize these default values
|
|
8
|
+
debounceMoveend: true,
|
|
9
|
+
pan: true,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function updateMapProps(instance, newProps) {
|
|
13
|
+
if (!newProps)
|
|
14
|
+
return;
|
|
15
|
+
// any is the default type for the Object.entries values anyway
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
for (const [key, value] of Object.entries(newProps)) {
|
|
18
|
+
// skip if the option value is unchanged
|
|
19
|
+
if (instance.options[key] === value)
|
|
20
|
+
continue;
|
|
21
|
+
// update the option value :
|
|
22
|
+
// - needed for future comparison (CF above)
|
|
23
|
+
// - handles simple cases :
|
|
24
|
+
// untested :
|
|
25
|
+
// closePopupOnClick markerZoomAnimation tapTolerance worldCopyJump(untested)
|
|
26
|
+
// tested :
|
|
27
|
+
// bounceAtZoomLimits preferCanvas
|
|
28
|
+
// easeLinearity transform3DLimit
|
|
29
|
+
// inertia wheelDebounceTime
|
|
30
|
+
// inertiaDeceleration zoomAnimationThreshold
|
|
31
|
+
// inertiaMaxSpeed zoomDelta
|
|
32
|
+
// maxBoundsViscosity zoomSnap
|
|
33
|
+
instance.options[key] = value;
|
|
34
|
+
switch (key) {
|
|
35
|
+
// TODO : move check of unsupported options before the unchanged check
|
|
36
|
+
case 'fadeAnimation':
|
|
37
|
+
case 'zoomAnimation':
|
|
38
|
+
case 'wheelPxPerZoomLevel':
|
|
39
|
+
case 'crs':
|
|
40
|
+
case 'layers':
|
|
41
|
+
case 'renderer':
|
|
42
|
+
// animations could be hacked around by changing style attributes
|
|
43
|
+
// not a priority
|
|
44
|
+
throw new Error(`mutation of ${key} option is not supported`);
|
|
45
|
+
// setters cases
|
|
46
|
+
case 'maxBounds':
|
|
47
|
+
case 'minZoom':
|
|
48
|
+
case 'maxZoom':
|
|
49
|
+
case 'zoom': {
|
|
50
|
+
const setterName = `set${capitalize(key)}`;
|
|
51
|
+
const setter = instance[setterName].bind(instance);
|
|
52
|
+
setter(value);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
// enable/disable cases (Handlers)
|
|
56
|
+
case 'boxZoom':
|
|
57
|
+
case 'scrollWheelZoom':
|
|
58
|
+
case 'doubleClickZoom':
|
|
59
|
+
case 'dragging':
|
|
60
|
+
case 'keyboard':
|
|
61
|
+
case 'tapHold':
|
|
62
|
+
case 'touchZoom': // untested
|
|
63
|
+
if (value)
|
|
64
|
+
instance[key]?.enable();
|
|
65
|
+
else
|
|
66
|
+
instance[key]?.disable();
|
|
67
|
+
break;
|
|
68
|
+
// Control cases
|
|
69
|
+
case 'zoomControl':
|
|
70
|
+
if (value) {
|
|
71
|
+
instance.zoomControl = instance.zoomControl || window.L.control.zoom();
|
|
72
|
+
instance.zoomControl.addTo(instance);
|
|
73
|
+
}
|
|
74
|
+
else
|
|
75
|
+
instance.zoomControl?.remove();
|
|
76
|
+
break;
|
|
77
|
+
case 'attributionControl':
|
|
78
|
+
if (value) {
|
|
79
|
+
instance.attributionControl =
|
|
80
|
+
instance.attributionControl || window.L.control.attribution();
|
|
81
|
+
instance.attributionControl.addTo(instance);
|
|
82
|
+
}
|
|
83
|
+
else
|
|
84
|
+
instance.attributionControl?.remove();
|
|
85
|
+
break;
|
|
86
|
+
//complex cases
|
|
87
|
+
case 'center':
|
|
88
|
+
instance.setView(value, instance.getZoom());
|
|
89
|
+
break;
|
|
90
|
+
case 'keyboardPanDelta':
|
|
91
|
+
// seems fine despite using a private method
|
|
92
|
+
instance.keyboard._setPanDelta(value);
|
|
93
|
+
break;
|
|
94
|
+
case 'trackResize':
|
|
95
|
+
if (boundInvalidateMapSize === null)
|
|
96
|
+
boundInvalidateMapSize = invalidateMapSize.bind(null, instance);
|
|
97
|
+
window.removeEventListener('resize', boundInvalidateMapSize);
|
|
98
|
+
if (value) {
|
|
99
|
+
window.addEventListener('resize', boundInvalidateMapSize);
|
|
100
|
+
invalidateMapSize(instance);
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export const mapEvents = [
|
|
107
|
+
...keyboardEvents,
|
|
108
|
+
...layerGroupEvents,
|
|
109
|
+
...layersControlEvents,
|
|
110
|
+
...leafletMouseEvents,
|
|
111
|
+
...locationEvents,
|
|
112
|
+
...mapStateChangeEvents,
|
|
113
|
+
...popupSpecificEvents,
|
|
114
|
+
...tooltipEvents,
|
|
115
|
+
'autopanstart',
|
|
116
|
+
'zoomanim',
|
|
117
|
+
];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Marker as LeafletMarker, MarkerOptions } from 'leaflet';
|
|
2
|
+
import { type CreateSvelteEventsMap } from './utils.js';
|
|
3
|
+
export declare function updateMarkerProps(instance: LeafletMarker, options: MarkerOptions): void;
|
|
4
|
+
export declare const markerEvents: readonly ["move", "dragstart", "movestart", "drag", "dragend", "moveend", "click", "dblclick", "mousedown", "mouseup", "mouseover", "mouseout", "contextmenu", "add", "remove", "popupopen", "popupclose", "tooltipopen", "tooltipclose"];
|
|
5
|
+
export type MarkerEvents = CreateSvelteEventsMap<typeof markerEvents, LeafletMarker>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { capitalize } from './utils.js';
|
|
2
|
+
import { draggingEvents, interactiveLayerEvents, layerEvents, popupSpecificEvents, tooltipEvents, } from './events.js';
|
|
3
|
+
// const L = globalThis.window.L;
|
|
4
|
+
export function updateMarkerProps(instance, options) {
|
|
5
|
+
if (!options)
|
|
6
|
+
return;
|
|
7
|
+
for (const [key, value] of Object.entries(options)) {
|
|
8
|
+
// skip if the option value is unchanged
|
|
9
|
+
if (instance.options[key] === value)
|
|
10
|
+
continue;
|
|
11
|
+
// update the option value :
|
|
12
|
+
// - needed for future comparison (CF above)
|
|
13
|
+
// - handles simple cases
|
|
14
|
+
// bubblingMouseEvents riseOffset autoPanPadding
|
|
15
|
+
// autoPanSpeed
|
|
16
|
+
instance.options[key] = value;
|
|
17
|
+
switch (key) {
|
|
18
|
+
// setter cases
|
|
19
|
+
case 'icon': // untested
|
|
20
|
+
case 'zIndexOffset':
|
|
21
|
+
case 'opacity': {
|
|
22
|
+
const setterName = `set${capitalize(key)}`;
|
|
23
|
+
const setter = instance[setterName].bind(instance);
|
|
24
|
+
setter(value);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
// complex cases
|
|
28
|
+
case 'title':
|
|
29
|
+
instance.getElement()?.setAttribute('title', value);
|
|
30
|
+
break;
|
|
31
|
+
case 'alt':
|
|
32
|
+
instance.getElement()?.setAttribute('alt', value);
|
|
33
|
+
break;
|
|
34
|
+
case 'draggable':
|
|
35
|
+
// option and handler are named differently
|
|
36
|
+
if (value)
|
|
37
|
+
instance.dragging?.enable();
|
|
38
|
+
else
|
|
39
|
+
instance.dragging?.disable();
|
|
40
|
+
break;
|
|
41
|
+
// TODO : move check of unsupported options before the unchanged check
|
|
42
|
+
case 'keyboard':
|
|
43
|
+
case 'riseOnHover':
|
|
44
|
+
case 'shadowPane':
|
|
45
|
+
case 'autoPan':
|
|
46
|
+
case 'autoPanOnFocus':
|
|
47
|
+
case 'interactive':
|
|
48
|
+
case 'pane':
|
|
49
|
+
case 'attribution':
|
|
50
|
+
throw new Error(`mutation of ${key} option is not supported`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export const markerEvents = [
|
|
55
|
+
'move',
|
|
56
|
+
...draggingEvents,
|
|
57
|
+
...interactiveLayerEvents,
|
|
58
|
+
...layerEvents,
|
|
59
|
+
...popupSpecificEvents,
|
|
60
|
+
...tooltipEvents,
|
|
61
|
+
];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type MarkerEvents } from './marker.svelte.js';
|
|
2
|
+
import type { CreateSvelteEventsMap } from './utils.js';
|
|
3
|
+
type ClusterifyMarkerEvent<E> = E extends `on${infer N}` ? `oncluster${N}` : never;
|
|
4
|
+
declare const clusterSpecificEvents: readonly ["animationend", "spiderfied", "unspiderfied"];
|
|
5
|
+
export declare const markerClusterGroupEvents: readonly [...("clustermovestart" | "clustermove" | "clustermoveend" | "clusterdragstart" | "clusterdrag" | "clusteradd" | "clusterremove" | "clusterpopupopen" | "clusterpopupclose" | "clustertooltipopen" | "clustertooltipclose" | "clusterclick" | "clusterdblclick" | "clustermousedown" | "clustermouseup" | "clustermouseover" | "clustermouseout" | "clustercontextmenu" | "clusterdragend")[], "animationend", "spiderfied", "unspiderfied"];
|
|
6
|
+
export type MarkerClusterGroupEvents = {
|
|
7
|
+
[K in keyof MarkerEvents as ClusterifyMarkerEvent<K>]: MarkerEvents[K];
|
|
8
|
+
} & CreateSvelteEventsMap<typeof clusterSpecificEvents>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { markerEvents } from './marker.svelte.js';
|
|
2
|
+
const clusteredMarkerEvents = markerEvents.map((event) => `cluster${event}`);
|
|
3
|
+
const clusterSpecificEvents = ['animationend', 'spiderfied', 'unspiderfied'];
|
|
4
|
+
export const markerClusterGroupEvents = [
|
|
5
|
+
...clusteredMarkerEvents,
|
|
6
|
+
...clusterSpecificEvents,
|
|
7
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CreateSvelteEventsMap } from './utils.js';
|
|
2
|
+
import type { Polygon as LeafletPolygon, Polyline as LeafletPolyline, PolylineOptions } from 'leaflet';
|
|
3
|
+
export declare function updatePolylineProps(instance: LeafletPolygon | LeafletPolyline, options: PolylineOptions): void;
|
|
4
|
+
export declare const polygonEvents: readonly ["click", "dblclick", "mousedown", "mouseup", "mouseover", "mouseout", "contextmenu", "add", "remove", "popupopen", "popupclose", "tooltipopen", "tooltipclose"];
|
|
5
|
+
export type PolygonEvents = CreateSvelteEventsMap<typeof polygonEvents, LeafletPolygon>;
|
|
6
|
+
export type PolylineEvents = CreateSvelteEventsMap<typeof polygonEvents, LeafletPolyline>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { interactiveLayerEvents, layerEvents, popupSpecificEvents, tooltipEvents, } from './events.js';
|
|
2
|
+
export function updatePolylineProps(instance, options) {
|
|
3
|
+
if (!options)
|
|
4
|
+
return;
|
|
5
|
+
for (const [key, value] of Object.entries(options)) {
|
|
6
|
+
// skip if the option value is unchanged
|
|
7
|
+
const oldValue = instance.options[key];
|
|
8
|
+
if (oldValue === value)
|
|
9
|
+
continue;
|
|
10
|
+
// update the option value :
|
|
11
|
+
// - needed for future comparison (CF above)
|
|
12
|
+
// - handles simple cases
|
|
13
|
+
// bubblingMouseEvents riseOffset autoPanPadding
|
|
14
|
+
// autoPanSpeed
|
|
15
|
+
instance.options[key] = value;
|
|
16
|
+
switch (key) {
|
|
17
|
+
case 'smoothFactor':
|
|
18
|
+
case 'noClip':
|
|
19
|
+
case 'renderer':
|
|
20
|
+
case 'interactive':
|
|
21
|
+
case 'bubblingMouseEvents':
|
|
22
|
+
case 'pane':
|
|
23
|
+
case 'attribution':
|
|
24
|
+
throw new Error(`mutation of ${key} option is not supported`);
|
|
25
|
+
case 'className':
|
|
26
|
+
if (value === '')
|
|
27
|
+
instance.getElement()?.classList.remove(oldValue);
|
|
28
|
+
else if (oldValue === '')
|
|
29
|
+
instance.getElement()?.classList.add(value);
|
|
30
|
+
else
|
|
31
|
+
instance.getElement()?.classList.replace(oldValue, value);
|
|
32
|
+
break;
|
|
33
|
+
// setStyle case
|
|
34
|
+
case 'stroke':
|
|
35
|
+
case 'color':
|
|
36
|
+
case 'weight':
|
|
37
|
+
case 'opacity':
|
|
38
|
+
case 'lineCap':
|
|
39
|
+
case 'lineJoin':
|
|
40
|
+
case 'dashArray':
|
|
41
|
+
case 'dashOffset':
|
|
42
|
+
case 'fill':
|
|
43
|
+
case 'fillColor':
|
|
44
|
+
case 'fillOpacity':
|
|
45
|
+
case 'fillRule':
|
|
46
|
+
instance.setStyle(options);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export const polygonEvents = [
|
|
52
|
+
...interactiveLayerEvents,
|
|
53
|
+
...layerEvents,
|
|
54
|
+
...popupSpecificEvents,
|
|
55
|
+
...tooltipEvents,
|
|
56
|
+
];
|