1 OSM.MapLibre.Marker = class extends maplibregl.Marker {
2 constructor({ icon = "dot", color = "var(--marker-red)", autoPan = false, ...options } = {}) {
3 const element = document.createElement("div");
4 element.className = "maplibre-gl-marker";
5 element.style.width = "25px";
6 element.style.height = "40px";
8 const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
9 svg.setAttribute("viewBox", "0 0 25 40");
10 svg.setAttribute("width", "25");
11 svg.setAttribute("height", "40");
12 svg.classList.add("pe-none");
13 svg.style.overflow = "visible";
15 // Use the marker icons from NoteMarker.svg
16 const use1 = document.createElementNS("http://www.w3.org/2000/svg", "use");
17 use1.setAttribute("href", "#pin-shadow");
19 const use2 = document.createElementNS("http://www.w3.org/2000/svg", "use");
20 use2.setAttribute("href", `#pin-${icon}`);
21 use2.setAttribute("color", color);
22 use2.classList.add("pe-auto");
24 svg.appendChild(use1);
25 svg.appendChild(use2);
26 element.appendChild(svg);
35 if (autoPan && options.draggable) this._enableAutoPan();
39 const edgeDistance = 50,
45 frame = requestAnimationFrame(step);
47 const map = this._map;
50 const point = map.project(this.getLngLat()),
51 { clientWidth, clientHeight } = map.getContainer();
55 if (point.x < edgeDistance) dx = point.x - edgeDistance;
56 else if (point.x > clientWidth - edgeDistance) dx = point.x - (clientWidth - edgeDistance);
57 if (point.y < edgeDistance) dy = point.y - edgeDistance;
58 else if (point.y > clientHeight - edgeDistance) dy = point.y - (clientHeight - edgeDistance);
59 if (!dx && !dy) return;
61 const clamp = (v) => Math.max(-maxPanStep, Math.min(maxPanStep, v));
62 map.panBy([clamp(dx), clamp(dy)], { duration: 0 });
63 this.setLngLat(map.unproject(point));
67 this.on("dragstart", () => {
68 if (frame === null) frame = requestAnimationFrame(step);
70 this.on("dragend", () => {
71 if (frame !== null) cancelAnimationFrame(frame);