diff --git a/package.json b/package.json index ecf44f0..5dc0d03 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "leaflet-html", "type": "module", - "version": "0.13.10", + "version": "0.13.11", "description": "Leaflet maps expressed in HTML suitable for HTMX", "keywords": [ "leaflet", diff --git a/src/l-div-icon.js b/src/l-div-icon.js index d234314..c0937ab 100644 --- a/src/l-div-icon.js +++ b/src/l-div-icon.js @@ -18,7 +18,11 @@ export default class CustomElement extends HTMLElement { } const iconAnchor = this.getAttribute("icon-anchor"); if (iconAnchor !== null) { - options["iconAnchor"] = iconAnchor; + options["iconAnchor"] = JSON.parse(iconAnchor); + } + const iconSize = this.getAttribute("icon-size"); + if (iconSize != null) { + options["iconSize"] = JSON.parse(iconSize); } this.icon = divIcon(options); diff --git a/src/l-div-icon.test.js b/src/l-div-icon.test.js index 53c8e1f..fd243e6 100644 --- a/src/l-div-icon.test.js +++ b/src/l-div-icon.test.js @@ -7,9 +7,30 @@ it("should render a div icon", () => { const el = document.createElement("l-div-icon"); el.innerHTML = "Hello, World!"; el.setAttribute("icon-anchor","[50, 50]"); + el.setAttribute("icon-size", "[100, 100]") document.body.appendChild(el); expect(el.icon).toBeInstanceOf(DivIcon); - expect(el.icon).toEqual(divIcon({ html: "Hello, World!" , iconAnchor: "[50, 50]"})); + expect(el.icon).toEqual(divIcon({ html: "Hello, World!" , iconAnchor: [50, 50], iconSize: [100, 100]})); +}); + +it("should assign null as iconSize when null passed", () => { + const el = document.createElement("l-div-icon"); + el.innerHTML = "Hello, World!"; + el.setAttribute("icon-anchor","[50, 50]"); + el.setAttribute("icon-size","null"); + document.body.appendChild(el); + expect(el.icon).toBeInstanceOf(DivIcon); + expect(el.icon).toEqual(divIcon({ html: "Hello, World!" , iconAnchor: [50, 50], iconSize: null})); +}); + +it("should have a default iconSize if not given", () => { + 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!" , iconAnchor: [50, 50]})); + expect(el.icon.options).toHaveProperty('iconSize', [12, 12]); }); it("should attach div icon to marker", () => { @@ -19,6 +40,5 @@ it("should attach div icon to marker", () => { marker.appendChild(icon); document.body.appendChild(marker); - const actual = marker.layer.getIcon(); expect(icon.icon).toEqual(marker.layer.getIcon()); });