leaflet-html 0.2.1 → 0.3.0
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.js +1 -1
- package/dist/leaflet-html.js.map +1 -1
- package/dist/leaflet-html.modern.js +2 -0
- package/dist/leaflet-html.modern.js.map +1 -0
- package/dist/leaflet-html.umd.js +1 -1
- package/dist/leaflet-html.umd.js.map +1 -1
- package/docs/content/articles/basic.md +14 -9
- package/docs/content/articles/icons.md +19 -7
- package/docs/static/style.css +45 -0
- package/docs/templates/base.html +16 -37
- package/example/geojson/index.html +7 -5
- package/example/index.html +7 -5
- package/example/overlays/index.html +7 -5
- package/package.json +4 -8
- package/src/l-base-layers.js +1 -0
- package/src/l-control-layers.js +9 -4
- package/src/l-geojson.js +15 -10
- package/src/l-image-overlay.js +12 -2
- package/src/l-lat-lng-bounds.js +1 -0
- package/src/l-layer-group.js +12 -4
- package/src/l-map.js +7 -2
- package/src/l-marker.js +1 -1
- package/src/l-overlay-layers.js +1 -0
- package/src/l-popup.js +1 -0
- package/src/l-tile-layer.js +11 -3
- package/src/l-video-overlay.js +3 -1
- package/dist/leaflet-html.esm.js +0 -2
- package/dist/leaflet-html.esm.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"leaflet-html.umd.js","sources":["../src/events.js","../src/l-base-layers.js","../src/l-control-layers.js","../src/l-layer-group.js","../src/l-map.js","../src/l-marker.js","../src/l-overlay-layers.js","../src/l-popup.js","../src/l-tile-layer.js","../src/l-lat-lng-bounds.js","../src/l-image-overlay.js","../src/l-video-overlay.js","../src/l-geojson.js","../src/l-icon.js","../src/index.js"],"sourcesContent":["export const mapAddTo = \"map:addTo\";\nexport const popupAdd = \"popup:add\";\nexport const layerRemove = \"layer:remove\";\n","import { mapAddTo } from \"./events.js\";\n\nclass LBaseLayers extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n this.addEventListener(mapAddTo, (ev) => {\n ev.detail[\"type\"] = \"base\";\n });\n }\n}\n\nexport default LBaseLayers;\n","import { mapAddTo } from \"./events.js\";\n\nclass LControlLayers extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const base = {};\n const overlay = {};\n const control = L.control.layers(base, overlay);\n\n this.addEventListener(mapAddTo, (ev) => {\n const { type, name, layer } = ev.detail;\n if (type === \"overlay\") {\n control.addOverlay(layer, name);\n } else if (type === \"base\") {\n control.addBaseLayer(layer, name);\n }\n ev.preventDefault();\n });\n\n const event = new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer: control,\n },\n });\n this.dispatchEvent(event);\n }\n}\n\nexport default LControlLayers;\n","import { mapAddTo } from \"./events.js\";\n\nclass LLayerGroup extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const name = this.getAttribute(\"name\");\n const group = L.layerGroup();\n const event = new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer: group,\n name,\n },\n });\n this.dispatchEvent(event);\n\n this.addEventListener(mapAddTo, (ev) => {\n ev.stopPropagation();\n group.addLayer(ev.detail.layer);\n });\n\n const observer = new MutationObserver(function (mutations) {\n mutations.forEach((mutation) => {\n mutation.removedNodes.forEach((node) => {\n const leafletId = node.getAttribute(\"leaflet-id\");\n const layer = group.getLayer(leafletId);\n group.removeLayer(layer);\n });\n });\n });\n observer.observe(this, { childList: true });\n }\n}\n\nexport default LLayerGroup;\n","// @ts-check\nimport { layerRemove, mapAddTo } from \"./events.js\";\n\nclass LMap extends HTMLElement {\n constructor() {\n super();\n\n this.map = null;\n this.addEventListener(\"map:bounds\", (ev) => {\n const { bounds, method } = ev.detail;\n this.map[method](bounds);\n });\n }\n\n connectedCallback() {\n this.map = L.map(this);\n const center = this.getAttribute(\"center\");\n const zoom = this.getAttribute(\"zoom\");\n if (center !== null && zoom !== null) {\n this.map.setView(JSON.parse(center), parseInt(zoom));\n }\n this.addEventListener(mapAddTo, (ev) => {\n const layer = ev.detail.layer;\n layer.addTo(this.map);\n });\n\n this.addEventListener(layerRemove, (ev) => {\n this.map.remove(ev.detail.layer);\n });\n }\n}\n\nexport default LMap;\n","// @vitest-environment happy-dom\nimport * as L from \"leaflet\";\nimport { mapAddTo, popupAdd } from \"./events.js\";\n\nclass LMarker extends HTMLElement {\n static observedAttributes = [\"lat-lng\", \"opacity\", \"icon\"];\n\n constructor() {\n super();\n this.layer = null;\n this.addEventListener(\"icon:add\", (ev) => {\n ev.stopPropagation();\n this.layer.setIcon(ev.detail.icon);\n })\n }\n\n connectedCallback() {\n const latLng = JSON.parse(this.getAttribute(\"lat-lng\"));\n const opacity = parseFloat(this.getAttribute(\"opacity\") || \"1.0\");\n this.layer = L.marker(latLng, { opacity });\n if (this.hasAttribute(\"icon\")) {\n const icon = L.icon(JSON.parse(this.getAttribute(\"icon\")));\n this.layer.setIcon(icon);\n }\n\n this.setAttribute(\"leaflet-id\", L.stamp(this.layer));\n\n this.addEventListener(popupAdd, (ev) => {\n const { content } = ev.detail;\n this.layer.bindPopup(content);\n });\n\n const event = new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer: this.layer,\n },\n });\n this.dispatchEvent(event);\n }\n\n attributeChangedCallback(name, _oldValue, newValue) {\n if (this.layer !== null) {\n if (name === \"lat-lng\") {\n this.layer.setLatLng(JSON.parse(newValue));\n }\n if (name === \"opacity\") {\n this.layer.setOpacity(parseFloat(newValue));\n }\n if (name === \"icon\") {\n this.layer.setIcon(L.icon(JSON.parse(newValue)));\n }\n }\n }\n}\n\nif (import.meta.vitest) {\n const { it, expect, beforeAll } = import.meta.vitest;\n\n beforeAll(() => {\n customElements.define(\"l-marker\", LMarker);\n });\n\n it(\"default icon\", () => {\n const el = document.createElement(\"l-marker\");\n document.body.appendChild(el);\n let actual = el.layer.getIcon();\n let expected = new L.Icon.Default();\n expect(actual).toEqual(expected);\n });\n\n it(\"adds an icon\", () => {\n const el = document.createElement(\"l-marker\");\n // Set attribute before appendChild\n el.setAttribute(\"icon\", JSON.stringify({ iconUrl: \"foo.png\" }));\n document.body.appendChild(el);\n let actual = el.layer.getIcon();\n let expected = L.icon({ iconUrl: \"foo.png\" });\n expect(actual).toEqual(expected);\n });\n\n it(\"changes an icon\", () => {\n const el = document.createElement(\"l-marker\");\n // Set attribute after appendChild\n document.body.appendChild(el);\n el.setAttribute(\"icon\", JSON.stringify({ iconUrl: \"bar.png\" }));\n let actual = el.layer.getIcon();\n let expected = L.icon({ iconUrl: \"bar.png\" });\n expect(actual).toEqual(expected);\n });\n}\n\nexport default LMarker;\n","import { mapAddTo } from \"./events.js\";\n\nclass LOverlayLayers extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n this.addEventListener(mapAddTo, (ev) => {\n ev.detail[\"type\"] = \"overlay\";\n });\n }\n}\n\nexport default LOverlayLayers;\n","import { popupAdd } from \"./events.js\";\n\nclass LPopup extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const content = this.getAttribute(\"content\");\n const event = new CustomEvent(popupAdd, {\n cancelable: true,\n bubbles: true,\n detail: {\n content,\n },\n });\n this.dispatchEvent(event);\n }\n}\n\nexport default LPopup;\n","import { mapAddTo } from \"./events.js\";\n\nclass LTileLayer extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const name = this.getAttribute(\"name\");\n const urlTemplate = this.getAttribute(\"url-template\");\n const attribution = this.getAttribute(\"attribution\");\n const options = { attribution };\n const layer = L.tileLayer(urlTemplate, options);\n const event = new CustomEvent(mapAddTo, {\n detail: { name, layer },\n bubbles: true,\n });\n this.dispatchEvent(event);\n }\n}\n\nexport default LTileLayer;\n","class LLatLngBounds extends HTMLElement {\n static observedAttributes = [\"bounds\"];\n\n constructor() {\n super();\n }\n\n attributeChangedCallback(_name, _oldValue, newValue) {\n const event = new CustomEvent(\"map:bounds\", {\n bubbles: true,\n detail: {\n bounds: JSON.parse(newValue),\n method: this.getAttribute(\"method\") || \"fitBounds\",\n },\n });\n this.dispatchEvent(event);\n }\n}\n\nexport default LLatLngBounds;\n","import { mapAddTo } from \"./events.js\";\n\nclass LImageOverlay extends HTMLElement {\n static observedAttributes = [\"url\", \"bounds\", \"opacity\"];\n\n constructor() {\n super();\n this.layer = null;\n }\n\n connectedCallback() {\n const url = this.getAttribute(\"url\");\n const bounds = JSON.parse(this.getAttribute(\"bounds\"));\n const options = {\n opacity: parseFloat(this.getAttribute(\"opacity\") || \"1.0\"),\n alt: this.getAttribute(\"alt\") || \"\",\n };\n this.layer = L.imageOverlay(url, bounds, options);\n this.dispatchEvent(\n new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer: this.layer,\n },\n }),\n );\n }\n\n attributeChangedCallback(name, _oldValue, newValue) {\n if (this.layer !== null) {\n if (name === \"url\") {\n this.layer.setUrl(newValue);\n } else if (name === \"bounds\") {\n this.layer.setBounds(JSON.parse(newValue));\n } else if (name === \"opacity\") {\n this.layer.setOpacity(parseFloat(newValue));\n }\n }\n }\n}\n\nexport default LImageOverlay;\n","import { mapAddTo } from \"./events.js\";\n\nclass LVideoOverlay extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const url = JSON.parse(this.getAttribute(\"url\"));\n const bounds = JSON.parse(this.getAttribute(\"bounds\"));\n const options = {\n opacity: parseFloat(this.getAttribute(\"opacity\") || \"1.0\"),\n alt: this.getAttribute(\"alt\") || \"\",\n autoplay: true,\n muted: true,\n playsInline: true,\n };\n const layer = L.videoOverlay(url, bounds, options);\n this.dispatchEvent(\n new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer,\n },\n }),\n );\n }\n}\n\nexport default LVideoOverlay;\n","import { mapAddTo } from \"./events.js\";\n\nclass LGeoJSON extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const layer = L.geoJSON(JSON.parse(this.getAttribute(\"geojson\")));\n this.dispatchEvent(\n new CustomEvent(mapAddTo, {\n bubbles: true,\n cancelable: true,\n detail: {\n layer,\n },\n }),\n );\n }\n}\n\nexport default LGeoJSON;\n","// @vitest-environment happy-dom\nimport * as L from \"leaflet\";\n\nconst camelCase = (kebab) => kebab.replace(/-./g, (x) => x[1].toUpperCase());\n\nclass LIcon extends HTMLElement {\n constructor() {\n super();\n this.icon = null;\n }\n\n connectedCallback() {\n const options = {};\n\n // Strings\n let keys = [\n \"icon-url\",\n \"icon-retina-url\",\n \"shadow-url\",\n \"shadow-retina-url\",\n \"class-name\",\n ];\n keys.forEach((key) => {\n if (this.hasAttribute(key)) {\n options[camelCase(key)] = this.getAttribute(key);\n }\n });\n\n // Points\n let points = [\n \"icon-anchor\",\n \"icon-size\",\n \"shadow-anchor\",\n \"shadow-size\",\n \"tooltip-anchor\",\n \"popup-anchor\",\n ];\n points.forEach((key) => {\n if (this.hasAttribute(key)) {\n options[camelCase(key)] = JSON.parse(this.getAttribute(key));\n }\n });\n\n if (this.hasAttribute(\"cross-origin\")) {\n options.crossOrigin = this.getAttribute(\"cross-origin\") === \"true\";\n }\n this.icon = L.icon(options);\n\n const event = new CustomEvent(\"icon:add\", {\n cancelable: true,\n bubbles: true,\n detail: {\n icon: this.icon,\n },\n });\n this.dispatchEvent(event);\n }\n}\n\nif (import.meta.vitest) {\n const { it, expect, beforeAll } = import.meta.vitest;\n\n beforeAll(() => {\n customElements.define(\"l-icon\", LIcon);\n });\n\n it(\"default\", () => {\n const el = document.createElement(\"l-icon\");\n document.body.appendChild(el);\n\n let actual = el.icon;\n let expected = L.icon();\n expect(actual).toEqual(expected);\n });\n\n it(\"emits icon:add event\", async () => {\n const el = document.createElement(\"l-icon\");\n let promise = new Promise((resolve) => {\n el.addEventListener(\"icon:add\", (ev) => {\n resolve(ev.detail.icon);\n });\n });\n document.body.appendChild(el);\n let actual = await promise;\n let expected = L.icon();\n expect(actual).toEqual(expected);\n });\n\n it(\"options\", () => {\n const el = document.createElement(\"l-icon\");\n el.setAttribute(\"icon-url\", \"url.png\");\n el.setAttribute(\"icon-retina-url\", \"retina.png\");\n el.setAttribute(\"icon-size\", \"[0, 0]\");\n el.setAttribute(\"icon-anchor\", \"[0, 0]\");\n el.setAttribute(\"popup-anchor\", \"[0, 0]\");\n el.setAttribute(\"tooltip-anchor\", \"[0, 0]\");\n el.setAttribute(\"shadow-url\", \"urlShadow.png\");\n el.setAttribute(\"shadow-retina-url\", \"retinaShadow.png\");\n el.setAttribute(\"shadow-size\", \"[0, 0]\");\n el.setAttribute(\"shadow-anchor\", \"[0, 0]\");\n el.setAttribute(\"class-name\", \"foo\");\n el.setAttribute(\"cross-origin\", \"true\");\n document.body.appendChild(el);\n\n let actual = el.icon;\n let expected = L.icon({\n iconUrl: \"url.png\",\n iconRetinaUrl: \"retina.png\",\n iconSize: [0, 0],\n iconAnchor: [0, 0],\n popupAnchor: [0, 0],\n tooltipAnchor: [0, 0],\n shadowUrl: \"urlShadow.png\",\n shadowRetinaUrl: \"retinaShadow.png\",\n shadowSize: [0, 0],\n shadowAnchor: [0, 0],\n className: \"foo\",\n crossOrigin: true,\n });\n expect(actual).toEqual(expected);\n });\n}\n\nexport default LIcon;\n","// @ts-check\nimport LBaseLayers from \"./l-base-layers.js\";\nimport LControlLayers from \"./l-control-layers.js\";\nimport LLayerGroup from \"./l-layer-group.js\";\nimport LMap from \"./l-map.js\";\nimport LMarker from \"./l-marker.js\";\nimport LOverlayLayers from \"./l-overlay-layers.js\";\nimport LPopup from \"./l-popup.js\";\nimport LTileLayer from \"./l-tile-layer.js\";\nimport LLatLngBounds from \"./l-lat-lng-bounds.js\";\nimport LImageOverlay from \"./l-image-overlay.js\";\nimport LVideoOverlay from \"./l-video-overlay.js\";\nimport LGeoJSON from \"./l-geojson.js\";\nimport LIcon from \"./l-icon.js\";\n\nconst init = (() => {\n // Custom elements (order of definition is important)\n customElements.define(\"l-map\", LMap);\n customElements.define(\"l-control-layers\", LControlLayers);\n customElements.define(\"l-base-layers\", LBaseLayers);\n customElements.define(\"l-overlay-layers\", LOverlayLayers);\n customElements.define(\"l-layer-group\", LLayerGroup);\n customElements.define(\"l-tile-layer\", LTileLayer);\n customElements.define(\"l-marker\", LMarker);\n customElements.define(\"l-popup\", LPopup);\n customElements.define(\"l-lat-lng-bounds\", LLatLngBounds);\n customElements.define(\"l-image-overlay\", LImageOverlay);\n customElements.define(\"l-video-overlay\", LVideoOverlay);\n customElements.define(\"l-geojson\", LGeoJSON);\n customElements.define(\"l-icon\", LIcon);\n})();\n\nexport default init;\n"],"names":["mapAddTo","popupAdd","LBaseLayers","_HTMLElement","call","this","_inheritsLoose","prototype","connectedCallback","addEventListener","ev","detail","_wrapNativeSuper","HTMLElement","LControlLayers","control","L","layers","_ev$detail","type","name","layer","addOverlay","addBaseLayer","preventDefault","event","CustomEvent","cancelable","bubbles","dispatchEvent","LLayerGroup","getAttribute","group","layerGroup","stopPropagation","addLayer","MutationObserver","mutations","forEach","mutation","removedNodes","node","leafletId","getLayer","removeLayer","observe","childList","LMap","_this","map","method","bounds","_this2","center","zoom","setView","JSON","parse","parseInt","addTo","remove","LMarker","setIcon","icon","_proto","latLng","opacity","parseFloat","marker","hasAttribute","setAttribute","stamp","bindPopup","content","attributeChangedCallback","_oldValue","newValue","setLatLng","setOpacity","observedAttributes","LOverlayLayers","LPopup","LTileLayer","urlTemplate","attribution","tileLayer","LLatLngBounds","_name","LImageOverlay","url","options","alt","imageOverlay","setUrl","setBounds","LVideoOverlay","autoplay","muted","playsInline","videoOverlay","LGeoJSON","geoJSON","camelCase","kebab","replace","x","toUpperCase","LIcon","key","crossOrigin","customElements","define"],"mappings":"guDAAaA,EAAW,YACXC,EAAW,YCClBC,eAAWC,SAAAA,GACf,SAAAD,IAAc,OACZC,EAAAC,KAAAC,OAAOA,IACT,CAMC,OANAC,EAAAJ,EAAAC,GAAAD,EAAAK,UAEDC,kBAAA,WACEH,KAAKI,iBAAiBT,EAAU,SAACU,GAC/BA,EAAGC,OAAa,KAAI,MACtB,EACF,EAACT,CAAA,CATcC,cASdS,EAT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AAO,QAAShE,GAC/B+D,eAAeC,OAAO,mBAAoBjG,GAC1CgG,eAAeC,OAAO,gBAAiB7G,GACvC4G,eAAeC,OAAO,mBAAoB/B,GAC1C8B,eAAeC,OAAO,gBAAiBjF,GACvCgF,eAAeC,OAAO,eAAgB7B,GACtC4B,eAAeC,OAAO,WAAYlD,GAClCiD,eAAeC,OAAO,UAAW9B,GACjC6B,eAAeC,OAAO,mBAAoBzB,GAC1CwB,eAAeC,OAAO,kBAAmBvB,GACzCsB,eAAeC,OAAO,kBAAmBhB,GACzCe,eAAeC,OAAO,YAAaX,QACnCU,eAAeC,OAAO,SAAUJ"}
|
1
|
+
{"version":3,"file":"leaflet-html.umd.js","sources":["../src/events.js","../src/l-base-layers.js","../src/l-control-layers.js","../src/l-layer-group.js","../src/l-map.js","../src/l-marker.js","../src/l-overlay-layers.js","../src/l-popup.js","../src/l-tile-layer.js","../src/l-lat-lng-bounds.js","../src/l-image-overlay.js","../src/l-video-overlay.js","../src/l-geojson.js","../src/l-icon.js","../src/index.js"],"sourcesContent":["export const mapAddTo = \"map:addTo\";\nexport const popupAdd = \"popup:add\";\nexport const layerRemove = \"layer:remove\";\n","// @ts-check\nimport { mapAddTo } from \"./events.js\";\n\nclass LBaseLayers extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n this.addEventListener(mapAddTo, (ev) => {\n ev.detail[\"type\"] = \"base\";\n });\n }\n}\n\nexport default LBaseLayers;\n","// @ts-check\n/** @typedef {import(\"leaflet\").Layer} Layer */\nimport { control } from \"leaflet\";\nimport { mapAddTo } from \"./events.js\";\n\nclass LControlLayers extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n /** @type {{ [key: string]: Layer }} */\n const base = {};\n /** @type {{ [key: string]: Layer }} */\n const overlay = {};\n const controlLayers = control.layers(base, overlay);\n\n this.addEventListener(mapAddTo, (ev) => {\n const { type, name, layer } = ev.detail;\n if (type === \"overlay\") {\n controlLayers.addOverlay(layer, name);\n } else if (type === \"base\") {\n controlLayers.addBaseLayer(layer, name);\n }\n ev.preventDefault();\n });\n\n const event = new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer: controlLayers,\n },\n });\n this.dispatchEvent(event);\n }\n}\n\nexport default LControlLayers;\n","// @ts-check\nimport { layerGroup } from \"leaflet\";\nimport { mapAddTo } from \"./events.js\";\n\nclass LLayerGroup extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const name = this.getAttribute(\"name\");\n const group = layerGroup();\n const event = new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer: group,\n name,\n },\n });\n this.dispatchEvent(event);\n\n this.addEventListener(mapAddTo, (ev) => {\n ev.stopPropagation();\n group.addLayer(ev.detail.layer);\n });\n\n const observer = new MutationObserver(function (mutations) {\n mutations.forEach((mutation) => {\n mutation.removedNodes.forEach((node) => {\n if (node instanceof HTMLElement) {\n const leafletId = node.getAttribute(\"leaflet-id\");\n if (leafletId !== null) {\n const layer = group.getLayer(parseInt(leafletId));\n if (typeof layer !== \"undefined\") {\n group.removeLayer(layer);\n }\n }\n }\n });\n });\n });\n observer.observe(this, { childList: true });\n }\n}\n\nexport default LLayerGroup;\n","// @ts-check\nimport * as L from \"leaflet\";\nimport { layerRemove, mapAddTo } from \"./events.js\";\n\nclass LMap extends HTMLElement {\n constructor() {\n super();\n\n this.map = null;\n this.addEventListener(\"map:bounds\", (ev) => {\n const { bounds, method } = ev.detail;\n if (this.map !== null) {\n this.map[method](bounds);\n }\n });\n }\n\n connectedCallback() {\n this.map = L.map(this);\n const center = this.getAttribute(\"center\");\n const zoom = this.getAttribute(\"zoom\");\n if (center !== null && zoom !== null) {\n this.map.setView(JSON.parse(center), parseInt(zoom));\n }\n this.addEventListener(mapAddTo, (ev) => {\n const layer = ev.detail.layer;\n layer.addTo(this.map);\n });\n\n this.addEventListener(layerRemove, (ev) => {\n if (this.map !== null) {\n this.map.removeLayer(ev.detail.layer);\n }\n });\n }\n}\n\nexport default LMap;\n","// @vitest-environment happy-dom\nimport * as L from \"leaflet\";\nimport { mapAddTo, popupAdd } from \"./events.js\";\n\nclass LMarker extends HTMLElement {\n static observedAttributes = [\"lat-lng\", \"opacity\", \"icon\"];\n\n constructor() {\n super();\n this.layer = null;\n this.addEventListener(\"icon:add\", (ev) => {\n ev.stopPropagation();\n this.layer.setIcon(ev.detail.icon);\n });\n }\n\n connectedCallback() {\n const latLng = JSON.parse(this.getAttribute(\"lat-lng\"));\n const opacity = parseFloat(this.getAttribute(\"opacity\") || \"1.0\");\n this.layer = L.marker(latLng, { opacity });\n if (this.hasAttribute(\"icon\")) {\n const icon = L.icon(JSON.parse(this.getAttribute(\"icon\")));\n this.layer.setIcon(icon);\n }\n\n this.setAttribute(\"leaflet-id\", L.stamp(this.layer));\n\n this.addEventListener(popupAdd, (ev) => {\n const { content } = ev.detail;\n this.layer.bindPopup(content);\n });\n\n const event = new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer: this.layer,\n },\n });\n this.dispatchEvent(event);\n }\n\n attributeChangedCallback(name, _oldValue, newValue) {\n if (this.layer !== null) {\n if (name === \"lat-lng\") {\n this.layer.setLatLng(JSON.parse(newValue));\n }\n if (name === \"opacity\") {\n this.layer.setOpacity(parseFloat(newValue));\n }\n if (name === \"icon\") {\n this.layer.setIcon(L.icon(JSON.parse(newValue)));\n }\n }\n }\n}\n\nif (import.meta.vitest) {\n const { it, expect, beforeAll } = import.meta.vitest;\n\n beforeAll(() => {\n customElements.define(\"l-marker\", LMarker);\n });\n\n it(\"default icon\", () => {\n const el = document.createElement(\"l-marker\");\n document.body.appendChild(el);\n let actual = el.layer.getIcon();\n let expected = new L.Icon.Default();\n expect(actual).toEqual(expected);\n });\n\n it(\"adds an icon\", () => {\n const el = document.createElement(\"l-marker\");\n // Set attribute before appendChild\n el.setAttribute(\"icon\", JSON.stringify({ iconUrl: \"foo.png\" }));\n document.body.appendChild(el);\n let actual = el.layer.getIcon();\n let expected = L.icon({ iconUrl: \"foo.png\" });\n expect(actual).toEqual(expected);\n });\n\n it(\"changes an icon\", () => {\n const el = document.createElement(\"l-marker\");\n // Set attribute after appendChild\n document.body.appendChild(el);\n el.setAttribute(\"icon\", JSON.stringify({ iconUrl: \"bar.png\" }));\n let actual = el.layer.getIcon();\n let expected = L.icon({ iconUrl: \"bar.png\" });\n expect(actual).toEqual(expected);\n });\n}\n\nexport default LMarker;\n","// @ts-check\nimport { mapAddTo } from \"./events.js\";\n\nclass LOverlayLayers extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n this.addEventListener(mapAddTo, (ev) => {\n ev.detail[\"type\"] = \"overlay\";\n });\n }\n}\n\nexport default LOverlayLayers;\n","// @ts-check\nimport { popupAdd } from \"./events.js\";\n\nclass LPopup extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const content = this.getAttribute(\"content\");\n const event = new CustomEvent(popupAdd, {\n cancelable: true,\n bubbles: true,\n detail: {\n content,\n },\n });\n this.dispatchEvent(event);\n }\n}\n\nexport default LPopup;\n","// @ts-check\nimport { tileLayer } from \"leaflet\";\nimport { mapAddTo } from \"./events.js\";\n\nclass LTileLayer extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const name = this.getAttribute(\"name\");\n const urlTemplate = this.getAttribute(\"url-template\");\n if (urlTemplate === null) {\n return;\n }\n const options = {};\n const key = \"attribution\";\n if (this.hasAttribute(key)) {\n options[key] = this.getAttribute(key);\n }\n const layer = tileLayer(urlTemplate, options);\n const event = new CustomEvent(mapAddTo, {\n detail: { name, layer },\n bubbles: true,\n });\n this.dispatchEvent(event);\n }\n}\n\nexport default LTileLayer;\n","// @ts-check\nclass LLatLngBounds extends HTMLElement {\n static observedAttributes = [\"bounds\"];\n\n constructor() {\n super();\n }\n\n attributeChangedCallback(_name, _oldValue, newValue) {\n const event = new CustomEvent(\"map:bounds\", {\n bubbles: true,\n detail: {\n bounds: JSON.parse(newValue),\n method: this.getAttribute(\"method\") || \"fitBounds\",\n },\n });\n this.dispatchEvent(event);\n }\n}\n\nexport default LLatLngBounds;\n","// @ts-check\nimport { imageOverlay } from \"leaflet\";\nimport { mapAddTo } from \"./events.js\";\n\nclass LImageOverlay extends HTMLElement {\n static observedAttributes = [\"url\", \"bounds\", \"opacity\"];\n\n constructor() {\n super();\n this.layer = null;\n }\n\n connectedCallback() {\n const url = this.getAttribute(\"url\");\n if (url === null) {\n console.warn(\"attribute 'url' not set\");\n return;\n }\n let bounds = this.getAttribute(\"bounds\");\n if (bounds === null) {\n console.warn(\"attribute 'bounds' not set\");\n return;\n }\n const options = {\n opacity: parseFloat(this.getAttribute(\"opacity\") || \"1.0\"),\n alt: this.getAttribute(\"alt\") || \"\",\n };\n this.layer = imageOverlay(url, JSON.parse(bounds), options);\n this.dispatchEvent(\n new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer: this.layer,\n },\n }),\n );\n }\n\n attributeChangedCallback(name, _oldValue, newValue) {\n if (this.layer !== null) {\n if (name === \"url\") {\n this.layer.setUrl(newValue);\n } else if (name === \"bounds\") {\n this.layer.setBounds(JSON.parse(newValue));\n } else if (name === \"opacity\") {\n this.layer.setOpacity(parseFloat(newValue));\n }\n }\n }\n}\n\nexport default LImageOverlay;\n","// @ts-check\nimport { videoOverlay } from \"leaflet\";\nimport { mapAddTo } from \"./events.js\";\n\nclass LVideoOverlay extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const url = JSON.parse(this.getAttribute(\"url\"));\n const bounds = JSON.parse(this.getAttribute(\"bounds\"));\n const options = {\n opacity: parseFloat(this.getAttribute(\"opacity\") || \"1.0\"),\n alt: this.getAttribute(\"alt\") || \"\",\n autoplay: true,\n muted: true,\n playsInline: true,\n };\n const layer = videoOverlay(url, bounds, options);\n this.dispatchEvent(\n new CustomEvent(mapAddTo, {\n cancelable: true,\n bubbles: true,\n detail: {\n layer,\n },\n }),\n );\n }\n}\n\nexport default LVideoOverlay;\n","// @ts-check\nimport { geoJSON } from \"leaflet\";\nimport { mapAddTo } from \"./events.js\";\n\nclass LGeoJSON extends HTMLElement {\n constructor() {\n super();\n }\n\n connectedCallback() {\n const value = this.getAttribute(\"geojson\");\n if (value !== null) {\n const layer = geoJSON(JSON.parse(value));\n this.dispatchEvent(\n new CustomEvent(mapAddTo, {\n bubbles: true,\n cancelable: true,\n detail: {\n layer,\n },\n }),\n );\n }\n }\n}\n\nexport default LGeoJSON;\n","// @vitest-environment happy-dom\nimport * as L from \"leaflet\";\n\nconst camelCase = (kebab) => kebab.replace(/-./g, (x) => x[1].toUpperCase());\n\nclass LIcon extends HTMLElement {\n constructor() {\n super();\n this.icon = null;\n }\n\n connectedCallback() {\n const options = {};\n\n // Strings\n let keys = [\n \"icon-url\",\n \"icon-retina-url\",\n \"shadow-url\",\n \"shadow-retina-url\",\n \"class-name\",\n ];\n keys.forEach((key) => {\n if (this.hasAttribute(key)) {\n options[camelCase(key)] = this.getAttribute(key);\n }\n });\n\n // Points\n let points = [\n \"icon-anchor\",\n \"icon-size\",\n \"shadow-anchor\",\n \"shadow-size\",\n \"tooltip-anchor\",\n \"popup-anchor\",\n ];\n points.forEach((key) => {\n if (this.hasAttribute(key)) {\n options[camelCase(key)] = JSON.parse(this.getAttribute(key));\n }\n });\n\n if (this.hasAttribute(\"cross-origin\")) {\n options.crossOrigin = this.getAttribute(\"cross-origin\") === \"true\";\n }\n this.icon = L.icon(options);\n\n const event = new CustomEvent(\"icon:add\", {\n cancelable: true,\n bubbles: true,\n detail: {\n icon: this.icon,\n },\n });\n this.dispatchEvent(event);\n }\n}\n\nif (import.meta.vitest) {\n const { it, expect, beforeAll } = import.meta.vitest;\n\n beforeAll(() => {\n customElements.define(\"l-icon\", LIcon);\n });\n\n it(\"default\", () => {\n const el = document.createElement(\"l-icon\");\n document.body.appendChild(el);\n\n let actual = el.icon;\n let expected = L.icon();\n expect(actual).toEqual(expected);\n });\n\n it(\"emits icon:add event\", async () => {\n const el = document.createElement(\"l-icon\");\n let promise = new Promise((resolve) => {\n el.addEventListener(\"icon:add\", (ev) => {\n resolve(ev.detail.icon);\n });\n });\n document.body.appendChild(el);\n let actual = await promise;\n let expected = L.icon();\n expect(actual).toEqual(expected);\n });\n\n it(\"options\", () => {\n const el = document.createElement(\"l-icon\");\n el.setAttribute(\"icon-url\", \"url.png\");\n el.setAttribute(\"icon-retina-url\", \"retina.png\");\n el.setAttribute(\"icon-size\", \"[0, 0]\");\n el.setAttribute(\"icon-anchor\", \"[0, 0]\");\n el.setAttribute(\"popup-anchor\", \"[0, 0]\");\n el.setAttribute(\"tooltip-anchor\", \"[0, 0]\");\n el.setAttribute(\"shadow-url\", \"urlShadow.png\");\n el.setAttribute(\"shadow-retina-url\", \"retinaShadow.png\");\n el.setAttribute(\"shadow-size\", \"[0, 0]\");\n el.setAttribute(\"shadow-anchor\", \"[0, 0]\");\n el.setAttribute(\"class-name\", \"foo\");\n el.setAttribute(\"cross-origin\", \"true\");\n document.body.appendChild(el);\n\n let actual = el.icon;\n let expected = L.icon({\n iconUrl: \"url.png\",\n iconRetinaUrl: \"retina.png\",\n iconSize: [0, 0],\n iconAnchor: [0, 0],\n popupAnchor: [0, 0],\n tooltipAnchor: [0, 0],\n shadowUrl: \"urlShadow.png\",\n shadowRetinaUrl: \"retinaShadow.png\",\n shadowSize: [0, 0],\n shadowAnchor: [0, 0],\n className: \"foo\",\n crossOrigin: true,\n });\n expect(actual).toEqual(expected);\n });\n}\n\nexport default LIcon;\n","// @ts-check\nimport LBaseLayers from \"./l-base-layers.js\";\nimport LControlLayers from \"./l-control-layers.js\";\nimport LLayerGroup from \"./l-layer-group.js\";\nimport LMap from \"./l-map.js\";\nimport LMarker from \"./l-marker.js\";\nimport LOverlayLayers from \"./l-overlay-layers.js\";\nimport LPopup from \"./l-popup.js\";\nimport LTileLayer from \"./l-tile-layer.js\";\nimport LLatLngBounds from \"./l-lat-lng-bounds.js\";\nimport LImageOverlay from \"./l-image-overlay.js\";\nimport LVideoOverlay from \"./l-video-overlay.js\";\nimport LGeoJSON from \"./l-geojson.js\";\nimport LIcon from \"./l-icon.js\";\n\nconst init = (() => {\n // Custom elements (order of definition is important)\n customElements.define(\"l-map\", LMap);\n customElements.define(\"l-control-layers\", LControlLayers);\n customElements.define(\"l-base-layers\", LBaseLayers);\n customElements.define(\"l-overlay-layers\", LOverlayLayers);\n customElements.define(\"l-layer-group\", LLayerGroup);\n customElements.define(\"l-tile-layer\", LTileLayer);\n customElements.define(\"l-marker\", LMarker);\n customElements.define(\"l-popup\", LPopup);\n customElements.define(\"l-lat-lng-bounds\", LLatLngBounds);\n customElements.define(\"l-image-overlay\", LImageOverlay);\n customElements.define(\"l-video-overlay\", LVideoOverlay);\n customElements.define(\"l-geojson\", LGeoJSON);\n customElements.define(\"l-icon\", LIcon);\n})();\n\nexport default init;\n"],"names":["mapAddTo","popupAdd","LBaseLayers","_HTMLElement","call","this","_inheritsLoose","prototype","connectedCallback","addEventListener","ev","detail","_wrapNativeSuper","HTMLElement","LControlLayers","controlLayers","control","layers","_ev$detail","type","name","layer","addOverlay","addBaseLayer","preventDefault","event","CustomEvent","cancelable","bubbles","dispatchEvent","LLayerGroup","getAttribute","group","layerGroup","stopPropagation","addLayer","MutationObserver","mutations","forEach","mutation","removedNodes","node","leafletId","getLayer","parseInt","removeLayer","observe","childList","LMap","_this","map","method","bounds","_this2","L","center","zoom","setView","JSON","parse","addTo","LMarker","setIcon","icon","_proto","latLng","opacity","parseFloat","marker","hasAttribute","setAttribute","stamp","bindPopup","content","attributeChangedCallback","_oldValue","newValue","setLatLng","setOpacity","observedAttributes","LOverlayLayers","LPopup","LTileLayer","urlTemplate","options","key","tileLayer","LLatLngBounds","_name","LImageOverlay","url","alt","imageOverlay","console","warn","setUrl","setBounds","LVideoOverlay","autoplay","muted","playsInline","videoOverlay","LGeoJSON","value","geoJSON","camelCase","kebab","replace","x","toUpperCase","LIcon","crossOrigin","customElements","define"],"mappings":"guDAAa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-
src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
51
|
-
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
52
|
-
crossorigin=""
|
53
|
-
></script>
|
54
49
|
...
|
55
50
|
</head>
|
56
51
|
```
|
@@ -61,10 +56,20 @@ Leaflet-HTML is available via **npm** and **unpkg**.
|
|
61
56
|
To get started quickly, use the CDN version available on **unpkg**.
|
62
57
|
|
63
58
|
```html
|
64
|
-
<script
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
<script type="importmap">
|
60
|
+
{
|
61
|
+
"imports": {
|
62
|
+
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
|
63
|
+
"leaflet-html": "https://unpkg.com/leaflet-html@latest/dist/leaflet-html.js"
|
64
|
+
}
|
65
|
+
}
|
66
|
+
</script>
|
67
|
+
```
|
68
|
+
|
69
|
+
```html
|
70
|
+
<script type="module">
|
71
|
+
import "leaflet-html";
|
72
|
+
</script>
|
68
73
|
```
|
69
74
|
|
70
75
|
The `@latest` keyword should keep your site up to date during development.
|
@@ -17,9 +17,15 @@ This is a more HTML centered approach.
|
|
17
17
|
The above JSON approach may be suitable in cases where the icon data is available in a data structure.
|
18
18
|
|
19
19
|
```html
|
20
|
-
<l-marker lat-lng="[51.5, -0.09]"
|
21
|
-
|
22
|
-
|
20
|
+
<l-marker lat-lng="[51.5, -0.09]"><l-icon
|
21
|
+
icon-url="/icons/leaf-green.png"
|
22
|
+
shadow-url="/icons/leaf-shadow.png"
|
23
|
+
icon-size="[38, 95]"
|
24
|
+
shadow-size="[50, 64]"
|
25
|
+
icon-anchor="[22, 94]"
|
26
|
+
shadow-anchor="[4, 62]"
|
27
|
+
popup-anchor="[-3, -76]"
|
28
|
+
></l-icon>
|
23
29
|
```
|
24
30
|
|
25
31
|
Both are supported, choose whichever is most convenient.
|
@@ -28,8 +34,14 @@ Both are supported, choose whichever is most convenient.
|
|
28
34
|
<l-tile-layer
|
29
35
|
url-template="https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png"
|
30
36
|
></l-tile-layer>
|
31
|
-
<l-marker
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
<l-marker lat-lng="[51.5, -0.09]"><l-icon
|
38
|
+
icon-url="/leaflet-html/icons/leaf-green.png"
|
39
|
+
shadow-url="/leaflet-html/icons/leaf-shadow.png"
|
40
|
+
icon-size="[38, 95]"
|
41
|
+
shadow-size="[50, 64]"
|
42
|
+
icon-anchor="[22, 94]"
|
43
|
+
shadow-anchor="[4, 62]"
|
44
|
+
popup-anchor="[-3, -76]"
|
45
|
+
></l-icon>
|
46
|
+
</l-marker>
|
35
47
|
</l-map>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
@import "https://unpkg.com/open-props";
|
2
|
+
|
3
|
+
l-map {
|
4
|
+
display: block;
|
5
|
+
block-size: 40ch;
|
6
|
+
isolation: isolate;
|
7
|
+
z-index: 1;
|
8
|
+
}
|
9
|
+
|
10
|
+
body {
|
11
|
+
font-family: system-ui;
|
12
|
+
line-height: 1.6;
|
13
|
+
margin: 0;
|
14
|
+
min-height: 100vh;
|
15
|
+
}
|
16
|
+
|
17
|
+
h1, h2, h3 {
|
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: auto;
|
26
|
+
}
|
27
|
+
|
28
|
+
main {
|
29
|
+
inline-size: min(90%, 80ch);
|
30
|
+
margin-inline: auto;
|
31
|
+
}
|
32
|
+
|
33
|
+
footer {
|
34
|
+
margin-block-start: auto;
|
35
|
+
min-height: 15ch;
|
36
|
+
background-color: var(--gray-9);
|
37
|
+
padding: var(--size-3);
|
38
|
+
|
39
|
+
& .logo {
|
40
|
+
color: var(--gray-2);
|
41
|
+
font-size: var(--font-size-0);
|
42
|
+
letter-spacing: var(--font-letterspacing-5);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
package/docs/templates/base.html
CHANGED
@@ -4,50 +4,26 @@
|
|
4
4
|
<meta charset="utf-8" />
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
6
6
|
<style>
|
7
|
-
|
8
|
-
l-map {
|
9
|
-
display: block;
|
10
|
-
block-size: 40ch;
|
11
|
-
isolation: isolate;
|
12
|
-
z-index: 1;
|
13
|
-
}
|
14
|
-
|
15
|
-
body {
|
16
|
-
font-family: system-ui;
|
17
|
-
line-height: 1.6;
|
18
|
-
}
|
19
|
-
|
20
|
-
h1, h2, h3 {
|
21
|
-
font-weight: 100;
|
22
|
-
}
|
23
|
-
|
24
|
-
pre {
|
25
|
-
padding-inline: 0.75rem;
|
26
|
-
padding-block: 0.5rem;
|
27
|
-
border-radius: 0.2rem;
|
28
|
-
overflow-x: auto;
|
29
|
-
}
|
30
|
-
|
31
|
-
main {
|
32
|
-
inline-size: min(90%, 80ch);
|
33
|
-
margin-inline: auto;
|
34
|
-
}
|
35
7
|
</style>
|
8
|
+
<link rel="stylesheet" href="/style.css" />
|
9
|
+
<link rel="stylesheet" href="/leaflet-html/style.css" />
|
36
10
|
<link
|
37
11
|
rel="stylesheet"
|
38
12
|
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
39
13
|
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
40
14
|
crossorigin=""
|
41
15
|
/>
|
42
|
-
<script
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
16
|
+
<script type="importmap">
|
17
|
+
{
|
18
|
+
"imports": {
|
19
|
+
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js",
|
20
|
+
"leaflet-html": "https://unpkg.com/leaflet-html@latest/dist/leaflet-html.js"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
</script>
|
24
|
+
<script type="module">
|
25
|
+
import "leaflet-html";
|
26
|
+
</script>
|
51
27
|
</head>
|
52
28
|
<body>
|
53
29
|
<nav>
|
@@ -55,5 +31,8 @@
|
|
55
31
|
<a href="{{ get_url(path='@/articles/_index.md') }}">Articles</a>
|
56
32
|
</nav>
|
57
33
|
{% block content %}{% endblock %}
|
34
|
+
<footer>
|
35
|
+
<div class="logo">Leaflet-HTML</div>
|
36
|
+
</footer>
|
58
37
|
</body>
|
59
38
|
</html>
|
@@ -10,11 +10,13 @@
|
|
10
10
|
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
11
11
|
crossorigin=""
|
12
12
|
/>
|
13
|
-
<script
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
<script type="importmap">
|
14
|
+
{
|
15
|
+
"imports": {
|
16
|
+
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
</script>
|
18
20
|
<script type="module" src="/src/index.js"></script>
|
19
21
|
<style>
|
20
22
|
* {
|
package/example/index.html
CHANGED
@@ -9,11 +9,13 @@
|
|
9
9
|
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
10
10
|
crossorigin=""
|
11
11
|
/>
|
12
|
-
<script
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
<script type="importmap">
|
13
|
+
{
|
14
|
+
"imports": {
|
15
|
+
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
</script>
|
17
19
|
<script
|
18
20
|
src="/src/index.js"
|
19
21
|
type="module"
|
@@ -10,11 +10,13 @@
|
|
10
10
|
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
11
11
|
crossorigin=""
|
12
12
|
/>
|
13
|
-
<script
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
<script type="importmap">
|
14
|
+
{
|
15
|
+
"imports": {
|
16
|
+
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
</script>
|
18
20
|
<script type="module" src="/src/index.js"></script>
|
19
21
|
<style>
|
20
22
|
* {
|
package/package.json
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "leaflet-html",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.3.0",
|
5
5
|
"description": "Leaflet expressed in HTML",
|
6
6
|
"source": "src/index.js",
|
7
|
-
"main": "./dist/leaflet-html.
|
8
|
-
"
|
9
|
-
"exports": {
|
10
|
-
"module": "./dist/leaflet-html.js"
|
11
|
-
},
|
12
|
-
"module": "./dist/leaflet-html.esm.js",
|
7
|
+
"main": "./dist/leaflet-html.cjs",
|
8
|
+
"module": "./dist/leaflet-html.js",
|
13
9
|
"author": "andrewgryan",
|
14
10
|
"repository": {
|
15
11
|
"type": "git",
|
@@ -17,7 +13,7 @@
|
|
17
13
|
},
|
18
14
|
"license": "MIT",
|
19
15
|
"scripts": {
|
20
|
-
"build": "microbundle
|
16
|
+
"build": "microbundle",
|
21
17
|
"watch": "microbundle watch",
|
22
18
|
"test": "vitest"
|
23
19
|
},
|
package/src/l-base-layers.js
CHANGED
package/src/l-control-layers.js
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
// @ts-check
|
2
|
+
/** @typedef {import("leaflet").Layer} Layer */
|
3
|
+
import { control } from "leaflet";
|
1
4
|
import { mapAddTo } from "./events.js";
|
2
5
|
|
3
6
|
class LControlLayers extends HTMLElement {
|
@@ -6,16 +9,18 @@ class LControlLayers extends HTMLElement {
|
|
6
9
|
}
|
7
10
|
|
8
11
|
connectedCallback() {
|
12
|
+
/** @type {{ [key: string]: Layer }} */
|
9
13
|
const base = {};
|
14
|
+
/** @type {{ [key: string]: Layer }} */
|
10
15
|
const overlay = {};
|
11
|
-
const
|
16
|
+
const controlLayers = control.layers(base, overlay);
|
12
17
|
|
13
18
|
this.addEventListener(mapAddTo, (ev) => {
|
14
19
|
const { type, name, layer } = ev.detail;
|
15
20
|
if (type === "overlay") {
|
16
|
-
|
21
|
+
controlLayers.addOverlay(layer, name);
|
17
22
|
} else if (type === "base") {
|
18
|
-
|
23
|
+
controlLayers.addBaseLayer(layer, name);
|
19
24
|
}
|
20
25
|
ev.preventDefault();
|
21
26
|
});
|
@@ -24,7 +29,7 @@ class LControlLayers extends HTMLElement {
|
|
24
29
|
cancelable: true,
|
25
30
|
bubbles: true,
|
26
31
|
detail: {
|
27
|
-
layer:
|
32
|
+
layer: controlLayers,
|
28
33
|
},
|
29
34
|
});
|
30
35
|
this.dispatchEvent(event);
|
package/src/l-geojson.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
// @ts-check
|
2
|
+
import { geoJSON } from "leaflet";
|
1
3
|
import { mapAddTo } from "./events.js";
|
2
4
|
|
3
5
|
class LGeoJSON extends HTMLElement {
|
@@ -6,16 +8,19 @@ class LGeoJSON extends HTMLElement {
|
|
6
8
|
}
|
7
9
|
|
8
10
|
connectedCallback() {
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
const value = this.getAttribute("geojson");
|
12
|
+
if (value !== null) {
|
13
|
+
const layer = geoJSON(JSON.parse(value));
|
14
|
+
this.dispatchEvent(
|
15
|
+
new CustomEvent(mapAddTo, {
|
16
|
+
bubbles: true,
|
17
|
+
cancelable: true,
|
18
|
+
detail: {
|
19
|
+
layer,
|
20
|
+
},
|
21
|
+
}),
|
22
|
+
);
|
23
|
+
}
|
19
24
|
}
|
20
25
|
}
|
21
26
|
|
package/src/l-image-overlay.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
// @ts-check
|
2
|
+
import { imageOverlay } from "leaflet";
|
1
3
|
import { mapAddTo } from "./events.js";
|
2
4
|
|
3
5
|
class LImageOverlay extends HTMLElement {
|
@@ -10,12 +12,20 @@ class LImageOverlay extends HTMLElement {
|
|
10
12
|
|
11
13
|
connectedCallback() {
|
12
14
|
const url = this.getAttribute("url");
|
13
|
-
|
15
|
+
if (url === null) {
|
16
|
+
console.warn("attribute 'url' not set");
|
17
|
+
return;
|
18
|
+
}
|
19
|
+
let bounds = this.getAttribute("bounds");
|
20
|
+
if (bounds === null) {
|
21
|
+
console.warn("attribute 'bounds' not set");
|
22
|
+
return;
|
23
|
+
}
|
14
24
|
const options = {
|
15
25
|
opacity: parseFloat(this.getAttribute("opacity") || "1.0"),
|
16
26
|
alt: this.getAttribute("alt") || "",
|
17
27
|
};
|
18
|
-
this.layer =
|
28
|
+
this.layer = imageOverlay(url, JSON.parse(bounds), options);
|
19
29
|
this.dispatchEvent(
|
20
30
|
new CustomEvent(mapAddTo, {
|
21
31
|
cancelable: true,
|
package/src/l-lat-lng-bounds.js
CHANGED
package/src/l-layer-group.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
// @ts-check
|
2
|
+
import { layerGroup } from "leaflet";
|
1
3
|
import { mapAddTo } from "./events.js";
|
2
4
|
|
3
5
|
class LLayerGroup extends HTMLElement {
|
@@ -7,7 +9,7 @@ class LLayerGroup extends HTMLElement {
|
|
7
9
|
|
8
10
|
connectedCallback() {
|
9
11
|
const name = this.getAttribute("name");
|
10
|
-
const group =
|
12
|
+
const group = layerGroup();
|
11
13
|
const event = new CustomEvent(mapAddTo, {
|
12
14
|
cancelable: true,
|
13
15
|
bubbles: true,
|
@@ -26,9 +28,15 @@ class LLayerGroup extends HTMLElement {
|
|
26
28
|
const observer = new MutationObserver(function (mutations) {
|
27
29
|
mutations.forEach((mutation) => {
|
28
30
|
mutation.removedNodes.forEach((node) => {
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
if (node instanceof HTMLElement) {
|
32
|
+
const leafletId = node.getAttribute("leaflet-id");
|
33
|
+
if (leafletId !== null) {
|
34
|
+
const layer = group.getLayer(parseInt(leafletId));
|
35
|
+
if (typeof layer !== "undefined") {
|
36
|
+
group.removeLayer(layer);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
32
40
|
});
|
33
41
|
});
|
34
42
|
});
|
package/src/l-map.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
// @ts-check
|
2
|
+
import * as L from "leaflet";
|
2
3
|
import { layerRemove, mapAddTo } from "./events.js";
|
3
4
|
|
4
5
|
class LMap extends HTMLElement {
|
@@ -8,7 +9,9 @@ class LMap extends HTMLElement {
|
|
8
9
|
this.map = null;
|
9
10
|
this.addEventListener("map:bounds", (ev) => {
|
10
11
|
const { bounds, method } = ev.detail;
|
11
|
-
this.map
|
12
|
+
if (this.map !== null) {
|
13
|
+
this.map[method](bounds);
|
14
|
+
}
|
12
15
|
});
|
13
16
|
}
|
14
17
|
|
@@ -25,7 +28,9 @@ class LMap extends HTMLElement {
|
|
25
28
|
});
|
26
29
|
|
27
30
|
this.addEventListener(layerRemove, (ev) => {
|
28
|
-
this.map
|
31
|
+
if (this.map !== null) {
|
32
|
+
this.map.removeLayer(ev.detail.layer);
|
33
|
+
}
|
29
34
|
});
|
30
35
|
}
|
31
36
|
}
|
package/src/l-marker.js
CHANGED
package/src/l-overlay-layers.js
CHANGED
package/src/l-popup.js
CHANGED
package/src/l-tile-layer.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
// @ts-check
|
2
|
+
import { tileLayer } from "leaflet";
|
1
3
|
import { mapAddTo } from "./events.js";
|
2
4
|
|
3
5
|
class LTileLayer extends HTMLElement {
|
@@ -8,9 +10,15 @@ class LTileLayer extends HTMLElement {
|
|
8
10
|
connectedCallback() {
|
9
11
|
const name = this.getAttribute("name");
|
10
12
|
const urlTemplate = this.getAttribute("url-template");
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
if (urlTemplate === null) {
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
const options = {};
|
17
|
+
const key = "attribution";
|
18
|
+
if (this.hasAttribute(key)) {
|
19
|
+
options[key] = this.getAttribute(key);
|
20
|
+
}
|
21
|
+
const layer = tileLayer(urlTemplate, options);
|
14
22
|
const event = new CustomEvent(mapAddTo, {
|
15
23
|
detail: { name, layer },
|
16
24
|
bubbles: true,
|