@radiofrance/svelte-leaflet 0.1.0-alpha.12 → 0.1.0-alpha.13

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.
@@ -1,40 +1,33 @@
1
1
  <script>import { createEventDispatcher, getContext, onDestroy, onMount } from "svelte";
2
- import {
3
- bindEvents,
4
- interactiveLayerEvents,
5
- layerEvents,
6
- popupEvents,
7
- tooltipEvents
8
- } from "./index.js";
2
+ import { bindEvents, interactiveLayerEvents, layerEvents, popupEvents, tooltipEvents } from "./index.js";
9
3
  export let center;
10
4
  export let options = { radius: 100 };
11
5
  export let instance = void 0;
12
6
  const events = [
13
- "move",
14
- ...interactiveLayerEvents,
15
- ...layerEvents,
16
- ...popupEvents,
17
- ...tooltipEvents
7
+ "move",
8
+ ...interactiveLayerEvents,
9
+ ...layerEvents,
10
+ ...popupEvents,
11
+ ...tooltipEvents
18
12
  ];
19
13
  let map = getContext("map")();
20
14
  const dispatch = createEventDispatcher();
21
- $:
22
- updateCircle(center, options);
15
+ $: updateCircle(center, options);
23
16
  function updateCircle(center2, options2) {
24
- if (instance) {
25
- instance.setLatLng(center2);
26
- instance.setStyle(options2);
27
- instance.setRadius(options2.radius);
28
- }
17
+ if (instance) {
18
+ instance.setLatLng(center2);
19
+ instance.setStyle(options2);
20
+ instance.setRadius(options2.radius);
21
+ }
29
22
  }
30
23
  onMount(async () => {
31
- const L = window.L;
32
- instance = new L.Circle(center, options);
33
- bindEvents(instance, dispatch, events);
34
- instance.addTo(map);
24
+ const L = window.L;
25
+ instance = new L.Circle(center, options);
26
+ bindEvents(instance, dispatch, events);
27
+ instance.addTo(map);
35
28
  });
36
29
  onDestroy(() => {
37
- instance?.remove();
30
+ instance?.remove();
38
31
  });
39
32
  </script>
40
33
 
package/dist/Map.svelte CHANGED
@@ -5,20 +5,11 @@ import markerIcon2x from "leaflet/dist/images/marker-icon-2x.png";
5
5
  import markerIcon from "leaflet/dist/images/marker-icon.png";
6
6
  import markerShadow from "leaflet/dist/images/marker-shadow.png";
7
7
  import { createEventDispatcher, setContext, tick } from "svelte";
8
- import {
9
- bindEvents,
10
- keyboardEvents,
11
- layerGroupEvents,
12
- layersControlEvents,
13
- leafletMouseEvents,
14
- locationEvents,
15
- mapStateChangeEvents,
16
- popupEvents,
17
- tooltipEvents
18
- } from "./index.js";
8
+ import { bindEvents, keyboardEvents, layerGroupEvents, layersControlEvents, leafletMouseEvents, locationEvents, mapStateChangeEvents, popupEvents, tooltipEvents } from "./index.js";
19
9
  import GeolocationButton from "./private/GeolocationButton.svelte";
20
10
  let L;
21
11
  let locateButtonContainer;
12
+ const defaultOptions = { center: [46.6188459, 1.7262114], zoom: 7, maxZoom: 18 };
22
13
  export let options = {};
23
14
  export let tilesUrl = "https://tile.openstreetmap.org/{z}/{x}/{y}.png";
24
15
  export let attribution = `&copy;<a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>`;
@@ -26,72 +17,72 @@ export let instance = null;
26
17
  export let locateControl = void 0;
27
18
  const dispatch = createEventDispatcher();
28
19
  export const getMarkers = () => {
29
- const markers = [];
30
- instance?.eachLayer((layer) => {
31
- if (layer instanceof L.Marker) {
32
- markers.push(layer);
33
- }
34
- });
35
- return markers;
20
+ const markers = [];
21
+ instance?.eachLayer((layer) => {
22
+ if (layer instanceof L.Marker) {
23
+ markers.push(layer);
24
+ }
25
+ });
26
+ return markers;
36
27
  };
