leaflet-html 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +14 -6
- 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 +1 -1
- package/dist/leaflet-html.modern.js.map +1 -1
- package/dist/leaflet-html.umd.js +1 -1
- package/dist/leaflet-html.umd.js.map +1 -1
- package/docs/content/articles/basic.md +8 -13
- package/docs/content/articles/htmx.md +67 -0
- package/docs/content/articles/icons.md +19 -7
- package/docs/static/htmx/clicked.html +1 -0
- package/docs/static/htmx/tile-esri.html +3 -0
- package/docs/static/htmx/tile-osm.html +4 -0
- package/docs/static/htmx/tile-voyager.html +4 -0
- package/docs/static/style.css +48 -0
- package/docs/templates/base.html +10 -38
- package/docs/templates/shortcodes/url.html +1 -0
- package/example/geojson/index.html +1 -6
- package/example/index.html +1 -6
- package/example/overlays/index.html +1 -6
- package/package.json +1 -1
- 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 +20 -2
- package/src/l-overlay-layers.js +1 -0
- package/src/l-popup.js +1 -0
- package/src/l-tile-layer.js +13 -4
- package/src/l-video-overlay.js +3 -1
@@ -10,15 +10,10 @@
|
|
10
10
|
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
11
11
|
crossorigin=""
|
12
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
13
|
<script type="importmap">
|
19
14
|
{
|
20
15
|
"imports": {
|
21
|
-
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
16
|
+
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js"
|
22
17
|
}
|
23
18
|
}
|
24
19
|
</script>
|
package/example/index.html
CHANGED
@@ -9,15 +9,10 @@
|
|
9
9
|
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
10
10
|
crossorigin=""
|
11
11
|
/>
|
12
|
-
<script
|
13
|
-
src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
14
|
-
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
15
|
-
crossorigin=""
|
16
|
-
></script>
|
17
12
|
<script type="importmap">
|
18
13
|
{
|
19
14
|
"imports": {
|
20
|
-
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
15
|
+
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js"
|
21
16
|
}
|
22
17
|
}
|
23
18
|
</script>
|
@@ -10,15 +10,10 @@
|
|
10
10
|
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
11
11
|
crossorigin=""
|
12
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
13
|
<script type="importmap">
|
19
14
|
{
|
20
15
|
"imports": {
|
21
|
-
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
16
|
+
"leaflet": "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js"
|
22
17
|
}
|
23
18
|
}
|
24
19
|
</script>
|
package/package.json
CHANGED
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,5 +1,7 @@
|
|
1
1
|
// @ts-check
|
2
|
+
import * as L from "leaflet";
|
2
3
|
import { layerRemove, mapAddTo } from "./events.js";
|
4
|
+
import LTileLayer from "./l-tile-layer.js";
|
3
5
|
|
4
6
|
class LMap extends HTMLElement {
|
5
7
|
constructor() {
|
@@ -8,8 +10,22 @@ class LMap extends HTMLElement {
|
|
8
10
|
this.map = null;
|
9
11
|
this.addEventListener("map:bounds", (ev) => {
|
10
12
|
const { bounds, method } = ev.detail;
|
11
|
-
this.map
|
13
|
+
if (this.map !== null) {
|
14
|
+
this.map[method](bounds);
|
15
|
+
}
|
12
16
|
});
|
17
|
+
|
18
|
+
// Observe removed l-tile-layers
|
19
|
+
const observer = new MutationObserver(function(mutations) {
|
20
|
+
mutations.forEach((mutation) => {
|
21
|
+
mutation.removedNodes.forEach((node) => {
|
22
|
+
if (node instanceof LTileLayer) {
|
23
|
+
this.map.removeLayer(node.layer)
|
24
|
+
}
|
25
|
+
})
|
26
|
+
})
|
27
|
+
})
|
28
|
+
observer.observe(this, { childList: true })
|
13
29
|
}
|
14
30
|
|
15
31
|
connectedCallback() {
|
@@ -25,7 +41,9 @@ class LMap extends HTMLElement {
|
|
25
41
|
});
|
26
42
|
|
27
43
|
this.addEventListener(layerRemove, (ev) => {
|
28
|
-
this.map
|
44
|
+
if (this.map !== null) {
|
45
|
+
this.map.removeLayer(ev.detail.layer);
|
46
|
+
}
|
29
47
|
});
|
30
48
|
}
|
31
49
|
}
|
package/src/l-overlay-layers.js
CHANGED
package/src/l-popup.js
CHANGED
package/src/l-tile-layer.js
CHANGED
@@ -1,18 +1,27 @@
|
|
1
|
+
// @ts-check
|
2
|
+
import { tileLayer } from "leaflet";
|
1
3
|
import { mapAddTo } from "./events.js";
|
2
4
|
|
3
5
|
class LTileLayer extends HTMLElement {
|
4
6
|
constructor() {
|
5
7
|
super();
|
8
|
+
this.layer = null
|
6
9
|
}
|
7
10
|
|
8
11
|
connectedCallback() {
|
9
12
|
const name = this.getAttribute("name");
|
10
13
|
const urlTemplate = this.getAttribute("url-template");
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
if (urlTemplate === null) {
|
15
|
+
return;
|
16
|
+
}
|
17
|
+
const options = {};
|
18
|
+
const key = "attribution";
|
19
|
+
if (this.hasAttribute(key)) {
|
20
|
+
options[key] = this.getAttribute(key);
|
21
|
+
}
|
22
|
+
this.layer = tileLayer(urlTemplate, options);
|
14
23
|
const event = new CustomEvent(mapAddTo, {
|
15
|
-
detail: { name, layer },
|
24
|
+
detail: { name, layer: this.layer },
|
16
25
|
bubbles: true,
|
17
26
|
});
|
18
27
|
this.dispatchEvent(event);
|
package/src/l-video-overlay.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
// @ts-check
|
2
|
+
import { videoOverlay } from "leaflet";
|
1
3
|
import { mapAddTo } from "./events.js";
|
2
4
|
|
3
5
|
class LVideoOverlay extends HTMLElement {
|
@@ -15,7 +17,7 @@ class LVideoOverlay extends HTMLElement {
|
|
15
17
|
muted: true,
|
16
18
|
playsInline: true,
|
17
19
|
};
|
18
|
-
const layer =
|
20
|
+
const layer = videoOverlay(url, bounds, options);
|
19
21
|
this.dispatchEvent(
|
20
22
|
new CustomEvent(mapAddTo, {
|
21
23
|
cancelable: true,
|