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
9 changes: 9 additions & 0 deletions src/l-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ class LMap extends HTMLElement {

connectedCallback() {
const options = { zoomControl: this.hasAttribute("zoom-control") };
if (this.hasAttribute("max-zoom")) {
options.maxZoom = parseFloat(this.getAttribute("max-zoom"));
}
if (this.hasAttribute("min-zoom")) {
options.minZoom = parseFloat(this.getAttribute("min-zoom"));
}
if (this.hasAttribute("max-bounds")) {
options.maxBounds = JSON.parse(this.getAttribute("max-bounds"));
}
if (this.hasAttribute("attribution-control")) {
options["attributionControl"] = this.getAttribute("attribution-control").toLowerCase() === "true";
}
Expand Down
21 changes: 20 additions & 1 deletion src/l-map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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";
import { map, latLngBounds } from "leaflet";

it("should emit map:addTo event(s)", async () => {
// Arrange: create a <l-map><l-tile-layer>... arrangement
Expand Down Expand Up @@ -142,3 +142,22 @@ it("should remove attributionControl given attribution-control=true attribute",
document.body.appendChild(el);
expect(el.map.attributionControl).not.toBe(undefined);
})

it("should set maxZoom and minZoom given max-zoom and min-zoom attribute", () => {
const el = document.createElement("l-map");
el.setAttribute("zoom", "0");
el.setAttribute("center", "[0,0]");
el.setAttribute("max-zoom", "5");
el.setAttribute("min-zoom", "0");
document.body.appendChild(el);
expect(el.map.options).toEqual({ zoomControl: false, maxZoom: 5, minZoom: 0 });
})

it("should set maxBounds given max-bounds attribute", () => {
const el = document.createElement("l-map");
el.setAttribute("zoom", "0");
el.setAttribute("center", "[0,0]");
el.setAttribute("max-bounds", "[[0, 0], [1, 1]]");
document.body.appendChild(el);
expect(el.map.options).toEqual({ zoomControl: false, maxBounds: latLngBounds([[0, 0], [1, 1]]) });
})