maplair 4.2.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/CHANGELOG.md +106 -8
  2. package/dist/esm/control/AttributionControl.js +10 -10
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/ButtonControl.js +0 -1
  5. package/dist/esm/control/ButtonControl.js.map +1 -1
  6. package/dist/esm/control/ContextMenu.js +1 -1
  7. package/dist/esm/control/ContextMenu.js.map +1 -1
  8. package/dist/esm/control/Control.js +16 -11
  9. package/dist/esm/control/Control.js.map +1 -1
  10. package/dist/esm/control/FullscreenControl.js +0 -1
  11. package/dist/esm/control/FullscreenControl.js.map +1 -1
  12. package/dist/esm/control/LayersControl.js +13 -9
  13. package/dist/esm/control/LayersControl.js.map +1 -1
  14. package/dist/esm/control/RotateControl.js +0 -1
  15. package/dist/esm/control/RotateControl.js.map +1 -1
  16. package/dist/esm/control/ScaleControl.js +4 -5
  17. package/dist/esm/control/ScaleControl.js.map +1 -1
  18. package/dist/esm/control/SideBySideControl.js +3 -2
  19. package/dist/esm/control/SideBySideControl.js.map +1 -1
  20. package/dist/esm/control/ZoomControl.js +13 -13
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Events.js +4 -2
  23. package/dist/esm/core/Events.js.map +1 -1
  24. package/dist/esm/core/Util.js +16 -4
  25. package/dist/esm/core/Util.js.map +1 -1
  26. package/dist/esm/dom/DomEvent.PointerEvents.js +55 -2
  27. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  28. package/dist/esm/dom/DomEvent.js +4 -7
  29. package/dist/esm/dom/DomEvent.js.map +1 -1
  30. package/dist/esm/dom/DomUtil.js +5 -5
  31. package/dist/esm/dom/DomUtil.js.map +1 -1
  32. package/dist/esm/dom/Draggable.js +4 -6
  33. package/dist/esm/dom/Draggable.js.map +1 -1
  34. package/dist/esm/geo/LatLng.js +23 -34
  35. package/dist/esm/geo/LatLng.js.map +1 -1
  36. package/dist/esm/geo/LatLngBounds.js +6 -3
  37. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  38. package/dist/esm/geometry/Bounds.js +2 -2
  39. package/dist/esm/geometry/Bounds.js.map +1 -1
  40. package/dist/esm/geometry/Point.js +12 -17
  41. package/dist/esm/geometry/Point.js.map +1 -1
  42. package/dist/esm/geometry/Transformation.js +1 -7
  43. package/dist/esm/geometry/Transformation.js.map +1 -1
  44. package/dist/esm/layer/BlanketOverlay.js +1 -1
  45. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  46. package/dist/esm/layer/DivOverlay.js +23 -23
  47. package/dist/esm/layer/DivOverlay.js.map +1 -1
  48. package/dist/esm/layer/ImageOverlay.js +7 -4
  49. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  50. package/dist/esm/layer/Layer.js +11 -6
  51. package/dist/esm/layer/Layer.js.map +1 -1
  52. package/dist/esm/layer/Popup.js +30 -11
  53. package/dist/esm/layer/Popup.js.map +1 -1
  54. package/dist/esm/layer/Tooltip.js +18 -35
  55. package/dist/esm/layer/Tooltip.js.map +1 -1
  56. package/dist/esm/layer/VideoOverlay.js +2 -2
  57. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  58. package/dist/esm/layer/marker/DivIcon.js +4 -8
  59. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  60. package/dist/esm/layer/marker/Icon.js +16 -15
  61. package/dist/esm/layer/marker/Icon.js.map +1 -1
  62. package/dist/esm/layer/marker/Marker.Drag.js +6 -7
  63. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  64. package/dist/esm/layer/marker/Marker.js +49 -48
  65. package/dist/esm/layer/marker/Marker.js.map +1 -1
  66. package/dist/esm/layer/marker/SvgIcon.js +1 -1
  67. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  68. package/dist/esm/layer/tile/GridLayer.js +18 -16
  69. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  70. package/dist/esm/layer/tile/TileLayer.js +9 -9
  71. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  72. package/dist/esm/layer/vector/Canvas.js +44 -93
  73. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  74. package/dist/esm/layer/vector/Circle.js +8 -7
  75. package/dist/esm/layer/vector/Circle.js.map +1 -1
  76. package/dist/esm/layer/vector/CircleMarker.js +9 -1
  77. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  78. package/dist/esm/layer/vector/Path.js +10 -5
  79. package/dist/esm/layer/vector/Path.js.map +1 -1
  80. package/dist/esm/layer/vector/Polygon.js +10 -11
  81. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  82. package/dist/esm/layer/vector/Polyline.js +19 -26
  83. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  84. package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
  85. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  86. package/dist/esm/layer/vector/Renderer.js +16 -0
  87. package/dist/esm/layer/vector/Renderer.js.map +1 -1
  88. package/dist/esm/layer/vector/SVG.js +3 -3
  89. package/dist/esm/layer/vector/SVG.js.map +1 -1
  90. package/dist/esm/map/Map.Rotation.js +6 -9
  91. package/dist/esm/map/Map.Rotation.js.map +1 -1
  92. package/dist/esm/map/Map.js +104 -49
  93. package/dist/esm/map/Map.js.map +1 -1
  94. package/dist/esm/map/MapSync.js +1 -4
  95. package/dist/esm/map/MapSync.js.map +1 -1
  96. package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
  97. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  98. package/dist/esm/map/handler/DisplaceHandler.js +68 -30
  99. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  100. package/dist/esm/map/handler/KeyboardHandler.js +3 -5
  101. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  102. package/dist/esm/map/handler/PinchZoomHandler.js +3 -6
  103. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  104. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -6
  105. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  106. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -4
  107. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  108. package/dist/esm/map/handler/TapHoldHandler.js +8 -20
  109. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  110. package/dist/esm/package.js +1 -1
  111. package/dist/maplair-global-src.js +700 -687
  112. package/dist/maplair-global-src.js.map +1 -1
  113. package/dist/maplair-global.js +2 -2
  114. package/dist/maplair-global.js.map +1 -1
  115. package/dist/maplair-src.js +700 -687
  116. package/dist/maplair-src.js.map +1 -1
  117. package/dist/maplair.css +1 -1
  118. package/dist/maplair.js +2 -2
  119. package/dist/maplair.js.map +1 -1
  120. package/i18n/en.json +1 -0
  121. package/package.json +2 -1
  122. package/src/control/AttributionControl.js +9 -9
  123. package/src/control/ButtonControl.js +0 -1
  124. package/src/control/ContextMenu.js +1 -1
  125. package/src/control/Control.js +13 -16
  126. package/src/control/FullscreenControl.js +0 -1
  127. package/src/control/LayersControl.js +14 -10
  128. package/src/control/RotateControl.js +0 -1
  129. package/src/control/ScaleControl.js +4 -5
  130. package/src/control/SideBySideControl.js +4 -2
  131. package/src/control/ZoomControl.js +10 -13
  132. package/src/core/Events.js +8 -2
  133. package/src/core/Util.js +16 -3
  134. package/src/dom/DomEvent.PointerEvents.js +47 -1
  135. package/src/dom/DomEvent.js +5 -17
  136. package/src/dom/DomUtil.js +5 -5
  137. package/src/dom/Draggable.js +5 -6
  138. package/src/geo/LatLng.js +22 -36
  139. package/src/geo/LatLngBounds.js +10 -4
  140. package/src/geometry/Bounds.js +3 -3
  141. package/src/geometry/Point.js +18 -26
  142. package/src/geometry/Transformation.js +1 -8
  143. package/src/layer/BlanketOverlay.js +1 -1
  144. package/src/layer/DivOverlay.js +28 -30
  145. package/src/layer/ImageOverlay.js +9 -7
  146. package/src/layer/Layer.js +18 -6
  147. package/src/layer/Popup.js +38 -17
  148. package/src/layer/Tooltip.js +17 -44
  149. package/src/layer/VideoOverlay.js +2 -2
  150. package/src/layer/marker/DivIcon.js +3 -6
  151. package/src/layer/marker/Icon.js +19 -18
  152. package/src/layer/marker/Marker.Drag.js +16 -18
  153. package/src/layer/marker/Marker.js +66 -59
  154. package/src/layer/marker/SvgIcon.js +1 -1
  155. package/src/layer/tile/GridLayer.js +21 -23
  156. package/src/layer/tile/TileLayer.js +17 -14
  157. package/src/layer/vector/Canvas.js +52 -148
  158. package/src/layer/vector/Circle.js +14 -9
  159. package/src/layer/vector/CircleMarker.js +11 -1
  160. package/src/layer/vector/Path.js +11 -5
  161. package/src/layer/vector/Polygon.js +11 -10
  162. package/src/layer/vector/Polyline.js +20 -21
  163. package/src/layer/vector/Renderer.getRenderer.js +2 -1
  164. package/src/layer/vector/Renderer.js +21 -3
  165. package/src/layer/vector/SVG.js +3 -3
  166. package/src/map/Map.Rotation.js +7 -6
  167. package/src/map/Map.js +135 -54
  168. package/src/map/MapSync.js +1 -1
  169. package/src/map/handler/BoxZoomHandler.js +2 -0
  170. package/src/map/handler/DisplaceHandler.js +53 -7
  171. package/src/map/handler/KeyboardHandler.js +5 -10
  172. package/src/map/handler/PinchZoomHandler.js +3 -3
  173. package/src/map/handler/ScrollWheelZoomHandler.js +3 -3
  174. package/src/map/handler/TapDragZoomHandler.js +1 -1
  175. package/src/map/handler/TapHoldHandler.js +13 -25
  176. package/src/maplair.css +38 -9
  177. package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
  178. package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
  179. package/src/dom/DomEvent.DoubleTap.js +0 -143
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * Maplair 4.2.0, a JS library for interactive maps. https://maplair.org
2
+ * Maplair 4.4.0, a JS library for interactive maps. https://maplair.org
3
3
  * (c) 2026 Simon Legner and Maplair contributors, (c) 2010-2026 Volodymyr Agafonkin, (c) 2010-2011 CloudMade
4
4
  */
