leaflet-html 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/master.yml +15 -0
- package/.github/workflows/npm-publish.yml +37 -0
- package/README.md +6 -0
- 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 +1 -1
- package/dist/leaflet-html.js.map +1 -1
- package/dist/leaflet-html.umd.js +1 -1
- package/dist/leaflet-html.umd.js.map +1 -1
- package/docs/config.toml +16 -0
- package/docs/content/_index.md +86 -0
- package/docs/templates/index.html +53 -0
- package/example/index.html +6 -5
- package/example/overlays/index.html +77 -0
- package/package.json +1 -1
- package/src/index.js +104 -10
- package/dist/leaflet-html.modern.js +0 -2
- package/dist/leaflet-html.modern.js.map +0 -1
@@ -0,0 +1,15 @@
|
|
1
|
+
on: push
|
2
|
+
name: Build and deploy GH Pages
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
if: github.ref == 'refs/heads/master'
|
7
|
+
steps:
|
8
|
+
- name: checkout
|
9
|
+
uses: actions/checkout@v4
|
10
|
+
- name: build_and_deploy
|
11
|
+
uses: shalzz/zola-deploy-action@v0.17.2
|
12
|
+
env:
|
13
|
+
BUILD_DIR: docs
|
14
|
+
PAGES_BRANCH: gh-pages
|
15
|
+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: npm-publish
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
jobs:
|
7
|
+
npm-publish:
|
8
|
+
name: npm-publish
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- name: Checkout repository
|
12
|
+
uses: actions/checkout@v4
|
13
|
+
- name: Set Node.js
|
14
|
+
uses: actions/setup-node@v4
|
15
|
+
with:
|
16
|
+
node-version: 21
|
17
|
+
- name: Install
|
18
|
+
uses: borales/actions-yarn@v4
|
19
|
+
with:
|
20
|
+
cmd: install
|
21
|
+
- name: Build
|
22
|
+
uses: borales/actions-yarn@v4
|
23
|
+
with:
|
24
|
+
cmd: build
|
25
|
+
- name: Publish if version has been updated
|
26
|
+
uses: pascalgn/npm-publish-action@1.3.9
|
27
|
+
with:
|
28
|
+
tag_name: "v%s"
|
29
|
+
tag_message: "v%s"
|
30
|
+
create_tag: "true"
|
31
|
+
commit_pattern: "^Release (\\S+)"
|
32
|
+
workspace: "."
|
33
|
+
publish_command: "yarn"
|
34
|
+
publish_args: "--non-interactive"
|
35
|
+
env:
|
36
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
37
|
+
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
|
package/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Leaflet expressed in HTML to add maps to Hypermedia Driven Applications (HDA).
|
4
4
|
|
5
|
+
Indeed, since it is HTML, any front end framework should work with it.
|
6
|
+
|
7
|
+
Fine grained reactive frameworks such as [Solid JS](https://solidjs.com) or [Van JS](https://vanjs.org) are ideal candidates for client side development.
|
8
|
+
|
9
|
+
RESTful frameworks, like [HTMX](Https://htmx.org), that serve HTML over the wire are perfect choices for server rendered content.
|
10
|
+
|
5
11
|
## Example
|
6
12
|
|
7
13
|
The HTML in `example/index.html` is a simple demonstration of the API.
|
package/dist/leaflet-html.cjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var t=void document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("
|
1
|
+
var a=function(a){return"[data-"+a+"]"},t=function(a){var t=a.dataset,e=t.attribution,r=t.maxZoom,o=t.minZoom,n=t.subdomains;return[a.dataset.urlTemplate,{attribution:void 0===e?null:e,maxZoom:void 0===r?"18":r,minZoom:void 0===o?"0":o,subdomains:void 0===n?"abc":n}]},e=function(a){var t=a.dataset.bounds;if(void 0===t)throw Error("data-bounds not specified");return[JSON.parse(t)]},r=void document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(a("leaflet-html")).forEach(function(r){var o=r.dataset,n=o.center,l=o.zoom,d=L.map(r).setView(JSON.parse(n),parseInt(l));r.querySelectorAll(a("lat-lng-bounds")).forEach(function(a){var t,r=(t=L).latLngBounds.apply(t,e(a));new MutationObserver(function(a){a.forEach(function(a){var t=e(a.target);d.flyToBounds(t[0])})}).observe(a,{attributes:!0,attributeFilter:["data-bounds"]}),d.fitBounds(r)}),r.querySelectorAll(a("tile-layer")).forEach(function(a){var e;(e=L).tileLayer.apply(e,t(a)).addTo(d)}),r.querySelectorAll(a("image-overlay")).forEach(function(a){var t;(t=L).imageOverlay.apply(t,function(a){var t=a.dataset,e=t.bounds;return[t.url,e=JSON.parse(e),{opacity:parseFloat(a.dataset.opacity)}]}(a)).addTo(d)}),r.querySelectorAll(a("video-overlay")).forEach(function(a){var t;(t=L).videoOverlay.apply(t,function(a){var t=a.dataset,e=t.url,r=t.bounds;e=JSON.parse(e),r=JSON.parse(r);var o=a.dataset,n=o.errorOverlayUrl,l=o.autoplay,d=void 0===l||l,i=o.muted,u=void 0===i||i,s=o.playsInline,c=void 0===s||s;return[e,r,{opacity:parseFloat(o.opacity),errorOverlayUrl:n,autoplay:d,muted:u,playsInline:c}]}(a)).addTo(d)}),r.querySelectorAll(a("control-layers")).forEach(function(e){var r={};e.querySelectorAll(a("tile-layer")).forEach(function(a){var e,o=a.dataset,n=o.name,l=o.show;r[n]=(e=L).tileLayer.apply(e,t(a)),null!=l&&r[n].addTo(d)});var o={};e.querySelectorAll(a("layer-group")).forEach(function(t){var e=t.dataset.name,r=[];new MutationObserver(function(a){var t=o[e];a.forEach(function(a){a.addedNodes.forEach(function(a){var e=L.marker(JSON.parse(a.dataset.latLng));t.addLayer(e),d.addLayer(e)}),a.removedNodes.forEach(function(a){var e=t.getLayer(a.dataset._leafletId);t.removeLayer(e),d.removeLayer(e)})})}).observe(t,{childList:!0}),t.querySelectorAll(a("marker")).forEach(function(t){var e=t.dataset.latLng,o=t.dataset.opacity,n={opacity:parseFloat(void 0===o?"1.0":o)},l=L.marker(JSON.parse(e),n).addTo(d);t.dataset._leafletId=L.stamp(l),new MutationObserver(function(a){a.forEach(function(a){l.setLatLng(JSON.parse(a.target.dataset.latLng))})}).observe(t,{attributes:!0,attributeFilter:["data-lat-lng"]}),t.querySelectorAll(a("popup")).forEach(function(a){l.bindPopup(a.dataset.content),new MutationObserver(function(){l.getPopup().setContent(a.dataset.content)}).observe(a,{attributes:!0,attributeFilter:["data-content"]})}),r.push(l)}),o[e]=L.layerGroup(r)}),L.control.layers(r,o).addTo(d)})})});module.exports=r;
|
2
2
|
//# sourceMappingURL=leaflet-html.cjs.map
|
@@ -1 +1 @@
|
|
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 } =\n 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, {\n attributes: true,\n attributeFilter: [\"data-lat-lng\"],\n });\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, {\n attributes: true,\n attributeFilter: [\"data-content\"],\n });\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":["init","document","addEventListener","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"],"mappings":"AAAA,IA4FMA,OACJC,SAASC,iBAAiB,mBA7Fb,WAEbD,SAASE,iBAAiB,uBAAuBC,QAAQ,SAACC,GACxD,IAA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B,KAAKC,MAAMsB,GAASU,GAASrB,MAAMf,GAC3DL,EAAGE,QAAQiC,WAAa7B,EAAEuC,MAAMf,GAEf,IAAIP,iBAAiB,SAAUC,GAC9CA,EAAUzB,QAAQ,SAAC2B,GAEjBI,EAAOgB,UAAUtC,KAAKC,MADHiB,EAASqB,OAAO7C,QAA3B6B,QAEV,EACF,GACSM,QAAQrC,EAAI,CACnBgD,YAAY,EACZC,gBAAiB,CAAC,kBAIpBjD,EAAGF,iBAAiB,gBAAgBC,QAAQ,SAACC,GAE3C8B,EAAOoB,UADalD,EAAGE,QAAfiD,SAES,IAAI5B,iBAAiB,WACpCO,EAAOsB,WAAWC,WAAWrD,EAAGE,QAAQiD,QAC1C,GACSd,QAAQrC,EAAI,CACnBgD,YAAY,EACZC,gBAAiB,CAAC,iBAEtB,GAEA3B,EAAOgC,KAAKxB,EACd,GAEAT,EAAYN,GAAQT,EAAEiD,WAAWjC,EACnC,GAEAhB,EAAEkD,QAAQlC,OAAOX,EAAUU,GAAaD,MAAMf,EAChD,EACF,EACF"}
|
1
|
+
{"version":3,"file":"leaflet-html.cjs","sources":["../src/index.js"],"sourcesContent":["// @ts-check\n\n// Helpers\nconst selector = (noun) => `[data-${noun}]`;\n\n/**\n * Parse L.tileLayer args from element attributes\n */\nconst parseTileLayer = (el) => {\n const { urlTemplate } = el.dataset;\n const {\n attribution = null,\n maxZoom = \"18\",\n minZoom = \"0\",\n subdomains = \"abc\",\n } = el.dataset;\n const options = { attribution, maxZoom, minZoom, subdomains };\n return [urlTemplate, options];\n};\n\n/**\n * Parse L.imageOverlay args from element attributes\n */\nconst parseImageOverlay = (el) => {\n let { url, bounds } = el.dataset;\n bounds = JSON.parse(bounds);\n const { opacity } = el.dataset;\n const options = { opacity: parseFloat(opacity) };\n return [url, bounds, options];\n};\n\n/**\n * Parse L.imageOverlay args from element attributes\n */\nconst parseVideoOverlay = (el) => {\n let { url, bounds } = el.dataset;\n url = JSON.parse(url);\n bounds = JSON.parse(bounds);\n const {\n opacity,\n errorOverlayUrl,\n autoplay = true,\n muted = true,\n playsInline = true,\n } = el.dataset;\n const options = {\n opacity: parseFloat(opacity),\n errorOverlayUrl,\n autoplay,\n muted,\n playsInline,\n };\n return [url, bounds, options];\n};\n\n/**\n * @param {HTMLElement} el\n */\nconst parseLatLngBounds = (el) => {\n let { bounds } = el.dataset;\n if (typeof bounds === \"undefined\") {\n throw Error(\"data-bounds not specified\")\n }\n return [JSON.parse(bounds)];\n}\n\nconst render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(selector(\"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.latLngBounds\n el.querySelectorAll(selector(\"lat-lng-bounds\")).forEach((el) => {\n const bounds = L.latLngBounds(...parseLatLngBounds(el))\n // TODO: encapsulate this design pattern\n const observer = new MutationObserver(function (mutations) {\n mutations.forEach((mutation) => {\n let [bounds] = parseLatLngBounds(mutation.target)\n map.flyToBounds(bounds); // TODO: Use HTML attrs for fly/fit bounds\n });\n });\n observer.observe(el, {\n attributes: true,\n attributeFilter: [\"data-bounds\"],\n });\n map.fitBounds(bounds)\n })\n\n // L.tileLayers\n el.querySelectorAll(selector(\"tile-layer\")).forEach((el) => {\n L.tileLayer(...parseTileLayer(el)).addTo(map);\n });\n\n el.querySelectorAll(selector(\"image-overlay\")).forEach((el) => {\n L.imageOverlay(...parseImageOverlay(el)).addTo(map);\n });\n\n el.querySelectorAll(selector(\"video-overlay\")).forEach((el) => {\n L.videoOverlay(...parseVideoOverlay(el)).addTo(map);\n });\n\n // L.control.layers\n el.querySelectorAll(selector(\"control-layers\")).forEach((el) => {\n const baseMaps = {};\n\n // L.tileLayers\n el.querySelectorAll(selector(\"tile-layer\")).forEach((el) => {\n const { name, show } = el.dataset;\n baseMaps[name] = L.tileLayer(...parseTileLayer(el));\n if (show != null) {\n baseMaps[name].addTo(map);\n }\n });\n\n const overlayMaps = {};\n // L.layerGroup\n el.querySelectorAll(selector(\"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(selector(\"marker\")).forEach((el) => {\n const { latLng } = el.dataset;\n const { opacity = \"1.0\" } = el.dataset;\n const options = { opacity: parseFloat(opacity) };\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, {\n attributes: true,\n attributeFilter: [\"data-lat-lng\"],\n });\n\n // marker.bindPopup\n el.querySelectorAll(selector(\"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, {\n attributes: true,\n attributeFilter: [\"data-content\"],\n });\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":["selector","noun","parseTileLayer","el","_el$dataset","dataset","_el$dataset$attributi","attribution","_el$dataset$maxZoom","maxZoom","_el$dataset$minZoom","minZoom","_el$dataset$subdomain","subdomains","urlTemplate","parseLatLngBounds","bounds","Error","JSON","parse","init","document","addEventListener","querySelectorAll","forEach","_el$dataset5","center","zoom","map","L","setView","parseInt","_L","latLngBounds","apply","MutationObserver","mutations","mutation","_parseLatLngBounds","target","flyToBounds","observe","attributes","attributeFilter","fitBounds","_L2","tileLayer","addTo","_L3","imageOverlay","_el$dataset2","url","opacity","parseFloat","parseImageOverlay","_L4","videoOverlay","_el$dataset3","_el$dataset4","errorOverlayUrl","_el$dataset4$autoplay","autoplay","_el$dataset4$muted","muted","_el$dataset4$playsInl","playsInline","parseVideoOverlay","baseMaps","_L5","_el$dataset6","name","show","overlayMaps","layers","group","addedNodes","node","layer","marker","latLng","addLayer","removedNodes","getLayer","_leafletId","removeLayer","childList","_el$dataset$opacity","options","stamp","setLatLng","bindPopup","content","getPopup","setContent","push","layerGroup","control"],"mappings":"AAGA,IAAMA,EAAW,SAACC,GAAkBA,MAAAA,SAAAA,OAK9BC,EAAiB,SAACC,GACtB,IACAC,EAKID,EAAGE,QAAOC,EAAAF,EAJZG,YAAkBC,EAAAJ,EAClBK,QAAcC,EAAAN,EACdO,QAAaC,EAAAR,EACbS,WAGF,MAAO,CARiBV,EAAGE,QAAnBS,YAOQ,CAAEP,iBALL,IAAAD,EAAG,KAAIA,EAKWG,aAJnB,IAAHD,EAAG,KAAIA,EAIwBG,aAH/B,IAAAD,EAAG,IAAGA,EAGkCG,gBAFlC,IAAHD,EAAG,MAAKA,GAItB,EAwCMG,EAAoB,SAACZ,GACzB,IAAMa,EAAWb,EAAGE,QAAdW,OACN,QAAsB,IAAXA,EACT,MAAMC,MAAM,6BAEd,MAAO,CAACC,KAAKC,MAAMH,GACrB,EA0HMI,OACJC,SAASC,iBAAiB,mBAzHb,WAEbD,SAASE,iBAAiBvB,EAAS,iBAAiBwB,QAAQ,SAACrB,GAC3D,IAAAsB,EAAyBtB,EAAGE,QAApBqB,EAAMD,EAANC,OAAQC,EAAIF,EAAJE,KACVC,EAAMC,EAAED,IAAIzB,GAAI2B,QAAQZ,KAAKC,MAAMO,GAASK,SAASJ,I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AAd0E,OACRO,EAA4BnF,EAAGE,QAAvB+C,QACFmC,EAAU,CAAEnC,QAASC,gBADZ,IAAAiC,EAAG,MAAKA,IAEjBR,EAASjD,EAAEiD,OAAO5D,KAAKC,MAAM4D,GAASQ,GAASxC,MAAMnB,GAC3DzB,EAAGE,QAAQ8E,WAAatD,EAAE2D,MAAMV,GAEf,IAAI3C,iBAAiB,SAAUC,GAC9CA,EAAUZ,QAAQ,SAACa,GAEjByC,EAAOW,UAAUvE,KAAKC,MADHkB,EAASE,OAAOlC,QAA3B0E,QAEV,EACF,GACStC,QAAQtC,EAAI,CACnBuC,YAAY,EACZC,gBAAiB,CAAC,kBAIpBxC,EAAGoB,iBAAiBvB,EAAS,UAAUwB,QAAQ,SAACrB,GAE9C2E,EAAOY,UADavF,EAAGE,QAAfsF,SAES,IAAIxD,iBAAiB,WACpC2C,EAAOc,WAAWC,WAAW1F,EAAGE,QAAQsF,QAC1C,GACSlD,QAAQtC,EAAI,CACnBuC,YAAY,EACZC,gBAAiB,CAAC,iBAEtB,GAEA8B,EAAOqB,KAAKhB,EACd,GAEAN,EAAYF,GAAQzC,EAAEkE,WAAWtB,EACnC,GAEA5C,EAAEmE,QAAQvB,OAAON,EAAUK,GAAazB,MAAMnB,EAChD,EACF,EACF"}
|
package/dist/leaflet-html.esm.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var t=void document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("
|
1
|
+
var a=function(a){return"[data-"+a+"]"},t=function(a){var t=a.dataset,e=t.attribution,r=t.maxZoom,o=t.minZoom,n=t.subdomains;return[a.dataset.urlTemplate,{attribution:void 0===e?null:e,maxZoom:void 0===r?"18":r,minZoom:void 0===o?"0":o,subdomains:void 0===n?"abc":n}]},e=function(a){var t=a.dataset.bounds;if(void 0===t)throw Error("data-bounds not specified");return[JSON.parse(t)]},r=void document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(a("leaflet-html")).forEach(function(r){var o=r.dataset,n=o.center,l=o.zoom,d=L.map(r).setView(JSON.parse(n),parseInt(l));r.querySelectorAll(a("lat-lng-bounds")).forEach(function(a){var t,r=(t=L).latLngBounds.apply(t,e(a));new MutationObserver(function(a){a.forEach(function(a){var t=e(a.target);d.flyToBounds(t[0])})}).observe(a,{attributes:!0,attributeFilter:["data-bounds"]}),d.fitBounds(r)}),r.querySelectorAll(a("tile-layer")).forEach(function(a){var e;(e=L).tileLayer.apply(e,t(a)).addTo(d)}),r.querySelectorAll(a("image-overlay")).forEach(function(a){var t;(t=L).imageOverlay.apply(t,function(a){var t=a.dataset,e=t.bounds;return[t.url,e=JSON.parse(e),{opacity:parseFloat(a.dataset.opacity)}]}(a)).addTo(d)}),r.querySelectorAll(a("video-overlay")).forEach(function(a){var t;(t=L).videoOverlay.apply(t,function(a){var t=a.dataset,e=t.url,r=t.bounds;e=JSON.parse(e),r=JSON.parse(r);var o=a.dataset,n=o.errorOverlayUrl,l=o.autoplay,d=void 0===l||l,i=o.muted,u=void 0===i||i,s=o.playsInline,c=void 0===s||s;return[e,r,{opacity:parseFloat(o.opacity),errorOverlayUrl:n,autoplay:d,muted:u,playsInline:c}]}(a)).addTo(d)}),r.querySelectorAll(a("control-layers")).forEach(function(e){var r={};e.querySelectorAll(a("tile-layer")).forEach(function(a){var e,o=a.dataset,n=o.name,l=o.show;r[n]=(e=L).tileLayer.apply(e,t(a)),null!=l&&r[n].addTo(d)});var o={};e.querySelectorAll(a("layer-group")).forEach(function(t){var e=t.dataset.name,r=[];new MutationObserver(function(a){var t=o[e];a.forEach(function(a){a.addedNodes.forEach(function(a){var e=L.marker(JSON.parse(a.dataset.latLng));t.addLayer(e),d.addLayer(e)}),a.removedNodes.forEach(function(a){var e=t.getLayer(a.dataset._leafletId);t.removeLayer(e),d.removeLayer(e)})})}).observe(t,{childList:!0}),t.querySelectorAll(a("marker")).forEach(function(t){var e=t.dataset.latLng,o=t.dataset.opacity,n={opacity:parseFloat(void 0===o?"1.0":o)},l=L.marker(JSON.parse(e),n).addTo(d);t.dataset._leafletId=L.stamp(l),new MutationObserver(function(a){a.forEach(function(a){l.setLatLng(JSON.parse(a.target.dataset.latLng))})}).observe(t,{attributes:!0,attributeFilter:["data-lat-lng"]}),t.querySelectorAll(a("popup")).forEach(function(a){l.bindPopup(a.dataset.content),new MutationObserver(function(){l.getPopup().setContent(a.dataset.content)}).observe(a,{attributes:!0,attributeFilter:["data-content"]})}),r.push(l)}),o[e]=L.layerGroup(r)}),L.control.layers(r,o).addTo(d)})})});export{r 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 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 } =\n 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, {\n attributes: true,\n attributeFilter: [\"data-lat-lng\"],\n });\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, {\n attributes: true,\n attributeFilter: [\"data-content\"],\n });\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":["init","document","addEventListener","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"],"mappings":"AAAA,IA4FMA,OACJC,SAASC,iBAAiB,mBA7Fb,WAEbD,SAASE,iBAAiB,uBAAuBC,QAAQ,SAACC,GACxD,IAAAC,EAAyBD,EAAGE,QAApBC,EAAMF,EAANE,OAAQC,EAAIH,EAAJG,KACVC,EAAMC,EAAED,IAAIL,GAAIO,QAAQC,KAA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B,SAAUC,GAC9CA,EAAUzB,QAAQ,SAAC2B,GAEjBI,EAAOgB,UAAUtC,KAAKC,MADHiB,EAASqB,OAAO7C,QAA3B6B,QAEV,EACF,GACSM,QAAQrC,EAAI,CACnBgD,YAAY,EACZC,gBAAiB,CAAC,kBAIpBjD,EAAGF,iBAAiB,gBAAgBC,QAAQ,SAACC,GAE3C8B,EAAOoB,UADalD,EAAGE,QAAfiD,SAES,IAAI5B,iBAAiB,WACpCO,EAAOsB,WAAWC,WAAWrD,EAAGE,QAAQiD,QAC1C,GACSd,QAAQrC,EAAI,CACnBgD,YAAY,EACZC,gBAAiB,CAAC,iBAEtB,GAEA3B,EAAOgC,KAAKxB,EACd,GAEAT,EAAYN,GAAQT,EAAEiD,WAAWjC,EACnC,GAEAhB,EAAEkD,QAAQlC,OAAOX,EAAUU,GAAaD,MAAMf,EAChD,EACF,EACF"}
|
1
|
+
{"version":3,"file":"leaflet-html.esm.js","sources":["../src/index.js"],"sourcesContent":["// @ts-check\n\n// Helpers\nconst selector = (noun) => `[data-${noun}]`;\n\n/**\n * Parse L.tileLayer args from element attributes\n */\nconst parseTileLayer = (el) => {\n const { urlTemplate } = el.dataset;\n const {\n attribution = null,\n maxZoom = \"18\",\n minZoom = \"0\",\n subdomains = \"abc\",\n } = el.dataset;\n const options = { attribution, maxZoom, minZoom, subdomains };\n return [urlTemplate, options];\n};\n\n/**\n * Parse L.imageOverlay args from element attributes\n */\nconst parseImageOverlay = (el) => {\n let { url, bounds } = el.dataset;\n bounds = JSON.parse(bounds);\n const { opacity } = el.dataset;\n const options = { opacity: parseFloat(opacity) };\n return [url, bounds, options];\n};\n\n/**\n * Parse L.imageOverlay args from element attributes\n */\nconst parseVideoOverlay = (el) => {\n let { url, bounds } = el.dataset;\n url = JSON.parse(url);\n bounds = JSON.parse(bounds);\n const {\n opacity,\n errorOverlayUrl,\n autoplay = true,\n muted = true,\n playsInline = true,\n } = el.dataset;\n const options = {\n opacity: parseFloat(opacity),\n errorOverlayUrl,\n autoplay,\n muted,\n playsInline,\n };\n return [url, bounds, options];\n};\n\n/**\n * @param {HTMLElement} el\n */\nconst parseLatLngBounds = (el) => {\n let { bounds } = el.dataset;\n if (typeof bounds === \"undefined\") {\n throw Error(\"data-bounds not specified\")\n }\n return [JSON.parse(bounds)];\n}\n\nconst render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(selector(\"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.latLngBounds\n el.querySelectorAll(selector(\"lat-lng-bounds\")).forEach((el) => {\n const bounds = L.latLngBounds(...parseLatLngBounds(el))\n // TODO: encapsulate this design pattern\n const observer = new MutationObserver(function (mutations) {\n mutations.forEach((mutation) => {\n let [bounds] = parseLatLngBounds(mutation.target)\n map.flyToBounds(bounds); // TODO: Use HTML attrs for fly/fit bounds\n });\n });\n observer.observe(el, {\n attributes: true,\n attributeFilter: [\"data-bounds\"],\n });\n map.fitBounds(bounds)\n })\n\n // L.tileLayers\n el.querySelectorAll(selector(\"tile-layer\")).forEach((el) => {\n L.tileLayer(...parseTileLayer(el)).addTo(map);\n });\n\n el.querySelectorAll(selector(\"image-overlay\")).forEach((el) => {\n L.imageOverlay(...parseImageOverlay(el)).addTo(map);\n });\n\n el.querySelectorAll(selector(\"video-overlay\")).forEach((el) => {\n L.videoOverlay(...parseVideoOverlay(el)).addTo(map);\n });\n\n // L.control.layers\n el.querySelectorAll(selector(\"control-layers\")).forEach((el) => {\n const baseMaps = {};\n\n // L.tileLayers\n el.querySelectorAll(selector(\"tile-layer\")).forEach((el) => {\n const { name, show } = el.dataset;\n baseMaps[name] = L.tileLayer(...parseTileLayer(el));\n if (show != null) {\n baseMaps[name].addTo(map);\n }\n });\n\n const overlayMaps = {};\n // L.layerGroup\n el.querySelectorAll(selector(\"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(selector(\"marker\")).forEach((el) => {\n const { latLng } = el.dataset;\n const { opacity = \"1.0\" } = el.dataset;\n const options = { opacity: parseFloat(opacity) };\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, {\n attributes: true,\n attributeFilter: [\"data-lat-lng\"],\n });\n\n // marker.bindPopup\n el.querySelectorAll(selector(\"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, {\n attributes: true,\n attributeFilter: [\"data-content\"],\n });\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":["selector","noun","parseTileLayer","el","_el$dataset","dataset","_el$dataset$attributi","attribution","_el$dataset$maxZoom","maxZoom","_el$dataset$minZoom","minZoom","_el$dataset$subdomain","subdomains","urlTemplate","parseLatLngBounds","bounds","Error","JSON","parse","init","document","addEventListener","querySelectorAll","forEach","_el$dataset5","center","zoom","map","L","setView","parseInt","_L","latLngBounds","apply","MutationObserver","mutations","mutation","_parseLatLngBounds","target","flyToBounds","observe","attributes","attributeFilter","fitBounds","_L2","tileLayer","addTo","_L3","imageOverlay","_el$dataset2","url","opacity","parseFloat","parseImageOverlay","_L4","videoOverlay","_el$dataset3","_el$dataset4","errorOverlayUrl","_el$dataset4$autoplay","autoplay","_el$dataset4$muted","muted","_el$dataset4$playsInl","playsInline","parseVideoOverlay","baseMaps","_L5","_el$dataset6","name","show","overlayMaps","layers","group","addedNodes","node","layer","marker","latLng","addLayer","removedNodes","getLayer","_leafletId","removeLayer","childList","_el$dataset$opacity","options","stamp","setLatLng","bindPopup","content","getPopup","setContent","push","layerGroup","control"],"mappings":"AAGA,IAAMA,EAAW,SAACC,GAAkBA,MAAAA,SAAAA,OAK9BC,EAAiB,SAACC,GACtB,IACAC,EAKID,EAAGE,QAAOC,EAAAF,EAJZG,YAAkBC,EAAAJ,EAClBK,QAAcC,EAAAN,EACdO,QAAaC,EAAAR,EACbS,WAGF,MAAO,CARiBV,EAAGE,QAAnBS,YAOQ,CAAEP,iBALL,IAAAD,EAAG,KAAIA,EAKWG,aAJnB,IAAHD,EAAG,KAAIA,EAIwBG,aAH/B,IAAAD,EAAG,IAAGA,EAGkCG,gBAFlC,IAAHD,EAAG,MAAKA,GAItB,EAwCMG,EAAoB,SAACZ,GACzB,IAAMa,EAAWb,EAAGE,QAAdW,OACN,QAAsB,IAAXA,EACT,MAAMC,MAAM,6BAEd,MAAO,CAACC,KAAKC,MAAMH,GACrB,EA0HMI,OACJC,SAASC,iBAAiB,mBAzHb,WAEbD,SAASE,iBAAiBvB,EAAS,iBAAiBwB,QAAQ,SAACrB,GAC3D,IAAAsB,EAAyBtB,EAAGE,QAApBqB,EAAMD,EAANC,OAAQC,EAAIF,EAAJE,KACVC,EAAMC,EAAED,IAAIzB,GAAI2B,QAAQZ,KAAKC,MAAMO,GAASK,SAASJ,IAG3DxB,EAAGoB,iBAAiBvB,EAAS,mBAAmBwB,QAAQ,SAACrB,GAAO,IAAA6B,EACxDhB,GAASgB,EAAAH,GAAEI,a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EAASjD,EAAEiD,OAAO5D,KAAKC,MAAM4D,GAASQ,GAASxC,MAAMnB,GAC3DzB,EAAGE,QAAQ8E,WAAatD,EAAE2D,MAAMV,GAEf,IAAI3C,iBAAiB,SAAUC,GAC9CA,EAAUZ,QAAQ,SAACa,GAEjByC,EAAOW,UAAUvE,KAAKC,MADHkB,EAASE,OAAOlC,QAA3B0E,QAEV,EACF,GACStC,QAAQtC,EAAI,CACnBuC,YAAY,EACZC,gBAAiB,CAAC,kBAIpBxC,EAAGoB,iBAAiBvB,EAAS,UAAUwB,QAAQ,SAACrB,GAE9C2E,EAAOY,UADavF,EAAGE,QAAfsF,SAES,IAAIxD,iBAAiB,WACpC2C,EAAOc,WAAWC,WAAW1F,EAAGE,QAAQsF,QAC1C,GACSlD,QAAQtC,EAAI,CACnBuC,YAAY,EACZC,gBAAiB,CAAC,iBAEtB,GAEA8B,EAAOqB,KAAKhB,EACd,GAEAN,EAAYF,GAAQzC,EAAEkE,WAAWtB,EACnC,GAEA5C,EAAEmE,QAAQvB,OAAON,EAAUK,GAAazB,MAAMnB,EAChD,EACF,EACF"}
|
package/dist/leaflet-html.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
const t=void document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll("
|
1
|
+
const t=t=>`[data-${t}]`,e=t=>{const{urlTemplate:e}=t.dataset,{attribution:a=null,maxZoom:o="18",minZoom:r="0",subdomains:l="abc"}=t.dataset;return[e,{attribution:a,maxZoom:o,minZoom:r,subdomains:l}]},a=t=>{let{bounds:e}=t.dataset;if(void 0===e)throw Error("data-bounds not specified");return[JSON.parse(e)]},o=void document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll(t("leaflet-html")).forEach(o=>{const{center:r,zoom:l}=o.dataset,n=L.map(o).setView(JSON.parse(r),parseInt(l));o.querySelectorAll(t("lat-lng-bounds")).forEach(t=>{const e=L.latLngBounds(...a(t)),o=new MutationObserver(function(t){t.forEach(t=>{let[e]=a(t.target);n.flyToBounds(e)})});o.observe(t,{attributes:!0,attributeFilter:["data-bounds"]}),n.fitBounds(e)}),o.querySelectorAll(t("tile-layer")).forEach(t=>{L.tileLayer(...e(t)).addTo(n)}),o.querySelectorAll(t("image-overlay")).forEach(t=>{L.imageOverlay(...(t=>{let{url:e,bounds:a}=t.dataset;a=JSON.parse(a);const{opacity:o}=t.dataset;return[e,a,{opacity:parseFloat(o)}]})(t)).addTo(n)}),o.querySelectorAll(t("video-overlay")).forEach(t=>{L.videoOverlay(...(t=>{let{url:e,bounds:a}=t.dataset;e=JSON.parse(e),a=JSON.parse(a);const{opacity:o,errorOverlayUrl:r,autoplay:l=!0,muted:n=!0,playsInline:s=!0}=t.dataset;return[e,a,{opacity:parseFloat(o),errorOverlayUrl:r,autoplay:l,muted:n,playsInline:s}]})(t)).addTo(n)}),o.querySelectorAll(t("control-layers")).forEach(a=>{const o={};a.querySelectorAll(t("tile-layer")).forEach(t=>{const{name:a,show:r}=t.dataset;o[a]=L.tileLayer(...e(t)),null!=r&&o[a].addTo(n)});const r={};a.querySelectorAll(t("layer-group")).forEach(e=>{const{name:a}=e.dataset,o=[];new MutationObserver(function(t){const e=r[a];t.forEach(t=>{t.addedNodes.forEach(t=>{const{latLng:a}=t.dataset,o=L.marker(JSON.parse(a));e.addLayer(o),n.addLayer(o)}),t.removedNodes.forEach(t=>{const{_leafletId:a}=t.dataset,o=e.getLayer(a);e.removeLayer(o),n.removeLayer(o)})})}).observe(e,{childList:!0}),e.querySelectorAll(t("marker")).forEach(e=>{const{latLng:a}=e.dataset,{opacity:r="1.0"}=e.dataset,l={opacity:parseFloat(r)},s=L.marker(JSON.parse(a),l).addTo(n);e.dataset._leafletId=L.stamp(s);const d=new MutationObserver(function(t){t.forEach(t=>{const{latLng:e}=t.target.dataset;s.setLatLng(JSON.parse(e))})});d.observe(e,{attributes:!0,attributeFilter:["data-lat-lng"]}),e.querySelectorAll(t("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"]})}),o.push(s)}),r[a]=L.layerGroup(o)}),L.control.layers(o,r).addTo(n)})})});export{o as default};
|
2
2
|
//# sourceMappingURL=leaflet-html.js.map
|
package/dist/leaflet-html.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"leaflet-html.js","sources":["../src/index.js"],"sourcesContent":["const render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(\"
|
1
|
+
{"version":3,"file":"leaflet-html.js","sources":["../src/index.js"],"sourcesContent":["// @ts-check\n\n// Helpers\nconst selector = (noun) => `[data-${noun}]`;\n\n/**\n * Parse L.tileLayer args from element attributes\n */\nconst parseTileLayer = (el) => {\n const { urlTemplate } = el.dataset;\n const {\n attribution = null,\n maxZoom = \"18\",\n minZoom = \"0\",\n subdomains = \"abc\",\n } = el.dataset;\n const options = { attribution, maxZoom, minZoom, subdomains };\n return [urlTemplate, options];\n};\n\n/**\n * Parse L.imageOverlay args from element attributes\n */\nconst parseImageOverlay = (el) => {\n let { url, bounds } = el.dataset;\n bounds = JSON.parse(bounds);\n const { opacity } = el.dataset;\n const options = { opacity: parseFloat(opacity) };\n return [url, bounds, options];\n};\n\n/**\n * Parse L.imageOverlay args from element attributes\n */\nconst parseVideoOverlay = (el) => {\n let { url, bounds } = el.dataset;\n url = JSON.parse(url);\n bounds = JSON.parse(bounds);\n const {\n opacity,\n errorOverlayUrl,\n autoplay = true,\n muted = true,\n playsInline = true,\n } = el.dataset;\n const options = {\n opacity: parseFloat(opacity),\n errorOverlayUrl,\n autoplay,\n muted,\n playsInline,\n };\n return [url, bounds, options];\n};\n\n/**\n * @param {HTMLElement} el\n */\nconst parseLatLngBounds = (el) => {\n let { bounds } = el.dataset;\n if (typeof bounds === \"undefined\") {\n throw Error(\"data-bounds not specified\")\n }\n return [JSON.parse(bounds)];\n}\n\nconst render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(selector(\"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.latLngBounds\n el.querySelectorAll(selector(\"lat-lng-bounds\")).forEach((el) => {\n const bounds = L.latLngBounds(...parseLatLngBounds(el))\n // TODO: encapsulate this design pattern\n const observer = new MutationObserver(function (mutations) {\n mutations.forEach((mutation) => {\n let [bounds] = parseLatLngBounds(mutation.target)\n map.flyToBounds(bounds); // TODO: Use HTML attrs for fly/fit bounds\n });\n });\n observer.observe(el, {\n attributes: true,\n attributeFilter: [\"data-bounds\"],\n });\n map.fitBounds(bounds)\n })\n\n // L.tileLayers\n el.querySelectorAll(selector(\"tile-layer\")).forEach((el) => {\n L.tileLayer(...parseTileLayer(el)).addTo(map);\n });\n\n el.querySelectorAll(selector(\"image-overlay\")).forEach((el) => {\n L.imageOverlay(...parseImageOverlay(el)).addTo(map);\n });\n\n el.querySelectorAll(selector(\"video-overlay\")).forEach((el) => {\n L.videoOverlay(...parseVideoOverlay(el)).addTo(map);\n });\n\n // L.control.layers\n el.querySelectorAll(selector(\"control-layers\")).forEach((el) => {\n const baseMaps = {};\n\n // L.tileLayers\n el.querySelectorAll(selector(\"tile-layer\")).forEach((el) => {\n const { name, show } = el.dataset;\n baseMaps[name] = L.tileLayer(...parseTileLayer(el));\n if (show != null) {\n baseMaps[name].addTo(map);\n }\n });\n\n const overlayMaps = {};\n // L.layerGroup\n el.querySelectorAll(selector(\"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(selector(\"marker\")).forEach((el) => {\n const { latLng } = el.dataset;\n const { opacity = \"1.0\" } = el.dataset;\n const options = { opacity: parseFloat(opacity) };\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, {\n attributes: true,\n attributeFilter: [\"data-lat-lng\"],\n });\n\n // marker.bindPopup\n el.querySelectorAll(selector(\"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, {\n attributes: true,\n attributeFilter: [\"data-content\"],\n });\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":["selector","noun","parseTileLayer","el","urlTemplate","dataset","attribution","maxZoom","minZoom","subdomains","parseLatLngBounds","bounds","Error","JSON","parse","init","document","addEventListener","render","querySelectorAll","forEach","center","zoom","map","L","setView","parseInt","latLngBounds","observer","MutationObserver","mutations","mutation","target","flyToBounds","observe","attributes","attributeFilter","fitBounds","tileLayer","addTo","imageOverlay","url","opacity","parseFloat","parseImageOverlay","videoOverlay","errorOverlayUrl","autoplay","muted","playsInline","parseVideoOverlay","baseMaps","name","show","overlayMaps","layers","group","addedNodes","node","latLng","layer","marker","addLayer","removedNodes","_leafletId","getLayer","removeLayer","childList","options","stamp","setLatLng","content","bindPopup","getPopup","setContent","push","layerGroup","control"],"mappings":"AAGA,MAAMA,EAAYC,GAAU,SAAQA,KAK9BC,EAAkBC,IACtB,MAAMC,YA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YAAYN,EAAK,EACtB,EAEL,GACS1B,QAAQ/B,EAAI,CAAEgE,WAAW,IAGlChE,EAAGgB,iBAAiBnB,EAAS,WAAWoB,QAASjB,IAC/C,MAAMwD,OAAEA,GAAWxD,EAAGE,SAChBqC,QAAEA,EAAU,OAAUvC,EAAGE,QACzB+D,EAAU,CAAE1B,QAASC,WAAWD,IAChCmB,EAASrC,EAAEqC,OAAOhD,KAAKC,MAAM6C,GAASS,GAAS7B,MAAMhB,GAC3DpB,EAAGE,QAAQ2D,WAAaxC,EAAE6C,MAAMR,GAEhC,MAAMjC,EAAW,IAAIC,iBAAiB,SAAUC,GAC9CA,EAAUV,QAASW,IACjB,MAAM4B,OAAEA,GAAW5B,EAASC,OAAO3B,QACnCwD,EAAOS,UAAUzD,KAAKC,MAAM6C,GAC9B,EACF,GACA/B,EAASM,QAAQ/B,EAAI,CACnBgC,YAAY,EACZC,gBAAiB,CAAC,kBAIpBjC,EAAGgB,iBAAiBnB,EAAS,UAAUoB,QAASjB,IAC9C,MAAMoE,QAAEA,GAAYpE,EAAGE,QACvBwD,EAAOW,UAAUD,GACA,IAAI1C,iBAAiB,WACpCgC,EAAOY,WAAWC,WAAWvE,EAAGE,QAAQkE,QAC1C,GACSrC,QAAQ/B,EAAI,CACnBgC,YAAY,EACZC,gBAAiB,CAAC,iBACnB,GAGHmB,EAAOoB,KAAKd,EACd,GAEAP,EAAYF,GAAQ5B,EAAEoD,WAAWrB,EACnC,GAEA/B,EAAEqD,QAAQtB,OAAOJ,EAAUG,GAAaf,MAAMhB,EAChD,EACF,EACF"}
|
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(){document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("
|
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(e){return"[data-"+e+"]"},t=function(e){var t=e.dataset,a=t.attribution,o=t.maxZoom,r=t.minZoom,n=t.subdomains;return[e.dataset.urlTemplate,{attribution:void 0===a?null:a,maxZoom:void 0===o?"18":o,minZoom:void 0===r?"0":r,subdomains:void 0===n?"abc":n}]},a=function(e){var t=e.dataset.bounds;if(void 0===t)throw Error("data-bounds not specified");return[JSON.parse(t)]};document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(e("leaflet-html")).forEach(function(o){var r=o.dataset,n=r.center,l=r.zoom,i=L.map(o).setView(JSON.parse(n),parseInt(l));o.querySelectorAll(e("lat-lng-bounds")).forEach(function(e){var t,o=(t=L).latLngBounds.apply(t,a(e));new MutationObserver(function(e){e.forEach(function(e){var t=a(e.target);i.flyToBounds(t[0])})}).observe(e,{attributes:!0,attributeFilter:["data-bounds"]}),i.fitBounds(o)}),o.querySelectorAll(e("tile-layer")).forEach(function(e){var a;(a=L).tileLayer.apply(a,t(e)).addTo(i)}),o.querySelectorAll(e("image-overlay")).forEach(function(e){var t;(t=L).imageOverlay.apply(t,function(e){var t=e.dataset,a=t.bounds;return[t.url,a=JSON.parse(a),{opacity:parseFloat(e.dataset.opacity)}]}(e)).addTo(i)}),o.querySelectorAll(e("video-overlay")).forEach(function(e){var t;(t=L).videoOverlay.apply(t,function(e){var t=e.dataset,a=t.url,o=t.bounds;a=JSON.parse(a),o=JSON.parse(o);var r=e.dataset,n=r.errorOverlayUrl,l=r.autoplay,i=void 0===l||l,d=r.muted,u=void 0===d||d,s=r.playsInline,c=void 0===s||s;return[a,o,{opacity:parseFloat(r.opacity),errorOverlayUrl:n,autoplay:i,muted:u,playsInline:c}]}(e)).addTo(i)}),o.querySelectorAll(e("control-layers")).forEach(function(a){var o={};a.querySelectorAll(e("tile-layer")).forEach(function(e){var a,r=e.dataset,n=r.name,l=r.show;o[n]=(a=L).tileLayer.apply(a,t(e)),null!=l&&o[n].addTo(i)});var r={};a.querySelectorAll(e("layer-group")).forEach(function(t){var a=t.dataset.name,o=[];new MutationObserver(function(e){var t=r[a];e.forEach(function(e){e.addedNodes.forEach(function(e){var a=L.marker(JSON.parse(e.dataset.latLng));t.addLayer(a),i.addLayer(a)}),e.removedNodes.forEach(function(e){var a=t.getLayer(e.dataset._leafletId);t.removeLayer(a),i.removeLayer(a)})})}).observe(t,{childList:!0}),t.querySelectorAll(e("marker")).forEach(function(t){var a=t.dataset.latLng,r=t.dataset.opacity,n={opacity:parseFloat(void 0===r?"1.0":r)},l=L.marker(JSON.parse(a),n).addTo(i);t.dataset._leafletId=L.stamp(l),new MutationObserver(function(e){e.forEach(function(e){l.setLatLng(JSON.parse(e.target.dataset.latLng))})}).observe(t,{attributes:!0,attributeFilter:["data-lat-lng"]}),t.querySelectorAll(e("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)}),r[a]=L.layerGroup(o)}),L.control.layers(o,r).addTo(i)})})})});
|
2
2
|
//# sourceMappingURL=leaflet-html.umd.js.map
|
@@ -1 +1 @@
|
|
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 } =\n 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, {\n attributes: true,\n attributeFilter: [\"data-lat-lng\"],\n });\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, {\n attributes: true,\n attributeFilter: [\"data-content\"],\n });\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":["document","addEventListener","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"],"mappings":"8NA6FEA,SAASC,iBAAiB,mBA7Fb,WAEbD,SAASE,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,EACED,EAAOV,QADDY,EAAID,EAAJC,KAAyCC,EAAIF,EAAJE,KAEjDJ,EAASI,GAAQT,EAAEU,UAFMH,EAAXI,YAE4B,CAAEC,QAFGL,EAAPK,QAEaC,YAFfN,EAAXM,cAGf,MAARL,GACFH,EAASI,GAAMK,MAAMf,EAEzB,GAEA,IAAMgB,EAAc,CAAA,EAEpBrB,EAAGF,iBAAiB,sBAAsBC,QAAQ,SAACC,GACjD,IAAQe,EAASf,EAAGE,QAAZa,KACFO,EAAS,GAEE,IAAIC,iBAAiB,SAAUC,GAC9C,IAAMC,EAAQJ,EAAYN,GAE1BS,EAAUzB,QAAQ,SAAC2B,GACjBA,EAASC,WAAW5B,QAAQ,SAAC6B,GAC3B,IACMC,EAAQvB,EAAEwB,OAAOtB,KAAKC,MADTmB,EAAK1B,QAAhB6B,SAERN,EAAMO,SAASH,GACfxB,EAAI2B,SAASH,EACf,GAEAH,EAASO,aAAalC,QAAQ,SAAC6B,GAC7B,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,gBADT,IAAHH,EAAG,MAAKA,IAEvBI,QAAQC,IAAIH,GACZ,IAAMX,EAASxB,EAAEwB,OAAOtB,KAAKC,MAAMsB,GAASU,GAASrB,MAAMf,GAC3DL,EAAGE,QAAQiC,WAAa7B,EAAEuC,MAAMf,GAEf,IAAIP,iBAAiB,SAAUC,GAC9CA,EAAUzB,QAAQ,SAAC2B,GAEjBI,EAAOgB,UAAUtC,KAAKC,MADHiB,EAASqB,OAAO7C,QAA3B6B,QAEV,EACF,GACSM,QAAQrC,EAAI,CACnBgD,YAAY,EACZC,gBAAiB,CAAC,kBAIpBjD,EAAGF,iBAAiB,gBAAgBC,QAAQ,SAACC,GAE3C8B,EAAOoB,UADalD,EAAGE,QAAfiD,SAES,IAAI5B,iBAAiB,WACpCO,EAAOsB,WAAWC,WAAWrD,EAAGE,QAAQiD,QAC1C,GACSd,QAAQrC,EAAI,CACnBgD,YAAY,EACZC,gBAAiB,CAAC,iBAEtB,GAEA3B,EAAOgC,KAAKxB,EACd,GAEAT,EAAYN,GAAQT,EAAEiD,WAAWjC,EACnC,GAEAhB,EAAEkD,QAAQlC,OAAOX,EAAUU,GAAaD,MAAMf,EAChD,EACF,EACF"}
|
1
|
+
{"version":3,"file":"leaflet-html.umd.js","sources":["../src/index.js"],"sourcesContent":["// @ts-check\n\n// Helpers\nconst selector = (noun) => `[data-${noun}]`;\n\n/**\n * Parse L.tileLayer args from element attributes\n */\nconst parseTileLayer = (el) => {\n const { urlTemplate } = el.dataset;\n const {\n attribution = null,\n maxZoom = \"18\",\n minZoom = \"0\",\n subdomains = \"abc\",\n } = el.dataset;\n const options = { attribution, maxZoom, minZoom, subdomains };\n return [urlTemplate, options];\n};\n\n/**\n * Parse L.imageOverlay args from element attributes\n */\nconst parseImageOverlay = (el) => {\n let { url, bounds } = el.dataset;\n bounds = JSON.parse(bounds);\n const { opacity } = el.dataset;\n const options = { opacity: parseFloat(opacity) };\n return [url, bounds, options];\n};\n\n/**\n * Parse L.imageOverlay args from element attributes\n */\nconst parseVideoOverlay = (el) => {\n let { url, bounds } = el.dataset;\n url = JSON.parse(url);\n bounds = JSON.parse(bounds);\n const {\n opacity,\n errorOverlayUrl,\n autoplay = true,\n muted = true,\n playsInline = true,\n } = el.dataset;\n const options = {\n opacity: parseFloat(opacity),\n errorOverlayUrl,\n autoplay,\n muted,\n playsInline,\n };\n return [url, bounds, options];\n};\n\n/**\n * @param {HTMLElement} el\n */\nconst parseLatLngBounds = (el) => {\n let { bounds } = el.dataset;\n if (typeof bounds === \"undefined\") {\n throw Error(\"data-bounds not specified\")\n }\n return [JSON.parse(bounds)];\n}\n\nconst render = () => {\n // Render Leaflet API calls\n document.querySelectorAll(selector(\"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.latLngBounds\n el.querySelectorAll(selector(\"lat-lng-bounds\")).forEach((el) => {\n const bounds = L.latLngBounds(...parseLatLngBounds(el))\n // TODO: encapsulate this design pattern\n const observer = new MutationObserver(function (mutations) {\n mutations.forEach((mutation) => {\n let [bounds] = parseLatLngBounds(mutation.target)\n map.flyToBounds(bounds); // TODO: Use HTML attrs for fly/fit bounds\n });\n });\n observer.observe(el, {\n attributes: true,\n attributeFilter: [\"data-bounds\"],\n });\n map.fitBounds(bounds)\n })\n\n // L.tileLayers\n el.querySelectorAll(selector(\"tile-layer\")).forEach((el) => {\n L.tileLayer(...parseTileLayer(el)).addTo(map);\n });\n\n el.querySelectorAll(selector(\"image-overlay\")).forEach((el) => {\n L.imageOverlay(...parseImageOverlay(el)).addTo(map);\n });\n\n el.querySelectorAll(selector(\"video-overlay\")).forEach((el) => {\n L.videoOverlay(...parseVideoOverlay(el)).addTo(map);\n });\n\n // L.control.layers\n el.querySelectorAll(selector(\"control-layers\")).forEach((el) => {\n const baseMaps = {};\n\n // L.tileLayers\n el.querySelectorAll(selector(\"tile-layer\")).forEach((el) => {\n const { name, show } = el.dataset;\n baseMaps[name] = L.tileLayer(...parseTileLayer(el));\n if (show != null) {\n baseMaps[name].addTo(map);\n }\n });\n\n const overlayMaps = {};\n // L.layerGroup\n el.querySelectorAll(selector(\"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(selector(\"marker\")).forEach((el) => {\n const { latLng } = el.dataset;\n const { opacity = \"1.0\" } = el.dataset;\n const options = { opacity: parseFloat(opacity) };\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, {\n attributes: true,\n attributeFilter: [\"data-lat-lng\"],\n });\n\n // marker.bindPopup\n el.querySelectorAll(selector(\"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, {\n attributes: true,\n attributeFilter: [\"data-content\"],\n });\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":["selector","noun","parseTileLayer","el","_el$dataset","dataset","_el$dataset$attributi","attribution","_el$dataset$maxZoom","maxZoom","_el$dataset$minZoom","minZoom","_el$dataset$subdomain","subdomains","urlTemplate","parseLatLngBounds","bounds","Error","JSON","parse","document","addEventListener","querySelectorAll","forEach","_el$dataset5","center","zoom","map","L","setView","parseInt","_L","latLngBounds","apply","MutationObserver","mutations","mutation","_parseLatLngBounds","target","flyToBounds","observe","attributes","attributeFilter","fitBounds","_L2","tileLayer","addTo","_L3","imageOverlay","_el$dataset2","url","opacity","parseFloat","parseImageOverlay","_L4","videoOverlay","_el$dataset3","_el$dataset4","errorOverlayUrl","_el$dataset4$autoplay","autoplay","_el$dataset4$muted","muted","_el$dataset4$playsInl","playsInline","parseVideoOverlay","baseMaps","_L5","_el$dataset6","name","show","overlayMaps","layers","group","addedNodes","node","layer","marker","latLng","addLayer","removedNodes","getLayer","_leafletId","removeLayer","childList","_el$dataset$opacity","options","stamp","setLatLng","bindPopup","content","getPopup","setContent","push","layerGroup","control"],"mappings":"8NAGA,IAAMA,EAAW,SAACC,GAAkBA,MAAAA,SAAAA,OAK9BC,EAAiB,SAACC,GACtB,IACAC,EAKID,EAAGE,QAAOC,EAAAF,EAJZG,YAAkBC,EAAAJ,EAClBK,QAAcC,EAAAN,EACdO,QAAaC,EAAAR,EACbS,WAGF,MAAO,CARiBV,EAAGE,QAAnBS,YAOQ,CAAEP,iBALL,IAAAD,EAAG,KAAIA,EAKWG,aAJnB,IAAHD,EAAG,KAAIA,EAIwBG,aAH/B,IAAAD,EAAG,IAAGA,EAGkCG,gBAFlC,IAAHD,EAAG,MAAKA,GAItB,EAwCMG,EAAoB,SAACZ,GACzB,IAAMa,EAAWb,EAAGE,QAAdW,OACN,QAAsB,IAAXA,EACT,MAAMC,MAAM,6BAEd,MAAO,CAACC,KAAKC,MAAMH,GACrB,EA2HE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,EAAQH,EAAMQ,SADGN,EAAKtE,QAApB6E,YAERT,EAAMU,YAAYP,GAElBjD,EAAIwD,YAAYP,EAClB,EACF,EACF,GACSpC,QAAQrC,EAAI,CAAEiF,WAAW,IAGlCjF,EAAGmB,iBAAiBtB,EAAS,WAAWuB,QAAQ,SAACpB,GAC/C,IAAQ2E,EAAW3E,EAAGE,QAAdyE,OACRO,EAA4BlF,EAAGE,QAAvB8C,QACFmC,EAAU,CAAEnC,QAASC,gBADZ,IAAAiC,EAAG,MAAKA,IAEjBR,EAASjD,EAAEiD,OAAO3D,KAAKC,MAAM2D,GAASQ,GAASxC,MAAMnB,GAC3DxB,EAAGE,QAAQ6E,WAAatD,EAAE2D,MAAMV,GAEf,IAAI3C,iBAAiB,SAAUC,GAC9CA,EAAUZ,QAAQ,SAACa,GAEjByC,EAAOW,UAAUtE,KAAKC,MADHiB,EAASE,OAAOjC,QAA3ByE,QAEV,EACF,GACStC,QAAQrC,EAAI,CACnBsC,YAAY,EACZC,gBAAiB,CAAC,kBAIpBvC,EAAGmB,iBAAiBtB,EAAS,UAAUuB,QAAQ,SAACpB,GAE9C0E,EAAOY,UADatF,EAAGE,QAAfqF,SAES,IAAIxD,iBAAiB,WACpC2C,EAAOc,WAAWC,WAAWzF,EAAGE,QAAQqF,QAC1C,GACSlD,QAAQrC,EAAI,CACnBsC,YAAY,EACZC,gBAAiB,CAAC,iBAEtB,GAEA8B,EAAOqB,KAAKhB,EACd,GAEAN,EAAYF,GAAQzC,EAAEkE,WAAWtB,EACnC,GAEA5C,EAAEmE,QAAQvB,OAAON,EAAUK,GAAazB,MAAMnB,EAChD,EACF,EACF"}
|
package/docs/config.toml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# The URL the site will be built for
|
2
|
+
base_url = "https://andrewgryan.github.io/leaflet-html"
|
3
|
+
|
4
|
+
# Whether to automatically compile all Sass files in the sass directory
|
5
|
+
compile_sass = false
|
6
|
+
|
7
|
+
# Whether to build a search index to be used later on by a JavaScript library
|
8
|
+
build_search_index = false
|
9
|
+
|
10
|
+
[markdown]
|
11
|
+
# Whether to do syntax highlighting
|
12
|
+
# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola
|
13
|
+
highlight_code = true
|
14
|
+
|
15
|
+
[extra]
|
16
|
+
# Put all your custom variables here
|
@@ -0,0 +1,86 @@
|
|
1
|
+
+++
|
2
|
+
+++
|
3
|
+
# Leaflet HTML
|
4
|
+
|
5
|
+
[LeafletJS](https://leafletjs.com/) is a library geared towards map based visualisations.
|
6
|
+
Leaflet HTML expresses that JavaScript API in HTML.
|
7
|
+
|
8
|
+
|
9
|
+
## Design principles
|
10
|
+
|
11
|
+
Leaflet HTML tries to model Leaflet's API as closely as possible to avoid confusion and to ease onboarding.
|
12
|
+
Naming conventions are followed where possible.
|
13
|
+
The hierarchy in the JS API is replicated by nesting HTML elements.
|
14
|
+
|
15
|
+
## Example
|
16
|
+
|
17
|
+
The following is a live running example of Leaflet HTML.
|
18
|
+
|
19
|
+
<div data-leaflet-html data-center="[39.61, -105.02]" data-zoom="10">
|
20
|
+
<div data-control-layers>
|
21
|
+
<div data-base-maps>
|
22
|
+
<div
|
23
|
+
data-tile-layer
|
24
|
+
data-name="CartoDB_Voyager"
|
25
|
+
data-url-template="https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png"
|
26
|
+
data-attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>'
|
27
|
+
data-max-zoom="20"
|
28
|
+
data-subdomains="abcd"
|
29
|
+
data-show
|
30
|
+
></div>
|
31
|
+
</div>
|
32
|
+
<div data-overlay-maps>
|
33
|
+
<div data-layer-group data-name="Cities">
|
34
|
+
<div data-marker data-lat-lng="[39.61, -105.02]">
|
35
|
+
<div data-popup data-content="This is Littleton, CO."></div>
|
36
|
+
</div>
|
37
|
+
<div data-marker data-lat-lng="[39.74, -104.99]">
|
38
|
+
<div data-popup data-content="This is Denver, CO."></div>
|
39
|
+
</div>
|
40
|
+
<div data-marker data-lat-lng="[39.73, -104.8]">
|
41
|
+
<div data-popup data-content="This is Aurora, CO."></div>
|
42
|
+
</div>
|
43
|
+
<div data-marker data-lat-lng="[39.77, -105.23]">
|
44
|
+
<div data-popup data-content="This is Golden, CO."></div>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
|
52
|
+
```html
|
53
|
+
<!-- Example -->
|
54
|
+
<div data-leaflet-html data-center="[39.61, -105.02]" data-zoom="10">
|
55
|
+
<div data-control-layers>
|
56
|
+
<div data-base-maps>
|
57
|
+
<div
|
58
|
+
data-tile-layer
|
59
|
+
data-name="CartoDB_Voyager"
|
60
|
+
data-url-template="https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png"
|
61
|
+
data-attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>'
|
62
|
+
data-max-zoom="20"
|
63
|
+
data-subdomains="abcd"
|
64
|
+
data-show
|
65
|
+
></div>
|
66
|
+
</div>
|
67
|
+
<div data-overlay-maps>
|
68
|
+
<div data-layer-group data-name="Cities">
|
69
|
+
<div data-marker data-lat-lng="[39.61, -105.02]">
|
70
|
+
<div data-popup data-content="This is Littleton, CO."></div>
|
71
|
+
</div>
|
72
|
+
<div data-marker data-lat-lng="[39.74, -104.99]">
|
73
|
+
<div data-popup data-content="This is Denver, CO."></div>
|
74
|
+
</div>
|
75
|
+
<div data-marker data-lat-lng="[39.73, -104.8]">
|
76
|
+
<div data-popup data-content="This is Aurora, CO."></div>
|
77
|
+
</div>
|
78
|
+
<div data-marker data-lat-lng="[39.77, -105.23]">
|
79
|
+
<div data-popup data-content="This is Golden, CO."></div>
|
80
|
+
</div>
|
81
|
+
</div>
|
82
|
+
</div>
|
83
|
+
</div>
|
84
|
+
</div>
|
85
|
+
```
|
86
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head lang="en">
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
6
|
+
<style>
|
7
|
+
|
8
|
+
[data-leaflet-html] {
|
9
|
+
block-size: 40ch;
|
10
|
+
isolation: isolate;
|
11
|
+
z-index: 1;
|
12
|
+
}
|
13
|
+
body {
|
14
|
+
font-family: system-ui;
|
15
|
+
line-height: 1.6;
|
16
|
+
}
|
17
|
+
h1, h2 {
|
18
|
+
font-weight: 100;
|
19
|
+
}
|
20
|
+
|
21
|
+
pre {
|
22
|
+
padding-inline: 0.75rem;
|
23
|
+
padding-block: 0.5rem;
|
24
|
+
border-radius: 0.2rem;
|
25
|
+
overflow-x: scroll;
|
26
|
+
}
|
27
|
+
|
28
|
+
.wrapper {
|
29
|
+
inline-size: 80ch;
|
30
|
+
margin-inline: auto;
|
31
|
+
}
|
32
|
+
</style>
|
33
|
+
<link
|
34
|
+
rel="stylesheet"
|
35
|
+
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
36
|
+
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
37
|
+
crossorigin=""
|
38
|
+
/>
|
39
|
+
<script
|
40
|
+
src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
41
|
+
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
42
|
+
crossorigin=""
|
43
|
+
></script>
|
44
|
+
<script
|
45
|
+
src="https://unpkg.com/leaflet-html@latest/dist/leaflet-html.umd.js"
|
46
|
+
></script>
|
47
|
+
</head>
|
48
|
+
<body>
|
49
|
+
<div class="wrapper">
|
50
|
+
{{ section.content | safe }}
|
51
|
+
</div>
|
52
|
+
</body>
|
53
|
+
</html>
|
package/example/index.html
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
crossorigin=""
|
16
16
|
></script>
|
17
17
|
<script
|
18
|
-
src="
|
18
|
+
src="/dist/leaflet-html.umd.js"
|
19
19
|
defer
|
20
20
|
></script>
|
21
21
|
<style>
|
@@ -57,10 +57,11 @@
|
|
57
57
|
></div>
|
58
58
|
<div
|
59
59
|
data-tile-layer
|
60
|
-
data-name="
|
61
|
-
data-url-template="https://
|
62
|
-
data-attribution=""
|
63
|
-
data-max-zoom="
|
60
|
+
data-name="CartoDB_Voyager"
|
61
|
+
data-url-template="https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png"
|
62
|
+
data-attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>'
|
63
|
+
data-max-zoom="20"
|
64
|
+
data-subdomains="abcd"
|
64
65
|
data-show
|
65
66
|
></div>
|
66
67
|
</div>
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head lang="en">
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
6
|
+
<title>Leaflet HTML imageOverlay</title>
|
7
|
+
<link
|
8
|
+
rel="stylesheet"
|
9
|
+
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
10
|
+
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
11
|
+
crossorigin=""
|
12
|
+
/>
|
13
|
+
<script
|
14
|
+
src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
15
|
+
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
16
|
+
crossorigin=""
|
17
|
+
></script>
|
18
|
+
<script src="/dist/leaflet-html.umd.js"></script>
|
19
|
+
<style>
|
20
|
+
* {
|
21
|
+
margin: 0;
|
22
|
+
}
|
23
|
+
|
24
|
+
[data-leaflet-html] {
|
25
|
+
block-size: 100vh;
|
26
|
+
isolation: isolate;
|
27
|
+
z-index: 1;
|
28
|
+
}
|
29
|
+
</style>
|
30
|
+
</head>
|
31
|
+
<body>
|
32
|
+
<div data-leaflet-html data-center="[37.8, -96]" data-zoom="4">
|
33
|
+
<div
|
34
|
+
data-lat-lng-bounds
|
35
|
+
data-bounds="[[40.799311, -74.118464], [40.68202047785919, -74.33]]"
|
36
|
+
></div>
|
37
|
+
<div
|
38
|
+
data-tile-layer
|
39
|
+
data-name="OpenStreetMap"
|
40
|
+
data-url-template="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
|
41
|
+
data-attribution=""
|
42
|
+
></div>
|
43
|
+
<!-- Newark -->
|
44
|
+
<div
|
45
|
+
data-image-overlay
|
46
|
+
data-url="https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg"
|
47
|
+
data-bounds="[[40.799311, -74.118464], [40.68202047785919, -74.33]]"
|
48
|
+
data-opacity="0.8"
|
49
|
+
data-interactive="true"
|
50
|
+
data-error-overlay-url="https://cdn-icons-png.flaticon.com/512/110/110686.png"
|
51
|
+
data-alt="Image of Newark, N.J. in 1922. Source: The University of Texas at Austin, UT Libraries Map Collection."
|
52
|
+
></div>
|
53
|
+
<!-- Hurricane Patricia -->
|
54
|
+
<div
|
55
|
+
data-video-overlay
|
56
|
+
data-url='["https://www.mapbox.com/bites/00188/patricia_nasa.webm", "https://www.mapbox.com/bites/00188/patricia_nasa.mp4"]'
|
57
|
+
data-error-overlay-url="https://cdn-icons-png.flaticon.com/512/110/110686.png"
|
58
|
+
data-bounds="[[32, -130], [13, -100]]"
|
59
|
+
></div>
|
60
|
+
</div>
|
61
|
+
<script>
|
62
|
+
el = document.querySelector("[data-lat-lng-bounds]")
|
63
|
+
let counter = 0
|
64
|
+
document.body.addEventListener("click", () => {
|
65
|
+
console.log("click")
|
66
|
+
if (counter === 0) {
|
67
|
+
const { bounds } = document.querySelector("[data-video-overlay]").dataset
|
68
|
+
el.dataset.bounds = bounds
|
69
|
+
} else {
|
70
|
+
const { bounds } = document.querySelector("[data-image-overlay]").dataset
|
71
|
+
el.dataset.bounds = bounds
|
72
|
+
}
|
73
|
+
counter += 1
|
74
|
+
})
|
75
|
+
</script>
|
76
|
+
</body>
|
77
|
+
</html>
|
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -1,18 +1,113 @@
|
|
1
|
+
// @ts-check
|
2
|
+
|
3
|
+
// Helpers
|
4
|
+
const selector = (noun) => `[data-${noun}]`;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Parse L.tileLayer args from element attributes
|
8
|
+
*/
|
9
|
+
const parseTileLayer = (el) => {
|
10
|
+
const { urlTemplate } = el.dataset;
|
11
|
+
const {
|
12
|
+
attribution = null,
|
13
|
+
maxZoom = "18",
|
14
|
+
minZoom = "0",
|
15
|
+
subdomains = "abc",
|
16
|
+
} = el.dataset;
|
17
|
+
const options = { attribution, maxZoom, minZoom, subdomains };
|
18
|
+
return [urlTemplate, options];
|
19
|
+
};
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Parse L.imageOverlay args from element attributes
|
23
|
+
*/
|
24
|
+
const parseImageOverlay = (el) => {
|
25
|
+
let { url, bounds } = el.dataset;
|
26
|
+
bounds = JSON.parse(bounds);
|
27
|
+
const { opacity } = el.dataset;
|
28
|
+
const options = { opacity: parseFloat(opacity) };
|
29
|
+
return [url, bounds, options];
|
30
|
+
};
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Parse L.imageOverlay args from element attributes
|
34
|
+
*/
|
35
|
+
const parseVideoOverlay = (el) => {
|
36
|
+
let { url, bounds } = el.dataset;
|
37
|
+
url = JSON.parse(url);
|
38
|
+
bounds = JSON.parse(bounds);
|
39
|
+
const {
|
40
|
+
opacity,
|
41
|
+
errorOverlayUrl,
|
42
|
+
autoplay = true,
|
43
|
+
muted = true,
|
44
|
+
playsInline = true,
|
45
|
+
} = el.dataset;
|
46
|
+
const options = {
|
47
|
+
opacity: parseFloat(opacity),
|
48
|
+
errorOverlayUrl,
|
49
|
+
autoplay,
|
50
|
+
muted,
|
51
|
+
playsInline,
|
52
|
+
};
|
53
|
+
return [url, bounds, options];
|
54
|
+
};
|
55
|
+
|
56
|
+
/**
|
57
|
+
* @param {HTMLElement} el
|
58
|
+
*/
|
59
|
+
const parseLatLngBounds = (el) => {
|
60
|
+
let { bounds } = el.dataset;
|
61
|
+
if (typeof bounds === "undefined") {
|
62
|
+
throw Error("data-bounds not specified")
|
63
|
+
}
|
64
|
+
return [JSON.parse(bounds)];
|
65
|
+
}
|
66
|
+
|
1
67
|
const render = () => {
|
2
68
|
// Render Leaflet API calls
|
3
|
-
document.querySelectorAll("
|
69
|
+
document.querySelectorAll(selector("leaflet-html")).forEach((el) => {
|
4
70
|
const { center, zoom } = el.dataset;
|
5
71
|
const map = L.map(el).setView(JSON.parse(center), parseInt(zoom));
|
6
72
|
|
73
|
+
// L.latLngBounds
|
74
|
+
el.querySelectorAll(selector("lat-lng-bounds")).forEach((el) => {
|
75
|
+
const bounds = L.latLngBounds(...parseLatLngBounds(el))
|
76
|
+
// TODO: encapsulate this design pattern
|
77
|
+
const observer = new MutationObserver(function (mutations) {
|
78
|
+
mutations.forEach((mutation) => {
|
79
|
+
let [bounds] = parseLatLngBounds(mutation.target)
|
80
|
+
map.flyToBounds(bounds); // TODO: Use HTML attrs for fly/fit bounds
|
81
|
+
});
|
82
|
+
});
|
83
|
+
observer.observe(el, {
|
84
|
+
attributes: true,
|
85
|
+
attributeFilter: ["data-bounds"],
|
86
|
+
});
|
87
|
+
map.fitBounds(bounds)
|
88
|
+
})
|
89
|
+
|
90
|
+
// L.tileLayers
|
91
|
+
el.querySelectorAll(selector("tile-layer")).forEach((el) => {
|
92
|
+
L.tileLayer(...parseTileLayer(el)).addTo(map);
|
93
|
+
});
|
94
|
+
|
95
|
+
el.querySelectorAll(selector("image-overlay")).forEach((el) => {
|
96
|
+
L.imageOverlay(...parseImageOverlay(el)).addTo(map);
|
97
|
+
});
|
98
|
+
|
99
|
+
el.querySelectorAll(selector("video-overlay")).forEach((el) => {
|
100
|
+
L.videoOverlay(...parseVideoOverlay(el)).addTo(map);
|
101
|
+
});
|
102
|
+
|
7
103
|
// L.control.layers
|
8
|
-
el.querySelectorAll("
|
104
|
+
el.querySelectorAll(selector("control-layers")).forEach((el) => {
|
9
105
|
const baseMaps = {};
|
10
106
|
|
11
107
|
// L.tileLayers
|
12
|
-
el.querySelectorAll("
|
13
|
-
const {
|
14
|
-
|
15
|
-
baseMaps[name] = L.tileLayer(urlTemplate, { maxZoom, attribution });
|
108
|
+
el.querySelectorAll(selector("tile-layer")).forEach((el) => {
|
109
|
+
const { name, show } = el.dataset;
|
110
|
+
baseMaps[name] = L.tileLayer(...parseTileLayer(el));
|
16
111
|
if (show != null) {
|
17
112
|
baseMaps[name].addTo(map);
|
18
113
|
}
|
@@ -20,7 +115,7 @@ const render = () => {
|
|
20
115
|
|
21
116
|
const overlayMaps = {};
|
22
117
|
// L.layerGroup
|
23
|
-
el.querySelectorAll("
|
118
|
+
el.querySelectorAll(selector("layer-group")).forEach((el) => {
|
24
119
|
const { name } = el.dataset;
|
25
120
|
const layers = [];
|
26
121
|
|
@@ -47,11 +142,10 @@ const render = () => {
|
|
47
142
|
observer.observe(el, { childList: true });
|
48
143
|
|
49
144
|
// L.marker
|
50
|
-
el.querySelectorAll("
|
145
|
+
el.querySelectorAll(selector("marker")).forEach((el) => {
|
51
146
|
const { latLng } = el.dataset;
|
52
147
|
const { opacity = "1.0" } = el.dataset;
|
53
148
|
const options = { opacity: parseFloat(opacity) };
|
54
|
-
console.log(options);
|
55
149
|
const marker = L.marker(JSON.parse(latLng), options).addTo(map);
|
56
150
|
el.dataset._leafletId = L.stamp(marker); // Save ID for later
|
57
151
|
|
@@ -67,7 +161,7 @@ const render = () => {
|
|
67
161
|
});
|
68
162
|
|
69
163
|
// marker.bindPopup
|
70
|
-
el.querySelectorAll("
|
164
|
+
el.querySelectorAll(selector("popup")).forEach((el) => {
|
71
165
|
const { content } = el.dataset;
|
72
166
|
marker.bindPopup(content);
|
73
167
|
const observer = new MutationObserver(function () {
|
@@ -1,2 +0,0 @@
|
|
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:s,maxZoom:n,name:l}=t.dataset;e[l]=L.tileLayer(r,{maxZoom:n,attribution:s}),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,s={opacity:parseFloat(a)};console.log(s);const n=L.marker(JSON.parse(e),s).addTo(o);t.dataset._leafletId=L.stamp(n);const l=new MutationObserver(function(t){t.forEach(t=>{const{latLng:e}=t.target.dataset;n.setLatLng(JSON.parse(e))})});l.observe(t,{attributes:!0,attributeFilter:["data-lat-lng"]}),t.querySelectorAll("[data-popup]").forEach(t=>{const{content:e}=t.dataset;n.bindPopup(e),new MutationObserver(function(){n.getPopup().setContent(t.dataset.content)}).observe(t,{attributes:!0,attributeFilter:["data-content"]})}),r.push(n)}),a[e]=L.layerGroup(r)}),L.control.layers(e,a).addTo(o)})})};export{t as default};
|
2
|
-
//# sourceMappingURL=leaflet-html.modern.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"leaflet-html.modern.js","sources":["../src/index.js"],"sourcesContent":["const init = () => {\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\nexport default init\n"],"names":["init","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"],"mappings":"AAAM,MAAAA,EAAOA,KAEXC,SAASC,iBAAiB,uBAAuBC,QAASC,IACxD,MAAMC,OAAEA,EAAMC,KAAEA,GAASF,EAAGG,QACtBC,EAAMC,EAAED,IAAIJ,GAAIM,QAAQC,KAAKC,MAAMP,GAASQ,SAASP,IAG3DF,EAAGF,iBAAiB,yBAAyBC,QAASC,IACpD,MAAMU,EAAW,CAAE,EAGnBV,EAAGF,iBAAiB,qBAAqBC,QAASY,IAChD,MAAMC,KAAEA,EAAIC,YAAEA,EAAWC,YAAEA,EAAWC,QAAEA,EAAOC,KAAEA,GAASL,EAAOR,QACjEO,EAASM,GAAQX,EAAEY,UAAUJ,EAAa,CAAEE,UAASD,gBACzC,MAARF,GACFF,EAASM,GAAME,MAAMd,EACvB,GAGF,MAAMe,EAAc,CAAE,EAEtBnB,EAAGF,iBAAiB,sBAAsBC,QAASC,IACjD,MAAMgB,KAAEA,GAAShB,EAAGG,QACdiB,EAAS,GAEE,IAAIC,iBAAiB,SAASC,GAC7C,MAAMC,EAAQJ,EAAYH,GAE1BM,EAAUvB,QAAQyB,IAChBA,EAASC,WAAW1B,QAAQ2B,IAC1B,MAAMC,OAAEA,GAAWD,EAAKvB,QAClByB,EAAQvB,EAAEwB,OAAO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