@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/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
A library that wraps leaflet classes in domless/renderless svelte components.
|
|
4
4
|
|
|
5
|
+
## Compatibility
|
|
6
|
+
|
|
7
|
+
Version 1.0.0 and above are compatible with Svelte 5.
|
|
8
|
+
|
|
9
|
+
For svelte 3 and 4, use version 0.1.x (not actively maintained).
|
|
10
|
+
|
|
5
11
|
## Install
|
|
6
12
|
|
|
7
13
|
`npm i -D @radiofrance/svelte-leaflet`
|
|
@@ -29,7 +35,7 @@ All events are forwarded from the Map class, see the leaflet documentation for m
|
|
|
29
35
|
Example:
|
|
30
36
|
|
|
31
37
|
```svelte
|
|
32
|
-
<Map {options}
|
|
38
|
+
<Map {options} onclick={(e) => console.log(e.detail.latlng)} />
|
|
33
39
|
```
|
|
34
40
|
|
|
35
41
|
### Marker
|
|
@@ -38,15 +44,14 @@ Add a marker to the map.
|
|
|
38
44
|
|
|
39
45
|
- Can be used as a child of `<Map>` or `<MarkerClusterGroup>`
|
|
40
46
|
- A `<Popup>` component can be passed as the Marker child to display a popup when the marker is clicked.
|
|
41
|
-
-
|
|
47
|
+
- To use a custom icon, pass a `Icon` or a `DivIcon` component as the marker child.
|
|
42
48
|
|
|
43
49
|
#### Attributes
|
|
44
50
|
|
|
45
|
-
| Name
|
|
46
|
-
|
|
|
47
|
-
| `latlng`
|
|
48
|
-
| `
|
|
49
|
-
| `id` | string | `''` | an identifier to link the maker with you data |
|
|
51
|
+
| Name | Type | Default | Notes |
|
|
52
|
+
| --------- | ------------------------------------------------------------------- | ---------- | ------------------------------------- |
|
|
53
|
+
| `latlng` | [LatLng](https://leafletjs.com/reference.html#latlng) | _required_ | position of the marker |
|
|
54
|
+
| `options` | [MarkerOptions](https://leafletjs.com/reference.html#marker-option) | `{}` | options to pass to the leaflet marker |
|
|
50
55
|
|
|
51
56
|
#### Events
|
|
52
57
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Marker as LeafletMarker, DivIcon as LeafletDivIcon, DivIconOptions } from 'leaflet';
|
|
3
|
+
|
|
4
|
+
import { getContext, onDestroy, onMount, type Snippet } from 'svelte';
|
|
5
|
+
import { MARKER } from './contexts.js';
|
|
6
|
+
|
|
7
|
+
type Props = { children: Snippet; instance?: LeafletDivIcon; options?: DivIconOptions };
|
|
8
|
+
|
|
9
|
+
let { children, instance = $bindable(), options = {} }: Props = $props();
|
|
10
|
+
let iconContainer: HTMLDivElement | undefined = $state();
|
|
11
|
+
|
|
12
|
+
const getMarker = getContext<() => LeafletMarker>(MARKER);
|
|
13
|
+
|
|
14
|
+
onMount(() => {
|
|
15
|
+
const marker = getMarker?.();
|
|
16
|
+
if (marker) {
|
|
17
|
+
instance = window.L.divIcon({
|
|
18
|
+
html: iconContainer,
|
|
19
|
+
className: '',
|
|
20
|
+
...options,
|
|
21
|
+
});
|
|
22
|
+
marker.setIcon(instance);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
onDestroy(() => {
|
|
27
|
+
if (instance) {
|
|
28
|
+
instance.remove?.();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<div class="container">
|
|
34
|
+
<div class="DivIcon" bind:this={iconContainer}>
|
|
35
|
+
{@render children()}
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<!--
|
|
40
|
+
@component
|
|
41
|
+
Renders a custom HTML icon for a marker.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
**It should only be used as a child of a `Marker` component.**
|
|
45
|
+
|
|
46
|
+
```svelte
|
|
47
|
+
...
|
|
48
|
+
<DivIcon {options}>
|
|
49
|
+
<div class="my-custom-icon">🤓</div>
|
|
50
|
+
</DivIcon>
|
|
51
|
+
...
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Reactivity
|
|
55
|
+
**None of the options are reactive.**
|
|
56
|
+
|
|
57
|
+
If you need to update the icon, you should create a new `DivIcon` component with the new options.
|
|
58
|
+
-->
|
|
59
|
+
|
|
60
|
+
<style>
|
|
61
|
+
.container {
|
|
62
|
+
display: none;
|
|
63
|
+
}
|
|
64
|
+
</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DivIcon as LeafletDivIcon, DivIconOptions } from 'leaflet';
|
|
2
|
+
import { type Snippet } from 'svelte';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a custom HTML icon for a marker.
|
|
5
|
+
*
|
|
6
|
+
* ## Usage
|
|
7
|
+
* **It should only be used as a child of a `Marker` component.**
|
|
8
|
+
*
|
|
9
|
+
* ```svelte
|
|
10
|
+
* ...
|
|
11
|
+
* <DivIcon {options}>
|
|
12
|
+
* <div class="my-custom-icon">🤓</div>
|
|
13
|
+
* </DivIcon>
|
|
14
|
+
* ...
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* ## Reactivity
|
|
18
|
+
* **None of the options are reactive.**
|
|
19
|
+
*
|
|
20
|
+
* If you need to update the icon, you should create a new `DivIcon` component with the new options.
|
|
21
|
+
*/
|
|
22
|
+
declare const DivIcon: import("svelte").Component<{
|
|
23
|
+
children: Snippet;
|
|
24
|
+
instance?: LeafletDivIcon;
|
|
25
|
+
options?: DivIconOptions;
|
|
26
|
+
}, {}, "instance">;
|
|
27
|
+
export default DivIcon;
|
package/dist/Icon.svelte
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Marker as LeafletMarker, Icon as LeafletIcon, IconOptions } from 'leaflet';
|
|
3
|
+
|
|
4
|
+
import { getContext, onDestroy, onMount } from 'svelte';
|
|
5
|
+
import { MARKER } from './contexts.js';
|
|
6
|
+
|
|
7
|
+
type Props = { instance?: LeafletIcon; options: IconOptions };
|
|
8
|
+
|
|
9
|
+
let { instance = $bindable(), options }: Props = $props();
|
|
10
|
+
|
|
11
|
+
const getMarker = getContext<() => LeafletMarker>(MARKER);
|
|
12
|
+
|
|
13
|
+
onMount(() => {
|
|
14
|
+
const marker = getMarker?.();
|
|
15
|
+
if (marker) {
|
|
16
|
+
instance = window.L.icon(options);
|
|
17
|
+
marker.setIcon(instance);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
onDestroy(() => {
|
|
22
|
+
if (instance) {
|
|
23
|
+
instance.remove?.();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<!--
|
|
29
|
+
@component
|
|
30
|
+
Renders a custom image icon for a marker.
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
**It should only be used as a child of a `Marker` component.**
|
|
34
|
+
|
|
35
|
+
`options.iconUrl` is required. The easiest way to use it is with data URL : import the image and pass it as the value.
|
|
36
|
+
|
|
37
|
+
Absolute and relative URLs are also supported.
|
|
38
|
+
|
|
39
|
+
```svelte
|
|
40
|
+
<script>
|
|
41
|
+
import myPngIcon from './icon.png';
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
...
|
|
45
|
+
<Icon options={{iconUrl: myPngIcon}}/>
|
|
46
|
+
...
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Reactivity
|
|
50
|
+
**None of the options are reactive.**
|
|
51
|
+
|
|
52
|
+
If you need to update the icon, you should create a new `DivIcon` component with the new options.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
-->
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Icon as LeafletIcon, IconOptions } from 'leaflet';
|
|
2
|
+
/**
|
|
3
|
+
* Renders a custom image icon for a marker.
|
|
4
|
+
*
|
|
5
|
+
* ## Usage
|
|
6
|
+
* **It should only be used as a child of a `Marker` component.**
|
|
7
|
+
*
|
|
8
|
+
* `options.iconUrl` is required. The easiest way to use it is with data URL : import the image and pass it as the value.
|
|
9
|
+
*
|
|
10
|
+
* Absolute and relative URLs are also supported.
|
|
11
|
+
*
|
|
12
|
+
* ```svelte
|
|
13
|
+
* <script>
|
|
14
|
+
* import myPngIcon from './icon.png';
|
|
15
|
+
* </script>
|
|
16
|
+
*
|
|
17
|
+
* ...
|
|
18
|
+
* <Icon options={{iconUrl: myPngIcon}}/>
|
|
19
|
+
* ...
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ## Reactivity
|
|
23
|
+
* **None of the options are reactive.**
|
|
24
|
+
*
|
|
25
|
+
* If you need to update the icon, you should create a new `DivIcon` component with the new options.
|
|
26
|
+
*/
|
|
27
|
+
declare const Icon: import("svelte").Component<{
|
|
28
|
+
instance?: LeafletIcon;
|
|
29
|
+
options: IconOptions;
|
|
30
|
+
}, {}, "instance">;
|
|
31
|
+
export default Icon;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onMount, type Snippet } from 'svelte';
|
|
3
|
+
import type { ControlPosition, Map as LeafletMap, LocateOptions } from 'leaflet';
|
|
4
|
+
import { MAP } from './contexts.js';
|
|
5
|
+
import GeolocationButton from './private/GeolocationButton.svelte';
|
|
6
|
+
import { getFirstNonCommentChild } from './utils.js';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
instance?: L.Control;
|
|
10
|
+
children?: Snippet;
|
|
11
|
+
position?: ControlPosition;
|
|
12
|
+
options?: LocateOptions;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let { instance = $bindable(), children, position = 'topleft', options }: Props = $props();
|
|
16
|
+
let locateButtonContainer: HTMLDivElement;
|
|
17
|
+
|
|
18
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
19
|
+
|
|
20
|
+
onMount(() => {
|
|
21
|
+
const map = getMap();
|
|
22
|
+
const control = window.L.Control.extend({
|
|
23
|
+
position,
|
|
24
|
+
onAdd: createLocateOnAdd(map, locateButtonContainer, options),
|
|
25
|
+
});
|
|
26
|
+
instance = new control({ position });
|
|
27
|
+
map.addControl(instance);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function createLocateOnAdd(
|
|
31
|
+
mapInstance: LeafletMap,
|
|
32
|
+
locateButtonContainer: HTMLElement,
|
|
33
|
+
locateControlOptions: L.LocateOptions = {},
|
|
34
|
+
) {
|
|
35
|
+
return () => {
|
|
36
|
+
const locateButtonElement = getFirstNonCommentChild(locateButtonContainer);
|
|
37
|
+
if (!locateButtonElement) return;
|
|
38
|
+
// prevent zoom on locate button double click
|
|
39
|
+
locateButtonElement.addEventListener('dblclick', (e: MouseEvent) => {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
});
|
|
43
|
+
locateButtonElement.addEventListener('click', () => {
|
|
44
|
+
mapInstance?.locate(locateControlOptions);
|
|
45
|
+
});
|
|
46
|
+
return locateButtonElement;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<div bind:this={locateButtonContainer}>
|
|
52
|
+
{#if children}
|
|
53
|
+
{@render children()}
|
|
54
|
+
{:else}
|
|
55
|
+
<GeolocationButton />
|
|
56
|
+
{/if}
|
|
57
|
+
</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { ControlPosition, LocateOptions } from 'leaflet';
|
|
3
|
+
declare const LocateControl: import("svelte").Component<{
|
|
4
|
+
instance?: L.Control;
|
|
5
|
+
children?: Snippet;
|
|
6
|
+
position?: ControlPosition;
|
|
7
|
+
options?: LocateOptions;
|
|
8
|
+
}, {}, "instance">;
|
|
9
|
+
export default LocateControl;
|
package/dist/Map.svelte
CHANGED
|
@@ -1,84 +1,135 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import 'leaflet/dist/leaflet.css';
|
|
3
|
+
import 'leaflet.markercluster/dist/MarkerCluster.css';
|
|
4
|
+
import 'leaflet.markercluster/dist/MarkerCluster.Default.css';
|
|
5
|
+
import markerIcon2x from 'leaflet/dist/images/marker-icon-2x.png';
|
|
6
|
+
import markerIcon from 'leaflet/dist/images/marker-icon.png';
|
|
7
|
+
import markerShadow from 'leaflet/dist/images/marker-shadow.png';
|
|
8
|
+
|
|
9
|
+
import type { MapOptions, Marker, Map as LeafletMap, LatLngTuple } from 'leaflet';
|
|
10
|
+
import { bindEvents } from './index.js';
|
|
11
|
+
import { setContext, type Snippet } from 'svelte';
|
|
12
|
+
import { mapEvents, updateMapProps, type MapEvents } from './map.svelte.js';
|
|
13
|
+
import { FOCUSABLE, MAP } from './contexts.js';
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
instance?: LeafletMap;
|
|
17
|
+
options?: MapOptions;
|
|
18
|
+
markers?: Marker[];
|
|
19
|
+
tilesUrl?: string;
|
|
20
|
+
attribution?: string;
|
|
21
|
+
focusable?: boolean;
|
|
22
|
+
children?: Snippet;
|
|
23
|
+
} & MapEvents;
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
instance = $bindable(),
|
|
27
|
+
options = $bindable({}),
|
|
28
|
+
markers = $bindable([]),
|
|
29
|
+
tilesUrl = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
30
|
+
attribution = `©<a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>`,
|
|
31
|
+
focusable = true,
|
|
32
|
+
children,
|
|
33
|
+
...restProps
|
|
34
|
+
}: Props = $props();
|
|
35
|
+
|
|
36
|
+
const defaultOptions = {
|
|
37
|
+
center: [48.852, 2.278] as LatLngTuple,
|
|
38
|
+
trackResize: true,
|
|
39
|
+
zoom: 3,
|
|
40
|
+
maxZoom: 18,
|
|
41
|
+
keyboard: options.keyboard === undefined ? focusable : options.keyboard,
|
|
42
|
+
};
|
|
43
|
+
// consider exporting a reference to the markers instead of a getter
|
|
44
|
+
export const getMarkers: () => Marker[] = () => {
|
|
45
|
+
const markers: Marker[] = [];
|
|
46
|
+
instance?.eachLayer((layer) => {
|
|
47
|
+
if (layer instanceof window.L.Marker) {
|
|
48
|
+
markers.push(layer);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return markers;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
setContext(MAP, () => instance);
|
|
55
|
+
setContext(FOCUSABLE, focusable ? null : -1);
|
|
56
|
+
let container: HTMLElement | null = $state(null);
|
|
57
|
+
|
|
58
|
+
$effect(() => {
|
|
59
|
+
if (instance) {
|
|
60
|
+
updateMapProps(instance, options);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
function onLoad() {
|
|
65
|
+
if (!container) return;
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
delete window.L.Icon.Default.prototype._getIconUrl;
|
|
68
|
+
window.L.Icon.Default.mergeOptions({
|
|
69
|
+
iconRetinaUrl: markerIcon2x,
|
|
70
|
+
iconUrl: markerIcon,
|
|
71
|
+
shadowUrl: markerShadow,
|
|
72
|
+
});
|
|
73
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
74
|
+
// trackResize is set to false else the resize callback couldn't be unbined (no reference)
|
|
75
|
+
instance = window.L.map(container, { ...mergedOptions, trackResize: false });
|
|
76
|
+
if (mergedOptions.trackResize) {
|
|
77
|
+
// this triggers updateMapProps and binds the custom resize callback
|
|
78
|
+
options.trackResize = true;
|
|
79
|
+
}
|
|
80
|
+
bindEvents(instance, restProps, mapEvents);
|
|
81
|
+
|
|
82
|
+
// create component for the tile layer ?
|
|
83
|
+
window.L.tileLayer(tilesUrl, {
|
|
84
|
+
attribution,
|
|
85
|
+
}).addTo(instance);
|
|
86
|
+
|
|
87
|
+
instance.on('layeradd', (event) => {
|
|
88
|
+
const layer = event.layer;
|
|
89
|
+
if (layer instanceof window.L.Marker) {
|
|
90
|
+
markers.push(layer);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
instance.on('layerremove', (event) => {
|
|
95
|
+
const layer = event.layer;
|
|
96
|
+
if (layer instanceof window.L.Marker) {
|
|
97
|
+
const index = markers.indexOf(layer);
|
|
98
|
+
if (index > -1) {
|
|
99
|
+
markers.splice(index, 1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
instance.whenReady(() => {
|
|
105
|
+
if (!instance) return;
|
|
106
|
+
// TODO: find out why manually firing the load event is needed
|
|
107
|
+
instance.fireEvent('load');
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function leafletLoader(_node: HTMLElement) {
|
|
112
|
+
(async function () {
|
|
113
|
+
await import('leaflet');
|
|
114
|
+
// leaflet.markercluster is loaded by default. It's 34ko (12ko gzipped).
|
|
115
|
+
// A single tile is around 30ko gzipped.
|
|
116
|
+
// TODO: consider making it optional (handle loading in MarkerClusterGroup.svelte ?)
|
|
117
|
+
await import('leaflet.markercluster');
|
|
118
|
+
onLoad();
|
|
119
|
+
})();
|
|
120
|
+
}
|
|
76
121
|
</script>
|
|
77
122
|
|
|
78
|
-
<svelte:window
|
|
123
|
+
<svelte:window use:leafletLoader />
|
|
79
124
|
|
|
80
125
|
<div class="Map" bind:this={container} style="height: 100%; width: 100%">
|
|
81
126
|
{#if instance}
|
|
82
|
-
|
|
127
|
+
{@render children?.()}
|
|
83
128
|
{/if}
|
|
84
129
|
</div>
|
|
130
|
+
|
|
131
|
+
<style>
|
|
132
|
+
.Map {
|
|
133
|
+
z-index: 0;
|
|
134
|
+
}
|
|
135
|
+
</style>
|
package/dist/Map.svelte.d.ts
CHANGED
|
@@ -1,67 +1,18 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type { MapOptions, Marker, Map } from 'leaflet';
|
|
3
|
-
import type Leaflet from 'leaflet';
|
|
4
1
|
import 'leaflet/dist/leaflet.css';
|
|
5
2
|
import 'leaflet.markercluster/dist/MarkerCluster.css';
|
|
6
3
|
import 'leaflet.markercluster/dist/MarkerCluster.Default.css';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
overlayadd: CustomEvent<Leaflet.LayersControlEvent>;
|
|
23
|
-
overlayremove: CustomEvent<Leaflet.LayersControlEvent>;
|
|
24
|
-
click: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
25
|
-
dblclick: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
26
|
-
mousedown: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
27
|
-
mouseup: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
28
|
-
mouseover: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
29
|
-
mouseout: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
30
|
-
contextmenu: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
31
|
-
mousemove: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
32
|
-
preclick: CustomEvent<Leaflet.LeafletMouseEvent>;
|
|
33
|
-
locationfound: CustomEvent<Leaflet.LocationEvent>;
|
|
34
|
-
locationerror: CustomEvent<Leaflet.ErrorEvent>;
|
|
35
|
-
load: CustomEvent<Leaflet.LeafletEvent>;
|
|
36
|
-
move: CustomEvent<Leaflet.LeafletEvent>;
|
|
37
|
-
moveend: CustomEvent<Leaflet.LeafletEvent>;
|
|
38
|
-
movestart: CustomEvent<Leaflet.LeafletEvent>;
|
|
39
|
-
unload: CustomEvent<Leaflet.LeafletEvent>;
|
|
40
|
-
viewreset: CustomEvent<Leaflet.LeafletEvent>;
|
|
41
|
-
zoom: CustomEvent<Leaflet.LeafletEvent>;
|
|
42
|
-
zoomend: CustomEvent<Leaflet.LeafletEvent>;
|
|
43
|
-
zoomlevelschange: CustomEvent<Leaflet.LeafletEvent>;
|
|
44
|
-
zoomstart: CustomEvent<Leaflet.LeafletEvent>;
|
|
45
|
-
resize: CustomEvent<Leaflet.ResizeEvent>;
|
|
46
|
-
popupopen: CustomEvent<Leaflet.PopupEvent>;
|
|
47
|
-
popupclose: CustomEvent<Leaflet.PopupEvent>;
|
|
48
|
-
tooltipopen: CustomEvent<Leaflet.TooltipEvent>;
|
|
49
|
-
tooltipclose: CustomEvent<Leaflet.TooltipEvent>;
|
|
50
|
-
autopanstart: CustomEvent<Leaflet.LeafletEvent>;
|
|
51
|
-
zoomanim: CustomEvent<Leaflet.LeafletEvent>;
|
|
52
|
-
} & {
|
|
53
|
-
[evt: string]: CustomEvent<any>;
|
|
54
|
-
};
|
|
55
|
-
slots: {
|
|
56
|
-
default: {
|
|
57
|
-
map: Map;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
export type MapProps = typeof __propDef.props;
|
|
62
|
-
export type MapEvents = typeof __propDef.events;
|
|
63
|
-
export type MapSlots = typeof __propDef.slots;
|
|
64
|
-
export default class Map extends SvelteComponent<MapProps, MapEvents, MapSlots> {
|
|
65
|
-
get getMarkers(): () => Marker<any>[];
|
|
66
|
-
}
|
|
67
|
-
export {};
|
|
4
|
+
import type { MapOptions, Marker, Map as LeafletMap } from 'leaflet';
|
|
5
|
+
import { type Snippet } from 'svelte';
|
|
6
|
+
import { type MapEvents } from './map.svelte.js';
|
|
7
|
+
declare const Map: import("svelte").Component<{
|
|
8
|
+
instance?: LeafletMap;
|
|
9
|
+
options?: MapOptions;
|
|
10
|
+
markers?: Marker[];
|
|
11
|
+
tilesUrl?: string;
|
|
12
|
+
attribution?: string;
|
|
13
|
+
focusable?: boolean;
|
|
14
|
+
children?: Snippet;
|
|
15
|
+
} & MapEvents, {
|
|
16
|
+
getMarkers: () => Marker[];
|
|
17
|
+
}, "instance" | "options" | "markers">;
|
|
18
|
+
export default Map;
|