5
5
  (function (previousL) {
@@ -18,7 +18,7 @@
18
18
  return target;
19
19
  };
20
20
  // package.json
21
- var version$1 = "4.2.0";
21
+ var version$1 = "4.4.0";
22
22
  // src/core/Util.js
23
23
  var Util_exports = /* @__PURE__ */ __exportAll({
24
24
  falseFn: () => falseFn,
@@ -29,6 +29,7 @@
29
29
  stamp: () => stamp,
30
30
  template: () => template,
31
31
  throttle: () => throttle,
32
+ toNumber: () => toNumber,
32
33
  wrapNum: () => wrapNum
33
34
  });
34
35
  /**
@@ -103,11 +104,21 @@
103
104
  * @param {number|false} [precision]
104
105
  * @returns {number}
105
106
  */
106
- function formatNum(num, precision) {
107
+ function formatNum(num, precision = 6) {
107
108
  if (precision === false) return num;
108
- const pow = 10 ** (precision === void 0 ? 6 : precision);
109
+ const pow = 10 ** precision;
109
110
  return Math.round(num * pow) / pow;
110
111
  }
112
+ /**
113
+ * Returns `value` if it's a number (including `Infinity`), converts it if it's a
114
+ * numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns
115
+ * `''`, `null` and booleans into `0` or `1`.
116
+ * @param {unknown} value
117
+ * @returns {number}
118
+ */
119
+ function toNumber(value) {
120
+ return typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? +value : NaN;
121
+ }
111
122
  const WHITESPACE_RE = /\s+/;
112
123
  /**
113
124
  * Trims and splits the string on whitespace and returns the array of parts.
@@ -115,7 +126,8 @@
115
126
  * @returns {string[]}
116
127
  */
117
128
  function splitWords(str) {
118
- return str.trim().split(WHITESPACE_RE);
129
+ const trimmed = str.trim();
130
+ return WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];
119
131
  }
120
132
  /**
121
133
  * Merges the given properties to the `options` of the `obj` object, returning the
@@ -422,31 +434,25 @@
422
434
  * @param {boolean} [round]
423
435
  */
424
436
  constructor(x, y, round) {
425
- if (!Point.validate(x, y)) throw new Error(`Invalid Point object: (${x}, ${y})`);
426
- let _x, _y;
427
- if (x instanceof Point) {
428
- _x = x.x;
429
- _y = x.y;
430
- } else if (Array.isArray(x)) {
437
+ let _x = x, _y = y;
438
+ if (Array.isArray(x)) {
431
439
  _x = x[0];
432
440
  _y = x[1];
433
- } else if (typeof x === "object" && "x" in x && "y" in x) {
441
+ } else if (typeof x === "object" && x !== null) {
434
442
  _x = x.x;
435
443
  _y = x.y;
436
- } else {
437
- _x = x;
438
- _y = y;
439
444
  }
440
445
  /**
441
446
  * The `x` coordinate of the point.
442
447
  * @type {number}
443
448
  */
444
- this.x = round ? Math.round(_x) : _x;
449
+ this.x = round ? Math.round(toNumber(_x)) : toNumber(_x);
445
450
  /**
446
451
  * The `y` coordinate of the point.
447
452
  * @type {number}
448
453
  */
449
- this.y = round ? Math.round(_y) : _y;
454
+ this.y = round ? Math.round(toNumber(_y)) : toNumber(_y);
455
+ if (this.x !== this.x || this.y !== this.y) throw new Error(`Invalid Point object: (${_x}, ${_y})`);
450
456
  }
451
457
  /**
452
458
  * Returns the given `Point` object as it is (unless `round` is set), or else a new
@@ -474,10 +480,11 @@
474
480
  * @returns {boolean}
475
481
  */
476
482
  static validate(x, y) {
477
- if (x instanceof Point || Array.isArray(x)) return true;
478
- else if (x && typeof x === "object" && "x" in x && "y" in x) return true;
479
- else if ((x || x === 0) && (y || y === 0)) return true;
480
- return false;
483
+ try {
484
+ return !!new Point(x, y);
485
+ } catch {
486
+ return false;
487
+ }
481
488
  }
482
489
  /**
483
490
  * Returns the result of addition of the current and the given points.
@@ -637,100 +644,15 @@
637
644
  return `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;
638
645
  }
639
646
  };
640
- // src/dom/DomEvent.DoubleTap.js
641
- function makeDblclick(ev) {
642
- const init = {
643
- bubbles: ev.bubbles,
644
- cancelable: ev.cancelable,
645
- composed: ev.composed,
646
- detail: 2,
647
- view: ev.view,
648
- screenX: ev.screenX,
649
- screenY: ev.screenY,
650
- clientX: ev.clientX,
651
- clientY: ev.clientY,
652
- ctrlKey: ev.ctrlKey,
653
- shiftKey: ev.shiftKey,
654
- altKey: ev.altKey,
655
- metaKey: ev.metaKey,
656
- button: ev.button,
657
- buttons: ev.buttons,
658
- relatedTarget: ev.relatedTarget,
659
- region: ev.region
660
- };
661
- let newEvent;
662
- if (ev instanceof PointerEvent) newEvent = new PointerEvent("dblclick", {
663
- ...init,
664
- pointerId: ev.pointerId,
665
- width: ev.width,
666
- height: ev.height,
667
- pressure: ev.pressure,
668
- tangentialPressure: ev.tangentialPressure,
669
- tiltX: ev.tiltX,
670
- tiltY: ev.tiltY,
671
- twist: ev.twist,
672
- pointerType: ev.pointerType,
673
- isPrimary: ev.isPrimary
674
- });
675
- else newEvent = new MouseEvent("dblclick", init);
676
- return newEvent;
677
- }
678
- const delay$1 = 200;
679
- /**
680
- * Adds a `dblclick` listener which also handles double taps (simulating `dblclick`
681
- * on platforms which don't fire it for touch events).
682
- * @param {EventTarget} obj
683
- * @param {(ev: MouseEvent) => void} handler
684
- * @returns {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}}
685
- * The listeners to pass to `removeDoubleTapListener`.
686
- */
687
- function addDoubleTapListener(obj, handler) {
688
- obj.addEventListener("dblclick", handler);
689
- let last = 0, detail, pointerType;
690
- function onPointerDown(ev) {
691
- pointerType = ev.pointerType;
692
- }
693
- function simDblclick(ev) {
694
- if (ev.detail !== 1) {
695
- detail = ev.detail;
696
- return;
697
- }
698
- if (pointerType === "mouse" || ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents) return;
699
- const path = ev.composedPath();
700
- if (path.some((el) => el instanceof HTMLLabelElement && el.htmlFor) && !path.some((el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement)) return;
701
- const now = Date.now();
702
- if (now - last <= delay$1) {
703
- detail++;
704
- if (detail === 2) ev.target.dispatchEvent(makeDblclick(ev));
705
- } else detail = 1;
706
- last = now;
707
- }
708
- obj.addEventListener("pointerdown", onPointerDown, true);
709
- obj.addEventListener("click", simDblclick);
710
- return {
711
- dblclick: handler,
712
- onPointerDown,
713
- simDblclick
714
- };
715
- }
716
- /**
717
- * Removes the listeners added by `addDoubleTapListener`.
718
- * @param {EventTarget} obj
719
- * @param {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}} handlers
720
- * @returns {void}
721
- */
722
- function removeDoubleTapListener(obj, handlers) {
723
- obj.removeEventListener("dblclick", handlers.dblclick);
724
- obj.removeEventListener("pointerdown", handlers.onPointerDown, true);
725
- obj.removeEventListener("click", handlers.simDblclick);
726
- }
727
647
  // src/dom/DomEvent.PointerEvents.js
728
648
  var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
729
649
  disablePointerDetection: () => disablePointerDetection,
730
650
  enablePointerDetection: () => enablePointerDetection,
731
- getPointers: () => getPointers
651
+ getPointers: () => getPointers,
652
+ simulateDblclick: () => simulateDblclick
732
653
  });
733
654
  const activePointers = /* @__PURE__ */ new Map();
655
+ let lastPointerType;
734
656
  /**
735
657
  * Enables pointer detection and capture for the document.
736
658
  * @group Pointer detection
@@ -759,6 +681,7 @@
759
681
  function _onSet(e) {
760
682
  if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
761
683
  activePointers.set(e.pointerId, e);
684
+ lastPointerType = e.pointerType;
762
685
  }
763
686
  function _onUpdate(e) {
764
687
  if (activePointers.has(e.pointerId)) activePointers.set(e.pointerId, e);
@@ -775,6 +698,56 @@
775
698
  function getPointers() {
776
699
  return [...activePointers.values()];
777
700
  }
701
+ const dblclickProps = [
702
+ "bubbles",
703
+ "cancelable",
704
+ "composed",
705
+ "view",
706
+ "screenX",
707
+ "screenY",
708
+ "clientX",
709
+ "clientY",
710
+ "ctrlKey",
711
+ "shiftKey",
712
+ "altKey",
713
+ "metaKey",
714
+ "button",
715
+ "buttons",
716
+ "relatedTarget"
717
+ ];
718
+ let lastClickTime = 0;
719
+ let lastClick;
720
+ let lastClickMap;
721
+ let clickCount = 0;
722
+ /**
723
+ * Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),
724
+ * which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The
725
+ * pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on
726
+ * clicks from touch (WebKit bug 282988). Called by the map for clicks in it.
727
+ * @internal
728
+ * @param {MouseEvent} e
729
+ * @param {HTMLElement} mapContainer The container of the map, two taps make a double
730
+ * tap only in the same map.
731
+ * @returns {void}
732
+ */
733
+ function simulateDblclick(e, mapContainer) {
734
+ if (e === lastClick) return;
735
+ lastClick = e;
736
+ const target = e.target;
737
+ if (e.detail !== 1 || lastPointerType === "mouse" || target.closest("label")) {
738
+ clickCount = 0;
739
+ return;
740
+ }
741
+ const now = Date.now();
742
+ clickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;
743
+ lastClickTime = now;
744
+ lastClickMap = mapContainer;
745
+ if (clickCount === 2) {
746
+ const init = { detail: 2 };
747
+ for (const prop of dblclickProps) init[prop] = e[prop];
748
+ target.dispatchEvent(new MouseEvent("dblclick", init));
749
+ }
750
+ }
778
751
  // src/dom/DomEvent.js
779
752
  var DomEvent_exports = /* @__PURE__ */ __exportAll({
780
753
  PointerEvents: () => DomEvent_PointerEvents_exports,
@@ -842,11 +815,10 @@
842
815
  function addOne(obj, type, fn, context) {
843
816
  const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
844
817
  if (obj[eventsKey] && obj[eventsKey][id]) return;
845
- let handler = function(e) {
818
+ const handler = function(e) {
846
819
  return fn.call(context || obj, e);
847
820
  };
848
- if (type === "dblclick") handler = addDoubleTapListener(obj, handler);
849
- else obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
821
+ obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
850
822
  obj[eventsKey] ??= {};
851
823
  obj[eventsKey][id] = handler;
852
824
  }
@@ -854,8 +826,7 @@
854
826
  id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
855
827
  const handler = obj[eventsKey] && obj[eventsKey][id];
856
828
  if (!handler) return;
857
- if (type === "dblclick") removeDoubleTapListener(obj, handler);
858
- else obj.removeEventListener(type, handler, false);
829
+ obj.removeEventListener(type, handler, false);
859
830
  obj[eventsKey][id] = null;
860
831
  }
861
832
  /**
@@ -941,7 +912,7 @@
941
912
  * @returns {number}
942
913
  */
943
914
  function getWheelDelta(e) {
944
- 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;
915
+ return -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;
945
916
  }
946
917
  /**
947
918
  * Checks if the pointer really left/entered the element `el` (for
@@ -988,7 +959,7 @@
988
959
  function create(tagName, className, container) {
989
960
  const el = document.createElement(tagName);
990
961
  el.className = className ?? "";
991
- container?.appendChild(el);
962
+ container?.append(el);
992
963
  return el;
993
964
  }
994
965
  /**
@@ -1000,8 +971,8 @@
1000
971
  function toFront(el) {
1001
972
  const parent = el.parentNode;
1002
973
  if (!parent || parent.lastChild === el) return;
1003
- if (el.matches(":hover")) while (el.nextSibling) parent.insertBefore(el.nextSibling, el);
1004
- else parent.appendChild(el);
974
+ if (el.matches(":hover")) while (el.nextSibling) el.before(el.nextSibling);
975
+ else parent.append(el);
1005
976
  }
1006
977
  /**
1007
978
  * Makes `el` the first child of its parent, so it renders behind the other children.
@@ -1011,8 +982,8 @@
1011
982
  function toBack(el) {
1012
983
  const parent = el.parentNode;
1013
984
  if (!parent || parent.firstChild === el) return;
1014
- if (el.matches(":hover")) while (el.previousSibling) parent.insertBefore(el.previousSibling, el.nextSibling);
1015
- else parent.insertBefore(el, parent.firstChild);
985
+ if (el.matches(":hover")) while (el.previousSibling) el.after(el.previousSibling);
986
+ else parent.prepend(el);
1016
987
  }
1017
988
  /**
1018
989
  * Resets the 3D CSS transform of `el` so it is translated by `offset` pixels
@@ -1151,12 +1122,16 @@
1151
1122
  * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that
1152
1123
  * removes the listeners previously added in `onAdd`. Called on
1153
1124
  * [`control.remove()`](#control-remove).
1125
+ * @property {() => Record<string, Function>} [getEvents] Should return an object like
1126
+ * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this object
1127
+ * will be automatically added and removed from the map with your control.
1154
1128
  * @lends Control
1155
1129
  */
1156
1130
  const controlOrders = /* @__PURE__ */ new WeakMap();
1157
1131
  /**
1158
- * Control is a base class for implementing map controls. Handles positioning.
1159
- * All other controls extend from this class.
1132
+ * Base class for map controls such as `ZoomControl`, `AttributionControl`,
1133
+ * `LayersControl` and `ScaleControl`, which handles positioning them. Extend it to
1134
+ * create your own controls.
1160
1135
  *
1161
1136
  * Every control should extend from `Control` and (re-)implement the following methods:
1162
1137
  *
@@ -1166,6 +1141,9 @@
1166
1141
  * * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes
1167
1142
  * the listeners previously added in [`onAdd`](#control-onadd). Called on
1168
1143
  * [`control.remove()`](#control-remove).
1144
+ * * `getEvents(): Object` (optional) should return an object like
1145
+ * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this
1146
+ * object will be automatically added and removed from the map with your control.
1169
1147
  */
1170
1148
  var Control = class Control extends Class {
1171
1149
  static defaultOptions = {
@@ -1219,7 +1197,11 @@
1219
1197
  const order = this.options.order ?? 0, bottom = pos.includes("bottom"), children = [...corner.children];
1220
1198
  controlOrders.set(container, order);
1221
1199
  corner.insertBefore(container, children.find((el) => bottom ? (controlOrders.get(el) ?? 0) <= order : (controlOrders.get(el) ?? 0) > order) ?? null);
1222
- this._map.on("unload", this.remove, this);
1200
+ this._mapEvents = {
1201
+ ...this.getEvents?.(),
1202
+ unload: this.remove
1203
+ };
1204
+ map.on(this._mapEvents, this);
1223
1205
  return this;
1224
1206
  }
1225
1207
  /**
@@ -1229,17 +1211,11 @@
1229
1211
  remove() {
1230
1212
  if (!this._map) return this;
1231
1213
  this._container.remove();
1232
- if (this.onRemove) this.onRemove(this._map);
1233
- this._map.off("unload", this.remove, this);
1214
+ this._map.off(this._mapEvents, this);
1215
+ this.onRemove?.(this._map);
1234
1216
  this._map = null;
1235
1217
  return this;
1236
1218
  }
1237
- _refocusOnMap(e) {
1238
- if (this._map && e && !(e.screenX === 0 && e.screenY === 0)) this._map.getContainer().focus({
1239
- preventScroll: true,
1240
- focusVisible: false
1241
- });
1242
- }
1243
1219
  /**
1244
1220
  * Registers this default feature on the map class, called by `MaplairMap` itself.
1245
1221
  * @internal
@@ -1385,21 +1361,22 @@
1385
1361
  disableClickPropagation(this._container);
1386
1362
  if (map._loaded) map.eachLayer((layer) => this._addLayer({ layer }));
1387
1363
  this._update();
1388
- map.on({
1389
- layeradd: this._addLayer,
1390
- layerremove: this._removeLayer
1391
- }, this);
1392
1364
  return this._container;
1393
1365
  }
1394
1366
  /**
1395
1367
  * @internal
1396
- * @param {MaplairMap} map
1368
+ * @returns {Record<string, Function>}
1397
1369
  */
1398
- onRemove(map) {
1399
- map.off({
1370
+ getEvents() {
1371
+ return {
1400
1372
  layeradd: this._addLayer,
1401
1373
  layerremove: this._removeLayer
1402
- }, this);
1374
+ };
1375
+ }
1376
+ /**
1377
+ * @internal
1378
+ */
1379
+ onRemove() {
1403
1380
  for (const layer of this._layerAttributions.keys()) this._removeLayer({ layer });
1404
1381
  }
1405
1382
  _addLayer({ layer }) {
@@ -1433,8 +1410,7 @@
1433
1410
  addAttribution(text, order = 0) {
1434
1411
  if (!text) return this;
1435
1412
  this._orders[text] = order;
1436
- if (!this._attributions[text]) this._attributions[text] = 0;
1437
- this._attributions[text]++;
1413
+ this._attributions[text] = (this._attributions[text] || 0) + 1;
1438
1414
  this._update();
1439
1415
  return this;
1440
1416
  }
@@ -1569,7 +1545,6 @@
1569
1545
  disableClickPropagation(button);
1570
1546
  on(button, "click", stop);
1571
1547
  on(button, "click", this._onClick, this);
1572
- on(button, "click", this._refocusOnMap, this);
1573
1548
  this._update();
1574
1549
  return button;
1575
1550
  }
@@ -1931,8 +1906,9 @@
1931
1906
  };
1932
1907
  if (_once) newListener.once = true;
1933
1908
  this._events ??= {};
1934
- this._events[type] ??= /* @__PURE__ */ new Set();
1935
- this._events[type].add(newListener);
1909
+ let listeners = this._events[type] ??= /* @__PURE__ */ new Set();
1910
+ if (this._firingCount) this._events[type] = listeners = new Set(listeners);
1911
+ listeners.add(newListener);
1936
1912
  if (contexts) contexts.set(context, newListener);
1937
1913
  else this._listenerIndex[type].set(fn, /* @__PURE__ */ new Map([[context, newListener]]));
1938
1914
  }
@@ -2065,6 +2041,7 @@
2065
2041
  }
2066
2042
  _propagateEvent(e) {
2067
2043
  for (const p of Object.values(this._eventParents ?? {})) p.fire(e.type, {
2044
+ layer: e.target,
2068
2045
  propagatedFrom: e.target,
2069
2046
  ...e
2070
2047
  }, true);
@@ -2206,8 +2183,8 @@
2206
2183
  const oldZoomSpan = this._getZoomSpan();
2207
2184
  for (const l of Object.values(this._zoomBoundLayers)) {
2208
2185
  const options = l.options;
2209
- minZoom = Math.min(minZoom, options.minZoom ?? Infinity);
2210
- maxZoom = Math.max(maxZoom, options.maxZoom ?? -Infinity);
2186
+ if (options.minZoom != null && !Number.isNaN(options.minZoom)) minZoom = Math.min(minZoom, options.minZoom);
2187
+ if (options.maxZoom != null && !Number.isNaN(options.maxZoom)) maxZoom = Math.max(maxZoom, options.maxZoom);
2211
2188
  }
2212
2189
  this._layersMaxZoom = maxZoom === -Infinity ? void 0 : maxZoom;
2213
2190
  this._layersMinZoom = minZoom === Infinity ? void 0 : minZoom;
@@ -2329,8 +2306,10 @@
2329
2306
  }
2330
2307
  _updateInteractive() {}
2331
2308
  /**
2332
- * Makes `targetEl` a target of pointer events of this layer.
2333
- * @internal
2309
+ * Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and
2310
+ * keyboard events on it (or its descendants) fire on the layer and bubble through its
2311
+ * parent groups to the map, the way they do for markers and paths. Custom layers call
2312
+ * it in [`onAdd`](#layer-onadd), once the layer is on a map.
2334
2313
  * @param {HTMLElement} targetEl
2335
2314
  * @returns {this}
2336
2315
  */
@@ -2339,8 +2318,8 @@
2339
2318
  return this;
2340
2319
  }
2341
2320
  /**
2342
- * Stops `targetEl` from being a target of pointer events of this layer.
2343
- * @internal
2321
+ * Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in
2322
+ * [`onRemove`](#layer-onremove).
2344
2323
  * @param {HTMLElement} targetEl
2345
2324
  * @returns {this}
2346
2325
  */
@@ -2348,6 +2327,9 @@
2348
2327
  delete this._map._targets[stamp(targetEl)];
2349
2328
  return this;
2350
2329
  }
2330
+ _togglesPopupOnClick() {
2331
+ return true;
2332
+ }
2351
2333
  /**
2352
2334
  * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).
2353
2335
  * @returns {string|null}
@@ -2515,7 +2497,7 @@
2515
2497
  }
2516
2498
  _createMenu(parent) {
2517
2499
  const container = this._container ??= create("div", `maplair-contextmenu ${this.options.className}`);
2518
- if (container.parentNode !== parent) parent.appendChild(container);
2500
+ if (container.parentNode !== parent) parent.append(container);
2519
2501
  container.popover = "auto";
2520
2502
  container.setAttribute("role", "menu");
2521
2503
  container.replaceChildren();
@@ -2682,7 +2664,6 @@
2682
2664
  disableClickPropagation(button);
2683
2665
  on(button, "click", stop);
2684
2666
  on(button, "click", this._toggleFullscreen, this);
2685
- on(button, "click", this._refocusOnMap, this);
2686
2667
  this._update();
2687
2668
  map.on("fullscreenchange", this._update, this);
2688
2669
  return container;
@@ -2766,6 +2747,8 @@
2766
2747
  * `maplair-control-layers-group-name` element, and each entry shows only its label.
2767
2748
  * Events like `baselayerchange` still carry the full `name`. When combined with
2768
2749
  * `sortLayers`, the entries are sorted first and grouped afterwards.
2750
+ * @property {string} [title] The title of the toggle button and the accessible label
2751
+ * of the layers list, the translation of `'Layers'` by default.
2769
2752
  * @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
2770
2753
  * collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
2771
2754
  * element. String content is rendered as HTML; do not pass untrusted input.
@@ -2850,6 +2833,7 @@
2850
2833
  collapsed: true,
2851
2834
  inline: false,
2852
2835
  groupBy: void 0,
2836
+ title: void 0,
2853
2837
  toggleContent: void 0,
2854
2838
  collapseDelay: 0,
2855
2839
  position: "topright",
@@ -2996,13 +2980,16 @@
2996
2980
  else this._container.classList.remove("maplair-control-layers-expanded");
2997
2981
  return this;
2998
2982
  }
2983
+ _getTitle() {
2984
+ return this.options.title ?? I18n.translate("Layers");
2985
+ }
2999
2986
  _initLayout() {
3000
2987
  const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this._isCollapsible();
3001
2988
  if (this.options.inline) container.classList.add(`${className}-inline`);
3002
2989
  disableClickPropagation(container);
3003
2990
  disableScrollPropagation(container);
3004
2991
  const section = this._section = create("fieldset", `${className}-list`);
3005
- section.setAttribute("aria-label", I18n.translate("Layers"));
2992
+ section.setAttribute("aria-label", this._getTitle());
3006
2993
  if (collapsed) {
3007
2994
  this._map.on("click", this.collapse, this);
3008
2995
  on(container, {
@@ -3015,8 +3002,8 @@
3015
3002
  if (!this.options.inline) {
3016
3003
  const link = this._layersLink = create("button", `${className}-toggle`, container);
3017
3004
  link.type = "button";
3018
- link.title = I18n.translate("Layers");
3019
- link.setAttribute("aria-label", I18n.translate("Layers"));
3005
+ link.title = this._getTitle();
3006
+ link.setAttribute("aria-label", link.title);
3020
3007
  const { toggleContent } = this.options;
3021
3008
  if (typeof toggleContent === "string") link.innerHTML = toggleContent;
3022
3009
  else if (toggleContent) link.replaceChildren(toggleContent);
@@ -3034,7 +3021,7 @@
3034
3021
  this._baseLayersList = create("div", `${className}-base`, section);
3035
3022
  this._separator = create("div", `${className}-separator`, section);
3036
3023
  this._overlaysList = create("div", `${className}-overlays`, section);
3037
- container.appendChild(section);
3024
+ container.append(section);
3038
3025
  }
3039
3026
  _addLayer(layer, name, overlay) {
3040
3027
  if (this._map) layer.on("add remove", this._onLayerChange, this);
@@ -3093,11 +3080,10 @@
3093
3080
  const name = document.createElement("span");
3094
3081
  name.innerHTML = ` ${group ? group.label : obj.name}`;
3095
3082
  const holder = document.createElement("span");
3096
- label.appendChild(holder);
3097
- holder.appendChild(input);
3098
- holder.appendChild(name);
3083
+ label.append(holder);
3084
+ holder.append(input, name);
3099
3085
  const list = obj.overlay ? this._overlaysList : this._baseLayersList;
3100
- (group ? this._getGroupContainer(list, group.group) : list).appendChild(label);
3086
+ (group ? this._getGroupContainer(list, group.group) : list).append(label);
3101
3087
  this._checkDisabledLayers();
3102
3088
  return label;
3103
3089
  }
@@ -3138,7 +3124,6 @@
3138
3124
  this._update();
3139
3125
  break;
3140
3126
  }
3141
- this._refocusOnMap(e);
3142
3127
  }
3143
3128
  _checkDisabledLayers() {
3144
3129
  const inputs = this._layerControlInputs, zoom = this._map.getZoom();
@@ -3331,7 +3316,7 @@
3331
3316
  */
3332
3317
  overlaps(bounds) {
3333
3318
  bounds = Bounds.from(bounds);
3334
- 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;
3319
+ 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);
3335
3320
  return xOverlaps && yOverlaps;
3336
3321
  }
3337
3322
  /**
@@ -3364,7 +3349,7 @@
3364
3349
  }
3365
3350
  };
3366
3351
  function isPointExpression(obj) {
3367
- return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] === "number" : "x" in obj);
3352
+ return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] !== "object" : "x" in obj);
3368
3353
  }
3369
3354
  // src/layer/BlanketOverlay.js
3370
3355
  /** @import {LayerOptions} from './Layer.js' */
@@ -3427,7 +3412,7 @@
3427
3412
  this._initContainer();
3428
3413
  this._container.classList.add("maplair-zoom-animated");
3429
3414
  }
3430
- this.getPane().appendChild(this._container);
3415
+ this.getPane().append(this._container);
3431
3416
  this._resizeContainer();
3432
3417
  this._onMoveEnd();
3433
3418
  }
@@ -3499,6 +3484,8 @@
3499
3484
  /** @import {BlanketOverlayOptions} from '../BlanketOverlay.js' */
3500
3485
  /** @import {MaplairEvent} from '../../core/Events.js' */
3501
3486
  /** @import {MaplairMap} from '../../map/Map.js' */
3487
+ /** @import {LatLngExpression} from '../../geo/LatLng.js' */
3488
+ /** @import {Point} from '../../geometry/Point.js' */
3502
3489
  /**
3503
3490
  * Options of `Renderer`, `SVG` and `Canvas`. The `continuous` option inherited from
3504
3491
  * `BlanketOverlay` cannot be set to `true`.
@@ -3540,6 +3527,7 @@
3540
3527
  * @param {MaplairMap} map
3541
3528
  */
3542
3529
  onAdd(map) {
3530
+ this._setPathView();
3543
3531
  super.onAdd(map);
3544
3532
  this.on("update", this._updatePaths, this);
3545
3533
  }
@@ -3551,12 +3539,25 @@
3551
3539
  this.off("update", this._updatePaths, this);
3552
3540
  }
3553
3541
  _onZoomEnd() {
3542
+ this._setPathView();
3554
3543
  for (const layer of Object.values(this._layers)) layer._project();
3555
3544
  }
3545
+ _setPathView() {
3546
+ this._pathZoom = this._map.getZoom();
3547
+ this._pathOrigin = this._map.getPixelOrigin();
3548
+ }
3549
+ /**
3550
+ * @param {LatLngExpression} latlng
3551
+ * @returns {Point}
3552
+ */
3553
+ _latLngToLayerPoint(latlng) {
3554
+ return this._map.project(latlng, this._pathZoom)._subtract(this._pathOrigin);
3555
+ }
3556
3556
  _updatePaths() {
3557
3557
  for (const layer of Object.values(this._layers)) layer._update();
3558
3558
  }
3559
3559
  _onViewReset() {
3560
+ this._setPathView();
3560
3561
  for (const layer of Object.values(this._layers)) layer._reset();
3561
3562
  }
3562
3563
  _onSettled() {
@@ -3606,7 +3607,7 @@
3606
3607
  this._container = SVG.create("svg");
3607
3608
  this._container.setAttribute("pointer-events", "none");
3608
3609
  this._rootGroup = SVG.create("g");
3609
- this._container.appendChild(this._rootGroup);
3610
+ this._container.append(this._rootGroup);
3610
3611
  }
3611
3612
  _destroyContainer() {
3612
3613
  super._destroyContainer();
@@ -3615,7 +3616,7 @@
3615
3616
  }
