@radiofrance/svelte-leaflet 0.1.0-alpha.9 → 1.0.0-next.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.
- 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 +22 -53
- package/dist/index.js +14 -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 +15 -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/Marker.svelte
CHANGED
|
@@ -1,74 +1,72 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onDestroy, onMount, setContext, type Snippet } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
Map as LeafletMap,
|
|
5
|
+
Marker as LeafletMarker,
|
|
6
|
+
MarkerOptions,
|
|
7
|
+
LayerGroup,
|
|
8
|
+
MarkerClusterGroup,
|
|
9
|
+
} from 'leaflet';
|
|
10
|
+
import { bindEvents, type LatLngExpression } from './index.js';
|
|
11
|
+
import { markerEvents, updateMarkerProps, type MarkerEvents } from './marker.svelte.js';
|
|
12
|
+
import { LAYERGROUP, MAP, MARKER } from './contexts.js';
|
|
2
13
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
marker = L.marker(latlng2, options2);
|
|
28
|
-
marker.id = id2;
|
|
29
|
-
marker.on("click", (e) => dispatch("click", e)).on("dblclick", (e) => dispatch("dblclick", e)).on("contextmenu", (e) => dispatch("contextmenu", e)).on("dragstart", (e) => dispatch("dragstart", e)).on("drag", (e) => dispatch("drag", e)).on("dragend", (e) => dispatch("dragend", e));
|
|
30
|
-
mapOrLayerGroup.addLayer(marker);
|
|
31
|
-
await tick();
|
|
32
|
-
if (markerElement.childElementCount > 0) {
|
|
33
|
-
marker.setIcon(
|
|
34
|
-
L.divIcon({
|
|
35
|
-
html: markerElement,
|
|
36
|
-
className: "map-marker",
|
|
37
|
-
iconSize: L.point(size2, size2)
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function removeMarker() {
|
|
43
|
-
if (!marker)
|
|
44
|
-
return;
|
|
45
|
-
const layerGroup = getLayerGroup?.();
|
|
46
|
-
const map = getMap();
|
|
47
|
-
const mapOrLayerGroup = layerGroup || map;
|
|
48
|
-
mapOrLayerGroup.removeLayer(marker);
|
|
49
|
-
}
|
|
50
|
-
onDestroy(() => {
|
|
51
|
-
removeMarker();
|
|
52
|
-
});
|
|
53
|
-
</script>
|
|
14
|
+
type Props = {
|
|
15
|
+
latlng: LatLngExpression;
|
|
16
|
+
options?: MarkerOptions;
|
|
17
|
+
instance?: LeafletMarker;
|
|
18
|
+
children?: Snippet;
|
|
19
|
+
} & MarkerEvents;
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
latlng,
|
|
23
|
+
options = $bindable(),
|
|
24
|
+
instance = $bindable(),
|
|
25
|
+
children,
|
|
26
|
+
...restProps
|
|
27
|
+
}: Props = $props();
|
|
28
|
+
|
|
29
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
30
|
+
const getLayerGroup = getContext<() => LayerGroup | MarkerClusterGroup>(LAYERGROUP);
|
|
31
|
+
setContext(MARKER, () => instance);
|
|
32
|
+
|
|
33
|
+
$effect(() => {
|
|
34
|
+
if (instance && options) {
|
|
35
|
+
updateMarkerProps(instance, options);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
54
38
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</div>
|
|
61
|
-
<slot />
|
|
62
|
-
{/if}
|
|
63
|
-
{/key}
|
|
64
|
-
</template>
|
|
39
|
+
$effect(() => {
|
|
40
|
+
if (!instance?.getLatLng().equals(latlng)) {
|
|
41
|
+
instance?.setLatLng(latlng);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
65
44
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
45
|
+
onMount(() => {
|
|
46
|
+
const markerOptions = { ...options };
|
|
47
|
+
instance = window.L.marker(latlng, markerOptions);
|
|
48
|
+
bindEvents(instance, restProps, markerEvents);
|
|
49
|
+
|
|
50
|
+
const map = getMap();
|
|
51
|
+
const layerGroup = getLayerGroup?.();
|
|
52
|
+
const mapOrLayerGroup = layerGroup || map;
|
|
53
|
+
instance.addTo(mapOrLayerGroup);
|
|
54
|
+
mapOrLayerGroup.remove;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
onDestroy(() => {
|
|
58
|
+
const layerGroup = getLayerGroup?.();
|
|
59
|
+
const map = getMap();
|
|
60
|
+
if (instance) {
|
|
61
|
+
if (layerGroup) {
|
|
62
|
+
layerGroup.removeLayer(instance);
|
|
63
|
+
} else {
|
|
64
|
+
map.removeLayer(instance);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
</script>
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
</style>
|
|
70
|
+
{#if instance && children}
|
|
71
|
+
{@render children()}
|
|
72
|
+
{/if}
|
package/dist/Marker.svelte.d.ts
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
options?: MarkerOptions | undefined;
|
|
13
|
-
};
|
|
14
|
-
events: {
|
|
15
|
-
click: CustomEvent<any>;
|
|
16
|
-
dblclick: CustomEvent<any>;
|
|
17
|
-
contextmenu: CustomEvent<any>;
|
|
18
|
-
dragstart: CustomEvent<any>;
|
|
19
|
-
drag: CustomEvent<any>;
|
|
20
|
-
dragend: CustomEvent<any>;
|
|
21
|
-
} & {
|
|
22
|
-
[evt: string]: CustomEvent<any>;
|
|
23
|
-
};
|
|
24
|
-
slots: {
|
|
25
|
-
icon: {};
|
|
26
|
-
default: {};
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
export type MarkerProps = typeof __propDef.props;
|
|
30
|
-
export type MarkerEvents = typeof __propDef.events;
|
|
31
|
-
export type MarkerSlots = typeof __propDef.slots;
|
|
32
|
-
export default class Marker extends SvelteComponent<MarkerProps, MarkerEvents, MarkerSlots> {
|
|
33
|
-
}
|
|
34
|
-
export {};
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { Marker as LeafletMarker, MarkerOptions } from 'leaflet';
|
|
3
|
+
import { type LatLngExpression } from './index.js';
|
|
4
|
+
import { type MarkerEvents } from './marker.svelte.js';
|
|
5
|
+
declare const Marker: import("svelte").Component<{
|
|
6
|
+
latlng: LatLngExpression;
|
|
7
|
+
options?: MarkerOptions;
|
|
8
|
+
instance?: LeafletMarker;
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
} & MarkerEvents, {}, "instance" | "options">;
|
|
11
|
+
export default Marker;
|
|
@@ -1,44 +1,75 @@
|
|
|
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
|
-
}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
getContext,
|
|
4
|
+
mount,
|
|
5
|
+
onDestroy,
|
|
6
|
+
onMount,
|
|
7
|
+
setContext,
|
|
8
|
+
type Component,
|
|
9
|
+
type Snippet,
|
|
10
|
+
} from 'svelte';
|
|
11
|
+
import type {
|
|
12
|
+
MarkerClusterGroup as LeafletMarkerClusterGroup,
|
|
13
|
+
LayerGroup as LeafletLayerGroup,
|
|
14
|
+
MarkerClusterGroupOptions,
|
|
15
|
+
LeafletEventHandlerFnMap,
|
|
16
|
+
MarkerCluster,
|
|
17
|
+
} from 'leaflet';
|
|
18
|
+
import { LAYERGROUP, MAP } from './contexts.js';
|
|
19
|
+
import {
|
|
20
|
+
markerClusterGroupEvents,
|
|
21
|
+
type MarkerClusterGroupEvents,
|
|
22
|
+
} from './markerClusterGroup.svelte.js';
|
|
23
|
+
import { bindEvents } from './index.js';
|
|
24
|
+
|
|
25
|
+
type Props = {
|
|
26
|
+
icon?: Component<{ count: number }>;
|
|
27
|
+
instance?: LeafletMarkerClusterGroup;
|
|
28
|
+
options?: MarkerClusterGroupOptions;
|
|
29
|
+
children?: Snippet;
|
|
30
|
+
} & MarkerClusterGroupEvents;
|
|
31
|
+
|
|
32
|
+
let { instance = $bindable(), options, children, icon, ...restProps }: Props = $props();
|
|
33
|
+
|
|
34
|
+
const getMap = getContext<() => L.Map>(MAP);
|
|
35
|
+
const getLayerGroup = getContext<() => LeafletLayerGroup>(LAYERGROUP);
|
|
36
|
+
|
|
37
|
+
setContext(LAYERGROUP, () => instance);
|
|
38
|
+
|
|
39
|
+
onMount(() => {
|
|
40
|
+
const map = getMap?.();
|
|
41
|
+
const layerGroup = getLayerGroup?.();
|
|
42
|
+
const context = layerGroup || map;
|
|
43
|
+
|
|
44
|
+
const mergedOptions = { ...options };
|
|
45
|
+
if (icon) {
|
|
46
|
+
mergedOptions.iconCreateFunction = (cluster: MarkerCluster) => {
|
|
47
|
+
const mountTarget = document.createElement('div');
|
|
48
|
+
mountTarget.classList.add('MOUNTTARGET');
|
|
49
|
+
mount(icon, {
|
|
50
|
+
target: mountTarget,
|
|
51
|
+
props: { count: cluster.getChildCount() },
|
|
52
|
+
});
|
|
53
|
+
const html = mountTarget.innerHTML;
|
|
54
|
+
return window.L.divIcon({ html });
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
instance = window.L.markerClusterGroup(mergedOptions);
|
|
59
|
+
context.addLayer(instance);
|
|
60
|
+
bindEvents(
|
|
61
|
+
instance,
|
|
62
|
+
restProps,
|
|
63
|
+
// TODO : find a better way to type this
|
|
64
|
+
markerClusterGroupEvents as unknown as readonly (keyof LeafletEventHandlerFnMap)[],
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
onDestroy(() => {
|
|
69
|
+
instance?.clearLayers();
|
|
70
|
+
});
|
|
27
71
|
</script>
|
|
28
72
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<slot name="icon" />
|
|
33
|
-
</div>
|
|
34
|
-
</template>
|
|
35
|
-
|
|
36
|
-
<style>
|
|
37
|
-
.leaflet-markercluster {
|
|
38
|
-
display: none;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
:global(.map-marker .leaflet-markercluster) {
|
|
42
|
-
display: inherit;
|
|
43
|
-
}
|
|
44
|
-
</style>
|
|
73
|
+
{#if instance && children}
|
|
74
|
+
{@render children()}
|
|
75
|
+
{/if}
|
|
@@ -1,21 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { MarkerClusterGroupOptions } from 'leaflet';
|
|
3
|
-
declare const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { type Component, type Snippet } from 'svelte';
|
|
2
|
+
import type { MarkerClusterGroup as LeafletMarkerClusterGroup, MarkerClusterGroupOptions } from 'leaflet';
|
|
3
|
+
declare const MarkerClusterGroup: Component<{
|
|
4
|
+
icon?: Component<{
|
|
5
|
+
count: number;
|
|
6
|
+
}>;
|
|
7
|
+
instance?: LeafletMarkerClusterGroup;
|
|
8
|
+
options?: MarkerClusterGroupOptions;
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
} & {
|
|
11
|
+
onclustermovestart?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
12
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
13
|
+
}) => void) | undefined;
|
|
14
|
+
onclustermove?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
15
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
16
|
+
}) => void) | undefined;
|
|
17
|
+
onclustermoveend?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
18
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
19
|
+
}) => void) | undefined;
|
|
20
|
+
onclusterdragstart?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
21
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
22
|
+
}) => void) | undefined;
|
|
23
|
+
onclusterdrag?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
24
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
25
|
+
}) => void) | undefined;
|
|
26
|
+
onclusteradd?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
27
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
28
|
+
}) => void) | undefined;
|
|
29
|
+
onclusterremove?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
30
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
31
|
+
}) => void) | undefined;
|
|
32
|
+
onclusterpopupopen?: ((e: Omit<import("leaflet").PopupEvent, "sourceTarget"> & {
|
|
33
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
34
|
+
}) => void) | undefined;
|
|
35
|
+
onclusterpopupclose?: ((e: Omit<import("leaflet").PopupEvent, "sourceTarget"> & {
|
|
36
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
37
|
+
}) => void) | undefined;
|
|
38
|
+
onclustertooltipopen?: ((e: Omit<import("leaflet").TooltipEvent, "sourceTarget"> & {
|
|
39
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
40
|
+
}) => void) | undefined;
|
|
41
|
+
onclustertooltipclose?: ((e: Omit<import("leaflet").TooltipEvent, "sourceTarget"> & {
|
|
42
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
43
|
+
}) => void) | undefined;
|
|
44
|
+
onclusterclick?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
45
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
46
|
+
}) => void) | undefined;
|
|
47
|
+
onclusterdblclick?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
48
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
49
|
+
}) => void) | undefined;
|
|
50
|
+
onclustermousedown?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
51
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
52
|
+
}) => void) | undefined;
|
|
53
|
+
onclustermouseup?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
54
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
55
|
+
}) => void) | undefined;
|
|
56
|
+
onclustermouseover?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
57
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
58
|
+
}) => void) | undefined;
|
|
59
|
+
onclustermouseout?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
60
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
61
|
+
}) => void) | undefined;
|
|
62
|
+
onclustercontextmenu?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
63
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
64
|
+
}) => void) | undefined;
|
|
65
|
+
onclusterdragend?: ((e: Omit<import("leaflet").DragEndEvent, "sourceTarget"> & {
|
|
66
|
+
sourceTarget: import("leaflet").Marker<any>;
|
|
67
|
+
}) => void) | undefined;
|
|
68
|
+
} & import("./utils.js").CreateSvelteEventsMap<readonly ["animationend", "spiderfied", "unspiderfied"]>, {}, "instance">;
|
|
69
|
+
export default MarkerClusterGroup;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onDestroy, onMount } from 'svelte';
|
|
3
|
+
import type { Polygon as LeafletPolygon, PolylineOptions, LayerGroup } from 'leaflet';
|
|
4
|
+
import { polygonEvents, updatePolylineProps, type PolygonEvents } from './polyline.svelte.js';
|
|
5
|
+
import { bindEvents, type Latlngs, type LeafletMap } from './index.js';
|
|
6
|
+
import { LAYERGROUP, MAP } from './contexts.js';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
latlngs: Latlngs<3>;
|
|
10
|
+
instance?: LeafletPolygon;
|
|
11
|
+
options?: PolylineOptions;
|
|
12
|
+
} & PolygonEvents;
|
|
13
|
+
|
|
14
|
+
let { latlngs, instance = $bindable(), options = {}, ...restProps }: Props = $props();
|
|
15
|
+
|
|
16
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
17
|
+
const getLayerGroup = getContext<() => LayerGroup>(LAYERGROUP);
|
|
18
|
+
|
|
19
|
+
onMount(() => {
|
|
20
|
+
const map = getMap?.();
|
|
21
|
+
const layerGroup = getLayerGroup?.();
|
|
22
|
+
const context = layerGroup || map;
|
|
23
|
+
instance = window.L.polygon(latlngs, options);
|
|
24
|
+
instance.addTo(context);
|
|
25
|
+
bindEvents(instance, restProps, polygonEvents);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
onDestroy(() => {
|
|
29
|
+
instance?.remove();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
$effect(() => {
|
|
33
|
+
if (instance && latlngs) {
|
|
34
|
+
instance.setLatLngs(latlngs);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
$effect(() => {
|
|
39
|
+
if (instance && options) {
|
|
40
|
+
updatePolylineProps(instance, options);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Polygon as LeafletPolygon, PolylineOptions } from 'leaflet';
|
|
2
|
+
import { type PolygonEvents } from './polyline.svelte.js';
|
|
3
|
+
import { type Latlngs } from './index.js';
|
|
4
|
+
declare const Polygon: import("svelte").Component<{
|
|
5
|
+
latlngs: Latlngs<3>;
|
|
6
|
+
instance?: LeafletPolygon;
|
|
7
|
+
options?: PolylineOptions;
|
|
8
|
+
} & PolygonEvents, {}, "instance">;
|
|
9
|
+
export default Polygon;
|
package/dist/Polyline.svelte
CHANGED
|
@@ -1,26 +1,43 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
line.on("click", (e) => dispatch("click", e));
|
|
19
|
-
line.addTo(map);
|
|
20
|
-
});
|
|
21
|
-
onDestroy(() => {
|
|
22
|
-
line?.remove();
|
|
23
|
-
});
|
|
24
|
-
</script>
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onDestroy, onMount } from 'svelte';
|
|
3
|
+
import type { Polyline as LeafletPolyline, PolylineOptions, LayerGroup } from 'leaflet';
|
|
4
|
+
import { polygonEvents, updatePolylineProps, type PolygonEvents } from './polyline.svelte.js';
|
|
5
|
+
import { bindEvents, type Latlngs, type LeafletMap } from './index.js';
|
|
6
|
+
import { LAYERGROUP, MAP } from './contexts.js';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
latlngs: Latlngs;
|
|
10
|
+
instance?: LeafletPolyline;
|
|
11
|
+
options?: PolylineOptions;
|
|
12
|
+
} & PolygonEvents;
|
|
13
|
+
|
|
14
|
+
let { latlngs, instance = $bindable(), options = {}, ...restProps }: Props = $props();
|
|
15
|
+
|
|
16
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
17
|
+
const getLayerGroup = getContext<() => LayerGroup>(LAYERGROUP);
|
|
25
18
|
|
|
26
|
-
|
|
19
|
+
onMount(() => {
|
|
20
|
+
const map = getMap?.();
|
|
21
|
+
const layerGroup = getLayerGroup?.();
|
|
22
|
+
const context = layerGroup || map;
|
|
23
|
+
instance = window.L.polyline(latlngs, options);
|
|
24
|
+
instance.addTo(context);
|
|
25
|
+
bindEvents(instance, restProps, polygonEvents);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
onDestroy(() => {
|
|
29
|
+
instance?.remove();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
$effect(() => {
|
|
33
|
+
if (instance && latlngs) {
|
|
34
|
+
instance.setLatLngs(latlngs);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
$effect(() => {
|
|
39
|
+
if (instance && options) {
|
|
40
|
+
updatePolylineProps(instance, options);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} & {
|
|
11
|
-
[evt: string]: CustomEvent<any>;
|
|
12
|
-
};
|
|
13
|
-
slots: {
|
|
14
|
-
default: {};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export type PolylineProps = typeof __propDef.props;
|
|
18
|
-
export type PolylineEvents = typeof __propDef.events;
|
|
19
|
-
export type PolylineSlots = typeof __propDef.slots;
|
|
20
|
-
export default class Polyline extends SvelteComponent<PolylineProps, PolylineEvents, PolylineSlots> {
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
1
|
+
import type { Polyline as LeafletPolyline, PolylineOptions } from 'leaflet';
|
|
2
|
+
import { type PolygonEvents } from './polyline.svelte.js';
|
|
3
|
+
import { type Latlngs } from './index.js';
|
|
4
|
+
declare const Polyline: import("svelte").Component<{
|
|
5
|
+
latlngs: Latlngs;
|
|
6
|
+
instance?: LeafletPolyline;
|
|
7
|
+
options?: PolylineOptions;
|
|
8
|
+
} & PolygonEvents, {}, "instance">;
|
|
9
|
+
export default Polyline;
|