@radiofrance/svelte-leaflet 0.1.0-alpha.8 → 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 +129 -46
- 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 -12
- package/dist/MarkerClusterGroup.svelte.d.ts +69 -19
- 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 +19 -8
- package/dist/index.js +16 -6
- 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 -26
- package/dist/Circle.svelte.d.ts +0 -22
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,8 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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;
|
|
19
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
// Reexport your entry components here
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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) {
|
|
11
|
+
events.forEach((event) => {
|
|
12
|
+
const eventCallback = eventsProps[`on${event}`];
|
|
13
|
+
if (typeof eventCallback !== 'function')
|
|
14
|
+
return;
|
|
15
|
+
instance.on(event, (e) => eventCallback(e));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -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
|
+
];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Popup as LeafletPopup, PopupOptions } from 'leaflet';
|
|
2
|
+
import type { CreateSvelteEventsMap } from './utils.js';
|
|
3
|
+
export declare function updatePopupProps(instance: LeafletPopup, options: PopupOptions): void;
|
|
4
|
+
export declare const popupEvents: readonly ["click", "dblclick", "mousedown", "mouseup", "mouseover", "mouseout", "contextmenu", "add", "remove", "popupopen", "popupclose", "tooltipopen", "tooltipclose"];
|
|
5
|
+
export type PopupEvents = CreateSvelteEventsMap<typeof popupEvents, LeafletPopup>;
|
|
6
|
+
declare module 'leaflet' {
|
|
7
|
+
interface Popup {
|
|
8
|
+
_source: Layer;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { interactiveLayerEvents, layerEvents, popupSpecificEvents, tooltipEvents, } from './events.js';
|
|
2
|
+
export function updatePopupProps(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
|
+
if (instance.options[key] === value)
|
|
8
|
+
continue;
|
|
9
|
+
// update the option value :
|
|
10
|
+
// - needed for future comparison (CF above)
|
|
11
|
+
// - handles simple cases
|
|
12
|
+
// bubblingMouseEvents riseOffset autoPanPadding
|
|
13
|
+
// autoPanSpeed
|
|
14
|
+
instance.options[key] = value;
|
|
15
|
+
switch (key) {
|
|
16
|
+
// unhandled
|
|
17
|
+
case 'className':
|
|
18
|
+
case 'interactive':
|
|
19
|
+
case 'closeButton':
|
|
20
|
+
case 'pane':
|
|
21
|
+
throw new Error(`mutation of ${key} option is not supported`);
|
|
22
|
+
// needs to reopen the popup
|
|
23
|
+
case 'keepInView':
|
|
24
|
+
case 'autoPan':
|
|
25
|
+
case 'autoClose':
|
|
26
|
+
case 'closeOnClick':
|
|
27
|
+
case 'closeOnEscapeKey':
|
|
28
|
+
case 'maxWidth':
|
|
29
|
+
case 'minWidth':
|
|
30
|
+
case 'maxHeight':
|
|
31
|
+
case 'offset':
|
|
32
|
+
if (instance.isOpen()) {
|
|
33
|
+
const source = instance._source;
|
|
34
|
+
source.closePopup();
|
|
35
|
+
source.openPopup();
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
case 'content':
|
|
39
|
+
instance.setContent(value);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export const popupEvents = [
|
|
45
|
+
// 'contentupdate', // needs @types/leaflet PR ?
|
|
46
|
+
...interactiveLayerEvents,
|
|
47
|
+
...layerEvents,
|
|
48
|
+
...popupSpecificEvents,
|
|
49
|
+
...tooltipEvents,
|
|
50
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import GeolocationIcon from './GeolocationIcon.svelte';
|
|
4
|
+
import { FOCUSABLE } from '../contexts.js';
|
|
5
|
+
|
|
6
|
+
const tabindex = getContext<-1 | null>(FOCUSABLE);
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<div>
|
|
10
|
+
<button {tabindex}>
|
|
11
|
+
<GeolocationIcon width="1rem" />
|
|
12
|
+
</button>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<style>
|
|
16
|
+
button {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
width: 30px;
|
|
21
|
+
height: 30px;
|
|
22
|
+
background-color: white;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
border: none;
|
|
25
|
+
border-radius: 2px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
button:hover {
|
|
29
|
+
background-color: #f4f4f4;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
div {
|
|
33
|
+
border-radius: 4px;
|
|
34
|
+
border: 2px solid rgba(0, 0, 0, 0.2);
|
|
35
|
+
}
|
|
36
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const GeolocationButton: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
}, {}, {}, string>;
|
|
17
|
+
type GeolocationButton = InstanceType<typeof GeolocationButton>;
|
|
18
|
+
export default GeolocationButton;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
interface Props {
|
|
3
|
+
width?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
let { width = '32px' }: Props = $props();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<svg
|
|
10
|
+
{width}
|
|
11
|
+
viewBox="0 0 16 16"
|
|
12
|
+
version="1.1"
|
|
13
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
14
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
15
|
+
fill="#000000"
|
|
16
|
+
>
|
|
17
|
+
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
|
|
18
|
+
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
|
|
19
|
+
<g id="SVGRepo_iconCarrier">
|
|
20
|
+
<rect width="16" height="16" id="icon-bound" fill="none"></rect>
|
|
21
|
+
<path
|
|
22
|
+
d="M13.916,7C13.494,4.488,11.512,2.506,9,2.084V0H7v2.084C4.488,2.506,2.506,4.488,2.084,7H0v2h2.084 C2.506,11.512,4.488,13.494,7,13.916V16h2v-2.084c2.512-0.422,4.494-2.403,4.916-4.916H16V7H13.916z M10.828,10.828 C10.072,11.584,9.069,12,8,12s-2.072-0.416-2.828-1.172S4,9.069,4,8s0.416-2.072,1.172-2.828S6.931,4,8,4s2.072,0.416,2.828,1.172 S12,6.931,12,8S11.584,10.072,10.828,10.828z M8,6C6.897,6,6,6.897,6,8s0.897,2,2,2s2-0.897,2-2S9.103,6,8,6z"
|
|
23
|
+
></path>
|
|
24
|
+
</g>
|
|
25
|
+
</svg>
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LeafletEventHandlerFnMap } from 'leaflet';
|
|
2
|
+
export declare function capitalize<T extends string>(str: T): Capitalize<T>;
|
|
3
|
+
export declare function getFirstNonCommentChild(element: HTMLElement): HTMLElement | null;
|
|
4
|
+
export type PickOptionByType<Options, Type> = keyof {
|
|
5
|
+
[K in keyof Options as true extends UnionContainsType<Options[K], Type> ? K : never]: Options[K];
|
|
6
|
+
};
|
|
7
|
+
export type UnionContainsType<Union, Type> = Union extends Type ? true : never;
|
|
8
|
+
export type CreateSvelteEventsMap<EventNames extends readonly (keyof LeafletEventHandlerFnMap)[], SourceTarget = null> = {
|
|
9
|
+
[K in EventNames[number] as `on${K}`]?: SourceTarget extends null ? LeafletEventHandlerFnMap[K] : (e: Omit<Parameters<Exclude<LeafletEventHandlerFnMap[K], undefined>>[0], 'sourceTarget'> & {
|
|
10
|
+
sourceTarget: SourceTarget;
|
|
11
|
+
}) => void;
|
|
12
|
+
};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function capitalize(str) {
|
|
2
|
+
return (str[0].toUpperCase() + str.slice(1));
|
|
3
|
+
}
|
|
4
|
+
export function getFirstNonCommentChild(element) {
|
|
5
|
+
let child = element.firstChild;
|
|
6
|
+
while (child && child.nodeType !== Node.ELEMENT_NODE) {
|
|
7
|
+
child = child.nextSibling;
|
|
8
|
+
}
|
|
9
|
+
return child;
|
|
10
|
+
}
|