@radiofrance/svelte-leaflet 1.0.0-next.0 → 1.0.0-next.2

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 CHANGED
@@ -1,12 +1,22 @@
1
1
  # @radiofrance/svelte-leaflet
2
2
 
3
- A library that wraps leaflet classes in domless/renderless svelte components.
3
+ Simple Leaflet maps for your Svelte projects.
4
4
 
5
- ## Compatibility
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
+ - ![](./static/map-types.png)
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
- Version 1.0.0 and above are compatible with Svelte 5.
16
+ ## Compatibility
8
17
 
9
- For svelte 3 and 4, use version 0.1.x (not actively maintained).
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
- ### Map
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
- `<Popup>` children will be displayed when the marker is clicked.
29
+ - Marker
30
+ - DivOverlay
31
+ - ✅ Popup
32
+ - Tooltip
65
33
 
66
- - Use as a `<Marker>` child.
34
+ ### Raster Layers
67
35
 
68
- #### Attributes
36
+ - TileLayer
37
+ - TileLayer.WMS
38
+ - ImageOverlay
39
+ - VideoOverlay
69
40
 
70
- | Name | Type | Default | Notes |
71
- | --------- | ----------------------------------------------------------------- | ------- | ------------------------------------ |
72
- | `options` | [PopupOptions](https://leafletjs.com/reference.html#popup-option) | `{}` | options to pass to the leaflet popup |
41
+ ### Vector Layers
73
42
 
74
- ### MarkerClusterGroup
43
+ - Path
44
+ - ✅ Polyline
45
+ - ✅ Polygon
46
+ - Rectangle
47
+ - Circle
48
+ - CircleMarker
49
+ - SVGOverlay
50
+ - SVG
51
+ - Canvas
75
52
 
76
- Enables clustering of child markers
53
+ ### Other Layers
77
54
 
78
- - Use as a `<Map>` child
55
+ - LayerGroup
56
+ - FeatureGroup
57
+ - GeoJSON
58
+ - GridLayer
79
59
 
80
- #### Attributes
60
+ ### Basic Types
81
61
 
82
- | Name | Type | Default | Notes |
83
- | --------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------- |
84
- | `options` | [MarkerClusterGroupOptions](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/leaflet.markercluster/index.d.ts#L36) | `{}` | [MarkerClusterGroup options](https://github.com/leaflet/Leaflet.markercluster?tab=readme-ov-file#defaults) |
62
+ - LatLng
63
+ - LatLngBounds
64
+ - Point
65
+ - Bounds
66
+ - ✅ Icon
67
+ - ✅ DivIcon
85
68
 
86
- ### Polyline
69
+ ### Controls
87
70
 
88
- Allows to draw lines on the map
71
+ - Zoom
72
+ - Attribution
73
+ - Layers
74
+ - Scale
89
75
 
90
- #### Attributes
76
+ ### Extra
91
77
 
92
- | Name | Type | Default | Notes |
93
- | --------- | ----------------------------------------------------------------------- | ---------- | --------------------------------------- |
94
- | `latlngs` | [LatLng[]](https://leafletjs.com/reference.html#latlng) | _required_ | array of points to draw the line |
95
- | `options` | [PolylineOptions](https://leafletjs.com/reference.html#polyline-option) | `{}` | options to pass to the leaflet polyline |
78
+ - MarkerClusterGroup
79
+ - LocateControl
80
+ - ![locate control](./static//locate-control.png)
package/dist/Map.svelte CHANGED
@@ -9,7 +9,7 @@
9
9
  import type { MapOptions, Marker, Map as LeafletMap, LatLngTuple } from 'leaflet';
10
10
  import { bindEvents } from './index.js';
11
11
  import { setContext, type Snippet } from 'svelte';
12
- import { mapEvents, updateMapProps, type MapEvents } from './map.svelte.js';
12
+ import { mapEvents, updateMapProps, type MapEvents } from './map.js';
13
13
  import { FOCUSABLE, MAP } from './contexts.js';
14
14
 
15
15
  type Props = {
@@ -33,6 +33,10 @@
33
33
  ...restProps
34
34
  }: Props = $props();
35
35
 
36
+ setContext(MAP, () => instance);
37
+ setContext(FOCUSABLE, focusable ? null : -1);
38
+ let container: HTMLElement | null = $state(null);
39
+
36
40
  const defaultOptions = {
37
41
  center: [48.852, 2.278] as LatLngTuple,
38
42
  trackResize: true,
@@ -40,20 +44,6 @@
40
44
  maxZoom: 18,
41
45
  keyboard: options.keyboard === undefined ? focusable : options.keyboard,
42
46
  };
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
47
 
58
48
  $effect(() => {
59
49
  if (instance) {
@@ -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.svelte.js';
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;
@@ -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.svelte.js';
11
+ import { markerEvents, updateMarkerProps, type MarkerEvents } from './marker.js';
12
12
  import { LAYERGROUP, MAP, MARKER } from './contexts.js';
13
13
 
14
14
  type Props = {
@@ -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.svelte.js';
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 = {
@@ -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.svelte.js';
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 { Polygon as LeafletPolygon, PolylineOptions } from 'leaflet';
2
- import { type PolygonEvents } from './polyline.svelte.js';
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>;
@@ -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.svelte.js';
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.svelte.js';
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;
package/dist/Popup.svelte CHANGED
@@ -9,7 +9,7 @@
9
9
  } from 'leaflet';
10
10
  import { getContext, onDestroy, onMount, type Snippet } from 'svelte';
11
11
  import { bindEvents } from './index.js';
12
- import { popupEvents, updatePopupProps, type PopupEvents } from './popup.svelte.js';
12
+ import { popupEvents, updatePopupProps, type PopupEvents } from './popup.js';
13
13
  import { LAYERGROUP, MAP, MARKER } from './contexts.js';
14
14
 
15
15
  type Props = {
@@ -1,6 +1,6 @@
1
1
  import type { LatLngExpression, PopupOptions, Popup as LeafletPopup } from 'leaflet';
2
2
  import { type Snippet } from 'svelte';
3
- import { type PopupEvents } from './popup.svelte.js';
3
+ import { type PopupEvents } from './popup.js';
4
4
  declare const Popup: import("svelte").Component<{
5
5
  latlng?: LatLngExpression;
6
6
  options?: PopupOptions;
@@ -0,0 +1,21 @@
1
+ <script lang="ts">
2
+ import { getContext, onMount, type Snippet } from 'svelte';
3
+ import type { Control, Map as LeafletMap } from 'leaflet';
4
+ import { MAP } from './contexts.js';
5
+
6
+ type Props = {
7
+ instance?: L.Control;
8
+ children?: Snippet;
9
+ options?: Control.ZoomOptions;
10
+ };
11
+
12
+ let { instance = $bindable(), options }: Props = $props();
13
+
14
+ const getMap = getContext<() => LeafletMap>(MAP);
15
+
16
+ onMount(() => {
17
+ const map = getMap();
18
+ instance = window.L.control.zoom(options);
19
+ instance.addTo(map);
20
+ });
21
+ </script>
@@ -0,0 +1,8 @@
1
+ import { type Snippet } from 'svelte';
2
+ import type { Control } from 'leaflet';
3
+ declare const ZoomControl: import("svelte").Component<{
4
+ instance?: L.Control;
5
+ children?: Snippet;
6
+ options?: Control.ZoomOptions;
7
+ }, {}, "instance">;
8
+ export default ZoomControl;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- import type { ControlPosition, Evented, LatLngExpression, LeafletEventHandlerFnMap, LocateOptions } from 'leaflet';
1
+ import type { ControlPosition, Evented, LatLngExpression, LeafletEvent as OriginalLeafletEvent, LeafletEventHandlerFnMap, LocateOptions } from 'leaflet';
2
2
  import DivIcon from './DivIcon.svelte';
3
+ import LocateControl from './LocateControl.svelte';
3
4
  import Map from './Map.svelte';
4
5
  import Marker from './Marker.svelte';
5
6
  import MarkerClusterGroup from './MarkerClusterGroup.svelte';
6
- import Popup from './Popup.svelte';
7
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';
8
+ import Polyline from './Polyline.svelte';
9
+ import Popup from './Popup.svelte';
10
+ export { DivIcon, Map, Marker, MarkerClusterGroup, Popup, Polyline, Polygon, LocateControl };
11
+ export type { Circle as LeafletCircle, CircleOptions, DragEndEvent, ErrorEvent, LatLngBoundsLiteral, LatLngExpression, LatLngLiteral, LatLngTuple, LayerEvent, LayersControlEvent, LeafletKeyboardEvent, LeafletMouseEvent, LocationEvent, Map as LeafletMap, Marker as LeafletMarker, MapOptions, MarkerOptions, PathOptions, PopupEvent, PopupOptions, ResizeEvent, TooltipEvent, } from 'leaflet';
11
12
  export type Latlngs<D = 2> = 2 extends D ? LatLngExpression[] | LatLngExpression[][] : 3 extends D ? LatLngExpression[] | LatLngExpression[][] | LatLngExpression[][][] : never;
12
13
  export type PrefixedLeafletEventHandlerFnMap = {
13
14
  [K in keyof LeafletEventHandlerFnMap as `on${K}`]: LeafletEventHandlerFnMap[K];
@@ -17,3 +18,6 @@ export type LocateControlOptions = {
17
18
  position?: ControlPosition;
18
19
  options?: LocateOptions;
19
20
  };
21
+ export type LeafletEvent<SourceTarget = any> = Omit<OriginalLeafletEvent, 'sourceTarget'> & {
22
+ sourceTarget: SourceTarget;
23
+ };
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  // Reexport your entry components here
2
2
  import DivIcon from './DivIcon.svelte';
3
+ import LocateControl from './LocateControl.svelte';
3
4
  import Map from './Map.svelte';
4
5
  import Marker from './Marker.svelte';
5
6
  import MarkerClusterGroup from './MarkerClusterGroup.svelte';
6
- import Popup from './Popup.svelte';
7
7
  import Polygon from './Polygon.svelte';
8
- import LocateControl from './LocateControl.svelte';
9
- export { DivIcon, Map, Marker, MarkerClusterGroup, Popup, Polygon, LocateControl };
8
+ import Polyline from './Polyline.svelte';
9
+ import Popup from './Popup.svelte';
10
+ export { DivIcon, Map, Marker, MarkerClusterGroup, Popup, Polyline, Polygon, LocateControl };
10
11
  export function bindEvents(instance, eventsProps, events) {
11
12
  events.forEach((event) => {
12
13
  const eventCallback = eventsProps[`on${event}`];
@@ -1,4 +1,4 @@
1
- import { type MarkerEvents } from './marker.svelte.js';
1
+ import { type MarkerEvents } from './marker.js';
2
2
  import type { CreateSvelteEventsMap } from './utils.js';
3
3
  type ClusterifyMarkerEvent<E> = E extends `on${infer N}` ? `oncluster${N}` : never;
4
4
  declare const clusterSpecificEvents: readonly ["animationend", "spiderfied", "unspiderfied"];
@@ -1,4 +1,4 @@
1
- import { markerEvents } from './marker.svelte.js';
1
+ import { markerEvents } from './marker.js';
2
2
  const clusteredMarkerEvents = markerEvents.map((event) => `cluster${event}`);
3
3
  const clusterSpecificEvents = ['animationend', 'spiderfied', 'unspiderfied'];
4
4
  export const markerClusterGroupEvents = [
package/dist/utils.d.ts CHANGED
@@ -10,3 +10,6 @@ export type CreateSvelteEventsMap<EventNames extends readonly (keyof LeafletEven
10
10
  sourceTarget: SourceTarget;
11
11
  }) => void;
12
12
  };
13
+ export type Simplify<T> = T extends object ? T extends infer O ? {
14
+ [K in keyof O]: Simplify<O[K]>;
15
+ } : never : T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiofrance/svelte-leaflet",
3
- "version": "1.0.0-next.0",
3
+ "version": "1.0.0-next.2",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes