maplair 4.2.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/CHANGELOG.md +106 -8
  2. package/dist/esm/control/AttributionControl.js +10 -10
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/ButtonControl.js +0 -1
  5. package/dist/esm/control/ButtonControl.js.map +1 -1
  6. package/dist/esm/control/ContextMenu.js +1 -1
  7. package/dist/esm/control/ContextMenu.js.map +1 -1
  8. package/dist/esm/control/Control.js +16 -11
  9. package/dist/esm/control/Control.js.map +1 -1
  10. package/dist/esm/control/FullscreenControl.js +0 -1
  11. package/dist/esm/control/FullscreenControl.js.map +1 -1
  12. package/dist/esm/control/LayersControl.js +13 -9
  13. package/dist/esm/control/LayersControl.js.map +1 -1
  14. package/dist/esm/control/RotateControl.js +0 -1
  15. package/dist/esm/control/RotateControl.js.map +1 -1
  16. package/dist/esm/control/ScaleControl.js +4 -5
  17. package/dist/esm/control/ScaleControl.js.map +1 -1
  18. package/dist/esm/control/SideBySideControl.js +3 -2
  19. package/dist/esm/control/SideBySideControl.js.map +1 -1
  20. package/dist/esm/control/ZoomControl.js +13 -13
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Events.js +4 -2
  23. package/dist/esm/core/Events.js.map +1 -1
  24. package/dist/esm/core/Util.js +16 -4
  25. package/dist/esm/core/Util.js.map +1 -1
  26. package/dist/esm/dom/DomEvent.PointerEvents.js +55 -2
  27. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  28. package/dist/esm/dom/DomEvent.js +4 -7
  29. package/dist/esm/dom/DomEvent.js.map +1 -1
  30. package/dist/esm/dom/DomUtil.js +5 -5
  31. package/dist/esm/dom/DomUtil.js.map +1 -1
  32. package/dist/esm/dom/Draggable.js +4 -6
  33. package/dist/esm/dom/Draggable.js.map +1 -1
  34. package/dist/esm/geo/LatLng.js +23 -34
  35. package/dist/esm/geo/LatLng.js.map +1 -1
  36. package/dist/esm/geo/LatLngBounds.js +6 -3
  37. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  38. package/dist/esm/geometry/Bounds.js +2 -2
  39. package/dist/esm/geometry/Bounds.js.map +1 -1
  40. package/dist/esm/geometry/Point.js +12 -17
  41. package/dist/esm/geometry/Point.js.map +1 -1
  42. package/dist/esm/geometry/Transformation.js +1 -7
  43. package/dist/esm/geometry/Transformation.js.map +1 -1
  44. package/dist/esm/layer/BlanketOverlay.js +1 -1
  45. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  46. package/dist/esm/layer/DivOverlay.js +23 -23
  47. package/dist/esm/layer/DivOverlay.js.map +1 -1
  48. package/dist/esm/layer/ImageOverlay.js +7 -4
  49. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  50. package/dist/esm/layer/Layer.js +11 -6
  51. package/dist/esm/layer/Layer.js.map +1 -1
  52. package/dist/esm/layer/Popup.js +30 -11
  53. package/dist/esm/layer/Popup.js.map +1 -1
  54. package/dist/esm/layer/Tooltip.js +18 -35
  55. package/dist/esm/layer/Tooltip.js.map +1 -1
  56. package/dist/esm/layer/VideoOverlay.js +2 -2
  57. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  58. package/dist/esm/layer/marker/DivIcon.js +4 -8
  59. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  60. package/dist/esm/layer/marker/Icon.js +16 -15
  61. package/dist/esm/layer/marker/Icon.js.map +1 -1
  62. package/dist/esm/layer/marker/Marker.Drag.js +6 -7
  63. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  64. package/dist/esm/layer/marker/Marker.js +49 -48
  65. package/dist/esm/layer/marker/Marker.js.map +1 -1
  66. package/dist/esm/layer/marker/SvgIcon.js +1 -1
  67. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  68. package/dist/esm/layer/tile/GridLayer.js +18 -16
  69. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  70. package/dist/esm/layer/tile/TileLayer.js +9 -9
  71. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  72. package/dist/esm/layer/vector/Canvas.js +44 -93
  73. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  74. package/dist/esm/layer/vector/Circle.js +8 -7
  75. package/dist/esm/layer/vector/Circle.js.map +1 -1
  76. package/dist/esm/layer/vector/CircleMarker.js +9 -1
  77. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  78. package/dist/esm/layer/vector/Path.js +10 -5
  79. package/dist/esm/layer/vector/Path.js.map +1 -1
  80. package/dist/esm/layer/vector/Polygon.js +10 -11
  81. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  82. package/dist/esm/layer/vector/Polyline.js +19 -26
  83. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  84. package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
  85. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  86. package/dist/esm/layer/vector/Renderer.js +16 -0
  87. package/dist/esm/layer/vector/Renderer.js.map +1 -1
  88. package/dist/esm/layer/vector/SVG.js +3 -3
  89. package/dist/esm/layer/vector/SVG.js.map +1 -1
  90. package/dist/esm/map/Map.Rotation.js +6 -9
  91. package/dist/esm/map/Map.Rotation.js.map +1 -1
  92. package/dist/esm/map/Map.js +104 -49
  93. package/dist/esm/map/Map.js.map +1 -1
  94. package/dist/esm/map/MapSync.js +1 -4
  95. package/dist/esm/map/MapSync.js.map +1 -1
  96. package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
  97. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  98. package/dist/esm/map/handler/DisplaceHandler.js +68 -30
  99. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  100. package/dist/esm/map/handler/KeyboardHandler.js +3 -5
  101. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  102. package/dist/esm/map/handler/PinchZoomHandler.js +3 -6
  103. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  104. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -6
  105. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  106. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -4
  107. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  108. package/dist/esm/map/handler/TapHoldHandler.js +8 -20
  109. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  110. package/dist/esm/package.js +1 -1
  111. package/dist/maplair-global-src.js +700 -687
  112. package/dist/maplair-global-src.js.map +1 -1
  113. package/dist/maplair-global.js +2 -2
  114. package/dist/maplair-global.js.map +1 -1
  115. package/dist/maplair-src.js +700 -687
  116. package/dist/maplair-src.js.map +1 -1
  117. package/dist/maplair.css +1 -1
  118. package/dist/maplair.js +2 -2
  119. package/dist/maplair.js.map +1 -1
  120. package/i18n/en.json +1 -0
  121. package/package.json +2 -1
  122. package/src/control/AttributionControl.js +9 -9
  123. package/src/control/ButtonControl.js +0 -1
  124. package/src/control/ContextMenu.js +1 -1
  125. package/src/control/Control.js +13 -16
  126. package/src/control/FullscreenControl.js +0 -1
  127. package/src/control/LayersControl.js +14 -10
  128. package/src/control/RotateControl.js +0 -1
  129. package/src/control/ScaleControl.js +4 -5
  130. package/src/control/SideBySideControl.js +4 -2
  131. package/src/control/ZoomControl.js +10 -13
  132. package/src/core/Events.js +8 -2
  133. package/src/core/Util.js +16 -3
  134. package/src/dom/DomEvent.PointerEvents.js +47 -1
  135. package/src/dom/DomEvent.js +5 -17
  136. package/src/dom/DomUtil.js +5 -5
  137. package/src/dom/Draggable.js +5 -6
  138. package/src/geo/LatLng.js +22 -36
  139. package/src/geo/LatLngBounds.js +10 -4
  140. package/src/geometry/Bounds.js +3 -3
  141. package/src/geometry/Point.js +18 -26
  142. package/src/geometry/Transformation.js +1 -8
  143. package/src/layer/BlanketOverlay.js +1 -1
  144. package/src/layer/DivOverlay.js +28 -30
  145. package/src/layer/ImageOverlay.js +9 -7
  146. package/src/layer/Layer.js +18 -6
  147. package/src/layer/Popup.js +38 -17
  148. package/src/layer/Tooltip.js +17 -44
  149. package/src/layer/VideoOverlay.js +2 -2
  150. package/src/layer/marker/DivIcon.js +3 -6
  151. package/src/layer/marker/Icon.js +19 -18
  152. package/src/layer/marker/Marker.Drag.js +16 -18
  153. package/src/layer/marker/Marker.js +66 -59
  154. package/src/layer/marker/SvgIcon.js +1 -1
  155. package/src/layer/tile/GridLayer.js +21 -23
  156. package/src/layer/tile/TileLayer.js +17 -14
  157. package/src/layer/vector/Canvas.js +52 -148
  158. package/src/layer/vector/Circle.js +14 -9
  159. package/src/layer/vector/CircleMarker.js +11 -1
  160. package/src/layer/vector/Path.js +11 -5
  161. package/src/layer/vector/Polygon.js +11 -10
  162. package/src/layer/vector/Polyline.js +20 -21
  163. package/src/layer/vector/Renderer.getRenderer.js +2 -1
  164. package/src/layer/vector/Renderer.js +21 -3
  165. package/src/layer/vector/SVG.js +3 -3
  166. package/src/map/Map.Rotation.js +7 -6
  167. package/src/map/Map.js +135 -54
  168. package/src/map/MapSync.js +1 -1
  169. package/src/map/handler/BoxZoomHandler.js +2 -0
  170. package/src/map/handler/DisplaceHandler.js +53 -7
  171. package/src/map/handler/KeyboardHandler.js +5 -10
  172. package/src/map/handler/PinchZoomHandler.js +3 -3
  173. package/src/map/handler/ScrollWheelZoomHandler.js +3 -3
  174. package/src/map/handler/TapDragZoomHandler.js +1 -1
  175. package/src/map/handler/TapHoldHandler.js +13 -25
  176. package/src/maplair.css +38 -9
  177. package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
  178. package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
  179. package/src/dom/DomEvent.DoubleTap.js +0 -143
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * Maplair 4.2.0, a JS library for interactive maps. https://maplair.org
2
+ * Maplair 4.4.0, a JS library for interactive maps. https://maplair.org
3
3
  * (c) 2026 Simon Legner and Maplair contributors, (c) 2010-2026 Volodymyr Agafonkin, (c) 2010-2011 CloudMade
4
4
  */
5
5
 
@@ -15,7 +15,7 @@ var __exportAll = (all, no_symbols) => {
15
15
  return target;
16
16
  };
17
17
  // package.json
18
- var version$1 = "4.2.0";
18
+ var version$1 = "4.4.0";
19
19
  // src/core/Util.js