3616
3617
  _resizeContainer() {
3617
3618
  const size = super._resizeContainer();
3618
- if (!this._svgSize || !this._svgSize.equals(size)) {
3619
+ if (!this._svgSize?.equals(size)) {
3619
3620
  this._svgSize = size;
3620
3621
  this._container.setAttribute("width", `${size.x}`);
3621
3622
  this._container.setAttribute("height", `${size.y}`);
@@ -3651,7 +3652,7 @@
3651
3652
  }
3652
3653
  _addPath(layer) {
3653
3654
  if (!this._rootGroup) this._initContainer();
3654
- this._rootGroup.appendChild(layer._path);
3655
+ this._rootGroup.append(layer._path);
3655
3656
  layer.addInteractiveTarget(layer._path);
3656
3657
  }
3657
3658
  _removePath(layer) {
@@ -3760,13 +3761,15 @@
3760
3761
  * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
3761
3762
  * afterwards.
3762
3763
  * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
3763
- * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),
3764
- * which is `SVG` by default. If set, it overrides the `pane` option.
3764
+ * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
3765
+ * (`SVG` by default), or in a custom pane, a renderer of the same kind created for
3766
+ * that pane. If set, it overrides the `pane` option.
3765
3767
  * @extends InteractiveLayerOptions
3766
3768
  */
3767
3769
  /**
3768
- * An abstract class that contains options and constants shared between vector
3769
- * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
3770
+ * An abstract class that contains options and methods shared between vector overlays
3771
+ * (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it
3772
+ * directly. Extends `Layer`.
3770
3773
  */
3771
3774
  var Path = class extends Layer {
3772
3775
  static defaultOptions = {
@@ -3863,8 +3866,11 @@
3863
3866
  this._project();
3864
3867
  this._update();
3865
3868
  }
3869
+ _togglesPopupOnClick() {
3870
+ return false;
3871
+ }
3866
3872
  _clickTolerance() {
3867
- return (this.options.stroke ? this.options.weight / 2 : 0) + (this._renderer.options.tolerance || 0);
3873
+ return (this.options.stroke ? this.options.weight / 2 || 0 : 0) + (this._renderer.options.tolerance || 0);
3868
3874
  }
3869
3875
  };
3870
3876
  // src/geo/LatLngBounds.js
@@ -3952,7 +3958,7 @@
3952
3958
  ({_southWest: sw2, _northEast: ne2} = obj);
3953
3959
  if (!sw2) return this;
3954
3960
  } else if (!obj) return this;
3955
- else if (LatLng.validate(obj)) sw2 = ne2 = LatLng.from(obj);
3961
+ else if (isLatLngExpression(obj)) sw2 = ne2 = LatLng.from(obj);
3956
3962
  else return this.extend(LatLngBounds.from(obj));
3957
3963
  if (!sw) {
3958
3964
  this._southWest = new LatLng(sw2.lat, sw2.lng);
@@ -4045,7 +4051,7 @@
4045
4051
  * @returns {boolean}
4046
4052
  */
4047
4053
  contains(obj) {
4048
- if (LatLng.validate(obj)) obj = LatLng.from(obj);
4054
+ if (isLatLngExpression(obj)) obj = LatLng.from(obj);
4049
4055
  else obj = LatLngBounds.from(obj);
4050
4056
  const sw = this._southWest, ne = this._northEast;
4051
4057
  let sw2, ne2;
@@ -4074,7 +4080,7 @@
4074
4080
  */
4075
4081
  overlaps(bounds) {
4076
4082
  bounds = LatLngBounds.from(bounds);
4077
- 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;
4083
+ 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);
4078
4084
  return latOverlaps && lngOverlaps;
4079
4085
  }
4080
4086
  /**
@@ -4112,6 +4118,9 @@
4112
4118
  return !!(this._southWest && this._northEast);
4113
4119
  }
4114
4120
  };
4121
+ function isLatLngExpression(obj) {
4122
+ return obj instanceof LatLng || (Array.isArray(obj) ? typeof obj[0] !== "object" : typeof obj === "object" && obj !== null && "lat" in obj);
4123
+ }
4115
4124
  // src/geo/LatLng.js
4116
4125
  const coordinate = String.raw`([+-]?\d+(?:\.\d+)?)\s*°?`;
4117
4126
  const separator = String.raw`(?:\s*[,;]\s*|\s+)`;
@@ -4161,46 +4170,36 @@
4161
4170
  * @param {number} [alt] Altitude in meters.
4162
4171
  */
4163
4172
  constructor(lat, lng, alt) {
4164
- if (!LatLng.validate(lat, lng, alt)) throw new Error(`Invalid LatLng object: (${lat}, ${lng})`);
4165
- let _lat, _lng, _alt;
4166
- if (lat instanceof LatLng) {
4167
- _lat = lat.lat;
4168
- _lng = lat.lng;
4169
- _alt = lat.alt;
4170
- } else if (Array.isArray(lat) && typeof lat[0] !== "object") {
4171
- if (lat.length === 3) {
4172
- _lat = lat[0];
4173
- _lng = lat[1];
4174
- _alt = lat[2];
4175
- } else if (lat.length === 2) {
4176
- _lat = lat[0];
4177
- _lng = lat[1];
4178
- }
4179
- } else if (typeof lat === "object" && "lat" in lat) {
4173
+ let _lat = lat, _lng = lng, _alt = alt;
4174
+ if (lat instanceof LatLng) ({lat: _lat, lng: _lng, alt: _alt} = lat);
4175
+ else if (Array.isArray(lat)) {
4176
+ _lat = lat.length <= 3 ? lat[0] : NaN;
4177
+ _lng = lat[1];
4178
+ _alt = lat[2];
4179
+ } else if (typeof lat === "object" && lat !== null) {
4180
4180
  _lat = lat.lat;
4181
4181
  _lng = "lng" in lat ? lat.lng : lat.lon;
4182
4182
  _alt = lat.alt;
4183
- } else {
4184
- _lat = lat;
4185
- _lng = lng;
4186
- _alt = alt;
4187
4183
  }
4188
4184
  /**
4189
4185
  * Latitude in degrees.
4190
4186
  * @type {number}
4191
4187
  */
4192
- this.lat = +_lat;
4188
+ this.lat = toNumber(_lat);
4193
4189
  /**
4194
4190
  * Longitude in degrees.
4195
4191
  * @type {number}
4196
4192
  */
4197
- this.lng = +_lng;
4198
- if (_alt !== void 0)
4199
- /**
4200
- * Altitude in meters (optional).
4201
- * @type {number|undefined}
4202
- */
4203
- this.alt = +_alt;
4193
+ this.lng = toNumber(_lng);
4194
+ if (isNaN(this.lat) || isNaN(this.lng)) throw new Error(`Invalid LatLng object: (${_lat}, ${_lng})`);
4195
+ if (_alt != null) {
4196
+ /**
4197
+ * Altitude in meters (optional).
4198
+ * @type {number|undefined}
4199
+ */
4200
+ this.alt = toNumber(_alt);
4201
+ if (isNaN(this.alt)) throw new Error(`Invalid LatLng altitude: ${_alt}`);
4202
+ }
4204
4203
  }
4205
4204
  /**
4206
4205
  * Returns the given `LatLng` object as it is, or else a new `LatLng` object created
@@ -4229,12 +4228,11 @@
4229
4228
  * @returns {boolean}
4230
4229
  */
4231
4230
  static validate(lat, lng, alt) {
4232
- if (lat instanceof LatLng || typeof lat === "object" && lat !== null && "lat" in lat) return true;
4233
- else if (lat && Array.isArray(lat) && typeof lat[0] !== "object") {
4234
- if (lat.length === 3 || lat.length === 2) return true;
4231
+ try {
4232
+ return !!new LatLng(lat, lng, alt);
4233
+ } catch {
4235
4234
  return false;
4236
- } else if ((lat || lat === 0) && (lng || lng === 0)) return true;
4237
- return false;
4235
+ }
4238
4236
  }
4239
4237
  /**
4240
4238
  * Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.
@@ -4624,6 +4622,7 @@
4624
4622
  });
4625
4623
  }
4626
4624
  // src/layer/vector/CircleMarker.js
4625
+ /** @import {MaplairMap} from '../../map/Map.js' */
4627
4626
  /** @import {Feature} from 'geojson' */
4628
4627
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
4629
4628
  /** @import {MaplairEvent} from '../../core/Events.js' */
@@ -4668,6 +4667,13 @@
4668
4667
  this.callInitHooks(CircleMarker);
4669
4668
  }
4670
4669
  /**
4670
+ * @param {MaplairMap} map
4671
+ */
4672
+ beforeAdd(map) {
4673
+ super.beforeAdd(map);
4674
+ map._displaceHandler?._beforeMarkerAdd(this);
4675
+ }
4676
+ /**
4671
4677
  * Sets the position of a circle marker to a new location.
4672
4678
  * @param {LatLngExpression} latlng
4673
4679
  * @returns {this}
@@ -4715,7 +4721,7 @@
4715
4721
  return this;
4716
4722
  }
4717
4723
  _project() {
4718
- this._point = this._map.latLngToLayerPoint(this._latlng)._round();
4724
+ this._point = this._renderer._latLngToLayerPoint(this._latlng)._round();
4719
4725
  this._pxRadius = this._radius;
4720
4726
  this._updateBounds();
4721
4727
  }
@@ -5192,13 +5198,7 @@
5192
5198
  * @param {number} [d]
5193
5199
  */
5194
5200
  constructor(a, b, c, d) {
5195
- if (Array.isArray(a)) {
5196
- this._a = a[0];
5197
- this._b = a[1];
5198
- this._c = a[2];
5199
- this._d = a[3];
5200
- return;
5201
- }
5201
+ if (Array.isArray(a)) [a, b, c, d] = a;
5202
5202
  this._a = a;
5203
5203
  this._b = b;
5204
5204
  this._c = c;
@@ -5342,10 +5342,10 @@
5342
5342
  * @property {string} [position='topleft'] The position of the control (one of the map
5343
5343
  * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
5344
5344
  * `'bottomright'`.
5345
- * @property {string} [zoomInText='<span aria-hidden="true">+</span>'] The text set on
5346
- * the 'zoom in' button.
5347
- * @property {string} [zoomOutText='<span aria-hidden="true">&#x2212;</span>'] The text
5348
- * set on the 'zoom out' button.
5345
+ * @property {string} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn
5346
+ * in SVG by default.
5347
+ * @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign
5348
+ * drawn in SVG by default.
5349
5349
  * @extends ControlOptions
5350
5350
  */
5351
5351
  /**
@@ -5369,8 +5369,8 @@
5369
5369
  var ZoomControl = class ZoomControl extends Control {
5370
5370
  static defaultOptions = {
5371
5371
  position: "topleft",
5372
- zoomInText: "<span aria-hidden=\"true\">+</span>",
5373
- zoomOutText: "<span aria-hidden=\"true\">&#x2212;</span>"
5372
+ zoomInText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12M6 0v12\"/></svg>",
5373
+ zoomOutText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12\"/></svg>"
5374
5374
  };
5375
5375
  /**
5376
5376
  * Creates a zoom control.
@@ -5382,23 +5382,24 @@
5382
5382
  }
5383
5383
  /**
5384
5384
  * @internal
5385
- * @param {MaplairMap} map
5386
5385
  * @returns {HTMLElement}
5387
5386
  */
5388
- onAdd(map) {
5387
+ onAdd() {
5389
5388
  const zoomName = "maplair-control-zoom", container = create("div", `${zoomName} maplair-bar`), options = this.options;
5390
5389
  this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, (e) => this._zoom(e, 1));
5391
5390
  this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, (e) => this._zoom(e, -1));
5392
5391
  this._updateDisabled();
5393
- map.on("zoomend zoomlevelschange", this._updateDisabled, this);
5394
5392
  return container;
5395
5393
  }
5396
5394
  /**
5397
5395
  * @internal
5398
- * @param {MaplairMap} map
5396
+ * @returns {Record<string, Function>}
5399
5397
  */
5400
- onRemove(map) {
5401
- map.off("zoomend zoomlevelschange", this._updateDisabled, this);
5398
+ getEvents() {
5399
+ return {
5400
+ zoomend: this._updateDisabled,
5401
+ zoomlevelschange: this._updateDisabled
5402
+ };
5402
5403
  }
5403
5404
  /**
5404
5405
  * Disables the zoom buttons.
@@ -5435,7 +5436,6 @@
5435
5436
  on(link, "click", (e) => {
5436
5437
  stop(e);
5437
5438
  fn.call(this, e);
5438
- this._refocusOnMap(e);
5439
5439
  });
5440
5440
  return link;
5441
5441
  }
@@ -5755,9 +5755,12 @@
5755
5755
  /** @import {EventListener, MaplairEvent} from '../core/Events.js' */
5756
5756
  /**
5757
5757
  * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an
5758
- * `HTMLElement`, or a function receiving the source layer and returning one of them.
5759
- * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent
5758
+ * `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and
5759
+ * returning one of them.
5760
+ * @typedef {string|HTMLElement|DocumentFragment|
5761
+ * ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent
5760
5762
  */
5763
+ const fragmentNodes = /* @__PURE__ */ new WeakMap();
5761
5764
  /**
5762
5765
  * Options of `DivOverlay`.
5763
5766
  * @typedef {object} DivOverlayOptions
@@ -5773,8 +5776,8 @@
5773
5776
  * in the DOM (for styling and events).
5774
5777
  * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while
5775
5778
  * initializing. If a function is passed the source layer will be passed to the
5776
- * function. The function should return a `String` or `HTMLElement` to be used in the
5777
- * overlay. String content is rendered as HTML; sanitize untrusted input or pass an
5779
+ * function. The function should return a `String`, `HTMLElement` or `DocumentFragment`
5780
+ * to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an
5778
5781
  * `HTMLElement` with safe `textContent` instead.
5779
5782
  * @extends InteractiveLayerOptions
5780
5783
  */
@@ -5806,7 +5809,8 @@
5806
5809
  } };
5807
5810
  /** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */
5808
5811
  /**
5809
- * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.
5812
+ * Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit
5813
+ * from it for custom overlays like plugins.
5810
5814
  *
5811
5815
  * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
5812
5816
  */
@@ -5883,8 +5887,7 @@
5883
5887
  else {
5884
5888
  if (arguments.length) this._source = layer;
5885
5889
  else layer = this._source;
5886
- this._prepareOpen();
5887
- this.openOn(layer._map);
5890
+ if (this._prepareOpen()) this.openOn(layer._map);
5888
5891
  }
5889
5892
  return this;
5890
5893
  }
@@ -5896,7 +5899,7 @@
5896
5899
  if (!this._container) this._initLayout();
5897
5900
  if (map._fadeAnimated) this._container.style.opacity = "0";
5898
5901
  clearTimeout(this._removeTimeout);
5899
- this.getPane().appendChild(this._container);
5902
+ this.getPane().append(this._container);
5900
5903
  if (this.options.overflow) {
5901
5904
  this._container.classList.add("maplair-overflow");
5902
5905
  this._container.popover = "manual";
@@ -5969,9 +5972,10 @@
5969
5972
  /**
5970
5973
  * Sets the HTML content of the overlay. A `String` argument is rendered as
5971
5974
  * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)
5972
- * or pass an `HTMLElement` with safe `textContent` instead. If a function is
5973
- * passed the source layer will be passed to the function. The function should
5974
- * return a `String` or `HTMLElement` to be used in the overlay.
5975
+ * or pass an `HTMLElement` with safe `textContent` instead. A `DocumentFragment`
5976
+ * can be passed as well. If a function is passed the source layer will be passed
5977
+ * to the function. The function should return a `String`, `HTMLElement` or
5978
+ * `DocumentFragment` to be used in the overlay.
5975
5979
  * @param {DivOverlayContent} content
5976
5980
  * @returns {this}
5977
5981
  */
@@ -6019,7 +6023,7 @@
6019
6023
  * @returns {boolean}
6020
6024
  */
6021
6025
  isOpen() {
6022
- return !!this._map && this._map.hasLayer(this);
6026
+ return !!this._map?.hasLayer(this);
6023
6027
  }
6024
6028
  /**
6025
6029
  * Brings this overlay in front of other overlays (in the same map pane).
@@ -6063,25 +6067,21 @@
6063
6067
  if (!source) return false;
6064
6068
  this._source = source;
6065
6069
  }
6066
- if (!latlng) {
6067
- if (source.getCenter) latlng = source.getCenter();
6068
- else if (source.getLatLng) latlng = source.getLatLng();
6069
- else if (source.getBounds) latlng = source.getBounds().getCenter();
6070
- else throw new Error("Unable to get source layer LatLng.");
6071
- }
6070
+ latlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();
6071
+ if (!latlng) throw new Error("Unable to get source layer LatLng.");
6072
6072
  this.setLatLng(latlng);
6073
6073
  if (this._map) this.update();
6074
6074
  return true;
6075
6075
  }
6076
6076
  _updateContent() {
6077
- if (!this._content) return;
6077
+ if (this._content == null) return;
6078
6078
  const node = this._contentNode;
6079
6079
  const content = typeof this._content === "function" ? this._content(this._source ?? this) : this._content;
6080
6080
  if (typeof content === "string") node.innerHTML = content;
6081
- else {
6082
- while (node.hasChildNodes()) node.removeChild(node.firstChild);
6083
- node.appendChild(content);
6084
- }
6081
+ else if (content instanceof DocumentFragment) {
6082
+ if (content.hasChildNodes()) fragmentNodes.set(content, [...content.childNodes]);
6083
+ node.replaceChildren(...fragmentNodes.get(content) ?? []);
6084
+ } else node.replaceChildren(content);
6085
6085
  this.fire("contentupdate");
6086
6086
  }
6087
6087
  _updatePosition() {
@@ -6232,7 +6232,7 @@
6232
6232
  * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
6233
6233
  * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
6234
6234
  * it will receive the layer as the first argument and should return a
6235
- * `String` or `HTMLElement`.
6235
+ * `String`, `HTMLElement` or `DocumentFragment`.
6236
6236
  * @group Popup methods
6237
6237
  * @param {DivOverlayContent|Popup} content
6238
6238
  * @param {PopupOptions} [options]
@@ -6240,6 +6240,7 @@
6240
6240
  */
6241
6241
  bindPopup(content, options) {
6242
6242
  this._popup = this._initOverlay(Popup, this._popup, content, options);
6243
+ this._popup._updateSourceAria(this._popup.isOpen());
6243
6244
  this.on({
6244
6245
  click: this._openPopup,
6245
6246
  remove: this.closePopup,
@@ -6259,6 +6260,9 @@
6259
6260
  remove: this.closePopup,
6260
6261
  move: this._movePopup
6261
6262
  });
6263
+ const el = this.getElement?.();
6264
+ el?.removeAttribute("aria-expanded");
6265
+ el?.removeAttribute("aria-controls");
6262
6266
  this._popup = null;
6263
6267
  }
6264
6268
  return this;
@@ -6327,9 +6331,8 @@
6327
6331
  if (!this._popup || !this._map) return;
6328
6332
  stopPropagation(e);
6329
6333
  const target = e.propagatedFrom ?? e.target;
6330
- if (this._popup._source === target && !(target instanceof Path)) {
6331
- if (this._map.hasLayer(this._popup)) this.closePopup();
6332
- else this.openPopup(e.latlng);
6334
+ if (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {
6335
+ this.closePopup();
6333
6336
  return;
6334
6337
  }
6335
6338
  this._popup._source = target;
@@ -6426,9 +6429,11 @@
6426
6429
  */
6427
6430
  openOn(map) {
6428
6431
  map = arguments.length ? map : this._source._map;
6429
- if (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) map.removeLayer(map._popup);
6432
+ if (!map.hasLayer(this) && map._popup?.options.autoClose) map.removeLayer(map._popup);
6430
6433
  map._popup = this;
6431
- return super.openOn(map);
6434
+ super.openOn(map);
6435
+ this._updateSourceAria(true);
6436
+ return this;
6432
6437
  }
6433
6438
  /**
6434
6439
  * Adds the popup to the map.
@@ -6443,9 +6448,10 @@
6443
6448
  (this._closeButton ?? this._container).focus({ preventScroll: true });
6444
6449
  }
6445
6450
  map.fire("popupopen", { popup: this });
6451
+ this._updateSourceAria(true);
6446
6452
  if (this._source) {
6447
6453
  this._source.fire("popupopen", { popup: this }, true);
6448
- if (!(this._source instanceof Path)) this._source.on("preclick", stopPropagation);
6454
+ if (this._source._togglesPopupOnClick()) this._source.on("preclick", stopPropagation);
6449
6455
  }
6450
6456
  }
6451
6457
  /**
@@ -6453,13 +6459,17 @@
6453
6459
  * @param {MaplairMap} map
6454
6460
  */
6455
6461
  onRemove(map) {
6456
- if (this._container.contains(document.activeElement) && this._returnFocus?.isConnected) this._returnFocus.focus({ preventScroll: true });
6462
+ if (this._container.contains(document.activeElement)) {
6463
+ const el = this._source?.getElement?.();
6464
+ (this._returnFocus?.isConnected ? this._returnFocus : el?.tabIndex >= 0 ? el : map._container).focus({ preventScroll: true });
6465
+ }
6457
6466
  this._returnFocus = null;
6458
6467
  super.onRemove(map);
6459
6468
  map.fire("popupclose", { popup: this });
6469
+ this._updateSourceAria(false);
6460
6470
  if (this._source) {
6461
6471
  this._source.fire("popupclose", { popup: this }, true);
6462
- if (!(this._source instanceof Path)) this._source.off("preclick", stopPropagation);
6472
+ if (this._source._togglesPopupOnClick()) this._source.off("preclick", stopPropagation);
6463
6473
  }
6464
6474
  }
6465
6475
  /**
@@ -6472,8 +6482,17 @@
6472
6482
  if (this.options.keepInView) events.moveend = this._adjustPan;
6473
6483
  return events;
6474
6484
  }
6485
+ _updateSourceAria(open) {
6486
+ this._ariaSource?.setAttribute("aria-expanded", "false");
6487
+ this._ariaSource?.removeAttribute("aria-controls");
6488
+ const el = this._source?.getElement?.();
6489
+ this._ariaSource = el?.getAttribute("role") === "button" ? el : null;
6490
+ this._ariaSource?.setAttribute("aria-expanded", String(open));
6491
+ if (open) this._ariaSource?.setAttribute("aria-controls", this._container.id);
6492
+ }
6475
6493
  _initLayout() {
6476
6494
  const prefix = "maplair-popup", container = this._container = create("div", `${prefix} ${this.options.className || ""} maplair-zoom-animated`);
6495
+ container.id = `maplair-popup-${stamp(this)}`;
6477
6496
  const wrapper = this._wrapper = create("div", `${prefix}-content-wrapper`, container);
6478
6497
  this._contentNode = create("div", `${prefix}-content`, wrapper);
6479
6498
  disableClickPropagation(container);
@@ -6485,7 +6504,7 @@
6485
6504
  const closeButton = this._closeButton = create("button", `${prefix}-close-button`, container);
6486
6505
  closeButton.type = "button";
6487
6506
  closeButton.setAttribute("aria-label", I18n.translate("Close popup"));
6488
- closeButton.innerHTML = "<span aria-hidden=\"true\">&#215;</span>";
6507
+ closeButton.textContent = "×";
6489
6508
  on(closeButton, "click", (ev) => {
6490
6509
  ev.preventDefault();
6491
6510
  this.close();
@@ -6553,13 +6572,13 @@
6553
6572
  }
6554
6573
  };
6555
6574
  // src/layer/Tooltip.js
6556
- const directions = [
6557
- "top",
6558
- "bottom",
6559
- "center",
6560
- "right",
6561
- "left"
6562
- ];
6575
+ const directions = {
6576
+ top: [.5, 1],
6577
+ bottom: [.5, 0],
6578
+ center: [.5, .5],
6579
+ right: [0, .5],
6580
+ left: [1, .5]
6581
+ };
6563
6582
  const tipSize = 6;
6564
6583
  const autoPadding = 4;
6565
6584
  function shiftInto(start, size, min, max) {
@@ -6652,7 +6671,7 @@
6652
6671
  * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
6653
6672
  * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
6654
6673
  * it will receive the layer as the first argument and should return a
6655
- * `String` or `HTMLElement`.
6674
+ * `String`, `HTMLElement` or `DocumentFragment`.
6656
6675
  * @group Tooltip methods
6657
6676
  * @param {DivOverlayContent|Tooltip} content
6658
6677
  * @param {TooltipOptions} [options]
@@ -6663,7 +6682,7 @@
6663
6682
  if (this._tooltip) this.unbindTooltip();
6664
6683
  this._tooltip = this._initOverlay(Tooltip, old, content, options);
6665
6684
  this._initTooltipInteractions();
6666
- if (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) this.openTooltip();
6685
+ if (this._tooltip.options.permanent && this._map?.hasLayer(this)) this.openTooltip();
6667
6686
  return this;
6668
6687
  },
6669
6688
  /**
@@ -6705,11 +6724,7 @@
6705
6724
  openTooltip(latlng) {
6706
6725
  if (this._tooltip) {
6707
6726
  if (!(this instanceof FeatureGroup)) this._tooltip._source = this;
6708
- if (this._tooltip._prepareOpen(latlng)) {
6709
- this._tooltip.openOn(this._map);
6710
- if (this.getElement) this._setAriaDescribedByOnLayer(this);
6711
- else if (this.eachLayer) this.eachLayer(this._setAriaDescribedByOnLayer, this);
6712
- }
6727
+ if (this._tooltip._prepareOpen(latlng)) this._tooltip.openOn(this._map);
6713
6728
  }
6714
6729
  return this;
6715
6730
  },
@@ -6770,7 +6785,7 @@
6770
6785
  if (!remove) {
6771
6786
  el._maplair_focus_handler && off(el, "focus", el._maplair_focus_handler, this);
6772
6787
  el._maplair_focus_handler = () => {
6773
- if (this._tooltip) {
6788
+ if (this._tooltip && el.matches(":focus-visible")) {
6774
6789
  this._tooltip._source = layer;
6775
6790
  this.openTooltip();
6776
6791
  }
@@ -6781,9 +6796,6 @@
6781
6796
  if (remove) delete el._maplair_focus_handler;
6782
6797
  }
6783
6798
  },
6784
- _setAriaDescribedByOnLayer(layer) {
6785
- (typeof layer.getElement === "function" && layer.getElement())?.setAttribute?.("aria-describedby", this._tooltip._container.id);
6786
- },
6787
6799
  _openTooltip(e) {
6788
6800
  if (!this._tooltip || !this._map) return;
6789
6801
  if (this._map.dragging?.moving()) {
@@ -6800,13 +6812,7 @@
6800
6812
  this.openTooltip(this._tooltip.options.sticky ? e.latlng : void 0);
6801
6813
  },
6802
6814
  _moveTooltip(e) {
6803
- let latlng = e.latlng, containerPoint, layerPoint;
6804
- if (this._tooltip.options.sticky && e.originalEvent) {
6805
- containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
6806
- layerPoint = this._map.containerPointToLayerPoint(containerPoint);
6807
- latlng = this._map.layerPointToLatLng(layerPoint);
6808
- }
6809
- this._tooltip.setLatLng(latlng);
6815
+ this._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ? this._map.pointerEventToLatLng(e.originalEvent) : e.latlng);
6810
6816
  }
6811
6817
  };
6812
6818
  /** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */
@@ -6895,6 +6901,7 @@
6895
6901
  map.fire("tooltipopen", { tooltip: this });
6896
6902
  if (this._source) {
6897
6903
  this.addEventParent(this._source);
6904
+ this._source.getElement?.()?.setAttribute("aria-describedby", this._container.id);
6898
6905
  this._source.fire("tooltipopen", { tooltip: this }, true);
6899
6906
  }
6900
6907
  }
@@ -6923,7 +6930,7 @@
6923
6930
  const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-animated`;
6924
6931
  this._contentNode = this._container = create("div", className);
6925
6932
  this._container.setAttribute("role", "tooltip");
6926
- this._container.setAttribute("id", `maplair-tooltip-${stamp(this)}`);
6933
+ this._container.id = `maplair-tooltip-${stamp(this)}`;
6927
6934
  }
6928
6935
  _updateLayout() {}
6929
6936
  _adjustPan() {}
@@ -6938,21 +6945,16 @@
6938
6945
  _setPosition(pos) {
6939
6946
  let direction = this.options.direction, shift = new Point(0, 0);
6940
6947
  const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset), anchor = this._getAnchor();
6941
- if (!directions.includes(direction)) {
6948
+ if (!(direction in directions)) {
6942
6949
  ({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));
6943
6950
  if (direction === "left") {
6944
6951
  offset.x = -offset.x;
6945
6952
  anchor.x = -anchor.x;
6946
6953
  }
6947
6954
  }
6948
- let subX = tooltipWidth / 2, subY = tooltipHeight / 2;
6949
- if (direction === "top") subY = tooltipHeight;
6950
- else if (direction === "bottom") subY = 0;
6951
- else if (direction === "right") subX = 0;
6952
- else if (direction === "left") subX = tooltipWidth;
6953
- pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor).add(shift);
6954
- container.classList.remove("maplair-tooltip-right", "maplair-tooltip-left", "maplair-tooltip-top", "maplair-tooltip-bottom");
6955
- container.classList.add(`maplair-tooltip-${direction}`);
6955
+ const [fx, fy] = directions[direction];
6956
+ pos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);
6957
+ for (const d in directions) container.classList.toggle(`maplair-tooltip-${d}`, d === direction);
6956
6958
  const tipShift = direction === "top" || direction === "bottom" ? clampTip(-shift.x, tooltipWidth) : clampTip(-shift.y, tooltipHeight);
6957
6959
  if (tipShift) container.style.setProperty("--maplair-tooltip-tip-shift", `${tipShift}px`);
6958
6960
  else container.style.removeProperty("--maplair-tooltip-tip-shift");
@@ -7068,7 +7070,8 @@
7068
7070
  * @lends MaplairMapOptions
7069
7071
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
7070
7072
  * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
7071
- * instead.
7073
+ * instead. Paths in custom panes get their own renderer for that pane, of the same
7074
+ * class and with the same options as this one.
7072
7075
  */
7073
7076
  /**
7074
7077
  * Registers `getRenderer()` and related methods on the given map class, called by
@@ -7197,12 +7200,14 @@
7197
7200
  */
7198
7201
  addHooks() {
7199
7202
  on(this._map._container, "pointerdown", this._onPointerDown, this);
7203
+ this._map._container.classList.add("maplair-box-zoom");
7200
7204
  }
7201
7205
  /**
7202
7206
  * Called when the handler is disabled, removes the event hooks.
7203
7207
  */
7204
7208
  removeHooks() {
7205
7209
  off(this._map._container, "pointerdown", this._onPointerDown, this);
7210
+ this._map._container.classList.remove("maplair-box-zoom");
7206
7211
  }
7207
7212
  /**
7208
7213
  * Returns `true` if a box has been drawn by the current or last interaction.
@@ -7415,13 +7420,13 @@
7415
7420
  }
7416
7421
  _onDown(e) {
7417
7422
  this._moved = false;
7418
- if (this._element.classList.contains("maplair-zoom-anim")) return;
7419
7423
  const pointers = getPointers().length;
7420
7424
  if (pointers > 1) {
7421
7425
  if (Draggable._dragging === this) this.finishDrag();
7422
7426
  return;
7423
7427
  }
7424
- if (Draggable._dragging || e.shiftKey || e.button !== 0 && e.pointerType !== "touch") return;
7428
+ const boxZoom = e.shiftKey && this._element.closest(".maplair-container")?.classList.contains("maplair-box-zoom");
7429
+ if (Draggable._dragging || boxZoom || e.button !== 0 && e.pointerType !== "touch") return;
7425
7430
  Draggable._dragging = this;
7426
7431
  disableImageDrag();
7427
7432
  if (this._moving) return;
@@ -7479,10 +7484,8 @@
7479
7484
  finishDrag(noInertia) {
7480
7485
  this._draggingContainer?.classList.remove("maplair-dragging");
7481
7486
  this._draggingContainer = null;
7482
- if (this._lastTarget) {
7483
- this._lastTarget.classList.remove("maplair-drag-target");
7484
- this._lastTarget = null;
7485
- }
7487
+ this._lastTarget?.classList.remove("maplair-drag-target");
7488
+ this._lastTarget = null;
7486
7489
  off(this._dragStartTarget, "pointermove", this._onMove, this);
7487
7490
  off(this._dragStartTarget, "pointerup pointercancel lostpointercapture", this._onUp, this);
7488
7491
  enableImageDrag();
@@ -7741,7 +7744,7 @@
7741
7744
  const container = this._map._container;
7742
7745
  if (container.tabIndex <= 0) container.tabIndex = 0;
7743
7746
  const shortcuts = this._map.options.ariaKeyShortcuts;
7744
- if (shortcuts) container.ariaKeyShortcuts = shortcuts === true ? "ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -" : shortcuts;
7747
+ if (shortcuts) container.setAttribute("aria-keyshortcuts", shortcuts === true ? "ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -" : shortcuts);
7745
7748
  on(container, {
7746
7749
  focus: this._onFocus,
7747
7750
  blur: this._onBlur,
@@ -7797,7 +7800,7 @@
7797
7800
  return help;
7798
7801
  }
7799
7802
  _onPointerDown() {
7800
- if (this._focused) return;
7803
+ if (this._focused || this._map._container.contains(document.activeElement)) return;
7801
7804
  this._map._container.focus({
7802
7805
  preventScroll: true,
7803
7806
  focusVisible: false
@@ -7815,11 +7818,9 @@
7815
7818
  }
7816
7819
  _onContainerKeyDown(e) {
7817
7820
  const map = this._map, popup = map._popup;
7818
- if (e.key !== "Escape" || e.defaultPrevented || !popup?.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
7819
- const inPopup = popup._container.contains(e.target), icon = popup._source?._icon;
7821
+ if (e.key !== "Escape" || e.defaultPrevented || !popup?.isOpen() || !popup.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
7820
7822
  map.closePopup();
7821
7823
  e.preventDefault();
7822
- if (inPopup) (icon?.tabIndex >= 0 ? icon : map._container).focus();
7823
7824
  }
7824
7825
  _onKeyDown(e) {
7825
7826
  if (e.altKey || e.ctrlKey || e.metaKey) return;
@@ -7924,8 +7925,8 @@
7924
7925
  this._moved = false;
7925
7926
  this._zooming = true;
7926
7927
  map._stop();
7927
- on(this._map._container, "pointermove", this._onPointerMove, this);
7928
- on(this._map._container, "pointerup pointercancel", this._onPointerEnd, this);
7928
+ on(map._container, "pointermove", this._onPointerMove, this);
7929
+ on(map._container, "pointerup pointercancel", this._onPointerEnd, this);
7929
7930
  e.preventDefault();
7930
7931
  }
7931
7932
  _onPointerMove(e) {
@@ -7948,10 +7949,7 @@
7948
7949
  this._moved = true;
7949
7950
  }
7950
7951
  cancelAnimationFrame(this._animRequest);
7951
- const moveFn = map._move.bind(map, this._center, this._zoom, {
7952
- pinch: true,
7953
- round: false
7954
- }, void 0);
7952
+ const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
7955
7953
  this._animRequest = requestAnimationFrame(moveFn.bind(this));
7956
7954
  e.preventDefault();
7957
7955
  }
@@ -8104,10 +8102,7 @@
8104
8102
  const frame = () => {
8105
8103
  const pinch = this._pinch, delta = pinch.zoom - pinch.shown;
8106
8104
  pinch.shown = eased && Math.abs(delta) > .01 ? pinch.shown + delta * .3 : pinch.zoom;
8107
- map._move(this._getPinchCenter(pinch.shown), pinch.shown, {
8108
- pinch: true,
8109
- round: false
8110
- });
8105
+ map._move(this._getPinchCenter(pinch.shown), pinch.shown, { pinch: true });
8111
8106
  if (pinch.shown !== pinch.zoom) this._pinchFrame = requestAnimationFrame(frame);
8112
8107
  };
8113
8108
  cancelAnimationFrame(this._pinchFrame);
@@ -8171,9 +8166,9 @@
8171
8166
  stop(e);
8172
8167
  }
8173
8168
  _performZoom() {
8174
- const map = this._map, zoom = map.getZoom(), snap = this._map.options.zoomSnap ?? 0;
8169
+ const map = this._map, zoom = map.getZoom(), snap = map.options.zoomSnap ?? 0;
8175
8170
  map._stop();
8176
- 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;
8171
+ 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;
8177
8172
  this._delta = 0;
8178
8173
  this._startTime = null;
8179
8174
  if (!delta || map._zoomInputBlocked()) return;
@@ -8238,47 +8233,35 @@
8238
8233
  removeHooks() {
8239
8234
  off(this._map._container, "pointerdown", this._onDown, this);
8240
8235
  this._cancel();
8241
- this._cancelClickPrevent();
8242
8236
  this._stopPreventingNative();
8243
8237
  }
8244
8238
  _onDown(e) {
8245
8239
  clearTimeout(this._holdTimeout);
8246
8240
  if (getPointers().length !== 1 || e.pointerType === "mouse") return;
8247
- const el = this._map._container;
8248
- this._startPos = this._newPos = new Point(e.clientX, e.clientY);
8241
+ const el = this._map._container, start = new Point(e.clientX, e.clientY);
8249
8242
  this._holdTimeout = setTimeout((() => {
8250
8243
  this._cancel();
8251
- if (!this._isTapValid()) return;
8252
- on(el, "pointerup", preventDefault);
8253
- on(el, "pointerup pointercancel", this._cancelClickPrevent, this);
8244
+ const pointers = getPointers(), p = pointers[0];
8245
+ if (pointers.length !== 1 || start.distanceTo([p.clientX, p.clientY]) > this._map.options.tapTolerance) return;
8254
8246
  this._simulateEvent("contextmenu", e);
8255
8247
  el.addEventListener("contextmenu", stop, true);
8248
+ el.addEventListener("click", stop, true);
8256
8249
  el.addEventListener("pointerdown", this._stopPreventingNative, true);
8250
+ el.addEventListener("keydown", this._stopPreventingNative, true);
8257
8251
  }), tapHoldDelay);
8258
8252
  on(el, "pointerup pointercancel contextmenu", this._cancel, this);
8259
- on(el, "pointermove", this._onMove, this);
8260
- }
8261
- _cancelClickPrevent() {
8262
- const el = this._map._container;
8263
- off(el, "pointerup", preventDefault);
8264
- off(el, "pointerup pointercancel", this._cancelClickPrevent, this);
8265
8253
  }
8266
8254
  _stopPreventingNative = () => {
8267
8255
  const el = this._map._container;
8268
8256
  el.removeEventListener("contextmenu", stop, true);
8257
+ el.removeEventListener("click", stop, true);
8269
8258
  el.removeEventListener("pointerdown", this._stopPreventingNative, true);
8259
+ el.removeEventListener("keydown", this._stopPreventingNative, true);
8270
8260
  };
8271
8261
  _cancel() {
8272
8262
  clearTimeout(this._holdTimeout);
8273
8263
  const el = this._map._container;
8274
8264
  off(el, "pointerup pointercancel contextmenu", this._cancel, this);
8275
- off(el, "pointermove", this._onMove, this);
8276
- }
8277
- _onMove(e) {
8278
- this._newPos = new Point(e.clientX, e.clientY);
8279
- }
8280
- _isTapValid() {
8281
- return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
8282
8265
  }
8283
8266
  _simulateEvent(type, e) {
8284
8267
  const simulatedEvent = new MouseEvent(type, {
@@ -8419,10 +8402,7 @@
8419
8402
  this._moved = true;
8420
8403
  }
8421
8404
  cancelAnimationFrame(this._animRequest);
8422
- this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, {
8423
- pinch: true,
8424
- round: false
8425
- }));
8405
+ this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, { pinch: true }));
8426
8406
  e.preventDefault();
8427
8407
  }
8428
8408
  _onUp() {
@@ -8478,7 +8458,9 @@
8478
8458
  * user tries to pan outside the view. To set the restriction dynamically, use
8479
8459
  * [`setMaxBounds`](#map-setmaxbounds) method.
8480
8460
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
8481
- * map. `SVG` or `Canvas` by default depending on browser support.
8461
+ * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
8462
+ * instead. Paths in custom panes get their own renderer for that pane, of the same
8463
+ * class and with the same options as this one.
8482
8464
  * @property {boolean} [zoomAnimation=true] Whether the map zoom animation is enabled.
8483
8465
  * @property {number} [zoomAnimationThreshold=4] Won't animate zoom if the zoom
8484
8466
  * difference exceeds this value (or 1 if the user prefers
@@ -8562,15 +8544,25 @@
8562
8544
  /**
8563
8545
  * Options of the `MaplairMap` methods which modify the zoom level and the center.
8564
8546
  * @typedef {object} ZoomPanOptions
8547
+ * @property {boolean} [animate] Whether to animate the change: like `ZoomOptions.animate`
8548
+ * if the zoom level changes, and like `PanOptions.animate` otherwise. The `zoom` and
8549
+ * `pan` options can set it for each case separately.
8550
+ * @property {boolean} [reset] If `true`, the view is reset without animation.
8551
+ * @property {ZoomOptions} [zoom] Options for the zoom part of the change, taking
8552
+ * precedence over `animate`.
8553
+ * @property {PanOptions} [pan] Options for the pan part of the change, taking
8554
+ * precedence over `animate`.
8565
8555
  * @extends ZoomOptions, PanOptions
8566
8556
  */
8567
8557
  /**
8568
8558
  * Options of `MaplairMap.invalidateSize()`.
8569
8559
  * @typedef {object} InvalidateSizeOptions
8560
+ * @property {boolean} [animate=false] If `true`, the map pans to its new center with
8561
+ * animation.
8570
8562
  * @property {boolean} [pan=true] If `false`, panning will not occur.
8571
8563
  * @property {boolean} [debounceMoveend=false] If `true`, it will delay `moveend` event
8572
8564
  * so that it doesn't happen often even if the method is called many times in a row.
8573
- * @extends ZoomPanOptions
8565
+ * @extends PanOptions
8574
8566
  */
8575
8567
  /**
8576
8568
  * Padding options of `MaplairMap` methods, e.g. `panInside()`.
@@ -8618,7 +8610,9 @@
8618
8610
  * pressing a key or clicking a zoom button) have an `originalEvent` property with the
8619
8611
  * DOM event that started the change. It is `undefined` for changes made by code (e.g.
8620
8612
  * `setView()`), which allows to tell them apart, e.g. to avoid feedback loops when
8621
- * synchronizing the view.
8613
+ * synchronizing the view. The `move` and `zoom` events also have `flyTo: true` on each
8614
+ * [`flyTo`](#map-flyto) animation frame, and `pinch: true` while the user pinch-zooms
8615
+ * the map.
8622
8616
  *
8623
8617
  * @example
8624
8618
  * ```js
@@ -8718,6 +8712,7 @@
8718
8712
  this._handlers = [];
8719
8713
  this._layers = {};
8720
8714
  this._zoomBoundLayers = {};
8715
+ this._canvases = [];
8721
8716
  this._sizeChanged = true;
8722
8717
  this._initContainer(id);
8723
8718
  this._initLayout();
@@ -8748,10 +8743,23 @@
8748
8743
  * @returns {this}
8749
8744
  */
8750
8745
  setView(center, zoom, options) {
8751
- zoom = zoom === void 0 ? this._zoom : this._limitZoom(zoom);
8746
+ zoom = zoom === void 0 ? this._targetZoom() : this._limitZoom(zoom);
8747
+ const targetCenter = center;
8752
8748
  center = this._limitCenter(new LatLng(center), zoom, this.options.maxBounds);
8753
8749
  options ??= {};
8754
8750
  this._stop();
8751
+ this._targetView = {
8752
+ center: targetCenter,
8753
+ zoom
8754
+ };
8755
+ if (this._animatingZoom) {
8756
+ this._pendingView = {
8757
+ center,
8758
+ zoom,
8759
+ options
8760
+ };
8761
+ return this;
8762
+ }
8755
8763
  if (this._loaded && !options.reset && options !== true) {
8756
8764
  if (options.animate !== void 0) {
8757
8765
  options.zoom = {
@@ -8764,12 +8772,12 @@
8764
8772
  ...options.pan
8765
8773
  };
8766
8774
  }
8767
- if (this._zoom !== zoom ? this._tryAnimatedZoom && this._tryAnimatedZoom(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan)) {
8775
+ if (this._zoom !== zoom ? this._tryAnimatedZoom?.(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan)) {
8768
8776
  clearTimeout(this._sizeTimer);
8769
8777
  return this;
8770
8778
  }
8771
8779
  }
8772
- this._resetView(center, zoom, options.pan?.noMoveStart);
8780
+ this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, zoom, options.pan?.noMoveStart);
8773
8781
  return this;
8774
8782
  }
8775
8783
  /**
@@ -8784,7 +8792,7 @@
8784
8792
  this._zoom = zoom;
8785
8793
  return this;
8786
8794
  }
8787
- return this.setView(this.getCenter(), zoom, { zoom: options });
8795
+ return this.setView(this._targetView?.center ?? this.getCenter(), zoom, { zoom: options });
8788
8796
  }
8789
8797
  /**
8790
8798
  * Increases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
@@ -8795,7 +8803,7 @@
8795
8803
  */
8796
8804
  zoomIn(delta, options) {
8797
8805
  delta ??= this.options.zoomDelta;
8798
- return this.setZoom(this._zoom + delta, options);
8806
+ return this.setZoom(this._targetZoom() + delta, options);
8799
8807
  }
8800
8808
  /**
8801
8809
  * Decreases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
@@ -8806,7 +8814,7 @@
8806
8814
  */
8807
8815
  zoomOut(delta, options) {
8808
8816
  delta ??= this.options.zoomDelta;
8809
- return this.setZoom(this._zoom - delta, options);
8817
+ return this.setZoom(this._targetZoom() - delta, options);
8810
8818
  }
8811
8819
  /**
8812
8820
  * Zooms the map while keeping a specified geographical point on the map
@@ -8828,7 +8836,7 @@
8828
8836
  bounds = bounds.getBounds ? bounds.getBounds() : LatLngBounds.from(bounds);
8829
8837
  const paddingTL = Point.from(options.paddingTopLeft || options.padding || [0, 0]), paddingBR = Point.from(options.paddingBottomRight || options.padding || [0, 0]);
8830
8838
  let zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR));
8831
- zoom = typeof options.maxZoom === "number" ? Math.min(options.maxZoom, zoom) : zoom;
8839
+ zoom = Math.min(options.maxZoom ?? Infinity, zoom);
8832
8840
  if (zoom === Infinity) return {
8833
8841
  center: bounds.getCenter(),
8834
8842
  zoom
@@ -8871,7 +8879,7 @@
8871
8879
  * @returns {this}
8872
8880
  */
8873
8881
  panTo(center, options) {
8874
- return this.setView(center, this._zoom, { pan: options });
8882
+ return this.setView(center, void 0, { pan: options });
8875
8883
  }
8876
8884
  /**
8877
8885
  * Pans the map by a given number of pixels (animated unless `animate: false` is passed,
@@ -8883,24 +8891,18 @@
8883
8891
  * @returns {this}
8884
8892
  */
8885
8893
  panBy(offset, options) {
8886
- offset = Point.from(offset).round();
8894
+ const { center = this.getCenter(), zoom = this._zoom } = this._targetView ?? {}, newCenter = this.unproject(this.project(center, zoom).add(Point.from(offset).round()), zoom);
8895
+ return this.setView(newCenter, zoom, { pan: options });
8896
+ }
8897
+ _panBy(offset, options) {
8887
8898
  options ??= {};
8888
- if (!offset.x && !offset.y) return this.fire("moveend");
8889
- const size = this.getSize();
8890
- if (options.animate !== true && !size.contains(offset)) {
8891
- const center = this.unproject(this.project(this.getCenter()).add(offset));
8892
- this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, this.getZoom());
8893
- return this;
8894
- }
8895
- if (!this._panAnim) {
8896
- this._panAnim = new PosAnimation();
8897
- this._panAnim.on({
8898
- "step": this._onPanTransitionStep,
8899
- "end": this._onPanTransitionEnd
8900
- }, this);
8901
- }
8899
+ if (!offset.x && !offset.y) return this._moveStart(false, true)._moveEnd(false);
8900
+ if (!this._panAnim) this._panAnim = new PosAnimation().on({
8901
+ step: this._onPanTransitionStep,
8902
+ end: this._onPanTransitionEnd
8903
+ }, this);
8902
8904
  if (!options.noMoveStart) this.fire("movestart");
8903
- const tooFarForReducedMotion = this._prefersReducedMotion() && !size.divideBy(2).contains(offset);
8905
+ const tooFarForReducedMotion = this._prefersReducedMotion() && !this.getSize().divideBy(2).contains(offset);
8904
8906
  if (options.animate === true || options.animate !== false && !tooFarForReducedMotion) {
8905
8907
  this._mapPane.classList.add("maplair-pan-anim");
8906
8908
  const newPos = this._getMapPanePos().subtract(offset).round();
@@ -8908,7 +8910,7 @@
8908
8910
  } else {
8909
8911
  this._rawPanBy(offset);
8910
8912
  this._wrapWorldCopy();
8911
- this.fire("move").fire("moveend");
8913
+ this.fire("move")._moveEnd(false);
8912
8914
  }
8913
8915
  return this;
8914
8916
  }
@@ -8932,9 +8934,14 @@
8932
8934
  }
8933
8935
  });
