leaflet-html 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,10 @@
14
14
  integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
15
15
  crossorigin=""
16
16
  ></script>
17
- <script src="https://www.unpkg.com/leaflet-html@0.1.3/dist/leaflet-html.umd.js"></script>
17
+ <script
18
+ src="https://www.unpkg.com/leaflet-html@0.1.4/dist/leaflet-html.umd.js"
19
+ defer
20
+ ></script>
18
21
  <style>
19
22
  * {
20
23
  margin: 0;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "leaflet-html",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "description": "Leaflet expressed in HTML",
6
6
  "source": "src/index.js",
7
7
  "main": "./dist/leaflet-html.js",
8
+ "umd:main": "./dist/leaflet-html.umd.js",
8
9
  "exports": {
9
10
  "default": "./dist/leaflet-html.js"
10
11
  },
package/src/index.js CHANGED
@@ -1,90 +1,97 @@
1
1
  const render = () => {
2
2
  // Render Leaflet API calls
3
3
  document.querySelectorAll("[data-leaflet-html]").forEach((el) => {
4
- const { center, zoom } = el.dataset
5
- const map = L.map(el).setView(JSON.parse(center), parseInt(zoom))
4
+ const { center, zoom } = el.dataset;
5
+ const map = L.map(el).setView(JSON.parse(center), parseInt(zoom));
6
6
 
7
7
  // L.control.layers
8
8
  el.querySelectorAll("[data-control-layers]").forEach((el) => {
9
- const baseMaps = {}
10
-
9
+ const baseMaps = {};
10
+
11
11
  // L.tileLayers
12
12
  el.querySelectorAll("[data-tile-layer]").forEach((tileEl) => {
13
- const { show, urlTemplate, attribution, maxZoom, name } = tileEl.dataset
13
+ const { show, urlTemplate, attribution, maxZoom, name } =
14
+ tileEl.dataset;
14
15
  baseMaps[name] = L.tileLayer(urlTemplate, { maxZoom, attribution });
15
16
  if (show != null) {
16
- baseMaps[name].addTo(map)
17
+ baseMaps[name].addTo(map);
17
18
  }
18
- })
19
+ });
19
20
 
20
- const overlayMaps = {}
21
+ const overlayMaps = {};
21
22
  // L.layerGroup
22
23
  el.querySelectorAll("[data-layer-group]").forEach((el) => {
23
- const { name } = el.dataset
24
- const layers = []
24
+ const { name } = el.dataset;
25
+ const layers = [];
25
26
 
26
- const observer = new MutationObserver(function(mutations) {
27
- const group = overlayMaps[name]
27
+ const observer = new MutationObserver(function (mutations) {
28
+ const group = overlayMaps[name];
28
29
 
29
- mutations.forEach(mutation => {
30
- mutation.addedNodes.forEach(node => {
31
- const { latLng } = node.dataset // MutationObserver needed
32
- const layer = L.marker(JSON.parse(latLng))
33
- group.addLayer(layer)
34
- map.addLayer(layer)
35
- })
30
+ mutations.forEach((mutation) => {
31
+ mutation.addedNodes.forEach((node) => {
32
+ const { latLng } = node.dataset; // MutationObserver needed
33
+ const layer = L.marker(JSON.parse(latLng));
34
+ group.addLayer(layer);
35
+ map.addLayer(layer);
36
+ });
36
37
 
37
- mutation.removedNodes.forEach(node => {
38
- const { _leafletId } = node.dataset
39
- const layer = group.getLayer(_leafletId)
40
- group.removeLayer(layer)
38
+ mutation.removedNodes.forEach((node) => {
39
+ const { _leafletId } = node.dataset;
40
+ const layer = group.getLayer(_leafletId);
41
+ group.removeLayer(layer);
41
42
 
42
- map.removeLayer(layer)
43
- })
44
- })
45
- })
46
- observer.observe(el, { childList: true })
43
+ map.removeLayer(layer);
44
+ });
45
+ });
46
+ });
47
+ observer.observe(el, { childList: true });
47
48
 
48
49
  // L.marker
49
50
  el.querySelectorAll("[data-marker]").forEach((el) => {
50
- const { latLng } = el.dataset
51
- const { opacity = "1.0" } = el.dataset
52
- const options = { opacity: parseFloat(opacity) }
53
- console.log(options)
54
- const marker = L.marker(JSON.parse(latLng), options).addTo(map)
55
- el.dataset._leafletId = L.stamp(marker) // Save ID for later
51
+ const { latLng } = el.dataset;
52
+ const { opacity = "1.0" } = el.dataset;
53
+ const options = { opacity: parseFloat(opacity) };
54
+ console.log(options);
55
+ const marker = L.marker(JSON.parse(latLng), options).addTo(map);
56
+ el.dataset._leafletId = L.stamp(marker); // Save ID for later
56
57
 
57
- const observer = new MutationObserver(function(mutations) {
58
- mutations.forEach((mutation) => {
59
- const { latLng } = mutation.target.dataset
60
- marker.setLatLng(JSON.parse(latLng))
61
- })
62
- })
63
- observer.observe(el, { attributes: true, attributeFilter: ["data-lat-lng"] })
58
+ const observer = new MutationObserver(function (mutations) {
59
+ mutations.forEach((mutation) => {
60
+ const { latLng } = mutation.target.dataset;
61
+ marker.setLatLng(JSON.parse(latLng));
62
+ });
63
+ });
64
+ observer.observe(el, {
65
+ attributes: true,
66
+ attributeFilter: ["data-lat-lng"],
67
+ });
64
68
 
65
69
  // marker.bindPopup
66
70
  el.querySelectorAll("[data-popup]").forEach((el) => {
67
- const { content } = el.dataset
68
- marker.bindPopup(content)
69
- const observer = new MutationObserver(function() {
70
- marker.getPopup().setContent(el.dataset.content)
71
- })
72
- observer.observe(el, { attributes: true, attributeFilter: ["data-content"] })
73
- })
71
+ const { content } = el.dataset;
72
+ marker.bindPopup(content);
73
+ const observer = new MutationObserver(function () {
74
+ marker.getPopup().setContent(el.dataset.content);
75
+ });
76
+ observer.observe(el, {
77
+ attributes: true,
78
+ attributeFilter: ["data-content"],
79
+ });
80
+ });
74
81
 
75
- layers.push(marker)
76
- })
82
+ layers.push(marker);
83
+ });
77
84
 
78
- overlayMaps[name] = L.layerGroup(layers)
79
- })
85
+ overlayMaps[name] = L.layerGroup(layers);
86
+ });
80
87
 
81
- L.control.layers(baseMaps, overlayMaps).addTo(map)
82
- })
83
- })
84
- }
88
+ L.control.layers(baseMaps, overlayMaps).addTo(map);
89
+ });
90
+ });
91
+ };
85
92
 
86
- const init = () => {
87
- document.addEventListener("DOMContentLoaded", render)
88
- }
93
+ const init = (() => {
94
+ document.addEventListener("DOMContentLoaded", render);
95
+ })();
89
96
 
90
- export default init
97
+ export default init;