20
20
  var Util_exports = /* @__PURE__ */ __exportAll({
21
21
  falseFn: () => falseFn,
@@ -26,6 +26,7 @@ var Util_exports = /* @__PURE__ */ __exportAll({
26
26
  stamp: () => stamp,
27
27
  template: () => template,
28
28
  throttle: () => throttle,
29
+ toNumber: () => toNumber,
29
30
  wrapNum: () => wrapNum
30
31
  });
31
32
  /**
@@ -100,11 +101,21 @@ function falseFn() {
100
101
  * @param {number|false} [precision]
101
102
  * @returns {number}
102
103
  */
103
- function formatNum(num, precision) {
104
+ function formatNum(num, precision = 6) {
104
105
  if (precision === false) return num;
105
- const pow = 10 ** (precision === void 0 ? 6 : precision);
106
+ const pow = 10 ** precision;
106
107
  return Math.round(num * pow) / pow;
107
108
  }
109
+ /**
110
+ * Returns `value` if it's a number (including `Infinity`), converts it if it's a
111
+ * numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns
112
+ * `''`, `null` and booleans into `0` or `1`.
113
+ * @param {unknown} value
114
+ * @returns {number}
115
+ */
116
+ function toNumber(value) {
117
+ return typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? +value : NaN;
118
+ }
108
119
  const WHITESPACE_RE = /\s+/;
109
120
  /**
110
121
  * Trims and splits the string on whitespace and returns the array of parts.
@@ -112,7 +123,8 @@ const WHITESPACE_RE = /\s+/;
112
123
  * @returns {string[]}
113
124
  */
114
125
  function splitWords(str) {
115
- return str.trim().split(WHITESPACE_RE);
126
+ const trimmed = str.trim();
127
+ return WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];
116
128
  }
117
129
  /**
118
130
  * Merges the given properties to the `options` of the `obj` object, returning the
@@ -419,31 +431,25 @@ var Point = class Point {
419
431
  * @param {boolean} [round]
420
432
  */
421
433
  constructor(x, y, round) {
422
- if (!Point.validate(x, y)) throw new Error(`Invalid Point object: (${x}, ${y})`);
423
- let _x, _y;
424
- if (x instanceof Point) {
425
- _x = x.x;
426
- _y = x.y;
427
- } else if (Array.isArray(x)) {
434
+ let _x = x, _y = y;
435
+ if (Array.isArray(x)) {
428
436
  _x = x[0];
429
437
  _y = x[1];
430
- } else if (typeof x === "object" && "x" in x && "y" in x) {
438
+ } else if (typeof x === "object" && x !== null) {
431
439
  _x = x.x;
432
440
  _y = x.y;
433
- } else {
434
- _x = x;
435
- _y = y;
436
441
  }
437
442
  /**
438
443
  * The `x` coordinate of the point.
439
444
  * @type {number}
440
445
  */
441
- this.x = round ? Math.round(_x) : _x;
446
+ this.x = round ? Math.round(toNumber(_x)) : toNumber(_x);
442
447
  /**
443
448
  * The `y` coordinate of the point.
444
449
  * @type {number}
445
450
  */
446
- this.y = round ? Math.round(_y) : _y;
451
+ this.y = round ? Math.round(toNumber(_y)) : toNumber(_y);
452
+ if (this.x !== this.x || this.y !== this.y) throw new Error(`Invalid Point object: (${_x}, ${_y})`);
447
453
  }
448
454
  /**
449
455
  * Returns the given `Point` object as it is (unless `round` is set), or else a new
@@ -471,10 +477,11 @@ var Point = class Point {
471
477
  * @returns {boolean}
472
478
  */
473
479
  static validate(x, y) {
474
- if (x instanceof Point || Array.isArray(x)) return true;
475
- else if (x && typeof x === "object" && "x" in x && "y" in x) return true;
476
- else if ((x || x === 0) && (y || y === 0)) return true;
477
- return false;
480
+ try {
481
+ return !!new Point(x, y);
482
+ } catch {
483
+ return false;
484
+ }
478
485
  }
479
486
  /**
480
487
  * Returns the result of addition of the current and the given points.
@@ -634,100 +641,15 @@ var Point = class Point {
634
641
  return `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;
635
642
  }
636
643
  };
637
- // src/dom/DomEvent.DoubleTap.js
638
- function makeDblclick(ev) {
639
- const init = {
640
- bubbles: ev.bubbles,
641
- cancelable: ev.cancelable,
642
- composed: ev.composed,
643
- detail: 2,
644
- view: ev.view,
645
- screenX: ev.screenX,
646
- screenY: ev.screenY,
647
- clientX: ev.clientX,
648
- clientY: ev.clientY,
649
- ctrlKey: ev.ctrlKey,
650
- shiftKey: ev.shiftKey,
651
- altKey: ev.altKey,
652
- metaKey: ev.metaKey,
653
- button: ev.button,
654
- buttons: ev.buttons,
655
- relatedTarget: ev.relatedTarget,
656
- region: ev.region
657
- };
658
- let newEvent;
659
- if (ev instanceof PointerEvent) newEvent = new PointerEvent("dblclick", {
660
- ...init,
661
- pointerId: ev.pointerId,
662
- width: ev.width,
663
- height: ev.height,
664
- pressure: ev.pressure,
665
- tangentialPressure: ev.tangentialPressure,
666
- tiltX: ev.tiltX,
667
- tiltY: ev.tiltY,
668
- twist: ev.twist,
669
- pointerType: ev.pointerType,
670
- isPrimary: ev.isPrimary
671
- });
672
- else newEvent = new MouseEvent("dblclick", init);
673
- return newEvent;
674
- }
675
- const delay$1 = 200;
676
- /**
677
- * Adds a `dblclick` listener which also handles double taps (simulating `dblclick`
678
- * on platforms which don't fire it for touch events).
679
- * @param {EventTarget} obj
680
- * @param {(ev: MouseEvent) => void} handler
681
- * @returns {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}}
682
- * The listeners to pass to `removeDoubleTapListener`.
683
- */
684
- function addDoubleTapListener(obj, handler) {
685
- obj.addEventListener("dblclick", handler);
686
- let last = 0, detail, pointerType;
687
- function onPointerDown(ev) {
688
- pointerType = ev.pointerType;
689
- }
690
- function simDblclick(ev) {
691
- if (ev.detail !== 1) {
692
- detail = ev.detail;
693
- return;
694
- }
695
- if (pointerType === "mouse" || ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents) return;
696
- const path = ev.composedPath();
697
- if (path.some((el) => el instanceof HTMLLabelElement && el.htmlFor) && !path.some((el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement)) return;
698
- const now = Date.now();
699
- if (now - last <= delay$1) {
700
- detail++;
701
- if (detail === 2) ev.target.dispatchEvent(makeDblclick(ev));
702
- } else detail = 1;
703
- last = now;
704
- }
705
- obj.addEventListener("pointerdown", onPointerDown, true);
706
- obj.addEventListener("click", simDblclick);
707
- return {
708
- dblclick: handler,
709
- onPointerDown,
710
- simDblclick
711
- };
712
- }
713
- /**
714
- * Removes the listeners added by `addDoubleTapListener`.
715
- * @param {EventTarget} obj
716
- * @param {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}} handlers
717
- * @returns {void}
718
- */
719
- function removeDoubleTapListener(obj, handlers) {
720
- obj.removeEventListener("dblclick", handlers.dblclick);
721
- obj.removeEventListener("pointerdown", handlers.onPointerDown, true);
722
- obj.removeEventListener("click", handlers.simDblclick);
723
- }
724
644
  // src/dom/DomEvent.PointerEvents.js
725
645
  var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
726
646
  disablePointerDetection: () => disablePointerDetection,
727
647
  enablePointerDetection: () => enablePointerDetection,
728
- getPointers: () => getPointers
648
+ getPointers: () => getPointers,
649
+ simulateDblclick: () => simulateDblclick
729
650
  });
730
651
  const activePointers = /* @__PURE__ */ new Map();
652
+ let lastPointerType;
731
653
  /**
732
654
  * Enables pointer detection and capture for the document.
733
655
  * @group Pointer detection
@@ -756,6 +678,7 @@ function disablePointerDetection(el) {
756
678
  function _onSet(e) {
757
679
  if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
758
680
  activePointers.set(e.pointerId, e);
681
+ lastPointerType = e.pointerType;
759
682
  }
760
683
  function _onUpdate(e) {
761
684
  if (activePointers.has(e.pointerId)) activePointers.set(e.pointerId, e);
@@ -772,6 +695,56 @@ function _onDelete(e) {
772
695
  function getPointers() {
773
696
  return [...activePointers.values()];
774
697
  }
698
+ const dblclickProps = [
699
+ "bubbles",
700
+ "cancelable",
701
+ "composed",
702
+ "view",
703
+ "screenX",
704
+ "screenY",
705
+ "clientX",
706
+ "clientY",
707
+ "ctrlKey",
708
+ "shiftKey",
709
+ "altKey",
710
+ "metaKey",
711
+ "button",
712
+ "buttons",
713
+ "relatedTarget"
714
+ ];
715
+ let lastClickTime = 0;
716
+ let lastClick;
717
+ let lastClickMap;
718
+ let clickCount = 0;
719
+ /**
720
+ * Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),
721
+ * which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The
722
+ * pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on
723
+ * clicks from touch (WebKit bug 282988). Called by the map for clicks in it.
724
+ * @internal
725
+ * @param {MouseEvent} e
726
+ * @param {HTMLElement} mapContainer The container of the map, two taps make a double
727
+ * tap only in the same map.
728
+ * @returns {void}
729
+ */
730
+ function simulateDblclick(e, mapContainer) {
731
+ if (e === lastClick) return;
732
+ lastClick = e;
733
+ const target = e.target;
734
+ if (e.detail !== 1 || lastPointerType === "mouse" || target.closest("label")) {
735
+ clickCount = 0;
736
+ return;
737
+ }
738
+ const now = Date.now();
739
+ clickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;
740
+ lastClickTime = now;
741
+ lastClickMap = mapContainer;
742
+ if (clickCount === 2) {
743
+ const init = { detail: 2 };
744
+ for (const prop of dblclickProps) init[prop] = e[prop];
745
+ target.dispatchEvent(new MouseEvent("dblclick", init));
746
+ }
747
+ }
775
748
  // src/dom/DomEvent.js
776
749
  var DomEvent_exports = /* @__PURE__ */ __exportAll({
777
750
  PointerEvents: () => DomEvent_PointerEvents_exports,
@@ -839,11 +812,10 @@ function batchRemove(obj, filterFn) {
839
812
  function addOne(obj, type, fn, context) {
840
813
  const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
841
814
  if (obj[eventsKey] && obj[eventsKey][id]) return;
842
- let handler = function(e) {
815
+ const handler = function(e) {
843
816
  return fn.call(context || obj, e);
844
817
  };
845
- if (type === "dblclick") handler = addDoubleTapListener(obj, handler);
846
- else obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
818
+ obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
847
819
  obj[eventsKey] ??= {};
848
820
  obj[eventsKey][id] = handler;
849
821
  }
@@ -851,8 +823,7 @@ function removeOne(obj, type, fn, context, id) {
851
823
  id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
852
824
  const handler = obj[eventsKey] && obj[eventsKey][id];
853
825
  if (!handler) return;
854
- if (type === "dblclick") removeDoubleTapListener(obj, handler);
855
- else obj.removeEventListener(type, handler, false);
826
+ obj.removeEventListener(type, handler, false);
856
827
  obj[eventsKey][id] = null;
857
828
  }
858
829
  /**
@@ -938,7 +909,7 @@ function getWheelPxFactor() {
938
909
  * @returns {number}
939
910
  */
940
911
  function getWheelDelta(e) {
941
- return e.deltaY && e.deltaMode === 0 ? -e.deltaY / getWheelPxFactor() : e.deltaY && e.deltaMode === 1 ? -e.deltaY * 20 : e.deltaY && e.deltaMode === 2 ? -e.deltaY * 60 : e.deltaX || e.deltaZ ? 0 : 0;
912
+ return -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;
942
913
  }
943
914
  /**
944
915
  * Checks if the pointer really left/entered the element `el` (for
@@ -985,7 +956,7 @@ function get(id) {
985
956
  function create(tagName, className, container) {
986
957
  const el = document.createElement(tagName);
987
958
  el.className = className ?? "";
988
- container?.appendChild(el);
959
+ container?.append(el);
989
960
  return el;
990
961
  }
991
962
  /**
@@ -997,8 +968,8 @@ function create(tagName, className, container) {
997
968
  function toFront(el) {
998
969
  const parent = el.parentNode;
999
970
  if (!parent || parent.lastChild === el) return;
1000
- if (el.matches(":hover")) while (el.nextSibling) parent.insertBefore(el.nextSibling, el);
1001
- else parent.appendChild(el);
971
+ if (el.matches(":hover")) while (el.nextSibling) el.before(el.nextSibling);
972
+ else parent.append(el);
1002
973
  }
1003
974
  /**
1004
975
  * Makes `el` the first child of its parent, so it renders behind the other children.
@@ -1008,8 +979,8 @@ function toFront(el) {
1008
979
  function toBack(el) {
1009
980
  const parent = el.parentNode;
1010
981
  if (!parent || parent.firstChild === el) return;
1011
- if (el.matches(":hover")) while (el.previousSibling) parent.insertBefore(el.previousSibling, el.nextSibling);
1012
- else parent.insertBefore(el, parent.firstChild);
982
+ if (el.matches(":hover")) while (el.previousSibling) el.after(el.previousSibling);
983
+ else parent.prepend(el);
1013
984
  }
1014
985
  /**
1015
986
  * Resets the 3D CSS transform of `el` so it is translated by `offset` pixels
@@ -1148,12 +1119,16 @@ const mapControlMethods = {
1148
1119
  * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that
1149
1120
  * removes the listeners previously added in `onAdd`. Called on
1150
1121
  * [`control.remove()`](#control-remove).
1122
+ * @property {() => Record<string, Function>} [getEvents] Should return an object like
1123
+ * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this object
1124
+ * will be automatically added and removed from the map with your control.
1151
1125
  * @lends Control
1152
1126
  */
1153
1127
  const controlOrders = /* @__PURE__ */ new WeakMap();
1154
1128
  /**
1155
- * Control is a base class for implementing map controls. Handles positioning.
1156
- * All other controls extend from this class.
1129
+ * Base class for map controls such as `ZoomControl`, `AttributionControl`,
1130
+ * `LayersControl` and `ScaleControl`, which handles positioning them. Extend it to
1131
+ * create your own controls.
1157
1132
  *
1158
1133
  * Every control should extend from `Control` and (re-)implement the following methods:
1159
1134
  *
@@ -1163,6 +1138,9 @@ const controlOrders = /* @__PURE__ */ new WeakMap();
1163
1138
  * * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes
1164
1139
  * the listeners previously added in [`onAdd`](#control-onadd). Called on
1165
1140
  * [`control.remove()`](#control-remove).
1141
+ * * `getEvents(): Object` (optional) should return an object like
1142
+ * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this
1143
+ * object will be automatically added and removed from the map with your control.
1166
1144
  */
1167
1145
  var Control = class Control extends Class {
1168
1146
  static defaultOptions = {
@@ -1216,7 +1194,11 @@ var Control = class Control extends Class {
1216
1194
  const order = this.options.order ?? 0, bottom = pos.includes("bottom"), children = [...corner.children];
1217
1195
  controlOrders.set(container, order);
1218
1196
  corner.insertBefore(container, children.find((el) => bottom ? (controlOrders.get(el) ?? 0) <= order : (controlOrders.get(el) ?? 0) > order) ?? null);
1219
- this._map.on("unload", this.remove, this);
1197
+ this._mapEvents = {
1198
+ ...this.getEvents?.(),
1199
+ unload: this.remove
1200
+ };
1201
+ map.on(this._mapEvents, this);
1220
1202
  return this;
1221
1203
  }
1222
1204
  /**
@@ -1226,17 +1208,11 @@ var Control = class Control extends Class {
1226
1208
  remove() {
1227
1209
  if (!this._map) return this;
1228
1210
  this._container.remove();
1229
- if (this.onRemove) this.onRemove(this._map);
1230
- this._map.off("unload", this.remove, this);
1211
+ this._map.off(this._mapEvents, this);
1212
+ this.onRemove?.(this._map);
1231
1213
  this._map = null;
1232
1214
  return this;
1233
1215
  }
1234
- _refocusOnMap(e) {
1235
- if (this._map && e && !(e.screenX === 0 && e.screenY === 0)) this._map.getContainer().focus({
1236
- preventScroll: true,
1237
- focusVisible: false
1238
- });
1239
- }
1240
1216
  /**
1241
1217
  * Registers this default feature on the map class, called by `MaplairMap` itself.
1242
1218
  * @internal
@@ -1382,21 +1358,22 @@ var AttributionControl = class AttributionControl extends Control {
1382
1358
  disableClickPropagation(this._container);
1383
1359
  if (map._loaded) map.eachLayer((layer) => this._addLayer({ layer }));
1384
1360
  this._update();
1385
- map.on({
1386
- layeradd: this._addLayer,
1387
- layerremove: this._removeLayer
1388
- }, this);
1389
1361
  return this._container;
1390
1362
  }
1391
1363
  /**
1392
1364
  * @internal
1393
- * @param {MaplairMap} map
1365
+ * @returns {Record<string, Function>}
1394
1366
  */
1395
- onRemove(map) {
1396
- map.off({
1367
+ getEvents() {
1368
+ return {
1397
1369
  layeradd: this._addLayer,
1398
1370
  layerremove: this._removeLayer
1399
- }, this);
1371
+ };
1372
+ }
1373
+ /**
1374
+ * @internal
1375
+ */
1376
+ onRemove() {
1400
1377
  for (const layer of this._layerAttributions.keys()) this._removeLayer({ layer });
1401
1378
  }
1402
1379
  _addLayer({ layer }) {
@@ -1430,8 +1407,7 @@ var AttributionControl = class AttributionControl extends Control {
1430
1407
  addAttribution(text, order = 0) {
1431
1408
  if (!text) return this;
1432
1409
  this._orders[text] = order;
1433
- if (!this._attributions[text]) this._attributions[text] = 0;
1434
- this._attributions[text]++;
1410
+ this._attributions[text] = (this._attributions[text] || 0) + 1;
1435
1411
  this._update();
1436
1412
  return this;
1437
1413
  }
@@ -1566,7 +1542,6 @@ var ButtonControl = class ButtonControl extends Control {
1566
1542
  disableClickPropagation(button);
1567
1543
  on(button, "click", stop);
1568
1544
  on(button, "click", this._onClick, this);
1569
- on(button, "click", this._refocusOnMap, this);
1570
1545
  this._update();
1571
1546
  return button;
1572
1547
  }
@@ -1928,8 +1903,9 @@ var Evented = class Evented extends Class {
1928
1903
  };
1929
1904
  if (_once) newListener.once = true;
1930
1905
  this._events ??= {};
1931
- this._events[type] ??= /* @__PURE__ */ new Set();
1932
- this._events[type].add(newListener);
1906
+ let listeners = this._events[type] ??= /* @__PURE__ */ new Set();
1907
+ if (this._firingCount) this._events[type] = listeners = new Set(listeners);
1908
+ listeners.add(newListener);
1933
1909
  if (contexts) contexts.set(context, newListener);
1934
1910
  else this._listenerIndex[type].set(fn, /* @__PURE__ */ new Map([[context, newListener]]));
1935
1911
  }
@@ -2062,6 +2038,7 @@ var Evented = class Evented extends Class {
2062
2038
  }
2063
2039
  _propagateEvent(e) {
2064
2040
  for (const p of Object.values(this._eventParents ?? {})) p.fire(e.type, {
2041
+ layer: e.target,
2065
2042
  propagatedFrom: e.target,
2066
2043
  ...e
2067
2044
  }, true);
@@ -2203,8 +2180,8 @@ const mapLayerMethods = {
2203
2180
  const oldZoomSpan = this._getZoomSpan();
2204
2181
  for (const l of Object.values(this._zoomBoundLayers)) {
2205
2182
  const options = l.options;
2206
- minZoom = Math.min(minZoom, options.minZoom ?? Infinity);
2207
- maxZoom = Math.max(maxZoom, options.maxZoom ?? -Infinity);
2183
+ if (options.minZoom != null && !Number.isNaN(options.minZoom)) minZoom = Math.min(minZoom, options.minZoom);
2184
+ if (options.maxZoom != null && !Number.isNaN(options.maxZoom)) maxZoom = Math.max(maxZoom, options.maxZoom);
2208
2185
  }
2209
2186
  this._layersMaxZoom = maxZoom === -Infinity ? void 0 : maxZoom;
2210
2187
  this._layersMinZoom = minZoom === Infinity ? void 0 : minZoom;
@@ -2326,8 +2303,10 @@ var Layer = class extends Evented {
2326
2303
  }
2327
2304
  _updateInteractive() {}
2328
2305
  /**
2329
- * Makes `targetEl` a target of pointer events of this layer.
2330
- * @internal
2306
+ * Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and
2307
+ * keyboard events on it (or its descendants) fire on the layer and bubble through its
2308
+ * parent groups to the map, the way they do for markers and paths. Custom layers call
2309
+ * it in [`onAdd`](#layer-onadd), once the layer is on a map.
2331
2310
  * @param {HTMLElement} targetEl
2332
2311
  * @returns {this}
2333
2312
  */
@@ -2336,8 +2315,8 @@ var Layer = class extends Evented {
2336
2315
  return this;
2337
2316
  }
2338
2317
  /**
2339
- * Stops `targetEl` from being a target of pointer events of this layer.
2340
- * @internal
2318
+ * Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in
2319
+ * [`onRemove`](#layer-onremove).
2341
2320
  * @param {HTMLElement} targetEl
2342
2321
  * @returns {this}
2343
2322
  */
@@ -2345,6 +2324,9 @@ var Layer = class extends Evented {
2345
2324
  delete this._map._targets[stamp(targetEl)];
2346
2325
  return this;
2347
2326
  }
2327
+ _togglesPopupOnClick() {
2328
+ return true;
2329
+ }
2348
2330
  /**
2349
2331
  * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).
2350
2332
  * @returns {string|null}
@@ -2512,7 +2494,7 @@ var ContextMenu = class ContextMenu extends Class {
2512
2494
  }
2513
2495
  _createMenu(parent) {
2514
2496
  const container = this._container ??= create("div", `maplair-contextmenu ${this.options.className}`);
2515
- if (container.parentNode !== parent) parent.appendChild(container);
2497
+ if (container.parentNode !== parent) parent.append(container);
2516
2498
  container.popover = "auto";
2517
2499
  container.setAttribute("role", "menu");
2518
2500
  container.replaceChildren();
@@ -2679,7 +2661,6 @@ var FullscreenControl = class FullscreenControl extends Control {
2679
2661
  disableClickPropagation(button);
2680
2662
  on(button, "click", stop);
2681
2663
  on(button, "click", this._toggleFullscreen, this);
2682
- on(button, "click", this._refocusOnMap, this);
2683
2664
  this._update();
2684
2665
  map.on("fullscreenchange", this._update, this);
2685
2666
  return container;
@@ -2763,6 +2744,8 @@ var FullscreenControl = class FullscreenControl extends Control {
2763
2744
  * `maplair-control-layers-group-name` element, and each entry shows only its label.
2764
2745
  * Events like `baselayerchange` still carry the full `name`. When combined with
2765
2746
  * `sortLayers`, the entries are sorted first and grouped afterwards.
2747
+ * @property {string} [title] The title of the toggle button and the accessible label
2748
+ * of the layers list, the translation of `'Layers'` by default.
2766
2749
  * @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
2767
2750
  * collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
2768
2751
  * element. String content is rendered as HTML; do not pass untrusted input.
@@ -2847,6 +2830,7 @@ var LayersControl = class LayersControl extends Control {
2847
2830
  collapsed: true,
2848
2831
  inline: false,
2849
2832
  groupBy: void 0,
2833
+ title: void 0,
2850
2834
  toggleContent: void 0,
2851
2835
  collapseDelay: 0,
2852
2836
  position: "topright",
@@ -2993,13 +2977,16 @@ var LayersControl = class LayersControl extends Control {
2993
2977
  else this._container.classList.remove("maplair-control-layers-expanded");
2994
2978
  return this;
2995
2979
  }
2980
+ _getTitle() {
2981
+ return this.options.title ?? I18n.translate("Layers");
2982
+ }
2996
2983
  _initLayout() {
2997
2984
  const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this._isCollapsible();
2998
2985
  if (this.options.inline) container.classList.add(`${className}-inline`);
2999
2986
  disableClickPropagation(container);
3000
2987
  disableScrollPropagation(container);
3001
2988
  const section = this._section = create("fieldset", `${className}-list`);
3002
- section.setAttribute("aria-label", I18n.translate("Layers"));
2989
+ section.setAttribute("aria-label", this._getTitle());
3003
2990
  if (collapsed) {
3004
2991
  this._map.on("click", this.collapse, this);
3005
2992
  on(container, {
@@ -3012,8 +2999,8 @@ var LayersControl = class LayersControl extends Control {
3012
2999
  if (!this.options.inline) {
3013
3000
  const link = this._layersLink = create("button", `${className}-toggle`, container);
3014
3001
  link.type = "button";
3015
- link.title = I18n.translate("Layers");
3016
- link.setAttribute("aria-label", I18n.translate("Layers"));
3002
+ link.title = this._getTitle();
3003
+ link.setAttribute("aria-label", link.title);
3017
3004
  const { toggleContent } = this.options;
3018
3005
  if (typeof toggleContent === "string") link.innerHTML = toggleContent;
3019
3006
  else if (toggleContent) link.replaceChildren(toggleContent);
@@ -3031,7 +3018,7 @@ var LayersControl = class LayersControl extends Control {
3031
3018
  this._baseLayersList = create("div", `${className}-base`, section);
3032
3019
  this._separator = create("div", `${className}-separator`, section);
3033
3020
  this._overlaysList = create("div", `${className}-overlays`, section);
3034
- container.appendChild(section);
3021
+ container.append(section);
3035
3022
  }
3036
3023
  _addLayer(layer, name, overlay) {
3037
3024
  if (this._map) layer.on("add remove", this._onLayerChange, this);
@@ -3090,11 +3077,10 @@ var LayersControl = class LayersControl extends Control {
3090
3077
  const name = document.createElement("span");
3091
3078
  name.innerHTML = ` ${group ? group.label : obj.name}`;
3092
3079
  const holder = document.createElement("span");
3093
- label.appendChild(holder);
3094
- holder.appendChild(input);
3095
- holder.appendChild(name);
3080
+ label.append(holder);
3081
+ holder.append(input, name);
3096
3082
  const list = obj.overlay ? this._overlaysList : this._baseLayersList;
3097
- (group ? this._getGroupContainer(list, group.group) : list).appendChild(label);
3083
+ (group ? this._getGroupContainer(list, group.group) : list).append(label);
3098
3084
  this._checkDisabledLayers();
3099
3085
  return label;
3100
3086
  }
@@ -3135,7 +3121,6 @@ var LayersControl = class LayersControl extends Control {
3135
3121
  this._update();
3136
3122
  break;
3137
3123
  }
3138
- this._refocusOnMap(e);
3139
3124
  }
3140
3125
  _checkDisabledLayers() {
3141
3126
  const inputs = this._layerControlInputs, zoom = this._map.getZoom();
@@ -3328,7 +3313,7 @@ var Bounds = class Bounds {
3328
3313
  */
3329
3314
  overlaps(bounds) {
3330
3315
  bounds = Bounds.from(bounds);
3331
- const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xOverlaps = max2.x > min.x && min2.x < max.x, yOverlaps = max2.y > min.y && min2.y < max.y;
3316
+ const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xOverlaps = Math.max(min.x, min2.x) < Math.min(max.x, max2.x), yOverlaps = Math.max(min.y, min2.y) < Math.min(max.y, max2.y);
3332
3317
  return xOverlaps && yOverlaps;
3333
3318
  }
3334
3319
  /**
@@ -3361,7 +3346,7 @@ var Bounds = class Bounds {
3361
3346
  }
3362
3347
  };
3363
3348
  function isPointExpression(obj) {
3364
- return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] === "number" : "x" in obj);
3349
+ return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] !== "object" : "x" in obj);
3365
3350
  }
3366
3351
  // src/layer/BlanketOverlay.js
3367
3352
  /** @import {LayerOptions} from './Layer.js' */
@@ -3424,7 +3409,7 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
3424
3409
  this._initContainer();
3425
3410
  this._container.classList.add("maplair-zoom-animated");
3426
3411
  }
3427
- this.getPane().appendChild(this._container);
3412
+ this.getPane().append(this._container);
3428
3413
  this._resizeContainer();
3429
3414
  this._onMoveEnd();
3430
3415
  }
@@ -3496,6 +3481,8 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
3496
3481
  /** @import {BlanketOverlayOptions} from '../BlanketOverlay.js' */
3497
3482
  /** @import {MaplairEvent} from '../../core/Events.js' */
3498
3483
  /** @import {MaplairMap} from '../../map/Map.js' */
3484
+ /** @import {LatLngExpression} from '../../geo/LatLng.js' */
3485
+ /** @import {Point} from '../../geometry/Point.js' */
3499
3486
  /**
3500
3487
  * Options of `Renderer`, `SVG` and `Canvas`. The `continuous` option inherited from
3501
3488
  * `BlanketOverlay` cannot be set to `true`.
@@ -3537,6 +3524,7 @@ var Renderer = class Renderer extends BlanketOverlay {
3537
3524
  * @param {MaplairMap} map
3538
3525
  */
3539
3526
  onAdd(map) {
3527
+ this._setPathView();
3540
3528
  super.onAdd(map);
3541
3529
  this.on("update", this._updatePaths, this);
3542
3530
  }
@@ -3548,12 +3536,25 @@ var Renderer = class Renderer extends BlanketOverlay {
3548
3536
  this.off("update", this._updatePaths, this);
3549
3537
  }
3550
3538
  _onZoomEnd() {
3539
+ this._setPathView();
3551
3540
  for (const layer of Object.values(this._layers)) layer._project();
3552
3541
  }
3542
+ _setPathView() {
3543
+ this._pathZoom = this._map.getZoom();
3544
+ this._pathOrigin = this._map.getPixelOrigin();
3545
+ }
3546
+ /**
3547
+ * @param {LatLngExpression} latlng
3548
+ * @returns {Point}
3549
+ */
3550
+ _latLngToLayerPoint(latlng) {
3551
+ return this._map.project(latlng, this._pathZoom)._subtract(this._pathOrigin);
3552
+ }
3553
3553
  _updatePaths() {
3554
3554
  for (const layer of Object.values(this._layers)) layer._update();
3555
3555
  }
3556
3556
  _onViewReset() {
3557
+ this._setPathView();
3557
3558
  for (const layer of Object.values(this._layers)) layer._reset();
3558
3559
  }
3559
3560
  _onSettled() {
@@ -3603,7 +3604,7 @@ var SVG = class SVG extends Renderer {
3603
3604
  this._container = SVG.create("svg");
3604
3605
  this._container.setAttribute("pointer-events", "none");
3605
3606
  this._rootGroup = SVG.create("g");
3606
- this._container.appendChild(this._rootGroup);
3607
+ this._container.append(this._rootGroup);
3607
3608
  }
3608
3609
  _destroyContainer() {
3609
3610
  super._destroyContainer();
@@ -3612,7 +3613,7 @@ var SVG = class SVG extends Renderer {
3612
3613
  }
3613
3614
  _resizeContainer() {
3614
3615
  const size = super._resizeContainer();
3615
- if (!this._svgSize || !this._svgSize.equals(size)) {
3616
+ if (!this._svgSize?.equals(size)) {
3616
3617
  this._svgSize = size;
3617
3618
  this._container.setAttribute("width", `${size.x}`);
3618
3619
  this._container.setAttribute("height", `${size.y}`);
@@ -3648,7 +3649,7 @@ var SVG = class SVG extends Renderer {
3648
3649
  }
3649
3650
  _addPath(layer) {
3650
3651
  if (!this._rootGroup) this._initContainer();
3651
- this._rootGroup.appendChild(layer._path);
3652
+ this._rootGroup.append(layer._path);
3652
3653
  layer.addInteractiveTarget(layer._path);
3653
3654
  }
3654
3655
  _removePath(layer) {
@@ -3757,13 +3758,15 @@ function num(v) {
3757
3758
  * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
3758
3759
  * afterwards.
3759
3760
  * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
3760
- * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),
3761
- * which is `SVG` by default. If set, it overrides the `pane` option.
3761
+ * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
3762
+ * (`SVG` by default), or in a custom pane, a renderer of the same kind created for
3763
+ * that pane. If set, it overrides the `pane` option.
3762
3764
  * @extends InteractiveLayerOptions
3763
3765
  */
3764
3766
  /**
3765
- * An abstract class that contains options and constants shared between vector
3766
- * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
3767
+ * An abstract class that contains options and methods shared between vector overlays
3768
+ * (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it
3769
+ * directly. Extends `Layer`.
3767
3770
  */
3768
3771
  var Path = class extends Layer {
3769
3772
  static defaultOptions = {
@@ -3860,8 +3863,11 @@ var Path = class extends Layer {
3860
3863
  this._project();
3861
3864
  this._update();
3862
3865
  }
3866
+ _togglesPopupOnClick() {
3867
+ return false;
3868
+ }
3863
3869
  _clickTolerance() {
3864
- return (this.options.stroke ? this.options.weight / 2 : 0) + (this._renderer.options.tolerance || 0);
3870
+ return (this.options.stroke ? this.options.weight / 2 || 0 : 0) + (this._renderer.options.tolerance || 0);
3865
3871
  }
3866
3872
  };
3867
3873
  // src/geo/LatLngBounds.js
@@ -3949,7 +3955,7 @@ var LatLngBounds = class LatLngBounds {
3949
3955
  ({_southWest: sw2, _northEast: ne2} = obj);
3950
3956
  if (!sw2) return this;
3951
3957
  } else if (!obj) return this;
3952
- else if (LatLng.validate(obj)) sw2 = ne2 = LatLng.from(obj);
3958
+ else if (isLatLngExpression(obj)) sw2 = ne2 = LatLng.from(obj);
3953
3959
  else return this.extend(LatLngBounds.from(obj));
3954
3960
  if (!sw) {
3955
3961
  this._southWest = new LatLng(sw2.lat, sw2.lng);
@@ -4042,7 +4048,7 @@ var LatLngBounds = class LatLngBounds {
4042
4048
  * @returns {boolean}
4043
4049
  */
4044
4050
  contains(obj) {
4045
- if (LatLng.validate(obj)) obj = LatLng.from(obj);
4051
+ if (isLatLngExpression(obj)) obj = LatLng.from(obj);
4046
4052
  else obj = LatLngBounds.from(obj);
4047
4053
  const sw = this._southWest, ne = this._northEast;
4048
4054
  let sw2, ne2;
@@ -4071,7 +4077,7 @@ var LatLngBounds = class LatLngBounds {
4071
4077
  */
4072
4078
  overlaps(bounds) {
4073
4079
  bounds = LatLngBounds.from(bounds);
4074
- const sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), ne2 = bounds.getNorthEast(), latOverlaps = ne2.lat > sw.lat && sw2.lat < ne.lat, lngOverlaps = ne2.lng > sw.lng && sw2.lng < ne.lng;
4080
+ const sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), ne2 = bounds.getNorthEast(), latOverlaps = Math.max(sw.lat, sw2.lat) < Math.min(ne.lat, ne2.lat), lngOverlaps = Math.max(sw.lng, sw2.lng) < Math.min(ne.lng, ne2.lng);
4075
4081
  return latOverlaps && lngOverlaps;
4076
4082
  }
4077
4083
  /**
@@ -4109,6 +4115,9 @@ var LatLngBounds = class LatLngBounds {
4109
4115
  return !!(this._southWest && this._northEast);
4110
4116
  }
4111
4117
  };
4118
+ function isLatLngExpression(obj) {
4119
+ return obj instanceof LatLng || (Array.isArray(obj) ? typeof obj[0] !== "object" : typeof obj === "object" && obj !== null && "lat" in obj);
4120
+ }
4112
4121
  // src/geo/LatLng.js
4113
4122
  const coordinate = String.raw`([+-]?\d+(?:\.\d+)?)\s*°?`;
4114
4123
  const separator = String.raw`(?:\s*[,;]\s*|\s+)`;
@@ -4158,46 +4167,36 @@ var LatLng = class LatLng {
4158
4167
  * @param {number} [alt] Altitude in meters.
4159
4168
  */
4160
4169
  constructor(lat, lng, alt) {
4161
- if (!LatLng.validate(lat, lng, alt)) throw new Error(`Invalid LatLng object: (${lat}, ${lng})`);
4162
- let _lat, _lng, _alt;
4163
- if (lat instanceof LatLng) {
4164
- _lat = lat.lat;
4165
- _lng = lat.lng;
4166
- _alt = lat.alt;
4167
- } else if (Array.isArray(lat) && typeof lat[0] !== "object") {
4168
- if (lat.length === 3) {
4169
- _lat = lat[0];
4170
- _lng = lat[1];
4171
- _alt = lat[2];
4172
- } else if (lat.length === 2) {
4173
- _lat = lat[0];
4174
- _lng = lat[1];
4175
- }
4176
- } else if (typeof lat === "object" && "lat" in lat) {
4170
+ let _lat = lat, _lng = lng, _alt = alt;
4171
+ if (lat instanceof LatLng) ({lat: _lat, lng: _lng, alt: _alt} = lat);
4172
+ else if (Array.isArray(lat)) {
4173
+ _lat = lat.length <= 3 ? lat[0] : NaN;
4174
+ _lng = lat[1];
4175
+ _alt = lat[2];
4176
+ } else if (typeof lat === "object" && lat !== null) {
4177
4177
  _lat = lat.lat;
4178
4178
  _lng = "lng" in lat ? lat.lng : lat.lon;
4179
4179
  _alt = lat.alt;
4180
- } else {
4181
- _lat = lat;
4182
- _lng = lng;
4183
- _alt = alt;
4184
4180
  }
4185
4181
  /**
4186
4182
  * Latitude in degrees.
4187
4183
  * @type {number}
4188
4184
  */
4189
- this.lat = +_lat;
4185
+ this.lat = toNumber(_lat);
4190
4186
  /**
4191
4187
  * Longitude in degrees.
4192
4188
  * @type {number}
4193
4189
  */
4194
- this.lng = +_lng;
4195
- if (_alt !== void 0)
4196
- /**
4197
- * Altitude in meters (optional).
4198
- * @type {number|undefined}
4199
- */
4200
- this.alt = +_alt;
4190
+ this.lng = toNumber(_lng);
4191
+ if (isNaN(this.lat) || isNaN(this.lng)) throw new Error(`Invalid LatLng object: (${_lat}, ${_lng})`);
4192
+ if (_alt != null) {
4193
+ /**
4194
+ * Altitude in meters (optional).
4195
+ * @type {number|undefined}
4196
+ */
4197
+ this.alt = toNumber(_alt);
4198
+ if (isNaN(this.alt)) throw new Error(`Invalid LatLng altitude: ${_alt}`);
4199
+ }
4201
4200
  }
4202
4201
  /**
4203
4202
  * Returns the given `LatLng` object as it is, or else a new `LatLng` object created
@@ -4226,12 +4225,11 @@ var LatLng = class LatLng {
4226
4225
  * @returns {boolean}
4227
4226
  */
4228
4227
  static validate(lat, lng, alt) {
4229
- if (lat instanceof LatLng || typeof lat === "object" && lat !== null && "lat" in lat) return true;
4230
- else if (lat && Array.isArray(lat) && typeof lat[0] !== "object") {
4231
- if (lat.length === 3 || lat.length === 2) return true;
4228
+ try {
4229
+ return !!new LatLng(lat, lng, alt);
4230
+ } catch {
4232
4231
  return false;
4233
- } else if ((lat || lat === 0) && (lng || lng === 0)) return true;
4234
- return false;
4232
+ }
4235
4233
  }
4236
4234
  /**
4237
4235
  * Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.
@@ -4621,6 +4619,7 @@ function pointToGeoJSON(layer, precision) {
4621
4619
  });
4622
4620
  }
4623
4621
  // src/layer/vector/CircleMarker.js
4622
+ /** @import {MaplairMap} from '../../map/Map.js' */
4624
4623
  /** @import {Feature} from 'geojson' */
4625
4624
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
4626
4625
  /** @import {MaplairEvent} from '../../core/Events.js' */
@@ -4665,6 +4664,13 @@ var CircleMarker = class CircleMarker extends Path {
4665
4664
  this.callInitHooks(CircleMarker);
4666
4665
  }
4667
4666
  /**
4667
+ * @param {MaplairMap} map
4668
+ */
4669
+ beforeAdd(map) {
4670
+ super.beforeAdd(map);
4671
+ map._displaceHandler?._beforeMarkerAdd(this);
4672
+ }
4673
+ /**
4668
4674
  * Sets the position of a circle marker to a new location.
4669
4675
  * @param {LatLngExpression} latlng
4670
4676
  * @returns {this}
@@ -4712,7 +4718,7 @@ var CircleMarker = class CircleMarker extends Path {
4712
4718
  return this;
4713
4719
  }
4714
4720
  _project() {
4715
- this._point = this._map.latLngToLayerPoint(this._latlng)._round();
4721
+ this._point = this._renderer._latLngToLayerPoint(this._latlng)._round();
4716
4722
  this._pxRadius = this._radius;
4717
4723
  this._updateBounds();
4718
4724
  }
@@ -5189,13 +5195,7 @@ var Transformation = class {
5189
5195
  * @param {number} [d]
5190
5196
  */
5191
5197
  constructor(a, b, c, d) {
5192
- if (Array.isArray(a)) {
5193
- this._a = a[0];
5194
- this._b = a[1];
5195
- this._c = a[2];
5196
- this._d = a[3];
5197
- return;
5198
- }
5198
+ if (Array.isArray(a)) [a, b, c, d] = a;
5199
5199
  this._a = a;
5200
5200
  this._b = b;
5201
5201
  this._c = c;
@@ -5339,10 +5339,10 @@ var PosAnimation = class PosAnimation extends Evented {
5339
5339
  * @property {string} [position='topleft'] The position of the control (one of the map
5340
5340
  * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
5341
5341
  * `'bottomright'`.
5342
- * @property {string} [zoomInText='<span aria-hidden="true">+</span>'] The text set on
5343
- * the 'zoom in' button.
5344
- * @property {string} [zoomOutText='<span aria-hidden="true">&#x2212;</span>'] The text
5345
- * set on the 'zoom out' button.
5342
+ * @property {string} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn
5343
+ * in SVG by default.
5344
+ * @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign
5345
+ * drawn in SVG by default.
5346
5346
  * @extends ControlOptions
5347
5347
  */
5348
5348
  /**
@@ -5366,8 +5366,8 @@ var PosAnimation = class PosAnimation extends Evented {
5366
5366
  var ZoomControl = class ZoomControl extends Control {
5367
5367
  static defaultOptions = {
5368
5368
  position: "topleft",
5369
- zoomInText: "<span aria-hidden=\"true\">+</span>",
5370
- zoomOutText: "<span aria-hidden=\"true\">&#x2212;</span>"
5369
+ zoomInText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12M6 0v12\"/></svg>",
5370
+ zoomOutText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12\"/></svg>"
5371
5371
  };
5372
5372
  /**
5373
5373
  * Creates a zoom control.
@@ -5379,23 +5379,24 @@ var ZoomControl = class ZoomControl extends Control {
5379
5379
  }
5380
5380
  /**
5381
5381
  * @internal
5382
- * @param {MaplairMap} map
5383
5382
  * @returns {HTMLElement}
5384
5383
  */
5385
- onAdd(map) {
5384
+ onAdd() {
5386
5385
  const zoomName = "maplair-control-zoom", container = create("div", `${zoomName} maplair-bar`), options = this.options;
5387
5386
  this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, (e) => this._zoom(e, 1));
5388
5387
  this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, (e) => this._zoom(e, -1));
5389
5388
  this._updateDisabled();
5390
- map.on("zoomend zoomlevelschange", this._updateDisabled, this);
5391
5389
  return container;
5392
5390
  }
5393
5391
  /**
5394
5392
  * @internal
5395
- * @param {MaplairMap} map
5393
+ * @returns {Record<string, Function>}
5396
5394
  */
5397
- onRemove(map) {
5398
- map.off("zoomend zoomlevelschange", this._updateDisabled, this);
5395
+ getEvents() {
5396
+ return {
5397
+ zoomend: this._updateDisabled,
5398
+ zoomlevelschange: this._updateDisabled
5399
+ };
5399
5400
  }
5400
5401
  /**
5401
5402
  * Disables the zoom buttons.
@@ -5432,7 +5433,6 @@ var ZoomControl = class ZoomControl extends Control {
5432
5433
  on(link, "click", (e) => {
5433
5434
  stop(e);
5434
5435
  fn.call(this, e);
5435
- this._refocusOnMap(e);
5436
5436
  });
5437
5437
  return link;
5438
5438
  }
@@ -5752,9 +5752,12 @@ var FeatureGroup = class FeatureGroup extends LayerGroup {
5752
5752
  /** @import {EventListener, MaplairEvent} from '../core/Events.js' */
5753
5753
  /**
5754
5754
  * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an
5755
- * `HTMLElement`, or a function receiving the source layer and returning one of them.
5756
- * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent
5755
+ * `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and
5756
+ * returning one of them.
5757
+ * @typedef {string|HTMLElement|DocumentFragment|
5758
+ * ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent
5757
5759
  */
5760
+ const fragmentNodes = /* @__PURE__ */ new WeakMap();
5758
5761
  /**
5759
5762
  * Options of `DivOverlay`.
5760
5763
  * @typedef {object} DivOverlayOptions
@@ -5770,8 +5773,8 @@ var FeatureGroup = class FeatureGroup extends LayerGroup {
5770
5773
  * in the DOM (for styling and events).
5771
5774
  * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while
5772
5775
  * initializing. If a function is passed the source layer will be passed to the
5773
- * function. The function should return a `String` or `HTMLElement` to be used in the
5774
- * overlay. String content is rendered as HTML; sanitize untrusted input or pass an
5776
+ * function. The function should return a `String`, `HTMLElement` or `DocumentFragment`
5777
+ * to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an
5775
5778
  * `HTMLElement` with safe `textContent` instead.
5776
5779
  * @extends InteractiveLayerOptions
5777
5780
  */
@@ -5803,7 +5806,8 @@ const layerDivOverlayMethods = { _initOverlay(OverlayClass, old, content, option
5803
5806
  } };
5804
5807
  /** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */
5805
5808
  /**
5806
- * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.
5809
+ * Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit
5810
+ * from it for custom overlays like plugins.
5807
5811
  *
5808
5812
  * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
5809
5813
  */
@@ -5880,8 +5884,7 @@ var DivOverlay = class DivOverlay extends Layer {
5880
5884
  else {
5881
5885
  if (arguments.length) this._source = layer;
5882
5886
  else layer = this._source;
5883
- this._prepareOpen();
5884
- this.openOn(layer._map);
5887
+ if (this._prepareOpen()) this.openOn(layer._map);
5885
5888
  }
5886
5889
  return this;
5887
5890
  }
@@ -5893,7 +5896,7 @@ var DivOverlay = class DivOverlay extends Layer {
5893
5896
  if (!this._container) this._initLayout();
5894
5897
  if (map._fadeAnimated) this._container.style.opacity = "0";
5895
5898
  clearTimeout(this._removeTimeout);
5896
- this.getPane().appendChild(this._container);
5899
+ this.getPane().append(this._container);
5897
5900
  if (this.options.overflow) {
5898
5901
  this._container.classList.add("maplair-overflow");
5899
5902
  this._container.popover = "manual";
@@ -5966,9 +5969,10 @@ var DivOverlay = class DivOverlay extends Layer {
5966
5969
  /**
5967
5970
  * Sets the HTML content of the overlay. A `String` argument is rendered as
5968
5971
  * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)
5969
- * or pass an `HTMLElement` with safe `textContent` instead. If a function is
5970
- * passed the source layer will be passed to the function. The function should
5971
- * return a `String` or `HTMLElement` to be used in the overlay.
5972
+ * or pass an `HTMLElement` with safe `textContent` instead. A `DocumentFragment`
5973
+ * can be passed as well. If a function is passed the source layer will be passed
5974
+ * to the function. The function should return a `String`, `HTMLElement` or
5975
+ * `DocumentFragment` to be used in the overlay.
5972
5976
  * @param {DivOverlayContent} content
5973
5977
  * @returns {this}
5974
5978
  */
@@ -6016,7 +6020,7 @@ var DivOverlay = class DivOverlay extends Layer {
6016
6020
  * @returns {boolean}
6017
6021
  */
6018
6022
  isOpen() {
6019
- return !!this._map && this._map.hasLayer(this);
6023
+ return !!this._map?.hasLayer(this);
6020
6024
  }
6021
6025
  /**
6022
6026
  * Brings this overlay in front of other overlays (in the same map pane).
@@ -6060,25 +6064,21 @@ var DivOverlay = class DivOverlay extends Layer {
6060
6064
  if (!source) return false;
6061
6065
  this._source = source;
6062
6066
  }
6063
- if (!latlng) {
6064
- if (source.getCenter) latlng = source.getCenter();
6065
- else if (source.getLatLng) latlng = source.getLatLng();
6066
- else if (source.getBounds) latlng = source.getBounds().getCenter();
6067
- else throw new Error("Unable to get source layer LatLng.");
6068
- }
6067
+ latlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();
6068
+ if (!latlng) throw new Error("Unable to get source layer LatLng.");
6069
6069
  this.setLatLng(latlng);
6070
6070
  if (this._map) this.update();
6071
6071
  return true;
6072
6072
  }
6073
6073
  _updateContent() {
6074
- if (!this._content) return;
6074
+ if (this._content == null) return;
6075
6075
  const node = this._contentNode;
6076
6076
  const content = typeof this._content === "function" ? this._content(this._source ?? this) : this._content;
6077
6077
  if (typeof content === "string") node.innerHTML = content;
6078
- else {
6079
- while (node.hasChildNodes()) node.removeChild(node.firstChild);
6080
- node.appendChild(content);
6081
- }
6078
+ else if (content instanceof DocumentFragment) {
6079
+ if (content.hasChildNodes()) fragmentNodes.set(content, [...content.childNodes]);
6080
+ node.replaceChildren(...fragmentNodes.get(content) ?? []);
6081
+ } else node.replaceChildren(content);
6082
6082
  this.fire("contentupdate");
6083
6083
  }
6084
6084
  _updatePosition() {
@@ -6229,7 +6229,7 @@ const layerPopupMethods = {
6229
6229
  * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
6230
6230
  * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
6231
6231
  * it will receive the layer as the first argument and should return a
6232
- * `String` or `HTMLElement`.
6232
+ * `String`, `HTMLElement` or `DocumentFragment`.
6233
6233
  * @group Popup methods
6234
6234
  * @param {DivOverlayContent|Popup} content
6235
6235
  * @param {PopupOptions} [options]
@@ -6237,6 +6237,7 @@ const layerPopupMethods = {
6237
6237
  */
6238
6238
  bindPopup(content, options) {
6239
6239
  this._popup = this._initOverlay(Popup, this._popup, content, options);
6240
+ this._popup._updateSourceAria(this._popup.isOpen());
6240
6241
  this.on({
6241
6242
  click: this._openPopup,
6242
6243
  remove: this.closePopup,
@@ -6256,6 +6257,9 @@ const layerPopupMethods = {
6256
6257
  remove: this.closePopup,
6257
6258
  move: this._movePopup
6258
6259
  });
6260
+ const el = this.getElement?.();
6261
+ el?.removeAttribute("aria-expanded");
6262
+ el?.removeAttribute("aria-controls");
6259
6263
  this._popup = null;
6260
6264
  }
6261
6265
  return this;
@@ -6324,9 +6328,8 @@ const layerPopupMethods = {
6324
6328
  if (!this._popup || !this._map) return;
6325
6329
  stopPropagation(e);
6326
6330
  const target = e.propagatedFrom ?? e.target;
6327
- if (this._popup._source === target && !(target instanceof Path)) {
6328
- if (this._map.hasLayer(this._popup)) this.closePopup();
6329
- else this.openPopup(e.latlng);
6331
+ if (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {
6332
+ this.closePopup();
6330
6333
  return;
6331
6334
  }
6332
6335
  this._popup._source = target;
@@ -6423,9 +6426,11 @@ var Popup = class Popup extends DivOverlay {
6423
6426
  */
6424
6427
  openOn(map) {
6425
6428
  map = arguments.length ? map : this._source._map;
6426
- if (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) map.removeLayer(map._popup);
6429
+ if (!map.hasLayer(this) && map._popup?.options.autoClose) map.removeLayer(map._popup);
6427
6430
  map._popup = this;
6428
- return super.openOn(map);
6431
+ super.openOn(map);
6432
+ this._updateSourceAria(true);
6433
+ return this;
6429
6434
  }
6430
6435
  /**
6431
6436
  * Adds the popup to the map.
@@ -6440,9 +6445,10 @@ var Popup = class Popup extends DivOverlay {
6440
6445
  (this._closeButton ?? this._container).focus({ preventScroll: true });
6441
6446
  }
6442
6447
  map.fire("popupopen", { popup: this });
6448
+ this._updateSourceAria(true);
6443
6449
  if (this._source) {
6444
6450
  this._source.fire("popupopen", { popup: this }, true);
6445
- if (!(this._source instanceof Path)) this._source.on("preclick", stopPropagation);
6451
+ if (this._source._togglesPopupOnClick()) this._source.on("preclick", stopPropagation);
6446
6452
  }
6447
6453
  }
6448
6454
  /**
@@ -6450,13 +6456,17 @@ var Popup = class Popup extends DivOverlay {
6450
6456
  * @param {MaplairMap} map
6451
6457
  */
6452
6458
  onRemove(map) {
6453
- if (this._container.contains(document.activeElement) && this._returnFocus?.isConnected) this._returnFocus.focus({ preventScroll: true });
6459
+ if (this._container.contains(document.activeElement)) {
6460
+ const el = this._source?.getElement?.();
6461
+ (this._returnFocus?.isConnected ? this._returnFocus : el?.tabIndex >= 0 ? el : map._container).focus({ preventScroll: true });
6462
+ }
6454
6463
  this._returnFocus = null;
6455
6464
  super.onRemove(map);
6456
6465
  map.fire("popupclose", { popup: this });
6466
+ this._updateSourceAria(false);
6457
6467
  if (this._source) {
6458
6468
  this._source.fire("popupclose", { popup: this }, true);
6459
- if (!(this._source instanceof Path)) this._source.off("preclick", stopPropagation);
6469
+ if (this._source._togglesPopupOnClick()) this._source.off("preclick", stopPropagation);
6460
6470
  }
6461
6471
  }
6462
6472
  /**
@@ -6469,8 +6479,17 @@ var Popup = class Popup extends DivOverlay {
6469
6479
  if (this.options.keepInView) events.moveend = this._adjustPan;
6470
6480
  return events;
6471
6481
  }
6482
+ _updateSourceAria(open) {
6483
+ this._ariaSource?.setAttribute("aria-expanded", "false");
6484
+ this._ariaSource?.removeAttribute("aria-controls");
6485
+ const el = this._source?.getElement?.();
6486
+ this._ariaSource = el?.getAttribute("role") === "button" ? el : null;
6487
+ this._ariaSource?.setAttribute("aria-expanded", String(open));
6488
+ if (open) this._ariaSource?.setAttribute("aria-controls", this._container.id);
6489
+ }
6472
6490
  _initLayout() {
6473
6491
  const prefix = "maplair-popup", container = this._container = create("div", `${prefix} ${this.options.className || ""} maplair-zoom-animated`);
6492
+ container.id = `maplair-popup-${stamp(this)}`;
6474
6493
  const wrapper = this._wrapper = create("div", `${prefix}-content-wrapper`, container);
6475
6494
  this._contentNode = create("div", `${prefix}-content`, wrapper);
6476
6495
  disableClickPropagation(container);
@@ -6482,7 +6501,7 @@ var Popup = class Popup extends DivOverlay {
6482
6501
  const closeButton = this._closeButton = create("button", `${prefix}-close-button`, container);
6483
6502
  closeButton.type = "button";
6484
6503
  closeButton.setAttribute("aria-label", I18n.translate("Close popup"));
6485
- closeButton.innerHTML = "<span aria-hidden=\"true\">&#215;</span>";
6504
+ closeButton.textContent = "×";
6486
6505
  on(closeButton, "click", (ev) => {
6487
6506
  ev.preventDefault();
6488
6507
  this.close();
@@ -6550,13 +6569,13 @@ var Popup = class Popup extends DivOverlay {
6550
6569
  }
6551
6570
  };
6552
6571
  // src/layer/Tooltip.js
6553
- const directions = [
6554
- "top",
6555
- "bottom",
6556
- "center",
6557
- "right",
6558
- "left"
6559
- ];
6572
+ const directions = {
6573
+ top: [.5, 1],
6574
+ bottom: [.5, 0],
6575
+ center: [.5, .5],
6576
+ right: [0, .5],
6577
+ left: [1, .5]
6578
+ };
6560
6579
  const tipSize = 6;
6561
6580
  const autoPadding = 4;
6562
6581
  function shiftInto(start, size, min, max) {
@@ -6649,7 +6668,7 @@ const layerTooltipMethods = {
6649
6668
  * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
6650
6669
  * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
6651
6670
  * it will receive the layer as the first argument and should return a
6652
- * `String` or `HTMLElement`.
6671
+ * `String`, `HTMLElement` or `DocumentFragment`.
6653
6672
  * @group Tooltip methods
6654
6673
  * @param {DivOverlayContent|Tooltip} content
6655
6674
  * @param {TooltipOptions} [options]
@@ -6660,7 +6679,7 @@ const layerTooltipMethods = {
6660
6679
  if (this._tooltip) this.unbindTooltip();
6661
6680
  this._tooltip = this._initOverlay(Tooltip, old, content, options);
6662
6681
  this._initTooltipInteractions();
6663
- if (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) this.openTooltip();
6682
+ if (this._tooltip.options.permanent && this._map?.hasLayer(this)) this.openTooltip();
6664
6683
  return this;
6665
6684
  },
6666
6685
  /**
@@ -6702,11 +6721,7 @@ const layerTooltipMethods = {
6702
6721
  openTooltip(latlng) {
6703
6722
  if (this._tooltip) {
6704
6723
  if (!(this instanceof FeatureGroup)) this._tooltip._source = this;
6705
- if (this._tooltip._prepareOpen(latlng)) {
6706
- this._tooltip.openOn(this._map);
6707
- if (this.getElement) this._setAriaDescribedByOnLayer(this);
6708
- else if (this.eachLayer) this.eachLayer(this._setAriaDescribedByOnLayer, this);
6709
- }
6724
+ if (this._tooltip._prepareOpen(latlng)) this._tooltip.openOn(this._map);
6710
6725
  }
6711
6726
  return this;
6712
6727
  },
@@ -6767,7 +6782,7 @@ const layerTooltipMethods = {
6767
6782
  if (!remove) {
6768
6783
  el._maplair_focus_handler && off(el, "focus", el._maplair_focus_handler, this);
6769
6784
  el._maplair_focus_handler = () => {
6770
- if (this._tooltip) {
6785
+ if (this._tooltip && el.matches(":focus-visible")) {
6771
6786
  this._tooltip._source = layer;
6772
6787
  this.openTooltip();
6773
6788
  }
@@ -6778,9 +6793,6 @@ const layerTooltipMethods = {
6778
6793
  if (remove) delete el._maplair_focus_handler;
6779
6794
  }
6780
6795
  },
6781
- _setAriaDescribedByOnLayer(layer) {
6782
- (typeof layer.getElement === "function" && layer.getElement())?.setAttribute?.("aria-describedby", this._tooltip._container.id);
6783
- },
6784
6796
  _openTooltip(e) {
6785
6797
  if (!this._tooltip || !this._map) return;
6786
6798
  if (this._map.dragging?.moving()) {
@@ -6797,13 +6809,7 @@ const layerTooltipMethods = {
6797
6809
  this.openTooltip(this._tooltip.options.sticky ? e.latlng : void 0);
6798
6810
  },
6799
6811
  _moveTooltip(e) {
6800
- let latlng = e.latlng, containerPoint, layerPoint;
6801
- if (this._tooltip.options.sticky && e.originalEvent) {
6802
- containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
6803
- layerPoint = this._map.containerPointToLayerPoint(containerPoint);
6804
- latlng = this._map.layerPointToLatLng(layerPoint);
6805
- }
6806
- this._tooltip.setLatLng(latlng);
6812
+ this._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ? this._map.pointerEventToLatLng(e.originalEvent) : e.latlng);
6807
6813
  }
6808
6814
  };
6809
6815
  /** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */
@@ -6892,6 +6898,7 @@ var Tooltip = class Tooltip extends DivOverlay {
6892
6898
  map.fire("tooltipopen", { tooltip: this });
6893
6899
  if (this._source) {
6894
6900
  this.addEventParent(this._source);
6901
+ this._source.getElement?.()?.setAttribute("aria-describedby", this._container.id);
6895
6902
  this._source.fire("tooltipopen", { tooltip: this }, true);
6896
6903
  }
6897
6904
  }
@@ -6920,7 +6927,7 @@ var Tooltip = class Tooltip extends DivOverlay {
6920
6927
  const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-animated`;
6921
6928
  this._contentNode = this._container = create("div", className);
6922
6929
  this._container.setAttribute("role", "tooltip");
6923
- this._container.setAttribute("id", `maplair-tooltip-${stamp(this)}`);
6930
+ this._container.id = `maplair-tooltip-${stamp(this)}`;
6924
6931
  }
6925
6932
  _updateLayout() {}
6926
6933
  _adjustPan() {}
@@ -6935,21 +6942,16 @@ var Tooltip = class Tooltip extends DivOverlay {
6935
6942
  _setPosition(pos) {
6936
6943
  let direction = this.options.direction, shift = new Point(0, 0);
6937
6944
  const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset), anchor = this._getAnchor();
6938
- if (!directions.includes(direction)) {
6945
+ if (!(direction in directions)) {
6939
6946
  ({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));
6940
6947
  if (direction === "left") {
6941
6948
  offset.x = -offset.x;
6942
6949
  anchor.x = -anchor.x;
6943
6950
  }
6944
6951
  }
6945
- let subX = tooltipWidth / 2, subY = tooltipHeight / 2;
6946
- if (direction === "top") subY = tooltipHeight;
6947
- else if (direction === "bottom") subY = 0;
6948
- else if (direction === "right") subX = 0;
6949
- else if (direction === "left") subX = tooltipWidth;
6950
- pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor).add(shift);
6951
- container.classList.remove("maplair-tooltip-right", "maplair-tooltip-left", "maplair-tooltip-top", "maplair-tooltip-bottom");
6952
- container.classList.add(`maplair-tooltip-${direction}`);
6952
+ const [fx, fy] = directions[direction];
6953
+ pos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);
6954
+ for (const d in directions) container.classList.toggle(`maplair-tooltip-${d}`, d === direction);
6953
6955
  const tipShift = direction === "top" || direction === "bottom" ? clampTip(-shift.x, tooltipWidth) : clampTip(-shift.y, tooltipHeight);
6954
6956
  if (tipShift) container.style.setProperty("--maplair-tooltip-tip-shift", `${tipShift}px`);
6955
6957
  else container.style.removeProperty("--maplair-tooltip-tip-shift");
@@ -7065,7 +7067,8 @@ const mapRendererMethods = {
7065
7067
  * @lends MaplairMapOptions
7066
7068
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
7067
7069
  * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
7068
- * instead.
7070
+ * instead. Paths in custom panes get their own renderer for that pane, of the same
7071
+ * class and with the same options as this one.
7069
7072
  */
7070
7073
  /**
7071
7074
  * Registers `getRenderer()` and related methods on the given map class, called by
@@ -7194,12 +7197,14 @@ var BoxZoomHandler = class BoxZoomHandler extends Handler {
7194
7197
  */
7195
7198
  addHooks() {
7196
7199
  on(this._map._container, "pointerdown", this._onPointerDown, this);
7200
+ this._map._container.classList.add("maplair-box-zoom");
7197
7201
  }
7198
7202
  /**
7199
7203
  * Called when the handler is disabled, removes the event hooks.
7200
7204
  */
7201
7205
  removeHooks() {
7202
7206
  off(this._map._container, "pointerdown", this._onPointerDown, this);
7207
+ this._map._container.classList.remove("maplair-box-zoom");
7203
7208
  }
7204
7209
  /**
7205
7210
  * Returns `true` if a box has been drawn by the current or last interaction.
@@ -7412,13 +7417,13 @@ var Draggable = class Draggable extends Evented {
7412
7417
  }
7413
7418
  _onDown(e) {
7414
7419
  this._moved = false;
7415
- if (this._element.classList.contains("maplair-zoom-anim")) return;
7416
7420
  const pointers = getPointers().length;
7417
7421
  if (pointers > 1) {
7418
7422
  if (Draggable._dragging === this) this.finishDrag();
7419
7423
  return;
7420
7424
  }
7421
- if (Draggable._dragging || e.shiftKey || e.button !== 0 && e.pointerType !== "touch") return;
7425
+ const boxZoom = e.shiftKey && this._element.closest(".maplair-container")?.classList.contains("maplair-box-zoom");
7426
+ if (Draggable._dragging || boxZoom || e.button !== 0 && e.pointerType !== "touch") return;
7422
7427
  Draggable._dragging = this;
7423
7428
  disableImageDrag();
7424
7429
  if (this._moving) return;
@@ -7476,10 +7481,8 @@ var Draggable = class Draggable extends Evented {
7476
7481
  finishDrag(noInertia) {
7477
7482
  this._draggingContainer?.classList.remove("maplair-dragging");
7478
7483
  this._draggingContainer = null;
7479
- if (this._lastTarget) {
7480
- this._lastTarget.classList.remove("maplair-drag-target");
7481
- this._lastTarget = null;
7482
- }
7484
+ this._lastTarget?.classList.remove("maplair-drag-target");
7485
+ this._lastTarget = null;
7483
7486
  off(this._dragStartTarget, "pointermove", this._onMove, this);
7484
7487
  off(this._dragStartTarget, "pointerup pointercancel lostpointercapture", this._onUp, this);
7485
7488
  enableImageDrag();
@@ -7738,7 +7741,7 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
7738
7741
  const container = this._map._container;
7739
7742
  if (container.tabIndex <= 0) container.tabIndex = 0;
7740
7743
  const shortcuts = this._map.options.ariaKeyShortcuts;
7741
- if (shortcuts) container.ariaKeyShortcuts = shortcuts === true ? "ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -" : shortcuts;
7744
+ if (shortcuts) container.setAttribute("aria-keyshortcuts", shortcuts === true ? "ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -" : shortcuts);
7742
7745
  on(container, {
7743
7746
  focus: this._onFocus,
7744
7747
  blur: this._onBlur,
@@ -7794,7 +7797,7 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
7794
7797
  return help;
7795
7798
  }
7796
7799
  _onPointerDown() {
7797
- if (this._focused) return;
7800
+ if (this._focused || this._map._container.contains(document.activeElement)) return;
7798
7801
  this._map._container.focus({
7799
7802
  preventScroll: true,
7800
7803
  focusVisible: false
@@ -7812,11 +7815,9 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
7812
7815
  }
7813
7816
  _onContainerKeyDown(e) {
7814
7817
  const map = this._map, popup = map._popup;
7815
- if (e.key !== "Escape" || e.defaultPrevented || !popup?.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
7816
- const inPopup = popup._container.contains(e.target), icon = popup._source?._icon;
7818
+ if (e.key !== "Escape" || e.defaultPrevented || !popup?.isOpen() || !popup.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
7817
7819
  map.closePopup();
7818
7820
  e.preventDefault();
7819
- if (inPopup) (icon?.tabIndex >= 0 ? icon : map._container).focus();
7820
7821
  }
7821
7822
  _onKeyDown(e) {
7822
7823
  if (e.altKey || e.ctrlKey || e.metaKey) return;
@@ -7921,8 +7922,8 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
7921
7922
  this._moved = false;
7922
7923
  this._zooming = true;
7923
7924
  map._stop();
7924
- on(this._map._container, "pointermove", this._onPointerMove, this);
7925
- on(this._map._container, "pointerup pointercancel", this._onPointerEnd, this);
7925
+ on(map._container, "pointermove", this._onPointerMove, this);
7926
+ on(map._container, "pointerup pointercancel", this._onPointerEnd, this);
7926
7927
  e.preventDefault();
7927
7928
  }
7928
7929
  _onPointerMove(e) {
@@ -7945,10 +7946,7 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
7945
7946
  this._moved = true;
7946
7947
  }
7947
7948
  cancelAnimationFrame(this._animRequest);
7948
- const moveFn = map._move.bind(map, this._center, this._zoom, {
7949
- pinch: true,
7950
- round: false
7951
- }, void 0);
7949
+ const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
7952
7950
  this._animRequest = requestAnimationFrame(moveFn.bind(this));
7953
7951
  e.preventDefault();
7954
7952
  }
@@ -8101,10 +8099,7 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
8101
8099
  const frame = () => {
8102
8100
  const pinch = this._pinch, delta = pinch.zoom - pinch.shown;
8103
8101
  pinch.shown = eased && Math.abs(delta) > .01 ? pinch.shown + delta * .3 : pinch.zoom;
8104
- map._move(this._getPinchCenter(pinch.shown), pinch.shown, {
8105
- pinch: true,
8106
- round: false
8107
- });
8102
+ map._move(this._getPinchCenter(pinch.shown), pinch.shown, { pinch: true });
8108
8103
  if (pinch.shown !== pinch.zoom) this._pinchFrame = requestAnimationFrame(frame);
8109
8104
  };
8110
8105
  cancelAnimationFrame(this._pinchFrame);
@@ -8168,9 +8163,9 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
8168
8163
  stop(e);
8169
8164
  }
8170
8165
  _performZoom() {
8171
- const map = this._map, zoom = map.getZoom(), snap = this._map.options.zoomSnap ?? 0;
8166
+ const map = this._map, zoom = map.getZoom(), snap = map.options.zoomSnap ?? 0;
8172
8167
  map._stop();
8173
- const d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4), d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2, d4 = snap ? Math.ceil(d3 / snap) * snap : d3, d5 = map._prefersReducedMotion() ? Math.min(d4, 1) : d4, delta = map._limitZoom(zoom + (this._delta > 0 ? d5 : -d5)) - zoom;
8168
+ const d2 = this._delta / (map.options.wheelPxPerZoomLevel * 4), d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2, d4 = snap ? Math.ceil(d3 / snap) * snap : d3, d5 = map._prefersReducedMotion() ? Math.min(d4, 1) : d4, delta = map._limitZoom(zoom + (this._delta > 0 ? d5 : -d5)) - zoom;
8174
8169
  this._delta = 0;
8175
8170
  this._startTime = null;
8176
8171
  if (!delta || map._zoomInputBlocked()) return;
@@ -8235,47 +8230,35 @@ var TapHoldHandler = class TapHoldHandler extends Handler {
8235
8230
  removeHooks() {
8236
8231
  off(this._map._container, "pointerdown", this._onDown, this);
8237
8232
  this._cancel();
8238
- this._cancelClickPrevent();
8239
8233
  this._stopPreventingNative();
8240
8234
  }
8241
8235
  _onDown(e) {
8242
8236
  clearTimeout(this._holdTimeout);
8243
8237
  if (getPointers().length !== 1 || e.pointerType === "mouse") return;
8244
- const el = this._map._container;
8245
- this._startPos = this._newPos = new Point(e.clientX, e.clientY);
8238
+ const el = this._map._container, start = new Point(e.clientX, e.clientY);
8246
8239
  this._holdTimeout = setTimeout((() => {
8247
8240
  this._cancel();
8248
- if (!this._isTapValid()) return;
8249
- on(el, "pointerup", preventDefault);
8250
- on(el, "pointerup pointercancel", this._cancelClickPrevent, this);
8241
+ const pointers = getPointers(), p = pointers[0];
8242
+ if (pointers.length !== 1 || start.distanceTo([p.clientX, p.clientY]) > this._map.options.tapTolerance) return;
8251
8243
  this._simulateEvent("contextmenu", e);
8252
8244
  el.addEventListener("contextmenu", stop, true);
8245
+ el.addEventListener("click", stop, true);
8253
8246
  el.addEventListener("pointerdown", this._stopPreventingNative, true);
8247
+ el.addEventListener("keydown", this._stopPreventingNative, true);
8254
8248
  }), tapHoldDelay);
8255
8249
  on(el, "pointerup pointercancel contextmenu", this._cancel, this);
8256
- on(el, "pointermove", this._onMove, this);
8257
- }
8258
- _cancelClickPrevent() {
8259
- const el = this._map._container;
8260
- off(el, "pointerup", preventDefault);
8261
- off(el, "pointerup pointercancel", this._cancelClickPrevent, this);
8262
8250
  }
8263
8251
  _stopPreventingNative = () => {
8264
8252
  const el = this._map._container;
8265
8253
  el.removeEventListener("contextmenu", stop, true);
8254
+ el.removeEventListener("click", stop, true);
8266
8255
  el.removeEventListener("pointerdown", this._stopPreventingNative, true);
8256
+ el.removeEventListener("keydown", this._stopPreventingNative, true);
8267
8257
  };
8268
8258
  _cancel() {
8269
8259
  clearTimeout(this._holdTimeout);
8270
8260
  const el = this._map._container;
8271
8261
  off(el, "pointerup pointercancel contextmenu", this._cancel, this);
8272
- off(el, "pointermove", this._onMove, this);
8273
- }
8274
- _onMove(e) {
8275
- this._newPos = new Point(e.clientX, e.clientY);
8276
- }
8277
- _isTapValid() {
8278
- return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
8279
8262
  }
8280
8263
  _simulateEvent(type, e) {
8281
8264
  const simulatedEvent = new MouseEvent(type, {
@@ -8416,10 +8399,7 @@ var TapDragZoomHandler = class TapDragZoomHandler extends Handler {
8416
8399
  this._moved = true;
8417
8400
  }
8418
8401
  cancelAnimationFrame(this._animRequest);
8419
- this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, {
8420
- pinch: true,
8421
- round: false
8422
- }));
8402
+ this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, { pinch: true }));
8423
8403
  e.preventDefault();
8424
8404
  }
8425
8405
  _onUp() {
@@ -8475,7 +8455,9 @@ const zoomAnimDuration = 250;
8475
8455
  * user tries to pan outside the view. To set the restriction dynamically, use
8476
8456
  * [`setMaxBounds`](#map-setmaxbounds) method.
8477
8457
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
8478
- * map. `SVG` or `Canvas` by default depending on browser support.
8458
+ * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
8459
+ * instead. Paths in custom panes get their own renderer for that pane, of the same
8460
+ * class and with the same options as this one.
8479
8461
  * @property {boolean} [zoomAnimation=true] Whether the map zoom animation is enabled.
8480
8462
  * @property {number} [zoomAnimationThreshold=4] Won't animate zoom if the zoom
8481
8463
  * difference exceeds this value (or 1 if the user prefers
@@ -8559,15 +8541,25 @@ const zoomAnimDuration = 250;
8559
8541
  /**
8560
8542
  * Options of the `MaplairMap` methods which modify the zoom level and the center.
8561
8543
  * @typedef {object} ZoomPanOptions
8544
+ * @property {boolean} [animate] Whether to animate the change: like `ZoomOptions.animate`
8545
+ * if the zoom level changes, and like `PanOptions.animate` otherwise. The `zoom` and
8546
+ * `pan` options can set it for each case separately.
8547
+ * @property {boolean} [reset] If `true`, the view is reset without animation.
8548
+ * @property {ZoomOptions} [zoom] Options for the zoom part of the change, taking
8549
+ * precedence over `animate`.
8550
+ * @property {PanOptions} [pan] Options for the pan part of the change, taking
8551
+ * precedence over `animate`.
8562
8552
  * @extends ZoomOptions, PanOptions
8563
8553
  */
8564
8554
  /**
8565
8555
  * Options of `MaplairMap.invalidateSize()`.
8566
8556
  * @typedef {object} InvalidateSizeOptions
8557
+ * @property {boolean} [animate=false] If `true`, the map pans to its new center with
8558
+ * animation.
8567
8559
  * @property {boolean} [pan=true] If `false`, panning will not occur.
8568
8560
  * @property {boolean} [debounceMoveend=false] If `true`, it will delay `moveend` event
8569
8561
  * so that it doesn't happen often even if the method is called many times in a row.
8570
- * @extends ZoomPanOptions
8562
+ * @extends PanOptions
8571
8563
  */
8572
8564
  /**
8573
8565
  * Padding options of `MaplairMap` methods, e.g. `panInside()`.
@@ -8615,7 +8607,9 @@ const zoomAnimDuration = 250;
8615
8607
  * pressing a key or clicking a zoom button) have an `originalEvent` property with the
8616
8608
  * DOM event that started the change. It is `undefined` for changes made by code (e.g.
8617
8609
  * `setView()`), which allows to tell them apart, e.g. to avoid feedback loops when
8618
- * synchronizing the view.
8610
+ * synchronizing the view. The `move` and `zoom` events also have `flyTo: true` on each
8611
+ * [`flyTo`](#map-flyto) animation frame, and `pinch: true` while the user pinch-zooms
8612
+ * the map.
8619
8613
  *
8620
8614
  * @example
8621
8615
  * ```js
@@ -8715,6 +8709,7 @@ var MaplairMap = class MaplairMap extends Evented {
8715
8709
  this._handlers = [];
8716
8710
  this._layers = {};
8717
8711
  this._zoomBoundLayers = {};
8712
+ this._canvases = [];
8718
8713
  this._sizeChanged = true;
8719
8714
  this._initContainer(id);
8720
8715
  this._initLayout();
@@ -8745,10 +8740,23 @@ var MaplairMap = class MaplairMap extends Evented {
8745
8740
  * @returns {this}
8746
8741
  */
8747
8742
  setView(center, zoom, options) {
8748
- zoom = zoom === void 0 ? this._zoom : this._limitZoom(zoom);
8743
+ zoom = zoom === void 0 ? this._targetZoom() : this._limitZoom(zoom);
8744
+ const targetCenter = center;
8749
8745
  center = this._limitCenter(new LatLng(center), zoom, this.options.maxBounds);
8750
8746
  options ??= {};
8751
8747
  this._stop();
8748
+ this._targetView = {
8749
+ center: targetCenter,
8750
+ zoom
8751
+ };
8752
+ if (this._animatingZoom) {
8753
+ this._pendingView = {
8754
+ center,
8755
+ zoom,
8756
+ options
8757
+ };
8758
+ return this;
8759
+ }
8752
8760
  if (this._loaded && !options.reset && options !== true) {
8753
8761
  if (options.animate !== void 0) {
8754
8762
  options.zoom = {
@@ -8761,12 +8769,12 @@ var MaplairMap = class MaplairMap extends Evented {
8761
8769
  ...options.pan
8762
8770
  };
8763
8771
  }
8764
- if (this._zoom !== zoom ? this._tryAnimatedZoom && this._tryAnimatedZoom(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan)) {
8772
+ if (this._zoom !== zoom ? this._tryAnimatedZoom?.(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan)) {
8765
8773
  clearTimeout(this._sizeTimer);
8766
8774
  return this;
8767
8775
  }
8768
8776
  }
8769
- this._resetView(center, zoom, options.pan?.noMoveStart);
8777
+ this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, zoom, options.pan?.noMoveStart);
8770
8778
  return this;
8771
8779
  }
8772
8780
  /**
@@ -8781,7 +8789,7 @@ var MaplairMap = class MaplairMap extends Evented {
8781
8789
  this._zoom = zoom;
8782
8790
  return this;
8783
8791
  }
8784
- return this.setView(this.getCenter(), zoom, { zoom: options });
8792
+ return this.setView(this._targetView?.center ?? this.getCenter(), zoom, { zoom: options });
8785
8793
  }
8786
8794
  /**
8787
8795
  * Increases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
@@ -8792,7 +8800,7 @@ var MaplairMap = class MaplairMap extends Evented {
8792
8800
  */
8793
8801
  zoomIn(delta, options) {
8794
8802
  delta ??= this.options.zoomDelta;
8795
- return this.setZoom(this._zoom + delta, options);
8803
+ return this.setZoom(this._targetZoom() + delta, options);
8796
8804
  }
8797
8805
  /**
8798
8806
  * Decreases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
@@ -8803,7 +8811,7 @@ var MaplairMap = class MaplairMap extends Evented {
8803
8811
  */
8804
8812
  zoomOut(delta, options) {
8805
8813
  delta ??= this.options.zoomDelta;
8806
- return this.setZoom(this._zoom - delta, options);
8814
+ return this.setZoom(this._targetZoom() - delta, options);
8807
8815
  }
8808
8816
  /**
8809
8817
  * Zooms the map while keeping a specified geographical point on the map
@@ -8825,7 +8833,7 @@ var MaplairMap = class MaplairMap extends Evented {
8825
8833
  bounds = bounds.getBounds ? bounds.getBounds() : LatLngBounds.from(bounds);
8826
8834
  const paddingTL = Point.from(options.paddingTopLeft || options.padding || [0, 0]), paddingBR = Point.from(options.paddingBottomRight || options.padding || [0, 0]);
8827
8835
  let zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR));
8828
- zoom = typeof options.maxZoom === "number" ? Math.min(options.maxZoom, zoom) : zoom;
8836
+ zoom = Math.min(options.maxZoom ?? Infinity, zoom);
8829
8837
  if (zoom === Infinity) return {
8830
8838
  center: bounds.getCenter(),
8831
8839
  zoom
@@ -8868,7 +8876,7 @@ var MaplairMap = class MaplairMap extends Evented {
8868
8876
  * @returns {this}
8869
8877
  */
8870
8878
  panTo(center, options) {
8871
- return this.setView(center, this._zoom, { pan: options });
8879
+ return this.setView(center, void 0, { pan: options });
8872
8880
  }
8873
8881
  /**
8874
8882
  * Pans the map by a given number of pixels (animated unless `animate: false` is passed,
@@ -8880,24 +8888,18 @@ var MaplairMap = class MaplairMap extends Evented {
8880
8888
  * @returns {this}
8881
8889
  */
8882
8890
  panBy(offset, options) {
8883
- offset = Point.from(offset).round();
8891
+ const { center = this.getCenter(), zoom = this._zoom } = this._targetView ?? {}, newCenter = this.unproject(this.project(center, zoom).add(Point.from(offset).round()), zoom);
8892
+ return this.setView(newCenter, zoom, { pan: options });
8893
+ }
8894
+ _panBy(offset, options) {
8884
8895
  options ??= {};
8885
- if (!offset.x && !offset.y) return this.fire("moveend");
8886
- const size = this.getSize();
8887
- if (options.animate !== true && !size.contains(offset)) {
8888
- const center = this.unproject(this.project(this.getCenter()).add(offset));
8889
- this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, this.getZoom());
8890
- return this;
8891
- }
8892
- if (!this._panAnim) {
8893
- this._panAnim = new PosAnimation();
8894
- this._panAnim.on({
8895
- "step": this._onPanTransitionStep,
8896
- "end": this._onPanTransitionEnd
8897
- }, this);
8898
- }
8896
+ if (!offset.x && !offset.y) return this._moveStart(false, true)._moveEnd(false);
8897
+ if (!this._panAnim) this._panAnim = new PosAnimation().on({
8898
+ step: this._onPanTransitionStep,
8899
+ end: this._onPanTransitionEnd
8900
+ }, this);
8899
8901
  if (!options.noMoveStart) this.fire("movestart");
8900
- const tooFarForReducedMotion = this._prefersReducedMotion() && !size.divideBy(2).contains(offset);
8902
+ const tooFarForReducedMotion = this._prefersReducedMotion() && !this.getSize().divideBy(2).contains(offset);
8901
8903
  if (options.animate === true || options.animate !== false && !tooFarForReducedMotion) {
8902
8904
  this._mapPane.classList.add("maplair-pan-anim");
8903
8905
  const newPos = this._getMapPanePos().subtract(offset).round();
@@ -8905,7 +8907,7 @@ var MaplairMap = class MaplairMap extends Evented {
8905
8907
  } else {
8906
8908
  this._rawPanBy(offset);
8907
8909
  this._wrapWorldCopy();
8908
- this.fire("move").fire("moveend");
8910
+ this.fire("move")._moveEnd(false);
8909
8911
  }
8910
8912
  return this;
8911
8913
  }
@@ -8929,9 +8931,14 @@ var MaplairMap = class MaplairMap extends Evented {
8929
8931
  }
8930
8932
  });
8931
8933
  if (options.animate !== true && this._prefersReducedMotion()) return this.setView(targetCenter, targetZoom, options);
8932
- this._stop();
8933
- targetZoom = targetZoom === void 0 ? this._zoom : this._limitZoom(targetZoom);
8934
+ targetZoom = targetZoom === void 0 ? this._targetZoom() : this._limitZoom(targetZoom);
8935
+ const requestedCenter = targetCenter;
8934
8936
  targetCenter = this._limitCenter(new LatLng(targetCenter), targetZoom, this.options.maxBounds);
8937
+ this._stop();
8938
+ this._targetView = {
8939
+ center: requestedCenter,
8940
+ zoom: targetZoom
8941
+ };
8935
8942
  const from = this.project(this.getCenter()), to = this.project(targetCenter), size = this.getSize(), startZoom = this._zoom;
8936
8943
  const w0 = Math.max(size.x, size.y), w1 = w0 * this.getZoomScale(startZoom, targetZoom), u1 = to.distanceTo(from) || 1, rho = 1.42, rho2 = rho * rho;
8937
8944
  function r(i) {
@@ -8945,7 +8952,7 @@ var MaplairMap = class MaplairMap extends Evented {
8945
8952
  function easeOut(t) {
8946
8953
  return 1 - (1 - t) ** 1.5;
8947
8954
  }
8948
- const start = Date.now(), S = (r(1) - r0) / rho, duration = options.duration ? 1e3 * options.duration : 1e3 * S * .8;
8955
+ const start = Date.now(), S = (r(1) - r0) / rho, duration = 1e3 * (options.duration || S * .8);
8949
8956
  const frame = () => {
8950
8957
  const t = (Date.now() - start) / duration, s = easeOut(t) * S;
8951
8958
  if (t <= 1) {
@@ -9097,8 +9104,8 @@ var MaplairMap = class MaplairMap extends Evented {
9097
9104
  }
9098
9105
  /**
9099
9106
  * Checks if the map container size changed and updates the map if so —
9100
- * call it after you've changed the map size dynamically, also animating
9101
- * pan by default. If `options.pan` is `false`, panning will not occur.
9107
+ * call it after you've changed the map size dynamically, also panning to
9108
+ * keep the center by default. If `options.pan` is `false`, panning will not occur.
9102
9109
  * If `options.debounceMoveend` is `true`, it will delay `moveend` event so
9103
9110
  * that it doesn't happen often even if the method is called many
9104
9111
  * times in a row. Passing `true` instead of options animates the panning.
@@ -9115,8 +9122,9 @@ var MaplairMap = class MaplairMap extends Evented {
9115
9122
  };
9116
9123
  const oldSize = this.getSize();
9117
9124
  this._sizeChanged = true;
9118
- this._lastCenter = null;
9119
- const newSize = this.getSize(), oldCenter = oldSize.divideBy(2).round(), newCenter = newSize.divideBy(2).round(), offset = oldCenter.subtract(newCenter);
9125
+ const newSize = this.getSize();
9126
+ if (!newSize.equals(oldSize)) this._lastCenter = null;
9127
+ const oldCenter = oldSize.divideBy(2).round(), newCenter = newSize.divideBy(2).round(), offset = oldCenter.subtract(newCenter);
9120
9128
  if (!offset.x && !offset.y) return this;
9121
9129
  if (options.animate && options.pan) this.panBy(offset);
9122
9130
  else {
@@ -9198,7 +9206,7 @@ var MaplairMap = class MaplairMap extends Evented {
9198
9206
  }
9199
9207
  _handleGeolocationResponse(pos) {
9200
9208
  if (!this._container._maplair_id) return;
9201
- const lat = pos.coords.latitude, lng = pos.coords.longitude, latlng = new LatLng(lat, lng), bounds = latlng.toBounds(pos.coords.accuracy * 2), options = this._locateOptions;
9209
+ const latlng = new LatLng(pos.coords.latitude, pos.coords.longitude), bounds = latlng.toBounds(pos.coords.accuracy * 2), options = this._locateOptions;
9202
9210
  if (options.setView) {
9203
9211
  const zoom = this.getBoundsZoom(bounds);
9204
9212
  this.setView(latlng, options.maxZoom ? Math.min(zoom, options.maxZoom) : zoom);
@@ -9232,7 +9240,7 @@ var MaplairMap = class MaplairMap extends Evented {
9232
9240
  */
9233
9241
  remove() {
9234
9242
  this._initEvents(true);
9235
- if (this.options.maxBounds) this.off("moveend", this._panInsideMaxBounds);
9243
+ this.off("moveend", this._panInsideMaxBounds);
9236
9244
  if (this._containerId !== this._container._maplair_id) throw new Error("Map container is being reused by another instance");
9237
9245
  delete this._container._maplair_id;
9238
9246
  delete this._containerId;
@@ -9331,7 +9339,7 @@ var MaplairMap = class MaplairMap extends Evented {
9331
9339
  bounds = LatLngBounds.from(bounds);
9332
9340
  padding = Point.from(padding ?? [0, 0]);
9333
9341
  let zoom = this.getZoom() ?? 0;
9334
- const min = this.getMinZoom(), max = this.getMaxZoom(), nw = bounds.getNorthWest(), se = bounds.getSouthEast(), size = this.getSize().subtract(padding), boundsSize = new Bounds(this.project(se, zoom), this.project(nw, zoom)).getSize(), snap = this.options.zoomSnap, scalex = size.x / boundsSize.x, scaley = size.y / boundsSize.y, scale = inside ? Math.max(scalex, scaley) : Math.min(scalex, scaley);
9342
+ const min = this.getMinZoom(), max = this.getMaxZoom(), nw = bounds.getNorthWest(), se = bounds.getSouthEast(), size = this.getSize().subtract(padding), boundsSize = new Bounds(this.project(se, zoom), this.project(nw, zoom)).getSize(), snap = this.options.zoomSnap, scalex = Math.max(size.x, 0) / boundsSize.x, scaley = Math.max(size.y, 0) / boundsSize.y, scale = inside ? Math.max(scalex, scaley) : Math.min(scalex, scaley);
9335
9343
  zoom = this.getScaleZoom(scale, zoom);
9336
9344
  if (snap) {
9337
9345
  zoom = Math.round(zoom / (snap / 100)) * (snap / 100);
@@ -9741,10 +9749,13 @@ var MaplairMap = class MaplairMap extends Evented {
9741
9749
  return this;
9742
9750
  }
9743
9751
  _moveEnd(zoomChanged) {
9752
+ if (!this._pendingView) this._targetView = null;
9744
9753
  if (zoomChanged) this.fire("zoomend");
9745
9754
  return this.fire("moveend");
9746
9755
  }
9747
9756
  _stop() {
9757
+ this._pendingView = null;
9758
+ this._targetView = null;
9748
9759
  cancelAnimationFrame(this._flyToFrame);
9749
9760
  cancelAnimationFrame(this._zoomAnimFrame);
9750
9761
  this._panAnim?.stop();
@@ -9801,13 +9812,14 @@ var MaplairMap = class MaplairMap extends Evented {
9801
9812
  _findEventTargets(e, type) {
9802
9813
  let targets = [], target, src = e.target, dragging = false;
9803
9814
  const isHover = type === "pointerout" || type === "pointerover";
9815
+ const canEndDrag = (type === "click" || type === "preclick") && e.detail > 0;
9804
9816
  while (src) {
9805
9817
  target = this._targets[stamp(src)];
9806
- if (target && (type === "click" || type === "preclick") && this._draggableMoved(target)) {
9818
+ if (target && canEndDrag && this._draggableMoved(target)) {
9807
9819
  dragging = true;
9808
9820
  break;
9809
9821
  }
9810
- if (target && target.listens(type, true)) {
9822
+ if (target?.listens(type, true)) {
9811
9823
  if (isHover && !isExternalTarget(src, e)) break;
9812
9824
  targets.push(target);
9813
9825
  if (isHover) break;
@@ -9826,8 +9838,23 @@ var MaplairMap = class MaplairMap extends Evented {
9826
9838
  }
9827
9839
  _handleDOMEvent(e) {
9828
9840
  const el = e.target;
9829
- if (!this._loaded || el["_maplair_disable_events"] || e.type === "click" && this._isClickDisabled(el)) return;
9830
- this._fireDOMEvent(e, e.type);
9841
+ if (e.type === "click") simulateDblclick(e, this._container);
9842
+ if (!this._loaded || e.type === "click" && this._isClickDisabled(el)) return;
9843
+ const type = e.type, move = type === "pointermove", hovered = this._hoveredCanvasLayer, skip = type === "pointerover" || type === "pointerout" || type.startsWith("key") || this._animatingZoom || move && this.dragging?.moving(), layer = skip ? void 0 : this._canvasLayerAt(e, type === "click"), leftMap = type === "pointerout" && !this._container.contains(e.relatedTarget);
9844
+ if (layer !== hovered && (move && !skip || leftMap)) {
9845
+ if (hovered) this._fireDOMEvent(e, "pointerout", [hovered]);
9846
+ this._container.classList.toggle("maplair-interactive", !!layer);
9847
+ this._hoveredCanvasLayer = layer;
9848
+ if (layer) this._fireDOMEvent(e, "pointerover", [layer]);
9849
+ }
9850
+ this._fireDOMEvent(e, type, layer && [layer]);
9851
+ }
9852
+ _canvasLayerAt(e, click) {
9853
+ for (let el = e.target; el !== this._container; el = el.parentNode) if (!el || el === this._controlContainer || this._targets[stamp(el)]) return;
9854
+ for (const renderer of this._canvases) {
9855
+ const layer = renderer._layerAt(e, click);
9856
+ if (layer) return layer;
9857
+ }
9831
9858
  }
9832
9859
  static _pointerEvents = [
9833
9860
  "click",
@@ -9838,7 +9865,7 @@ var MaplairMap = class MaplairMap extends Evented {
9838
9865
  ];
9839
9866
  _fireDOMEvent(e, type, canvasTargets) {
9840
9867
  if (type === "click") this._fireDOMEvent(e, "preclick", canvasTargets);
9841
- let targets = this._findEventTargets(e, type);
9868
+ let targets = canvasTargets && (type === "pointerover" || type === "pointerout") ? [] : this._findEventTargets(e, type);
9842
9869
  if (canvasTargets) targets = [...canvasTargets.filter((t) => t.listens(type, true)), ...targets];
9843
9870
  if (!targets.length) return;
9844
9871
  if (type === "contextmenu") e.preventDefault();
@@ -9926,17 +9953,17 @@ var MaplairMap = class MaplairMap extends Evented {
9926
9953
  _onPanTransitionEnd() {
9927
9954
  this._mapPane.classList.remove("maplair-pan-anim");
9928
9955
  this._wrapWorldCopy();
9929
- this.fire("moveend");
9956
+ this._moveEnd(false);
9930
9957
  }
9931
9958
  _tryAnimatedPan(center, options) {
9932
- const offset = this._getCenterOffset(center)._trunc();
9959
+ const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
9933
9960
  if (options?.animate !== true && !this.getSize().contains(offset)) return false;
9934
- this.panBy(offset, options);
9961
+ this._panBy(offset, options);
9935
9962
  return true;
9936
9963
  }
9937
9964
  _createAnimProxy() {
9938
9965
  this._proxy = create("div", "maplair-proxy maplair-zoom-animated");
9939
- this._panes.mapPane.appendChild(this._proxy);
9966
+ this._panes.mapPane.append(this._proxy);
9940
9967
  this.on("zoomanim", this._animateProxyZoom, this);
9941
9968
  this.on("load moveend", this._animMoveEnd, this);
9942
9969
  on(this._proxy, "transitionend", this._catchTransitionEnd, this);
@@ -9970,6 +9997,9 @@ var MaplairMap = class MaplairMap extends Evented {
9970
9997
  };
9971
9998
  this._flyToFrame = requestAnimationFrame(frame);
9972
9999
  }
10000
+ _targetZoom() {
10001
+ return this._targetView?.zoom ?? this._zoom;
10002
+ }
9973
10003
  _zoomInputBlocked() {
9974
10004
  return this._animatingZoom || Date.now() < this._instantZoomEnd;
9975
10005
  }
@@ -10013,11 +10043,16 @@ var MaplairMap = class MaplairMap extends Evented {
10013
10043
  if (!this._animatingZoom) return;
10014
10044
  this._mapPane?.classList.remove("maplair-zoom-anim");
10015
10045
  this._animatingZoom = false;
10016
- this._move(this._animateToCenter, this._animateToZoom, void 0, true);
10046
+ this._move(this.getCenter(), this._animateToZoom, void 0, true);
10017
10047
  if (this._tempFireZoomEvent) this.fire("zoom");
10018
10048
  delete this._tempFireZoomEvent;
10019
10049
  this.fire("move");
10020
10050
  this._moveEnd(true);
10051
+ const view = this._pendingView;
10052
+ if (view) {
10053
+ this._pendingView = null;
10054
+ this.setView(view.center, view.zoom, view.options);
10055
+ }
10021
10056
  }
10022
10057
  };
10023
10058
  for (const feature of [
@@ -10137,9 +10172,9 @@ var Polyline = class Polyline extends Path {
10137
10172
  closestLayerPoint(p) {
10138
10173
  p = Point.from(p);
10139
10174
  let minDistance = Infinity, minPoint = null, p1, p2;
10140
- const closest = _sqClosestPointOnSegment;
10141
- for (const points of this._parts) for (let i = 1, len = points.length; i < len; i++) {
10142
- p1 = points[i - 1];
10175
+ const closest = _sqClosestPointOnSegment, closed = this._isClosed();
10176
+ for (const points of this._parts) for (let i = closed ? 0 : 1, len = points.length; i < len; i++) {
10177
+ p1 = points[(i || len) - 1];
10143
10178
  p2 = points[i];
10144
10179
  const sqDist = closest(p, p1, p2, true);
10145
10180
  if (sqDist < minDistance) {
@@ -10212,7 +10247,7 @@ var Polyline = class Polyline extends Path {
10212
10247
  }
10213
10248
  _projectLatlngs(latlngs, result, projectedBounds) {
10214
10249
  if (latlngs[0] instanceof LatLng) {
10215
- const ring = latlngs.map((latlng) => this._map.latLngToLayerPoint(latlng));
10250
+ const ring = latlngs.map((latlng) => this._renderer._latLngToLayerPoint(latlng));
10216
10251
  ring.forEach((r) => projectedBounds.extend(r));
10217
10252
  result.push(ring);
10218
10253
  } else latlngs.forEach((latlng) => this._projectLatlngs(latlng, result, projectedBounds));
@@ -10220,24 +10255,21 @@ var Polyline = class Polyline extends Path {
10220
10255
  _clipPoints() {
10221
10256
  const bounds = this._renderer._bounds;
10222
10257
  this._parts = [];
10223
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
10258
+ if (!this._pxBounds?.intersects(bounds)) return;
10224
10259
  if (this.options.noClip) {
10225
10260
  this._parts = this._rings;
10226
10261
  return;
10227
10262
  }
10228
10263
  const parts = this._parts;
10229
- let i, j, k, len, len2, segment, points;
10230
- for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
10231
- points = this._rings[i];
10232
- for (j = 0, len2 = points.length; j < len2 - 1; j++) {
10233
- segment = clipSegment(points[j], points[j + 1], bounds, j);
10234
- if (!segment) continue;
10235
- parts[k] ??= [];
10236
- parts[k].push(segment[0]);
10237
- if (segment[1] !== points[j + 1] || j === len2 - 2) {
10238
- parts[k].push(segment[1]);
10239
- k++;
10240
- }
10264
+ let k = 0;
10265
+ for (const points of this._rings) for (let j = 0, len = points.length; j < len - 1; j++) {
10266
+ const segment = clipSegment(points[j], points[j + 1], bounds, j);
10267
+ if (!segment) continue;
10268
+ parts[k] ??= [];
10269
+ parts[k].push(segment[0]);
10270
+ if (segment[1] !== points[j + 1] || j === len - 2) {
10271
+ parts[k].push(segment[1]);
10272
+ k++;
10241
10273
  }
10242
10274
  }
10243
10275
  }
@@ -10254,17 +10286,13 @@ var Polyline = class Polyline extends Path {
10254
10286
  _updatePath() {
10255
10287
  this._renderer._updatePoly(this);
10256
10288
  }
10289
+ _isClosed() {
10290
+ return false;
10291
+ }
10257
10292
  _containsPoint(p, closed) {
10258
- let i, j, k, len, len2, part;
10259
10293
  const w = this._clickTolerance();
10260
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
10261
- for (i = 0, len = this._parts.length; i < len; i++) {
10262
- part = this._parts[i];
10263
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
10264
- if (!closed && j === 0) continue;
10265
- if (pointToSegmentDistance(p, part[k], part[j]) <= w) return true;
10266
- }
10267
- }
10294
+ if (!this._pxBounds?.contains(p)) return false;
10295
+ for (const part of this._parts) for (let j = closed ? 0 : 1, len = part.length; j < len; j++) if (pointToSegmentDistance(p, part[(j || len) - 1], part[j]) <= w) return true;
10268
10296
  return false;
10269
10297
  }
10270
10298
  /**
@@ -10461,10 +10489,10 @@ var Polygon = class Polygon extends Polyline {
10461
10489
  }
10462
10490
  _clipPoints() {
10463
10491
  let bounds = this._renderer._bounds;
10464
- const w = this.options.weight, p = new Point(w, w);
10492
+ const w = +this.options.weight || 0, p = new Point(w, w);
10465
10493
  bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
10466
10494
  this._parts = [];
10467
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
10495
+ if (!this._pxBounds?.intersects(bounds)) return;
10468
10496
  if (this.options.noClip) {
10469
10497
  this._parts = this._rings;
10470
10498
  return;
@@ -10477,16 +10505,15 @@ var Polygon = class Polygon extends Polyline {
10477
10505
  _updatePath() {
10478
10506
  this._renderer._updatePoly(this, true);
10479
10507
  }
10508
+ _isClosed() {
10509
+ return true;
10510
+ }
10480
10511
  _containsPoint(p) {
10481
- let inside = false, part, p1, p2, i, j, k, len, len2;
10482
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
10483
- for (i = 0, len = this._parts.length; i < len; i++) {
10484
- part = this._parts[i];
10485
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
10486
- p1 = part[j];
10487
- p2 = part[k];
10488
- if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) inside = !inside;
10489
- }
10512
+ let inside = false;
10513
+ if (!this._pxBounds?.contains(p)) return false;
10514
+ for (const part of this._parts) for (let j = 0, len = part.length, k = len - 1; j < len; k = j++) {
10515
+ const p1 = part[j], p2 = part[k];
10516
+ if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) inside = !inside;
10490
10517
  }
10491
10518
  return inside || super._containsPoint(p, true);
10492
10519
  }
@@ -10729,16 +10756,15 @@ var ScaleControl = class ScaleControl extends Control {
10729
10756
  onAdd(map) {
10730
10757
  const className = "maplair-control-scale", container = create("div", className), options = this.options;
10731
10758
  this._addScales(options, `${className}-line`, container);
10732
- map.on(options.updateWhenIdle ? "moveend" : "move", this._update, this);
10733
10759
  map.whenReady(this._update, this);
10734
10760
  return container;
10735
10761
  }
10736
10762
  /**
10737
10763
  * @internal
10738
- * @param {MaplairMap} map
10764
+ * @returns {Record<string, Function>}
10739
10765
  */
10740
- onRemove(map) {
10741
- map.off(this.options.updateWhenIdle ? "moveend" : "move", this._update, this);
10766
+ getEvents() {
10767
+ return { [this.options.updateWhenIdle ? "moveend" : "move"]: this._update };
10742
10768
  }
10743
10769
  _addScales(options, className, container) {
10744
10770
  if (options.metric) this._mScale = create("div", className, container);
@@ -10771,7 +10797,7 @@ var ScaleControl = class ScaleControl extends Control {
10771
10797
  }
10772
10798
  _updateScale(scale, text, ratio) {
10773
10799
  scale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;
10774
- scale.innerHTML = text;
10800
+ scale.textContent = text;
10775
10801
  }
10776
10802
  _getRoundNum(num) {
10777
10803
  const pow10 = 10 ** (`${Math.floor(num)}`.length - 1);
@@ -10878,25 +10904,26 @@ var Icon = class Icon extends Class {
10878
10904
  const img = this._createImg(src, oldIcon instanceof HTMLImageElement ? oldIcon : null);
10879
10905
  this._setIconStyles(img, name);
10880
10906
  if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
10907
+ else img.crossOrigin = null;
10881
10908
  return img;
10882
10909
  }
10883
10910
  _setIconStyles(img, name) {
10884
10911
  const options = this.options;
10885
- let sizeOption = options[`${name}Size`];
10886
- if (typeof sizeOption === "number") sizeOption = [sizeOption, sizeOption];
10887
- const size = Point.validate(sizeOption) && Point.from(sizeOption);
10888
- const anchorPosition = name === "shadow" && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
10889
- const anchor = Point.validate(anchorPosition) && Point.from(anchorPosition);
10912
+ const sizeOption = options[`${name}Size`];
10913
+ const [width, height] = (typeof sizeOption === "number" ? [sizeOption, sizeOption] : Array.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);
10914
+ const anchorOption = name === "shadow" && options.shadowAnchor || options.iconAnchor;
10915
+ const anchor = Point.validate(anchorOption) ? Point.from(anchorOption) : {
10916
+ x: Math.round(width / 2),
10917
+ y: Math.round(height / 2)
10918
+ };
10890
10919
  img.className = `maplair-marker-${name} ${options.className || ""}`;
10891
- if (anchor) {
10892
- img.style.marginLeft = `${-anchor.x}px`;
10893
- img.style.marginTop = `${-anchor.y}px`;
10894
- }
10895
- img.style.transformOrigin = anchor ? `${anchor.x}px ${anchor.y}px` : "0 0";
10896
- if (size) {
10897
- img.style.width = `${size.x}px`;
10898
- img.style.height = `${size.y}px`;
10899
- }
10920
+ const { style } = img;
10921
+ style.marginLeft = style.marginTop = style.width = style.height = "";
10922
+ if (!isNaN(anchor.x)) style.marginLeft = `${-anchor.x}px`;
10923
+ if (!isNaN(anchor.y)) style.marginTop = `${-anchor.y}px`;
10924
+ style.transformOrigin = !isNaN(anchor.x) && !isNaN(anchor.y) ? `${anchor.x}px ${anchor.y}px` : "0 0";
10925
+ if (!isNaN(width)) style.width = `${width}px`;
10926
+ if (!isNaN(height)) style.height = `${height}px`;
10900
10927
  }
10901
10928
  _createImg(src, el) {
10902
10929
  el ??= document.createElement("img");
@@ -11044,10 +11071,10 @@ var MarkerDrag = class MarkerDrag extends Handler {
11044
11071
  return this._draggable?._moved;
11045
11072
  }
11046
11073
  _adjustPan(e) {
11047
- const marker = this._marker, map = marker._map, speed = this._marker.options.autoPanSpeed, padding = this._marker.options.autoPanPadding, iconPos = getPosition(marker._icon), bounds = map.getPixelBounds(), origin = map.getPixelOrigin();
11048
- const panBounds = new Bounds(bounds.min._subtract(origin).add(padding), bounds.max._subtract(origin).subtract(padding));
11049
- if (!panBounds.contains(iconPos)) {
11050
- const movement = new Point((Math.max(panBounds.max.x, iconPos.x) - panBounds.max.x) / (bounds.max.x - panBounds.max.x) - (Math.min(panBounds.min.x, iconPos.x) - panBounds.min.x) / (bounds.min.x - panBounds.min.x), (Math.max(panBounds.max.y, iconPos.y) - panBounds.max.y) / (bounds.max.y - panBounds.max.y) - (Math.min(panBounds.min.y, iconPos.y) - panBounds.min.y) / (bounds.min.y - panBounds.min.y)).multiplyBy(speed);
11074
+ const marker = this._marker, map = marker._map, speed = this._marker.options.autoPanSpeed, padding = new Point(this._marker.options.autoPanPadding), iconPos = getPosition(marker._icon), bounds = map.getPixelBounds(), origin = map.getPixelOrigin(), min = bounds.min._subtract(origin)._add(padding), max = bounds.max._subtract(origin)._subtract(padding), dx = Math.max(iconPos.x - max.x, 0) + Math.min(iconPos.x - min.x, 0), dy = Math.max(iconPos.y - max.y, 0) + Math.min(iconPos.y - min.y, 0);
11075
+ if (dx || dy) {
11076
+ const movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed), map.options.maxBounds)._round();
11077
+ if (!movement.x && !movement.y) return;
11051
11078
  map.panBy(movement, { animate: false });
11052
11079
  this._draggable._newPos._add(movement);
11053
11080
  this._draggable._startPos._add(movement);
@@ -11068,7 +11095,8 @@ var MarkerDrag = class MarkerDrag extends Handler {
11068
11095
  }
11069
11096
  }
11070
11097
  _onDrag(e) {
11071
- const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos);
11098
+ const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos), { alt } = this._oldLatLng;
11099
+ if (alt !== void 0) latlng.alt = alt;
11072
11100
  marker._positionElements(iconPos);
11073
11101
  marker._latlng = latlng;
11074
11102
  e.latlng = latlng;
@@ -11077,7 +11105,6 @@ var MarkerDrag = class MarkerDrag extends Handler {
11077
11105
  }
11078
11106
  _onDragEnd(e) {
11079
11107
  cancelAnimationFrame(this._panRequest);
11080
- delete this._oldLatLng;
11081
11108
  this._marker.fire("moveend").fire("dragend", e);
11082
11109
  }
11083
11110
  /** @param {KeyboardEvent|FocusEvent} e */
@@ -11129,7 +11156,8 @@ var MarkerDrag = class MarkerDrag extends Handler {
11129
11156
  * @property {string} [title=''] Text for the browser tooltip that appear on marker hover
11130
11157
  * (no tooltip by default).
11131
11158
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
11132
- * @property {string} [alt='Marker'] Text for the `alt` attribute of the icon image.
11159
+ * @property {string} [alt] Text for the `alt` attribute of the icon image, the
11160
+ * translation of `'Marker'` by default.
11133
11161
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
11134
11162
  * @property {number} [zIndexOffset=0] By default, marker images zIndex is set
11135
11163
  * automatically based on its latitude. Use this option if you want to put the marker on
@@ -11141,9 +11169,9 @@ var MarkerDrag = class MarkerDrag extends Handler {
11141
11169
  * marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
11142
11170
  * under a tilted one. `null` means no rotation.
11143
11171
  * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
11144
- * others when you hover the pointer over it.
11145
- * @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`
11146
- * feature.
11172
+ * others while the pointer is over it. It always does while it has focus.
11173
+ * @property {number} [riseOffset=250] The z-index offset used when the marker gets on
11174
+ * top of others on hover or focus.
11147
11175
  * @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.
11148
11176
  * @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will
11149
11177
  * be added.
@@ -11196,7 +11224,7 @@ var Marker = class Marker extends Layer {
11196
11224
  interactive: true,
11197
11225
  keyboard: true,
11198
11226
  title: "",
11199
- alt: "Marker",
11227
+ alt: void 0,
11200
11228
  zIndexOffset: 0,
11201
11229
  opacity: 1,
11202
11230
  rotation: null,
@@ -11340,7 +11368,7 @@ var Marker = class Marker extends Layer {
11340
11368
  if (this._icon) this._removeIcon();
11341
11369
  addIcon = true;
11342
11370
  if (options.title) icon.title = options.title;
11343
- if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? "";
11371
+ if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? I18n.translate("Marker");
11344
11372
  }
11345
11373
  icon.classList.add(classToAdd);
11346
11374
  if (options.keyboard) {
@@ -11349,10 +11377,9 @@ var Marker = class Marker extends Layer {
11349
11377
  on(icon, "keydown", this._onKeyDown, this);
11350
11378
  }
11351
11379
  this._icon = icon;
11352
- if (options.riseOnHover) this.on({
11353
- pointerover: this._bringToFront,
11354
- pointerout: this._resetZIndex
11355
- });
11380
+ if (this._popup?._source === this) this._popup._updateSourceAria(this._popup.isOpen());
11381
+ on(icon, "focusin focusout", this._updateRise, this);
11382
+ if (options.riseOnHover) on(icon, "pointerover pointerout", this._updateRise, this);
11356
11383
  if (this.options.autoPanOnFocus) on(icon, "focus", this._panOnFocus, this);
11357
11384
  const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
11358
11385
  let addShadow = false;
@@ -11366,15 +11393,13 @@ var Marker = class Marker extends Layer {
11366
11393
  }
11367
11394
  this._shadow = newShadow;
11368
11395
  if (options.opacity < 1) this._updateOpacity();
11369
- if (addIcon) this.getPane().appendChild(this._icon);
11396
+ if (addIcon) this.getPane().append(this._icon);
11370
11397
  this._initInteraction();
11371
- if (newShadow && addShadow) this.getPane(options.shadowPane).appendChild(this._shadow);
11398
+ if (newShadow && addShadow) this.getPane(options.shadowPane).append(this._shadow);
11372
11399
  }
11373
11400
  _removeIcon() {
11374
- if (this.options.riseOnHover) this.off({
11375
- pointerover: this._bringToFront,
11376
- pointerout: this._resetZIndex
11377
- });
11401
+ off(this._icon, "pointerover pointerout focusin focusout", this._updateRise, this);
11402
+ this._hovered = this._focused = false;
11378
11403
  if (this.options.autoPanOnFocus) off(this._icon, "focus", this._panOnFocus, this);
11379
11404
  off(this._icon, "keydown", this._onKeyDown, this);
11380
11405
  this._icon.remove();
@@ -11387,8 +11412,8 @@ var Marker = class Marker extends Layer {
11387
11412
  if (visible === !this._culled) return;
11388
11413
  this._culled = !visible;
11389
11414
  if (visible) {
11390
- this.getPane().appendChild(this._icon);
11391
- if (this._shadow) this.getPane(this.options.shadowPane).appendChild(this._shadow);
11415
+ this.getPane().append(this._icon);
11416
+ if (this._shadow) this.getPane(this.options.shadowPane).append(this._shadow);
11392
11417
  this.update();
11393
11418
  } else {
11394
11419
  this._icon.remove();
@@ -11402,7 +11427,7 @@ var Marker = class Marker extends Layer {
11402
11427
  _setPos(pos) {
11403
11428
  this._positionElements(pos);
11404
11429
  this._zIndex = pos.y + this.options.zIndexOffset;
11405
- this._resetZIndex();
11430
+ this._updateRise();
11406
11431
  }
11407
11432
  _positionElements(pos) {
11408
11433
  const rotation = this.options.rotation;
@@ -11444,33 +11469,31 @@ var Marker = class Marker extends Layer {
11444
11469
  if (!this.options.interactive) return;
11445
11470
  this._icon.classList.add("maplair-interactive");
11446
11471
  this.addInteractiveTarget(this._icon);
11447
- if (MarkerDrag) {
11448
- if (this.dragging?._draggable?._element === this._icon) {
11449
- this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
11450
- return;
11451
- }
11452
- let draggable = this.options.draggable;
11453
- if (this.dragging) {
11454
- draggable = this.dragging.enabled();
11455
- this.dragging.disable();
11456
- }
11457
- /**
11458
- * Marker dragging handler, see `Handler`. Only valid when the marker is on the
11459
- * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
11460
- *
11461
- * Interaction handlers are properties of a marker instance that allow you to
11462
- * control interaction behavior in runtime, enabling or disabling certain
11463
- * features such as dragging (see `Handler` methods). Example:
11464
- *
11465
- * ```js
11466
- * marker.dragging.disable();
11467
- * ```
11468
- * @group Interaction handlers
11469
- * @type {MarkerDrag}
11470
- */
11471
- this.dragging = new MarkerDrag(this);
11472
- if (draggable) this.dragging.enable();
11472
+ if (this.dragging?._draggable?._element === this._icon) {
11473
+ this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
11474
+ return;
11473
11475
  }
11476
+ let draggable = this.options.draggable;
11477
+ if (this.dragging) {
11478
+ draggable = this.dragging.enabled();
11479
+ this.dragging.disable();
11480
+ }
11481
+ /**
11482
+ * Marker dragging handler, see `Handler`. Only valid when the marker is on the
11483
+ * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
11484
+ *
11485
+ * Interaction handlers are properties of a marker instance that allow you to
11486
+ * control interaction behavior in runtime, enabling or disabling certain
11487
+ * features such as dragging (see `Handler` methods). Example:
11488
+ *
11489
+ * ```js
11490
+ * marker.dragging.disable();
11491
+ * ```
11492
+ * @group Interaction handlers
11493
+ * @type {MarkerDrag}
11494
+ */
11495
+ this.dragging = new MarkerDrag(this);
11496
+ if (draggable) this.dragging.enable();
11474
11497
  }
11475
11498
  /**
11476
11499
  * Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
@@ -11504,9 +11527,13 @@ var Marker = class Marker extends Layer {
11504
11527
  return this;
11505
11528
  }
11506
11529
  _updateOpacity() {
11507
- const opacity = this.options.opacity;
11508
- if (this._icon) this._icon.style.opacity = `${opacity}`;
11509
- if (this._shadow) this._shadow.style.opacity = `${opacity}`;
11530
+ for (const el of [this._icon, this._shadow]) if (el) el.style.opacity = `${this.options.opacity}`;
11531
+ }
11532
+ _updateRise(e) {
11533
+ if (e?.type.startsWith("pointer")) this._hovered = e.type === "pointerover";
11534
+ else if (e) this._focused = e.type === "focusin";
11535
+ if (this._hovered || this._focused) this._bringToFront();
11536
+ else this._resetZIndex();
11510
11537
  }
11511
11538
  _bringToFront() {
11512
11539
  this._updateZIndex(this.options.riseOffset);
@@ -12130,8 +12157,9 @@ var SideBySideControl = class SideBySideControl extends Control {
12130
12157
  this.remove();
12131
12158
  this._map = map;
12132
12159
  this._container = this.onAdd(map);
12133
- map._container.appendChild(this._container);
12134
- map.on("unload", this.remove, this);
12160
+ map._container.append(this._container);
12161
+ this._mapEvents = { unload: this.remove };
12162
+ map.on(this._mapEvents, this);
12135
12163
  return this;
12136
12164
  }
12137
12165
  /**
@@ -13666,6 +13694,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
13666
13694
  onAdd() {
13667
13695
  if (!this._image) {
13668
13696
  this._initImage();
13697
+ this._updateZIndex();
13669
13698
  if (this.options.opacity < 1) this._updateOpacity();
13670
13699
  }
13671
13700
  if (this.options.interactive) {
@@ -13673,7 +13702,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
13673
13702
  this.addInteractiveTarget(this._image);
13674
13703
  }
13675
13704
  this._image.classList.toggle("maplair-pixelated", !!this.options.pixelated);
13676
- this.getPane().appendChild(this._image);
13705
+ this.getPane().append(this._image);
13677
13706
  this._reset();
13678
13707
  }
13679
13708
  /**
@@ -13706,7 +13735,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
13706
13735
  * @returns {this}
13707
13736
  */
13708
13737
  setStyle(styleOpts) {
13709
- if (styleOpts.opacity) this.setOpacity(styleOpts.opacity);
13738
+ if (styleOpts.opacity != null) this.setOpacity(styleOpts.opacity);
13710
13739
  return this;
13711
13740
  }
13712
13741
  /**
@@ -13792,7 +13821,6 @@ var ImageOverlay = class ImageOverlay extends Layer {
13792
13821
  img.onerror = this._overlayOnError.bind(this);
13793
13822
  if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
13794
13823
  img.decoding = this.options.decoding;
13795
- if (this.options.zIndex) this._updateZIndex();
13796
13824
  if (wasElementSupplied) {
13797
13825
  this._url = img.src;
13798
13826
  return;
@@ -13814,7 +13842,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
13814
13842
  this._image.style.opacity = `${this.options.opacity}`;
13815
13843
  }
13816
13844
  _updateZIndex() {
13817
- if (this._image && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._image.style.zIndex = `${this.options.zIndex}`;
13845
+ if (this._image && this.options.zIndex != null) this._image.style.zIndex = `${this.options.zIndex}`;
13818
13846
  }
13819
13847
  _overlayOnError() {
13820
13848
  this.fire("error");
@@ -13831,6 +13859,9 @@ var ImageOverlay = class ImageOverlay extends Layer {
13831
13859
  getCenter() {
13832
13860
  return this._bounds.getCenter();
13833
13861
  }
13862
+ _togglesPopupOnClick() {
13863
+ return false;
13864
+ }
13834
13865
  };
13835
13866
  // src/layer/VideoOverlay.js
13836
13867
  /** @import {ImageOverlayOptions} from './ImageOverlay.js' */
@@ -13911,7 +13942,7 @@ var VideoOverlay = class VideoOverlay extends ImageOverlay {
13911
13942
  return;
13912
13943
  }
13913
13944
  if (!Array.isArray(this._url)) this._url = [this._url];
13914
- if (!this.options.keepAspectRatio) vid.style["objectFit"] = "fill";
13945
+ if (!this.options.keepAspectRatio) vid.style.objectFit = "fill";
13915
13946
  vid.autoplay = !!this.options.autoplay;
13916
13947
  vid.controls = !!this.options.controls;
13917
13948
  vid.loop = !!this.options.loop;
@@ -13920,7 +13951,7 @@ var VideoOverlay = class VideoOverlay extends ImageOverlay {
13920
13951
  for (const url of this._url) {
13921
13952
  const source = create("source");
13922
13953
  source.src = url;
13923
- vid.appendChild(source);
13954
+ vid.append(source);
13924
13955
  }
13925
13956
  }
13926
13957
  };
@@ -14023,14 +14054,10 @@ var DivIcon = class DivIcon extends Icon {
14023
14054
  */
14024
14055
  createIcon(oldIcon) {
14025
14056
  const div = oldIcon instanceof HTMLDivElement ? oldIcon : document.createElement("div"), options = this.options;
14026
- if (options.html instanceof Element) {
14027
- div.replaceChildren();
14028
- div.appendChild(options.html);
14029
- } else div.innerHTML = options.html !== false ? options.html : "";
14030
- if (options.bgPos) {
14031
- const bgPos = Point.from(options.bgPos);
14032
- div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
14033
- }
14057
+ if (options.html instanceof Element) div.replaceChildren(options.html);
14058
+ else div.innerHTML = options.html !== false ? options.html : "";
14059
+ const bgPos = options.bgPos && Point.from(options.bgPos);
14060
+ div.style.backgroundPosition = bgPos ? `${-bgPos.x}px ${-bgPos.y}px` : "";
14034
14061
  this._setIconStyles(div, "icon");
14035
14062
  return div;
14036
14063
  }
@@ -14055,7 +14082,7 @@ const glyphSize = 230;
14055
14082
  function svgElement(name, attributes, parent) {
14056
14083
  const el = document.createElementNS(svgNS, name);
14057
14084
  for (const [key, value] of Object.entries(attributes)) el.setAttribute(key, value);
14058
- parent?.appendChild(el);
14085
+ parent?.append(el);
14059
14086
  return el;
14060
14087
  }
14061
14088
  /**
@@ -14500,10 +14527,10 @@ var MarkerClusterGroup = class MarkerClusterGroup extends FeatureGroup {
14500
14527
  * @typedef {(error: any, tile: HTMLElement) => void} TileDoneCallback
14501
14528
  */
14502
14529
  /**
14503
- * Generic class for handling a tiled grid of HTML elements. This is the base class for
14504
- * all tile layers and replaces `TileLayer.Canvas`. GridLayer can be extended to create
14505
- * a tiled grid of HTML elements like `<canvas>`, `<img>` or `<div>`. GridLayer will
14506
- * handle creating and animating these DOM elements for you.
14530
+ * Generic class for handling a tiled grid of HTML elements, and the base class of all
14531
+ * tile layers. To show map tiles from a URL, use `TileLayer` (or `WMSTileLayer`).
14532
+ * Extend `GridLayer` to create a tiled grid of your own elements like `<canvas>`,
14533
+ * `<img>` or `<div>`; it handles creating and animating them for you.
14507
14534
  *
14508
14535
  * Layers extending `GridLayer` shall reimplement the [`createTile()`](#gridlayer-createtile)
14509
14536
  * method.
@@ -14699,7 +14726,7 @@ var GridLayer = class GridLayer extends Layer {
14699
14726
  redraw() {
14700
14727
  if (this._map) {
14701
14728
  this._removeAllTiles();
14702
- const tileZoom = this._clampZoom(Math.round(this._map.getZoom()));
14729
+ const tileZoom = this._getTileZoom(this._map.getZoom());
14703
14730
  if (tileZoom !== this._tileZoom) {
14704
14731
  this._tileZoom = tileZoom;
14705
14732
  this._updateLevels();
@@ -14750,7 +14777,7 @@ var GridLayer = class GridLayer extends Layer {
14750
14777
  return s instanceof Point ? s : new Point(s, s);
14751
14778
  }
14752
14779
  _updateZIndex() {
14753
- if (this._container && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._container.style.zIndex = `${this.options.zIndex}`;
14780
+ if (this._container && this.options.zIndex != null) this._container.style.zIndex = `${this.options.zIndex}`;
14754
14781
  }
14755
14782
  _setAutoZIndex(compare) {
14756
14783
  const layers = this.getPane().children;
@@ -14775,7 +14802,7 @@ var GridLayer = class GridLayer extends Layer {
14775
14802
  this._container.classList.toggle("maplair-pixelated", !!this.options.pixelated);
14776
14803
  this._updateZIndex();
14777
14804
  if (this.options.opacity < 1) this._updateOpacity();
14778
- this.getPane().appendChild(this._container);
14805
+ this.getPane().append(this._container);
14779
14806
  }
14780
14807
  _keepCurrentTiles() {
14781
14808
  const zoom = this._tileZoom, level = this._levels?.[zoom];
@@ -14849,8 +14876,7 @@ var GridLayer = class GridLayer extends Layer {
14849
14876
  _onCreateLevel() {}
14850
14877
  _pruneTiles() {
14851
14878
  if (!this._map) return;
14852
- const zoom = this._map.getZoom();
14853
- if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
14879
+ if (this._getTileZoom(this._map.getZoom()) === void 0) {
14854
14880
  this._removeAllTiles();
14855
14881
  return;
14856
14882
  }
@@ -14905,6 +14931,11 @@ var GridLayer = class GridLayer extends Layer {
14905
14931
  _animateZoom(e) {
14906
14932
  this._setView(e.center, e.zoom, true, e.noUpdate);
14907
14933
  }
14934
+ _getTileZoom(zoom) {
14935
+ const { minZoom, maxZoom = Infinity } = this.options;
14936
+ if (zoom < minZoom || zoom > maxZoom) return;
14937
+ return this._clampZoom(Math.round(zoom));
14938
+ }
14908
14939
  _clampZoom(zoom) {
14909
14940
  const options = this.options;
14910
14941
  if (void 0 !== options.minNativeZoom && zoom < options.minNativeZoom) return options.minNativeZoom;
@@ -14912,13 +14943,11 @@ var GridLayer = class GridLayer extends Layer {
14912
14943
  return zoom;
14913
14944
  }
14914
14945
  _setView(center, zoom, noPrune, noUpdate) {
14915
- let tileZoom = Math.round(zoom);
14916
- if (this.options.maxZoom !== void 0 && tileZoom > this.options.maxZoom || this.options.minZoom !== void 0 && tileZoom < this.options.minZoom) tileZoom = void 0;
14917
- else tileZoom = this._clampZoom(tileZoom);
14946
+ const tileZoom = this._getTileZoom(zoom);
14918
14947
  const tileZoomChanged = this.options.updateWhenZooming && tileZoom !== this._tileZoom;
14919
14948
  if (!noUpdate || tileZoomChanged) {
14920
14949
  this._tileZoom = tileZoom;
14921
- if (this._abortLoading) this._abortLoading();
14950
+ this._abortLoading?.();
14922
14951
  this._updateLevels();
14923
14952
  this._resetGrid();
14924
14953
  if (tileZoom !== void 0) this._update(center);
@@ -14987,7 +15016,7 @@ var GridLayer = class GridLayer extends Layer {
14987
15016
  else queue.push(coords);
14988
15017
  }
14989
15018
  queue.sort((a, b) => a.distanceTo(tileCenter) - b.distanceTo(tileCenter));
14990
- if (queue.length !== 0) {
15019
+ if (queue.length) {
14991
15020
  if (!this._loading) {
14992
15021
  this._loading = true;
14993
15022
  this.fire("loading");
@@ -14995,7 +15024,7 @@ var GridLayer = class GridLayer extends Layer {
14995
15024
  }
14996
15025
  const fragment = document.createDocumentFragment();
14997
15026
  for (const q of queue) this._addTile(q, fragment);
14998
- this._level.el.appendChild(fragment);
15027
+ this._level.el.append(fragment);
14999
15028
  }
15000
15029
  }
15001
15030
  _isValidTile(coords) {
@@ -15049,7 +15078,7 @@ var GridLayer = class GridLayer extends Layer {
15049
15078
  coords,
15050
15079
  current: true
15051
15080
  };
15052
- container.appendChild(tile);
15081
+ container.append(tile);
15053
15082
  this.fire("tileloadstart", {
15054
15083
  tile,
15055
15084
  coords
@@ -15254,13 +15283,13 @@ var TileLayer = class TileLayer extends GridLayer {
15254
15283
  if (!this.options.zoomReverse) {
15255
15284
  this.options.zoomOffset++;
15256
15285
  this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);
15257
- if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
15258
- if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
15259
15286
  } else {
15260
15287
  this.options.zoomOffset--;
15261
15288
  this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);
15262
15289
  }
15263
15290
  this.options.minZoom = Math.max(0, this.options.minZoom);
15291
+ if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
15292
+ if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
15264
15293
  } else if (!this.options.zoomReverse) this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);
15265
15294
  else this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);
15266
15295
  }
@@ -15356,16 +15385,17 @@ var TileLayer = class TileLayer extends GridLayer {
15356
15385
  * @returns {string}
15357
15386
  */
15358
15387
  getTileUrl(coords) {
15359
- const data = Object.create(this.options);
15388
+ const z = coords.z ?? this._tileZoom, data = Object.create(this.options);
15360
15389
  Object.assign(data, {
15361
15390
  r: window.devicePixelRatio > 1 ? "@2x" : "",
15362
15391
  s: this._getSubdomain(coords),
15363
15392
  x: coords.x,
15364
15393
  y: coords.y,
15365
- z: this._getZoomForUrl()
15394
+ z: this._getZoomForUrl(z)
15366
15395
  });
15367
- if (this._map && !this._map.options.crs.infinite) {
15368
- const invertedY = this._globalTileRange.max.y - coords.y;
15396
+ const worldBounds = this._map?.getPixelWorldBounds(z);
15397
+ if (worldBounds) {
15398
+ const invertedY = this._pxBoundsToTileRange(worldBounds).max.y - coords.y;
15369
15399
  if (this.options.tms) data["y"] = invertedY;
15370
15400
  data["-y"] = invertedY;
15371
15401
  }
@@ -15380,8 +15410,7 @@ var TileLayer = class TileLayer extends GridLayer {
15380
15410
  if (errorUrl && src !== errorUrl && (src || tile.isConnected)) tile.src = errorUrl;
15381
15411
  done(e, tile);
15382
15412
  }
15383
- _getZoomForUrl() {
15384
- let zoom = this._tileZoom;
15413
+ _getZoomForUrl(zoom) {
15385
15414
  const maxZoom = this.options.maxZoom, zoomReverse = this.options.zoomReverse, zoomOffset = this.options.zoomOffset;
15386
15415
  if (zoomReverse) zoom = maxZoom - zoom;
15387
15416
  return zoom + zoomOffset;
@@ -15414,7 +15443,7 @@ var TileLayer = class TileLayer extends GridLayer {
15414
15443
  return super._removeTile(key);
15415
15444
  }
15416
15445
  _tileReady(coords, err, tile) {
15417
- if (!this._map || tile && tile.getAttribute("src") === "") return;
15446
+ if (!this._map || tile?.getAttribute("src") === "") return;
15418
15447
  return super._tileReady(coords, err, tile);
15419
15448
  }
15420
15449
  _clampZoom(zoom) {
@@ -15668,22 +15697,21 @@ var Canvas = class Canvas extends Renderer {
15668
15697
  */
15669
15698
  onAdd(map) {
15670
15699
  super.onAdd(map);
15700
+ const z = (r) => +getComputedStyle(r._container.parentNode).zIndex || 0;
15701
+ map._canvases.push(this);
15702
+ map._canvases.sort((a, b) => z(b) - z(a) || (a._container.compareDocumentPosition(b._container) & 2) - 1);
15671
15703
  this._draw();
15672
15704
  }
15705
+ _initContainer() {
15706
+ const container = this._container = document.createElement("canvas");
15707
+ this._ctx = container.getContext("2d");
15708
+ }
15673
15709
  /**
15674
15710
  * Removes the canvas from the map.
15675
15711
  */
15676
15712
  onRemove() {
15713
+ this._map._canvases = this._map._canvases.filter((r) => r !== this);
15677
15714
  super.onRemove();
15678
- clearTimeout(this._pointerHoverThrottleTimeout);
15679
- }
15680
- _initContainer() {
15681
- const container = this._container = document.createElement("canvas");
15682
- on(container, "pointermove", this._onPointerMove, this);
15683
- on(container, "click dblclick pointerdown pointerup contextmenu", this._onClick, this);
15684
- on(container, "pointerout", this._handlePointerOut, this);
15685
- container["_maplair_disable_events"] = true;
15686
- this._ctx = container.getContext("2d");
15687
15715
  }
15688
15716
  _destroyContainer() {
15689
15717
  cancelAnimationFrame(this._redrawRequest);
@@ -15719,26 +15747,13 @@ var Canvas = class Canvas extends Renderer {
15719
15747
  _initPath(layer) {
15720
15748
  this._updateDashArray(layer);
15721
15749
  this._layers[stamp(layer)] = layer;
15722
- const order = layer._order = {
15723
- layer,
15724
- prev: this._drawLast,
15725
- next: null
15726
- };
15727
- if (this._drawLast) this._drawLast.next = order;
15728
- this._drawLast = order;
15729
- this._drawFirst ??= this._drawLast;
15750
+ this._append(layer._order = { layer });
15730
15751
  }
15731
15752
  _addPath(layer) {
15732
15753
  this._requestRedraw(layer);
15733
15754
  }
15734
15755
  _removePath(layer) {
15735
- const order = layer._order;
15736
- const next = order.next;
15737
- const prev = order.prev;
15738
- if (next) next.prev = prev;
15739
- else this._drawLast = prev;
15740
- if (prev) prev.next = next;
15741
- else this._drawFirst = next;
15756
+ this._unlink(layer._order);
15742
15757
  delete layer._order;
15743
15758
  delete this._layers[stamp(layer)];
15744
15759
  this._requestRedraw(layer);
@@ -15764,7 +15779,7 @@ var Canvas = class Canvas extends Renderer {
15764
15779
  }
15765
15780
  _extendRedrawBounds(layer) {
15766
15781
  if (layer._pxBounds) {
15767
- const padding = (layer.options.weight ?? 0) + 1;
15782
+ const padding = (+layer.options.weight || 0) + 1;
15768
15783
  this._redrawBounds ??= new Bounds();
15769
15784
  this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
15770
15785
  this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
@@ -15806,7 +15821,7 @@ var Canvas = class Canvas extends Renderer {
15806
15821
  this._drawing = true;
15807
15822
  for (let order = this._drawFirst; order; order = order.next) {
15808
15823
  layer = order.layer;
15809
- if (!bounds || layer._pxBounds && layer._pxBounds.intersects(bounds)) layer._updatePath();
15824
+ if (!bounds || layer._pxBounds?.intersects(bounds)) layer._updatePath();
15810
15825
  }
15811
15826
  this._drawing = false;
15812
15827
  this._ctx.restore();
@@ -15851,84 +15866,50 @@ var Canvas = class Canvas extends Renderer {
15851
15866
  }
15852
15867
  }
15853
15868
  _updateInteractive() {}
15854
- _onClick(e) {
15869
+ /**
15870
+ * Returns the topmost interactive layer under the pointer.
15871
+ * @param {MouseEvent} e
15872
+ * @param {boolean} [click] Skip layers that were just dragged, so the drag doesn't end with a click.
15873
+ * @returns {Path|undefined}
15874
+ */
15875
+ _layerAt(e, click) {
15855
15876
  const point = this._map.pointerEventToLayerPoint(e);
15856
- let layer, clickedLayer;
15857
- for (let order = this._drawFirst; order; order = order.next) {
15858
- layer = order.layer;
15859
- if (layer.options.interactive && layer._containsPoint(point)) {
15860
- if (!(e.type === "click" || e.type === "preclick") || !this._map._draggableMoved(layer)) clickedLayer = layer;
15861
- }
15877
+ for (let order = this._drawLast; order; order = order.prev) {
15878
+ const layer = order.layer;
15879
+ if (layer.options.interactive && layer._containsPoint(point) && !(click && this._map._draggableMoved(layer))) return layer;
15862
15880
  }
15863
- this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
15864
15881
  }
15865
- _onPointerMove(e) {
15866
- if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) return;
15867
- const point = this._map.pointerEventToLayerPoint(e);
15868
- this._handlePointerHover(e, point);
15869
- }
15870
- _handlePointerOut(e) {
15871
- const layer = this._hoveredLayer;
15872
- if (layer) {
15873
- this._container.classList.remove("maplair-interactive");
15874
- this._fireEvent([layer], e, "pointerout");
15875
- this._hoveredLayer = null;
15876
- this._pointerHoverThrottled = false;
15882
+ _bringToFront(layer) {
15883
+ const order = layer._order;
15884
+ if (order?.next) {
15885
+ this._unlink(order);
15886
+ this._append(order);
15887
+ this._requestRedraw(layer);
15877
15888
  }
15878
15889
  }
15879
- _handlePointerHover(e, point) {
15880
- if (this._pointerHoverThrottled) return;
15881
- let layer, candidateHoveredLayer;
15882
- for (let order = this._drawFirst; order; order = order.next) {
15883
- layer = order.layer;
15884
- if (layer.options.interactive && layer._containsPoint(point)) candidateHoveredLayer = layer;
15885
- }
15886
- if (candidateHoveredLayer !== this._hoveredLayer) {
15887
- this._handlePointerOut(e);
15888
- if (candidateHoveredLayer) {
15889
- this._container.classList.add("maplair-interactive");
15890
- this._fireEvent([candidateHoveredLayer], e, "pointerover");
15891
- this._hoveredLayer = candidateHoveredLayer;
15892
- }
15890
+ _bringToBack(layer) {
15891
+ const order = layer._order;
15892
+ if (order?.prev) {
15893
+ this._unlink(order);
15894
+ order.prev = null;
15895
+ order.next = this._drawFirst;
15896
+ this._drawFirst.prev = order;
15897
+ this._drawFirst = order;
15898
+ this._requestRedraw(layer);
15893
15899
  }
15894
- this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
15895
- this._pointerHoverThrottled = true;
15896
- this._pointerHoverThrottleTimeout = setTimeout((() => {
15897
- this._pointerHoverThrottled = false;
15898
- }), 32);
15899
- }
15900
- _fireEvent(layers, e, type) {
15901
- this._map._fireDOMEvent(e, type || e.type, layers);
15902
15900
  }
15903
- _bringToFront(layer) {
15904
- const order = layer._order;
15905
- if (!order) return;
15906
- const next = order.next;
15907
- const prev = order.prev;
15908
- if (next) next.prev = prev;
15909
- else return;
15910
- if (prev) prev.next = next;
15911
- else if (next) this._drawFirst = next;
15901
+ _append(order) {
15912
15902
  order.prev = this._drawLast;
15913
- this._drawLast.next = order;
15914
15903
  order.next = null;
15904
+ if (this._drawLast) this._drawLast.next = order;
15915
15905
  this._drawLast = order;
15916
- this._requestRedraw(layer);
15906
+ this._drawFirst ??= order;
15917
15907
  }
15918
- _bringToBack(layer) {
15919
- const order = layer._order;
15920
- if (!order) return;
15921
- const next = order.next;
15922
- const prev = order.prev;
15923
- if (prev) prev.next = next;
15924
- else return;
15908
+ _unlink({ prev, next }) {
15925
15909
  if (next) next.prev = prev;
15926
- else if (prev) this._drawLast = prev;
15927
- order.prev = null;
15928
- order.next = this._drawFirst;
15929
- this._drawFirst.prev = order;
15930
- this._drawFirst = order;
15931
- this._requestRedraw(layer);
15910
+ else this._drawLast = prev;
15911
+ if (prev) prev.next = next;
15912
+ else this._drawFirst = next;
15932
15913
  }
15933
15914
  };
15934
15915
  // src/layer/vector/Circle.js
@@ -15960,6 +15941,7 @@ var Circle = class Circle extends CircleMarker {
15960
15941
  * @param {CircleOptions} [options]
15961
15942
  */
15962
15943
  constructor(latlng, options) {
15944
+ if (typeof options === "number") throw new Error("Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).");
15963
15945
  super(latlng, options);
15964
15946
  if (isNaN(this.options.radius)) throw new Error("Circle radius cannot be NaN");
15965
15947
  this.callInitHooks(Circle);
@@ -15975,18 +15957,18 @@ var Circle = class Circle extends CircleMarker {
15975
15957
  return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half)));
15976
15958
  }
15977
15959
  _project() {
15978
- const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs;
15960
+ const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs, renderer = this._renderer, zoom = renderer._pathZoom;
15979
15961
  if (crs.distance === EarthCRS.distance) {
15980
- const d = Math.PI / 180, latR = this._radius / EarthCRS.R / d, top = map.project([lat + latR, lng]), bottom = map.project([lat - latR, lng]), p = top.add(bottom).divideBy(2), lat2 = map.unproject(p).lat;
15962
+ const d = Math.PI / 180, latR = this._radius / EarthCRS.R / d, top = map.project([lat + latR, lng], zoom), bottom = map.project([lat - latR, lng], zoom), p = top.add(bottom).divideBy(2), lat2 = map.unproject(p, zoom).lat;
15981
15963
  let lngR = 2 * Math.asin(Math.sqrt((Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) / (Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;
15982
- if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(Math.PI / 180 * lat);
15983
- this._point = p.subtract(map.getPixelOrigin());
15984
- this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;
15964
+ if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(lat * d);
15965
+ this._point = p.subtract(renderer._pathOrigin);
15966
+ this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR], zoom).x;
15985
15967
  this._pxRadiusY = p.y - top.y;
15986
15968
  } else {
15987
15969
  const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
15988
- this._point = map.latLngToLayerPoint(this._latlng);
15989
- this._pxRadius = Math.abs(this._point.x - map.latLngToLayerPoint(latlng2).x);
15970
+ this._point = renderer._latLngToLayerPoint(this._latlng);
15971
+ this._pxRadius = Math.abs(this._point.x - renderer._latLngToLayerPoint(latlng2).x);
15990
15972
  }
15991
15973
  this._updateBounds();
15992
15974
  }
@@ -16417,10 +16399,7 @@ var MapSync = class {
16417
16399
  other._rawPanBy(offset);
16418
16400
  other.fire("move");
16419
16401
  }
16420
- } else other._move(center, zoom, during ? {
16421
- pinch: true,
16422
- round: false
16423
- } : void 0);
16402
+ } else other._move(center, zoom, during ? { pinch: true } : void 0);
16424
16403
  }
16425
16404
  _syncAll(map) {
16426
16405
  for (const other of this._maps.filter((m) => m !== map)) {
@@ -16552,6 +16531,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16552
16531
  * Called when the handler is enabled, adds the event hooks.
16553
16532
  */
16554
16533
  addHooks() {
16534
+ this._map._displaceHandler = this;
16555
16535
  this._map.on("zoomend", this.schedule, this);
16556
16536
  this._map.on("layeradd", this._onLayerAdd, this);
16557
16537
  this._map.on("layerremove", this._onLayerRemove, this);
@@ -16563,6 +16543,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16563
16543
  * true positions of the markers.
16564
16544
  */
16565
16545
  removeHooks() {
16546
+ if (this._map._displaceHandler === this) delete this._map._displaceHandler;
16566
16547
  this._map.off("zoomend", this.schedule, this);
16567
16548
  this._map.off("layeradd", this._onLayerAdd, this);
16568
16549
  this._map.off("layerremove", this._onLayerRemove, this);
@@ -16634,6 +16615,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16634
16615
  * @param {LatLng} latLng
16635
16616
  */
16636
16617
  _moveTo(marker, latLng) {
16618
+ if (marker.getLatLng().equals(latLng)) return;
16637
16619
  this._moving = true;
16638
16620
  try {
16639
16621
  marker.setLatLng(latLng);
@@ -16653,6 +16635,19 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16653
16635
  if (this._enabled && this._map.hasLayer(event.target)) this.schedule();
16654
16636
  }
16655
16637
  /**
16638
+ * Called by `CircleMarker#beforeAdd`: puts a marker whose `displaceId` already
16639
+ * has a displaced position at the current zoom (e.g. the same station on
16640
+ * another layer) there before it is drawn, instead of drawing it twice.
16641
+ * @param {CircleMarker} marker
16642
+ */
16643
+ _beforeMarkerAdd(marker) {
16644
+ if (!displaceable(marker)) return;
16645
+ this._track(marker);
16646
+ const { displaceId } = marker.options;
16647
+ const latLng = displaceId && this._displacedPositions.get(this._map.getZoom())?.get(displaceId);
16648
+ if (latLng) this._moveTo(marker, latLng);
16649
+ }
16650
+ /**
16656
16651
  * @param {LayerEvent} event
16657
16652
  */
16658
16653
  _onLayerAdd(event) {
@@ -16689,6 +16684,10 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16689
16684
  }
16690
16685
  };
16691
16686
  /**
16687
+ * Movement in pixels per pass below which `displace` stops early
16688
+ */
16689
+ const MIN_MOVE = .01;
16690
+ /**
16692
16691
  * Displaces overlapping points in pixel space until they are at least
16693
16692
  * `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed
16694
16693
  * apart by half of its overlap per pass. Neighbour lookup uses a grid (cell
@@ -16696,7 +16695,8 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16696
16695
  *
16697
16696
  * No point ends up further than `maxDisplacement` away from where it started.
16698
16697
  * Points which hit that limit stay overlapping – the limit wins over the
16699
- * separation.
16698
+ * separation. The relaxation stops early once the points are separated or
16699
+ * no point moves by more than a hundredth of a pixel per pass.
16700
16700
  *
16701
16701
  * @param {Point[]} points Pixel coordinates (modified in place)
16702
16702
  * @param {number} minSeparation Minimum distance between centers, in pixels
@@ -16716,49 +16716,62 @@ function displace(points, minSeparation, { iterations = DisplaceHandler.defaultO
16716
16716
  for (let iter = 0; iter < iterations; iter++) {
16717
16717
  dx.fill(0);
16718
16718
  dy.fill(0);
16719
- /** @type {Map<string, number[]>} */
16719
+ /** @type {Map<number, Map<number, number[]>>} */
16720
16720
  const grid = /* @__PURE__ */ new Map();
16721
16721
  for (let i = 0; i < n; i++) {
16722
- const key = `${Math.floor(points[i].x / cell)},${Math.floor(points[i].y / cell)}`;
16723
- const bucket = grid.get(key);
16722
+ const cx = Math.floor(points[i].x / cell);
16723
+ const cy = Math.floor(points[i].y / cell);
16724
+ let column = grid.get(cx);
16725
+ if (!column) {
16726
+ column = /* @__PURE__ */ new Map();
16727
+ grid.set(cx, column);
16728
+ }
16729
+ const bucket = column.get(cy);
16724
16730
  if (bucket) bucket.push(i);
16725
- else grid.set(key, [i]);
16731
+ else column.set(cy, [i]);
16726
16732
  }
16727
16733
  let overlaps = 0;
16728
16734
  for (let i = 0; i < n; i++) {
16729
16735
  const cx = Math.floor(points[i].x / cell);
16730
16736
  const cy = Math.floor(points[i].y / cell);
16731
- for (let gx = cx - 1; gx <= cx + 1; gx++) for (let gy = cy - 1; gy <= cy + 1; gy++) {
16732
- const bucket = grid.get(`${gx},${gy}`);
16733
- if (!bucket) continue;
16734
- for (const j of bucket) {
16735
- if (j <= i) continue;
16736
- let vx = points[i].x - points[j].x;
16737
- let vy = points[i].y - points[j].y;
16738
- const distSq = vx * vx + vy * vy;
16739
- if (distSq >= sepSq) continue;
16740
- overlaps++;
16741
- let dist;
16742
- if (distSq === 0) {
16743
- const angle = i * 2.399963229728653;
16744
- vx = Math.cos(angle);
16745
- vy = Math.sin(angle);
16746
- dist = 1;
16747
- } else {
16748
- dist = Math.sqrt(distSq);
16749
- vx /= dist;
16750
- vy /= dist;
16737
+ for (let gx = cx - 1; gx <= cx + 1; gx++) {
16738
+ const column = grid.get(gx);
16739
+ if (!column) continue;
16740
+ for (let gy = cy - 1; gy <= cy + 1; gy++) {
16741
+ const bucket = column.get(gy);
16742
+ if (!bucket) continue;
16743
+ for (const j of bucket) {
16744
+ if (j <= i) continue;
16745
+ let vx = points[i].x - points[j].x;
16746
+ let vy = points[i].y - points[j].y;
16747
+ const distSq = vx * vx + vy * vy;
16748
+ if (distSq >= sepSq) continue;
16749
+ overlaps++;
16750
+ let dist;
16751
+ if (distSq === 0) {
16752
+ const angle = i * 2.399963229728653;
16753
+ vx = Math.cos(angle);
16754
+ vy = Math.sin(angle);
16755
+ dist = 1;
16756
+ } else {
16757
+ dist = Math.sqrt(distSq);
16758
+ vx /= dist;
16759
+ vy /= dist;
16760
+ }
16761
+ const push = (sep - dist) / 2;
16762
+ dx[i] += vx * push;
16763
+ dy[i] += vy * push;
16764
+ dx[j] -= vx * push;
16765
+ dy[j] -= vy * push;
16751
16766
  }
16752
- const push = (sep - dist) / 2;
16753
- dx[i] += vx * push;
16754
- dy[i] += vy * push;
16755
- dx[j] -= vx * push;
16756
- dy[j] -= vy * push;
16757
16767
  }
16758
16768
  }
16759
16769
  }
16760
16770
  if (overlaps === 0) break;
16771
+ let maxMoveSq = 0;
16761
16772
  for (let i = 0; i < n; i++) {
16773
+ const x = points[i].x;
16774
+ const y = points[i].y;
16762
16775
  points[i].x += dx[i];
16763
16776
  points[i].y += dy[i];
16764
16777
  const ox = points[i].x - ax[i];
@@ -16769,7 +16782,11 @@ function displace(points, minSeparation, { iterations = DisplaceHandler.defaultO
16769
16782
  points[i].x = ax[i] + ox * scale;
16770
16783
  points[i].y = ay[i] + oy * scale;
16771
16784
  }
16785
+ const mx = points[i].x - x;
16786
+ const my = points[i].y - y;
16787
+ maxMoveSq = Math.max(maxMoveSq, mx * mx + my * my);
16772
16788
  }
16789
+ if (maxMoveSq < MIN_MOVE * MIN_MOVE) break;
16773
16790
  }
16774
16791
  return points;
16775
16792
  }
@@ -16839,7 +16856,6 @@ var RotateControl = class RotateControl extends Control {
16839
16856
  disableClickPropagation(button);
16840
16857
  on(button, "click", stop);
16841
16858
  on(button, "click", this._resetNorth, this);
16842
- on(button, "click", this._refocusOnMap, this);
16843
16859
  this._update();
16844
16860
  map.on("rotate", this._update, this);
16845
16861
  return container;
@@ -16943,8 +16959,8 @@ MaplairMap.include({
16943
16959
  if (!this._rotatePane) {
16944
16960
  const rotatePane = this._rotatePane = create("div", "maplair-rotate-pane");
16945
16961
  rotatedMaps.set(rotatePane, this);
16946
- this._container.insertBefore(rotatePane, this._mapPane);
16947
- rotatePane.appendChild(this._mapPane);
16962
+ this._mapPane.before(rotatePane);
16963
+ rotatePane.append(this._mapPane);
16948
16964
  }
16949
16965
  if (bearing === this.getBearing()) return;
16950
16966
  this._bearing = bearing;
@@ -17033,9 +17049,9 @@ MaplairMap.include({
17033
17049
  return panBy.call(this, this._rotateToPane(Point.from(offset)), options);
17034
17050
  },
17035
17051
  _tryAnimatedPan(center, options) {
17036
- const offset = this._rotateToContainer(this._getCenterOffset(center)._trunc());
17037
- if (options?.animate !== true && !this.getSize().contains(offset)) return false;
17038
- this.panBy(offset, options);
17052
+ const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
17053
+ if (options?.animate !== true && !this.getSize().contains(this._rotateToContainer(offset))) return false;
17054
+ this._panBy(offset, options);
17039
17055
  return true;
17040
17056
  },
17041
17057
  /**
@@ -17327,10 +17343,7 @@ PinchZoomHandler.include({
17327
17343
  this._moved = true;
17328
17344
  }
17329
17345
  cancelAnimationFrame(this._animRequest);
17330
- const moveFn = map._move.bind(map, this._center, this._zoom, {
17331
- pinch: true,
17332
- round: false
17333
- }, void 0);
17346
+ const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
17334
17347
  this._animRequest = requestAnimationFrame(moveFn.bind(this));
17335
17348
  e.preventDefault();
17336
17349
  }