37
28
  setContext("map", () => instance);
38
29
  let container;
39
- $:
40
- if (instance)
30
+ $: if (instance) {
41
31
  instance.options = Object.assign(instance.options, options);
32
+ }
42
33
  function resizeMap() {
43
- instance?.invalidateSize();
34
+ instance?.invalidateSize();
44
35
  }
45
36
  const events = [
46
- ...keyboardEvents,
47
- ...layerGroupEvents,
48
- ...layersControlEvents,
49
- ...leafletMouseEvents,
50
- ...locationEvents,
51
- ...mapStateChangeEvents,
52
- ...popupEvents,
53
- ...tooltipEvents,
54
- "autopanstart",
55
- "zoomanim"
37
+ ...keyboardEvents,
38
+ ...layerGroupEvents,
39
+ ...layersControlEvents,
40
+ ...leafletMouseEvents,
41
+ ...locationEvents,
42
+ ...mapStateChangeEvents,
43
+ ...popupEvents,
44
+ ...tooltipEvents,
45
+ "autopanstart",
46
+ "zoomanim"
56
47
  ];
57
48
  function onLoad() {
58
- L = window.L;
59
- delete L.Icon.Default.prototype._getIconUrl;
60
- L.Icon.Default.mergeOptions({
61
- iconRetinaUrl: markerIcon2x,
62
- iconUrl: markerIcon,
63
- shadowUrl: markerShadow
64
- });
65
- instance = L.map(container, { maxZoom: 18, ...options });
66
- bindEvents(instance, dispatch, events);
67
- L.tileLayer(tilesUrl, {
68
- attribution
69
- }).addTo(instance);
70
- instance.whenReady(async () => {
71
- instance.fireEvent("load");
72
- await tick();
73
- if (locateControl) {
74
- const control = L.Control.extend({
75
- position: "topleft",
76
- onAdd() {
77
- const button = locateButtonContainer.firstChild;
78
- button.onclick = (e) => {
79
- e.stopPropagation();
80
- instance.locate(locateControl?.options);
81
- };
82
- return button;
49
+ L = window.L;
50
+ delete L.Icon.Default.prototype._getIconUrl;
51
+ L.Icon.Default.mergeOptions({
52
+ iconRetinaUrl: markerIcon2x,
53
+ iconUrl: markerIcon,
54
+ shadowUrl: markerShadow
55
+ });
56
+ instance = L.map(container, { ...defaultOptions, ...options });
57
+ bindEvents(instance, dispatch, events);
58
+ L.tileLayer(tilesUrl, {
59
+ attribution
60
+ }).addTo(instance);
61
+ instance.whenReady(async () => {
62
+ instance.fireEvent("load");
63
+ await tick();
64
+ if (locateControl) {
65
+ const control = L.Control.extend({
66
+ position: "topleft",
67
+ onAdd() {
68
+ const button = locateButtonContainer.firstChild;
69
+ button.onclick = (e) => {
70
+ e.stopPropagation();
71
+ instance.locate(locateControl?.options);
72
+ };
73
+ return button;
74
+ }
75
+ });
76
+ instance.addControl(new control(locateControl));
83
77
  }
84
- });
85
- instance.addControl(new control(locateControl));
86
- }
87
- });
78
+ });
88
79
  }
89
80
  function leafletLoader(_node) {
90
- (async function() {
91
- await import("leaflet");
92
- await import("leaflet.markercluster");
93
- onLoad();
94
- })();
81
+ (async function () {
82
+ await import("leaflet");
83
+ await import("leaflet.markercluster");
84
+ onLoad();
85
+ })();
95
86
  }
96
87
  </script>
97
88
 
@@ -99,7 +90,7 @@ function leafletLoader(_node) {
99
90
 
100
91
  <div class="Map" bind:this={container} style="height: 100%; width: 100%">
101
92
  {#if instance}
102
- <slot map={instance} />
93
+ <slot />
103
94
  {/if}
104
95
  </div>
105
96
  <div class="locate-button-container" bind:this={locateButtonContainer}>
@@ -108,12 +99,4 @@ function leafletLoader(_node) {
108
99
  </slot>
109
100
  </div>
110
101
 
111
- <style>
112
- .Map {
113
- z-index: 0;
114
- }
115
-
116
- .locate-button-container {
117
- display: none;
118
- }
119
- </style>
102
+ <style>.Map{z-index:0}.locate-button-container{display:none}</style>
@@ -55,9 +55,7 @@ declare const __propDef: {
55
55
  [evt: string]: CustomEvent<any>;
56
56
  };
57
57
  slots: {
58
- default: {
59
- map: Map;
60
- };
58
+ default: {};
61
59
  'locate-button': {};
62
60
  };
63
61
  };
@@ -1,4 +1,5 @@
1
- <script context="module"></script>
1
+ <script context="module">"use strict";
2
+ </script>
2
3
 
3
4
  <script>import { createEventDispatcher, getContext, onDestroy, setContext, tick } from "svelte";
4
5
  const dispatch = createEventDispatcher();
@@ -12,43 +13,40 @@ let marker;
12
13
  const getMap = getContext("map");
13
14
  const getLayerGroup = getContext("layerGroup");
14
15
  setContext("layer", () => marker);
15
- $:
16
- recreateMarker(size, latlng, id, options);
16
+ $: recreateMarker(size, latlng, id, options);
17
17
  async function recreateMarker(size2, latlng2, id2, options2) {
18
- removeMarker();
19
- await tick();
20
- createMarker(size2, latlng2, id2, options2);
18
+ removeMarker();
19
+ await tick();
20
+ createMarker(size2, latlng2, id2, options2);
21
21
  }
22
22
  async function createMarker(size2, latlng2, id2, options2) {
23
- await tick();
24
- const layerGroup = getLayerGroup?.();
25
- const map = getMap();
26
- const mapOrLayerGroup = layerGroup || map;
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
- }
23
+ await tick();
24
+ const layerGroup = getLayerGroup?.();
25
+ const map = getMap();
26
+ const mapOrLayerGroup = layerGroup || map;
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(L.divIcon({
34
+ html: markerElement,
35
+ className: "map-marker",
36
+ iconSize: L.point(size2, size2)
37
+ }));
38
+ }
41
39
  }
42
40
  function removeMarker() {
43
- if (!marker)
44
- return;
45
- const layerGroup = getLayerGroup?.();
46
- const map = getMap();
47
- const mapOrLayerGroup = layerGroup || map;
48
- mapOrLayerGroup.removeLayer(marker);
41
+ if (!marker)
42
+ return;
43
+ const layerGroup = getLayerGroup?.();
44
+ const map = getMap();
45
+ const mapOrLayerGroup = layerGroup || map;
46
+ mapOrLayerGroup.removeLayer(marker);
49
47
  }
50
48
  onDestroy(() => {
51
- removeMarker();
49
+ removeMarker();
52
50
  });
53
51
  </script>
54
52
 
@@ -61,12 +59,4 @@ onDestroy(() => {
61
59
  {/if}
62
60
  {/key}
63
61
 
64
- <style>
65
- .leaflet-marker {
66
- display: none;
67
- }
68
-
69
- :global(.map-marker .leaflet-marker) {
70
- display: inherit;
71
- }
72
- </style>
62
+ <style>.leaflet-marker{display:none}:global(.map-marker .leaflet-marker){display:inherit}</style>
@@ -7,38 +7,30 @@ const getMap = getContext("map");
7
7
  let clusterGroup;
8
8
  setContext("layerGroup", () => clusterGroup);
9
9
  onMount(async () => {
10
- const map = getMap();
11
- if (icon) {
12
- options.iconCreateFunction = function(cluster) {
13
- const html = document.createElement("div");
14
- new icon({ target: html, props: { count: cluster.getChildCount() } });
15
- return L.divIcon({ html });
16
- };
17
- }
18
- if (markerElement.childElementCount > 0) {
19
- options.iconCreateFunction = function(cluster) {
20
- const html = markerElement.innerHTML.replace("%count%", cluster.getChildCount().toString());
21
- return L.divIcon({ html });
22
- };
23
- }
24
- clusterGroup = L.markerClusterGroup(options);
25
- map.addLayer(clusterGroup);
10
+ const map = getMap();
11
+ if (icon) {
12
+ options.iconCreateFunction = function (cluster) {
13
+ const html = document.createElement("div");
14
+ new icon({ target: html, props: { count: cluster.getChildCount() } });
15
+ return L.divIcon({ html });
16
+ };
17
+ }
18
+ if (markerElement.childElementCount > 0) {
19
+ options.iconCreateFunction = function (cluster) {
20
+ const html = markerElement.innerHTML.replace("%count%", cluster.getChildCount().toString());
21
+ return L.divIcon({ html });
22
+ };
23
+ }
24
+ clusterGroup = L.markerClusterGroup(options);
25
+ map.addLayer(clusterGroup);
26
26
  });
27
27
  </script>
28
28
 
29
29
  <slot />
30
- <template>
30
+
31
31
  <div bind:this={markerElement} class="leaflet-markercluster">
32
32
  <slot name="icon" />
33
33
  </div>
34
- </template>
35
34
 
36
- <style>
37
- /* .leaflet-markercluster {
38
- display: none;
39
- }
40
35
 
41
- :global(.map-marker .leaflet-markercluster) {
42
- display: inherit;
43
- } */
44
- </style>
36
+ <style></style>
@@ -4,22 +4,21 @@ export let options = {};
4
4
  let line;
5
5
  let map = getContext("map")();
6
6
  const dispatch = createEventDispatcher();
7
- $:
8
- updateLine(latlngs, options);
7
+ $: updateLine(latlngs, options);
9
8
  function updateLine(latLngs, lineStyle) {
10
- if (line) {
11
- line.setLatLngs(latLngs);
12
- line.setStyle(lineStyle);
13
- }
9
+ if (line) {
10
+ line.setLatLngs(latLngs);
11
+ line.setStyle(lineStyle);
12
+ }
14
13
  }
15
14
  onMount(async () => {
16
- const L = window.L;
17
- line = new L.Polyline(latlngs, options);
18
- line.on("click", (e) => dispatch("click", e));
19
- line.addTo(map);
15
+ const L = window.L;
16
+ line = new L.Polyline(latlngs, options);
17
+ line.on("click", (e) => dispatch("click", e));
18
+ line.addTo(map);
20
19
  });
21
20
  onDestroy(() => {
22
- line?.remove();
21
+ line?.remove();
23
22
  });
24
23
  </script>
25
24
 
package/dist/Popup.svelte CHANGED
@@ -1,7 +1,7 @@
1
1
  <script>import { getContext, onDestroy, onMount, tick } from "svelte";
2
2
  const L = globalThis.window.L;
3
3
  export let options = {
4
- autoPan: false
4
+ autoPan: false
5
5
  };
6
6
  let popup = void 0;
7
7
  let popupElement;
@@ -10,34 +10,34 @@ let popupOpen = false;
10
10
  const getLayer = getContext("layer");
11
11
  let layer;
12
12
  function removePopup() {
13
- if (!popup)
14
- return;
15
- layer.unbindPopup();
16
- popup.remove();
13
+ if (!popup)
14
+ return;
15
+ layer.unbindPopup();
16
+ popup.remove();
17
17
  }
18
18
  async function createPopup() {
19
- await tick();
20
- layer = getLayer();
21
- popup = L.popup().setContent(popupElement);
22
- layer.bindPopup(popup, options);
23
- layer.on("popupopen", async () => {
24
- popupOpen = true;
25
- showContents = true;
26
19
  await tick();
27
- popup?.update();
28
- });
29
- layer.on("popupclose", async () => {
30
- popupOpen = false;
31
- setTimeout(() => {
32
- if (!popupOpen) {
33
- showContents = false;
34
- }
35
- }, 200);
36
- });
20
+ layer = getLayer();
21
+ popup = L.popup().setContent(popupElement);
22
+ layer.bindPopup(popup, options);
23
+ layer.on("popupopen", async () => {
24
+ popupOpen = true;
25
+ showContents = true;
26
+ await tick();
27
+ popup?.update();
28
+ });
29
+ layer.on("popupclose", async () => {
30
+ popupOpen = false;
31
+ setTimeout(() => {
32
+ if (!popupOpen) {
33
+ showContents = false;
34
+ }
35
+ }, 200);
36
+ });
37
37
  }
38
38
  onMount(createPopup);
39
39
  onDestroy(() => {
40
- removePopup();
40
+ removePopup();
41
41
  });
42
42
  </script>
43
43
 
@@ -8,25 +8,4 @@
8
8
  </button>
9
9
  </div>
10
10
 
11
- <style>
12
- button {
13
- display: flex;
14
- align-items: center;
15
- justify-content: center;
16
- width: 30px;
17
- height: 30px;
18
- background-color: white;
19
- cursor: pointer;
20
- border: none;
21
- border-radius: 2px;
22
- }
23
-
24
- button:hover {
25
- background-color: #f4f4f4;
26
- }
27
-
28
- div {
29
- border-radius: 4px;
30
- border: 2px solid rgba(0, 0, 0, 0.2);
31
- }
32
- </style>
11
+ <style>button{display:flex;align-items:center;justify-content:center;width:30px;height:30px;background-color:#fff;cursor:pointer;border:0;border-radius:2px}button:hover{background-color:#f4f4f4}div{border-radius:4px;border:2px solid rgba(0,0,0,.2)}</style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiofrance/svelte-leaflet",
3
- "version": "0.1.0-alpha.12",
3
+ "version": "0.1.0-alpha.13",
4
4
  "description": "A library that wraps leaflet classes in domless/renderless svelte components.",
5
5
  "keywords": [
6
6
  "svelte",
@@ -46,6 +46,7 @@
46
46
  "svelte": "^4.0.0"
47
47
  },
48
48
  "devDependencies": {
49
+ "@csstools/postcss-global-data": "^2.1.1",
49
50
  "@playwright/test": "^1.28.1",
50
51
  "@sveltejs/adapter-auto": "^3.0.0",
51
52
  "@sveltejs/kit": "^2.0.0",
@@ -56,16 +57,21 @@
56
57
  "@types/eslint": "8.56.0",
57
58
  "@typescript-eslint/eslint-plugin": "^6.0.0",
58
59
  "@typescript-eslint/parser": "^6.0.0",
60
+ "autoprefixer": "^10.4.19",
59
61
  "d3-scale": "^4.0.2",
60
62
  "d3-scale-chromatic": "^3.0.0",
61
63
  "eslint": "^8.56.0",
62
64
  "eslint-config-prettier": "^9.1.0",
63
65
  "eslint-plugin-svelte": "^2.35.1",
66
+ "postcss": "^8.4.39",
67
+ "postcss-csso": "^6.0.1",
68
+ "postcss-preset-env": "^9.6.0",
64
69
  "prettier": "^3.1.1",
65
70
  "prettier-plugin-svelte": "^3.1.2",
66
71
  "publint": "^0.1.9",
67
72
  "svelte": "^4.2.7",
68
73
  "svelte-check": "^3.6.0",
74
+ "svelte-preprocess": "^6.0.1",
69
75
  "tslib": "^2.4.1",
70
76
  "typescript": "^5.0.0",
71
77
  "vite": "^5.0.11",