8934
8936
  if (options.animate !== true && this._prefersReducedMotion()) return this.setView(targetCenter, targetZoom, options);
8935
- this._stop();
8936
- targetZoom = targetZoom === void 0 ? this._zoom : this._limitZoom(targetZoom);
8937
+ targetZoom = targetZoom === void 0 ? this._targetZoom() : this._limitZoom(targetZoom);
8938
+ const requestedCenter = targetCenter;
8937
8939
  targetCenter = this._limitCenter(new LatLng(targetCenter), targetZoom, this.options.maxBounds);
8940
+ this._stop();
8941
+ this._targetView = {
8942
+ center: requestedCenter,
8943
+ zoom: targetZoom
8944
+ };
8938
8945
  const from = this.project(this.getCenter()), to = this.project(targetCenter), size = this.getSize(), startZoom = this._zoom;
8939
8946
  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;
8940
8947
  function r(i) {
@@ -8948,7 +8955,7 @@
8948
8955
  function easeOut(t) {
8949
8956
  return 1 - (1 - t) ** 1.5;
8950
8957
  }
8951
- const start = Date.now(), S = (r(1) - r0) / rho, duration = options.duration ? 1e3 * options.duration : 1e3 * S * .8;
8958
+ const start = Date.now(), S = (r(1) - r0) / rho, duration = 1e3 * (options.duration || S * .8);
8952
8959
  const frame = () => {
8953
8960
  const t = (Date.now() - start) / duration, s = easeOut(t) * S;
8954
8961
  if (t <= 1) {
@@ -9100,8 +9107,8 @@
9100
9107
  }
9101
9108
  /**
9102
9109
  * Checks if the map container size changed and updates the map if so —
9103
- * call it after you've changed the map size dynamically, also animating
9104
- * pan by default. If `options.pan` is `false`, panning will not occur.
9110
+ * call it after you've changed the map size dynamically, also panning to
9111
+ * keep the center by default. If `options.pan` is `false`, panning will not occur.
9105
9112
  * If `options.debounceMoveend` is `true`, it will delay `moveend` event so
9106
9113
  * that it doesn't happen often even if the method is called many
9107
9114
  * times in a row. Passing `true` instead of options animates the panning.
@@ -9118,8 +9125,9 @@
9118
9125
  };
9119
9126
  const oldSize = this.getSize();
9120
9127
  this._sizeChanged = true;
9121
- this._lastCenter = null;
9122
- const newSize = this.getSize(), oldCenter = oldSize.divideBy(2).round(), newCenter = newSize.divideBy(2).round(), offset = oldCenter.subtract(newCenter);
9128
+ const newSize = this.getSize();
9129
+ if (!newSize.equals(oldSize)) this._lastCenter = null;
9130
+ const oldCenter = oldSize.divideBy(2).round(), newCenter = newSize.divideBy(2).round(), offset = oldCenter.subtract(newCenter);
9123
9131
  if (!offset.x && !offset.y) return this;
9124
9132
  if (options.animate && options.pan) this.panBy(offset);
9125
9133
  else {
@@ -9201,7 +9209,7 @@
9201
9209
  }
9202
9210
  _handleGeolocationResponse(pos) {
9203
9211
  if (!this._container._maplair_id) return;
9204
- const lat = pos.coords.latitude, lng = pos.coords.longitude, latlng = new LatLng(lat, lng), bounds = latlng.toBounds(pos.coords.accuracy * 2), options = this._locateOptions;
9212
+ const latlng = new LatLng(pos.coords.latitude, pos.coords.longitude), bounds = latlng.toBounds(pos.coords.accuracy * 2), options = this._locateOptions;
9205
9213
  if (options.setView) {
9206
9214
  const zoom = this.getBoundsZoom(bounds);
9207
9215
  this.setView(latlng, options.maxZoom ? Math.min(zoom, options.maxZoom) : zoom);
@@ -9235,7 +9243,7 @@
9235
9243
  */
9236
9244
  remove() {
9237
9245
  this._initEvents(true);
9238
- if (this.options.maxBounds) this.off("moveend", this._panInsideMaxBounds);
9246
+ this.off("moveend", this._panInsideMaxBounds);
9239
9247
  if (this._containerId !== this._container._maplair_id) throw new Error("Map container is being reused by another instance");
9240
9248
  delete this._container._maplair_id;
9241
9249
  delete this._containerId;
@@ -9334,7 +9342,7 @@
9334
9342
  bounds = LatLngBounds.from(bounds);
9335
9343
  padding = Point.from(padding ?? [0, 0]);
9336
9344
  let zoom = this.getZoom() ?? 0;
9337
- 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);
9345
+ 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);
9338
9346
  zoom = this.getScaleZoom(scale, zoom);
9339
9347
  if (snap) {
9340
9348
  zoom = Math.round(zoom / (snap / 100)) * (snap / 100);
@@ -9744,10 +9752,13 @@
9744
9752
  return this;
9745
9753
  }
9746
9754
  _moveEnd(zoomChanged) {
9755
+ if (!this._pendingView) this._targetView = null;
9747
9756
  if (zoomChanged) this.fire("zoomend");
9748
9757
  return this.fire("moveend");
9749
9758
  }
9750
9759
  _stop() {
9760
+ this._pendingView = null;
9761
+ this._targetView = null;
9751
9762
  cancelAnimationFrame(this._flyToFrame);
9752
9763
  cancelAnimationFrame(this._zoomAnimFrame);
9753
9764
  this._panAnim?.stop();
@@ -9804,13 +9815,14 @@
9804
9815
  _findEventTargets(e, type) {
9805
9816
  let targets = [], target, src = e.target, dragging = false;
9806
9817
  const isHover = type === "pointerout" || type === "pointerover";
9818
+ const canEndDrag = (type === "click" || type === "preclick") && e.detail > 0;
9807
9819
  while (src) {
9808
9820
  target = this._targets[stamp(src)];
9809
- if (target && (type === "click" || type === "preclick") && this._draggableMoved(target)) {
9821
+ if (target && canEndDrag && this._draggableMoved(target)) {
9810
9822
  dragging = true;
9811
9823
  break;
9812
9824
  }
9813
- if (target && target.listens(type, true)) {
9825
+ if (target?.listens(type, true)) {
9814
9826
  if (isHover && !isExternalTarget(src, e)) break;
9815
9827
  targets.push(target);
9816
9828
  if (isHover) break;
@@ -9829,8 +9841,23 @@
9829
9841
  }
9830
9842
  _handleDOMEvent(e) {
9831
9843
  const el = e.target;
9832
- if (!this._loaded || el["_maplair_disable_events"] || e.type === "click" && this._isClickDisabled(el)) return;
9833
- this._fireDOMEvent(e, e.type);
9844
+ if (e.type === "click") simulateDblclick(e, this._container);
9845
+ if (!this._loaded || e.type === "click" && this._isClickDisabled(el)) return;
9846
+ 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);
9847
+ if (layer !== hovered && (move && !skip || leftMap)) {
9848
+ if (hovered) this._fireDOMEvent(e, "pointerout", [hovered]);
9849
+ this._container.classList.toggle("maplair-interactive", !!layer);
9850
+ this._hoveredCanvasLayer = layer;
9851
+ if (layer) this._fireDOMEvent(e, "pointerover", [layer]);
9852
+ }
9853
+ this._fireDOMEvent(e, type, layer && [layer]);
9854
+ }
9855
+ _canvasLayerAt(e, click) {
9856
+ for (let el = e.target; el !== this._container; el = el.parentNode) if (!el || el === this._controlContainer || this._targets[stamp(el)]) return;
9857
+ for (const renderer of this._canvases) {
9858
+ const layer = renderer._layerAt(e, click);
9859
+ if (layer) return layer;
9860
+ }
9834
9861
  }
9835
9862
  static _pointerEvents = [
9836
9863
  "click",
@@ -9841,7 +9868,7 @@
9841
9868
  ];
9842
9869
  _fireDOMEvent(e, type, canvasTargets) {
9843
9870
  if (type === "click") this._fireDOMEvent(e, "preclick", canvasTargets);
9844
- let targets = this._findEventTargets(e, type);
9871
+ let targets = canvasTargets && (type === "pointerover" || type === "pointerout") ? [] : this._findEventTargets(e, type);
9845
9872
  if (canvasTargets) targets = [...canvasTargets.filter((t) => t.listens(type, true)), ...targets];
9846
9873
  if (!targets.length) return;
9847
9874
  if (type === "contextmenu") e.preventDefault();
@@ -9929,17 +9956,17 @@
9929
9956
  _onPanTransitionEnd() {
9930
9957
  this._mapPane.classList.remove("maplair-pan-anim");
9931
9958
  this._wrapWorldCopy();
9932
- this.fire("moveend");
9959
+ this._moveEnd(false);
9933
9960
  }
9934
9961
  _tryAnimatedPan(center, options) {
9935
- const offset = this._getCenterOffset(center)._trunc();
9962
+ const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
9936
9963
  if (options?.animate !== true && !this.getSize().contains(offset)) return false;
9937
- this.panBy(offset, options);
9964
+ this._panBy(offset, options);
9938
9965
  return true;
9939
9966
  }
9940
9967
  _createAnimProxy() {
9941
9968
  this._proxy = create("div", "maplair-proxy maplair-zoom-animated");
9942
- this._panes.mapPane.appendChild(this._proxy);
9969
+ this._panes.mapPane.append(this._proxy);
9943
9970
  this.on("zoomanim", this._animateProxyZoom, this);
9944
9971
  this.on("load moveend", this._animMoveEnd, this);
9945
9972
  on(this._proxy, "transitionend", this._catchTransitionEnd, this);
@@ -9973,6 +10000,9 @@
9973
10000
  };
9974
10001
  this._flyToFrame = requestAnimationFrame(frame);
9975
10002
  }
10003
+ _targetZoom() {
10004
+ return this._targetView?.zoom ?? this._zoom;
10005
+ }
9976
10006
  _zoomInputBlocked() {
9977
10007
  return this._animatingZoom || Date.now() < this._instantZoomEnd;
9978
10008
  }
@@ -10016,11 +10046,16 @@
10016
10046
  if (!this._animatingZoom) return;
10017
10047
  this._mapPane?.classList.remove("maplair-zoom-anim");
10018
10048
  this._animatingZoom = false;
10019
- this._move(this._animateToCenter, this._animateToZoom, void 0, true);
10049
+ this._move(this.getCenter(), this._animateToZoom, void 0, true);
10020
10050
  if (this._tempFireZoomEvent) this.fire("zoom");
10021
10051
  delete this._tempFireZoomEvent;
10022
10052
  this.fire("move");
10023
10053
  this._moveEnd(true);
10054
+ const view = this._pendingView;
10055
+ if (view) {
10056
+ this._pendingView = null;
10057
+ this.setView(view.center, view.zoom, view.options);
10058
+ }
10024
10059
  }
10025
10060
  };
10026
10061
  for (const feature of [
@@ -10140,9 +10175,9 @@
10140
10175
  closestLayerPoint(p) {
10141
10176
  p = Point.from(p);
10142
10177
  let minDistance = Infinity, minPoint = null, p1, p2;
10143
- const closest = _sqClosestPointOnSegment;
10144
- for (const points of this._parts) for (let i = 1, len = points.length; i < len; i++) {
10145
- p1 = points[i - 1];
10178
+ const closest = _sqClosestPointOnSegment, closed = this._isClosed();
10179
+ for (const points of this._parts) for (let i = closed ? 0 : 1, len = points.length; i < len; i++) {
10180
+ p1 = points[(i || len) - 1];
10146
10181
  p2 = points[i];
10147
10182
  const sqDist = closest(p, p1, p2, true);
10148
10183
  if (sqDist < minDistance) {
@@ -10215,7 +10250,7 @@
10215
10250
  }
10216
10251
  _projectLatlngs(latlngs, result, projectedBounds) {
10217
10252
  if (latlngs[0] instanceof LatLng) {
10218
- const ring = latlngs.map((latlng) => this._map.latLngToLayerPoint(latlng));
10253
+ const ring = latlngs.map((latlng) => this._renderer._latLngToLayerPoint(latlng));
10219
10254
  ring.forEach((r) => projectedBounds.extend(r));
10220
10255
  result.push(ring);
10221
10256
  } else latlngs.forEach((latlng) => this._projectLatlngs(latlng, result, projectedBounds));
@@ -10223,24 +10258,21 @@
10223
10258
  _clipPoints() {
10224
10259
  const bounds = this._renderer._bounds;
10225
10260
  this._parts = [];
10226
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
10261
+ if (!this._pxBounds?.intersects(bounds)) return;
10227
10262
  if (this.options.noClip) {
10228
10263
  this._parts = this._rings;
10229
10264
  return;
10230
10265
  }
10231
10266
  const parts = this._parts;
10232
- let i, j, k, len, len2, segment, points;
10233
- for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
10234
- points = this._rings[i];
10235
- for (j = 0, len2 = points.length; j < len2 - 1; j++) {
10236
- segment = clipSegment(points[j], points[j + 1], bounds, j);
10237
- if (!segment) continue;
10238
- parts[k] ??= [];
10239
- parts[k].push(segment[0]);
10240
- if (segment[1] !== points[j + 1] || j === len2 - 2) {
10241
- parts[k].push(segment[1]);
10242
- k++;
10243
- }
10267
+ let k = 0;
10268
+ for (const points of this._rings) for (let j = 0, len = points.length; j < len - 1; j++) {
10269
+ const segment = clipSegment(points[j], points[j + 1], bounds, j);
10270
+ if (!segment) continue;
10271
+ parts[k] ??= [];
10272
+ parts[k].push(segment[0]);
10273
+ if (segment[1] !== points[j + 1] || j === len - 2) {
10274
+ parts[k].push(segment[1]);
10275
+ k++;
10244
10276
  }
10245
10277
  }
10246
10278
  }
@@ -10257,17 +10289,13 @@
10257
10289
  _updatePath() {
10258
10290
  this._renderer._updatePoly(this);
10259
10291
  }
10292
+ _isClosed() {
10293
+ return false;
10294
+ }
10260
10295
  _containsPoint(p, closed) {
10261
- let i, j, k, len, len2, part;
10262
10296
  const w = this._clickTolerance();
10263
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
10264
- for (i = 0, len = this._parts.length; i < len; i++) {
10265
- part = this._parts[i];
10266
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
10267
- if (!closed && j === 0) continue;
10268
- if (pointToSegmentDistance(p, part[k], part[j]) <= w) return true;
10269
- }
10270
- }
10297
+ if (!this._pxBounds?.contains(p)) return false;
10298
+ 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;
10271
10299
  return false;
10272
10300
  }
10273
10301
  /**
@@ -10464,10 +10492,10 @@
10464
10492
  }
10465
10493
  _clipPoints() {
10466
10494
  let bounds = this._renderer._bounds;
10467
- const w = this.options.weight, p = new Point(w, w);
10495
+ const w = +this.options.weight || 0, p = new Point(w, w);
10468
10496
  bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
10469
10497
  this._parts = [];
10470
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
10498
+ if (!this._pxBounds?.intersects(bounds)) return;
10471
10499
  if (this.options.noClip) {
10472
10500
  this._parts = this._rings;
10473
10501
  return;
@@ -10480,16 +10508,15 @@
10480
10508
  _updatePath() {
10481
10509
  this._renderer._updatePoly(this, true);
10482
10510
  }
10511
+ _isClosed() {
10512
+ return true;
10513
+ }
10483
10514
  _containsPoint(p) {
10484
- let inside = false, part, p1, p2, i, j, k, len, len2;
10485
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
10486
- for (i = 0, len = this._parts.length; i < len; i++) {
10487
- part = this._parts[i];
10488
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
10489
- p1 = part[j];
10490
- p2 = part[k];
10491
- 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;
10492
- }
10515
+ let inside = false;
10516
+ if (!this._pxBounds?.contains(p)) return false;
10517
+ for (const part of this._parts) for (let j = 0, len = part.length, k = len - 1; j < len; k = j++) {
10518
+ const p1 = part[j], p2 = part[k];
10519
+ 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;
10493
10520
  }
10494
10521
  return inside || super._containsPoint(p, true);
10495
10522
  }
@@ -10732,16 +10759,15 @@
10732
10759
  onAdd(map) {
10733
10760
  const className = "maplair-control-scale", container = create("div", className), options = this.options;
10734
10761
  this._addScales(options, `${className}-line`, container);
10735
- map.on(options.updateWhenIdle ? "moveend" : "move", this._update, this);
10736
10762
  map.whenReady(this._update, this);
10737
10763
  return container;
10738
10764
  }
10739
10765
  /**
10740
10766
  * @internal
10741
- * @param {MaplairMap} map
10767
+ * @returns {Record<string, Function>}
10742
10768
  */
10743
- onRemove(map) {
10744
- map.off(this.options.updateWhenIdle ? "moveend" : "move", this._update, this);
10769
+ getEvents() {
10770
+ return { [this.options.updateWhenIdle ? "moveend" : "move"]: this._update };
10745
10771
  }
10746
10772
  _addScales(options, className, container) {
10747
10773
  if (options.metric) this._mScale = create("div", className, container);
@@ -10774,7 +10800,7 @@
10774
10800
  }
10775
10801
  _updateScale(scale, text, ratio) {
10776
10802
  scale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;
10777
- scale.innerHTML = text;
10803
+ scale.textContent = text;
10778
10804
  }
10779
10805
  _getRoundNum(num) {
10780
10806
  const pow10 = 10 ** (`${Math.floor(num)}`.length - 1);
@@ -10881,25 +10907,26 @@
10881
10907
  const img = this._createImg(src, oldIcon instanceof HTMLImageElement ? oldIcon : null);
10882
10908
  this._setIconStyles(img, name);
10883
10909
  if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
10910
+ else img.crossOrigin = null;
10884
10911
  return img;
10885
10912
  }
10886
10913
  _setIconStyles(img, name) {
10887
10914
  const options = this.options;
10888
- let sizeOption = options[`${name}Size`];
10889
- if (typeof sizeOption === "number") sizeOption = [sizeOption, sizeOption];
10890
- const size = Point.validate(sizeOption) && Point.from(sizeOption);
10891
- const anchorPosition = name === "shadow" && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
10892
- const anchor = Point.validate(anchorPosition) && Point.from(anchorPosition);
10915
+ const sizeOption = options[`${name}Size`];
10916
+ const [width, height] = (typeof sizeOption === "number" ? [sizeOption, sizeOption] : Array.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);
10917
+ const anchorOption = name === "shadow" && options.shadowAnchor || options.iconAnchor;
10918
+ const anchor = Point.validate(anchorOption) ? Point.from(anchorOption) : {
10919
+ x: Math.round(width / 2),
10920
+ y: Math.round(height / 2)
10921
+ };
10893
10922
  img.className = `maplair-marker-${name} ${options.className || ""}`;
10894
- if (anchor) {
10895
- img.style.marginLeft = `${-anchor.x}px`;
10896
- img.style.marginTop = `${-anchor.y}px`;
10897
- }
10898
- img.style.transformOrigin = anchor ? `${anchor.x}px ${anchor.y}px` : "0 0";
10899
- if (size) {
10900
- img.style.width = `${size.x}px`;
10901
- img.style.height = `${size.y}px`;
10902
- }
10923
+ const { style } = img;
10924
+ style.marginLeft = style.marginTop = style.width = style.height = "";
10925
+ if (!isNaN(anchor.x)) style.marginLeft = `${-anchor.x}px`;
10926
+ if (!isNaN(anchor.y)) style.marginTop = `${-anchor.y}px`;
10927
+ style.transformOrigin = !isNaN(anchor.x) && !isNaN(anchor.y) ? `${anchor.x}px ${anchor.y}px` : "0 0";
10928
+ if (!isNaN(width)) style.width = `${width}px`;
10929
+ if (!isNaN(height)) style.height = `${height}px`;
10903
10930
  }
10904
10931
  _createImg(src, el) {
10905
10932
  el ??= document.createElement("img");
@@ -11047,10 +11074,10 @@
11047
11074
  return this._draggable?._moved;
11048
11075
  }
11049
11076
  _adjustPan(e) {
11050
- 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();
11051
- const panBounds = new Bounds(bounds.min._subtract(origin).add(padding), bounds.max._subtract(origin).subtract(padding));
11052
- if (!panBounds.contains(iconPos)) {
11053
- 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);
11077
+ 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);
11078
+ if (dx || dy) {
11079
+ const movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed), map.options.maxBounds)._round();
11080
+ if (!movement.x && !movement.y) return;
11054
11081
  map.panBy(movement, { animate: false });
11055
11082
  this._draggable._newPos._add(movement);
11056
11083
  this._draggable._startPos._add(movement);
@@ -11071,7 +11098,8 @@
11071
11098
  }
11072
11099
  }
11073
11100
  _onDrag(e) {
11074
- const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos);
11101
+ const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos), { alt } = this._oldLatLng;
11102
+ if (alt !== void 0) latlng.alt = alt;
11075
11103
  marker._positionElements(iconPos);
11076
11104
  marker._latlng = latlng;
11077
11105
  e.latlng = latlng;
@@ -11080,7 +11108,6 @@
11080
11108
  }
11081
11109
  _onDragEnd(e) {
11082
11110
  cancelAnimationFrame(this._panRequest);
11083
- delete this._oldLatLng;
11084
11111
  this._marker.fire("moveend").fire("dragend", e);
11085
11112
  }
11086
11113
  /** @param {KeyboardEvent|FocusEvent} e */
@@ -11132,7 +11159,8 @@
11132
11159
  * @property {string} [title=''] Text for the browser tooltip that appear on marker hover
11133
11160
  * (no tooltip by default).
11134
11161
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
11135
- * @property {string} [alt='Marker'] Text for the `alt` attribute of the icon image.
11162
+ * @property {string} [alt] Text for the `alt` attribute of the icon image, the
11163
+ * translation of `'Marker'` by default.
11136
11164
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
11137
11165
  * @property {number} [zIndexOffset=0] By default, marker images zIndex is set
11138
11166
  * automatically based on its latitude. Use this option if you want to put the marker on
@@ -11144,9 +11172,9 @@
11144
11172
  * marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
11145
11173
  * under a tilted one. `null` means no rotation.
11146
11174
  * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
11147
- * others when you hover the pointer over it.
11148
- * @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`
11149
- * feature.
11175
+ * others while the pointer is over it. It always does while it has focus.
11176
+ * @property {number} [riseOffset=250] The z-index offset used when the marker gets on
11177
+ * top of others on hover or focus.
11150
11178
  * @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.
11151
11179
  * @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will
11152
11180
  * be added.
@@ -11199,7 +11227,7 @@
11199
11227
  interactive: true,
11200
11228
  keyboard: true,
11201
11229
  title: "",
11202
- alt: "Marker",
11230
+ alt: void 0,
11203
11231
  zIndexOffset: 0,
11204
11232
  opacity: 1,
11205
11233
  rotation: null,
@@ -11343,7 +11371,7 @@
11343
11371
  if (this._icon) this._removeIcon();
11344
11372
  addIcon = true;
11345
11373
  if (options.title) icon.title = options.title;
11346
- if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? "";
11374
+ if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? I18n.translate("Marker");
11347
11375
  }
11348
11376
  icon.classList.add(classToAdd);
11349
11377
  if (options.keyboard) {
@@ -11352,10 +11380,9 @@
11352
11380
  on(icon, "keydown", this._onKeyDown, this);
11353
11381
  }
11354
11382
  this._icon = icon;
11355
- if (options.riseOnHover) this.on({
11356
- pointerover: this._bringToFront,
11357
- pointerout: this._resetZIndex
11358
- });
11383
+ if (this._popup?._source === this) this._popup._updateSourceAria(this._popup.isOpen());
11384
+ on(icon, "focusin focusout", this._updateRise, this);
11385
+ if (options.riseOnHover) on(icon, "pointerover pointerout", this._updateRise, this);
11359
11386
  if (this.options.autoPanOnFocus) on(icon, "focus", this._panOnFocus, this);
11360
11387
  const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
11361
11388
  let addShadow = false;
@@ -11369,15 +11396,13 @@
11369
11396
  }
11370
11397
  this._shadow = newShadow;
11371
11398
  if (options.opacity < 1) this._updateOpacity();
11372
- if (addIcon) this.getPane().appendChild(this._icon);
11399
+ if (addIcon) this.getPane().append(this._icon);
11373
11400
  this._initInteraction();
11374
- if (newShadow && addShadow) this.getPane(options.shadowPane).appendChild(this._shadow);
11401
+ if (newShadow && addShadow) this.getPane(options.shadowPane).append(this._shadow);
11375
11402
  }
11376
11403
  _removeIcon() {
11377
- if (this.options.riseOnHover) this.off({
11378
- pointerover: this._bringToFront,
11379
- pointerout: this._resetZIndex
11380
- });
11404
+ off(this._icon, "pointerover pointerout focusin focusout", this._updateRise, this);
11405
+ this._hovered = this._focused = false;
11381
11406
  if (this.options.autoPanOnFocus) off(this._icon, "focus", this._panOnFocus, this);
11382
11407
  off(this._icon, "keydown", this._onKeyDown, this);
11383
11408
  this._icon.remove();
@@ -11390,8 +11415,8 @@
11390
11415
  if (visible === !this._culled) return;
11391
11416
  this._culled = !visible;
11392
11417
  if (visible) {
11393
- this.getPane().appendChild(this._icon);
11394
- if (this._shadow) this.getPane(this.options.shadowPane).appendChild(this._shadow);
11418
+ this.getPane().append(this._icon);
11419
+ if (this._shadow) this.getPane(this.options.shadowPane).append(this._shadow);
11395
11420
  this.update();
11396
11421
  } else {
11397
11422
  this._icon.remove();
@@ -11405,7 +11430,7 @@
11405
11430
  _setPos(pos) {
11406
11431
  this._positionElements(pos);
11407
11432
  this._zIndex = pos.y + this.options.zIndexOffset;
11408
- this._resetZIndex();
11433
+ this._updateRise();
11409
11434
  }
11410
11435
  _positionElements(pos) {
11411
11436
  const rotation = this.options.rotation;
@@ -11447,33 +11472,31 @@
11447
11472
  if (!this.options.interactive) return;
11448
11473
  this._icon.classList.add("maplair-interactive");
11449
11474
  this.addInteractiveTarget(this._icon);
11450
- if (MarkerDrag) {
11451
- if (this.dragging?._draggable?._element === this._icon) {
11452
- this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
11453
- return;
11454
- }
11455
- let draggable = this.options.draggable;
11456
- if (this.dragging) {
11457
- draggable = this.dragging.enabled();
11458
- this.dragging.disable();
11459
- }
11460
- /**
11461
- * Marker dragging handler, see `Handler`. Only valid when the marker is on the
11462
- * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
11463
- *
11464
- * Interaction handlers are properties of a marker instance that allow you to
11465
- * control interaction behavior in runtime, enabling or disabling certain
11466
- * features such as dragging (see `Handler` methods). Example:
11467
- *
11468
- * ```js
11469
- * marker.dragging.disable();
11470
- * ```
11471
- * @group Interaction handlers
11472
- * @type {MarkerDrag}
11473
- */
11474
- this.dragging = new MarkerDrag(this);
11475
- if (draggable) this.dragging.enable();
11475
+ if (this.dragging?._draggable?._element === this._icon) {
11476
+ this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
11477
+ return;
11476
11478
  }
11479
+ let draggable = this.options.draggable;
11480
+ if (this.dragging) {
11481
+ draggable = this.dragging.enabled();
11482
+ this.dragging.disable();
11483
+ }
11484
+ /**
11485
+ * Marker dragging handler, see `Handler`. Only valid when the marker is on the
11486
+ * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
11487
+ *
11488
+ * Interaction handlers are properties of a marker instance that allow you to
11489
+ * control interaction behavior in runtime, enabling or disabling certain
11490
+ * features such as dragging (see `Handler` methods). Example:
11491
+ *
11492
+ * ```js
11493
+ * marker.dragging.disable();
11494
+ * ```
11495
+ * @group Interaction handlers
11496
+ * @type {MarkerDrag}
11497
+ */
11498
+ this.dragging = new MarkerDrag(this);
11499
+ if (draggable) this.dragging.enable();
11477
11500
  }
11478
11501
  /**
11479
11502
  * Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
@@ -11507,9 +11530,13 @@
11507
11530
  return this;
11508
11531
  }
11509
11532
  _updateOpacity() {
11510
- const opacity = this.options.opacity;
11511
- if (this._icon) this._icon.style.opacity = `${opacity}`;
11512
- if (this._shadow) this._shadow.style.opacity = `${opacity}`;
11533
+ for (const el of [this._icon, this._shadow]) if (el) el.style.opacity = `${this.options.opacity}`;
11534
+ }
11535
+ _updateRise(e) {
11536
+ if (e?.type.startsWith("pointer")) this._hovered = e.type === "pointerover";
11537
+ else if (e) this._focused = e.type === "focusin";
11538
+ if (this._hovered || this._focused) this._bringToFront();
11539
+ else this._resetZIndex();
11513
11540
  }
11514
11541
  _bringToFront() {
11515
11542
  this._updateZIndex(this.options.riseOffset);
@@ -12133,8 +12160,9 @@
12133
12160
  this.remove();
12134
12161
  this._map = map;
12135
12162
  this._container = this.onAdd(map);
12136
- map._container.appendChild(this._container);
12137
- map.on("unload", this.remove, this);
12163
+ map._container.append(this._container);
12164
+ this._mapEvents = { unload: this.remove };
12165
+ map.on(this._mapEvents, this);
12138
12166
  return this;
12139
12167
  }
12140
12168
  /**
@@ -13669,6 +13697,7 @@
13669
13697
  onAdd() {
13670
13698
  if (!this._image) {
13671
13699
  this._initImage();
13700
+ this._updateZIndex();
13672
13701
  if (this.options.opacity < 1) this._updateOpacity();
13673
13702
  }
13674
13703
  if (this.options.interactive) {
@@ -13676,7 +13705,7 @@
13676
13705
  this.addInteractiveTarget(this._image);
13677
13706
  }
13678
13707
  this._image.classList.toggle("maplair-pixelated", !!this.options.pixelated);
13679
- this.getPane().appendChild(this._image);
13708
+ this.getPane().append(this._image);
13680
13709
  this._reset();
13681
13710
  }
13682
13711
  /**
@@ -13709,7 +13738,7 @@
13709
13738
  * @returns {this}
13710
13739
  */
13711
13740
  setStyle(styleOpts) {
13712
- if (styleOpts.opacity) this.setOpacity(styleOpts.opacity);
13741
+ if (styleOpts.opacity != null) this.setOpacity(styleOpts.opacity);
13713
13742
  return this;
13714
13743
  }
13715
13744
  /**
@@ -13795,7 +13824,6 @@
13795
13824
  img.onerror = this._overlayOnError.bind(this);
13796
13825
  if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
13797
13826
  img.decoding = this.options.decoding;
13798
- if (this.options.zIndex) this._updateZIndex();
13799
13827
  if (wasElementSupplied) {
13800
13828
  this._url = img.src;
13801
13829
  return;
@@ -13817,7 +13845,7 @@
13817
13845
  this._image.style.opacity = `${this.options.opacity}`;
13818
13846
  }
13819
13847
  _updateZIndex() {
13820
- if (this._image && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._image.style.zIndex = `${this.options.zIndex}`;
13848
+ if (this._image && this.options.zIndex != null) this._image.style.zIndex = `${this.options.zIndex}`;
13821
13849
  }
13822
13850
  _overlayOnError() {
13823
13851
  this.fire("error");
@@ -13834,6 +13862,9 @@
13834
13862
  getCenter() {
13835
13863
  return this._bounds.getCenter();
13836
13864
  }
13865
+ _togglesPopupOnClick() {
13866
+ return false;
13867
+ }
13837
13868
  };
13838
13869
  // src/layer/VideoOverlay.js
13839
13870
  /** @import {ImageOverlayOptions} from './ImageOverlay.js' */
@@ -13914,7 +13945,7 @@
13914
13945
  return;
13915
13946
  }
13916
13947
  if (!Array.isArray(this._url)) this._url = [this._url];
13917
- if (!this.options.keepAspectRatio) vid.style["objectFit"] = "fill";
13948
+ if (!this.options.keepAspectRatio) vid.style.objectFit = "fill";
13918
13949
  vid.autoplay = !!this.options.autoplay;
13919
13950
  vid.controls = !!this.options.controls;
13920
13951
  vid.loop = !!this.options.loop;
@@ -13923,7 +13954,7 @@
13923
13954
  for (const url of this._url) {
13924
13955
  const source = create("source");
13925
13956
  source.src = url;
13926
- vid.appendChild(source);
13957
+ vid.append(source);
13927
13958
  }
13928
13959
  }
13929
13960
  };
@@ -14026,14 +14057,10 @@
14026
14057
  */
14027
14058
  createIcon(oldIcon) {
14028
14059
  const div = oldIcon instanceof HTMLDivElement ? oldIcon : document.createElement("div"), options = this.options;
14029
- if (options.html instanceof Element) {
14030
- div.replaceChildren();
14031
- div.appendChild(options.html);
14032
- } else div.innerHTML = options.html !== false ? options.html : "";
14033
- if (options.bgPos) {
14034
- const bgPos = Point.from(options.bgPos);
14035
- div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
14036
- }
14060
+ if (options.html instanceof Element) div.replaceChildren(options.html);
14061
+ else div.innerHTML = options.html !== false ? options.html : "";
14062
+ const bgPos = options.bgPos && Point.from(options.bgPos);
14063
+ div.style.backgroundPosition = bgPos ? `${-bgPos.x}px ${-bgPos.y}px` : "";
14037
14064
  this._setIconStyles(div, "icon");
14038
14065
  return div;
14039
14066
  }
@@ -14058,7 +14085,7 @@
14058
14085
  function svgElement(name, attributes, parent) {
14059
14086
  const el = document.createElementNS(svgNS, name);
14060
14087
  for (const [key, value] of Object.entries(attributes)) el.setAttribute(key, value);
14061
- parent?.appendChild(el);
14088
+ parent?.append(el);
14062
14089
  return el;
14063
14090
  }
14064
14091
  /**
@@ -14503,10 +14530,10 @@
14503
14530
  * @typedef {(error: any, tile: HTMLElement) => void} TileDoneCallback
14504
14531
  */
14505
14532
  /**
14506
- * Generic class for handling a tiled grid of HTML elements. This is the base class for
14507
- * all tile layers and replaces `TileLayer.Canvas`. GridLayer can be extended to create
14508
- * a tiled grid of HTML elements like `<canvas>`, `<img>` or `<div>`. GridLayer will
14509
- * handle creating and animating these DOM elements for you.
14533
+ * Generic class for handling a tiled grid of HTML elements, and the base class of all
14534
+ * tile layers. To show map tiles from a URL, use `TileLayer` (or `WMSTileLayer`).
14535
+ * Extend `GridLayer` to create a tiled grid of your own elements like `<canvas>`,
14536
+ * `<img>` or `<div>`; it handles creating and animating them for you.
14510
14537
  *
14511
14538
  * Layers extending `GridLayer` shall reimplement the [`createTile()`](#gridlayer-createtile)
14512
14539
  * method.
@@ -14702,7 +14729,7 @@
14702
14729
  redraw() {
14703
14730
  if (this._map) {
14704
14731
  this._removeAllTiles();
14705
- const tileZoom = this._clampZoom(Math.round(this._map.getZoom()));
14732
+ const tileZoom = this._getTileZoom(this._map.getZoom());
14706
14733
  if (tileZoom !== this._tileZoom) {
14707
14734
  this._tileZoom = tileZoom;
14708
14735
  this._updateLevels();
@@ -14753,7 +14780,7 @@
14753
14780
  return s instanceof Point ? s : new Point(s, s);
14754
14781
  }
14755
14782
  _updateZIndex() {
14756
- if (this._container && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._container.style.zIndex = `${this.options.zIndex}`;
14783
+ if (this._container && this.options.zIndex != null) this._container.style.zIndex = `${this.options.zIndex}`;
14757
14784
  }
14758
14785
  _setAutoZIndex(compare) {
14759
14786
  const layers = this.getPane().children;
@@ -14778,7 +14805,7 @@
14778
14805
  this._container.classList.toggle("maplair-pixelated", !!this.options.pixelated);
14779
14806
  this._updateZIndex();
14780
14807
  if (this.options.opacity < 1) this._updateOpacity();
14781
- this.getPane().appendChild(this._container);
14808
+ this.getPane().append(this._container);
14782
14809
  }
14783
14810
  _keepCurrentTiles() {
14784
14811
  const zoom = this._tileZoom, level = this._levels?.[zoom];
@@ -14852,8 +14879,7 @@
14852
14879
  _onCreateLevel() {}
14853
14880
  _pruneTiles() {
14854
14881
  if (!this._map) return;
14855
- const zoom = this._map.getZoom();
14856
- if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
14882
+ if (this._getTileZoom(this._map.getZoom()) === void 0) {
14857
14883
  this._removeAllTiles();
14858
14884
  return;
14859
14885
  }
@@ -14908,6 +14934,11 @@
14908
14934
  _animateZoom(e) {
14909
14935
  this._setView(e.center, e.zoom, true, e.noUpdate);
14910
14936
  }
14937
+ _getTileZoom(zoom) {
14938
+ const { minZoom, maxZoom = Infinity } = this.options;
14939
+ if (zoom < minZoom || zoom > maxZoom) return;
14940
+ return this._clampZoom(Math.round(zoom));
14941
+ }
14911
14942
  _clampZoom(zoom) {
14912
14943
  const options = this.options;
14913
14944
  if (void 0 !== options.minNativeZoom && zoom < options.minNativeZoom) return options.minNativeZoom;
@@ -14915,13 +14946,11 @@
14915
14946
  return zoom;
14916
14947
  }
14917
14948
  _setView(center, zoom, noPrune, noUpdate) {
14918
- let tileZoom = Math.round(zoom);
14919
- if (this.options.maxZoom !== void 0 && tileZoom > this.options.maxZoom || this.options.minZoom !== void 0 && tileZoom < this.options.minZoom) tileZoom = void 0;
14920
- else tileZoom = this._clampZoom(tileZoom);
14949
+ const tileZoom = this._getTileZoom(zoom);
14921
14950
  const tileZoomChanged = this.options.updateWhenZooming && tileZoom !== this._tileZoom;
14922
14951
  if (!noUpdate || tileZoomChanged) {
14923
14952
  this._tileZoom = tileZoom;
14924
- if (this._abortLoading) this._abortLoading();
14953
+ this._abortLoading?.();
14925
14954
  this._updateLevels();
14926
14955
  this._resetGrid();
14927
14956
  if (tileZoom !== void 0) this._update(center);
@@ -14990,7 +15019,7 @@
14990
15019
  else queue.push(coords);
14991
15020
  }
14992
15021
  queue.sort((a, b) => a.distanceTo(tileCenter) - b.distanceTo(tileCenter));
14993
- if (queue.length !== 0) {
15022
+ if (queue.length) {
14994
15023
  if (!this._loading) {
14995
15024
  this._loading = true;
14996
15025
  this.fire("loading");
@@ -14998,7 +15027,7 @@
14998
15027
  }
14999
15028
  const fragment = document.createDocumentFragment();
15000
15029
  for (const q of queue) this._addTile(q, fragment);
15001
- this._level.el.appendChild(fragment);
15030
+ this._level.el.append(fragment);
15002
15031
  }
15003
15032
  }
15004
15033
  _isValidTile(coords) {
@@ -15052,7 +15081,7 @@
15052
15081
  coords,
15053
15082
  current: true
15054
15083
  };
15055
- container.appendChild(tile);
15084
+ container.append(tile);
15056
15085
  this.fire("tileloadstart", {
15057
15086
  tile,
15058
15087
  coords
@@ -15257,13 +15286,13 @@
15257
15286
  if (!this.options.zoomReverse) {
15258
15287
  this.options.zoomOffset++;
15259
15288
  this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);
15260
- if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
15261
- if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
15262
15289
  } else {
15263
15290
  this.options.zoomOffset--;
15264
15291
  this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);
15265
15292
  }
15266
15293
  this.options.minZoom = Math.max(0, this.options.minZoom);
15294
+ if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
15295
+ if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
15267
15296
  } else if (!this.options.zoomReverse) this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);
15268
15297
  else this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);
15269
15298
  }
@@ -15359,16 +15388,17 @@
15359
15388
  * @returns {string}
15360
15389
  */
15361
15390
  getTileUrl(coords) {
15362
- const data = Object.create(this.options);
15391
+ const z = coords.z ?? this._tileZoom, data = Object.create(this.options);
15363
15392
  Object.assign(data, {
15364
15393
  r: window.devicePixelRatio > 1 ? "@2x" : "",
15365
15394
  s: this._getSubdomain(coords),
15366
15395
  x: coords.x,
15367
15396
  y: coords.y,
15368
- z: this._getZoomForUrl()
15397
+ z: this._getZoomForUrl(z)
15369
15398
  });
15370
- if (this._map && !this._map.options.crs.infinite) {
15371
- const invertedY = this._globalTileRange.max.y - coords.y;
15399
+ const worldBounds = this._map?.getPixelWorldBounds(z);
15400
+ if (worldBounds) {
15401
+ const invertedY = this._pxBoundsToTileRange(worldBounds).max.y - coords.y;
15372
15402
  if (this.options.tms) data["y"] = invertedY;
15373
15403
  data["-y"] = invertedY;
15374
15404
  }
@@ -15383,8 +15413,7 @@
15383
15413
  if (errorUrl && src !== errorUrl && (src || tile.isConnected)) tile.src = errorUrl;
15384
15414
  done(e, tile);
15385
15415
  }
15386
- _getZoomForUrl() {
15387
- let zoom = this._tileZoom;
15416
+ _getZoomForUrl(zoom) {
15388
15417
  const maxZoom = this.options.maxZoom, zoomReverse = this.options.zoomReverse, zoomOffset = this.options.zoomOffset;
15389
15418
  if (zoomReverse) zoom = maxZoom - zoom;
15390
15419
  return zoom + zoomOffset;
@@ -15417,7 +15446,7 @@
15417
15446
  return super._removeTile(key);
15418
15447
  }
15419
15448
  _tileReady(coords, err, tile) {
15420
- if (!this._map || tile && tile.getAttribute("src") === "") return;
15449
+ if (!this._map || tile?.getAttribute("src") === "") return;
15421
15450
  return super._tileReady(coords, err, tile);
15422
15451
  }
15423
15452
  _clampZoom(zoom) {
@@ -15671,22 +15700,21 @@
15671
15700
  */
15672
15701
  onAdd(map) {
15673
15702
  super.onAdd(map);
15703
+ const z = (r) => +getComputedStyle(r._container.parentNode).zIndex || 0;
15704
+ map._canvases.push(this);
15705
+ map._canvases.sort((a, b) => z(b) - z(a) || (a._container.compareDocumentPosition(b._container) & 2) - 1);
15674
15706
  this._draw();
15675
15707
  }
15708
+ _initContainer() {
15709
+ const container = this._container = document.createElement("canvas");
15710
+ this._ctx = container.getContext("2d");
15711
+ }
15676
15712
  /**
15677
15713
  * Removes the canvas from the map.
15678
15714
  */
15679
15715
  onRemove() {
15716
+ this._map._canvases = this._map._canvases.filter((r) => r !== this);
15680
15717
  super.onRemove();
15681
- clearTimeout(this._pointerHoverThrottleTimeout);
15682
- }
15683
- _initContainer() {
15684
- const container = this._container = document.createElement("canvas");
15685
- on(container, "pointermove", this._onPointerMove, this);
15686
- on(container, "click dblclick pointerdown pointerup contextmenu", this._onClick, this);
15687
- on(container, "pointerout", this._handlePointerOut, this);
15688
- container["_maplair_disable_events"] = true;
15689
- this._ctx = container.getContext("2d");
15690
15718
  }
15691
15719
  _destroyContainer() {
15692
15720
  cancelAnimationFrame(this._redrawRequest);
@@ -15722,26 +15750,13 @@
15722
15750
  _initPath(layer) {
15723
15751
  this._updateDashArray(layer);
15724
15752
  this._layers[stamp(layer)] = layer;
15725
- const order = layer._order = {
15726
- layer,
15727
- prev: this._drawLast,
15728
- next: null
15729
- };
15730
- if (this._drawLast) this._drawLast.next = order;
15731
- this._drawLast = order;
15732
- this._drawFirst ??= this._drawLast;
15753
+ this._append(layer._order = { layer });
15733
15754
  }
15734
15755
  _addPath(layer) {
15735
15756
  this._requestRedraw(layer);
15736
15757
  }
15737
15758
  _removePath(layer) {
15738
- const order = layer._order;
15739
- const next = order.next;
15740
- const prev = order.prev;
15741
- if (next) next.prev = prev;
15742
- else this._drawLast = prev;
15743
- if (prev) prev.next = next;
15744
- else this._drawFirst = next;
15759
+ this._unlink(layer._order);
15745
15760
  delete layer._order;
15746
15761
  delete this._layers[stamp(layer)];
15747
15762
  this._requestRedraw(layer);
@@ -15767,7 +15782,7 @@
15767
15782
  }
15768
15783
  _extendRedrawBounds(layer) {
15769
15784
  if (layer._pxBounds) {
15770
- const padding = (layer.options.weight ?? 0) + 1;
15785
+ const padding = (+layer.options.weight || 0) + 1;
15771
15786
  this._redrawBounds ??= new Bounds();
15772
15787
  this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
15773
15788
  this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
@@ -15809,7 +15824,7 @@
15809
15824
  this._drawing = true;
15810
15825
  for (let order = this._drawFirst; order; order = order.next) {
15811
15826
  layer = order.layer;
15812
- if (!bounds || layer._pxBounds && layer._pxBounds.intersects(bounds)) layer._updatePath();
15827
+ if (!bounds || layer._pxBounds?.intersects(bounds)) layer._updatePath();
15813
15828
  }
15814
15829
  this._drawing = false;
15815
15830
  this._ctx.restore();
@@ -15854,84 +15869,50 @@
15854
15869
  }
15855
15870
  }
15856
15871
  _updateInteractive() {}
15857
- _onClick(e) {
15872
+ /**
15873
+ * Returns the topmost interactive layer under the pointer.
15874
+ * @param {MouseEvent} e
15875
+ * @param {boolean} [click] Skip layers that were just dragged, so the drag doesn't end with a click.
15876
+ * @returns {Path|undefined}
15877
+ */
15878
+ _layerAt(e, click) {
15858
15879
  const point = this._map.pointerEventToLayerPoint(e);
15859
- let layer, clickedLayer;
15860
- for (let order = this._drawFirst; order; order = order.next) {
15861
- layer = order.layer;
15862
- if (layer.options.interactive && layer._containsPoint(point)) {
15863
- if (!(e.type === "click" || e.type === "preclick") || !this._map._draggableMoved(layer)) clickedLayer = layer;
15864
- }
15880
+ for (let order = this._drawLast; order; order = order.prev) {
15881
+ const layer = order.layer;
15882
+ if (layer.options.interactive && layer._containsPoint(point) && !(click && this._map._draggableMoved(layer))) return layer;
15865
15883
  }
15866
- this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
15867
15884
  }
15868
- _onPointerMove(e) {
15869
- if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) return;
15870
- const point = this._map.pointerEventToLayerPoint(e);
15871
- this._handlePointerHover(e, point);
15872
- }
15873
- _handlePointerOut(e) {
15874
- const layer = this._hoveredLayer;
15875
- if (layer) {
15876
- this._container.classList.remove("maplair-interactive");
15877
- this._fireEvent([layer], e, "pointerout");
15878
- this._hoveredLayer = null;
15879
- this._pointerHoverThrottled = false;
15885
+ _bringToFront(layer) {
15886
+ const order = layer._order;
15887
+ if (order?.next) {
15888
+ this._unlink(order);
15889
+ this._append(order);
15890
+ this._requestRedraw(layer);
15880
15891
  }
15881
15892
  }
15882
- _handlePointerHover(e, point) {
15883
- if (this._pointerHoverThrottled) return;
15884
- let layer, candidateHoveredLayer;
15885
- for (let order = this._drawFirst; order; order = order.next) {
15886
- layer = order.layer;
15887
- if (layer.options.interactive && layer._containsPoint(point)) candidateHoveredLayer = layer;
15888
- }
15889
- if (candidateHoveredLayer !== this._hoveredLayer) {
15890
- this._handlePointerOut(e);
15891
- if (candidateHoveredLayer) {
15892
- this._container.classList.add("maplair-interactive");
15893
- this._fireEvent([candidateHoveredLayer], e, "pointerover");
15894
- this._hoveredLayer = candidateHoveredLayer;
15895
- }
15893
+ _bringToBack(layer) {
15894
+ const order = layer._order;
15895
+ if (order?.prev) {
15896
+ this._unlink(order);
15897
+ order.prev = null;
15898
+ order.next = this._drawFirst;
15899
+ this._drawFirst.prev = order;
15900
+ this._drawFirst = order;
15901
+ this._requestRedraw(layer);
15896
15902
  }
15897
- this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
15898
- this._pointerHoverThrottled = true;
15899
- this._pointerHoverThrottleTimeout = setTimeout((() => {
15900
- this._pointerHoverThrottled = false;
15901
- }), 32);
15902
- }
15903
- _fireEvent(layers, e, type) {
15904
- this._map._fireDOMEvent(e, type || e.type, layers);
15905
15903
  }
15906
- _bringToFront(layer) {
15907
- const order = layer._order;
15908
- if (!order) return;
15909
- const next = order.next;
15910
- const prev = order.prev;
15911
- if (next) next.prev = prev;
15912
- else return;
15913
- if (prev) prev.next = next;
15914
- else if (next) this._drawFirst = next;
15904
+ _append(order) {
15915
15905
  order.prev = this._drawLast;
15916
- this._drawLast.next = order;
15917
15906
  order.next = null;
15907
+ if (this._drawLast) this._drawLast.next = order;
15918
15908
  this._drawLast = order;
15919
- this._requestRedraw(layer);
15909
+ this._drawFirst ??= order;
15920
15910
  }
15921
- _bringToBack(layer) {
15922
- const order = layer._order;
15923
- if (!order) return;
15924
- const next = order.next;
15925
- const prev = order.prev;
15926
- if (prev) prev.next = next;
15927
- else return;
15911
+ _unlink({ prev, next }) {
15928
15912
  if (next) next.prev = prev;
15929
- else if (prev) this._drawLast = prev;
15930
- order.prev = null;
15931
- order.next = this._drawFirst;
15932
- this._drawFirst.prev = order;
15933
- this._drawFirst = order;
15934
- this._requestRedraw(layer);
15913
+ else this._drawLast = prev;
15914
+ if (prev) prev.next = next;
15915
+ else this._drawFirst = next;
15935
15916
  }
15936
15917
  };
15937
15918
  // src/layer/vector/Circle.js
@@ -15963,6 +15944,7 @@
15963
15944
  * @param {CircleOptions} [options]
15964
15945
  */
15965
15946
  constructor(latlng, options) {
15947
+ if (typeof options === "number") throw new Error("Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).");
15966
15948
  super(latlng, options);
15967
15949
  if (isNaN(this.options.radius)) throw new Error("Circle radius cannot be NaN");
15968
15950
  this.callInitHooks(Circle);
@@ -15978,18 +15960,18 @@
15978
15960
  return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half)));
15979
15961
  }
15980
15962
  _project() {
15981
- const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs;
15963
+ const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs, renderer = this._renderer, zoom = renderer._pathZoom;
15982
15964
  if (crs.distance === EarthCRS.distance) {
15983
- 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;
15965
+ 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;
15984
15966
  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;
15985
- if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(Math.PI / 180 * lat);
15986
- this._point = p.subtract(map.getPixelOrigin());
15987
- this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;
15967
+ if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(lat * d);
15968
+ this._point = p.subtract(renderer._pathOrigin);
15969
+ this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR], zoom).x;
15988
15970
  this._pxRadiusY = p.y - top.y;
15989
15971
  } else {
15990
15972
  const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
15991
- this._point = map.latLngToLayerPoint(this._latlng);
15992
- this._pxRadius = Math.abs(this._point.x - map.latLngToLayerPoint(latlng2).x);
15973
+ this._point = renderer._latLngToLayerPoint(this._latlng);
15974
+ this._pxRadius = Math.abs(this._point.x - renderer._latLngToLayerPoint(latlng2).x);
15993
15975
  }
15994
15976
  this._updateBounds();
15995
15977
  }
@@ -16420,10 +16402,7 @@
16420
16402
  other._rawPanBy(offset);
16421
16403
  other.fire("move");
16422
16404
  }
16423
- } else other._move(center, zoom, during ? {
16424
- pinch: true,
16425
- round: false
16426
- } : void 0);
16405
+ } else other._move(center, zoom, during ? { pinch: true } : void 0);
16427
16406
  }
16428
16407
  _syncAll(map) {
16429
16408
  for (const other of this._maps.filter((m) => m !== map)) {
@@ -16555,6 +16534,7 @@
16555
16534
  * Called when the handler is enabled, adds the event hooks.
16556
16535
  */
16557
16536
  addHooks() {
16537
+ this._map._displaceHandler = this;
16558
16538
  this._map.on("zoomend", this.schedule, this);
16559
16539
  this._map.on("layeradd", this._onLayerAdd, this);
16560
16540
  this._map.on("layerremove", this._onLayerRemove, this);
@@ -16566,6 +16546,7 @@
16566
16546
  * true positions of the markers.
16567
16547
  */
16568
16548
  removeHooks() {
16549
+ if (this._map._displaceHandler === this) delete this._map._displaceHandler;
16569
16550
  this._map.off("zoomend", this.schedule, this);
16570
16551
  this._map.off("layeradd", this._onLayerAdd, this);
16571
16552
  this._map.off("layerremove", this._onLayerRemove, this);
@@ -16637,6 +16618,7 @@
16637
16618
  * @param {LatLng} latLng
16638
16619
  */
16639
16620
  _moveTo(marker, latLng) {
16621
+ if (marker.getLatLng().equals(latLng)) return;
16640
16622
  this._moving = true;
16641
16623
  try {
16642
16624
  marker.setLatLng(latLng);
@@ -16656,6 +16638,19 @@
16656
16638
  if (this._enabled && this._map.hasLayer(event.target)) this.schedule();
16657
16639
  }
16658
16640
  /**
16641
+ * Called by `CircleMarker#beforeAdd`: puts a marker whose `displaceId` already
16642
+ * has a displaced position at the current zoom (e.g. the same station on
16643
+ * another layer) there before it is drawn, instead of drawing it twice.
16644
+ * @param {CircleMarker} marker
16645
+ */
16646
+ _beforeMarkerAdd(marker) {
16647
+ if (!displaceable(marker)) return;
16648
+ this._track(marker);
16649
+ const { displaceId } = marker.options;
16650
+ const latLng = displaceId && this._displacedPositions.get(this._map.getZoom())?.get(displaceId);
16651
+ if (latLng) this._moveTo(marker, latLng);
16652
+ }
16653
+ /**
16659
16654
  * @param {LayerEvent} event
16660
16655
  */
16661
16656
  _onLayerAdd(event) {
@@ -16692,6 +16687,10 @@
16692
16687
  }
16693
16688
  };
16694
16689
  /**
16690
+ * Movement in pixels per pass below which `displace` stops early
16691
+ */
16692
+ const MIN_MOVE = .01;
16693
+ /**
16695
16694
  * Displaces overlapping points in pixel space until they are at least
16696
16695
  * `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed
16697
16696
  * apart by half of its overlap per pass. Neighbour lookup uses a grid (cell
@@ -16699,7 +16698,8 @@
16699
16698
  *
16700
16699
  * No point ends up further than `maxDisplacement` away from where it started.
16701
16700
  * Points which hit that limit stay overlapping – the limit wins over the
16702
- * separation.
16701
+ * separation. The relaxation stops early once the points are separated or
16702
+ * no point moves by more than a hundredth of a pixel per pass.
16703
16703
  *
16704
16704
  * @param {Point[]} points Pixel coordinates (modified in place)
16705
16705
  * @param {number} minSeparation Minimum distance between centers, in pixels
@@ -16719,49 +16719,62 @@
16719
16719
  for (let iter = 0; iter < iterations; iter++) {
16720
16720
  dx.fill(0);
16721
16721
  dy.fill(0);
16722
- /** @type {Map<string, number[]>} */
16722
+ /** @type {Map<number, Map<number, number[]>>} */
16723
16723
  const grid = /* @__PURE__ */ new Map();
16724
16724
  for (let i = 0; i < n; i++) {
16725
- const key = `${Math.floor(points[i].x / cell)},${Math.floor(points[i].y / cell)}`;
16726
- const bucket = grid.get(key);
16725
+ const cx = Math.floor(points[i].x / cell);
16726
+ const cy = Math.floor(points[i].y / cell);
16727
+ let column = grid.get(cx);
16728
+ if (!column) {
16729
+ column = /* @__PURE__ */ new Map();
16730
+ grid.set(cx, column);
16731
+ }
16732
+ const bucket = column.get(cy);
16727
16733
  if (bucket) bucket.push(i);
16728
- else grid.set(key, [i]);
16734
+ else column.set(cy, [i]);
16729
16735
  }
16730
16736
  let overlaps = 0;
16731
16737
  for (let i = 0; i < n; i++) {
16732
16738
  const cx = Math.floor(points[i].x / cell);
16733
16739
  const cy = Math.floor(points[i].y / cell);
16734
- for (let gx = cx - 1; gx <= cx + 1; gx++) for (let gy = cy - 1; gy <= cy + 1; gy++) {
16735
- const bucket = grid.get(`${gx},${gy}`);
16736
- if (!bucket) continue;
16737
- for (const j of bucket) {
16738
- if (j <= i) continue;
16739
- let vx = points[i].x - points[j].x;
16740
- let vy = points[i].y - points[j].y;
16741
- const distSq = vx * vx + vy * vy;
16742
- if (distSq >= sepSq) continue;
16743
- overlaps++;
16744
- let dist;
16745
- if (distSq === 0) {
16746
- const angle = i * 2.399963229728653;
16747
- vx = Math.cos(angle);
16748
- vy = Math.sin(angle);
16749
- dist = 1;
16750
- } else {
16751
- dist = Math.sqrt(distSq);
16752
- vx /= dist;
16753
- vy /= dist;
16740
+ for (let gx = cx - 1; gx <= cx + 1; gx++) {
16741
+ const column = grid.get(gx);
16742
+ if (!column) continue;
16743
+ for (let gy = cy - 1; gy <= cy + 1; gy++) {
16744
+ const bucket = column.get(gy);
16745
+ if (!bucket) continue;
16746
+ for (const j of bucket) {
16747
+ if (j <= i) continue;
16748
+ let vx = points[i].x - points[j].x;
16749
+ let vy = points[i].y - points[j].y;
16750
+ const distSq = vx * vx + vy * vy;
16751
+ if (distSq >= sepSq) continue;
16752
+ overlaps++;
16753
+ let dist;
16754
+ if (distSq === 0) {
16755
+ const angle = i * 2.399963229728653;
16756
+ vx = Math.cos(angle);
16757
+ vy = Math.sin(angle);
16758
+ dist = 1;
16759
+ } else {
16760
+ dist = Math.sqrt(distSq);
16761
+ vx /= dist;
16762
+ vy /= dist;
16763
+ }
16764
+ const push = (sep - dist) / 2;
16765
+ dx[i] += vx * push;
16766
+ dy[i] += vy * push;
16767
+ dx[j] -= vx * push;
16768
+ dy[j] -= vy * push;
16754
16769
  }
16755
- const push = (sep - dist) / 2;
16756
- dx[i] += vx * push;
16757
- dy[i] += vy * push;
16758
- dx[j] -= vx * push;
16759
- dy[j] -= vy * push;
16760
16770
  }
16761
16771
  }
16762
16772
  }
16763
16773
  if (overlaps === 0) break;
16774
+ let maxMoveSq = 0;
16764
16775
  for (let i = 0; i < n; i++) {
16776
+ const x = points[i].x;
16777
+ const y = points[i].y;
16765
16778
  points[i].x += dx[i];
16766
16779
  points[i].y += dy[i];
16767
16780
  const ox = points[i].x - ax[i];
@@ -16772,7 +16785,11 @@
16772
16785
  points[i].x = ax[i] + ox * scale;
16773
16786
  points[i].y = ay[i] + oy * scale;
16774
16787
  }
16788
+ const mx = points[i].x - x;
16789
+ const my = points[i].y - y;
16790
+ maxMoveSq = Math.max(maxMoveSq, mx * mx + my * my);
16775
16791
  }
16792
+ if (maxMoveSq < MIN_MOVE * MIN_MOVE) break;
16776
16793
  }
16777
16794
  return points;
16778
16795
  }
@@ -16842,7 +16859,6 @@
16842
16859
  disableClickPropagation(button);
16843
16860
  on(button, "click", stop);
16844
16861
  on(button, "click", this._resetNorth, this);
16845
- on(button, "click", this._refocusOnMap, this);
16846
16862
  this._update();
16847
16863
  map.on("rotate", this._update, this);
16848
16864
  return container;
@@ -16946,8 +16962,8 @@
16946
16962
  if (!this._rotatePane) {
16947
16963
  const rotatePane = this._rotatePane = create("div", "maplair-rotate-pane");
16948
16964
  rotatedMaps.set(rotatePane, this);
16949
- this._container.insertBefore(rotatePane, this._mapPane);
16950
- rotatePane.appendChild(this._mapPane);
16965
+ this._mapPane.before(rotatePane);
16966
+ rotatePane.append(this._mapPane);
16951
16967
  }
16952
16968
  if (bearing === this.getBearing()) return;
16953
16969
  this._bearing = bearing;
@@ -17036,9 +17052,9 @@
17036
17052
  return panBy.call(this, this._rotateToPane(Point.from(offset)), options);
17037
17053
  },
17038
17054
  _tryAnimatedPan(center, options) {
17039
- const offset = this._rotateToContainer(this._getCenterOffset(center)._trunc());
17040
- if (options?.animate !== true && !this.getSize().contains(offset)) return false;
17041
- this.panBy(offset, options);
17055
+ const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
17056
+ if (options?.animate !== true && !this.getSize().contains(this._rotateToContainer(offset))) return false;
17057
+ this._panBy(offset, options);
17042
17058
  return true;
17043
17059
  },
17044
17060
  /**
@@ -17330,10 +17346,7 @@
17330
17346
  this._moved = true;
17331
17347
  }
17332
17348
  cancelAnimationFrame(this._animRequest);
17333
- const moveFn = map._move.bind(map, this._center, this._zoom, {
17334
- pinch: true,
17335
- round: false
17336
- }, void 0);
17349
+ const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
17337
17350
  this._animRequest = requestAnimationFrame(moveFn.bind(this));
17338
17351
  e.preventDefault();
17339
17352
  }