leaflet-html 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/leaflet-html.cjs +1 -1
- package/dist/leaflet-html.cjs.map +1 -1
- package/dist/leaflet-html.esm.js +1 -1
- package/dist/leaflet-html.esm.js.map +1 -1
- package/dist/leaflet-html.js +2 -0
- package/dist/leaflet-html.js.map +1 -0
- package/dist/leaflet-html.umd.js +1 -1
- package/dist/leaflet-html.umd.js.map +1 -1
- package/example/index.html +33 -30
- package/package.json +4 -1
- package/src/index.js +5 -1
package/dist/leaflet-html.cjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
var t=function(){document.querySelectorAll("[data-leaflet-html]").forEach(function(t){var a=t.dataset,e=a.center,r=a.zoom,o=L.map(t).setView(JSON.parse(e),parseInt(r));t.querySelectorAll("[data-control-layers]").forEach(function(t){var a={};t.querySelectorAll("[data-tile-layer]").forEach(function(t){var e=t.dataset,r=e.show,n=e.name;a[n]=L.tileLayer(e.urlTemplate,{maxZoom:e.maxZoom,attribution:e.attribution}),null!=r&&a[n].addTo(o)});var e={};t.querySelectorAll("[data-layer-group]").forEach(function(t){var a=t.dataset.name,r=[];new MutationObserver(function(t){var r=e[a];t.forEach(function(t){t.addedNodes.forEach(function(t){var a=L.marker(JSON.parse(t.dataset.latLng));r.addLayer(a),o.addLayer(a)}),t.removedNodes.forEach(function(t){var a=r.getLayer(t.dataset._leafletId);r.removeLayer(a),o.removeLayer(a)})})}).observe(t,{childList:!0}),t.querySelectorAll("[data-marker]").forEach(function(t){var a=t.dataset.latLng,e=t.dataset.opacity,n={opacity:parseFloat(void 0===e?"1.0":e)};console.log(n);var l=L.marker(JSON.parse(a),n).addTo(o);t.dataset._leafletId=L.stamp(l),new MutationObserver(function(t){t.forEach(function(t){l.setLatLng(JSON.parse(t.target.dataset.latLng))})}).observe(t,{attributes:!0,attributeFilter:["data-lat-lng"]}),t.querySelectorAll("[data-popup]").forEach(function(t){l.bindPopup(t.dataset.content),new MutationObserver(function(){l.getPopup().setContent(t.dataset.content)}).observe(t,{attributes:!0,attributeFilter:["data-content"]})}),r.push(l)}),e[a]=L.layerGroup(r)}),L.control.layers(a,e).addTo(o)})})};module.exports=function(){document.addEventListener("DOMContentLoaded",t)};
|
2
2
|
//# sourceMappingURL=leaflet-html.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"leaflet-html.cjs","sources":["../src/index.js"],"sourcesContent":["const
|
1
|
+
{"version":3,"file":"leaflet-html.cjs","sources":["../src/index.js"],"sourcesContent":["const render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(\"[data-leaflet-html]\").forEach((el) => {\n const { center, zoom } = el.dataset\n const map = L.map(el).setView(JSON.parse(center), parseInt(zoom))\n\n // L.control.layers\n el.querySelectorAll(\"[data-control-layers]\").forEach((el) => {\n const baseMaps = {}\n \n // L.tileLayers\n el.querySelectorAll(\"[data-tile-layer]\").forEach((tileEl) => {\n const { show, urlTemplate, attribution, maxZoom, name } = tileEl.dataset\n baseMaps[name] = L.tileLayer(urlTemplate, { maxZoom, attribution });\n if (show != null) {\n baseMaps[name].addTo(map)\n }\n })\n\n const overlayMaps = {}\n // L.layerGroup\n el.querySelectorAll(\"[data-layer-group]\").forEach((el) => {\n const { name } = el.dataset\n const layers = []\n\n const observer = new MutationObserver(function(mutations) {\n const group = overlayMaps[name]\n\n mutations.forEach(mutation => {\n mutation.addedNodes.forEach(node => {\n const { latLng } = node.dataset // MutationObserver needed\n const layer = L.marker(JSON.parse(latLng))\n group.addLayer(layer)\n map.addLayer(layer)\n })\n\n mutation.removedNodes.forEach(node => {\n const { _leafletId } = node.dataset\n const layer = group.getLayer(_leafletId)\n group.removeLayer(layer)\n\n map.removeLayer(layer)\n })\n })\n })\n observer.observe(el, { childList: true })\n\n // L.marker\n el.querySelectorAll(\"[data-marker]\").forEach((el) => {\n const { latLng } = el.dataset\n const { opacity = \"1.0\" } = el.dataset\n const options = { opacity: parseFloat(opacity) }\n console.log(options)\n const marker = L.marker(JSON.parse(latLng), options).addTo(map)\n el.dataset._leafletId = L.stamp(marker) // Save ID for later\n\n const observer = new MutationObserver(function(mutations) {\n mutations.forEach((mutation) => {\n const { latLng } = mutation.target.dataset\n marker.setLatLng(JSON.parse(latLng))\n })\n })\n observer.observe(el, { attributes: true, attributeFilter: [\"data-lat-lng\"] })\n\n // marker.bindPopup\n el.querySelectorAll(\"[data-popup]\").forEach((el) => {\n const { content } = el.dataset\n marker.bindPopup(content)\n const observer = new MutationObserver(function() {\n marker.getPopup().setContent(el.dataset.content)\n })\n observer.observe(el, { attributes: true, attributeFilter: [\"data-content\"] })\n })\n\n layers.push(marker)\n })\n\n overlayMaps[name] = L.layerGroup(layers)\n })\n\n L.control.layers(baseMaps, overlayMaps).addTo(map)\n })\n })\n}\n\nconst init = () => {\n document.addEventListener(\"DOMContentLoaded\", render)\n}\n\nexport default init\n"],"names":["render","document","querySelectorAll","forEach","el","_el$dataset","dataset","center","zoom","map","L","setView","JSON","parse","parseInt","baseMaps","tileEl","_tileEl$dataset","show","name","tileLayer","urlTemplate","maxZoom","attribution","addTo","overlayMaps","layers","MutationObserver","mutations","group","mutation","addedNodes","node","layer","marker","latLng","addLayer","removedNodes","getLayer","_leafletId","removeLayer","observe","childList","_el$dataset$opacity","opacity","options","parseFloat","console","log","stamp","setLatLng","target","attributes","attributeFilter","bindPopup","content","getPopup","setContent","push","layerGroup","control","addEventListener"],"mappings":"AAAA,IAAMA,EAAS,WAEbC,SAASC,iBAAiB,uBAAuBC,QAAQ,SAACC,GACxD,IAAAC,EAAyBD,EAAGE,QAApBC,EAAMF,EAANE,OAAQC,EAAIH,EAAJG,KACVC,EAAMC,EAAED,IAAIL,GAAIO,QAAQC,KAAKC,MAAMN,GAASO,SAASN,IAG3DJ,EAAGF,iBAAiB,yBAAyBC,QAAQ,SAACC,GACpD,IAAMW,EAAW,GAGjBX,EAAGF,iBAAiB,qBAAqBC,QAAQ,SAACa,GAChD,IAAAC,EAA0DD,EAAOV,QAAzD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C,kBAG3DjD,EAAGF,iBAAiB,gBAAgBC,QAAQ,SAACC,GAE3C8B,EAAOoB,UADalD,EAAGE,QAAfiD,SAES,IAAI5B,iBAAiB,WACpCO,EAAOsB,WAAWC,WAAWrD,EAAGE,QAAQiD,QAC1C,GACSd,QAAQrC,EAAI,CAAEgD,YAAY,EAAMC,gBAAiB,CAAC,iBAC7D,GAEA3B,EAAOgC,KAAKxB,EACd,GAEAT,EAAYN,GAAQT,EAAEiD,WAAWjC,EACnC,GAEAhB,EAAEkD,QAAQlC,OAAOX,EAAUU,GAAaD,MAAMf,EAChD,EACF,EACF,iBAEa,WACXR,SAAS4D,iBAAiB,mBAAoB7D,EAChD"}
|
package/dist/leaflet-html.esm.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var
|
1
|
+
var t=function(){document.querySelectorAll("[data-leaflet-html]").forEach(function(t){var a=t.dataset,e=a.center,r=a.zoom,o=L.map(t).setView(JSON.parse(e),parseInt(r));t.querySelectorAll("[data-control-layers]").forEach(function(t){var a={};t.querySelectorAll("[data-tile-layer]").forEach(function(t){var e=t.dataset,r=e.show,n=e.name;a[n]=L.tileLayer(e.urlTemplate,{maxZoom:e.maxZoom,attribution:e.attribution}),null!=r&&a[n].addTo(o)});var e={};t.querySelectorAll("[data-layer-group]").forEach(function(t){var a=t.dataset.name,r=[];new MutationObserver(function(t){var r=e[a];t.forEach(function(t){t.addedNodes.forEach(function(t){var a=L.marker(JSON.parse(t.dataset.latLng));r.addLayer(a),o.addLayer(a)}),t.removedNodes.forEach(function(t){var a=r.getLayer(t.dataset._leafletId);r.removeLayer(a),o.removeLayer(a)})})}).observe(t,{childList:!0}),t.querySelectorAll("[data-marker]").forEach(function(t){var a=t.dataset.latLng,e=t.dataset.opacity,n={opacity:parseFloat(void 0===e?"1.0":e)};console.log(n);var l=L.marker(JSON.parse(a),n).addTo(o);t.dataset._leafletId=L.stamp(l),new MutationObserver(function(t){t.forEach(function(t){l.setLatLng(JSON.parse(t.target.dataset.latLng))})}).observe(t,{attributes:!0,attributeFilter:["data-lat-lng"]}),t.querySelectorAll("[data-popup]").forEach(function(t){l.bindPopup(t.dataset.content),new MutationObserver(function(){l.getPopup().setContent(t.dataset.content)}).observe(t,{attributes:!0,attributeFilter:["data-content"]})}),r.push(l)}),e[a]=L.layerGroup(r)}),L.control.layers(a,e).addTo(o)})})},a=function(){document.addEventListener("DOMContentLoaded",t)};export{a as default};
|
2
2
|
//# sourceMappingURL=leaflet-html.esm.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"leaflet-html.esm.js","sources":["../src/index.js"],"sourcesContent":["const
|
1
|
+
{"version":3,"file":"leaflet-html.esm.js","sources":["../src/index.js"],"sourcesContent":["const render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(\"[data-leaflet-html]\").forEach((el) => {\n const { center, zoom } = el.dataset\n const map = L.map(el).setView(JSON.parse(center), parseInt(zoom))\n\n // L.control.layers\n el.querySelectorAll(\"[data-control-layers]\").forEach((el) => {\n const baseMaps = {}\n \n // L.tileLayers\n el.querySelectorAll(\"[data-tile-layer]\").forEach((tileEl) => {\n const { show, urlTemplate, attribution, maxZoom, name } = tileEl.dataset\n baseMaps[name] = L.tileLayer(urlTemplate, { maxZoom, attribution });\n if (show != null) {\n baseMaps[name].addTo(map)\n }\n })\n\n const overlayMaps = {}\n // L.layerGroup\n el.querySelectorAll(\"[data-layer-group]\").forEach((el) => {\n const { name } = el.dataset\n const layers = []\n\n const observer = new MutationObserver(function(mutations) {\n const group = overlayMaps[name]\n\n mutations.forEach(mutation => {\n mutation.addedNodes.forEach(node => {\n const { latLng } = node.dataset // MutationObserver needed\n const layer = L.marker(JSON.parse(latLng))\n group.addLayer(layer)\n map.addLayer(layer)\n })\n\n mutation.removedNodes.forEach(node => {\n const { _leafletId } = node.dataset\n const layer = group.getLayer(_leafletId)\n group.removeLayer(layer)\n\n map.removeLayer(layer)\n })\n })\n })\n observer.observe(el, { childList: true })\n\n // L.marker\n el.querySelectorAll(\"[data-marker]\").forEach((el) => {\n const { latLng } = el.dataset\n const { opacity = \"1.0\" } = el.dataset\n const options = { opacity: parseFloat(opacity) }\n console.log(options)\n const marker = L.marker(JSON.parse(latLng), options).addTo(map)\n el.dataset._leafletId = L.stamp(marker) // Save ID for later\n\n const observer = new MutationObserver(function(mutations) {\n mutations.forEach((mutation) => {\n const { latLng } = mutation.target.dataset\n marker.setLatLng(JSON.parse(latLng))\n })\n })\n observer.observe(el, { attributes: true, attributeFilter: [\"data-lat-lng\"] })\n\n // marker.bindPopup\n el.querySelectorAll(\"[data-popup]\").forEach((el) => {\n const { content } = el.dataset\n marker.bindPopup(content)\n const observer = new MutationObserver(function() {\n marker.getPopup().setContent(el.dataset.content)\n })\n observer.observe(el, { attributes: true, attributeFilter: [\"data-content\"] })\n })\n\n layers.push(marker)\n })\n\n overlayMaps[name] = L.layerGroup(layers)\n })\n\n L.control.layers(baseMaps, overlayMaps).addTo(map)\n })\n })\n}\n\nconst init = () => {\n document.addEventListener(\"DOMContentLoaded\", render)\n}\n\nexport default init\n"],"names":["render","document","querySelectorAll","forEach","el","_el$dataset","dataset","center","zoom","map","L","setView","JSON","parse","parseInt","baseMaps","tileEl","_tileEl$dataset","show","name","tileLayer","urlTemplate","maxZoom","attribution","addTo","overlayMaps","layers","MutationObserver","mutations","group","mutation","addedNodes","node","layer","marker","latLng","addLayer","removedNodes","getLayer","_leafletId","removeLayer","observe","childList","_el$dataset$opacity","opacity","options","parseFloat","console","log","stamp","setLatLng","target","attributes","attributeFilter","bindPopup","content","getPopup","setContent","push","layerGroup","control","init","addEventListener"],"mappings":"AAAA,IAAMA,EAAS,WAEbC,SAASC,iBAAiB,uBAAuBC,QAAQ,SAACC,GACxD,IAAAC,EAAyBD,EAAGE,QAApBC,EAAMF,EAANE,OAAQC,EAAIH,EAAJG,KACVC,EAAMC,EAAED,IAAIL,GAAIO,QAAQC,KAAKC,MAAMN,GAASO,SAASN,IAG3DJ,EAAGF,iBAAiB,yBAA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OgB,UAAUtC,KAAKC,MADHiB,EAASqB,OAAO7C,QAA3B6B,QAEV,EACJ,GACSM,QAAQrC,EAAI,CAAEgD,YAAY,EAAMC,gBAAiB,CAAC,kBAG3DjD,EAAGF,iBAAiB,gBAAgBC,QAAQ,SAACC,GAE3C8B,EAAOoB,UADalD,EAAGE,QAAfiD,SAES,IAAI5B,iBAAiB,WACpCO,EAAOsB,WAAWC,WAAWrD,EAAGE,QAAQiD,QAC1C,GACSd,QAAQrC,EAAI,CAAEgD,YAAY,EAAMC,gBAAiB,CAAC,iBAC7D,GAEA3B,EAAOgC,KAAKxB,EACd,GAEAT,EAAYN,GAAQT,EAAEiD,WAAWjC,EACnC,GAEAhB,EAAEkD,QAAQlC,OAAOX,EAAUU,GAAaD,MAAMf,EAChD,EACF,EACF,EAEMoD,EAAO,WACX5D,SAAS6D,iBAAiB,mBAAoB9D,EAChD"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
const t=()=>{document.querySelectorAll("[data-leaflet-html]").forEach(t=>{const{center:e,zoom:a}=t.dataset,o=L.map(t).setView(JSON.parse(e),parseInt(a));t.querySelectorAll("[data-control-layers]").forEach(t=>{const e={};t.querySelectorAll("[data-tile-layer]").forEach(t=>{const{show:a,urlTemplate:r,attribution:n,maxZoom:s,name:l}=t.dataset;e[l]=L.tileLayer(r,{maxZoom:s,attribution:n}),null!=a&&e[l].addTo(o)});const a={};t.querySelectorAll("[data-layer-group]").forEach(t=>{const{name:e}=t.dataset,r=[];new MutationObserver(function(t){const r=a[e];t.forEach(t=>{t.addedNodes.forEach(t=>{const{latLng:e}=t.dataset,a=L.marker(JSON.parse(e));r.addLayer(a),o.addLayer(a)}),t.removedNodes.forEach(t=>{const{_leafletId:e}=t.dataset,a=r.getLayer(e);r.removeLayer(a),o.removeLayer(a)})})}).observe(t,{childList:!0}),t.querySelectorAll("[data-marker]").forEach(t=>{const{latLng:e}=t.dataset,{opacity:a="1.0"}=t.dataset,n={opacity:parseFloat(a)};console.log(n);const s=L.marker(JSON.parse(e),n).addTo(o);t.dataset._leafletId=L.stamp(s);const l=new MutationObserver(function(t){t.forEach(t=>{const{latLng:e}=t.target.dataset;s.setLatLng(JSON.parse(e))})});l.observe(t,{attributes:!0,attributeFilter:["data-lat-lng"]}),t.querySelectorAll("[data-popup]").forEach(t=>{const{content:e}=t.dataset;s.bindPopup(e),new MutationObserver(function(){s.getPopup().setContent(t.dataset.content)}).observe(t,{attributes:!0,attributeFilter:["data-content"]})}),r.push(s)}),a[e]=L.layerGroup(r)}),L.control.layers(e,a).addTo(o)})})},e=()=>{document.addEventListener("DOMContentLoaded",t)};export{e as default};
|
2
|
+
//# sourceMappingURL=leaflet-html.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"leaflet-html.js","sources":["../src/index.js"],"sourcesContent":["const render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(\"[data-leaflet-html]\").forEach((el) => {\n const { center, zoom } = el.dataset\n const map = L.map(el).setView(JSON.parse(center), parseInt(zoom))\n\n // L.control.layers\n el.querySelectorAll(\"[data-control-layers]\").forEach((el) => {\n const baseMaps = {}\n \n // L.tileLayers\n el.querySelectorAll(\"[data-tile-layer]\").forEach((tileEl) => {\n const { show, urlTemplate, attribution, maxZoom, name } = tileEl.dataset\n baseMaps[name] = L.tileLayer(urlTemplate, { maxZoom, attribution });\n if (show != null) {\n baseMaps[name].addTo(map)\n }\n })\n\n const overlayMaps = {}\n // L.layerGroup\n el.querySelectorAll(\"[data-layer-group]\").forEach((el) => {\n const { name } = el.dataset\n const layers = []\n\n const observer = new MutationObserver(function(mutations) {\n const group = overlayMaps[name]\n\n mutations.forEach(mutation => {\n mutation.addedNodes.forEach(node => {\n const { latLng } = node.dataset // MutationObserver needed\n const layer = L.marker(JSON.parse(latLng))\n group.addLayer(layer)\n map.addLayer(layer)\n })\n\n mutation.removedNodes.forEach(node => {\n const { _leafletId } = node.dataset\n const layer = group.getLayer(_leafletId)\n group.removeLayer(layer)\n\n map.removeLayer(layer)\n })\n })\n })\n observer.observe(el, { childList: true })\n\n // L.marker\n el.querySelectorAll(\"[data-marker]\").forEach((el) => {\n const { latLng } = el.dataset\n const { opacity = \"1.0\" } = el.dataset\n const options = { opacity: parseFloat(opacity) }\n console.log(options)\n const marker = L.marker(JSON.parse(latLng), options).addTo(map)\n el.dataset._leafletId = L.stamp(marker) // Save ID for later\n\n const observer = new MutationObserver(function(mutations) {\n mutations.forEach((mutation) => {\n const { latLng } = mutation.target.dataset\n marker.setLatLng(JSON.parse(latLng))\n })\n })\n observer.observe(el, { attributes: true, attributeFilter: [\"data-lat-lng\"] })\n\n // marker.bindPopup\n el.querySelectorAll(\"[data-popup]\").forEach((el) => {\n const { content } = el.dataset\n marker.bindPopup(content)\n const observer = new MutationObserver(function() {\n marker.getPopup().setContent(el.dataset.content)\n })\n observer.observe(el, { attributes: true, attributeFilter: [\"data-content\"] })\n })\n\n layers.push(marker)\n })\n\n overlayMaps[name] = L.layerGroup(layers)\n })\n\n L.control.layers(baseMaps, overlayMaps).addTo(map)\n })\n })\n}\n\nconst init = () => {\n document.addEventListener(\"DOMContentLoaded\", render)\n}\n\nexport default init\n"],"names":["render","document","querySelectorAll","forEach","el","center","zoom","dataset","map","L","setView","JSON","parse","parseInt","baseMaps","tileEl","show","urlTemplate","attribution","maxZoom","name","tileLayer","addTo","overlayMaps","layers","MutationObserver","mutations","group","mutation","addedNodes","node","latLng","layer","marker","addLayer","removedNodes","_leafletId","getLayer","removeLayer","observe","childList","opacity","options","parseFloat","console","log","stamp","observer","target","setLatLng","attributes","attributeFilter","content","bindPopup","getPopup","setContent","push","layerGroup","control","init","addEventListener"],"mappings":"AAAA,MAAMA,EAASA,KAEbC,SAASC,iBAAiB,uBAAuBC,QAASC,IACxD,MAAMC,OAAEA,EAAMC,KAAEA,GAASF,EAAGG,QACtBC,EAAMC,EAAED,IAAIJ,GAAIM,QAAQC,KAAKC,MAAMP,GAASQ,SAASP,IAG3DF,EAAGF,iBAAiB,yBAAy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,EAAOgB,UAAUtC,KAAKC,MAAMmB,GAC9B,EACJ,GACAgB,EAASR,QAAQnC,EAAI,CAAE8C,YAAY,EAAMC,gBAAiB,CAAC,kBAG3D/C,EAAGF,iBAAiB,gBAAgBC,QAASC,IAC3C,MAAMgD,QAAEA,GAAYhD,EAAGG,QACvB0B,EAAOoB,UAAUD,GACA,IAAI3B,iBAAiB,WACpCQ,EAAOqB,WAAWC,WAAWnD,EAAGG,QAAQ6C,QAC1C,GACSb,QAAQnC,EAAI,CAAE8C,YAAY,EAAMC,gBAAiB,CAAC,iBAC7D,GAEA3B,EAAOgC,KAAKvB,EACd,GAEAV,EAAYH,GAAQX,EAAEgD,WAAWjC,EACnC,GAEAf,EAAEiD,QAAQlC,OAAOV,EAAUS,GAAaD,MAAMd,EAChD,EACF,EACF,EAEMmD,EAAOA,KACX1D,SAAS2D,iBAAiB,mBAAoB5D,EAChD"}
|
package/dist/leaflet-html.umd.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).leafletHtml=t()}(this,function(){
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).leafletHtml=t()}(this,function(){var e=function(){document.querySelectorAll("[data-leaflet-html]").forEach(function(e){var t=e.dataset,a=t.center,o=t.zoom,r=L.map(e).setView(JSON.parse(a),parseInt(o));e.querySelectorAll("[data-control-layers]").forEach(function(e){var t={};e.querySelectorAll("[data-tile-layer]").forEach(function(e){var a=e.dataset,o=a.show,n=a.name;t[n]=L.tileLayer(a.urlTemplate,{maxZoom:a.maxZoom,attribution:a.attribution}),null!=o&&t[n].addTo(r)});var a={};e.querySelectorAll("[data-layer-group]").forEach(function(e){var t=e.dataset.name,o=[];new MutationObserver(function(e){var o=a[t];e.forEach(function(e){e.addedNodes.forEach(function(e){var t=L.marker(JSON.parse(e.dataset.latLng));o.addLayer(t),r.addLayer(t)}),e.removedNodes.forEach(function(e){var t=o.getLayer(e.dataset._leafletId);o.removeLayer(t),r.removeLayer(t)})})}).observe(e,{childList:!0}),e.querySelectorAll("[data-marker]").forEach(function(e){var t=e.dataset.latLng,a=e.dataset.opacity,n={opacity:parseFloat(void 0===a?"1.0":a)};console.log(n);var l=L.marker(JSON.parse(t),n).addTo(r);e.dataset._leafletId=L.stamp(l),new MutationObserver(function(e){e.forEach(function(e){l.setLatLng(JSON.parse(e.target.dataset.latLng))})}).observe(e,{attributes:!0,attributeFilter:["data-lat-lng"]}),e.querySelectorAll("[data-popup]").forEach(function(e){l.bindPopup(e.dataset.content),new MutationObserver(function(){l.getPopup().setContent(e.dataset.content)}).observe(e,{attributes:!0,attributeFilter:["data-content"]})}),o.push(l)}),a[t]=L.layerGroup(o)}),L.control.layers(t,a).addTo(r)})})};return function(){document.addEventListener("DOMContentLoaded",e)}});
|
2
2
|
//# sourceMappingURL=leaflet-html.umd.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"leaflet-html.umd.js","sources":["../src/index.js"],"sourcesContent":["const
|
1
|
+
{"version":3,"file":"leaflet-html.umd.js","sources":["../src/index.js"],"sourcesContent":["const render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(\"[data-leaflet-html]\").forEach((el) => {\n const { center, zoom } = el.dataset\n const map = L.map(el).setView(JSON.parse(center), parseInt(zoom))\n\n // L.control.layers\n el.querySelectorAll(\"[data-control-layers]\").forEach((el) => {\n const baseMaps = {}\n \n // L.tileLayers\n el.querySelectorAll(\"[data-tile-layer]\").forEach((tileEl) => {\n const { show, urlTemplate, attribution, maxZoom, name } = tileEl.dataset\n baseMaps[name] = L.tileLayer(urlTemplate, { maxZoom, attribution });\n if (show != null) {\n baseMaps[name].addTo(map)\n }\n })\n\n const overlayMaps = {}\n // L.layerGroup\n el.querySelectorAll(\"[data-layer-group]\").forEach((el) => {\n const { name } = el.dataset\n const layers = []\n\n const observer = new MutationObserver(function(mutations) {\n const group = overlayMaps[name]\n\n mutations.forEach(mutation => {\n mutation.addedNodes.forEach(node => {\n const { latLng } = node.dataset // MutationObserver needed\n const layer = L.marker(JSON.parse(latLng))\n group.addLayer(layer)\n map.addLayer(layer)\n })\n\n mutation.removedNodes.forEach(node => {\n const { _leafletId } = node.dataset\n const layer = group.getLayer(_leafletId)\n group.removeLayer(layer)\n\n map.removeLayer(layer)\n })\n })\n })\n observer.observe(el, { childList: true })\n\n // L.marker\n el.querySelectorAll(\"[data-marker]\").forEach((el) => {\n const { latLng } = el.dataset\n const { opacity = \"1.0\" } = el.dataset\n const options = { opacity: parseFloat(opacity) }\n console.log(options)\n const marker = L.marker(JSON.parse(latLng), options).addTo(map)\n el.dataset._leafletId = L.stamp(marker) // Save ID for later\n\n const observer = new MutationObserver(function(mutations) {\n mutations.forEach((mutation) => {\n const { latLng } = mutation.target.dataset\n marker.setLatLng(JSON.parse(latLng))\n })\n })\n observer.observe(el, { attributes: true, attributeFilter: [\"data-lat-lng\"] })\n\n // marker.bindPopup\n el.querySelectorAll(\"[data-popup]\").forEach((el) => {\n const { content } = el.dataset\n marker.bindPopup(content)\n const observer = new MutationObserver(function() {\n marker.getPopup().setContent(el.dataset.content)\n })\n observer.observe(el, { attributes: true, attributeFilter: [\"data-content\"] })\n })\n\n layers.push(marker)\n })\n\n overlayMaps[name] = L.layerGroup(layers)\n })\n\n L.control.layers(baseMaps, overlayMaps).addTo(map)\n })\n })\n}\n\nconst init = () => {\n document.addEventListener(\"DOMContentLoaded\", render)\n}\n\nexport default init\n"],"names":["render","document","querySelectorAll","forEach","el","_el$dataset","dataset","center","zoom","map","L","setView","JSON","parse","parseInt","baseMaps","tileEl","_tileEl$dataset","show","name","tileLayer","urlTemplate","maxZoom","attribution","addTo","overlayMaps","layers","MutationObserver","mutations","group","mutation","addedNodes","node","layer","marker","latLng","addLayer","removedNodes","getLayer","_leafletId","removeLayer","observe","childList","_el$dataset$opacity","opacity","options","parseFloat","console","log","stamp","setLatLng","target","attributes","attributeFilter","bindPopup","content","getPopup","setContent","push","layerGroup","control","addEventListener"],"mappings":"8NAAA,IAAMA,EAAS,WAEbC,SAASC,iBAAiB,uBAAuBC,QAAQ,SAACC,GACxD,IAAAC,EAAyBD,EAAGE,QAApBC,EAAMF,EAANE,OAAQC,EAAIH,EAAJG,KACVC,EAAMC,EAAED,IAAIL,GAAIO,QAAQC,KAAKC,MAAMN,GAASO,SAASN,IAG3DJ,EAAGF,iBAAiB,yBAAyBC,QAAQ,SAACC,GACpD,IAAMW,EAAW,GAGjBX,EAAGF,iBAAiB,qBAAqBC,QAAQ,SAACa,GAChD,IAAAC,EAA0DD,EAAOV,QAAzDY,EAAID,EAAJC,KAAyCC,EAAIF,EAAJE,KACjDJ,EAASI,GAAQT,EAAEU,UADMH,EAAXI,YAC4B,CAAEC,QADGL,EAAPK,QACaC,YADfN,EAAXM,cAEf,MAARL,GACFH,EAASI,GAAMK,MAAMf,EAEzB,GAEA,IAAMgB,EAAc,CAAE,EAEtBrB,EAAGF,iBAAiB,sBAAsBC,QAAQ,SAACC,GACjD,IAAQe,EAASf,EAAGE,QAAZa,KACFO,EAAS,GAEE,IAAIC,iBAAiB,SAASC,GAC7C,IAAMC,EAAQJ,EAAYN,GAE1BS,EAAUzB,QAAQ,SAAA2B,GAChBA,EAASC,WAAW5B,QAAQ,SAAA6B,GAC1B,IACMC,EAAQvB,EAAEwB,OAAOtB,KAAKC,MADTmB,EAAK1B,QAAhB6B,SAERN,EAAMO,SAASH,GACfxB,EAAI2B,SAASH,EACf,GAEAH,EAASO,aAAalC,QAAQ,SAAA6B,GAC5B,IACMC,EAAQJ,EAAMS,SADGN,EAAK1B,QAApBiC,YAERV,EAAMW,YAAYP,GAElBxB,EAAI+B,YAAYP,EAClB,EACF,EACF,GACSQ,QAAQrC,EAAI,CAAEsC,WAAW,IAGlCtC,EAAGF,iBAAiB,iBAAiBC,QAAQ,SAACC,GAC5C,IAAQ+B,EAAW/B,EAAGE,QAAd6B,OACRQ,EAA4BvC,EAAGE,QAAvBsC,QACFC,EAAU,CAAED,QAASE,gBADZ,IAAAH,EAAG,MAAKA,IAEvBI,QAAQC,IAAIH,GACZ,IAAMX,EAASxB,EAAEwB,OAAOtB,KAAKC,MAAMsB,GAASU,GAASrB,MAAMf,GAC3DL,EAAGE,QAAQiC,WAAa7B,EAAEuC,MAAMf,GAEf,IAAIP,iBAAiB,SAASC,GAC3CA,EAAUzB,QAAQ,SAAC2B,GAEjBI,EAAOgB,UAAUtC,KAAKC,MADHiB,EAASqB,OAAO7C,QAA3B6B,QAEV,EACJ,GACSM,QAAQrC,EAAI,CAAEgD,YAAY,EAAMC,gBAAiB,CAAC,kBAG3DjD,EAAGF,iBAAiB,gBAAgBC,QAAQ,SAACC,GAE3C8B,EAAOoB,UADalD,EAAGE,QAAfiD,SAES,IAAI5B,iBAAiB,WACpCO,EAAOsB,WAAWC,WAAWrD,EAAGE,QAAQiD,QAC1C,GACSd,QAAQrC,EAAI,CAAEgD,YAAY,EAAMC,gBAAiB,CAAC,iBAC7D,GAEA3B,EAAOgC,KAAKxB,EACd,GAEAT,EAAYN,GAAQT,EAAEiD,WAAWjC,EACnC,GAEAhB,EAAEkD,QAAQlC,OAAOX,EAAUU,GAAaD,MAAMf,EAChD,EACF,EACF,SAEa,WACXR,SAAS4D,iBAAiB,mBAAoB7D,EAChD"}
|
package/example/index.html
CHANGED
@@ -3,12 +3,18 @@
|
|
3
3
|
<head>
|
4
4
|
<title>Leaflet HTML</title>
|
5
5
|
<meta charset="utf-8" />
|
6
|
-
<link
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
<link
|
7
|
+
rel="stylesheet"
|
8
|
+
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
9
|
+
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
10
|
+
crossorigin=""
|
11
|
+
/>
|
12
|
+
<script
|
13
|
+
src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
14
|
+
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
15
|
+
crossorigin=""
|
16
|
+
></script>
|
17
|
+
<script src="https://www.unpkg.com/leaflet-html@0.1.3/dist/leaflet-html.umd.js"></script>
|
12
18
|
<style>
|
13
19
|
* {
|
14
20
|
margin: 0;
|
@@ -39,18 +45,20 @@
|
|
39
45
|
<div data-leaflet-html data-center="[39.61, -105.02]" data-zoom="10">
|
40
46
|
<div data-control-layers>
|
41
47
|
<div data-base-maps>
|
42
|
-
<div
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
<div
|
49
|
+
data-tile-layer
|
50
|
+
data-name="OpenStreetMap"
|
51
|
+
data-url-template="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
|
52
|
+
data-attribution='© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
53
|
+
data-max-zoom="12"
|
47
54
|
></div>
|
48
|
-
<div
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
55
|
+
<div
|
56
|
+
data-tile-layer
|
57
|
+
data-name="Toner"
|
58
|
+
data-url-template="https://tiles.stadiamaps.com/tiles/stamen_toner/{z}/{x}/{y}{r}.png"
|
59
|
+
data-attribution=""
|
60
|
+
data-max-zoom="12"
|
61
|
+
data-show
|
54
62
|
></div>
|
55
63
|
</div>
|
56
64
|
<div data-overlay-maps>
|
@@ -70,27 +78,22 @@
|
|
70
78
|
</div>
|
71
79
|
</div>
|
72
80
|
</div>
|
73
|
-
|
74
81
|
</div>
|
75
82
|
<button id="btn">Add a city</button>
|
76
83
|
<script type="module">
|
77
|
-
import leafletHTML from "/dist/leaflet-html.esm.js"
|
78
|
-
|
79
|
-
leafletHTML()
|
80
|
-
|
81
84
|
// Manual tests
|
82
85
|
document.getElementById("btn").addEventListener("click", () => {
|
83
86
|
// New city
|
84
|
-
let el = document.querySelector('[data-name="Cities"]')
|
85
|
-
const city = document.createElement("div")
|
86
|
-
city.dataset.marker =
|
87
|
-
city.dataset.latLng = "[39.60, -105.02]"
|
88
|
-
el.appendChild(city)
|
87
|
+
let el = document.querySelector('[data-name="Cities"]');
|
88
|
+
const city = document.createElement("div");
|
89
|
+
city.dataset.marker = "";
|
90
|
+
city.dataset.latLng = "[39.60, -105.02]";
|
91
|
+
el.appendChild(city);
|
89
92
|
|
90
93
|
// Remove Denver
|
91
|
-
el = document.querySelector('[data-lat-lng="[39.74, -104.99]"]')
|
92
|
-
el.remove()
|
93
|
-
})
|
94
|
+
el = document.querySelector('[data-lat-lng="[39.74, -104.99]"]');
|
95
|
+
el.remove();
|
96
|
+
});
|
94
97
|
</script>
|
95
98
|
</body>
|
96
99
|
</html>
|
package/package.json
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "leaflet-html",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.1.
|
4
|
+
"version": "0.1.3",
|
5
5
|
"description": "Leaflet expressed in HTML",
|
6
6
|
"source": "src/index.js",
|
7
7
|
"main": "./dist/leaflet-html.js",
|
8
|
+
"exports": {
|
9
|
+
"default": "./dist/leaflet-html.js"
|
10
|
+
},
|
8
11
|
"module": "./dist/leaflet-html.esm.js",
|
9
12
|
"author": "andrewgryan",
|
10
13
|
"repository": {
|
package/src/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const
|
1
|
+
const render = () => {
|
2
2
|
// Render Leaflet API calls
|
3
3
|
document.querySelectorAll("[data-leaflet-html]").forEach((el) => {
|
4
4
|
const { center, zoom } = el.dataset
|
@@ -83,4 +83,8 @@ const init = () => {
|
|
83
83
|
})
|
84
84
|
}
|
85
85
|
|
86
|
+
const init = () => {
|
87
|
+
document.addEventListener("DOMContentLoaded", render)
|
88
|
+
}
|
89
|
+
|
86
90
|
export default init
|