Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/l-div-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default class CustomElement extends HTMLElement {
if (className !== null) {
options["className"] = className;
}
const iconAnchor = this.getAttribute("icon-anchor");
if (iconAnchor !== null) {
options["iconAnchor"] = iconAnchor;
}

this.icon = divIcon(options);
this.dispatchEvent(
Expand Down
3 changes: 2 additions & 1 deletion src/l-div-icon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import "./index.js";
it("should render a div icon", () => {
const el = document.createElement("l-div-icon");
el.innerHTML = "Hello, World!";
el.setAttribute("icon-anchor","[50, 50]");
document.body.appendChild(el);
expect(el.icon).toBeInstanceOf(DivIcon);
expect(el.icon).toEqual(divIcon({ html: "Hello, World!" }));
expect(el.icon).toEqual(divIcon({ html: "Hello, World!" , iconAnchor: "[50, 50]"}));
});

it("should attach div icon to marker", () => {
Expand Down
4 changes: 4 additions & 0 deletions src/l-geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class LGeoJSON extends HTMLElement {
if (pane !== null) {
options["pane"] = pane.getAttribute("name");
}
const style = this.getAttribute("style");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause problems with native browser styling?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts, https://leafletjs.com/reference.html#path-option, Path options aren't similar enough to native browser style options to force an unintuitive api usage

if (style !== null) {
options["style"] = JSON.parse(style)
}

if (value !== null) {
this.layer = geoJSON(JSON.parse(value), options);
Expand Down
31 changes: 31 additions & 0 deletions src/l-geojson.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @vitest-environment happy-dom
import { geoJson } from "leaflet";
import { it, expect } from "vitest";
import "./index.js";
import { layerConnected } from "./events.js";

it("should render a geoJson object", async () => {
const el = document.createElement("l-geojson");
el.setAttribute("geojson", "[[50, 0], [50, -1], [49, -1], [49,0]]");
el.setAttribute("id", "test-layer");
el.setAttribute("style", '{"color": "#0000ff"}');
let promise = new Promise((resolve) => {
el.addEventListener(layerConnected, (ev) => {
resolve(ev.detail);
});
});
document.body.appendChild(el);
const actual = await promise;
const expected = {
layer: geoJson(
[
[50, 0],
[50, -1],
[49, -1],
[49, 0],
],
{ style: { color: "#0000ff" } },
)
};
expect(actual).toEqual(expected);
});