diff --git a/README.md b/README.md index 0e892b5..e71e9dc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ -

- -

+ +![f26c08f1-ab0e-47de-ae8d-fbd062383555~3.jpg](https://github.com/user-attachments/assets/38887c1b-1c20-48de-be01-df264ee6cdeb) # Leaflet HTML diff --git a/package.json b/package.json index 446eb22..51a5f6b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "leaflet-html", "type": "module", - "version": "0.13.4", + "version": "0.13.5", "description": "Leaflet maps expressed in HTML suitable for HTMX", "keywords": [ "leaflet", diff --git a/src/l-map.js b/src/l-map.js index 1cf3553..f73f264 100644 --- a/src/l-map.js +++ b/src/l-map.js @@ -54,7 +54,11 @@ class LMap extends HTMLElement { } connectedCallback() { - this.map = L.map(this, { zoomControl: this.hasAttribute("zoom-control") }); + const options = { zoomControl: this.hasAttribute("zoom-control") }; + if (this.hasAttribute("attribution-control")) { + options["attributionControl"] = this.getAttribute("attribution-control").toLowerCase() === "true"; + } + this.map = L.map(this, options); // Allow listeners to know when the map is "ready" this.map.whenReady(() => { diff --git a/src/l-map.test.js b/src/l-map.test.js index 2facb03..77ee079 100644 --- a/src/l-map.test.js +++ b/src/l-map.test.js @@ -4,6 +4,7 @@ import { layerRemoved, layerConnected } from "./events" import { vi, it, expect } from "vitest"; import LTileLayer from "./l-tile-layer"; import LMap from "./l-map.js"; +import { map } from "leaflet"; it("should emit map:addTo event(s)", async () => { // Arrange: create a ... arrangement @@ -112,3 +113,32 @@ it("should handle layerConnected event from l-control-layers correctly", async ( const map = el.map; // Map instance from expect(mockLayer.addTo).toHaveBeenCalledWith(map); }); + + +it("should have attributionControl by default", () => { + const el = document.createElement("l-map") + el.setAttribute("zoom", "0"); + el.setAttribute("center", "[0,0]"); + document.body.appendChild(el); + expect(el.map.attributionControl).not.toBe(undefined); +}) + + +it("should remove attributionControl given attribution-control=false attribute", () => { + const el = document.createElement("l-map") + el.setAttribute("zoom", "0"); + el.setAttribute("center", "[0,0]"); + el.setAttribute("attribution-control", "false"); + document.body.appendChild(el); + expect(el.map.attributionControl).toBe(undefined); +}) + + +it("should remove attributionControl given attribution-control=true attribute", () => { + const el = document.createElement("l-map") + el.setAttribute("zoom", "0"); + el.setAttribute("center", "[0,0]"); + el.setAttribute("attribution-control", "true"); + document.body.appendChild(el); + expect(el.map.attributionControl).not.toBe(undefined); +})