leaflet-html 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-publish.yml +27 -27
- package/.prettierignore +2 -0
- package/.prettierrc +1 -0
- package/README.md +2 -2
- 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/_index.md +7 -2
- package/docs/content/articles/_index.md +5 -0
- package/docs/content/articles/basic.md +115 -0
- package/docs/content/articles/icons.md +35 -0
- package/docs/content/articles/style.md +14 -0
- package/docs/public/icons/leaf-green.png +0 -0
- package/docs/public/icons/leaf-orange.png +0 -0
- package/docs/public/icons/leaf-red.png +0 -0
- package/docs/public/icons/leaf-shadow.png +0 -0
- package/docs/static/icons/leaf-green.png +0 -0
- package/docs/static/icons/leaf-orange.png +0 -0
- package/docs/static/icons/leaf-red.png +0 -0
- package/docs/static/icons/leaf-shadow.png +0 -0
- package/docs/templates/article-page.html +8 -0
- package/docs/templates/article.html +12 -0
- package/docs/templates/base.html +66 -0
- package/docs/templates/index.html +5 -56
- package/example/geojson/index.html +7 -0
- package/example/index.html +7 -0
- package/example/overlays/index.html +7 -0
- package/package.json +12 -9
- package/src/events.js +3 -3
- package/src/index.js +19 -18
- package/src/l-base-layers.js +6 -7
- package/src/l-control-layers.js +17 -17
- package/src/l-geojson.js +13 -11
- package/src/l-icon.js +124 -0
- package/src/l-image-overlay.js +22 -20
- package/src/l-lat-lng-bounds.js +7 -7
- package/src/l-layer-group.js +15 -15
- package/src/l-map.js +17 -17
- package/src/l-marker.js +67 -18
- package/src/l-overlay-layers.js +6 -6
- package/src/l-popup.js +8 -10
- package/src/l-tile-layer.js +13 -10
- package/src/l-video-overlay.js +17 -16
- package/vite.config.js +7 -0
- package/dist/leaflet-html.esm.js +0 -2
- package/dist/leaflet-html.esm.js.map +0 -1
package/src/l-control-layers.js
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
import { mapAddTo } from "./events.js"
|
1
|
+
import { mapAddTo } from "./events.js";
|
2
2
|
|
3
3
|
class LControlLayers extends HTMLElement {
|
4
4
|
constructor() {
|
5
|
-
super()
|
5
|
+
super();
|
6
6
|
}
|
7
|
-
|
7
|
+
|
8
8
|
connectedCallback() {
|
9
|
-
const base = {}
|
10
|
-
const overlay = {}
|
11
|
-
const control = L.control.layers(base, overlay)
|
9
|
+
const base = {};
|
10
|
+
const overlay = {};
|
11
|
+
const control = L.control.layers(base, overlay);
|
12
12
|
|
13
13
|
this.addEventListener(mapAddTo, (ev) => {
|
14
|
-
const { type, name, layer } = ev.detail
|
14
|
+
const { type, name, layer } = ev.detail;
|
15
15
|
if (type === "overlay") {
|
16
|
-
control.addOverlay(layer, name)
|
16
|
+
control.addOverlay(layer, name);
|
17
17
|
} else if (type === "base") {
|
18
|
-
control.addBaseLayer(layer, name)
|
18
|
+
control.addBaseLayer(layer, name);
|
19
19
|
}
|
20
|
-
ev.preventDefault()
|
21
|
-
})
|
22
|
-
|
20
|
+
ev.preventDefault();
|
21
|
+
});
|
22
|
+
|
23
23
|
const event = new CustomEvent(mapAddTo, {
|
24
24
|
cancelable: true,
|
25
25
|
bubbles: true,
|
26
26
|
detail: {
|
27
|
-
layer: control
|
28
|
-
}
|
29
|
-
})
|
30
|
-
this.dispatchEvent(event)
|
27
|
+
layer: control,
|
28
|
+
},
|
29
|
+
});
|
30
|
+
this.dispatchEvent(event);
|
31
31
|
}
|
32
32
|
}
|
33
33
|
|
34
|
-
export default LControlLayers
|
34
|
+
export default LControlLayers;
|
package/src/l-geojson.js
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
import { mapAddTo } from "./events.js"
|
1
|
+
import { mapAddTo } from "./events.js";
|
2
2
|
|
3
3
|
class LGeoJSON extends HTMLElement {
|
4
4
|
constructor() {
|
5
|
-
super()
|
5
|
+
super();
|
6
6
|
}
|
7
7
|
|
8
8
|
connectedCallback() {
|
9
|
-
const layer = L.geoJSON(JSON.parse(this.getAttribute("geojson")))
|
10
|
-
this.dispatchEvent(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
const layer = L.geoJSON(JSON.parse(this.getAttribute("geojson")));
|
10
|
+
this.dispatchEvent(
|
11
|
+
new CustomEvent(mapAddTo, {
|
12
|
+
bubbles: true,
|
13
|
+
cancelable: true,
|
14
|
+
detail: {
|
15
|
+
layer,
|
16
|
+
},
|
17
|
+
}),
|
18
|
+
);
|
17
19
|
}
|
18
20
|
}
|
19
21
|
|
20
|
-
export default LGeoJSON
|
22
|
+
export default LGeoJSON;
|
package/src/l-icon.js
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
// @vitest-environment happy-dom
|
2
|
+
import * as L from "leaflet";
|
3
|
+
|
4
|
+
const camelCase = (kebab) => kebab.replace(/-./g, (x) => x[1].toUpperCase());
|
5
|
+
|
6
|
+
class LIcon extends HTMLElement {
|
7
|
+
constructor() {
|
8
|
+
super();
|
9
|
+
this.icon = null;
|
10
|
+
}
|
11
|
+
|
12
|
+
connectedCallback() {
|
13
|
+
const options = {};
|
14
|
+
|
15
|
+
// Strings
|
16
|
+
let keys = [
|
17
|
+
"icon-url",
|
18
|
+
"icon-retina-url",
|
19
|
+
"shadow-url",
|
20
|
+
"shadow-retina-url",
|
21
|
+
"class-name",
|
22
|
+
];
|
23
|
+
keys.forEach((key) => {
|
24
|
+
if (this.hasAttribute(key)) {
|
25
|
+
options[camelCase(key)] = this.getAttribute(key);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
29
|
+
// Points
|
30
|
+
let points = [
|
31
|
+
"icon-anchor",
|
32
|
+
"icon-size",
|
33
|
+
"shadow-anchor",
|
34
|
+
"shadow-size",
|
35
|
+
"tooltip-anchor",
|
36
|
+
"popup-anchor",
|
37
|
+
];
|
38
|
+
points.forEach((key) => {
|
39
|
+
if (this.hasAttribute(key)) {
|
40
|
+
options[camelCase(key)] = JSON.parse(this.getAttribute(key));
|
41
|
+
}
|
42
|
+
});
|
43
|
+
|
44
|
+
if (this.hasAttribute("cross-origin")) {
|
45
|
+
options.crossOrigin = this.getAttribute("cross-origin") === "true";
|
46
|
+
}
|
47
|
+
this.icon = L.icon(options);
|
48
|
+
|
49
|
+
const event = new CustomEvent("icon:add", {
|
50
|
+
cancelable: true,
|
51
|
+
bubbles: true,
|
52
|
+
detail: {
|
53
|
+
icon: this.icon,
|
54
|
+
},
|
55
|
+
});
|
56
|
+
this.dispatchEvent(event);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
if (import.meta.vitest) {
|
61
|
+
const { it, expect, beforeAll } = import.meta.vitest;
|
62
|
+
|
63
|
+
beforeAll(() => {
|
64
|
+
customElements.define("l-icon", LIcon);
|
65
|
+
});
|
66
|
+
|
67
|
+
it("default", () => {
|
68
|
+
const el = document.createElement("l-icon");
|
69
|
+
document.body.appendChild(el);
|
70
|
+
|
71
|
+
let actual = el.icon;
|
72
|
+
let expected = L.icon();
|
73
|
+
expect(actual).toEqual(expected);
|
74
|
+
});
|
75
|
+
|
76
|
+
it("emits icon:add event", async () => {
|
77
|
+
const el = document.createElement("l-icon");
|
78
|
+
let promise = new Promise((resolve) => {
|
79
|
+
el.addEventListener("icon:add", (ev) => {
|
80
|
+
resolve(ev.detail.icon);
|
81
|
+
});
|
82
|
+
});
|
83
|
+
document.body.appendChild(el);
|
84
|
+
let actual = await promise;
|
85
|
+
let expected = L.icon();
|
86
|
+
expect(actual).toEqual(expected);
|
87
|
+
});
|
88
|
+
|
89
|
+
it("options", () => {
|
90
|
+
const el = document.createElement("l-icon");
|
91
|
+
el.setAttribute("icon-url", "url.png");
|
92
|
+
el.setAttribute("icon-retina-url", "retina.png");
|
93
|
+
el.setAttribute("icon-size", "[0, 0]");
|
94
|
+
el.setAttribute("icon-anchor", "[0, 0]");
|
95
|
+
el.setAttribute("popup-anchor", "[0, 0]");
|
96
|
+
el.setAttribute("tooltip-anchor", "[0, 0]");
|
97
|
+
el.setAttribute("shadow-url", "urlShadow.png");
|
98
|
+
el.setAttribute("shadow-retina-url", "retinaShadow.png");
|
99
|
+
el.setAttribute("shadow-size", "[0, 0]");
|
100
|
+
el.setAttribute("shadow-anchor", "[0, 0]");
|
101
|
+
el.setAttribute("class-name", "foo");
|
102
|
+
el.setAttribute("cross-origin", "true");
|
103
|
+
document.body.appendChild(el);
|
104
|
+
|
105
|
+
let actual = el.icon;
|
106
|
+
let expected = L.icon({
|
107
|
+
iconUrl: "url.png",
|
108
|
+
iconRetinaUrl: "retina.png",
|
109
|
+
iconSize: [0, 0],
|
110
|
+
iconAnchor: [0, 0],
|
111
|
+
popupAnchor: [0, 0],
|
112
|
+
tooltipAnchor: [0, 0],
|
113
|
+
shadowUrl: "urlShadow.png",
|
114
|
+
shadowRetinaUrl: "retinaShadow.png",
|
115
|
+
shadowSize: [0, 0],
|
116
|
+
shadowAnchor: [0, 0],
|
117
|
+
className: "foo",
|
118
|
+
crossOrigin: true,
|
119
|
+
});
|
120
|
+
expect(actual).toEqual(expected);
|
121
|
+
});
|
122
|
+
}
|
123
|
+
|
124
|
+
export default LIcon;
|
package/src/l-image-overlay.js
CHANGED
@@ -1,41 +1,43 @@
|
|
1
|
-
import { mapAddTo } from "./events.js"
|
1
|
+
import { mapAddTo } from "./events.js";
|
2
2
|
|
3
3
|
class LImageOverlay extends HTMLElement {
|
4
|
-
static observedAttributes = ["url", "bounds", "opacity"]
|
4
|
+
static observedAttributes = ["url", "bounds", "opacity"];
|
5
5
|
|
6
6
|
constructor() {
|
7
|
-
super()
|
8
|
-
this.layer = null
|
7
|
+
super();
|
8
|
+
this.layer = null;
|
9
9
|
}
|
10
10
|
|
11
11
|
connectedCallback() {
|
12
|
-
const url = this.getAttribute("url")
|
13
|
-
const bounds = JSON.parse(this.getAttribute("bounds"))
|
12
|
+
const url = this.getAttribute("url");
|
13
|
+
const bounds = JSON.parse(this.getAttribute("bounds"));
|
14
14
|
const options = {
|
15
15
|
opacity: parseFloat(this.getAttribute("opacity") || "1.0"),
|
16
|
-
alt: this.getAttribute("alt") || ""
|
17
|
-
}
|
18
|
-
this.layer = L.imageOverlay(url, bounds, options)
|
19
|
-
this.dispatchEvent(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
alt: this.getAttribute("alt") || "",
|
17
|
+
};
|
18
|
+
this.layer = L.imageOverlay(url, bounds, options);
|
19
|
+
this.dispatchEvent(
|
20
|
+
new CustomEvent(mapAddTo, {
|
21
|
+
cancelable: true,
|
22
|
+
bubbles: true,
|
23
|
+
detail: {
|
24
|
+
layer: this.layer,
|
25
|
+
},
|
26
|
+
}),
|
27
|
+
);
|
26
28
|
}
|
27
29
|
|
28
30
|
attributeChangedCallback(name, _oldValue, newValue) {
|
29
31
|
if (this.layer !== null) {
|
30
32
|
if (name === "url") {
|
31
|
-
this.layer.setUrl(newValue)
|
33
|
+
this.layer.setUrl(newValue);
|
32
34
|
} else if (name === "bounds") {
|
33
|
-
this.layer.setBounds(JSON.parse(newValue))
|
35
|
+
this.layer.setBounds(JSON.parse(newValue));
|
34
36
|
} else if (name === "opacity") {
|
35
|
-
this.layer.setOpacity(parseFloat(newValue))
|
37
|
+
this.layer.setOpacity(parseFloat(newValue));
|
36
38
|
}
|
37
39
|
}
|
38
40
|
}
|
39
41
|
}
|
40
42
|
|
41
|
-
export default LImageOverlay
|
43
|
+
export default LImageOverlay;
|
package/src/l-lat-lng-bounds.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class LLatLngBounds extends HTMLElement {
|
2
|
-
static observedAttributes = ["bounds"]
|
2
|
+
static observedAttributes = ["bounds"];
|
3
3
|
|
4
4
|
constructor() {
|
5
|
-
super()
|
5
|
+
super();
|
6
6
|
}
|
7
7
|
|
8
8
|
attributeChangedCallback(_name, _oldValue, newValue) {
|
@@ -10,11 +10,11 @@ class LLatLngBounds extends HTMLElement {
|
|
10
10
|
bubbles: true,
|
11
11
|
detail: {
|
12
12
|
bounds: JSON.parse(newValue),
|
13
|
-
method: this.getAttribute("method") || "fitBounds"
|
14
|
-
}
|
15
|
-
})
|
16
|
-
this.dispatchEvent(event)
|
13
|
+
method: this.getAttribute("method") || "fitBounds",
|
14
|
+
},
|
15
|
+
});
|
16
|
+
this.dispatchEvent(event);
|
17
17
|
}
|
18
18
|
}
|
19
19
|
|
20
|
-
export default LLatLngBounds
|
20
|
+
export default LLatLngBounds;
|
package/src/l-layer-group.js
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
import { mapAddTo } from "./events.js"
|
1
|
+
import { mapAddTo } from "./events.js";
|
2
2
|
|
3
3
|
class LLayerGroup extends HTMLElement {
|
4
4
|
constructor() {
|
5
|
-
super()
|
5
|
+
super();
|
6
6
|
}
|
7
|
-
|
7
|
+
|
8
8
|
connectedCallback() {
|
9
|
-
const name = this.getAttribute("name")
|
10
|
-
const group = L.layerGroup()
|
9
|
+
const name = this.getAttribute("name");
|
10
|
+
const group = L.layerGroup();
|
11
11
|
const event = new CustomEvent(mapAddTo, {
|
12
12
|
cancelable: true,
|
13
13
|
bubbles: true,
|
14
14
|
detail: {
|
15
15
|
layer: group,
|
16
|
-
name
|
17
|
-
}
|
18
|
-
})
|
19
|
-
this.dispatchEvent(event)
|
16
|
+
name,
|
17
|
+
},
|
18
|
+
});
|
19
|
+
this.dispatchEvent(event);
|
20
20
|
|
21
21
|
this.addEventListener(mapAddTo, (ev) => {
|
22
|
-
ev.stopPropagation()
|
23
|
-
group.addLayer(ev.detail.layer)
|
24
|
-
})
|
22
|
+
ev.stopPropagation();
|
23
|
+
group.addLayer(ev.detail.layer);
|
24
|
+
});
|
25
25
|
|
26
|
-
const observer = new MutationObserver(function(mutations) {
|
26
|
+
const observer = new MutationObserver(function (mutations) {
|
27
27
|
mutations.forEach((mutation) => {
|
28
28
|
mutation.removedNodes.forEach((node) => {
|
29
29
|
const leafletId = node.getAttribute("leaflet-id");
|
@@ -32,8 +32,8 @@ class LLayerGroup extends HTMLElement {
|
|
32
32
|
});
|
33
33
|
});
|
34
34
|
});
|
35
|
-
observer.observe(this, { childList: true })
|
35
|
+
observer.observe(this, { childList: true });
|
36
36
|
}
|
37
37
|
}
|
38
38
|
|
39
|
-
export default LLayerGroup
|
39
|
+
export default LLayerGroup;
|
package/src/l-map.js
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
// @ts-check
|
2
|
-
import { layerRemove, mapAddTo } from "./events.js"
|
2
|
+
import { layerRemove, mapAddTo } from "./events.js";
|
3
3
|
|
4
4
|
class LMap extends HTMLElement {
|
5
5
|
constructor() {
|
6
|
-
super()
|
6
|
+
super();
|
7
7
|
|
8
|
-
this.map = null
|
8
|
+
this.map = null;
|
9
9
|
this.addEventListener("map:bounds", (ev) => {
|
10
|
-
const { bounds, method } = ev.detail
|
11
|
-
this.map[method](bounds)
|
12
|
-
})
|
10
|
+
const { bounds, method } = ev.detail;
|
11
|
+
this.map[method](bounds);
|
12
|
+
});
|
13
13
|
}
|
14
14
|
|
15
15
|
connectedCallback() {
|
16
|
-
this.map = L.map(this)
|
17
|
-
const center = this.getAttribute("center")
|
18
|
-
const zoom = this.getAttribute("zoom")
|
19
|
-
if (
|
20
|
-
this.map.setView(JSON.parse(center), parseInt(zoom))
|
16
|
+
this.map = L.map(this);
|
17
|
+
const center = this.getAttribute("center");
|
18
|
+
const zoom = this.getAttribute("zoom");
|
19
|
+
if (center !== null && zoom !== null) {
|
20
|
+
this.map.setView(JSON.parse(center), parseInt(zoom));
|
21
21
|
}
|
22
22
|
this.addEventListener(mapAddTo, (ev) => {
|
23
|
-
const layer = ev.detail.layer
|
24
|
-
layer.addTo(this.map)
|
25
|
-
})
|
23
|
+
const layer = ev.detail.layer;
|
24
|
+
layer.addTo(this.map);
|
25
|
+
});
|
26
26
|
|
27
27
|
this.addEventListener(layerRemove, (ev) => {
|
28
|
-
this.map.remove(ev.detail.layer)
|
29
|
-
})
|
28
|
+
this.map.remove(ev.detail.layer);
|
29
|
+
});
|
30
30
|
}
|
31
31
|
}
|
32
32
|
|
33
|
-
export default LMap
|
33
|
+
export default LMap;
|
package/src/l-marker.js
CHANGED
@@ -1,45 +1,94 @@
|
|
1
|
-
|
1
|
+
// @vitest-environment happy-dom
|
2
|
+
import * as L from "leaflet";
|
3
|
+
import { mapAddTo, popupAdd } from "./events.js";
|
2
4
|
|
3
5
|
class LMarker extends HTMLElement {
|
4
|
-
static observedAttributes = ["lat-lng", "opacity"]
|
6
|
+
static observedAttributes = ["lat-lng", "opacity", "icon"];
|
5
7
|
|
6
8
|
constructor() {
|
7
|
-
super()
|
8
|
-
this.layer = null
|
9
|
+
super();
|
10
|
+
this.layer = null;
|
11
|
+
this.addEventListener("icon:add", (ev) => {
|
12
|
+
ev.stopPropagation();
|
13
|
+
this.layer.setIcon(ev.detail.icon);
|
14
|
+
});
|
9
15
|
}
|
10
16
|
|
11
17
|
connectedCallback() {
|
12
|
-
const latLng = JSON.parse(this.getAttribute("lat-lng"))
|
13
|
-
const opacity = parseFloat(this.getAttribute("opacity") || "1.0")
|
18
|
+
const latLng = JSON.parse(this.getAttribute("lat-lng"));
|
19
|
+
const opacity = parseFloat(this.getAttribute("opacity") || "1.0");
|
14
20
|
this.layer = L.marker(latLng, { opacity });
|
15
|
-
this.
|
21
|
+
if (this.hasAttribute("icon")) {
|
22
|
+
const icon = L.icon(JSON.parse(this.getAttribute("icon")));
|
23
|
+
this.layer.setIcon(icon);
|
24
|
+
}
|
25
|
+
|
26
|
+
this.setAttribute("leaflet-id", L.stamp(this.layer));
|
16
27
|
|
17
28
|
this.addEventListener(popupAdd, (ev) => {
|
18
|
-
const { content } = ev.detail
|
19
|
-
this.layer.bindPopup(content)
|
20
|
-
})
|
21
|
-
|
29
|
+
const { content } = ev.detail;
|
30
|
+
this.layer.bindPopup(content);
|
31
|
+
});
|
32
|
+
|
22
33
|
const event = new CustomEvent(mapAddTo, {
|
23
34
|
cancelable: true,
|
24
35
|
bubbles: true,
|
25
36
|
detail: {
|
26
|
-
layer: this.layer
|
27
|
-
}
|
28
|
-
})
|
29
|
-
this.dispatchEvent(event)
|
37
|
+
layer: this.layer,
|
38
|
+
},
|
39
|
+
});
|
40
|
+
this.dispatchEvent(event);
|
30
41
|
}
|
31
42
|
|
32
43
|
attributeChangedCallback(name, _oldValue, newValue) {
|
33
44
|
if (this.layer !== null) {
|
34
45
|
if (name === "lat-lng") {
|
35
|
-
this.layer.setLatLng(JSON.parse(newValue))
|
46
|
+
this.layer.setLatLng(JSON.parse(newValue));
|
36
47
|
}
|
37
48
|
if (name === "opacity") {
|
38
|
-
this.layer.setOpacity(parseFloat(newValue))
|
49
|
+
this.layer.setOpacity(parseFloat(newValue));
|
50
|
+
}
|
51
|
+
if (name === "icon") {
|
52
|
+
this.layer.setIcon(L.icon(JSON.parse(newValue)));
|
39
53
|
}
|
40
54
|
}
|
41
55
|
}
|
42
56
|
}
|
43
57
|
|
58
|
+
if (import.meta.vitest) {
|
59
|
+
const { it, expect, beforeAll } = import.meta.vitest;
|
60
|
+
|
61
|
+
beforeAll(() => {
|
62
|
+
customElements.define("l-marker", LMarker);
|
63
|
+
});
|
64
|
+
|
65
|
+
it("default icon", () => {
|
66
|
+
const el = document.createElement("l-marker");
|
67
|
+
document.body.appendChild(el);
|
68
|
+
let actual = el.layer.getIcon();
|
69
|
+
let expected = new L.Icon.Default();
|
70
|
+
expect(actual).toEqual(expected);
|
71
|
+
});
|
72
|
+
|
73
|
+
it("adds an icon", () => {
|
74
|
+
const el = document.createElement("l-marker");
|
75
|
+
// Set attribute before appendChild
|
76
|
+
el.setAttribute("icon", JSON.stringify({ iconUrl: "foo.png" }));
|
77
|
+
document.body.appendChild(el);
|
78
|
+
let actual = el.layer.getIcon();
|
79
|
+
let expected = L.icon({ iconUrl: "foo.png" });
|
80
|
+
expect(actual).toEqual(expected);
|
81
|
+
});
|
82
|
+
|
83
|
+
it("changes an icon", () => {
|
84
|
+
const el = document.createElement("l-marker");
|
85
|
+
// Set attribute after appendChild
|
86
|
+
document.body.appendChild(el);
|
87
|
+
el.setAttribute("icon", JSON.stringify({ iconUrl: "bar.png" }));
|
88
|
+
let actual = el.layer.getIcon();
|
89
|
+
let expected = L.icon({ iconUrl: "bar.png" });
|
90
|
+
expect(actual).toEqual(expected);
|
91
|
+
});
|
92
|
+
}
|
44
93
|
|
45
|
-
export default LMarker
|
94
|
+
export default LMarker;
|
package/src/l-overlay-layers.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
import { mapAddTo } from "./events.js"
|
1
|
+
import { mapAddTo } from "./events.js";
|
2
2
|
|
3
3
|
class LOverlayLayers extends HTMLElement {
|
4
4
|
constructor() {
|
5
|
-
super()
|
5
|
+
super();
|
6
6
|
}
|
7
|
-
|
7
|
+
|
8
8
|
connectedCallback() {
|
9
9
|
this.addEventListener(mapAddTo, (ev) => {
|
10
|
-
ev.detail["type"] = "overlay"
|
11
|
-
})
|
10
|
+
ev.detail["type"] = "overlay";
|
11
|
+
});
|
12
12
|
}
|
13
13
|
}
|
14
14
|
|
15
|
-
export default LOverlayLayers
|
15
|
+
export default LOverlayLayers;
|
package/src/l-popup.js
CHANGED
@@ -1,23 +1,21 @@
|
|
1
|
-
import { popupAdd } from "./events.js"
|
1
|
+
import { popupAdd } from "./events.js";
|
2
2
|
|
3
3
|
class LPopup extends HTMLElement {
|
4
4
|
constructor() {
|
5
|
-
super()
|
5
|
+
super();
|
6
6
|
}
|
7
7
|
|
8
8
|
connectedCallback() {
|
9
|
-
const content = this.getAttribute("content")
|
9
|
+
const content = this.getAttribute("content");
|
10
10
|
const event = new CustomEvent(popupAdd, {
|
11
11
|
cancelable: true,
|
12
12
|
bubbles: true,
|
13
13
|
detail: {
|
14
|
-
content
|
15
|
-
}
|
16
|
-
})
|
17
|
-
this.dispatchEvent(event)
|
14
|
+
content,
|
15
|
+
},
|
16
|
+
});
|
17
|
+
this.dispatchEvent(event);
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|
21
|
-
|
22
|
-
export default LPopup
|
23
|
-
|
21
|
+
export default LPopup;
|
package/src/l-tile-layer.js
CHANGED
@@ -1,19 +1,22 @@
|
|
1
|
-
import { mapAddTo } from "./events.js"
|
1
|
+
import { mapAddTo } from "./events.js";
|
2
2
|
|
3
3
|
class LTileLayer extends HTMLElement {
|
4
4
|
constructor() {
|
5
|
-
super()
|
5
|
+
super();
|
6
6
|
}
|
7
7
|
|
8
8
|
connectedCallback() {
|
9
|
-
const name = this.getAttribute("name")
|
10
|
-
const urlTemplate = this.getAttribute("url-template")
|
11
|
-
const attribution = this.getAttribute("attribution")
|
12
|
-
const options = { attribution }
|
13
|
-
const layer = L.tileLayer(urlTemplate, options)
|
14
|
-
const event = new CustomEvent(mapAddTo, {
|
15
|
-
|
9
|
+
const name = this.getAttribute("name");
|
10
|
+
const urlTemplate = this.getAttribute("url-template");
|
11
|
+
const attribution = this.getAttribute("attribution");
|
12
|
+
const options = { attribution };
|
13
|
+
const layer = L.tileLayer(urlTemplate, options);
|
14
|
+
const event = new CustomEvent(mapAddTo, {
|
15
|
+
detail: { name, layer },
|
16
|
+
bubbles: true,
|
17
|
+
});
|
18
|
+
this.dispatchEvent(event);
|
16
19
|
}
|
17
20
|
}
|
18
21
|
|
19
|
-
export default LTileLayer
|
22
|
+
export default LTileLayer;
|
package/src/l-video-overlay.js
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
-
import { mapAddTo } from "./events.js"
|
1
|
+
import { mapAddTo } from "./events.js";
|
2
2
|
|
3
3
|
class LVideoOverlay extends HTMLElement {
|
4
4
|
constructor() {
|
5
|
-
super()
|
5
|
+
super();
|
6
6
|
}
|
7
7
|
|
8
8
|
connectedCallback() {
|
9
|
-
const url = JSON.parse(this.getAttribute("url"))
|
10
|
-
const bounds = JSON.parse(this.getAttribute("bounds"))
|
9
|
+
const url = JSON.parse(this.getAttribute("url"));
|
10
|
+
const bounds = JSON.parse(this.getAttribute("bounds"));
|
11
11
|
const options = {
|
12
12
|
opacity: parseFloat(this.getAttribute("opacity") || "1.0"),
|
13
13
|
alt: this.getAttribute("alt") || "",
|
14
14
|
autoplay: true,
|
15
15
|
muted: true,
|
16
|
-
playsInline: true
|
17
|
-
}
|
18
|
-
const layer = L.videoOverlay(url, bounds, options)
|
19
|
-
this.dispatchEvent(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
playsInline: true,
|
17
|
+
};
|
18
|
+
const layer = L.videoOverlay(url, bounds, options);
|
19
|
+
this.dispatchEvent(
|
20
|
+
new CustomEvent(mapAddTo, {
|
21
|
+
cancelable: true,
|
22
|
+
bubbles: true,
|
23
|
+
detail: {
|
24
|
+
layer,
|
25
|
+
},
|
26
|
+
}),
|
27
|
+
);
|
26
28
|
}
|
27
29
|
}
|
28
30
|
|
29
|
-
export default LVideoOverlay
|
30
|
-
|
31
|
+
export default LVideoOverlay;
|