maplair 4.3.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 +89 -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 +3 -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 +7 -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 +698 -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 +698 -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 +1 -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 +6 -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 +11 -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.3.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.3.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
  }
@@ -2204,8 +2180,8 @@ const mapLayerMethods = {
2204
2180
  const oldZoomSpan = this._getZoomSpan();
2205
2181
  for (const l of Object.values(this._zoomBoundLayers)) {
2206
2182
  const options = l.options;
2207
- minZoom = Math.min(minZoom, options.minZoom ?? Infinity);
2208
- 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);
2209
2185
  }
2210
2186
  this._layersMaxZoom = maxZoom === -Infinity ? void 0 : maxZoom;
2211
2187
  this._layersMinZoom = minZoom === Infinity ? void 0 : minZoom;
@@ -2327,8 +2303,10 @@ var Layer = class extends Evented {
2327
2303
  }
2328
2304
  _updateInteractive() {}
2329
2305
  /**
2330
- * Makes `targetEl` a target of pointer events of this layer.
2331
- * @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.
2332
2310
  * @param {HTMLElement} targetEl
2333
2311
  * @returns {this}
2334
2312
  */
@@ -2337,8 +2315,8 @@ var Layer = class extends Evented {
2337
2315
  return this;
2338
2316
  }
2339
2317
  /**
2340
- * Stops `targetEl` from being a target of pointer events of this layer.
2341
- * @internal
2318
+ * Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in
2319
+ * [`onRemove`](#layer-onremove).
2342
2320
  * @param {HTMLElement} targetEl
2343
2321
  * @returns {this}
2344
2322
  */
@@ -2346,6 +2324,9 @@ var Layer = class extends Evented {
2346
2324
  delete this._map._targets[stamp(targetEl)];
2347
2325
  return this;
2348
2326
  }
2327
+ _togglesPopupOnClick() {
2328
+ return true;
2329
+ }
2349
2330
  /**
2350
2331
  * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).
2351
2332
  * @returns {string|null}
@@ -2513,7 +2494,7 @@ var ContextMenu = class ContextMenu extends Class {
2513
2494
  }
2514
2495
  _createMenu(parent) {
2515
2496
  const container = this._container ??= create("div", `maplair-contextmenu ${this.options.className}`);
2516
- if (container.parentNode !== parent) parent.appendChild(container);
2497
+ if (container.parentNode !== parent) parent.append(container);
2517
2498
  container.popover = "auto";
2518
2499
  container.setAttribute("role", "menu");
2519
2500
  container.replaceChildren();
@@ -2680,7 +2661,6 @@ var FullscreenControl = class FullscreenControl extends Control {
2680
2661
  disableClickPropagation(button);
2681
2662
  on(button, "click", stop);
2682
2663
  on(button, "click", this._toggleFullscreen, this);
2683
- on(button, "click", this._refocusOnMap, this);
2684
2664
  this._update();
2685
2665
  map.on("fullscreenchange", this._update, this);
2686
2666
  return container;
@@ -2764,6 +2744,8 @@ var FullscreenControl = class FullscreenControl extends Control {
2764
2744
  * `maplair-control-layers-group-name` element, and each entry shows only its label.
2765
2745
  * Events like `baselayerchange` still carry the full `name`. When combined with
2766
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.
2767
2749
  * @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
2768
2750
  * collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
2769
2751
  * element. String content is rendered as HTML; do not pass untrusted input.
@@ -2848,6 +2830,7 @@ var LayersControl = class LayersControl extends Control {
2848
2830
  collapsed: true,
2849
2831
  inline: false,
2850
2832
  groupBy: void 0,
2833
+ title: void 0,
2851
2834
  toggleContent: void 0,
2852
2835
  collapseDelay: 0,
2853
2836
  position: "topright",
@@ -2994,13 +2977,16 @@ var LayersControl = class LayersControl extends Control {
2994
2977
  else this._container.classList.remove("maplair-control-layers-expanded");
2995
2978
  return this;
2996
2979
  }
2980
+ _getTitle() {
2981
+ return this.options.title ?? I18n.translate("Layers");
2982
+ }
2997
2983
  _initLayout() {
2998
2984
  const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this._isCollapsible();
2999
2985
  if (this.options.inline) container.classList.add(`${className}-inline`);
3000
2986
  disableClickPropagation(container);
3001
2987
  disableScrollPropagation(container);
3002
2988
  const section = this._section = create("fieldset", `${className}-list`);
3003
- section.setAttribute("aria-label", I18n.translate("Layers"));
2989
+ section.setAttribute("aria-label", this._getTitle());
3004
2990
  if (collapsed) {
3005
2991
  this._map.on("click", this.collapse, this);
3006
2992
  on(container, {
@@ -3013,8 +2999,8 @@ var LayersControl = class LayersControl extends Control {
3013
2999
  if (!this.options.inline) {
3014
3000
  const link = this._layersLink = create("button", `${className}-toggle`, container);
3015
3001
  link.type = "button";
3016
- link.title = I18n.translate("Layers");
3017
- link.setAttribute("aria-label", I18n.translate("Layers"));
3002
+ link.title = this._getTitle();
3003
+ link.setAttribute("aria-label", link.title);
3018
3004
  const { toggleContent } = this.options;
3019
3005
  if (typeof toggleContent === "string") link.innerHTML = toggleContent;
3020
3006
  else if (toggleContent) link.replaceChildren(toggleContent);
@@ -3032,7 +3018,7 @@ var LayersControl = class LayersControl extends Control {
3032
3018
  this._baseLayersList = create("div", `${className}-base`, section);
3033
3019
  this._separator = create("div", `${className}-separator`, section);
3034
3020
  this._overlaysList = create("div", `${className}-overlays`, section);
3035
- container.appendChild(section);
3021
+ container.append(section);
3036
3022
  }
3037
3023
  _addLayer(layer, name, overlay) {
3038
3024
  if (this._map) layer.on("add remove", this._onLayerChange, this);
@@ -3091,11 +3077,10 @@ var LayersControl = class LayersControl extends Control {
3091
3077
  const name = document.createElement("span");
3092
3078
  name.innerHTML = ` ${group ? group.label : obj.name}`;
3093
3079
  const holder = document.createElement("span");
3094
- label.appendChild(holder);
3095
- holder.appendChild(input);
3096
- holder.appendChild(name);
3080
+ label.append(holder);
3081
+ holder.append(input, name);
3097
3082
  const list = obj.overlay ? this._overlaysList : this._baseLayersList;
3098
- (group ? this._getGroupContainer(list, group.group) : list).appendChild(label);
3083
+ (group ? this._getGroupContainer(list, group.group) : list).append(label);
3099
3084
  this._checkDisabledLayers();
3100
3085
  return label;
3101
3086
  }
@@ -3136,7 +3121,6 @@ var LayersControl = class LayersControl extends Control {
3136
3121
  this._update();
3137
3122
  break;
3138
3123
  }
3139
- this._refocusOnMap(e);
3140
3124
  }
3141
3125
  _checkDisabledLayers() {
3142
3126
  const inputs = this._layerControlInputs, zoom = this._map.getZoom();
@@ -3329,7 +3313,7 @@ var Bounds = class Bounds {
3329
3313
  */
3330
3314
  overlaps(bounds) {
3331
3315
  bounds = Bounds.from(bounds);
3332
- 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);
3333
3317
  return xOverlaps && yOverlaps;
3334
3318
  }
3335
3319
  /**
@@ -3362,7 +3346,7 @@ var Bounds = class Bounds {
3362
3346
  }
3363
3347
  };
3364
3348
  function isPointExpression(obj) {
3365
- 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);
3366
3350
  }
3367
3351
  // src/layer/BlanketOverlay.js
3368
3352
  /** @import {LayerOptions} from './Layer.js' */
@@ -3425,7 +3409,7 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
3425
3409
  this._initContainer();
3426
3410
  this._container.classList.add("maplair-zoom-animated");
3427
3411
  }
3428
- this.getPane().appendChild(this._container);
3412
+ this.getPane().append(this._container);
3429
3413
  this._resizeContainer();
3430
3414
  this._onMoveEnd();
3431
3415
  }
@@ -3497,6 +3481,8 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
3497
3481
  /** @import {BlanketOverlayOptions} from '../BlanketOverlay.js' */
3498
3482
  /** @import {MaplairEvent} from '../../core/Events.js' */
3499
3483
  /** @import {MaplairMap} from '../../map/Map.js' */
3484
+ /** @import {LatLngExpression} from '../../geo/LatLng.js' */
3485
+ /** @import {Point} from '../../geometry/Point.js' */
3500
3486
  /**
3501
3487
  * Options of `Renderer`, `SVG` and `Canvas`. The `continuous` option inherited from
3502
3488
  * `BlanketOverlay` cannot be set to `true`.
@@ -3538,6 +3524,7 @@ var Renderer = class Renderer extends BlanketOverlay {
3538
3524
  * @param {MaplairMap} map
3539
3525
  */
3540
3526
  onAdd(map) {
3527
+ this._setPathView();
3541
3528
  super.onAdd(map);
3542
3529
  this.on("update", this._updatePaths, this);
3543
3530
  }
@@ -3549,12 +3536,25 @@ var Renderer = class Renderer extends BlanketOverlay {
3549
3536
  this.off("update", this._updatePaths, this);
3550
3537
  }
3551
3538
  _onZoomEnd() {
3539
+ this._setPathView();
3552
3540
  for (const layer of Object.values(this._layers)) layer._project();
3553
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
+ }
3554
3553
  _updatePaths() {
3555
3554
  for (const layer of Object.values(this._layers)) layer._update();
3556
3555
  }
3557
3556
  _onViewReset() {
3557
+ this._setPathView();
3558
3558
  for (const layer of Object.values(this._layers)) layer._reset();
3559
3559
  }
