@radiofrance/svelte-leaflet 1.0.0-next.1 → 1.0.0-next.3
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 +55 -70
- package/dist/Circle.svelte +45 -0
- package/dist/Circle.svelte.d.ts +8 -0
- package/dist/CircleMarker.svelte +49 -0
- package/dist/CircleMarker.svelte.d.ts +8 -0
- package/dist/ImageOverlay.svelte +66 -0
- package/dist/ImageOverlay.svelte.d.ts +10 -0
- package/dist/LayersControl.svelte +23 -0
- package/dist/LayersControl.svelte.d.ts +6 -0
- package/dist/Map.svelte +39 -24
- package/dist/Map.svelte.d.ts +2 -4
- package/dist/Marker.svelte +1 -1
- package/dist/Marker.svelte.d.ts +1 -1
- package/dist/MarkerClusterGroup.svelte +1 -4
- package/dist/MarkerClusterGroup.svelte.d.ts +19 -19
- package/dist/Polygon.svelte +1 -1
- package/dist/Polygon.svelte.d.ts +1 -1
- package/dist/Polyline.svelte +1 -1
- package/dist/Polyline.svelte.d.ts +1 -1
- package/dist/Popup.svelte +1 -1
- package/dist/Popup.svelte.d.ts +1 -1
- package/dist/Rectangle.svelte +48 -0
- package/dist/Rectangle.svelte.d.ts +8 -0
- package/dist/SVGOverlay.svelte +52 -0
- package/dist/SVGOverlay.svelte.d.ts +8 -0
- package/dist/TileLayer.svelte +34 -0
- package/dist/TileLayer.svelte.d.ts +8 -0
- package/dist/TileLayerWMS.svelte +36 -0
- package/dist/TileLayerWMS.svelte.d.ts +8 -0
- package/dist/Tooltip.svelte +73 -0
- package/dist/Tooltip.svelte.d.ts +10 -0
- package/dist/VideoOverlay.svelte +66 -0
- package/dist/VideoOverlay.svelte.d.ts +10 -0
- package/dist/ZoomControl.svelte +21 -0
- package/dist/ZoomControl.svelte.d.ts +8 -0
- package/dist/circleMarker.d.ts +4 -0
- package/dist/circleMarker.js +8 -0
- package/dist/contexts.d.ts +8 -0
- package/dist/contexts.js +18 -0
- package/dist/events.d.ts +1 -1
- package/dist/events.js +1 -1
- package/dist/imageOverlay.d.ts +5 -0
- package/dist/imageOverlay.js +25 -0
- package/dist/{map.svelte.js → map.js} +2 -2
- package/dist/{marker.svelte.js → marker.js} +2 -2
- package/dist/{markerClusterGroup.svelte.d.ts → markerClusterGroup.d.ts} +2 -2
- package/dist/{markerClusterGroup.svelte.js → markerClusterGroup.js} +1 -1
- package/dist/{polyline.svelte.js → polyline.js} +2 -2
- package/dist/{popup.svelte.js → popup.js} +2 -2
- package/dist/tileLayer.d.ts +5 -0
- package/dist/tileLayer.js +1 -0
- package/dist/tileLayerWMS.d.ts +7 -0
- package/dist/tileLayerWMS.js +1 -0
- package/dist/tooltip.d.ts +10 -0
- package/dist/tooltip.js +34 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +7 -0
- package/dist/videoOverlay.d.ts +5 -0
- package/dist/videoOverlay.js +25 -0
- package/package.json +1 -1
- /package/dist/{map.svelte.d.ts → map.d.ts} +0 -0
- /package/dist/{marker.svelte.d.ts → marker.d.ts} +0 -0
- /package/dist/{polygon.svelte.d.ts → polygon.d.ts} +0 -0
- /package/dist/{polygon.svelte.js → polygon.js} +0 -0
- /package/dist/{polyline.svelte.d.ts → polyline.d.ts} +0 -0
- /package/dist/{popup.svelte.d.ts → popup.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
# @radiofrance/svelte-leaflet
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Simple Leaflet maps for your Svelte projects.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Works in SSR pages
|
|
8
|
+
- TypeScript : events, props and options are fully typed
|
|
9
|
+
- Simple event usage with the `oneventname` syntax
|
|
10
|
+
- 
|
|
11
|
+
- `event.sourceTarget` is correctly typed
|
|
12
|
+
- Fully reactive : update props and options, the components will update
|
|
13
|
+
- Customize `DivIcon`, `Popup` and more with Svelte components or HTML instead of strings
|
|
14
|
+
- Single dependency : no `leaflet` or `@types/leaflet` needed
|
|
6
15
|
|
|
7
|
-
|
|
16
|
+
## Compatibility
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
- Version 1.0.0 and above are compatible with Svelte 5.
|
|
19
|
+
- For Svelte 3 and 4, use version 0.1.x (not actively maintained).
|
|
10
20
|
|
|
11
21
|
## Install
|
|
12
22
|
|
|
@@ -14,82 +24,57 @@ For svelte 3 and 4, use version 0.1.x (not actively maintained).
|
|
|
14
24
|
|
|
15
25
|
## Components
|
|
16
26
|
|
|
17
|
-
###
|
|
18
|
-
|
|
19
|
-
Renders a map Leaflet Map. The Map will take up 100% of its container's height and width.
|
|
20
|
-
|
|
21
|
-
#### Attributes
|
|
22
|
-
|
|
23
|
-
| Attribute | Type | Default | Notes |
|
|
24
|
-
| ------------- | ------------------------------------------------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
25
|
-
| `options` | [MapOptions](https://leafletjs.com/reference.html#map-option) | `{}` | Map options |
|
|
26
|
-
| `tilesUrl` | string | `'https://tile.openstreetmap.org/{z}/{x}/{y}.png'` | more free tile services can be found at https://alexurquhart.github.io/free-tiles/ |
|
|
27
|
-
| `attribution` | string | `'©OpenStreetMap'` _(link to openstreetmap)_ | |
|
|
28
|
-
|
|
29
|
-
#### Events
|
|
30
|
-
|
|
31
|
-
All events are forwarded from the Map class, see the leaflet documentation for more information.
|
|
32
|
-
|
|
33
|
-
- https://leafletjs.com/reference.html#map-event
|
|
34
|
-
|
|
35
|
-
Example:
|
|
36
|
-
|
|
37
|
-
```svelte
|
|
38
|
-
<Map {options} onclick={(e) => console.log(e.detail.latlng)} />
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Marker
|
|
42
|
-
|
|
43
|
-
Add a marker to the map.
|
|
44
|
-
|
|
45
|
-
- Can be used as a child of `<Map>` or `<MarkerClusterGroup>`
|
|
46
|
-
- A `<Popup>` component can be passed as the Marker child to display a popup when the marker is clicked.
|
|
47
|
-
- To use a custom icon, pass a `Icon` or a `DivIcon` component as the marker child.
|
|
48
|
-
|
|
49
|
-
#### Attributes
|
|
50
|
-
|
|
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 |
|
|
55
|
-
|
|
56
|
-
#### Events
|
|
57
|
-
|
|
58
|
-
All events are forwarded from the Marker class, see the leaflet documentation for more information.
|
|
59
|
-
|
|
60
|
-
- https://leafletjs.com/reference.html#marker-event
|
|
61
|
-
|
|
62
|
-
### Popup
|
|
27
|
+
### UI Layers
|
|
63
28
|
|
|
64
|
-
|
|
29
|
+
- ✅ Marker
|
|
30
|
+
- DivOverlay _(abstract class)_
|
|
31
|
+
- ✅ Popup
|
|
32
|
+
- ✅ Tooltip
|
|
65
33
|
|
|
66
|
-
|
|
34
|
+
### Raster Layers
|
|
67
35
|
|
|
68
|
-
|
|
36
|
+
- ✅ TileLayer
|
|
37
|
+
- ✅ TileLayer.WMS
|
|
38
|
+
- ✅ ImageOverlay
|
|
39
|
+
- ✅ VideoOverlay
|
|
69
40
|
|
|
70
|
-
|
|
71
|
-
| --------- | ----------------------------------------------------------------- | ------- | ------------------------------------ |
|
|
72
|
-
| `options` | [PopupOptions](https://leafletjs.com/reference.html#popup-option) | `{}` | options to pass to the leaflet popup |
|
|
41
|
+
### Vector Layers
|
|
73
42
|
|
|
74
|
-
|
|
43
|
+
- Path
|
|
44
|
+
- ✅ Polyline
|
|
45
|
+
- ✅ Polygon
|
|
46
|
+
- ✅ Rectangle
|
|
47
|
+
- ✅ Circle
|
|
48
|
+
- ✅ CircleMarker
|
|
49
|
+
- ✅ SVGOverlay
|
|
50
|
+
- SVG _(this is a Renderer, won't be implemented)_
|
|
51
|
+
- Canvas _(this is a Renderer, won't be implemented)_
|
|
75
52
|
|
|
76
|
-
|
|
53
|
+
### Other Layers
|
|
77
54
|
|
|
78
|
-
-
|
|
55
|
+
- LayerGroup
|
|
56
|
+
- FeatureGroup
|
|
57
|
+
- GeoJSON
|
|
58
|
+
- GridLayer
|
|
79
59
|
|
|
80
|
-
|
|
60
|
+
### Basic Types
|
|
81
61
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
62
|
+
- LatLng
|
|
63
|
+
- LatLngBounds
|
|
64
|
+
- Point
|
|
65
|
+
- Bounds
|
|
66
|
+
- ✅ Icon
|
|
67
|
+
- ✅ DivIcon
|
|
85
68
|
|
|
86
|
-
###
|
|
69
|
+
### Controls
|
|
87
70
|
|
|
88
|
-
|
|
71
|
+
- ✅ Zoom
|
|
72
|
+
- Attribution
|
|
73
|
+
- Layers
|
|
74
|
+
- Scale
|
|
89
75
|
|
|
90
|
-
|
|
76
|
+
### Extra
|
|
91
77
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
| `options` | [PolylineOptions](https://leafletjs.com/reference.html#polyline-option) | `{}` | options to pass to the leaflet polyline |
|
|
78
|
+
- ✅ MarkerClusterGroup
|
|
79
|
+
- ✅ LocateControl
|
|
80
|
+
- 
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onDestroy, onMount } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
Circle as LeafletCircle,
|
|
5
|
+
LatLngExpression,
|
|
6
|
+
CircleMarkerOptions,
|
|
7
|
+
LayerGroup,
|
|
8
|
+
} from 'leaflet';
|
|
9
|
+
import { polygonEvents, updatePolylineProps, type PolygonEvents } from './polyline.js';
|
|
10
|
+
import { bindEvents, type LeafletMap } from './index.js';
|
|
11
|
+
import { LAYERGROUP, MAP } from './contexts.js';
|
|
12
|
+
import { circleMarkerEvents, type CircleMarkerEvents } from './circleMarker.js';
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
latlng: LatLngExpression;
|
|
16
|
+
instance?: LeafletCircle;
|
|
17
|
+
options?: CircleMarkerOptions;
|
|
18
|
+
} & CircleMarkerEvents;
|
|
19
|
+
|
|
20
|
+
let { latlng, instance = $bindable(), options = { radius: 50 }, ...restProps }: Props = $props();
|
|
21
|
+
|
|
22
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
23
|
+
const getLayerGroup = getContext<() => LayerGroup>(LAYERGROUP);
|
|
24
|
+
|
|
25
|
+
onMount(() => {
|
|
26
|
+
const map = getMap?.();
|
|
27
|
+
const layerGroup = getLayerGroup?.();
|
|
28
|
+
const context = layerGroup || map;
|
|
29
|
+
instance = window.L.circle(latlng, { ...options });
|
|
30
|
+
instance.addTo(context);
|
|
31
|
+
bindEvents(instance, restProps, circleMarkerEvents);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
onDestroy(() => {
|
|
35
|
+
instance?.remove();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
$effect(() => {
|
|
39
|
+
if (instance && latlng) {
|
|
40
|
+
instance.setLatLng(latlng);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// TODO : implement reactivity
|
|
45
|
+
</script>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Circle as LeafletCircle, LatLngExpression, CircleMarkerOptions } from 'leaflet';
|
|
2
|
+
import { type CircleMarkerEvents } from './circleMarker.js';
|
|
3
|
+
declare const Circle: import("svelte").Component<{
|
|
4
|
+
latlng: LatLngExpression;
|
|
5
|
+
instance?: LeafletCircle;
|
|
6
|
+
options?: CircleMarkerOptions;
|
|
7
|
+
} & CircleMarkerEvents, {}, "instance">;
|
|
8
|
+
export default Circle;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onDestroy, onMount } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
CircleMarker as LeafletCircleMarker,
|
|
5
|
+
LatLngExpression,
|
|
6
|
+
CircleMarkerOptions,
|
|
7
|
+
LayerGroup,
|
|
8
|
+
} from 'leaflet';
|
|
9
|
+
import { bindEvents, type LeafletMap } from './index.js';
|
|
10
|
+
import { LAYERGROUP, MAP } from './contexts.js';
|
|
11
|
+
import { circleMarkerEvents, type CircleMarkerEvents } from './circleMarker.js';
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
latlng: LatLngExpression;
|
|
15
|
+
instance?: LeafletCircleMarker;
|
|
16
|
+
options?: CircleMarkerOptions;
|
|
17
|
+
} & CircleMarkerEvents;
|
|
18
|
+
|
|
19
|
+
let { latlng, instance = $bindable(), options = { radius: 50 }, ...restProps }: Props = $props();
|
|
20
|
+
|
|
21
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
22
|
+
const getLayerGroup = getContext<() => LayerGroup>(LAYERGROUP);
|
|
23
|
+
|
|
24
|
+
onMount(() => {
|
|
25
|
+
const map = getMap?.();
|
|
26
|
+
const layerGroup = getLayerGroup?.();
|
|
27
|
+
const context = layerGroup || map;
|
|
28
|
+
instance = window.L.circleMarker(latlng, { ...options });
|
|
29
|
+
instance.addTo(context);
|
|
30
|
+
bindEvents(instance, restProps, circleMarkerEvents);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
onDestroy(() => {
|
|
34
|
+
instance?.remove();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
$effect(() => {
|
|
38
|
+
if (instance && latlng) {
|
|
39
|
+
instance.setLatLng(latlng);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// TODO : implement reactivity
|
|
44
|
+
// $effect(() => {
|
|
45
|
+
// if (instance && options) {
|
|
46
|
+
// updatePolylineProps(instance, options);
|
|
47
|
+
// }
|
|
48
|
+
// });
|
|
49
|
+
</script>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CircleMarker as LeafletCircleMarker, LatLngExpression, CircleMarkerOptions } from 'leaflet';
|
|
2
|
+
import { type CircleMarkerEvents } from './circleMarker.js';
|
|
3
|
+
declare const CircleMarker: import("svelte").Component<{
|
|
4
|
+
latlng: LatLngExpression;
|
|
5
|
+
instance?: LeafletCircleMarker;
|
|
6
|
+
options?: CircleMarkerOptions;
|
|
7
|
+
} & CircleMarkerEvents, {}, "instance">;
|
|
8
|
+
export default CircleMarker;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onDestroy, onMount } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
ImageOverlay as LeafletImageOverlay,
|
|
5
|
+
Map as LeafletMap,
|
|
6
|
+
ImageOverlayOptions,
|
|
7
|
+
LayerGroup,
|
|
8
|
+
LatLngBoundsLiteral,
|
|
9
|
+
} from 'leaflet';
|
|
10
|
+
import {
|
|
11
|
+
imageOverlayEvents,
|
|
12
|
+
updateImageOverlayProps,
|
|
13
|
+
type ImageOverlayEvents,
|
|
14
|
+
} from './imageOverlay.js';
|
|
15
|
+
import { bindEvents } from './index.js';
|
|
16
|
+
import { getOverlaysStore, LAYERGROUP, MAP } from './contexts.js';
|
|
17
|
+
import { getRandomString } from './utils.js';
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
name?: string;
|
|
21
|
+
url: string;
|
|
22
|
+
bounds: LatLngBoundsLiteral;
|
|
23
|
+
options?: ImageOverlayOptions;
|
|
24
|
+
instance?: LeafletImageOverlay;
|
|
25
|
+
} & ImageOverlayEvents;
|
|
26
|
+
|
|
27
|
+
let {
|
|
28
|
+
name = `overlay-${getRandomString(5)}`,
|
|
29
|
+
url,
|
|
30
|
+
bounds,
|
|
31
|
+
options = {},
|
|
32
|
+
instance = $bindable(),
|
|
33
|
+
...restProps
|
|
34
|
+
}: Props = $props();
|
|
35
|
+
|
|
36
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
37
|
+
const getLayerGroup = getContext<() => LayerGroup>(LAYERGROUP);
|
|
38
|
+
const overlaysStore = getOverlaysStore();
|
|
39
|
+
|
|
40
|
+
onMount(() => {
|
|
41
|
+
const map = getMap?.();
|
|
42
|
+
const layerGroup = getLayerGroup?.();
|
|
43
|
+
const context = layerGroup || map;
|
|
44
|
+
instance = window.L.imageOverlay(url, bounds, options);
|
|
45
|
+
$overlaysStore[name] = instance;
|
|
46
|
+
bindEvents(instance, restProps, imageOverlayEvents);
|
|
47
|
+
instance.addTo(context);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
onDestroy(() => {
|
|
51
|
+
instance?.remove();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
$effect(() => {
|
|
55
|
+
if (instance && options) {
|
|
56
|
+
updateImageOverlayProps(instance, options);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
$effect(() => {
|
|
61
|
+
if (instance && bounds) {
|
|
62
|
+
const latlngBounds = window.L.latLngBounds(bounds);
|
|
63
|
+
instance.setBounds(latlngBounds);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ImageOverlay as LeafletImageOverlay, ImageOverlayOptions, LatLngBoundsLiteral } from 'leaflet';
|
|
2
|
+
import { type ImageOverlayEvents } from './imageOverlay.js';
|
|
3
|
+
declare const ImageOverlay: import("svelte").Component<{
|
|
4
|
+
name?: string;
|
|
5
|
+
url: string;
|
|
6
|
+
bounds: LatLngBoundsLiteral;
|
|
7
|
+
options?: ImageOverlayOptions;
|
|
8
|
+
instance?: LeafletImageOverlay;
|
|
9
|
+
} & ImageOverlayEvents, {}, "instance">;
|
|
10
|
+
export default ImageOverlay;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onMount, tick } from 'svelte';
|
|
3
|
+
import { getBaseLayersStore, getOverlaysStore, MAP } from './contexts.js';
|
|
4
|
+
import type { Control, Map as LeafletMap } from 'leaflet';
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
instance?: Control;
|
|
8
|
+
options?: Control.LayersOptions;
|
|
9
|
+
};
|
|
10
|
+
let { instance = $bindable(), options }: Props = $props();
|
|
11
|
+
|
|
12
|
+
const getMap = getContext<() => LeafletMap>(MAP);
|
|
13
|
+
const baseLayersStore = getBaseLayersStore();
|
|
14
|
+
const overlaysStore = getOverlaysStore();
|
|
15
|
+
|
|
16
|
+
onMount(async () => {
|
|
17
|
+
const map = getMap();
|
|
18
|
+
// wait for layers to be initialized
|
|
19
|
+
await tick();
|
|
20
|
+
instance = window.L.control.layers($baseLayersStore, $overlaysStore, options);
|
|
21
|
+
instance.addTo(map);
|
|
22
|
+
});
|
|
23
|
+
</script>
|
package/dist/Map.svelte
CHANGED
|
@@ -8,9 +8,15 @@
|
|
|
8
8
|
|
|
9
9
|
import type { MapOptions, Marker, Map as LeafletMap, LatLngTuple } from 'leaflet';
|
|
10
10
|
import { bindEvents } from './index.js';
|
|
11
|
-
import { setContext, type Snippet } from 'svelte';
|
|
12
|
-
import { mapEvents, updateMapProps, type MapEvents } from './map.
|
|
13
|
-
import {
|
|
11
|
+
import { setContext, tick, type Snippet } from 'svelte';
|
|
12
|
+
import { mapEvents, updateMapProps, type MapEvents } from './map.js';
|
|
13
|
+
import {
|
|
14
|
+
FOCUSABLE,
|
|
15
|
+
getBaseLayersStore,
|
|
16
|
+
initBaseLayersStore,
|
|
17
|
+
initOverlaysStore,
|
|
18
|
+
MAP,
|
|
19
|
+
} from './contexts.js';
|
|
14
20
|
|
|
15
21
|
type Props = {
|
|
16
22
|
instance?: LeafletMap;
|
|
@@ -27,12 +33,20 @@
|
|
|
27
33
|
options = $bindable({}),
|
|
28
34
|
markers = $bindable([]),
|
|
29
35
|
tilesUrl = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
30
|
-
attribution = `©
|
|
36
|
+
attribution = `© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors`,
|
|
31
37
|
focusable = true,
|
|
32
38
|
children,
|
|
33
39
|
...restProps
|
|
34
40
|
}: Props = $props();
|
|
35
41
|
|
|
42
|
+
setContext(MAP, () => instance);
|
|
43
|
+
setContext(FOCUSABLE, focusable ? null : -1);
|
|
44
|
+
initBaseLayersStore();
|
|
45
|
+
initOverlaysStore();
|
|
46
|
+
const baseLayersStore = getBaseLayersStore();
|
|
47
|
+
|
|
48
|
+
let container: HTMLElement | null = $state(null);
|
|
49
|
+
|
|
36
50
|
const defaultOptions = {
|
|
37
51
|
center: [48.852, 2.278] as LatLngTuple,
|
|
38
52
|
trackResize: true,
|
|
@@ -40,20 +54,6 @@
|
|
|
40
54
|
maxZoom: 18,
|
|
41
55
|
keyboard: options.keyboard === undefined ? focusable : options.keyboard,
|
|
42
56
|
};
|
|
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
57
|
|
|
58
58
|
$effect(() => {
|
|
59
59
|
if (instance) {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
function onLoad() {
|
|
64
|
+
async function onLoad() {
|
|
65
65
|
if (!container) return;
|
|
66
66
|
// @ts-ignore
|
|
67
67
|
delete window.L.Icon.Default.prototype._getIconUrl;
|
|
@@ -79,11 +79,6 @@
|
|
|
79
79
|
}
|
|
80
80
|
bindEvents(instance, restProps, mapEvents);
|
|
81
81
|
|
|
82
|
-
// create component for the tile layer ?
|
|
83
|
-
window.L.tileLayer(tilesUrl, {
|
|
84
|
-
attribution,
|
|
85
|
-
}).addTo(instance);
|
|
86
|
-
|
|
87
82
|
instance.on('layeradd', (event) => {
|
|
88
83
|
const layer = event.layer;
|
|
89
84
|
if (layer instanceof window.L.Marker) {
|
|
@@ -101,6 +96,16 @@
|
|
|
101
96
|
}
|
|
102
97
|
});
|
|
103
98
|
|
|
99
|
+
// waits for the user layers before adding a default layer
|
|
100
|
+
await tick();
|
|
101
|
+
if (!hasTileLayer(instance)) {
|
|
102
|
+
const defaultBaseLayer = window.L.tileLayer(tilesUrl, {
|
|
103
|
+
attribution,
|
|
104
|
+
});
|
|
105
|
+
defaultBaseLayer.addTo(instance);
|
|
106
|
+
$baseLayersStore['Default Layer'] = defaultBaseLayer;
|
|
107
|
+
}
|
|
108
|
+
|
|
104
109
|
instance.whenReady(() => {
|
|
105
110
|
if (!instance) return;
|
|
106
111
|
// TODO: find out why manually firing the load event is needed
|
|
@@ -108,6 +113,16 @@
|
|
|
108
113
|
});
|
|
109
114
|
}
|
|
110
115
|
|
|
116
|
+
function hasTileLayer(map: LeafletMap) {
|
|
117
|
+
let hasTileLayer = false;
|
|
118
|
+
map.eachLayer(function (layer) {
|
|
119
|
+
if (layer instanceof window.L.TileLayer) {
|
|
120
|
+
hasTileLayer = true;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return hasTileLayer;
|
|
124
|
+
}
|
|
125
|
+
|
|
111
126
|
function leafletLoader(_node: HTMLElement) {
|
|
112
127
|
(async function () {
|
|
113
128
|
await import('leaflet');
|
package/dist/Map.svelte.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import 'leaflet.markercluster/dist/MarkerCluster.css';
|
|
|
3
3
|
import 'leaflet.markercluster/dist/MarkerCluster.Default.css';
|
|
4
4
|
import type { MapOptions, Marker, Map as LeafletMap } from 'leaflet';
|
|
5
5
|
import { type Snippet } from 'svelte';
|
|
6
|
-
import { type MapEvents } from './map.
|
|
6
|
+
import { type MapEvents } from './map.js';
|
|
7
7
|
declare const Map: import("svelte").Component<{
|
|
8
8
|
instance?: LeafletMap;
|
|
9
9
|
options?: MapOptions;
|
|
@@ -12,7 +12,5 @@ declare const Map: import("svelte").Component<{
|
|
|
12
12
|
attribution?: string;
|
|
13
13
|
focusable?: boolean;
|
|
14
14
|
children?: Snippet;
|
|
15
|
-
} & MapEvents, {
|
|
16
|
-
getMarkers: () => Marker[];
|
|
17
|
-
}, "instance" | "options" | "markers">;
|
|
15
|
+
} & MapEvents, {}, "instance" | "options" | "markers">;
|
|
18
16
|
export default Map;
|
package/dist/Marker.svelte
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
MarkerClusterGroup,
|
|
9
9
|
} from 'leaflet';
|
|
10
10
|
import { bindEvents, type LatLngExpression } from './index.js';
|
|
11
|
-
import { markerEvents, updateMarkerProps, type MarkerEvents } from './marker.
|
|
11
|
+
import { markerEvents, updateMarkerProps, type MarkerEvents } from './marker.js';
|
|
12
12
|
import { LAYERGROUP, MAP, MARKER } from './contexts.js';
|
|
13
13
|
|
|
14
14
|
type Props = {
|
package/dist/Marker.svelte.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Snippet } from 'svelte';
|
|
2
2
|
import type { Marker as LeafletMarker, MarkerOptions } from 'leaflet';
|
|
3
3
|
import { type LatLngExpression } from './index.js';
|
|
4
|
-
import { type MarkerEvents } from './marker.
|
|
4
|
+
import { type MarkerEvents } from './marker.js';
|
|
5
5
|
declare const Marker: import("svelte").Component<{
|
|
6
6
|
latlng: LatLngExpression;
|
|
7
7
|
options?: MarkerOptions;
|
|
@@ -16,10 +16,7 @@
|
|
|
16
16
|
MarkerCluster,
|
|
17
17
|
} from 'leaflet';
|
|
18
18
|
import { LAYERGROUP, MAP } from './contexts.js';
|
|
19
|
-
import {
|
|
20
|
-
markerClusterGroupEvents,
|
|
21
|
-
type MarkerClusterGroupEvents,
|
|
22
|
-
} from './markerClusterGroup.svelte.js';
|
|
19
|
+
import { markerClusterGroupEvents, type MarkerClusterGroupEvents } from './markerClusterGroup.js';
|
|
23
20
|
import { bindEvents } from './index.js';
|
|
24
21
|
|
|
25
22
|
type Props = {
|
|
@@ -8,61 +8,61 @@ declare const MarkerClusterGroup: Component<{
|
|
|
8
8
|
options?: MarkerClusterGroupOptions;
|
|
9
9
|
children?: Snippet;
|
|
10
10
|
} & {
|
|
11
|
-
|
|
11
|
+
onclusterclick?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
12
12
|
sourceTarget: import("leaflet").Marker<any>;
|
|
13
13
|
}) => void) | undefined;
|
|
14
|
-
|
|
14
|
+
onclusterdblclick?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
15
15
|
sourceTarget: import("leaflet").Marker<any>;
|
|
16
16
|
}) => void) | undefined;
|
|
17
|
-
|
|
17
|
+
onclustermousedown?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
18
18
|
sourceTarget: import("leaflet").Marker<any>;
|
|
19
19
|
}) => void) | undefined;
|
|
20
|
-
|
|
20
|
+
onclustermouseup?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
21
21
|
sourceTarget: import("leaflet").Marker<any>;
|
|
22
22
|
}) => void) | undefined;
|
|
23
|
-
|
|
23
|
+
onclustermouseover?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
24
24
|
sourceTarget: import("leaflet").Marker<any>;
|
|
25
25
|
}) => void) | undefined;
|
|
26
|
-
|
|
26
|
+
onclustermouseout?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
27
27
|
sourceTarget: import("leaflet").Marker<any>;
|
|
28
28
|
}) => void) | undefined;
|
|
29
|
-
|
|
29
|
+
onclustercontextmenu?: ((e: Omit<import("leaflet").LeafletMouseEvent, "sourceTarget"> & {
|
|
30
30
|
sourceTarget: import("leaflet").Marker<any>;
|
|
31
31
|
}) => void) | undefined;
|
|
32
|
-
|
|
32
|
+
onclusterdragstart?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
33
33
|
sourceTarget: import("leaflet").Marker<any>;
|
|
34
34
|
}) => void) | undefined;
|
|
35
|
-
|
|
35
|
+
onclustermovestart?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
36
36
|
sourceTarget: import("leaflet").Marker<any>;
|
|
37
37
|
}) => void) | undefined;
|
|
38
|
-
|
|
38
|
+
onclusterdrag?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
39
39
|
sourceTarget: import("leaflet").Marker<any>;
|
|
40
40
|
}) => void) | undefined;
|
|
41
|
-
|
|
41
|
+
onclusterdragend?: ((e: Omit<import("leaflet").DragEndEvent, "sourceTarget"> & {
|
|
42
42
|
sourceTarget: import("leaflet").Marker<any>;
|
|
43
43
|
}) => void) | undefined;
|
|
44
|
-
|
|
44
|
+
onclustermoveend?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
45
45
|
sourceTarget: import("leaflet").Marker<any>;
|
|
46
46
|
}) => void) | undefined;
|
|
47
|
-
|
|
47
|
+
onclusteradd?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
48
48
|
sourceTarget: import("leaflet").Marker<any>;
|
|
49
49
|
}) => void) | undefined;
|
|
50
|
-
|
|
50
|
+
onclusterremove?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
51
51
|
sourceTarget: import("leaflet").Marker<any>;
|
|
52
52
|
}) => void) | undefined;
|
|
53
|
-
|
|
53
|
+
onclusterpopupopen?: ((e: Omit<import("leaflet").PopupEvent, "sourceTarget"> & {
|
|
54
54
|
sourceTarget: import("leaflet").Marker<any>;
|
|
55
55
|
}) => void) | undefined;
|
|
56
|
-
|
|
56
|
+
onclusterpopupclose?: ((e: Omit<import("leaflet").PopupEvent, "sourceTarget"> & {
|
|
57
57
|
sourceTarget: import("leaflet").Marker<any>;
|
|
58
58
|
}) => void) | undefined;
|
|
59
|
-
|
|
59
|
+
onclustertooltipopen?: ((e: Omit<import("leaflet").TooltipEvent, "sourceTarget"> & {
|
|
60
60
|
sourceTarget: import("leaflet").Marker<any>;
|
|
61
61
|
}) => void) | undefined;
|
|
62
|
-
|
|
62
|
+
onclustertooltipclose?: ((e: Omit<import("leaflet").TooltipEvent, "sourceTarget"> & {
|
|
63
63
|
sourceTarget: import("leaflet").Marker<any>;
|
|
64
64
|
}) => void) | undefined;
|
|
65
|
-
|
|
65
|
+
onclustermove?: ((e: Omit<import("leaflet").LeafletEvent, "sourceTarget"> & {
|
|
66
66
|
sourceTarget: import("leaflet").Marker<any>;
|
|
67
67
|
}) => void) | undefined;
|
|
68
68
|
} & import("./utils.js").CreateSvelteEventsMap<readonly ["animationend", "spiderfied", "unspiderfied"]>, {}, "instance">;
|
package/dist/Polygon.svelte
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getContext, onDestroy, onMount } from 'svelte';
|
|
3
3
|
import type { Polygon as LeafletPolygon, PolylineOptions, LayerGroup } from 'leaflet';
|
|
4
|
-
import { polygonEvents, updatePolylineProps, type PolygonEvents } from './polyline.
|
|
4
|
+
import { polygonEvents, updatePolylineProps, type PolygonEvents } from './polyline.js';
|
|
5
5
|
import { bindEvents, type Latlngs, type LeafletMap } from './index.js';
|
|
6
6
|
import { LAYERGROUP, MAP } from './contexts.js';
|
|
7
7
|
|
package/dist/Polygon.svelte.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Polygon as LeafletPolygon, PolylineOptions } from 'leaflet';
|
|
2
|
-
import { type PolygonEvents } from './polyline.
|
|
2
|
+
import { type PolygonEvents } from './polyline.js';
|
|
3
3
|
import { type Latlngs } from './index.js';
|
|
4
4
|
declare const Polygon: import("svelte").Component<{
|
|
5
5
|
latlngs: Latlngs<3>;
|
package/dist/Polyline.svelte
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getContext, onDestroy, onMount } from 'svelte';
|
|
3
3
|
import type { Polyline as LeafletPolyline, PolylineOptions, LayerGroup } from 'leaflet';
|
|
4
|
-
import { polygonEvents, updatePolylineProps, type PolygonEvents } from './polyline.
|
|
4
|
+
import { polygonEvents, updatePolylineProps, type PolygonEvents } from './polyline.js';
|
|
5
5
|
import { bindEvents, type Latlngs, type LeafletMap } from './index.js';
|
|
6
6
|
import { LAYERGROUP, MAP } from './contexts.js';
|
|
7
7
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Polyline as LeafletPolyline, PolylineOptions } from 'leaflet';
|
|
2
|
-
import { type PolygonEvents } from './polyline.
|
|
2
|
+
import { type PolygonEvents } from './polyline.js';
|
|
3
3
|
import { type Latlngs } from './index.js';
|
|
4
4
|
declare const Polyline: import("svelte").Component<{
|
|
5
5
|
latlngs: Latlngs;
|