3560
3560
  _onSettled() {
@@ -3604,7 +3604,7 @@ var SVG = class SVG extends Renderer {
3604
3604
  this._container = SVG.create("svg");
3605
3605
  this._container.setAttribute("pointer-events", "none");
3606
3606
  this._rootGroup = SVG.create("g");
3607
- this._container.appendChild(this._rootGroup);
3607
+ this._container.append(this._rootGroup);
3608
3608
  }
3609
3609
  _destroyContainer() {
3610
3610
  super._destroyContainer();
@@ -3613,7 +3613,7 @@ var SVG = class SVG extends Renderer {
3613
3613
  }
3614
3614
  _resizeContainer() {
3615
3615
  const size = super._resizeContainer();
3616
- if (!this._svgSize || !this._svgSize.equals(size)) {
3616
+ if (!this._svgSize?.equals(size)) {
3617
3617
  this._svgSize = size;
3618
3618
  this._container.setAttribute("width", `${size.x}`);
3619
3619
  this._container.setAttribute("height", `${size.y}`);
@@ -3649,7 +3649,7 @@ var SVG = class SVG extends Renderer {
3649
3649
  }
3650
3650
  _addPath(layer) {
3651
3651
  if (!this._rootGroup) this._initContainer();
3652
- this._rootGroup.appendChild(layer._path);
3652
+ this._rootGroup.append(layer._path);
3653
3653
  layer.addInteractiveTarget(layer._path);
3654
3654
  }
3655
3655
  _removePath(layer) {
@@ -3758,13 +3758,15 @@ function num(v) {
3758
3758
  * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
3759
3759
  * afterwards.
3760
3760
  * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
3761
- * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),
3762
- * 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.
3763
3764
  * @extends InteractiveLayerOptions
3764
3765
  */
3765
3766
  /**
3766
- * An abstract class that contains options and constants shared between vector
3767
- * 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`.
3768
3770
  */
3769
3771
  var Path = class extends Layer {
3770
3772
  static defaultOptions = {
@@ -3861,8 +3863,11 @@ var Path = class extends Layer {
3861
3863
  this._project();
3862
3864
  this._update();
3863
3865
  }
3866
+ _togglesPopupOnClick() {
3867
+ return false;
3868
+ }
3864
3869
  _clickTolerance() {
3865
- 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);
3866
3871
  }
3867
3872
  };
3868
3873
  // src/geo/LatLngBounds.js
@@ -3950,7 +3955,7 @@ var LatLngBounds = class LatLngBounds {
3950
3955
  ({_southWest: sw2, _northEast: ne2} = obj);
3951
3956
  if (!sw2) return this;
3952
3957
  } else if (!obj) return this;
3953
- else if (LatLng.validate(obj)) sw2 = ne2 = LatLng.from(obj);
3958
+ else if (isLatLngExpression(obj)) sw2 = ne2 = LatLng.from(obj);
3954
3959
  else return this.extend(LatLngBounds.from(obj));
3955
3960
  if (!sw) {
3956
3961
  this._southWest = new LatLng(sw2.lat, sw2.lng);
@@ -4043,7 +4048,7 @@ var LatLngBounds = class LatLngBounds {
4043
4048
  * @returns {boolean}
4044
4049
  */
4045
4050
  contains(obj) {
4046
- if (LatLng.validate(obj)) obj = LatLng.from(obj);
4051
+ if (isLatLngExpression(obj)) obj = LatLng.from(obj);
4047
4052
  else obj = LatLngBounds.from(obj);
4048
4053
  const sw = this._southWest, ne = this._northEast;
4049
4054
  let sw2, ne2;
@@ -4072,7 +4077,7 @@ var LatLngBounds = class LatLngBounds {
4072
4077
  */
4073
4078
  overlaps(bounds) {
4074
4079
  bounds = LatLngBounds.from(bounds);
4075
- 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);
4076
4081
  return latOverlaps && lngOverlaps;
4077
4082
  }
4078
4083
  /**
@@ -4110,6 +4115,9 @@ var LatLngBounds = class LatLngBounds {
4110
4115
  return !!(this._southWest && this._northEast);
4111
4116
  }
4112
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
+ }
4113
4121
  // src/geo/LatLng.js
4114
4122
  const coordinate = String.raw`([+-]?\d+(?:\.\d+)?)\s*°?`;
4115
4123
  const separator = String.raw`(?:\s*[,;]\s*|\s+)`;
@@ -4159,46 +4167,36 @@ var LatLng = class LatLng {
4159
4167
  * @param {number} [alt] Altitude in meters.
4160
4168
  */
4161
4169
  constructor(lat, lng, alt) {
4162
- if (!LatLng.validate(lat, lng, alt)) throw new Error(`Invalid LatLng object: (${lat}, ${lng})`);
4163
- let _lat, _lng, _alt;
4164
- if (lat instanceof LatLng) {
4165
- _lat = lat.lat;
4166
- _lng = lat.lng;
4167
- _alt = lat.alt;
4168
- } else if (Array.isArray(lat) && typeof lat[0] !== "object") {
4169
- if (lat.length === 3) {
4170
- _lat = lat[0];
4171
- _lng = lat[1];
4172
- _alt = lat[2];
4173
- } else if (lat.length === 2) {
4174
- _lat = lat[0];
4175
- _lng = lat[1];
4176
- }
4177
- } 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) {
4178
4177
  _lat = lat.lat;
4179
4178
  _lng = "lng" in lat ? lat.lng : lat.lon;
4180
4179
  _alt = lat.alt;
4181
- } else {
4182
- _lat = lat;
4183
- _lng = lng;
4184
- _alt = alt;
4185
4180
  }
4186
4181
  /**
4187
4182
  * Latitude in degrees.
4188
4183
  * @type {number}
4189
4184
  */
4190
- this.lat = +_lat;
4185
+ this.lat = toNumber(_lat);
4191
4186
  /**
4192
4187
  * Longitude in degrees.
4193
4188
  * @type {number}
4194
4189
  */
4195
- this.lng = +_lng;
4196
- if (_alt !== void 0)
4197
- /**
4198
- * Altitude in meters (optional).
4199
- * @type {number|undefined}
4200
- */
4201
- 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
+ }
4202
4200
  }
4203
4201
  /**
4204
4202
  * Returns the given `LatLng` object as it is, or else a new `LatLng` object created
@@ -4227,12 +4225,11 @@ var LatLng = class LatLng {
4227
4225
  * @returns {boolean}
4228
4226
  */
4229
4227
  static validate(lat, lng, alt) {
4230
- if (lat instanceof LatLng || typeof lat === "object" && lat !== null && "lat" in lat) return true;
4231
- else if (lat && Array.isArray(lat) && typeof lat[0] !== "object") {
4232
- if (lat.length === 3 || lat.length === 2) return true;
4228
+ try {
4229
+ return !!new LatLng(lat, lng, alt);
4230
+ } catch {
4233
4231
  return false;
4234
- } else if ((lat || lat === 0) && (lng || lng === 0)) return true;
4235
- return false;
4232
+ }
4236
4233
  }
4237
4234
  /**
4238
4235
  * Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.
@@ -4622,6 +4619,7 @@ function pointToGeoJSON(layer, precision) {
4622
4619
  });
4623
4620
  }
4624
4621
  // src/layer/vector/CircleMarker.js
4622
+ /** @import {MaplairMap} from '../../map/Map.js' */
4625
4623
  /** @import {Feature} from 'geojson' */
4626
4624
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
4627
4625
  /** @import {MaplairEvent} from '../../core/Events.js' */
@@ -4666,6 +4664,13 @@ var CircleMarker = class CircleMarker extends Path {
4666
4664
  this.callInitHooks(CircleMarker);
4667
4665
  }
4668
4666
  /**
4667
+ * @param {MaplairMap} map
4668
+ */
4669
+ beforeAdd(map) {
4670
+ super.beforeAdd(map);
4671
+ map._displaceHandler?._beforeMarkerAdd(this);
4672
+ }
4673
+ /**
4669
4674
  * Sets the position of a circle marker to a new location.
4670
4675
  * @param {LatLngExpression} latlng
4671
4676
  * @returns {this}
@@ -4713,7 +4718,7 @@ var CircleMarker = class CircleMarker extends Path {
4713
4718
  return this;
4714
4719
  }
4715
4720
  _project() {
4716
- this._point = this._map.latLngToLayerPoint(this._latlng)._round();
4721
+ this._point = this._renderer._latLngToLayerPoint(this._latlng)._round();
4717
4722
  this._pxRadius = this._radius;
4718
4723
  this._updateBounds();
4719
4724
  }
@@ -5190,13 +5195,7 @@ var Transformation = class {
5190
5195
  * @param {number} [d]
5191
5196
  */
5192
5197
  constructor(a, b, c, d) {
5193
- if (Array.isArray(a)) {
5194
- this._a = a[0];
5195
- this._b = a[1];
5196
- this._c = a[2];
5197
- this._d = a[3];
5198
- return;
5199
- }
5198
+ if (Array.isArray(a)) [a, b, c, d] = a;
5200
5199
  this._a = a;
5201
5200
  this._b = b;
5202
5201
  this._c = c;
@@ -5340,10 +5339,10 @@ var PosAnimation = class PosAnimation extends Evented {
5340
5339
  * @property {string} [position='topleft'] The position of the control (one of the map
5341
5340
  * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
5342
5341
  * `'bottomright'`.
5343
- * @property {string} [zoomInText='<span aria-hidden="true">+</span>'] The text set on
5344
- * the 'zoom in' button.
5345
- * @property {string} [zoomOutText='<span aria-hidden="true">&#x2212;</span>'] The text
5346
- * 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.
5347
5346
  * @extends ControlOptions
5348
5347
  */
5349
5348
  /**
@@ -5367,8 +5366,8 @@ var PosAnimation = class PosAnimation extends Evented {
5367
5366
  var ZoomControl = class ZoomControl extends Control {
5368
5367
  static defaultOptions = {
5369
5368
  position: "topleft",
5370
- zoomInText: "<span aria-hidden=\"true\">+</span>",
5371
- 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>"
5372
5371
  };
5373
5372
  /**
5374
5373
  * Creates a zoom control.
@@ -5380,23 +5379,24 @@ var ZoomControl = class ZoomControl extends Control {
5380
5379
  }
5381
5380
  /**
5382
5381
  * @internal
5383
- * @param {MaplairMap} map
5384
5382
  * @returns {HTMLElement}
5385
5383
  */
5386
- onAdd(map) {
5384
+ onAdd() {
5387
5385
  const zoomName = "maplair-control-zoom", container = create("div", `${zoomName} maplair-bar`), options = this.options;
5388
5386
  this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, (e) => this._zoom(e, 1));
5389
5387
  this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, (e) => this._zoom(e, -1));
5390
5388
  this._updateDisabled();
5391
- map.on("zoomend zoomlevelschange", this._updateDisabled, this);
5392
5389
  return container;
5393
5390
  }
5394
5391
  /**
5395
5392
  * @internal
5396
- * @param {MaplairMap} map
5393
+ * @returns {Record<string, Function>}
5397
5394
  */
5398
- onRemove(map) {
5399
- map.off("zoomend zoomlevelschange", this._updateDisabled, this);
5395
+ getEvents() {
5396
+ return {
5397
+ zoomend: this._updateDisabled,
5398
+ zoomlevelschange: this._updateDisabled
5399
+ };
5400
5400
  }
5401
5401
  /**
5402
5402
  * Disables the zoom buttons.
@@ -5433,7 +5433,6 @@ var ZoomControl = class ZoomControl extends Control {
5433
5433
  on(link, "click", (e) => {
5434
5434
  stop(e);
5435
5435
  fn.call(this, e);
5436
- this._refocusOnMap(e);
5437
5436
  });
5438
5437
  return link;
5439
5438
  }
@@ -5753,9 +5752,12 @@ var FeatureGroup = class FeatureGroup extends LayerGroup {
5753
5752
  /** @import {EventListener, MaplairEvent} from '../core/Events.js' */
5754
5753
  /**
5755
5754
  * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an
5756
- * `HTMLElement`, or a function receiving the source layer and returning one of them.
5757
- * @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
5758
5759
  */
5760
+ const fragmentNodes = /* @__PURE__ */ new WeakMap();
5759
5761
  /**
5760
5762
  * Options of `DivOverlay`.
5761
5763
  * @typedef {object} DivOverlayOptions
@@ -5771,8 +5773,8 @@ var FeatureGroup = class FeatureGroup extends LayerGroup {
5771
5773
  * in the DOM (for styling and events).
5772
5774
  * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while
5773
5775
  * initializing. If a function is passed the source layer will be passed to the
5774
- * function. The function should return a `String` or `HTMLElement` to be used in the
5775
- * 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
5776
5778
  * `HTMLElement` with safe `textContent` instead.
5777
5779
  * @extends InteractiveLayerOptions
5778
5780
  */
@@ -5804,7 +5806,8 @@ const layerDivOverlayMethods = { _initOverlay(OverlayClass, old, content, option
5804
5806
  } };
5805
5807
  /** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */
5806
5808
  /**
5807
- * 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.
5808
5811
  *
5809
5812
  * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
5810
5813
  */
@@ -5881,8 +5884,7 @@ var DivOverlay = class DivOverlay extends Layer {
5881
5884
  else {
5882
5885
  if (arguments.length) this._source = layer;
5883
5886
  else layer = this._source;
5884
- this._prepareOpen();
5885
- this.openOn(layer._map);
5887
+ if (this._prepareOpen()) this.openOn(layer._map);
5886
5888
  }
5887
5889
  return this;
5888
5890
  }
@@ -5894,7 +5896,7 @@ var DivOverlay = class DivOverlay extends Layer {
5894
5896
  if (!this._container) this._initLayout();
5895
5897
  if (map._fadeAnimated) this._container.style.opacity = "0";
5896
5898
  clearTimeout(this._removeTimeout);
5897
- this.getPane().appendChild(this._container);
5899
+ this.getPane().append(this._container);
5898
5900
  if (this.options.overflow) {
5899
5901
  this._container.classList.add("maplair-overflow");
5900
5902
  this._container.popover = "manual";
@@ -5967,9 +5969,10 @@ var DivOverlay = class DivOverlay extends Layer {
5967
5969
  /**
5968
5970
  * Sets the HTML content of the overlay. A `String` argument is rendered as
5969
5971
  * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)
5970
- * or pass an `HTMLElement` with safe `textContent` instead. If a function is
5971
- * passed the source layer will be passed to the function. The function should
5972
- * 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.
5973
5976
  * @param {DivOverlayContent} content
5974
5977
  * @returns {this}
5975
5978
  */
@@ -6017,7 +6020,7 @@ var DivOverlay = class DivOverlay extends Layer {
6017
6020
  * @returns {boolean}
6018
6021
  */
6019
6022
  isOpen() {
6020
- return !!this._map && this._map.hasLayer(this);
6023
+ return !!this._map?.hasLayer(this);
6021
6024
  }
6022
6025
  /**
6023
6026
  * Brings this overlay in front of other overlays (in the same map pane).
@@ -6061,25 +6064,21 @@ var DivOverlay = class DivOverlay extends Layer {
6061
6064
  if (!source) return false;
6062
6065
  this._source = source;
6063
6066
  }
6064
- if (!latlng) {
6065
- if (source.getCenter) latlng = source.getCenter();
6066
- else if (source.getLatLng) latlng = source.getLatLng();
6067
- else if (source.getBounds) latlng = source.getBounds().getCenter();
6068
- else throw new Error("Unable to get source layer LatLng.");
6069
- }
6067
+ latlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();
6068
+ if (!latlng) throw new Error("Unable to get source layer LatLng.");
6070
6069
  this.setLatLng(latlng);
6071
6070
  if (this._map) this.update();
6072
6071
  return true;
6073
6072
  }
6074
6073
  _updateContent() {
6075
- if (!this._content) return;
6074
+ if (this._content == null) return;
6076
6075
  const node = this._contentNode;
6077
6076
  const content = typeof this._content === "function" ? this._content(this._source ?? this) : this._content;
6078
6077
  if (typeof content === "string") node.innerHTML = content;
6079
- else {
6080
- while (node.hasChildNodes()) node.removeChild(node.firstChild);
6081
- node.appendChild(content);
6082
- }
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);
6083
6082
  this.fire("contentupdate");
6084
6083
  }
6085
6084
  _updatePosition() {
@@ -6230,7 +6229,7 @@ const layerPopupMethods = {
6230
6229
  * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
6231
6230
  * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
6232
6231
  * it will receive the layer as the first argument and should return a
6233
- * `String` or `HTMLElement`.
6232
+ * `String`, `HTMLElement` or `DocumentFragment`.
6234
6233
  * @group Popup methods
6235
6234
  * @param {DivOverlayContent|Popup} content
6236
6235
  * @param {PopupOptions} [options]
@@ -6238,6 +6237,7 @@ const layerPopupMethods = {
6238
6237
  */
6239
6238
  bindPopup(content, options) {
6240
6239
  this._popup = this._initOverlay(Popup, this._popup, content, options);
6240
+ this._popup._updateSourceAria(this._popup.isOpen());
6241
6241
  this.on({
6242
6242
  click: this._openPopup,
6243
6243
  remove: this.closePopup,
@@ -6257,6 +6257,9 @@ const layerPopupMethods = {
6257
6257
  remove: this.closePopup,
6258
6258
  move: this._movePopup
6259
6259
  });
6260
+ const el = this.getElement?.();
6261
+ el?.removeAttribute("aria-expanded");
6262
+ el?.removeAttribute("aria-controls");
6260
6263
  this._popup = null;
6261
6264
  }
6262
6265
  return this;
@@ -6325,9 +6328,8 @@ const layerPopupMethods = {
6325
6328
  if (!this._popup || !this._map) return;
6326
6329
  stopPropagation(e);
6327
6330
  const target = e.propagatedFrom ?? e.target;
6328
- if (this._popup._source === target && !(target instanceof Path)) {
6329
- if (this._map.hasLayer(this._popup)) this.closePopup();
6330
- else this.openPopup(e.latlng);
6331
+ if (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {
6332
+ this.closePopup();
6331
6333
  return;
6332
6334
  }
6333
6335
  this._popup._source = target;
@@ -6424,9 +6426,11 @@ var Popup = class Popup extends DivOverlay {
6424
6426
  */
6425
6427
  openOn(map) {
6426
6428
  map = arguments.length ? map : this._source._map;
6427
- 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);
6428
6430
  map._popup = this;
6429
- return super.openOn(map);
6431
+ super.openOn(map);
6432
+ this._updateSourceAria(true);
6433
+ return this;
6430
6434
  }
6431
6435
  /**
6432
6436
  * Adds the popup to the map.
@@ -6441,9 +6445,10 @@ var Popup = class Popup extends DivOverlay {
6441
6445
  (this._closeButton ?? this._container).focus({ preventScroll: true });
6442
6446
  }
6443
6447
  map.fire("popupopen", { popup: this });
6448
+ this._updateSourceAria(true);
6444
6449
  if (this._source) {
6445
6450
  this._source.fire("popupopen", { popup: this }, true);
6446
- if (!(this._source instanceof Path)) this._source.on("preclick", stopPropagation);
6451
+ if (this._source._togglesPopupOnClick()) this._source.on("preclick", stopPropagation);
6447
6452
  }
6448
6453
  }
6449
6454
  /**
@@ -6451,13 +6456,17 @@ var Popup = class Popup extends DivOverlay {
6451
6456
  * @param {MaplairMap} map
6452
6457
  */
6453
6458
  onRemove(map) {
6454
- 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
+ }
6455
6463
  this._returnFocus = null;
6456
6464
  super.onRemove(map);
6457
6465
  map.fire("popupclose", { popup: this });
6466
+ this._updateSourceAria(false);
6458
6467
  if (this._source) {
6459
6468
  this._source.fire("popupclose", { popup: this }, true);
6460
- if (!(this._source instanceof Path)) this._source.off("preclick", stopPropagation);
6469
+ if (this._source._togglesPopupOnClick()) this._source.off("preclick", stopPropagation);
6461
6470
  }
6462
6471
  }
6463
6472
  /**
@@ -6470,8 +6479,17 @@ var Popup = class Popup extends DivOverlay {
6470
6479
  if (this.options.keepInView) events.moveend = this._adjustPan;
6471
6480
  return events;
6472
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
+ }
6473
6490
  _initLayout() {
6474
6491
  const prefix = "maplair-popup", container = this._container = create("div", `${prefix} ${this.options.className || ""} maplair-zoom-animated`);
6492
+ container.id = `maplair-popup-${stamp(this)}`;
6475
6493
  const wrapper = this._wrapper = create("div", `${prefix}-content-wrapper`, container);
6476
6494
  this._contentNode = create("div", `${prefix}-content`, wrapper);
6477
6495
  disableClickPropagation(container);
@@ -6483,7 +6501,7 @@ var Popup = class Popup extends DivOverlay {
6483
6501
  const closeButton = this._closeButton = create("button", `${prefix}-close-button`, container);
6484
6502
  closeButton.type = "button";
6485
6503
  closeButton.setAttribute("aria-label", I18n.translate("Close popup"));
6486
- closeButton.innerHTML = "<span aria-hidden=\"true\">&#215;</span>";
6504
+ closeButton.textContent = "×";
6487
6505
  on(closeButton, "click", (ev) => {
6488
6506
  ev.preventDefault();
6489
6507
  this.close();
@@ -6551,13 +6569,13 @@ var Popup = class Popup extends DivOverlay {
6551
6569
  }
6552
6570
  };
6553
6571
  // src/layer/Tooltip.js
6554
- const directions = [
6555
- "top",
6556
- "bottom",
6557
- "center",
6558
- "right",
6559
- "left"
6560
- ];
6572
+ const directions = {
6573
+ top: [.5, 1],
6574
+ bottom: [.5, 0],
6575
+ center: [.5, .5],
6576
+ right: [0, .5],
6577
+ left: [1, .5]
6578
+ };
6561
6579
  const tipSize = 6;
6562
6580
  const autoPadding = 4;
6563
6581
  function shiftInto(start, size, min, max) {
@@ -6650,7 +6668,7 @@ const layerTooltipMethods = {
6650
6668
  * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
6651
6669
  * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
6652
6670
  * it will receive the layer as the first argument and should return a
6653
- * `String` or `HTMLElement`.
6671
+ * `String`, `HTMLElement` or `DocumentFragment`.
6654
6672
  * @group Tooltip methods
6655
6673
  * @param {DivOverlayContent|Tooltip} content
6656
6674
  * @param {TooltipOptions} [options]
@@ -6661,7 +6679,7 @@ const layerTooltipMethods = {
6661
6679
  if (this._tooltip) this.unbindTooltip();
6662
6680
  this._tooltip = this._initOverlay(Tooltip, old, content, options);
6663
6681
  this._initTooltipInteractions();
6664
- 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();
6665
6683
  return this;
6666
6684
  },
6667
6685
  /**
@@ -6703,11 +6721,7 @@ const layerTooltipMethods = {
6703
6721
  openTooltip(latlng) {
6704
6722
  if (this._tooltip) {
6705
6723
  if (!(this instanceof FeatureGroup)) this._tooltip._source = this;
6706
- if (this._tooltip._prepareOpen(latlng)) {
6707
- this._tooltip.openOn(this._map);
6708
- if (this.getElement) this._setAriaDescribedByOnLayer(this);
6709
- else if (this.eachLayer) this.eachLayer(this._setAriaDescribedByOnLayer, this);
6710
- }
6724
+ if (this._tooltip._prepareOpen(latlng)) this._tooltip.openOn(this._map);
6711
6725
  }
6712
6726
  return this;
6713
6727
  },
@@ -6768,7 +6782,7 @@ const layerTooltipMethods = {
6768
6782
  if (!remove) {
6769
6783
  el._maplair_focus_handler && off(el, "focus", el._maplair_focus_handler, this);
6770
6784
  el._maplair_focus_handler = () => {
6771
- if (this._tooltip) {
6785
+ if (this._tooltip && el.matches(":focus-visible")) {
6772
6786
  this._tooltip._source = layer;
6773
6787
  this.openTooltip();
6774
6788
  }
@@ -6779,9 +6793,6 @@ const layerTooltipMethods = {
6779
6793
  if (remove) delete el._maplair_focus_handler;
6780
6794
  }
6781
6795
  },
6782
- _setAriaDescribedByOnLayer(layer) {
6783
- (typeof layer.getElement === "function" && layer.getElement())?.setAttribute?.("aria-describedby", this._tooltip._container.id);
6784
- },
6785
6796
  _openTooltip(e) {
6786
6797
  if (!this._tooltip || !this._map) return;
6787
6798
  if (this._map.dragging?.moving()) {
@@ -6798,13 +6809,7 @@ const layerTooltipMethods = {
6798
6809
  this.openTooltip(this._tooltip.options.sticky ? e.latlng : void 0);
6799
6810
  },
6800
6811
  _moveTooltip(e) {
6801
- let latlng = e.latlng, containerPoint, layerPoint;
6802
- if (this._tooltip.options.sticky && e.originalEvent) {
6803
- containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
6804
- layerPoint = this._map.containerPointToLayerPoint(containerPoint);
6805
- latlng = this._map.layerPointToLatLng(layerPoint);
6806
- }
6807
- this._tooltip.setLatLng(latlng);
6812
+ this._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ? this._map.pointerEventToLatLng(e.originalEvent) : e.latlng);
6808
6813
  }
6809
6814
  };
6810
6815
  /** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */
@@ -6893,6 +6898,7 @@ var Tooltip = class Tooltip extends DivOverlay {
6893
6898
  map.fire("tooltipopen", { tooltip: this });
6894
6899
  if (this._source) {
6895
6900
  this.addEventParent(this._source);
6901
+ this._source.getElement?.()?.setAttribute("aria-describedby", this._container.id);
6896
6902
  this._source.fire("tooltipopen", { tooltip: this }, true);
6897
6903
  }
6898
6904
  }
@@ -6921,7 +6927,7 @@ var Tooltip = class Tooltip extends DivOverlay {
6921
6927
  const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-animated`;
6922
6928
  this._contentNode = this._container = create("div", className);
6923
6929
  this._container.setAttribute("role", "tooltip");
6924
- this._container.setAttribute("id", `maplair-tooltip-${stamp(this)}`);
6930
+ this._container.id = `maplair-tooltip-${stamp(this)}`;
6925
6931
  }
6926
6932
  _updateLayout() {}
6927
6933
  _adjustPan() {}
@@ -6936,21 +6942,16 @@ var Tooltip = class Tooltip extends DivOverlay {
6936
6942
  _setPosition(pos) {
6937
6943
  let direction = this.options.direction, shift = new Point(0, 0);
6938
6944
  const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset), anchor = this._getAnchor();
6939
- if (!directions.includes(direction)) {
6945
+ if (!(direction in directions)) {
6940
6946
  ({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));
6941
6947
  if (direction === "left") {
6942
6948
  offset.x = -offset.x;
6943
6949
  anchor.x = -anchor.x;
6944
6950
  }
6945
6951
  }
6946
- let subX = tooltipWidth / 2, subY = tooltipHeight / 2;
6947
- if (direction === "top") subY = tooltipHeight;
6948
- else if (direction === "bottom") subY = 0;
6949
- else if (direction === "right") subX = 0;
6950
- else if (direction === "left") subX = tooltipWidth;
6951
- pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor).add(shift);
6952
- container.classList.remove("maplair-tooltip-right", "maplair-tooltip-left", "maplair-tooltip-top", "maplair-tooltip-bottom");
6953
- 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);
6954
6955
  const tipShift = direction === "top" || direction === "bottom" ? clampTip(-shift.x, tooltipWidth) : clampTip(-shift.y, tooltipHeight);
6955
6956
  if (tipShift) container.style.setProperty("--maplair-tooltip-tip-shift", `${tipShift}px`);
6956
6957
  else container.style.removeProperty("--maplair-tooltip-tip-shift");
@@ -7066,7 +7067,8 @@ const mapRendererMethods = {
7066
7067
  * @lends MaplairMapOptions
7067
7068
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
7068
7069
  * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
7069
- * 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.
7070
7072
  */
7071
7073
  /**
7072
7074
  * Registers `getRenderer()` and related methods on the given map class, called by
@@ -7195,12 +7197,14 @@ var BoxZoomHandler = class BoxZoomHandler extends Handler {
7195
7197
  */
7196
7198
  addHooks() {
7197
7199
  on(this._map._container, "pointerdown", this._onPointerDown, this);
7200
+ this._map._container.classList.add("maplair-box-zoom");
7198
7201
  }
7199
7202
  /**
7200
7203
  * Called when the handler is disabled, removes the event hooks.
7201
7204
  */
7202
7205
  removeHooks() {
7203
7206
  off(this._map._container, "pointerdown", this._onPointerDown, this);
7207
+ this._map._container.classList.remove("maplair-box-zoom");
7204
7208
  }
7205
7209
  /**
7206
7210
  * Returns `true` if a box has been drawn by the current or last interaction.
@@ -7413,13 +7417,13 @@ var Draggable = class Draggable extends Evented {
7413
7417
  }
7414
7418
  _onDown(e) {
7415
7419
  this._moved = false;
7416
- if (this._element.classList.contains("maplair-zoom-anim")) return;
7417
7420
  const pointers = getPointers().length;
7418
7421
  if (pointers > 1) {
7419
7422
  if (Draggable._dragging === this) this.finishDrag();
7420
7423
  return;
7421
7424
  }
7422
- 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;
7423
7427
  Draggable._dragging = this;
7424
7428
  disableImageDrag();
7425
7429
  if (this._moving) return;
@@ -7477,10 +7481,8 @@ var Draggable = class Draggable extends Evented {
7477
7481
  finishDrag(noInertia) {
7478
7482
  this._draggingContainer?.classList.remove("maplair-dragging");
7479
7483
  this._draggingContainer = null;
7480
- if (this._lastTarget) {
7481
- this._lastTarget.classList.remove("maplair-drag-target");
7482
- this._lastTarget = null;
7483
- }
7484
+ this._lastTarget?.classList.remove("maplair-drag-target");
7485
+ this._lastTarget = null;
7484
7486
  off(this._dragStartTarget, "pointermove", this._onMove, this);
7485
7487
  off(this._dragStartTarget, "pointerup pointercancel lostpointercapture", this._onUp, this);
7486
7488
  enableImageDrag();
@@ -7739,7 +7741,7 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
7739
7741
  const container = this._map._container;
7740
7742
  if (container.tabIndex <= 0) container.tabIndex = 0;
7741
7743
  const shortcuts = this._map.options.ariaKeyShortcuts;
7742
- 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);
7743
7745
  on(container, {
7744
7746
  focus: this._onFocus,
7745
7747
  blur: this._onBlur,
@@ -7795,7 +7797,7 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
7795
7797
  return help;
7796
7798
  }
7797
7799
  _onPointerDown() {
7798
- if (this._focused) return;
7800
+ if (this._focused || this._map._container.contains(document.activeElement)) return;
7799
7801
  this._map._container.focus({
7800
7802
  preventScroll: true,
7801
7803
  focusVisible: false
@@ -7813,11 +7815,9 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
7813
7815
  }
7814
7816
  _onContainerKeyDown(e) {
7815
7817
  const map = this._map, popup = map._popup;
7816
- if (e.key !== "Escape" || e.defaultPrevented || !popup?.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
7817
- 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;
7818
7819
  map.closePopup();
7819
7820
  e.preventDefault();
7820
- if (inPopup) (icon?.tabIndex >= 0 ? icon : map._container).focus();
7821
7821
  }
7822
7822
  _onKeyDown(e) {
7823
7823
  if (e.altKey || e.ctrlKey || e.metaKey) return;
@@ -7922,8 +7922,8 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
7922
7922
  this._moved = false;
7923
7923
  this._zooming = true;
7924
7924
  map._stop();
7925
- on(this._map._container, "pointermove", this._onPointerMove, this);
7926
- 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);
7927
7927
  e.preventDefault();
7928
7928
  }
7929
7929
  _onPointerMove(e) {
@@ -7946,10 +7946,7 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
7946
7946
  this._moved = true;
7947
7947
  }
7948
7948
  cancelAnimationFrame(this._animRequest);
7949
- const moveFn = map._move.bind(map, this._center, this._zoom, {
7950
- pinch: true,
7951
- round: false
7952
- }, void 0);
7949
+ const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
7953
7950
  this._animRequest = requestAnimationFrame(moveFn.bind(this));
7954
7951
  e.preventDefault();
7955
7952
  }
@@ -8102,10 +8099,7 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
8102
8099
  const frame = () => {
8103
8100
  const pinch = this._pinch, delta = pinch.zoom - pinch.shown;
8104
8101
  pinch.shown = eased && Math.abs(delta) > .01 ? pinch.shown + delta * .3 : pinch.zoom;
8105
- map._move(this._getPinchCenter(pinch.shown), pinch.shown, {
8106
- pinch: true,
8107
- round: false
8108
- });
8102
+ map._move(this._getPinchCenter(pinch.shown), pinch.shown, { pinch: true });
8109
8103
  if (pinch.shown !== pinch.zoom) this._pinchFrame = requestAnimationFrame(frame);
8110
8104
  };
8111
8105
  cancelAnimationFrame(this._pinchFrame);
@@ -8169,9 +8163,9 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
8169
8163
  stop(e);
8170
8164
  }
8171
8165
  _performZoom() {
8172
- 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;
8173
8167
  map._stop();
8174
- 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;
8175
8169
  this._delta = 0;
8176
8170
  this._startTime = null;
8177
8171
  if (!delta || map._zoomInputBlocked()) return;
@@ -8236,47 +8230,35 @@ var TapHoldHandler = class TapHoldHandler extends Handler {
8236
8230
  removeHooks() {
8237
8231
  off(this._map._container, "pointerdown", this._onDown, this);
8238
8232
  this._cancel();
8239
- this._cancelClickPrevent();
8240
8233
  this._stopPreventingNative();
8241
8234
  }
8242
8235
  _onDown(e) {
8243
8236
  clearTimeout(this._holdTimeout);
8244
8237
  if (getPointers().length !== 1 || e.pointerType === "mouse") return;
8245
- const el = this._map._container;
8246
- this._startPos = this._newPos = new Point(e.clientX, e.clientY);
8238
+ const el = this._map._container, start = new Point(e.clientX, e.clientY);
8247
8239
  this._holdTimeout = setTimeout((() => {
8248
8240
  this._cancel();
8249
- if (!this._isTapValid()) return;
8250
- on(el, "pointerup", preventDefault);
8251
- 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;
8252
8243
  this._simulateEvent("contextmenu", e);
8253
8244
  el.addEventListener("contextmenu", stop, true);
8245
+ el.addEventListener("click", stop, true);
8254
8246
  el.addEventListener("pointerdown", this._stopPreventingNative, true);
8247
+ el.addEventListener("keydown", this._stopPreventingNative, true);
8255
8248
  }), tapHoldDelay);
8256
8249
  on(el, "pointerup pointercancel contextmenu", this._cancel, this);
8257
- on(el, "pointermove", this._onMove, this);
8258
- }
8259
- _cancelClickPrevent() {
8260
- const el = this._map._container;
8261
- off(el, "pointerup", preventDefault);
8262
- off(el, "pointerup pointercancel", this._cancelClickPrevent, this);
8263
8250
  }
8264
8251
  _stopPreventingNative = () => {
8265
8252
  const el = this._map._container;
8266
8253
  el.removeEventListener("contextmenu", stop, true);
8254
+ el.removeEventListener("click", stop, true);
8267
8255
  el.removeEventListener("pointerdown", this._stopPreventingNative, true);
8256
+ el.removeEventListener("keydown", this._stopPreventingNative, true);
8268
8257
  };
8269
8258
  _cancel() {
8270
8259
  clearTimeout(this._holdTimeout);
8271
8260
  const el = this._map._container;
8272
8261
  off(el, "pointerup pointercancel contextmenu", this._cancel, this);
8273
- off(el, "pointermove", this._onMove, this);
8274
- }
8275
- _onMove(e) {
8276
- this._newPos = new Point(e.clientX, e.clientY);
8277
- }
8278
- _isTapValid() {
8279
- return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
8280
8262
  }
8281
8263
  _simulateEvent(type, e) {
8282
8264
  const simulatedEvent = new MouseEvent(type, {
@@ -8417,10 +8399,7 @@ var TapDragZoomHandler = class TapDragZoomHandler extends Handler {
8417
8399
  this._moved = true;
8418
8400
  }
8419
8401
  cancelAnimationFrame(this._animRequest);
8420
- this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, {
8421
- pinch: true,
8422
- round: false
8423
- }));
8402
+ this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, { pinch: true }));
8424
8403
  e.preventDefault();
8425
8404
  }
8426
8405
  _onUp() {
@@ -8476,7 +8455,9 @@ const zoomAnimDuration = 250;
8476
8455
  * user tries to pan outside the view. To set the restriction dynamically, use
8477
8456
  * [`setMaxBounds`](#map-setmaxbounds) method.
8478
8457
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
8479
- * 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.
8480
8461
  * @property {boolean} [zoomAnimation=true] Whether the map zoom animation is enabled.
8481
8462
  * @property {number} [zoomAnimationThreshold=4] Won't animate zoom if the zoom
8482
8463
  * difference exceeds this value (or 1 if the user prefers
@@ -8560,15 +8541,25 @@ const zoomAnimDuration = 250;
8560
8541
  /**
8561
8542
  * Options of the `MaplairMap` methods which modify the zoom level and the center.
8562
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`.
8563
8552
  * @extends ZoomOptions, PanOptions
8564
8553
  */
8565
8554
  /**
8566
8555
  * Options of `MaplairMap.invalidateSize()`.
8567
8556
  * @typedef {object} InvalidateSizeOptions
8557
+ * @property {boolean} [animate=false] If `true`, the map pans to its new center with
8558
+ * animation.
8568
8559
  * @property {boolean} [pan=true] If `false`, panning will not occur.
8569
8560
  * @property {boolean} [debounceMoveend=false] If `true`, it will delay `moveend` event
8570
8561
  * so that it doesn't happen often even if the method is called many times in a row.
8571
- * @extends ZoomPanOptions
8562
+ * @extends PanOptions
8572
8563
  */
8573
8564
  /**
8574
8565
  * Padding options of `MaplairMap` methods, e.g. `panInside()`.
@@ -8616,7 +8607,9 @@ const zoomAnimDuration = 250;
8616
8607
  * pressing a key or clicking a zoom button) have an `originalEvent` property with the
8617
8608
  * DOM event that started the change. It is `undefined` for changes made by code (e.g.
8618
8609
  * `setView()`), which allows to tell them apart, e.g. to avoid feedback loops when
8619
- * 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.
8620
8613
  *
8621
8614
  * @example
8622
8615
  * ```js
@@ -8716,6 +8709,7 @@ var MaplairMap = class MaplairMap extends Evented {
8716
8709
  this._handlers = [];
8717
8710
  this._layers = {};
8718
8711
  this._zoomBoundLayers = {};
8712
+ this._canvases = [];
8719
8713
  this._sizeChanged = true;
8720
8714
  this._initContainer(id);
8721
8715
  this._initLayout();
@@ -8746,10 +8740,23 @@ var MaplairMap = class MaplairMap extends Evented {
8746
8740
  * @returns {this}
8747
8741
  */
8748
8742
  setView(center, zoom, options) {
8749
- zoom = zoom === void 0 ? this._zoom : this._limitZoom(zoom);
8743
+ zoom = zoom === void 0 ? this._targetZoom() : this._limitZoom(zoom);
8744
+ const targetCenter = center;
8750
8745
  center = this._limitCenter(new LatLng(center), zoom, this.options.maxBounds);
8751
8746
  options ??= {};
8752
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
+ }
8753
8760
  if (this._loaded && !options.reset && options !== true) {
8754
8761
  if (options.animate !== void 0) {
8755
8762
  options.zoom = {
@@ -8762,12 +8769,12 @@ var MaplairMap = class MaplairMap extends Evented {
8762
8769
  ...options.pan
8763
8770
  };
8764
8771
  }
8765
- 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)) {
8766
8773
  clearTimeout(this._sizeTimer);
8767
8774
  return this;
8768
8775
  }
8769
8776
  }
8770
- this._resetView(center, zoom, options.pan?.noMoveStart);
8777
+ this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, zoom, options.pan?.noMoveStart);
8771
8778
  return this;
8772
8779
  }
8773
8780
  /**
@@ -8782,7 +8789,7 @@ var MaplairMap = class MaplairMap extends Evented {
8782
8789
  this._zoom = zoom;
8783
8790
  return this;
8784
8791
  }
8785
- return this.setView(this.getCenter(), zoom, { zoom: options });
8792
+ return this.setView(this._targetView?.center ?? this.getCenter(), zoom, { zoom: options });
8786
8793
  }
8787
8794
  /**
8788
8795
  * Increases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
@@ -8793,7 +8800,7 @@ var MaplairMap = class MaplairMap extends Evented {
8793
8800
  */
8794
8801
  zoomIn(delta, options) {
8795
8802
  delta ??= this.options.zoomDelta;
8796
- return this.setZoom(this._zoom + delta, options);
8803
+ return this.setZoom(this._targetZoom() + delta, options);
8797
8804
  }
8798
8805
  /**
8799
8806
  * Decreases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
@@ -8804,7 +8811,7 @@ var MaplairMap = class MaplairMap extends Evented {
8804
8811
  */
8805
8812
  zoomOut(delta, options) {
8806
8813
  delta ??= this.options.zoomDelta;
8807
- return this.setZoom(this._zoom - delta, options);
8814
+ return this.setZoom(this._targetZoom() - delta, options);
8808
8815
  }
8809
8816
  /**
8810
8817
  * Zooms the map while keeping a specified geographical point on the map
@@ -8826,7 +8833,7 @@ var MaplairMap = class MaplairMap extends Evented {
8826
8833
  bounds = bounds.getBounds ? bounds.getBounds() : LatLngBounds.from(bounds);
8827
8834
  const paddingTL = Point.from(options.paddingTopLeft || options.padding || [0, 0]), paddingBR = Point.from(options.paddingBottomRight || options.padding || [0, 0]);
8828
8835
  let zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR));
8829
- zoom = typeof options.maxZoom === "number" ? Math.min(options.maxZoom, zoom) : zoom;
8836
+ zoom = Math.min(options.maxZoom ?? Infinity, zoom);
8830
8837
  if (zoom === Infinity) return {
8831
8838
  center: bounds.getCenter(),
8832
8839
  zoom
@@ -8869,7 +8876,7 @@ var MaplairMap = class MaplairMap extends Evented {
8869
8876
  * @returns {this}
8870
8877
  */
8871
8878
  panTo(center, options) {
8872
- return this.setView(center, this._zoom, { pan: options });
8879
+ return this.setView(center, void 0, { pan: options });
8873
8880
  }
8874
8881
  /**
8875
8882
  * Pans the map by a given number of pixels (animated unless `animate: false` is passed,
@@ -8881,24 +8888,18 @@ var MaplairMap = class MaplairMap extends Evented {
8881
8888
  * @returns {this}
8882
8889
  */
8883
8890
  panBy(offset, options) {
8884
- 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) {
8885
8895
  options ??= {};
8886
- if (!offset.x && !offset.y) return this.fire("moveend");
8887
- const size = this.getSize();
8888
- if (options.animate !== true && !size.contains(offset)) {
8889
- const center = this.unproject(this.project(this.getCenter()).add(offset));
8890
- this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, this.getZoom());
8891
- return this;
8892
- }
8893
- if (!this._panAnim) {
8894
- this._panAnim = new PosAnimation();
8895
- this._panAnim.on({
8896
- "step": this._onPanTransitionStep,
8897
- "end": this._onPanTransitionEnd
8898
- }, this);
8899
- }
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);
8900
8901
  if (!options.noMoveStart) this.fire("movestart");
8901
- const tooFarForReducedMotion = this._prefersReducedMotion() && !size.divideBy(2).contains(offset);
8902
+ const tooFarForReducedMotion = this._prefersReducedMotion() && !this.getSize().divideBy(2).contains(offset);
8902
8903
  if (options.animate === true || options.animate !== false && !tooFarForReducedMotion) {
8903
8904
  this._mapPane.classList.add("maplair-pan-anim");
8904
8905
  const newPos = this._getMapPanePos().subtract(offset).round();
@@ -8906,7 +8907,7 @@ var MaplairMap = class MaplairMap extends Evented {
8906
8907
  } else {
8907
8908
  this._rawPanBy(offset);
8908
8909
  this._wrapWorldCopy();
8909
- this.fire("move").fire("moveend");
8910
+ this.fire("move")._moveEnd(false);
8910
8911
  }
8911
8912
  return this;
8912
8913
  }
@@ -8930,9 +8931,14 @@ var MaplairMap = class MaplairMap extends Evented {
8930
8931
  }
8931
8932
  });
8932
8933
  if (options.animate !== true && this._prefersReducedMotion()) return this.setView(targetCenter, targetZoom, options);
8933
- this._stop();
8934
- targetZoom = targetZoom === void 0 ? this._zoom : this._limitZoom(targetZoom);
8934
+ targetZoom = targetZoom === void 0 ? this._targetZoom() : this._limitZoom(targetZoom);
8935
+ const requestedCenter = targetCenter;
8935
8936
  targetCenter = this._limitCenter(new LatLng(targetCenter), targetZoom, this.options.maxBounds);
8937
+ this._stop();
8938
+ this._targetView = {
8939
+ center: requestedCenter,
8940
+ zoom: targetZoom
8941
+ };
8936
8942
  const from = this.project(this.getCenter()), to = this.project(targetCenter), size = this.getSize(), startZoom = this._zoom;
8937
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;
8938
8944
  function r(i) {
@@ -8946,7 +8952,7 @@ var MaplairMap = class MaplairMap extends Evented {
8946
8952
  function easeOut(t) {
8947
8953
  return 1 - (1 - t) ** 1.5;
8948
8954
  }
8949
- 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);
8950
8956
  const frame = () => {
8951
8957
  const t = (Date.now() - start) / duration, s = easeOut(t) * S;
8952
8958
  if (t <= 1) {
@@ -9098,8 +9104,8 @@ var MaplairMap = class MaplairMap extends Evented {
9098
9104
  }
9099
9105
  /**
9100
9106
  * Checks if the map container size changed and updates the map if so —
9101
- * call it after you've changed the map size dynamically, also animating
9102
- * 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.
9103
9109
  * If `options.debounceMoveend` is `true`, it will delay `moveend` event so
9104
9110
  * that it doesn't happen often even if the method is called many
9105
9111
  * times in a row. Passing `true` instead of options animates the panning.
@@ -9116,8 +9122,9 @@ var MaplairMap = class MaplairMap extends Evented {
9116
9122
  };
9117
9123
  const oldSize = this.getSize();
9118
9124
  this._sizeChanged = true;
9119
- this._lastCenter = null;
9120
- 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);
9121
9128
  if (!offset.x && !offset.y) return this;
9122
9129
  if (options.animate && options.pan) this.panBy(offset);
9123
9130
  else {
@@ -9199,7 +9206,7 @@ var MaplairMap = class MaplairMap extends Evented {
9199
9206
  }
9200
9207
  _handleGeolocationResponse(pos) {
9201
9208
  if (!this._container._maplair_id) return;
9202
- 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;
9203
9210
  if (options.setView) {
9204
9211
  const zoom = this.getBoundsZoom(bounds);
9205
9212
  this.setView(latlng, options.maxZoom ? Math.min(zoom, options.maxZoom) : zoom);
@@ -9233,7 +9240,7 @@ var MaplairMap = class MaplairMap extends Evented {
9233
9240
  */
9234
9241
  remove() {
9235
9242
  this._initEvents(true);
9236
- if (this.options.maxBounds) this.off("moveend", this._panInsideMaxBounds);
9243
+ this.off("moveend", this._panInsideMaxBounds);
9237
9244
  if (this._containerId !== this._container._maplair_id) throw new Error("Map container is being reused by another instance");
9238
9245
  delete this._container._maplair_id;
9239
9246
  delete this._containerId;
@@ -9332,7 +9339,7 @@ var MaplairMap = class MaplairMap extends Evented {
9332
9339
  bounds = LatLngBounds.from(bounds);
9333
9340
  padding = Point.from(padding ?? [0, 0]);
9334
9341
  let zoom = this.getZoom() ?? 0;
9335
- 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);
9336
9343
  zoom = this.getScaleZoom(scale, zoom);
9337
9344
  if (snap) {
9338
9345
  zoom = Math.round(zoom / (snap / 100)) * (snap / 100);
@@ -9742,10 +9749,13 @@ var MaplairMap = class MaplairMap extends Evented {
9742
9749
  return this;
9743
9750
  }
9744
9751
  _moveEnd(zoomChanged) {
9752
+ if (!this._pendingView) this._targetView = null;
9745
9753
  if (zoomChanged) this.fire("zoomend");
9746
9754
  return this.fire("moveend");
9747
9755
  }
9748
9756
  _stop() {
9757
+ this._pendingView = null;
9758
+ this._targetView = null;
9749
9759
  cancelAnimationFrame(this._flyToFrame);
9750
9760
  cancelAnimationFrame(this._zoomAnimFrame);
9751
9761
  this._panAnim?.stop();
@@ -9802,13 +9812,14 @@ var MaplairMap = class MaplairMap extends Evented {
9802
9812
  _findEventTargets(e, type) {
9803
9813
  let targets = [], target, src = e.target, dragging = false;
9804
9814
  const isHover = type === "pointerout" || type === "pointerover";
9815
+ const canEndDrag = (type === "click" || type === "preclick") && e.detail > 0;
9805
9816
  while (src) {
9806
9817
  target = this._targets[stamp(src)];
9807
- if (target && (type === "click" || type === "preclick") && this._draggableMoved(target)) {
9818
+ if (target && canEndDrag && this._draggableMoved(target)) {
9808
9819
  dragging = true;
9809
9820
  break;
9810
9821
  }
9811
- if (target && target.listens(type, true)) {
9822
+ if (target?.listens(type, true)) {
9812
9823
  if (isHover && !isExternalTarget(src, e)) break;
9813
9824
  targets.push(target);
9814
9825
  if (isHover) break;
@@ -9827,8 +9838,23 @@ var MaplairMap = class MaplairMap extends Evented {
9827
9838
  }
9828
9839
  _handleDOMEvent(e) {
9829
9840
  const el = e.target;
9830
- if (!this._loaded || el["_maplair_disable_events"] || e.type === "click" && this._isClickDisabled(el)) return;
9831
- 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
+ }
9832
9858
  }
9833
9859
  static _pointerEvents = [
9834
9860
  "click",
@@ -9839,7 +9865,7 @@ var MaplairMap = class MaplairMap extends Evented {
9839
9865
  ];
9840
9866
  _fireDOMEvent(e, type, canvasTargets) {
9841
9867
  if (type === "click") this._fireDOMEvent(e, "preclick", canvasTargets);
9842
- let targets = this._findEventTargets(e, type);
9868
+ let targets = canvasTargets && (type === "pointerover" || type === "pointerout") ? [] : this._findEventTargets(e, type);
9843
9869
  if (canvasTargets) targets = [...canvasTargets.filter((t) => t.listens(type, true)), ...targets];
9844
9870
  if (!targets.length) return;
9845
9871
  if (type === "contextmenu") e.preventDefault();
@@ -9927,17 +9953,17 @@ var MaplairMap = class MaplairMap extends Evented {
9927
9953
  _onPanTransitionEnd() {
9928
9954
  this._mapPane.classList.remove("maplair-pan-anim");
9929
9955
  this._wrapWorldCopy();
9930
- this.fire("moveend");
9956
+ this._moveEnd(false);
9931
9957
  }
9932
9958
  _tryAnimatedPan(center, options) {
9933
- const offset = this._getCenterOffset(center)._trunc();
9959
+ const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
9934
9960
  if (options?.animate !== true && !this.getSize().contains(offset)) return false;
9935
- this.panBy(offset, options);
9961
+ this._panBy(offset, options);
9936
9962
  return true;
9937
9963
  }
9938
9964
  _createAnimProxy() {
9939
9965
  this._proxy = create("div", "maplair-proxy maplair-zoom-animated");
9940
- this._panes.mapPane.appendChild(this._proxy);
9966
+ this._panes.mapPane.append(this._proxy);
9941
9967
  this.on("zoomanim", this._animateProxyZoom, this);
9942
9968
  this.on("load moveend", this._animMoveEnd, this);
9943
9969
  on(this._proxy, "transitionend", this._catchTransitionEnd, this);
@@ -9971,6 +9997,9 @@ var MaplairMap = class MaplairMap extends Evented {
9971
9997
  };
9972
9998
  this._flyToFrame = requestAnimationFrame(frame);
9973
9999
  }
10000
+ _targetZoom() {
10001
+ return this._targetView?.zoom ?? this._zoom;
10002
+ }
9974
10003
  _zoomInputBlocked() {
9975
10004
  return this._animatingZoom || Date.now() < this._instantZoomEnd;
9976
10005
  }
@@ -10014,11 +10043,16 @@ var MaplairMap = class MaplairMap extends Evented {
10014
10043
  if (!this._animatingZoom) return;
10015
10044
  this._mapPane?.classList.remove("maplair-zoom-anim");
10016
10045
  this._animatingZoom = false;
10017
- this._move(this._animateToCenter, this._animateToZoom, void 0, true);
10046
+ this._move(this.getCenter(), this._animateToZoom, void 0, true);
10018
10047
  if (this._tempFireZoomEvent) this.fire("zoom");
10019
10048
  delete this._tempFireZoomEvent;
10020
10049
  this.fire("move");
10021
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
+ }
10022
10056
  }
10023
10057
  };
10024
10058
  for (const feature of [
@@ -10138,9 +10172,9 @@ var Polyline = class Polyline extends Path {
10138
10172
  closestLayerPoint(p) {
10139
10173
  p = Point.from(p);
10140
10174
  let minDistance = Infinity, minPoint = null, p1, p2;
10141
- const closest = _sqClosestPointOnSegment;
10142
- for (const points of this._parts) for (let i = 1, len = points.length; i < len; i++) {
10143
- 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];
10144
10178
  p2 = points[i];
10145
10179
  const sqDist = closest(p, p1, p2, true);
10146
10180
  if (sqDist < minDistance) {
@@ -10213,7 +10247,7 @@ var Polyline = class Polyline extends Path {
10213
10247
  }
10214
10248
  _projectLatlngs(latlngs, result, projectedBounds) {
10215
10249
  if (latlngs[0] instanceof LatLng) {
10216
- const ring = latlngs.map((latlng) => this._map.latLngToLayerPoint(latlng));
10250
+ const ring = latlngs.map((latlng) => this._renderer._latLngToLayerPoint(latlng));
10217
10251
  ring.forEach((r) => projectedBounds.extend(r));
10218
10252
  result.push(ring);
10219
10253
  } else latlngs.forEach((latlng) => this._projectLatlngs(latlng, result, projectedBounds));
@@ -10221,24 +10255,21 @@ var Polyline = class Polyline extends Path {
10221
10255
  _clipPoints() {
10222
10256
  const bounds = this._renderer._bounds;
10223
10257
  this._parts = [];
10224
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
10258
+ if (!this._pxBounds?.intersects(bounds)) return;
10225
10259
  if (this.options.noClip) {
10226
10260
  this._parts = this._rings;
10227
10261
  return;
10228
10262
  }
10229
10263
  const parts = this._parts;
10230
- let i, j, k, len, len2, segment, points;
10231
- for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
10232
- points = this._rings[i];
10233
- for (j = 0, len2 = points.length; j < len2 - 1; j++) {
10234
- segment = clipSegment(points[j], points[j + 1], bounds, j);
10235
- if (!segment) continue;
10236
- parts[k] ??= [];
10237
- parts[k].push(segment[0]);
10238
- if (segment[1] !== points[j + 1] || j === len2 - 2) {
10239
- parts[k].push(segment[1]);
10240
- k++;
10241
- }
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++;
10242
10273
  }
10243
10274
  }
10244
10275
  }
@@ -10255,17 +10286,13 @@ var Polyline = class Polyline extends Path {
10255
10286
  _updatePath() {
10256
10287
  this._renderer._updatePoly(this);
10257
10288
  }
10289
+ _isClosed() {
10290
+ return false;
10291
+ }
10258
10292
  _containsPoint(p, closed) {
10259
- let i, j, k, len, len2, part;
10260
10293
  const w = this._clickTolerance();
10261
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
10262
- for (i = 0, len = this._parts.length; i < len; i++) {
10263
- part = this._parts[i];
10264
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
10265
- if (!closed && j === 0) continue;
10266
- if (pointToSegmentDistance(p, part[k], part[j]) <= w) return true;
10267
- }
10268
- }
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;
10269
10296
  return false;
10270
10297
  }
10271
10298
  /**
@@ -10462,10 +10489,10 @@ var Polygon = class Polygon extends Polyline {
10462
10489
  }
10463
10490
  _clipPoints() {
10464
10491
  let bounds = this._renderer._bounds;
10465
- const w = this.options.weight, p = new Point(w, w);
10492
+ const w = +this.options.weight || 0, p = new Point(w, w);
10466
10493
  bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
10467
10494
  this._parts = [];
10468
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
10495
+ if (!this._pxBounds?.intersects(bounds)) return;
10469
10496
  if (this.options.noClip) {
10470
10497
  this._parts = this._rings;
10471
10498
  return;
@@ -10478,16 +10505,15 @@ var Polygon = class Polygon extends Polyline {
10478
10505
  _updatePath() {
10479
10506
  this._renderer._updatePoly(this, true);
10480
10507
  }
10508
+ _isClosed() {
10509
+ return true;
10510
+ }
10481
10511
  _containsPoint(p) {
10482
- let inside = false, part, p1, p2, i, j, k, len, len2;
10483
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
10484
- for (i = 0, len = this._parts.length; i < len; i++) {
10485
- part = this._parts[i];
10486
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
10487
- p1 = part[j];
10488
- p2 = part[k];
10489
- 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
- }
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;
10491
10517
  }
10492
10518
  return inside || super._containsPoint(p, true);
10493
10519
  }
@@ -10730,16 +10756,15 @@ var ScaleControl = class ScaleControl extends Control {
10730
10756
  onAdd(map) {
10731
10757
  const className = "maplair-control-scale", container = create("div", className), options = this.options;
10732
10758
  this._addScales(options, `${className}-line`, container);
10733
- map.on(options.updateWhenIdle ? "moveend" : "move", this._update, this);
10734
10759
  map.whenReady(this._update, this);
10735
10760
  return container;
10736
10761
  }
10737
10762
  /**
10738
10763
  * @internal
10739
- * @param {MaplairMap} map
10764
+ * @returns {Record<string, Function>}
10740
10765
  */
10741
- onRemove(map) {
10742
- map.off(this.options.updateWhenIdle ? "moveend" : "move", this._update, this);
10766
+ getEvents() {
10767
+ return { [this.options.updateWhenIdle ? "moveend" : "move"]: this._update };
10743
10768
  }
10744
10769
  _addScales(options, className, container) {
10745
10770
  if (options.metric) this._mScale = create("div", className, container);
@@ -10772,7 +10797,7 @@ var ScaleControl = class ScaleControl extends Control {
10772
10797
  }
10773
10798
  _updateScale(scale, text, ratio) {
10774
10799
  scale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;
10775
- scale.innerHTML = text;
10800
+ scale.textContent = text;
10776
10801
  }
10777
10802
  _getRoundNum(num) {
10778
10803
  const pow10 = 10 ** (`${Math.floor(num)}`.length - 1);
@@ -10879,25 +10904,26 @@ var Icon = class Icon extends Class {
10879
10904
  const img = this._createImg(src, oldIcon instanceof HTMLImageElement ? oldIcon : null);
10880
10905
  this._setIconStyles(img, name);
10881
10906
  if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
10907
+ else img.crossOrigin = null;
10882
10908
  return img;
10883
10909
  }
10884
10910
  _setIconStyles(img, name) {
10885
10911
  const options = this.options;
10886
- let sizeOption = options[`${name}Size`];
10887
- if (typeof sizeOption === "number") sizeOption = [sizeOption, sizeOption];
10888
- const size = Point.validate(sizeOption) && Point.from(sizeOption);
10889
- const anchorPosition = name === "shadow" && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
10890
- 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
+ };
10891
10919
  img.className = `maplair-marker-${name} ${options.className || ""}`;
10892
- if (anchor) {
10893
- img.style.marginLeft = `${-anchor.x}px`;
10894
- img.style.marginTop = `${-anchor.y}px`;
10895
- }
10896
- img.style.transformOrigin = anchor ? `${anchor.x}px ${anchor.y}px` : "0 0";
10897
- if (size) {
10898
- img.style.width = `${size.x}px`;
10899
- img.style.height = `${size.y}px`;
10900
- }
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`;
10901
10927
  }
10902
10928
  _createImg(src, el) {
10903
10929
  el ??= document.createElement("img");
@@ -11045,10 +11071,10 @@ var MarkerDrag = class MarkerDrag extends Handler {
11045
11071
  return this._draggable?._moved;
11046
11072
  }
11047
11073
  _adjustPan(e) {
11048
- 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();
11049
- const panBounds = new Bounds(bounds.min._subtract(origin).add(padding), bounds.max._subtract(origin).subtract(padding));
11050
- if (!panBounds.contains(iconPos)) {
11051
- 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;
11052
11078
  map.panBy(movement, { animate: false });
11053
11079
  this._draggable._newPos._add(movement);
11054
11080
  this._draggable._startPos._add(movement);
@@ -11069,7 +11095,8 @@ var MarkerDrag = class MarkerDrag extends Handler {
11069
11095
  }
11070
11096
  }
11071
11097
  _onDrag(e) {
11072
- 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;
11073
11100
  marker._positionElements(iconPos);
11074
11101
  marker._latlng = latlng;
11075
11102
  e.latlng = latlng;
@@ -11078,7 +11105,6 @@ var MarkerDrag = class MarkerDrag extends Handler {
11078
11105
  }
11079
11106
  _onDragEnd(e) {
11080
11107
  cancelAnimationFrame(this._panRequest);
11081
- delete this._oldLatLng;
11082
11108
  this._marker.fire("moveend").fire("dragend", e);
11083
11109
  }
11084
11110
  /** @param {KeyboardEvent|FocusEvent} e */
@@ -11130,7 +11156,8 @@ var MarkerDrag = class MarkerDrag extends Handler {
11130
11156
  * @property {string} [title=''] Text for the browser tooltip that appear on marker hover
11131
11157
  * (no tooltip by default).
11132
11158
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
11133
- * @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.
11134
11161
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
11135
11162
  * @property {number} [zIndexOffset=0] By default, marker images zIndex is set
11136
11163
  * automatically based on its latitude. Use this option if you want to put the marker on
@@ -11142,9 +11169,9 @@ var MarkerDrag = class MarkerDrag extends Handler {
11142
11169
  * marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
11143
11170
  * under a tilted one. `null` means no rotation.
11144
11171
  * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
11145
- * others when you hover the pointer over it.
11146
- * @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`
11147
- * 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.
11148
11175
  * @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.
11149
11176
  * @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will
11150
11177
  * be added.
@@ -11197,7 +11224,7 @@ var Marker = class Marker extends Layer {
11197
11224
  interactive: true,
11198
11225
  keyboard: true,
11199
11226
  title: "",
11200
- alt: "Marker",
11227
+ alt: void 0,
11201
11228
  zIndexOffset: 0,
11202
11229
  opacity: 1,
11203
11230
  rotation: null,
@@ -11341,7 +11368,7 @@ var Marker = class Marker extends Layer {
11341
11368
  if (this._icon) this._removeIcon();
11342
11369
  addIcon = true;
11343
11370
  if (options.title) icon.title = options.title;
11344
- if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? "";
11371
+ if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? I18n.translate("Marker");
11345
11372
  }
11346
11373
  icon.classList.add(classToAdd);
11347
11374
  if (options.keyboard) {
@@ -11350,10 +11377,9 @@ var Marker = class Marker extends Layer {
11350
11377
  on(icon, "keydown", this._onKeyDown, this);
11351
11378
  }
11352
11379
  this._icon = icon;
11353
- if (options.riseOnHover) this.on({
11354
- pointerover: this._bringToFront,
11355
- pointerout: this._resetZIndex
11356
- });
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);
11357
11383
  if (this.options.autoPanOnFocus) on(icon, "focus", this._panOnFocus, this);
11358
11384
  const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
11359
11385
  let addShadow = false;
@@ -11367,15 +11393,13 @@ var Marker = class Marker extends Layer {
11367
11393
  }
11368
11394
  this._shadow = newShadow;
11369
11395
  if (options.opacity < 1) this._updateOpacity();
11370
- if (addIcon) this.getPane().appendChild(this._icon);
11396
+ if (addIcon) this.getPane().append(this._icon);
11371
11397
  this._initInteraction();
11372
- if (newShadow && addShadow) this.getPane(options.shadowPane).appendChild(this._shadow);
11398
+ if (newShadow && addShadow) this.getPane(options.shadowPane).append(this._shadow);
11373
11399
  }
11374
11400
  _removeIcon() {
11375
- if (this.options.riseOnHover) this.off({
11376
- pointerover: this._bringToFront,
11377
- pointerout: this._resetZIndex
11378
- });
11401
+ off(this._icon, "pointerover pointerout focusin focusout", this._updateRise, this);
11402
+ this._hovered = this._focused = false;
11379
11403
  if (this.options.autoPanOnFocus) off(this._icon, "focus", this._panOnFocus, this);
11380
11404
  off(this._icon, "keydown", this._onKeyDown, this);
11381
11405
  this._icon.remove();
@@ -11388,8 +11412,8 @@ var Marker = class Marker extends Layer {
11388
11412
  if (visible === !this._culled) return;
11389
11413
  this._culled = !visible;
11390
11414
  if (visible) {
11391
- this.getPane().appendChild(this._icon);
11392
- 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);
11393
11417
  this.update();
11394
11418
  } else {
11395
11419
  this._icon.remove();
@@ -11403,7 +11427,7 @@ var Marker = class Marker extends Layer {
11403
11427
  _setPos(pos) {
11404
11428
  this._positionElements(pos);
11405
11429
  this._zIndex = pos.y + this.options.zIndexOffset;
11406
- this._resetZIndex();
11430
+ this._updateRise();
11407
11431
  }
11408
11432
  _positionElements(pos) {
11409
11433
  const rotation = this.options.rotation;
@@ -11445,33 +11469,31 @@ var Marker = class Marker extends Layer {
11445
11469
  if (!this.options.interactive) return;
11446
11470
  this._icon.classList.add("maplair-interactive");
11447
11471
  this.addInteractiveTarget(this._icon);
11448
- if (MarkerDrag) {
11449
- if (this.dragging?._draggable?._element === this._icon) {
11450
- this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
11451
- return;
11452
- }
11453
- let draggable = this.options.draggable;
11454
- if (this.dragging) {
11455
- draggable = this.dragging.enabled();
11456
- this.dragging.disable();
11457
- }
11458
- /**
11459
- * Marker dragging handler, see `Handler`. Only valid when the marker is on the
11460
- * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
11461
- *
11462
- * Interaction handlers are properties of a marker instance that allow you to
11463
- * control interaction behavior in runtime, enabling or disabling certain
11464
- * features such as dragging (see `Handler` methods). Example:
11465
- *
11466
- * ```js
11467
- * marker.dragging.disable();
11468
- * ```
11469
- * @group Interaction handlers
11470
- * @type {MarkerDrag}
11471
- */
11472
- this.dragging = new MarkerDrag(this);
11473
- 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;
11474
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();
11475
11497
  }
11476
11498
  /**
11477
11499
  * Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
@@ -11505,9 +11527,13 @@ var Marker = class Marker extends Layer {
11505
11527
  return this;
11506
11528
  }
11507
11529
  _updateOpacity() {
11508
- const opacity = this.options.opacity;
11509
- if (this._icon) this._icon.style.opacity = `${opacity}`;
11510
- 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();
11511
11537
  }
11512
11538
  _bringToFront() {
11513
11539
  this._updateZIndex(this.options.riseOffset);
@@ -12131,8 +12157,9 @@ var SideBySideControl = class SideBySideControl extends Control {
12131
12157
  this.remove();
12132
12158
  this._map = map;
12133
12159
  this._container = this.onAdd(map);
12134
- map._container.appendChild(this._container);
12135
- map.on("unload", this.remove, this);
12160
+ map._container.append(this._container);
12161
+ this._mapEvents = { unload: this.remove };
12162
+ map.on(this._mapEvents, this);
12136
12163
  return this;
12137
12164
  }
12138
12165
  /**
@@ -13667,6 +13694,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
13667
13694
  onAdd() {
13668
13695
  if (!this._image) {
13669
13696
  this._initImage();
13697
+ this._updateZIndex();
13670
13698
  if (this.options.opacity < 1) this._updateOpacity();
13671
13699
  }
13672
13700
  if (this.options.interactive) {
@@ -13674,7 +13702,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
13674
13702
  this.addInteractiveTarget(this._image);
13675
13703
  }
13676
13704
  this._image.classList.toggle("maplair-pixelated", !!this.options.pixelated);
13677
- this.getPane().appendChild(this._image);
13705
+ this.getPane().append(this._image);
13678
13706
  this._reset();
13679
13707
  }
13680
13708
  /**
@@ -13707,7 +13735,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
13707
13735
  * @returns {this}
13708
13736
  */
13709
13737
  setStyle(styleOpts) {
13710
- if (styleOpts.opacity) this.setOpacity(styleOpts.opacity);
13738
+ if (styleOpts.opacity != null) this.setOpacity(styleOpts.opacity);
13711
13739
  return this;
13712
13740
  }
13713
13741
  /**
@@ -13793,7 +13821,6 @@ var ImageOverlay = class ImageOverlay extends Layer {
13793
13821
  img.onerror = this._overlayOnError.bind(this);
13794
13822
  if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
13795
13823
  img.decoding = this.options.decoding;
13796
- if (this.options.zIndex) this._updateZIndex();
13797
13824
  if (wasElementSupplied) {
13798
13825
  this._url = img.src;
13799
13826
  return;
@@ -13815,7 +13842,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
13815
13842
  this._image.style.opacity = `${this.options.opacity}`;
13816
13843
  }
13817
13844
  _updateZIndex() {
13818
- 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}`;
13819
13846
  }
13820
13847
  _overlayOnError() {
13821
13848
  this.fire("error");
@@ -13832,6 +13859,9 @@ var ImageOverlay = class ImageOverlay extends Layer {
13832
13859
  getCenter() {
13833
13860
  return this._bounds.getCenter();
13834
13861
  }
13862
+ _togglesPopupOnClick() {
13863
+ return false;
13864
+ }
13835
13865
  };
13836
13866
  // src/layer/VideoOverlay.js
13837
13867
  /** @import {ImageOverlayOptions} from './ImageOverlay.js' */
@@ -13912,7 +13942,7 @@ var VideoOverlay = class VideoOverlay extends ImageOverlay {
13912
13942
  return;
13913
13943
  }
13914
13944
  if (!Array.isArray(this._url)) this._url = [this._url];
13915
- if (!this.options.keepAspectRatio) vid.style["objectFit"] = "fill";
13945
+ if (!this.options.keepAspectRatio) vid.style.objectFit = "fill";
13916
13946
  vid.autoplay = !!this.options.autoplay;
13917
13947
  vid.controls = !!this.options.controls;
13918
13948
  vid.loop = !!this.options.loop;
@@ -13921,7 +13951,7 @@ var VideoOverlay = class VideoOverlay extends ImageOverlay {
13921
13951
  for (const url of this._url) {
13922
13952
  const source = create("source");
13923
13953
  source.src = url;
13924
- vid.appendChild(source);
13954
+ vid.append(source);
13925
13955
  }
13926
13956
  }
13927
13957
  };
@@ -14024,14 +14054,10 @@ var DivIcon = class DivIcon extends Icon {
14024
14054
  */
14025
14055
  createIcon(oldIcon) {
14026
14056
  const div = oldIcon instanceof HTMLDivElement ? oldIcon : document.createElement("div"), options = this.options;
14027
- if (options.html instanceof Element) {
14028
- div.replaceChildren();
14029
- div.appendChild(options.html);
14030
- } else div.innerHTML = options.html !== false ? options.html : "";
14031
- if (options.bgPos) {
14032
- const bgPos = Point.from(options.bgPos);
14033
- div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
14034
- }
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` : "";
14035
14061
  this._setIconStyles(div, "icon");
14036
14062
  return div;
14037
14063
  }
@@ -14056,7 +14082,7 @@ const glyphSize = 230;
14056
14082
  function svgElement(name, attributes, parent) {
14057
14083
  const el = document.createElementNS(svgNS, name);
14058
14084
  for (const [key, value] of Object.entries(attributes)) el.setAttribute(key, value);
14059
- parent?.appendChild(el);
14085
+ parent?.append(el);
14060
14086
  return el;
14061
14087
  }
14062
14088
  /**
@@ -14501,10 +14527,10 @@ var MarkerClusterGroup = class MarkerClusterGroup extends FeatureGroup {
14501
14527
  * @typedef {(error: any, tile: HTMLElement) => void} TileDoneCallback
14502
14528
  */
14503
14529
  /**
14504
- * Generic class for handling a tiled grid of HTML elements. This is the base class for
14505
- * all tile layers and replaces `TileLayer.Canvas`. GridLayer can be extended to create
14506
- * a tiled grid of HTML elements like `<canvas>`, `<img>` or `<div>`. GridLayer will
14507
- * 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.
14508
14534
  *
14509
14535
  * Layers extending `GridLayer` shall reimplement the [`createTile()`](#gridlayer-createtile)
14510
14536
  * method.
@@ -14700,7 +14726,7 @@ var GridLayer = class GridLayer extends Layer {
14700
14726
  redraw() {
14701
14727
  if (this._map) {
14702
14728
  this._removeAllTiles();
14703
- const tileZoom = this._clampZoom(Math.round(this._map.getZoom()));
14729
+ const tileZoom = this._getTileZoom(this._map.getZoom());
14704
14730
  if (tileZoom !== this._tileZoom) {
14705
14731
  this._tileZoom = tileZoom;
14706
14732
  this._updateLevels();
@@ -14751,7 +14777,7 @@ var GridLayer = class GridLayer extends Layer {
14751
14777
  return s instanceof Point ? s : new Point(s, s);
14752
14778
  }
14753
14779
  _updateZIndex() {
14754
- 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}`;
14755
14781
  }
14756
14782
  _setAutoZIndex(compare) {
14757
14783
  const layers = this.getPane().children;
@@ -14776,7 +14802,7 @@ var GridLayer = class GridLayer extends Layer {
14776
14802
  this._container.classList.toggle("maplair-pixelated", !!this.options.pixelated);
14777
14803
  this._updateZIndex();
14778
14804
  if (this.options.opacity < 1) this._updateOpacity();
14779
- this.getPane().appendChild(this._container);
14805
+ this.getPane().append(this._container);
14780
14806
  }
14781
14807
  _keepCurrentTiles() {
14782
14808
  const zoom = this._tileZoom, level = this._levels?.[zoom];
@@ -14850,8 +14876,7 @@ var GridLayer = class GridLayer extends Layer {
14850
14876
  _onCreateLevel() {}
14851
14877
  _pruneTiles() {
14852
14878
  if (!this._map) return;
14853
- const zoom = this._map.getZoom();
14854
- if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
14879
+ if (this._getTileZoom(this._map.getZoom()) === void 0) {
14855
14880
  this._removeAllTiles();
14856
14881
  return;
14857
14882
  }
@@ -14906,6 +14931,11 @@ var GridLayer = class GridLayer extends Layer {
14906
14931
  _animateZoom(e) {
14907
14932
  this._setView(e.center, e.zoom, true, e.noUpdate);
14908
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
+ }
14909
14939
  _clampZoom(zoom) {
14910
14940
  const options = this.options;
14911
14941
  if (void 0 !== options.minNativeZoom && zoom < options.minNativeZoom) return options.minNativeZoom;
@@ -14913,13 +14943,11 @@ var GridLayer = class GridLayer extends Layer {
14913
14943
  return zoom;
14914
14944
  }
14915
14945
  _setView(center, zoom, noPrune, noUpdate) {
14916
- let tileZoom = Math.round(zoom);
14917
- if (this.options.maxZoom !== void 0 && tileZoom > this.options.maxZoom || this.options.minZoom !== void 0 && tileZoom < this.options.minZoom) tileZoom = void 0;
14918
- else tileZoom = this._clampZoom(tileZoom);
14946
+ const tileZoom = this._getTileZoom(zoom);
14919
14947
  const tileZoomChanged = this.options.updateWhenZooming && tileZoom !== this._tileZoom;
14920
14948
  if (!noUpdate || tileZoomChanged) {
14921
14949
  this._tileZoom = tileZoom;
14922
- if (this._abortLoading) this._abortLoading();
14950
+ this._abortLoading?.();
14923
14951
  this._updateLevels();
14924
14952
  this._resetGrid();
14925
14953
  if (tileZoom !== void 0) this._update(center);
@@ -14988,7 +15016,7 @@ var GridLayer = class GridLayer extends Layer {
14988
15016
  else queue.push(coords);
14989
15017
  }
14990
15018
  queue.sort((a, b) => a.distanceTo(tileCenter) - b.distanceTo(tileCenter));
14991
- if (queue.length !== 0) {
15019
+ if (queue.length) {
14992
15020
  if (!this._loading) {
14993
15021
  this._loading = true;
14994
15022
  this.fire("loading");
@@ -14996,7 +15024,7 @@ var GridLayer = class GridLayer extends Layer {
14996
15024
  }
14997
15025
  const fragment = document.createDocumentFragment();
14998
15026
  for (const q of queue) this._addTile(q, fragment);
14999
- this._level.el.appendChild(fragment);
15027
+ this._level.el.append(fragment);
15000
15028
  }
15001
15029
  }
15002
15030
  _isValidTile(coords) {
@@ -15050,7 +15078,7 @@ var GridLayer = class GridLayer extends Layer {
15050
15078
  coords,
15051
15079
  current: true
15052
15080
  };
15053
- container.appendChild(tile);
15081
+ container.append(tile);
15054
15082
  this.fire("tileloadstart", {
15055
15083
  tile,
15056
15084
  coords
@@ -15255,13 +15283,13 @@ var TileLayer = class TileLayer extends GridLayer {
15255
15283
  if (!this.options.zoomReverse) {
15256
15284
  this.options.zoomOffset++;
15257
15285
  this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);
15258
- if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
15259
- if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
15260
15286
  } else {
15261
15287
  this.options.zoomOffset--;
15262
15288
  this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);
15263
15289
  }
15264
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);
15265
15293
  } else if (!this.options.zoomReverse) this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);
15266
15294
  else this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);
15267
15295
  }
@@ -15357,16 +15385,17 @@ var TileLayer = class TileLayer extends GridLayer {
15357
15385
  * @returns {string}
15358
15386
  */
15359
15387
  getTileUrl(coords) {
15360
- const data = Object.create(this.options);
15388
+ const z = coords.z ?? this._tileZoom, data = Object.create(this.options);
15361
15389
  Object.assign(data, {
15362
15390
  r: window.devicePixelRatio > 1 ? "@2x" : "",
15363
15391
  s: this._getSubdomain(coords),
15364
15392
  x: coords.x,
15365
15393
  y: coords.y,
15366
- z: this._getZoomForUrl()
15394
+ z: this._getZoomForUrl(z)
15367
15395
  });
15368
- if (this._map && !this._map.options.crs.infinite) {
15369
- 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;
15370
15399
  if (this.options.tms) data["y"] = invertedY;
15371
15400
  data["-y"] = invertedY;
15372
15401
  }
@@ -15381,8 +15410,7 @@ var TileLayer = class TileLayer extends GridLayer {
15381
15410
  if (errorUrl && src !== errorUrl && (src || tile.isConnected)) tile.src = errorUrl;
15382
15411
  done(e, tile);
15383
15412
  }
15384
- _getZoomForUrl() {
15385
- let zoom = this._tileZoom;
15413
+ _getZoomForUrl(zoom) {
15386
15414
  const maxZoom = this.options.maxZoom, zoomReverse = this.options.zoomReverse, zoomOffset = this.options.zoomOffset;
15387
15415
  if (zoomReverse) zoom = maxZoom - zoom;
15388
15416
  return zoom + zoomOffset;
@@ -15415,7 +15443,7 @@ var TileLayer = class TileLayer extends GridLayer {
15415
15443
  return super._removeTile(key);
15416
15444
  }
15417
15445
  _tileReady(coords, err, tile) {
15418
- if (!this._map || tile && tile.getAttribute("src") === "") return;
15446
+ if (!this._map || tile?.getAttribute("src") === "") return;
15419
15447
  return super._tileReady(coords, err, tile);
15420
15448
  }
15421
15449
  _clampZoom(zoom) {
@@ -15669,22 +15697,21 @@ var Canvas = class Canvas extends Renderer {
15669
15697
  */
15670
15698
  onAdd(map) {
15671
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);
15672
15703
  this._draw();
15673
15704
  }
15705
+ _initContainer() {
15706
+ const container = this._container = document.createElement("canvas");
15707
+ this._ctx = container.getContext("2d");
15708
+ }
15674
15709
  /**
15675
15710
  * Removes the canvas from the map.
15676
15711
  */
15677
15712
  onRemove() {
15713
+ this._map._canvases = this._map._canvases.filter((r) => r !== this);
15678
15714
  super.onRemove();
15679
- clearTimeout(this._pointerHoverThrottleTimeout);
15680
- }
15681
- _initContainer() {
15682
- const container = this._container = document.createElement("canvas");
15683
- on(container, "pointermove", this._onPointerMove, this);
15684
- on(container, "click dblclick pointerdown pointerup contextmenu", this._onClick, this);
15685
- on(container, "pointerout", this._handlePointerOut, this);
15686
- container["_maplair_disable_events"] = true;
15687
- this._ctx = container.getContext("2d");
15688
15715
  }
15689
15716
  _destroyContainer() {
15690
15717
  cancelAnimationFrame(this._redrawRequest);
@@ -15720,26 +15747,13 @@ var Canvas = class Canvas extends Renderer {
15720
15747
  _initPath(layer) {
15721
15748
  this._updateDashArray(layer);
15722
15749
  this._layers[stamp(layer)] = layer;
15723
- const order = layer._order = {
15724
- layer,
15725
- prev: this._drawLast,
15726
- next: null
15727
- };
15728
- if (this._drawLast) this._drawLast.next = order;
15729
- this._drawLast = order;
15730
- this._drawFirst ??= this._drawLast;
15750
+ this._append(layer._order = { layer });
15731
15751
  }
15732
15752
  _addPath(layer) {
15733
15753
  this._requestRedraw(layer);
15734
15754
  }
15735
15755
  _removePath(layer) {
15736
- const order = layer._order;
15737
- const next = order.next;
15738
- const prev = order.prev;
15739
- if (next) next.prev = prev;
15740
- else this._drawLast = prev;
15741
- if (prev) prev.next = next;
15742
- else this._drawFirst = next;
15756
+ this._unlink(layer._order);
15743
15757
  delete layer._order;
15744
15758
  delete this._layers[stamp(layer)];
15745
15759
  this._requestRedraw(layer);
@@ -15765,7 +15779,7 @@ var Canvas = class Canvas extends Renderer {
15765
15779
  }
15766
15780
  _extendRedrawBounds(layer) {
15767
15781
  if (layer._pxBounds) {
15768
- const padding = (layer.options.weight ?? 0) + 1;
15782
+ const padding = (+layer.options.weight || 0) + 1;
15769
15783
  this._redrawBounds ??= new Bounds();
15770
15784
  this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
15771
15785
  this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
@@ -15807,7 +15821,7 @@ var Canvas = class Canvas extends Renderer {
15807
15821
  this._drawing = true;
15808
15822
  for (let order = this._drawFirst; order; order = order.next) {
15809
15823
  layer = order.layer;
15810
- if (!bounds || layer._pxBounds && layer._pxBounds.intersects(bounds)) layer._updatePath();
15824
+ if (!bounds || layer._pxBounds?.intersects(bounds)) layer._updatePath();
15811
15825
  }
15812
15826
  this._drawing = false;
15813
15827
  this._ctx.restore();
@@ -15852,84 +15866,50 @@ var Canvas = class Canvas extends Renderer {
15852
15866
  }
15853
15867
  }
15854
15868
  _updateInteractive() {}
15855
- _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) {
15856
15876
  const point = this._map.pointerEventToLayerPoint(e);
15857
- let layer, clickedLayer;
15858
- for (let order = this._drawFirst; order; order = order.next) {
15859
- layer = order.layer;
15860
- if (layer.options.interactive && layer._containsPoint(point)) {
15861
- if (!(e.type === "click" || e.type === "preclick") || !this._map._draggableMoved(layer)) clickedLayer = layer;
15862
- }
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;
15863
15880
  }
15864
- this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
15865
15881
  }
15866
- _onPointerMove(e) {
15867
- if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) return;
15868
- const point = this._map.pointerEventToLayerPoint(e);
15869
- this._handlePointerHover(e, point);
15870
- }
15871
- _handlePointerOut(e) {
15872
- const layer = this._hoveredLayer;
15873
- if (layer) {
15874
- this._container.classList.remove("maplair-interactive");
15875
- this._fireEvent([layer], e, "pointerout");
15876
- this._hoveredLayer = null;
15877
- 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);
15878
15888
  }
15879
15889
  }
15880
- _handlePointerHover(e, point) {
15881
- if (this._pointerHoverThrottled) return;
15882
- let layer, candidateHoveredLayer;
15883
- for (let order = this._drawFirst; order; order = order.next) {
15884
- layer = order.layer;
15885
- if (layer.options.interactive && layer._containsPoint(point)) candidateHoveredLayer = layer;
15886
- }
15887
- if (candidateHoveredLayer !== this._hoveredLayer) {
15888
- this._handlePointerOut(e);
15889
- if (candidateHoveredLayer) {
15890
- this._container.classList.add("maplair-interactive");
15891
- this._fireEvent([candidateHoveredLayer], e, "pointerover");
15892
- this._hoveredLayer = candidateHoveredLayer;
15893
- }
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);
15894
15899
  }
15895
- this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
15896
- this._pointerHoverThrottled = true;
15897
- this._pointerHoverThrottleTimeout = setTimeout((() => {
15898
- this._pointerHoverThrottled = false;
15899
- }), 32);
15900
- }
15901
- _fireEvent(layers, e, type) {
15902
- this._map._fireDOMEvent(e, type || e.type, layers);
15903
15900
  }
15904
- _bringToFront(layer) {
15905
- const order = layer._order;
15906
- if (!order) return;
15907
- const next = order.next;
15908
- const prev = order.prev;
15909
- if (next) next.prev = prev;
15910
- else return;
15911
- if (prev) prev.next = next;
15912
- else if (next) this._drawFirst = next;
15901
+ _append(order) {
15913
15902
  order.prev = this._drawLast;
15914
- this._drawLast.next = order;
15915
15903
  order.next = null;
15904
+ if (this._drawLast) this._drawLast.next = order;
15916
15905
  this._drawLast = order;
15917
- this._requestRedraw(layer);
15906
+ this._drawFirst ??= order;
15918
15907
  }
15919
- _bringToBack(layer) {
15920
- const order = layer._order;
15921
- if (!order) return;
15922
- const next = order.next;
15923
- const prev = order.prev;
15924
- if (prev) prev.next = next;
15925
- else return;
15908
+ _unlink({ prev, next }) {
15926
15909
  if (next) next.prev = prev;
15927
- else if (prev) this._drawLast = prev;
15928
- order.prev = null;
15929
- order.next = this._drawFirst;
15930
- this._drawFirst.prev = order;
15931
- this._drawFirst = order;
15932
- this._requestRedraw(layer);
15910
+ else this._drawLast = prev;
15911
+ if (prev) prev.next = next;
15912
+ else this._drawFirst = next;
15933
15913
  }
15934
15914
  };
15935
15915
  // src/layer/vector/Circle.js
@@ -15977,18 +15957,18 @@ var Circle = class Circle extends CircleMarker {
15977
15957
  return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half)));
15978
15958
  }
15979
15959
  _project() {
15980
- 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;
15981
15961
  if (crs.distance === EarthCRS.distance) {
15982
- 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;
15983
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;
15984
- if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(Math.PI / 180 * lat);
15985
- this._point = p.subtract(map.getPixelOrigin());
15986
- 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;
15987
15967
  this._pxRadiusY = p.y - top.y;
15988
15968
  } else {
15989
15969
  const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
15990
- this._point = map.latLngToLayerPoint(this._latlng);
15991
- 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);
15992
15972
  }
15993
15973
  this._updateBounds();
15994
15974
  }
@@ -16419,10 +16399,7 @@ var MapSync = class {
16419
16399
  other._rawPanBy(offset);
16420
16400
  other.fire("move");
16421
16401
  }
16422
- } else other._move(center, zoom, during ? {
16423
- pinch: true,
16424
- round: false
16425
- } : void 0);
16402
+ } else other._move(center, zoom, during ? { pinch: true } : void 0);
16426
16403
  }
16427
16404
  _syncAll(map) {
16428
16405
  for (const other of this._maps.filter((m) => m !== map)) {
@@ -16554,6 +16531,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16554
16531
  * Called when the handler is enabled, adds the event hooks.
16555
16532
  */
16556
16533
  addHooks() {
16534
+ this._map._displaceHandler = this;
16557
16535
  this._map.on("zoomend", this.schedule, this);
16558
16536
  this._map.on("layeradd", this._onLayerAdd, this);
16559
16537
  this._map.on("layerremove", this._onLayerRemove, this);
@@ -16565,6 +16543,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16565
16543
  * true positions of the markers.
16566
16544
  */
16567
16545
  removeHooks() {
16546
+ if (this._map._displaceHandler === this) delete this._map._displaceHandler;
16568
16547
  this._map.off("zoomend", this.schedule, this);
16569
16548
  this._map.off("layeradd", this._onLayerAdd, this);
16570
16549
  this._map.off("layerremove", this._onLayerRemove, this);
@@ -16636,6 +16615,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16636
16615
  * @param {LatLng} latLng
16637
16616
  */
16638
16617
  _moveTo(marker, latLng) {
16618
+ if (marker.getLatLng().equals(latLng)) return;
16639
16619
  this._moving = true;
16640
16620
  try {
16641
16621
  marker.setLatLng(latLng);
@@ -16655,6 +16635,19 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16655
16635
  if (this._enabled && this._map.hasLayer(event.target)) this.schedule();
16656
16636
  }
16657
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
+ /**
16658
16651
  * @param {LayerEvent} event
16659
16652
  */
16660
16653
  _onLayerAdd(event) {
@@ -16691,6 +16684,10 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16691
16684
  }
16692
16685
  };
16693
16686
  /**
16687
+ * Movement in pixels per pass below which `displace` stops early
16688
+ */
16689
+ const MIN_MOVE = .01;
16690
+ /**
16694
16691
  * Displaces overlapping points in pixel space until they are at least
16695
16692
  * `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed
16696
16693
  * apart by half of its overlap per pass. Neighbour lookup uses a grid (cell
@@ -16698,7 +16695,8 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
16698
16695
  *
16699
16696
  * No point ends up further than `maxDisplacement` away from where it started.
16700
16697
  * Points which hit that limit stay overlapping – the limit wins over the
16701
- * 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.
16702
16700
  *
16703
16701
  * @param {Point[]} points Pixel coordinates (modified in place)
16704
16702
  * @param {number} minSeparation Minimum distance between centers, in pixels
@@ -16718,49 +16716,62 @@ function displace(points, minSeparation, { iterations = DisplaceHandler.defaultO
16718
16716
  for (let iter = 0; iter < iterations; iter++) {
16719
16717
  dx.fill(0);
16720
16718
  dy.fill(0);
16721
- /** @type {Map<string, number[]>} */
16719
+ /** @type {Map<number, Map<number, number[]>>} */
16722
16720
  const grid = /* @__PURE__ */ new Map();
16723
16721
  for (let i = 0; i < n; i++) {
16724
- const key = `${Math.floor(points[i].x / cell)},${Math.floor(points[i].y / cell)}`;
16725
- 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);
16726
16730
  if (bucket) bucket.push(i);
16727
- else grid.set(key, [i]);
16731
+ else column.set(cy, [i]);
16728
16732
  }
16729
16733
  let overlaps = 0;
16730
16734
  for (let i = 0; i < n; i++) {
16731
16735
  const cx = Math.floor(points[i].x / cell);
16732
16736
  const cy = Math.floor(points[i].y / cell);
16733
- for (let gx = cx - 1; gx <= cx + 1; gx++) for (let gy = cy - 1; gy <= cy + 1; gy++) {
16734
- const bucket = grid.get(`${gx},${gy}`);
16735
- if (!bucket) continue;
16736
- for (const j of bucket) {
16737
- if (j <= i) continue;
16738
- let vx = points[i].x - points[j].x;
16739
- let vy = points[i].y - points[j].y;
16740
- const distSq = vx * vx + vy * vy;
16741
- if (distSq >= sepSq) continue;
16742
- overlaps++;
16743
- let dist;
16744
- if (distSq === 0) {
16745
- const angle = i * 2.399963229728653;
16746
- vx = Math.cos(angle);
16747
- vy = Math.sin(angle);
16748
- dist = 1;
16749
- } else {
16750
- dist = Math.sqrt(distSq);
16751
- vx /= dist;
16752
- 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;
16753
16766
  }
16754
- const push = (sep - dist) / 2;
16755
- dx[i] += vx * push;
16756
- dy[i] += vy * push;
16757
- dx[j] -= vx * push;
16758
- dy[j] -= vy * push;
16759
16767
  }
16760
16768
  }
16761
16769
  }
16762
16770
  if (overlaps === 0) break;
16771
+ let maxMoveSq = 0;
16763
16772
  for (let i = 0; i < n; i++) {
16773
+ const x = points[i].x;
16774
+ const y = points[i].y;
16764
16775
  points[i].x += dx[i];
16765
16776
  points[i].y += dy[i];
16766
16777
  const ox = points[i].x - ax[i];
@@ -16771,7 +16782,11 @@ function displace(points, minSeparation, { iterations = DisplaceHandler.defaultO
16771
16782
  points[i].x = ax[i] + ox * scale;
16772
16783
  points[i].y = ay[i] + oy * scale;
16773
16784
  }
16785
+ const mx = points[i].x - x;
16786
+ const my = points[i].y - y;
16787
+ maxMoveSq = Math.max(maxMoveSq, mx * mx + my * my);
16774
16788
  }
16789
+ if (maxMoveSq < MIN_MOVE * MIN_MOVE) break;
16775
16790
  }
16776
16791
  return points;
16777
16792
  }
@@ -16841,7 +16856,6 @@ var RotateControl = class RotateControl extends Control {
16841
16856
  disableClickPropagation(button);
16842
16857
  on(button, "click", stop);
16843
16858
  on(button, "click", this._resetNorth, this);
16844
- on(button, "click", this._refocusOnMap, this);
16845
16859
  this._update();
16846
16860
  map.on("rotate", this._update, this);
16847
16861
  return container;
@@ -16945,8 +16959,8 @@ MaplairMap.include({
16945
16959
  if (!this._rotatePane) {
16946
16960
  const rotatePane = this._rotatePane = create("div", "maplair-rotate-pane");
16947
16961
  rotatedMaps.set(rotatePane, this);
16948
- this._container.insertBefore(rotatePane, this._mapPane);
16949
- rotatePane.appendChild(this._mapPane);
16962
+ this._mapPane.before(rotatePane);
16963
+ rotatePane.append(this._mapPane);
16950
16964
  }
16951
16965
  if (bearing === this.getBearing()) return;
16952
16966
  this._bearing = bearing;
@@ -17035,9 +17049,9 @@ MaplairMap.include({
17035
17049
  return panBy.call(this, this._rotateToPane(Point.from(offset)), options);
17036
17050
  },
17037
17051
  _tryAnimatedPan(center, options) {
17038
- const offset = this._rotateToContainer(this._getCenterOffset(center)._trunc());
17039
- if (options?.animate !== true && !this.getSize().contains(offset)) return false;
17040
- 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);
17041
17055
  return true;
17042
17056
  },
17043
17057
  /**
@@ -17329,10 +17343,7 @@ PinchZoomHandler.include({
17329
17343
  this._moved = true;
17330
17344
  }
17331
17345
  cancelAnimationFrame(this._animRequest);
17332
- const moveFn = map._move.bind(map, this._center, this._zoom, {
17333
- pinch: true,
17334
- round: false
17335
- }, void 0);
17346
+ const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
17336
17347
  this._animRequest = requestAnimationFrame(moveFn.bind(this));
17337
17348
  e.preventDefault();
17338
17349
  }