maplair 4.3.0 → 4.5.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 (191) hide show
  1. package/CHANGELOG.md +151 -8
  2. package/dist/esm/control/AttributionControl.js +30 -13
  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 +46 -27
  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 +7 -8
  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 +14 -13
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Events.js +3 -2
  23. package/dist/esm/core/Events.js.map +1 -1
  24. package/dist/esm/core/Util.js +17 -5
  25. package/dist/esm/core/Util.js.map +1 -1
  26. package/dist/esm/dom/DomEvent.PointerEvents.js +72 -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 +10 -8
  33. package/dist/esm/dom/Draggable.js.map +1 -1
  34. package/dist/esm/geo/LatLng.js +24 -35
  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 +16 -19
  41. package/dist/esm/geometry/Point.js.map +1 -1
  42. package/dist/esm/geometry/PolyUtil.js +10 -3
  43. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  44. package/dist/esm/geometry/Transformation.js +1 -7
  45. package/dist/esm/geometry/Transformation.js.map +1 -1
  46. package/dist/esm/layer/BlanketOverlay.js +3 -2
  47. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  48. package/dist/esm/layer/DivOverlay.js +25 -25
  49. package/dist/esm/layer/DivOverlay.js.map +1 -1
  50. package/dist/esm/layer/ImageOverlay.js +8 -5
  51. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  52. package/dist/esm/layer/Layer.js +12 -7
  53. package/dist/esm/layer/Layer.js.map +1 -1
  54. package/dist/esm/layer/Popup.js +33 -15
  55. package/dist/esm/layer/Popup.js.map +1 -1
  56. package/dist/esm/layer/Tooltip.js +48 -56
  57. package/dist/esm/layer/Tooltip.js.map +1 -1
  58. package/dist/esm/layer/VideoOverlay.js +2 -2
  59. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  60. package/dist/esm/layer/marker/DivIcon.js +4 -8
  61. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  62. package/dist/esm/layer/marker/Icon.js +37 -17
  63. package/dist/esm/layer/marker/Icon.js.map +1 -1
  64. package/dist/esm/layer/marker/Marker.Drag.js +11 -12
  65. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  66. package/dist/esm/layer/marker/Marker.js +54 -53
  67. package/dist/esm/layer/marker/Marker.js.map +1 -1
  68. package/dist/esm/layer/marker/SvgIcon.js +1 -1
  69. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  70. package/dist/esm/layer/tile/GridLayer.js +29 -21
  71. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  72. package/dist/esm/layer/tile/TileLayer.js +19 -15
  73. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  74. package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
  75. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  76. package/dist/esm/layer/vector/Canvas.js +45 -94
  77. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  78. package/dist/esm/layer/vector/Circle.js +8 -9
  79. package/dist/esm/layer/vector/Circle.js.map +1 -1
  80. package/dist/esm/layer/vector/CircleMarker.js +15 -4
  81. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  82. package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
  83. package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
  84. package/dist/esm/layer/vector/Path.js +10 -5
  85. package/dist/esm/layer/vector/Path.js.map +1 -1
  86. package/dist/esm/layer/vector/Polygon.js +10 -11
  87. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  88. package/dist/esm/layer/vector/Polyline.js +19 -26
  89. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  90. package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
  91. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  92. package/dist/esm/layer/vector/Renderer.js +16 -0
  93. package/dist/esm/layer/vector/Renderer.js.map +1 -1
  94. package/dist/esm/layer/vector/SVG.js +3 -3
  95. package/dist/esm/layer/vector/SVG.js.map +1 -1
  96. package/dist/esm/map/Map.Rotation.js +9 -11
  97. package/dist/esm/map/Map.Rotation.js.map +1 -1
  98. package/dist/esm/map/Map.js +158 -71
  99. package/dist/esm/map/Map.js.map +1 -1
  100. package/dist/esm/map/MapSync.js +2 -5
  101. package/dist/esm/map/MapSync.js.map +1 -1
  102. package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
  103. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  104. package/dist/esm/map/handler/DisplaceHandler.js +68 -30
  105. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  106. package/dist/esm/map/handler/DragHandler.js +7 -2
  107. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  108. package/dist/esm/map/handler/KeyboardHandler.js +3 -5
  109. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  110. package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
  111. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  112. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
  113. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  114. package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
  115. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  116. package/dist/esm/map/handler/TapHoldHandler.js +8 -20
  117. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  118. package/dist/esm/package.js +1 -1
  119. package/dist/maplair-global-src.js +970 -810
  120. package/dist/maplair-global-src.js.map +1 -1
  121. package/dist/maplair-global.js +2 -2
  122. package/dist/maplair-global.js.map +1 -1
  123. package/dist/maplair-src.js +970 -810
  124. package/dist/maplair-src.js.map +1 -1
  125. package/dist/maplair.css +1 -1
  126. package/dist/maplair.js +2 -2
  127. package/dist/maplair.js.map +1 -1
  128. package/i18n/en.json +1 -0
  129. package/package.json +1 -1
  130. package/src/control/AttributionControl.js +37 -11
  131. package/src/control/ButtonControl.js +0 -1
  132. package/src/control/ContextMenu.js +1 -1
  133. package/src/control/Control.js +13 -16
  134. package/src/control/FullscreenControl.js +0 -1
  135. package/src/control/LayersControl.js +61 -37
  136. package/src/control/RotateControl.js +0 -1
  137. package/src/control/ScaleControl.js +10 -8
  138. package/src/control/SideBySideControl.js +4 -2
  139. package/src/control/ZoomControl.js +11 -13
  140. package/src/core/Events.js +6 -2
  141. package/src/core/Util.js +17 -4
  142. package/src/dom/DomEvent.PointerEvents.js +68 -2
  143. package/src/dom/DomEvent.js +5 -17
  144. package/src/dom/DomUtil.js +5 -5
  145. package/src/dom/Draggable.js +11 -8
  146. package/src/geo/LatLng.js +24 -37
  147. package/src/geo/LatLngBounds.js +10 -4
  148. package/src/geometry/Bounds.js +3 -3
  149. package/src/geometry/Point.js +22 -28
  150. package/src/geometry/PolyUtil.js +12 -3
  151. package/src/geometry/Transformation.js +1 -8
  152. package/src/layer/BlanketOverlay.js +6 -3
  153. package/src/layer/DivOverlay.js +30 -32
  154. package/src/layer/ImageOverlay.js +12 -9
  155. package/src/layer/Layer.js +19 -7
  156. package/src/layer/Popup.js +41 -21
  157. package/src/layer/Tooltip.js +50 -70
  158. package/src/layer/VideoOverlay.js +2 -2
  159. package/src/layer/marker/DivIcon.js +3 -6
  160. package/src/layer/marker/Icon.js +41 -20
  161. package/src/layer/marker/Marker.Drag.js +22 -24
  162. package/src/layer/marker/Marker.js +71 -64
  163. package/src/layer/marker/SvgIcon.js +1 -1
  164. package/src/layer/tile/GridLayer.js +41 -30
  165. package/src/layer/tile/TileLayer.js +31 -21
  166. package/src/layer/tile/WMSTileLayer.js +4 -2
  167. package/src/layer/vector/Canvas.js +53 -149
  168. package/src/layer/vector/Circle.js +13 -13
  169. package/src/layer/vector/CircleMarker.js +16 -3
  170. package/src/layer/vector/Path.ZoomStyles.js +5 -3
  171. package/src/layer/vector/Path.js +11 -5
  172. package/src/layer/vector/Polygon.js +11 -10
  173. package/src/layer/vector/Polyline.js +20 -21
  174. package/src/layer/vector/Renderer.getRenderer.js +2 -1
  175. package/src/layer/vector/Renderer.js +21 -3
  176. package/src/layer/vector/SVG.js +3 -3
  177. package/src/map/Map.Rotation.js +13 -9
  178. package/src/map/Map.js +195 -83
  179. package/src/map/MapSync.js +2 -2
  180. package/src/map/handler/BoxZoomHandler.js +5 -0
  181. package/src/map/handler/DisplaceHandler.js +53 -7
  182. package/src/map/handler/DragHandler.js +5 -5
  183. package/src/map/handler/KeyboardHandler.js +5 -10
  184. package/src/map/handler/PinchZoomHandler.js +4 -4
  185. package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
  186. package/src/map/handler/TapDragZoomHandler.js +2 -2
  187. package/src/map/handler/TapHoldHandler.js +13 -25
  188. package/src/maplair.css +50 -10
  189. package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
  190. package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
  191. package/src/dom/DomEvent.DoubleTap.js +0 -143
@@ -1,5 +1,5 @@
1
1
  /* @preserve
2
- * Maplair 4.3.0, a JS library for interactive maps. https://maplair.org
2
+ * Maplair 4.5.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.3.0";
21
+ var version$1 = "4.5.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
@@ -141,7 +153,7 @@
141
153
  }
142
154
  return defaults;
143
155
  }
144
- const templateRe = /\{ *([\w_ -]+) *\}/g;
156
+ const templateRe = /\{ *([\w_ -]+?) *\}/g;
145
157
  /**
146
158
  * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`
147
159
  * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string
@@ -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.
@@ -536,19 +543,21 @@
536
543
  * `scale`. In linear algebra terms, multiply the point by the
537
544
  * [scaling matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation)
538
545
  * defined by `scale`.
539
- * @param {Point} point The scale.
546
+ * @param {PointExpression} point The scale.
540
547
  * @returns {Point}
541
548
  */
542
549
  scaleBy(point) {
550
+ point = Point.from(point);
543
551
  return new Point(this.x * point.x, this.y * point.y);
544
552
  }
545
553
  /**
546
554
  * Inverse of `scaleBy`. Divide each coordinate of the current point by
547
555
  * each coordinate of `scale`.
548
- * @param {Point} point The scale.
556
+ * @param {PointExpression} point The scale.
549
557
  * @returns {Point}
550
558
  */
551
559
  unscaleBy(point) {
560
+ point = Point.from(point);
552
561
  return new Point(this.x / point.x, this.y / point.y);
553
562
  }
554
563
  /**
@@ -637,100 +646,16 @@
637
646
  return `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;
638
647
  }
639
648
  };
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
649
  // src/dom/DomEvent.PointerEvents.js
728
650
  var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
729
651
  disablePointerDetection: () => disablePointerDetection,
730
652
  enablePointerDetection: () => enablePointerDetection,
731
- getPointers: () => getPointers
653
+ getPointers: () => getPointers,
654
+ isClickDisabled: () => isClickDisabled,
655
+ simulateDblclick: () => simulateDblclick
732
656
  });
733
657
  const activePointers = /* @__PURE__ */ new Map();
658
+ let lastPointerType;
734
659
  /**
735
660
  * Enables pointer detection and capture for the document.
736
661
  * @group Pointer detection
@@ -756,7 +681,24 @@
756
681
  el.removeEventListener("pointerup", _onDelete, { capture: true });
757
682
  el.removeEventListener("pointercancel", _onDelete, { capture: true });
758
683
  }
684
+ /**
685
+ * Whether `el` is inside an element that `DomEvent.disableClickPropagation` was called
686
+ * on (before reaching `container`), or detached from the DOM.
687
+ * @internal
688
+ * @param {Node|null} el
689
+ * @param {EventTarget|null} container
690
+ * @returns {boolean}
691
+ */
692
+ function isClickDisabled(el, container) {
693
+ while (el && el !== container) {
694
+ if (el["_maplair_disable_click"] || !el.parentNode) return true;
695
+ el = el.parentNode;
696
+ }
697
+ return false;
698
+ }
759
699
  function _onSet(e) {
700
+ lastPointerType = e.pointerType;
701
+ if (isClickDisabled(e.target, e.currentTarget)) return;
760
702
  if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
761
703
  activePointers.set(e.pointerId, e);
762
704
  }
@@ -775,6 +717,56 @@
775
717
  function getPointers() {
776
718
  return [...activePointers.values()];
777
719
  }
720
+ const dblclickProps = [
721
+ "bubbles",
722
+ "cancelable",
723
+ "composed",
724
+ "view",
725
+ "screenX",
726
+ "screenY",
727
+ "clientX",
728
+ "clientY",
729
+ "ctrlKey",
730
+ "shiftKey",
731
+ "altKey",
732
+ "metaKey",
733
+ "button",
734
+ "buttons",
735
+ "relatedTarget"
736
+ ];
737
+ let lastClickTime = 0;
738
+ let lastClick;
739
+ let lastClickMap;
740
+ let clickCount = 0;
741
+ /**
742
+ * Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),
743
+ * which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The
744
+ * pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on
745
+ * clicks from touch (WebKit bug 282988). Called by the map for clicks in it.
746
+ * @internal
747
+ * @param {MouseEvent} e
748
+ * @param {HTMLElement} mapContainer The container of the map, two taps make a double
749
+ * tap only in the same map.
750
+ * @returns {void}
751
+ */
752
+ function simulateDblclick(e, mapContainer) {
753
+ if (e === lastClick) return;
754
+ lastClick = e;
755
+ const target = e.target;
756
+ if (e.detail !== 1 || lastPointerType === "mouse" || target.closest("label")) {
757
+ clickCount = 0;
758
+ return;
759
+ }
760
+ const now = Date.now();
761
+ clickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;
762
+ lastClickTime = now;
763
+ lastClickMap = mapContainer;
764
+ if (clickCount === 2) {
765
+ const init = { detail: 2 };
766
+ for (const prop of dblclickProps) init[prop] = e[prop];
767
+ target.dispatchEvent(new MouseEvent("dblclick", init));
768
+ }
769
+ }
778
770
  // src/dom/DomEvent.js
779
771
  var DomEvent_exports = /* @__PURE__ */ __exportAll({
780
772
  PointerEvents: () => DomEvent_PointerEvents_exports,
@@ -842,11 +834,10 @@
842
834
  function addOne(obj, type, fn, context) {
843
835
  const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
844
836
  if (obj[eventsKey] && obj[eventsKey][id]) return;
845
- let handler = function(e) {
837
+ const handler = function(e) {
846
838
  return fn.call(context || obj, e);
847
839
  };
848
- if (type === "dblclick") handler = addDoubleTapListener(obj, handler);
849
- else obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
840
+ obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
850
841
  obj[eventsKey] ??= {};
851
842
  obj[eventsKey][id] = handler;
852
843
  }
@@ -854,8 +845,7 @@
854
845
  id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
855
846
  const handler = obj[eventsKey] && obj[eventsKey][id];
856
847
  if (!handler) return;
857
- if (type === "dblclick") removeDoubleTapListener(obj, handler);
858
- else obj.removeEventListener(type, handler, false);
848
+ obj.removeEventListener(type, handler, false);
859
849
  obj[eventsKey][id] = null;
860
850
  }
861
851
  /**
@@ -941,7 +931,7 @@
941
931
  * @returns {number}
942
932
  */
943
933
  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;
934
+ return -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;
945
935
  }
946
936
  /**
947
937
  * Checks if the pointer really left/entered the element `el` (for
@@ -988,7 +978,7 @@
988
978
  function create(tagName, className, container) {
989
979
  const el = document.createElement(tagName);
990
980
  el.className = className ?? "";
991
- container?.appendChild(el);
981
+ container?.append(el);
992
982
  return el;
993
983
  }
994
984
  /**
@@ -1000,8 +990,8 @@
1000
990
  function toFront(el) {
1001
991
  const parent = el.parentNode;
1002
992
  if (!parent || parent.lastChild === el) return;
1003
- if (el.matches(":hover")) while (el.nextSibling) parent.insertBefore(el.nextSibling, el);
1004
- else parent.appendChild(el);
993
+ if (el.matches(":hover")) while (el.nextSibling) el.before(el.nextSibling);
994
+ else parent.append(el);
1005
995
  }
1006
996
  /**
1007
997
  * Makes `el` the first child of its parent, so it renders behind the other children.
@@ -1011,8 +1001,8 @@
1011
1001
  function toBack(el) {
1012
1002
  const parent = el.parentNode;
1013
1003
  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);
1004
+ if (el.matches(":hover")) while (el.previousSibling) el.after(el.previousSibling);
1005
+ else parent.prepend(el);
1016
1006
  }
1017
1007
  /**
1018
1008
  * Resets the 3D CSS transform of `el` so it is translated by `offset` pixels
@@ -1151,12 +1141,16 @@
1151
1141
  * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that
1152
1142
  * removes the listeners previously added in `onAdd`. Called on
1153
1143
  * [`control.remove()`](#control-remove).
1144
+ * @property {() => Record<string, Function>} [getEvents] Should return an object like
1145
+ * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this object
1146
+ * will be automatically added and removed from the map with your control.
1154
1147
  * @lends Control
1155
1148
  */
1156
1149
  const controlOrders = /* @__PURE__ */ new WeakMap();
1157
1150
  /**
1158
- * Control is a base class for implementing map controls. Handles positioning.
1159
- * All other controls extend from this class.
1151
+ * Base class for map controls such as `ZoomControl`, `AttributionControl`,
1152
+ * `LayersControl` and `ScaleControl`, which handles positioning them. Extend it to
1153
+ * create your own controls.
1160
1154
  *
1161
1155
  * Every control should extend from `Control` and (re-)implement the following methods:
1162
1156
  *
@@ -1166,6 +1160,9 @@
1166
1160
  * * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes
1167
1161
  * the listeners previously added in [`onAdd`](#control-onadd). Called on
1168
1162
  * [`control.remove()`](#control-remove).
1163
+ * * `getEvents(): Object` (optional) should return an object like
1164
+ * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this
1165
+ * object will be automatically added and removed from the map with your control.
1169
1166
  */
1170
1167
  var Control = class Control extends Class {
1171
1168
  static defaultOptions = {
@@ -1219,7 +1216,11 @@
1219
1216
  const order = this.options.order ?? 0, bottom = pos.includes("bottom"), children = [...corner.children];
1220
1217
  controlOrders.set(container, order);
1221
1218
  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);
1219
+ this._mapEvents = {
1220
+ ...this.getEvents?.(),
1221
+ unload: this.remove
1222
+ };
1223
+ map.on(this._mapEvents, this);
1223
1224
  return this;
1224
1225
  }
1225
1226
  /**
@@ -1229,17 +1230,11 @@
1229
1230
  remove() {
1230
1231
  if (!this._map) return this;
1231
1232
  this._container.remove();
1232
- if (this.onRemove) this.onRemove(this._map);
1233
- this._map.off("unload", this.remove, this);
1233
+ this._map.off(this._mapEvents, this);
1234
+ this.onRemove?.(this._map);
1234
1235
  this._map = null;
1235
1236
  return this;
1236
1237
  }
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
1238
  /**
1244
1239
  * Registers this default feature on the map class, called by `MaplairMap` itself.
1245
1240
  * @internal
@@ -1372,6 +1367,7 @@
1372
1367
  this._attributions = {};
1373
1368
  this._orders = {};
1374
1369
  this._layerAttributions = /* @__PURE__ */ new Map();
1370
+ this._shownLayers = /* @__PURE__ */ new Set();
1375
1371
  this.callInitHooks(AttributionControl);
1376
1372
  }
1377
1373
  /**
@@ -1385,33 +1381,50 @@
1385
1381
  disableClickPropagation(this._container);
1386
1382
  if (map._loaded) map.eachLayer((layer) => this._addLayer({ layer }));
1387
1383
  this._update();
1388
- map.on({
1389
- layeradd: this._addLayer,
1390
- layerremove: this._removeLayer
1391
- }, this);
1392
1384
  return this._container;
1393
1385
  }
1394
1386
  /**
1395
1387
  * @internal
1396
- * @param {MaplairMap} map
1388
+ * @returns {Record<string, Function>}
1397
1389
  */
1398
- onRemove(map) {
1399
- map.off({
1390
+ getEvents() {
1391
+ return {
1400
1392
  layeradd: this._addLayer,
1401
- layerremove: this._removeLayer
1402
- }, this);
1393
+ layerremove: this._removeLayer,
1394
+ zoomend: this._onZoomEnd
1395
+ };
1396
+ }
1397
+ /**
1398
+ * @internal
1399
+ */
1400
+ onRemove() {
1403
1401
  for (const layer of this._layerAttributions.keys()) this._removeLayer({ layer });
1404
1402
  }
1405
1403
  _addLayer({ layer }) {
1406
1404
  const text = layer.getAttribution?.();
1407
1405
  if (!text || this._layerAttributions.has(layer)) return;
1408
1406
  this._layerAttributions.set(layer, text);
1409
- this.addAttribution(text, layer.options?.attributionOrder);
1407
+ this._updateLayer(layer);
1410
1408
  }
1411
1409
  _removeLayer({ layer }) {
1412
- this.removeAttribution(this._layerAttributions.get(layer));
1410
+ if (this._shownLayers.delete(layer)) this.removeAttribution(this._layerAttributions.get(layer));
1413
1411
  this._layerAttributions.delete(layer);
1414
1412
  }
1413
+ _onZoomEnd() {
1414
+ for (const layer of this._layerAttributions.keys()) this._updateLayer(layer);
1415
+ }
1416
+ _updateLayer(layer) {
1417
+ const { minZoom = -Infinity, maxZoom = Infinity } = layer.options ?? {}, zoom = this._map.getZoom(), show = zoom >= minZoom && zoom <= maxZoom;
1418
+ if (show === this._shownLayers.has(layer)) return;
1419
+ const text = this._layerAttributions.get(layer);
1420
+ if (show) {
1421
+ this._shownLayers.add(layer);
1422
+ this.addAttribution(text, layer.options?.attributionOrder);
1423
+ } else {
1424
+ this._shownLayers.delete(layer);
1425
+ this.removeAttribution(text);
1426
+ }
1427
+ }
1415
1428
  /**
1416
1429
  * The HTML text shown before the attributions. Pass `false` to disable.
1417
1430
  * @param {string|false} prefix
@@ -1433,8 +1446,7 @@
1433
1446
  addAttribution(text, order = 0) {
1434
1447
  if (!text) return this;
1435
1448
  this._orders[text] = order;
1436
- if (!this._attributions[text]) this._attributions[text] = 0;
1437
- this._attributions[text]++;
1449
+ this._attributions[text] = (this._attributions[text] || 0) + 1;
1438
1450
  this._update();
1439
1451
  return this;
1440
1452
  }
@@ -1569,7 +1581,6 @@
1569
1581
  disableClickPropagation(button);
1570
1582
  on(button, "click", stop);
1571
1583
  on(button, "click", this._onClick, this);
1572
- on(button, "click", this._refocusOnMap, this);
1573
1584
  this._update();
1574
1585
  return button;
1575
1586
  }
@@ -1931,8 +1942,9 @@
1931
1942
  };
1932
1943
  if (_once) newListener.once = true;
1933
1944
  this._events ??= {};
1934
- this._events[type] ??= /* @__PURE__ */ new Set();
1935
- this._events[type].add(newListener);
1945
+ let listeners = this._events[type] ??= /* @__PURE__ */ new Set();
1946
+ if (this._firingCount) this._events[type] = listeners = new Set(listeners);
1947
+ listeners.add(newListener);
1936
1948
  if (contexts) contexts.set(context, newListener);
1937
1949
  else this._listenerIndex[type].set(fn, /* @__PURE__ */ new Map([[context, newListener]]));
1938
1950
  }
@@ -2207,13 +2219,13 @@
2207
2219
  const oldZoomSpan = this._getZoomSpan();
2208
2220
  for (const l of Object.values(this._zoomBoundLayers)) {
2209
2221
  const options = l.options;
2210
- minZoom = Math.min(minZoom, options.minZoom ?? Infinity);
2211
- maxZoom = Math.max(maxZoom, options.maxZoom ?? -Infinity);
2222
+ if (options.minZoom != null && !Number.isNaN(options.minZoom)) minZoom = Math.min(minZoom, options.minZoom);
2223
+ if (options.maxZoom != null && !Number.isNaN(options.maxZoom)) maxZoom = Math.max(maxZoom, options.maxZoom);
2212
2224
  }
2213
2225
  this._layersMaxZoom = maxZoom === -Infinity ? void 0 : maxZoom;
2214
2226
  this._layersMinZoom = minZoom === Infinity ? void 0 : minZoom;
2215
2227
  if (oldZoomSpan !== this._getZoomSpan()) this.fire("zoomlevelschange");
2216
- if (this.options.maxZoom === void 0 && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) this.setZoom(this._layersMaxZoom);
2228
+ if (this.options.maxZoom === void 0 && this._layersMaxZoom !== void 0 && this.getZoom() > this._layersMaxZoom) this.setZoom(this._layersMaxZoom);
2217
2229
  if (this.options.minZoom === void 0 && this._layersMinZoom && this.getZoom() < this._layersMinZoom) this.setZoom(this._layersMinZoom);
2218
2230
  }
2219
2231
  };
@@ -2330,8 +2342,10 @@
2330
2342
  }
2331
2343
  _updateInteractive() {}
2332
2344
  /**
2333
- * Makes `targetEl` a target of pointer events of this layer.
2334
- * @internal
2345
+ * Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and
2346
+ * keyboard events on it (or its descendants) fire on the layer and bubble through its
2347
+ * parent groups to the map, the way they do for markers and paths. Custom layers call
2348
+ * it in [`onAdd`](#layer-onadd), once the layer is on a map.
2335
2349
  * @param {HTMLElement} targetEl
2336
2350
  * @returns {this}
2337
2351
  */
@@ -2340,8 +2354,8 @@
2340
2354
  return this;
2341
2355
  }
2342
2356
  /**
2343
- * Stops `targetEl` from being a target of pointer events of this layer.
2344
- * @internal
2357
+ * Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in
2358
+ * [`onRemove`](#layer-onremove).
2345
2359
  * @param {HTMLElement} targetEl
2346
2360
  * @returns {this}
2347
2361
  */
@@ -2349,6 +2363,9 @@
2349
2363
  delete this._map._targets[stamp(targetEl)];
2350
2364
  return this;
2351
2365
  }
2366
+ _togglesPopupOnClick() {
2367
+ return true;
2368
+ }
2352
2369
  /**
2353
2370
  * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).
2354
2371
  * @returns {string|null}
@@ -2516,7 +2533,7 @@
2516
2533
  }
2517
2534
  _createMenu(parent) {
2518
2535
  const container = this._container ??= create("div", `maplair-contextmenu ${this.options.className}`);
2519
- if (container.parentNode !== parent) parent.appendChild(container);
2536
+ if (container.parentNode !== parent) parent.append(container);
2520
2537
  container.popover = "auto";
2521
2538
  container.setAttribute("role", "menu");
2522
2539
  container.replaceChildren();
@@ -2683,7 +2700,6 @@
2683
2700
  disableClickPropagation(button);
2684
2701
  on(button, "click", stop);
2685
2702
  on(button, "click", this._toggleFullscreen, this);
2686
- on(button, "click", this._refocusOnMap, this);
2687
2703
  this._update();
2688
2704
  map.on("fullscreenchange", this._update, this);
2689
2705
  return container;
@@ -2767,6 +2783,8 @@
2767
2783
  * `maplair-control-layers-group-name` element, and each entry shows only its label.
2768
2784
  * Events like `baselayerchange` still carry the full `name`. When combined with
2769
2785
  * `sortLayers`, the entries are sorted first and grouped afterwards.
2786
+ * @property {string} [title] The title of the toggle button and the accessible label
2787
+ * of the layers list, the translation of `'Layers'` by default.
2770
2788
  * @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
2771
2789
  * collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
2772
2790
  * element. String content is rendered as HTML; do not pass untrusted input.
@@ -2851,6 +2869,7 @@
2851
2869
  collapsed: true,
2852
2870
  inline: false,
2853
2871
  groupBy: void 0,
2872
+ title: void 0,
2854
2873
  toggleContent: void 0,
2855
2874
  collapseDelay: 0,
2856
2875
  position: "topright",
@@ -2877,6 +2896,7 @@
2877
2896
  this._lastZIndex = 0;
2878
2897
  this._handlingClick = false;
2879
2898
  this._preventClick = false;
2899
+ this._needsUpdate = false;
2880
2900
  for (const [name, layer] of Object.entries(baseLayers ?? {})) this._addLayer(layer, name);
2881
2901
  for (const [name, layer] of Object.entries(overlays ?? {})) this._addLayer(layer, name, true);
2882
2902
  this.callInitHooks(LayersControl);
@@ -2962,6 +2982,7 @@
2962
2982
  * @returns {this}
2963
2983
  */
2964
2984
  selectLayer(layer) {
2985
+ if (this._needsUpdate) this._update(true);
2965
2986
  const input = this._layerControlInputs.find((input) => input._layer === layer);
2966
2987
  if (input && !input.checked) {
2967
2988
  input.checked = true;
@@ -2976,6 +2997,7 @@
2976
2997
  expand() {
2977
2998
  clearTimeout(this._collapseDelayTimeout);
2978
2999
  this._container.classList.add("maplair-control-layers-expanded");
3000
+ if (this._needsUpdate) this._update();
2979
3001
  this._section.style.height = "";
2980
3002
  const acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
2981
3003
  if (acceptableHeight < this._section.clientHeight) {
@@ -2991,19 +3013,40 @@
2991
3013
  */
2992
3014
  collapse() {
2993
3015
  if (this.options.inline) return this;
3016
+ clearTimeout(this._collapseDelayTimeout);
2994
3017
  if (this.options.collapseDelay > 0) this._collapseDelayTimeout = setTimeout(() => {
2995
3018
  this._container.classList.remove("maplair-control-layers-expanded");
2996
3019
  }, this.options.collapseDelay);
2997
3020
  else this._container.classList.remove("maplair-control-layers-expanded");
2998
3021
  return this;
2999
3022
  }
3023
+ _getTitle() {
3024
+ return this.options.title ?? I18n.translate("Layers");
3025
+ }
3000
3026
  _initLayout() {
3001
3027
  const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this._isCollapsible();
3002
3028
  if (this.options.inline) container.classList.add(`${className}-inline`);
3003
3029
  disableClickPropagation(container);
3004
3030
  disableScrollPropagation(container);
3005
3031
  const section = this._section = create("fieldset", `${className}-list`);
3006
- section.setAttribute("aria-label", I18n.translate("Layers"));
3032
+ section.setAttribute("aria-label", this._getTitle());
3033
+ section.tabIndex = -1;
3034
+ let link;
3035
+ if (!this.options.inline) {
3036
+ link = this._layersLink = create("button", `${className}-toggle`, container);
3037
+ link.type = "button";
3038
+ link.title = this._getTitle();
3039
+ link.setAttribute("aria-label", link.title);
3040
+ const { toggleContent } = this.options;
3041
+ if (typeof toggleContent === "string") link.innerHTML = toggleContent;
3042
+ else if (toggleContent) link.replaceChildren(toggleContent);
3043
+ on(link, "click", (e) => {
3044
+ e.preventDefault();
3045
+ const focused = document.activeElement === link;
3046
+ this._expandSafely();
3047
+ if (focused) section.focus();
3048
+ });
3049
+ }
3007
3050
  if (collapsed) {
3008
3051
  this._map.on("click", this.collapse, this);
3009
3052
  on(container, {
@@ -3012,30 +3055,19 @@
3012
3055
  if (e.pointerType !== "touch") this.collapse();
3013
3056
  }
3014
3057
  }, this);
3015
- }
3016
- if (!this.options.inline) {
3017
- const link = this._layersLink = create("button", `${className}-toggle`, container);
3018
- link.type = "button";
3019
- link.title = I18n.translate("Layers");
3020
- link.setAttribute("aria-label", I18n.translate("Layers"));
3021
- const { toggleContent } = this.options;
3022
- if (typeof toggleContent === "string") link.innerHTML = toggleContent;
3023
- else if (toggleContent) link.replaceChildren(toggleContent);
3024
- on(link, {
3025
- keydown(e) {
3026
- if (e.code === "Enter") this._expandSafely();
3027
- },
3028
- click(e) {
3058
+ on(section, "keydown", (e) => {
3059
+ if (e.key === "Escape") {
3060
+ clearTimeout(this._collapseDelayTimeout);
3061
+ container.classList.remove(`${className}-expanded`);
3062
+ link.focus();
3029
3063
  e.preventDefault();
3030
- this._expandSafely();
3031
3064
  }
3032
- }, this);
3033
- }
3034
- if (!collapsed) this.expand();
3065
+ });
3066
+ } else this.expand();
3035
3067
  this._baseLayersList = create("div", `${className}-base`, section);
3036
3068
  this._separator = create("div", `${className}-separator`, section);
3037
3069
  this._overlaysList = create("div", `${className}-overlays`, section);
3038
- container.appendChild(section);
3070
+ container.append(section);
3039
3071
  }
3040
3072
  _addLayer(layer, name, overlay) {
3041
3073
  if (this._map) layer.on("add remove", this._onLayerChange, this);
@@ -3051,8 +3083,13 @@
3051
3083
  }
3052
3084
  this._expandIfNotCollapsed();
3053
3085
  }
3054
- _update() {
3086
+ _update(force) {
3055
3087
  if (!this._container) return this;
3088
+ if (!force && !this._container.classList.contains("maplair-control-layers-expanded")) {
3089
+ this._needsUpdate = true;
3090
+ return this;
3091
+ }
3092
+ this._needsUpdate = false;
3056
3093
  this._baseLayersList.replaceChildren();
3057
3094
  this._overlaysList.replaceChildren();
3058
3095
  this._layerControlInputs = [];
@@ -3069,6 +3106,7 @@
3069
3106
  this._baseLayersList.style.display = baseLayersPresent ? "" : "none";
3070
3107
  }
3071
3108
  this._separator.style.display = overlaysPresent && baseLayersPresent ? "" : "none";
3109
+ this._checkDisabledLayers();
3072
3110
  return this;
3073
3111
  }
3074
3112
  _onLayerChange(e) {
@@ -3094,12 +3132,10 @@
3094
3132
  const name = document.createElement("span");
3095
3133
  name.innerHTML = ` ${group ? group.label : obj.name}`;
3096
3134
  const holder = document.createElement("span");
3097
- label.appendChild(holder);
3098
- holder.appendChild(input);
3099
- holder.appendChild(name);
3135
+ label.append(holder);
3136
+ holder.append(input, name);
3100
3137
  const list = obj.overlay ? this._overlaysList : this._baseLayersList;
3101
- (group ? this._getGroupContainer(list, group.group) : list).appendChild(label);
3102
- this._checkDisabledLayers();
3138
+ (group ? this._getGroupContainer(list, group.group) : list).append(label);
3103
3139
  return label;
3104
3140
  }
3105
3141
  /**
@@ -3139,7 +3175,6 @@
3139
3175
  this._update();
3140
3176
  break;
3141
3177
  }
3142
- this._refocusOnMap(e);
3143
3178
  }
3144
3179
  _checkDisabledLayers() {
3145
3180
  const inputs = this._layerControlInputs, zoom = this._map.getZoom();
@@ -3332,7 +3367,7 @@
3332
3367
  */
3333
3368
  overlaps(bounds) {
3334
3369
  bounds = Bounds.from(bounds);
3335
- 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;
3370
+ 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);
3336
3371
  return xOverlaps && yOverlaps;
3337
3372
  }
3338
3373
  /**
@@ -3365,7 +3400,7 @@
3365
3400
  }
3366
3401
  };
3367
3402
  function isPointExpression(obj) {
3368
- return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] === "number" : "x" in obj);
3403
+ return obj instanceof Point || (Array.isArray(obj) ? obj.length > 0 && typeof obj[0] !== "object" : "x" in obj);
3369
3404
  }
3370
3405
  // src/layer/BlanketOverlay.js
3371
3406
  /** @import {LayerOptions} from './Layer.js' */
@@ -3428,7 +3463,7 @@
3428
3463
  this._initContainer();
3429
3464
  this._container.classList.add("maplair-zoom-animated");
3430
3465
  }
3431
- this.getPane().appendChild(this._container);
3466
+ this.getPane().append(this._container);
3432
3467
  this._resizeContainer();
3433
3468
  this._onMoveEnd();
3434
3469
  }
@@ -3462,7 +3497,8 @@
3462
3497
  this._updateTransform(this._map.getCenter(), this._map.getZoom());
3463
3498
  }
3464
3499
  _updateTransform(center, zoom) {
3465
- const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map.getSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom))._round();
3500
+ const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map.getSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom));
3501
+ if (scale === 1) this._map._snapLayerPoint(topLeftOffset);
3466
3502
  setTransform(this._container, topLeftOffset, scale);
3467
3503
  }
3468
3504
  _onMoveEnd(ev) {
@@ -3500,6 +3536,8 @@
3500
3536
  /** @import {BlanketOverlayOptions} from '../BlanketOverlay.js' */
3501
3537
  /** @import {MaplairEvent} from '../../core/Events.js' */
3502
3538
  /** @import {MaplairMap} from '../../map/Map.js' */
3539
+ /** @import {LatLngExpression} from '../../geo/LatLng.js' */
3540
+ /** @import {Point} from '../../geometry/Point.js' */
3503
3541
  /**
3504
3542
  * Options of `Renderer`, `SVG` and `Canvas`. The `continuous` option inherited from
3505
3543
  * `BlanketOverlay` cannot be set to `true`.
@@ -3541,6 +3579,7 @@
3541
3579
  * @param {MaplairMap} map
3542
3580
  */
3543
3581
  onAdd(map) {
3582
+ this._setPathView();
3544
3583
  super.onAdd(map);
3545
3584
  this.on("update", this._updatePaths, this);
3546
3585
  }
@@ -3552,12 +3591,25 @@
3552
3591
  this.off("update", this._updatePaths, this);
3553
3592
  }
3554
3593
  _onZoomEnd() {
3594
+ this._setPathView();
3555
3595
  for (const layer of Object.values(this._layers)) layer._project();
3556
3596
  }
3597
+ _setPathView() {
3598
+ this._pathZoom = this._map.getZoom();
3599
+ this._pathOrigin = this._map.getPixelOrigin();
3600
+ }
3601
+ /**
3602
+ * @param {LatLngExpression} latlng
3603
+ * @returns {Point}
3604
+ */
3605
+ _latLngToLayerPoint(latlng) {
3606
+ return this._map.project(latlng, this._pathZoom)._subtract(this._pathOrigin);
3607
+ }
3557
3608
  _updatePaths() {
3558
3609
  for (const layer of Object.values(this._layers)) layer._update();
3559
3610
  }
3560
3611
  _onViewReset() {
3612
+ this._setPathView();
3561
3613
  for (const layer of Object.values(this._layers)) layer._reset();
3562
3614
  }
3563
3615
  _onSettled() {
@@ -3607,7 +3659,7 @@
3607
3659
  this._container = SVG.create("svg");
3608
3660
  this._container.setAttribute("pointer-events", "none");
3609
3661
  this._rootGroup = SVG.create("g");
3610
- this._container.appendChild(this._rootGroup);
3662
+ this._container.append(this._rootGroup);
3611
3663
  }
3612
3664
  _destroyContainer() {
3613
3665
  super._destroyContainer();
@@ -3616,7 +3668,7 @@
3616
3668
  }
3617
3669
  _resizeContainer() {
3618
3670
  const size = super._resizeContainer();
3619
- if (!this._svgSize || !this._svgSize.equals(size)) {
3671
+ if (!this._svgSize?.equals(size)) {
3620
3672
  this._svgSize = size;
3621
3673
  this._container.setAttribute("width", `${size.x}`);
3622
3674
  this._container.setAttribute("height", `${size.y}`);
@@ -3652,7 +3704,7 @@
3652
3704
  }
3653
3705
  _addPath(layer) {
3654
3706
  if (!this._rootGroup) this._initContainer();
3655
- this._rootGroup.appendChild(layer._path);
3707
+ this._rootGroup.append(layer._path);
3656
3708
  layer.addInteractiveTarget(layer._path);
3657
3709
  }
3658
3710
  _removePath(layer) {
@@ -3761,13 +3813,15 @@
3761
3813
  * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
3762
3814
  * afterwards.
3763
3815
  * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
3764
- * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),
3765
- * which is `SVG` by default. If set, it overrides the `pane` option.
3816
+ * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
3817
+ * (`SVG` by default), or in a custom pane, a renderer of the same kind created for
3818
+ * that pane. If set, it overrides the `pane` option.
3766
3819
  * @extends InteractiveLayerOptions
3767
3820
  */
3768
3821
  /**
3769
- * An abstract class that contains options and constants shared between vector
3770
- * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
3822
+ * An abstract class that contains options and methods shared between vector overlays
3823
+ * (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it
3824
+ * directly. Extends `Layer`.
3771
3825
  */
3772
3826
  var Path = class extends Layer {
3773
3827
  static defaultOptions = {
@@ -3864,8 +3918,11 @@
3864
3918
  this._project();
3865
3919
  this._update();
3866
3920
  }
3921
+ _togglesPopupOnClick() {
3922
+ return false;
3923
+ }
3867
3924
  _clickTolerance() {
3868
- return (this.options.stroke ? this.options.weight / 2 : 0) + (this._renderer.options.tolerance || 0);
3925
+ return (this.options.stroke ? this.options.weight / 2 || 0 : 0) + (this._renderer.options.tolerance || 0);
3869
3926
  }
3870
3927
  };
3871
3928
  // src/geo/LatLngBounds.js
@@ -3953,7 +4010,7 @@
3953
4010
  ({_southWest: sw2, _northEast: ne2} = obj);
3954
4011
  if (!sw2) return this;
3955
4012
  } else if (!obj) return this;
3956
- else if (LatLng.validate(obj)) sw2 = ne2 = LatLng.from(obj);
4013
+ else if (isLatLngExpression(obj)) sw2 = ne2 = LatLng.from(obj);
3957
4014
  else return this.extend(LatLngBounds.from(obj));
3958
4015
  if (!sw) {
3959
4016
  this._southWest = new LatLng(sw2.lat, sw2.lng);
@@ -4046,7 +4103,7 @@
4046
4103
  * @returns {boolean}
4047
4104
  */
4048
4105
  contains(obj) {
4049
- if (LatLng.validate(obj)) obj = LatLng.from(obj);
4106
+ if (isLatLngExpression(obj)) obj = LatLng.from(obj);
4050
4107
  else obj = LatLngBounds.from(obj);
4051
4108
  const sw = this._southWest, ne = this._northEast;
4052
4109
  let sw2, ne2;
@@ -4075,7 +4132,7 @@
4075
4132
  */
4076
4133
  overlaps(bounds) {
4077
4134
  bounds = LatLngBounds.from(bounds);
4078
- 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;
4135
+ 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);
4079
4136
  return latOverlaps && lngOverlaps;
4080
4137
  }
4081
4138
  /**
@@ -4113,6 +4170,9 @@
4113
4170
  return !!(this._southWest && this._northEast);
4114
4171
  }
4115
4172
  };
4173
+ function isLatLngExpression(obj) {
4174
+ return obj instanceof LatLng || (Array.isArray(obj) ? obj.length > 0 && typeof obj[0] !== "object" : typeof obj === "object" && obj !== null && "lat" in obj);
4175
+ }
4116
4176
  // src/geo/LatLng.js
4117
4177
  const coordinate = String.raw`([+-]?\d+(?:\.\d+)?)\s*°?`;
4118
4178
  const separator = String.raw`(?:\s*[,;]\s*|\s+)`;
@@ -4162,46 +4222,36 @@
4162
4222
  * @param {number} [alt] Altitude in meters.
4163
4223
  */
4164
4224
  constructor(lat, lng, alt) {
4165
- if (!LatLng.validate(lat, lng, alt)) throw new Error(`Invalid LatLng object: (${lat}, ${lng})`);
4166
- let _lat, _lng, _alt;
4167
- if (lat instanceof LatLng) {
4168
- _lat = lat.lat;
4169
- _lng = lat.lng;
4170
- _alt = lat.alt;
4171
- } else if (Array.isArray(lat) && typeof lat[0] !== "object") {
4172
- if (lat.length === 3) {
4173
- _lat = lat[0];
4174
- _lng = lat[1];
4175
- _alt = lat[2];
4176
- } else if (lat.length === 2) {
4177
- _lat = lat[0];
4178
- _lng = lat[1];
4179
- }
4180
- } else if (typeof lat === "object" && "lat" in lat) {
4225
+ let _lat = lat, _lng = lng, _alt = alt;
4226
+ if (lat instanceof LatLng) ({lat: _lat, lng: _lng, alt: _alt} = lat);
4227
+ else if (Array.isArray(lat)) {
4228
+ _lat = lat.length <= 3 ? lat[0] : NaN;
4229
+ _lng = lat[1];
4230
+ _alt = lat[2];
4231
+ } else if (typeof lat === "object" && lat !== null) {
4181
4232
  _lat = lat.lat;
4182
4233
  _lng = "lng" in lat ? lat.lng : lat.lon;
4183
4234
  _alt = lat.alt;
4184
- } else {
4185
- _lat = lat;
4186
- _lng = lng;
4187
- _alt = alt;
4188
4235
  }
4189
4236
  /**
4190
4237
  * Latitude in degrees.
4191
4238
  * @type {number}
4192
4239
  */
4193
- this.lat = +_lat;
4240
+ this.lat = toNumber(_lat);
4194
4241
  /**
4195
4242
  * Longitude in degrees.
4196
4243
  * @type {number}
4197
4244
  */
4198
- this.lng = +_lng;
4199
- if (_alt !== void 0)
4200
- /**
4201
- * Altitude in meters (optional).
4202
- * @type {number|undefined}
4203
- */
4204
- this.alt = +_alt;
4245
+ this.lng = toNumber(_lng);
4246
+ if (isNaN(this.lat) || isNaN(this.lng)) throw new Error(`Invalid LatLng object: (${_lat}, ${_lng})`);
4247
+ if (_alt != null) {
4248
+ /**
4249
+ * Altitude in meters (optional).
4250
+ * @type {number|undefined}
4251
+ */
4252
+ this.alt = toNumber(_alt);
4253
+ if (isNaN(this.alt)) throw new Error(`Invalid LatLng altitude: ${_alt}`);
4254
+ }
4205
4255
  }
4206
4256
  /**
4207
4257
  * Returns the given `LatLng` object as it is, or else a new `LatLng` object created
@@ -4230,12 +4280,11 @@
4230
4280
  * @returns {boolean}
4231
4281
  */
4232
4282
  static validate(lat, lng, alt) {
4233
- if (lat instanceof LatLng || typeof lat === "object" && lat !== null && "lat" in lat) return true;
4234
- else if (lat && Array.isArray(lat) && typeof lat[0] !== "object") {
4235
- if (lat.length === 3 || lat.length === 2) return true;
4283
+ try {
4284
+ return !!new LatLng(lat, lng, alt);
4285
+ } catch {
4236
4286
  return false;
4237
- } else if ((lat || lat === 0) && (lng || lng === 0)) return true;
4238
- return false;
4287
+ }
4239
4288
  }
4240
4289
  /**
4241
4290
  * Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.
@@ -4330,7 +4379,7 @@
4330
4379
  * @returns {number}
4331
4380
  */
4332
4381
  function haversineDistance(latlng1, latlng2, R) {
4333
- const rad = Math.PI / 180, lat1 = latlng1.lat * rad, lat2 = latlng2.lat * rad, sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2), sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2), a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon;
4382
+ const rad = Math.PI / 180, lat1 = latlng1.lat * rad, lat2 = latlng2.lat * rad, sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2), sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2), a = Math.min(sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon, 1);
4334
4383
  return R * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
4335
4384
  }
4336
4385
  // src/geometry/LineUtil.js
@@ -4625,6 +4674,7 @@
4625
4674
  });
4626
4675
  }
4627
4676
  // src/layer/vector/CircleMarker.js
4677
+ /** @import {MaplairMap} from '../../map/Map.js' */
4628
4678
  /** @import {Feature} from 'geojson' */
4629
4679
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
4630
4680
  /** @import {MaplairEvent} from '../../core/Events.js' */
@@ -4665,10 +4715,17 @@
4665
4715
  super();
4666
4716
  setOptions(this, options);
4667
4717
  this._latlng = new LatLng(latlng);
4668
- this._radius = this.options.radius;
4718
+ this.setRadius(this.options.radius);
4669
4719
  this.callInitHooks(CircleMarker);
4670
4720
  }
4671
4721
  /**
4722
+ * @param {MaplairMap} map
4723
+ */
4724
+ beforeAdd(map) {
4725
+ super.beforeAdd(map);
4726
+ map._displaceHandler?._beforeMarkerAdd(this);
4727
+ }
4728
+ /**
4672
4729
  * Sets the position of a circle marker to a new location.
4673
4730
  * @param {LatLngExpression} latlng
4674
4731
  * @returns {this}
@@ -4695,7 +4752,10 @@
4695
4752
  * @returns {this}
4696
4753
  */
4697
4754
  setRadius(radius) {
4698
- this.options.radius = this._radius = radius;
4755
+ const r = toNumber(radius);
4756
+ if (isNaN(r)) throw new Error(`Invalid radius: ${radius}`);
4757
+ /** @type {number} */
4758
+ this._radius = this.options.radius = r;
4699
4759
  return this.redraw();
4700
4760
  }
4701
4761
  /**
@@ -4716,7 +4776,7 @@
4716
4776
  return this;
4717
4777
  }
4718
4778
  _project() {
4719
- this._point = this._map.latLngToLayerPoint(this._latlng)._round();
4779
+ this._point = this._renderer._latLngToLayerPoint(this._latlng)._round();
4720
4780
  this._pxRadius = this._radius;
4721
4781
  this._updateBounds();
4722
4782
  }
@@ -5193,13 +5253,7 @@
5193
5253
  * @param {number} [d]
5194
5254
  */
5195
5255
  constructor(a, b, c, d) {
5196
- if (Array.isArray(a)) {
5197
- this._a = a[0];
5198
- this._b = a[1];
5199
- this._c = a[2];
5200
- this._d = a[3];
5201
- return;
5202
- }
5256
+ if (Array.isArray(a)) [a, b, c, d] = a;
5203
5257
  this._a = a;
5204
5258
  this._b = b;
5205
5259
  this._c = c;
@@ -5343,10 +5397,10 @@
5343
5397
  * @property {string} [position='topleft'] The position of the control (one of the map
5344
5398
  * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
5345
5399
  * `'bottomright'`.
5346
- * @property {string} [zoomInText='<span aria-hidden="true">+</span>'] The text set on
5347
- * the 'zoom in' button.
5348
- * @property {string} [zoomOutText='<span aria-hidden="true">&#x2212;</span>'] The text
5349
- * set on the 'zoom out' button.
5400
+ * @property {string} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn
5401
+ * in SVG by default.
5402
+ * @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign
5403
+ * drawn in SVG by default.
5350
5404
  * @extends ControlOptions
5351
5405
  */
5352
5406
  /**
@@ -5370,8 +5424,8 @@
5370
5424
  var ZoomControl = class ZoomControl extends Control {
5371
5425
  static defaultOptions = {
5372
5426
  position: "topleft",
5373
- zoomInText: "<span aria-hidden=\"true\">+</span>",
5374
- zoomOutText: "<span aria-hidden=\"true\">&#x2212;</span>"
5427
+ zoomInText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12M6 0v12\"/></svg>",
5428
+ zoomOutText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12\"/></svg>"
5375
5429
  };
5376
5430
  /**
5377
5431
  * Creates a zoom control.
@@ -5383,23 +5437,24 @@
5383
5437
  }
5384
5438
  /**
5385
5439
  * @internal
5386
- * @param {MaplairMap} map
5387
5440
  * @returns {HTMLElement}
5388
5441
  */
5389
- onAdd(map) {
5442
+ onAdd() {
5390
5443
  const zoomName = "maplair-control-zoom", container = create("div", `${zoomName} maplair-bar`), options = this.options;
5391
5444
  this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, (e) => this._zoom(e, 1));
5392
5445
  this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, (e) => this._zoom(e, -1));
5393
5446
  this._updateDisabled();
5394
- map.on("zoomend zoomlevelschange", this._updateDisabled, this);
5395
5447
  return container;
5396
5448
  }
5397
5449
  /**
5398
5450
  * @internal
5399
- * @param {MaplairMap} map
5451
+ * @returns {Record<string, Function>}
5400
5452
  */
5401
- onRemove(map) {
5402
- map.off("zoomend zoomlevelschange", this._updateDisabled, this);
5453
+ getEvents() {
5454
+ return {
5455
+ zoomend: this._updateDisabled,
5456
+ zoomlevelschange: this._updateDisabled
5457
+ };
5403
5458
  }
5404
5459
  /**
5405
5460
  * Disables the zoom buttons.
@@ -5436,12 +5491,12 @@
5436
5491
  on(link, "click", (e) => {
5437
5492
  stop(e);
5438
5493
  fn.call(this, e);
5439
- this._refocusOnMap(e);
5440
5494
  });
5441
5495
  return link;
5442
5496
  }
5443
5497
  _updateDisabled() {
5444
5498
  const map = this._map;
5499
+ if (!map) return;
5445
5500
  for (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {
5446
5501
  const disabled = this._disabled || map._zoom === limit;
5447
5502
  button.classList.toggle("maplair-disabled", disabled);
@@ -5756,9 +5811,12 @@
5756
5811
  /** @import {EventListener, MaplairEvent} from '../core/Events.js' */
5757
5812
  /**
5758
5813
  * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an
5759
- * `HTMLElement`, or a function receiving the source layer and returning one of them.
5760
- * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent
5814
+ * `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and
5815
+ * returning one of them.
5816
+ * @typedef {string|HTMLElement|DocumentFragment|
5817
+ * ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent
5761
5818
  */
5819
+ const fragmentNodes = /* @__PURE__ */ new WeakMap();
5762
5820
  /**
5763
5821
  * Options of `DivOverlay`.
5764
5822
  * @typedef {object} DivOverlayOptions
@@ -5774,8 +5832,8 @@
5774
5832
  * in the DOM (for styling and events).
5775
5833
  * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while
5776
5834
  * initializing. If a function is passed the source layer will be passed to the
5777
- * function. The function should return a `String` or `HTMLElement` to be used in the
5778
- * overlay. String content is rendered as HTML; sanitize untrusted input or pass an
5835
+ * function. The function should return a `String`, `HTMLElement` or `DocumentFragment`
5836
+ * to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an
5779
5837
  * `HTMLElement` with safe `textContent` instead.
5780
5838
  * @extends InteractiveLayerOptions
5781
5839
  */
@@ -5807,7 +5865,8 @@
5807
5865
  } };
5808
5866
  /** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */
5809
5867
  /**
5810
- * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.
5868
+ * Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit
5869
+ * from it for custom overlays like plugins.
5811
5870
  *
5812
5871
  * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
5813
5872
  */
@@ -5884,8 +5943,7 @@
5884
5943
  else {
5885
5944
  if (arguments.length) this._source = layer;
5886
5945
  else layer = this._source;
5887
- this._prepareOpen();
5888
- this.openOn(layer._map);
5946
+ if (this._prepareOpen()) this.openOn(layer._map);
5889
5947
  }
5890
5948
  return this;
5891
5949
  }
@@ -5897,7 +5955,7 @@
5897
5955
  if (!this._container) this._initLayout();
5898
5956
  if (map._fadeAnimated) this._container.style.opacity = "0";
5899
5957
  clearTimeout(this._removeTimeout);
5900
- this.getPane().appendChild(this._container);
5958
+ this.getPane().append(this._container);
5901
5959
  if (this.options.overflow) {
5902
5960
  this._container.classList.add("maplair-overflow");
5903
5961
  this._container.popover = "manual";
@@ -5969,10 +6027,11 @@
5969
6027
  }
5970
6028
  /**
5971
6029
  * Sets the HTML content of the overlay. A `String` argument is rendered as
5972
- * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)
5973
- * or pass an `HTMLElement` with safe `textContent` instead. If a function is
5974
- * passed the source layer will be passed to the function. The function should
5975
- * return a `String` or `HTMLElement` to be used in the overlay.
6030
+ * HTML; if it may contain untrusted input, sanitize it or pass an `HTMLElement`
6031
+ * with safe `textContent` instead. A `DocumentFragment`
6032
+ * can be passed as well. If a function is passed the source layer will be passed
6033
+ * to the function. The function should return a `String`, `HTMLElement` or
6034
+ * `DocumentFragment` to be used in the overlay.
5976
6035
  * @param {DivOverlayContent} content
5977
6036
  * @returns {this}
5978
6037
  */
@@ -6020,7 +6079,7 @@
6020
6079
  * @returns {boolean}
6021
6080
  */
6022
6081
  isOpen() {
6023
- return !!this._map && this._map.hasLayer(this);
6082
+ return !!this._map?.hasLayer(this);
6024
6083
  }
6025
6084
  /**
6026
6085
  * Brings this overlay in front of other overlays (in the same map pane).
@@ -6064,30 +6123,26 @@
6064
6123
  if (!source) return false;
6065
6124
  this._source = source;
6066
6125
  }
6067
- if (!latlng) {
6068
- if (source.getCenter) latlng = source.getCenter();
6069
- else if (source.getLatLng) latlng = source.getLatLng();
6070
- else if (source.getBounds) latlng = source.getBounds().getCenter();
6071
- else throw new Error("Unable to get source layer LatLng.");
6072
- }
6126
+ latlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();
6127
+ if (!latlng) throw new Error("Unable to get source layer LatLng.");
6073
6128
  this.setLatLng(latlng);
6074
6129
  if (this._map) this.update();
6075
6130
  return true;
6076
6131
  }
6077
6132
  _updateContent() {
6078
- if (!this._content) return;
6133
+ if (this._content == null) return;
6079
6134
  const node = this._contentNode;
6080
6135
  const content = typeof this._content === "function" ? this._content(this._source ?? this) : this._content;
6081
6136
  if (typeof content === "string") node.innerHTML = content;
6082
- else {
6083
- while (node.hasChildNodes()) node.removeChild(node.firstChild);
6084
- node.appendChild(content);
6085
- }
6137
+ else if (content instanceof DocumentFragment) {
6138
+ if (content.hasChildNodes()) fragmentNodes.set(content, [...content.childNodes]);
6139
+ node.replaceChildren(...fragmentNodes.get(content) ?? []);
6140
+ } else node.replaceChildren(content);
6086
6141
  this.fire("contentupdate");
6087
6142
  }
6088
6143
  _updatePosition() {
6089
6144
  if (!this._map) return;
6090
- const pos = this._map.latLngToLayerPoint(this._latlng)._round(), offset = Point.from(this.options.offset);
6145
+ const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng)), offset = Point.from(this.options.offset);
6091
6146
  this._setContainerPosition(pos.add(this._getAnchor()));
6092
6147
  const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
6093
6148
  if (this.options.overflow) {
@@ -6230,10 +6285,10 @@
6230
6285
  /**
6231
6286
  * Binds a popup to the layer with the passed `content` and sets up the
6232
6287
  * necessary event listeners. A `String` argument is rendered as HTML; if it
6233
- * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
6234
- * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
6288
+ * may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
6289
+ * `textContent` instead. If a `Function` is passed
6235
6290
  * it will receive the layer as the first argument and should return a
6236
- * `String` or `HTMLElement`.
6291
+ * `String`, `HTMLElement` or `DocumentFragment`.
6237
6292
  * @group Popup methods
6238
6293
  * @param {DivOverlayContent|Popup} content
6239
6294
  * @param {PopupOptions} [options]
@@ -6241,6 +6296,7 @@
6241
6296
  */
6242
6297
  bindPopup(content, options) {
6243
6298
  this._popup = this._initOverlay(Popup, this._popup, content, options);
6299
+ this._popup._updateSourceAria(this._popup.isOpen());
6244
6300
  this.on({
6245
6301
  click: this._openPopup,
6246
6302
  remove: this.closePopup,
@@ -6260,6 +6316,9 @@
6260
6316
  remove: this.closePopup,
6261
6317
  move: this._movePopup
6262
6318
  });
6319
+ const el = this.getElement?.();
6320
+ el?.removeAttribute("aria-expanded");
6321
+ el?.removeAttribute("aria-controls");
6263
6322
  this._popup = null;
6264
6323
  }
6265
6324
  return this;
@@ -6328,9 +6387,8 @@
6328
6387
  if (!this._popup || !this._map) return;
6329
6388
  stopPropagation(e);
6330
6389
  const target = e.propagatedFrom ?? e.target;
6331
- if (this._popup._source === target && !(target instanceof Path)) {
6332
- if (this._map.hasLayer(this._popup)) this.closePopup();
6333
- else this.openPopup(e.latlng);
6390
+ if (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {
6391
+ this.closePopup();
6334
6392
  return;
6335
6393
  }
6336
6394
  this._popup._source = target;
@@ -6370,8 +6428,7 @@
6370
6428
  *
6371
6429
  * **Security note.** Popup string content is rendered as HTML. If your content
6372
6430
  * may include untrusted input (e.g. data from users or external APIs), sanitize
6373
- * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or
6374
- * build a DOM element using `textContent` to render it as plain text:
6431
+ * it first, or build a DOM element using `textContent` to render it as plain text:
6375
6432
  *
6376
6433
  * ```js
6377
6434
  * const el = document.createElement('div');
@@ -6427,9 +6484,11 @@
6427
6484
  */
6428
6485
  openOn(map) {
6429
6486
  map = arguments.length ? map : this._source._map;
6430
- if (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) map.removeLayer(map._popup);
6487
+ if (!map.hasLayer(this) && map._popup?.options.autoClose) map.removeLayer(map._popup);
6431
6488
  map._popup = this;
6432
- return super.openOn(map);
6489
+ super.openOn(map);
6490
+ this._updateSourceAria(true);
6491
+ return this;
6433
6492
  }
6434
6493
  /**
6435
6494
  * Adds the popup to the map.
@@ -6444,9 +6503,10 @@
6444
6503
  (this._closeButton ?? this._container).focus({ preventScroll: true });
6445
6504
  }
6446
6505
  map.fire("popupopen", { popup: this });
6506
+ this._updateSourceAria(true);
6447
6507
  if (this._source) {
6448
6508
  this._source.fire("popupopen", { popup: this }, true);
6449
- if (!(this._source instanceof Path)) this._source.on("preclick", stopPropagation);
6509
+ if (this._source._togglesPopupOnClick()) this._source.on("preclick", stopPropagation);
6450
6510
  }
6451
6511
  }
6452
6512
  /**
@@ -6454,13 +6514,17 @@
6454
6514
  * @param {MaplairMap} map
6455
6515
  */
6456
6516
  onRemove(map) {
6457
- if (this._container.contains(document.activeElement) && this._returnFocus?.isConnected) this._returnFocus.focus({ preventScroll: true });
6517
+ if (this._container.contains(document.activeElement)) {
6518
+ const el = this._source?.getElement?.();
6519
+ (this._returnFocus?.isConnected ? this._returnFocus : el?.tabIndex >= 0 ? el : map._container).focus({ preventScroll: true });
6520
+ }
6458
6521
  this._returnFocus = null;
6459
6522
  super.onRemove(map);
6460
6523
  map.fire("popupclose", { popup: this });
6524
+ this._updateSourceAria(false);
6461
6525
  if (this._source) {
6462
6526
  this._source.fire("popupclose", { popup: this }, true);
6463
- if (!(this._source instanceof Path)) this._source.off("preclick", stopPropagation);
6527
+ if (this._source._togglesPopupOnClick()) this._source.off("preclick", stopPropagation);
6464
6528
  }
6465
6529
  }
6466
6530
  /**
@@ -6473,8 +6537,17 @@
6473
6537
  if (this.options.keepInView) events.moveend = this._adjustPan;
6474
6538
  return events;
6475
6539
  }
6540
+ _updateSourceAria(open) {
6541
+ this._ariaSource?.setAttribute("aria-expanded", "false");
6542
+ this._ariaSource?.removeAttribute("aria-controls");
6543
+ const el = this._source?.getElement?.();
6544
+ this._ariaSource = el?.getAttribute("role") === "button" ? el : null;
6545
+ this._ariaSource?.setAttribute("aria-expanded", String(open));
6546
+ if (open) this._ariaSource?.setAttribute("aria-controls", this._container.id);
6547
+ }
6476
6548
  _initLayout() {
6477
6549
  const prefix = "maplair-popup", container = this._container = create("div", `${prefix} ${this.options.className || ""} maplair-zoom-animated`);
6550
+ container.id = `maplair-popup-${stamp(this)}`;
6478
6551
  const wrapper = this._wrapper = create("div", `${prefix}-content-wrapper`, container);
6479
6552
  this._contentNode = create("div", `${prefix}-content`, wrapper);
6480
6553
  disableClickPropagation(container);
@@ -6486,7 +6559,7 @@
6486
6559
  const closeButton = this._closeButton = create("button", `${prefix}-close-button`, container);
6487
6560
  closeButton.type = "button";
6488
6561
  closeButton.setAttribute("aria-label", I18n.translate("Close popup"));
6489
- closeButton.innerHTML = "<span aria-hidden=\"true\">&#215;</span>";
6562
+ closeButton.textContent = "×";
6490
6563
  on(closeButton, "click", (ev) => {
6491
6564
  ev.preventDefault();
6492
6565
  this.close();
@@ -6554,13 +6627,13 @@
6554
6627
  }
6555
6628
  };
6556
6629
  // src/layer/Tooltip.js
6557
- const directions = [
6558
- "top",
6559
- "bottom",
6560
- "center",
6561
- "right",
6562
- "left"
6563
- ];
6630
+ const directions = {
6631
+ top: [.5, 1],
6632
+ bottom: [.5, 0],
6633
+ center: [.5, .5],
6634
+ right: [0, .5],
6635
+ left: [1, .5]
6636
+ };
6564
6637
  const tipSize = 6;
6565
6638
  const autoPadding = 4;
6566
6639
  function shiftInto(start, size, min, max) {
@@ -6579,7 +6652,8 @@
6579
6652
  * Options of `Tooltip`.
6580
6653
  * @typedef {object} TooltipOptions
6581
6654
  * @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.
6582
- * @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position.
6655
+ * @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position, in
6656
+ * pixels. Mirrored horizontally when an `auto` tooltip opens to the left.
6583
6657
  * @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']
6584
6658
  * Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,
6585
6659
  * `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when
@@ -6650,10 +6724,10 @@
6650
6724
  /**
6651
6725
  * Binds a tooltip to the layer with the passed `content` and sets up the
6652
6726
  * necessary event listeners. A `String` argument is rendered as HTML; if it
6653
- * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
6654
- * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
6727
+ * may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
6728
+ * `textContent` instead. If a `Function` is passed
6655
6729
  * it will receive the layer as the first argument and should return a
6656
- * `String` or `HTMLElement`.
6730
+ * `String`, `HTMLElement` or `DocumentFragment`.
6657
6731
  * @group Tooltip methods
6658
6732
  * @param {DivOverlayContent|Tooltip} content
6659
6733
  * @param {TooltipOptions} [options]
@@ -6664,7 +6738,7 @@
6664
6738
  if (this._tooltip) this.unbindTooltip();
6665
6739
  this._tooltip = this._initOverlay(Tooltip, old, content, options);
6666
6740
  this._initTooltipInteractions();
6667
- if (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) this.openTooltip();
6741
+ if (this._tooltip.options.permanent && this._map?.hasLayer(this)) this.openTooltip();
6668
6742
  return this;
6669
6743
  },
6670
6744
  /**
@@ -6706,11 +6780,7 @@
6706
6780
  openTooltip(latlng) {
6707
6781
  if (this._tooltip) {
6708
6782
  if (!(this instanceof FeatureGroup)) this._tooltip._source = this;
6709
- if (this._tooltip._prepareOpen(latlng)) {
6710
- this._tooltip.openOn(this._map);
6711
- if (this.getElement) this._setAriaDescribedByOnLayer(this);
6712
- else if (this.eachLayer) this.eachLayer(this._setAriaDescribedByOnLayer, this);
6713
- }
6783
+ if (this._tooltip._prepareOpen(latlng)) this._tooltip.openOn(this._map);
6714
6784
  }
6715
6785
  return this;
6716
6786
  },
@@ -6771,7 +6841,7 @@
6771
6841
  if (!remove) {
6772
6842
  el._maplair_focus_handler && off(el, "focus", el._maplair_focus_handler, this);
6773
6843
  el._maplair_focus_handler = () => {
6774
- if (this._tooltip) {
6844
+ if (this._tooltip && el.matches(":focus-visible")) {
6775
6845
  this._tooltip._source = layer;
6776
6846
  this.openTooltip();
6777
6847
  }
@@ -6782,9 +6852,6 @@
6782
6852
  if (remove) delete el._maplair_focus_handler;
6783
6853
  }
6784
6854
  },
6785
- _setAriaDescribedByOnLayer(layer) {
6786
- (typeof layer.getElement === "function" && layer.getElement())?.setAttribute?.("aria-describedby", this._tooltip._container.id);
6787
- },
6788
6855
  _openTooltip(e) {
6789
6856
  if (!this._tooltip || !this._map) return;
6790
6857
  if (this._map.dragging?.moving()) {
@@ -6801,13 +6868,7 @@
6801
6868
  this.openTooltip(this._tooltip.options.sticky ? e.latlng : void 0);
6802
6869
  },
6803
6870
  _moveTooltip(e) {
6804
- let latlng = e.latlng, containerPoint, layerPoint;
6805
- if (this._tooltip.options.sticky && e.originalEvent) {
6806
- containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
6807
- layerPoint = this._map.containerPointToLayerPoint(containerPoint);
6808
- latlng = this._map.layerPointToLatLng(layerPoint);
6809
- }
6810
- this._tooltip.setLatLng(latlng);
6871
+ this._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ? this._map.pointerEventToLatLng(e.originalEvent) : e.latlng);
6811
6872
  }
6812
6873
  };
6813
6874
  /** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */
@@ -6838,8 +6899,7 @@
6838
6899
  *
6839
6900
  * **Security note.** Tooltip string content is rendered as HTML. If your content
6840
6901
  * may include untrusted input (e.g. data from users or external APIs), sanitize
6841
- * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or
6842
- * build a DOM element using `textContent` to render it as plain text:
6902
+ * it first, or build a DOM element using `textContent` to render it as plain text:
6843
6903
  *
6844
6904
  * ```js
6845
6905
  * const el = document.createElement('div');
@@ -6896,6 +6956,8 @@
6896
6956
  map.fire("tooltipopen", { tooltip: this });
6897
6957
  if (this._source) {
6898
6958
  this.addEventParent(this._source);
6959
+ this._ariaSource = this._source.getElement?.();
6960
+ this._ariaSource?.setAttribute("aria-describedby", this._container.id);
6899
6961
  this._source.fire("tooltipopen", { tooltip: this }, true);
6900
6962
  }
6901
6963
  }
@@ -6908,6 +6970,9 @@
6908
6970
  map.fire("tooltipclose", { tooltip: this });
6909
6971
  if (this._source) {
6910
6972
  this.removeEventParent(this._source);
6973
+ const el = this._ariaSource;
6974
+ if (el?.getAttribute("aria-describedby") === this._container.id) el.removeAttribute("aria-describedby");
6975
+ this._ariaSource = null;
6911
6976
  this._source.fire("tooltipclose", { tooltip: this }, true);
6912
6977
  }
6913
6978
  }
@@ -6924,7 +6989,7 @@
6924
6989
  const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-animated`;
6925
6990
  this._contentNode = this._container = create("div", className);
6926
6991
  this._container.setAttribute("role", "tooltip");
6927
- this._container.setAttribute("id", `maplair-tooltip-${stamp(this)}`);
6992
+ this._container.id = `maplair-tooltip-${stamp(this)}`;
6928
6993
  }
6929
6994
  _updateLayout() {}
6930
6995
  _adjustPan() {}
@@ -6938,33 +7003,33 @@
6938
7003
  }
6939
7004
  _setPosition(pos) {
6940
7005
  let direction = this.options.direction, shift = new Point(0, 0);
6941
- const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset), anchor = this._getAnchor();
6942
- if (!directions.includes(direction)) {
6943
- ({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));
6944
- if (direction === "left") {
6945
- offset.x = -offset.x;
6946
- anchor.x = -anchor.x;
6947
- }
6948
- }
6949
- let subX = tooltipWidth / 2, subY = tooltipHeight / 2;
6950
- if (direction === "top") subY = tooltipHeight;
6951
- else if (direction === "bottom") subY = 0;
6952
- else if (direction === "right") subX = 0;
6953
- else if (direction === "left") subX = tooltipWidth;
6954
- pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor).add(shift);
6955
- container.classList.remove("maplair-tooltip-right", "maplair-tooltip-left", "maplair-tooltip-top", "maplair-tooltip-bottom");
6956
- container.classList.add(`maplair-tooltip-${direction}`);
7006
+ const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset);
7007
+ if (!(direction in directions)) {
7008
+ ({direction, shift} = this._getAutoPlacement(pos, offset, tooltipWidth, tooltipHeight));
7009
+ if (direction === "left") offset.x = -offset.x;
7010
+ }
7011
+ const anchor = this._getAnchor(direction);
7012
+ const [fx, fy] = directions[direction];
7013
+ pos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);
7014
+ for (const d in directions) container.classList.toggle(`maplair-tooltip-${d}`, d === direction);
6957
7015
  const tipShift = direction === "top" || direction === "bottom" ? clampTip(-shift.x, tooltipWidth) : clampTip(-shift.y, tooltipHeight);
6958
7016
  if (tipShift) container.style.setProperty("--maplair-tooltip-tip-shift", `${tipShift}px`);
6959
7017
  else container.style.removeProperty("--maplair-tooltip-tip-shift");
6960
7018
  this._setContainerPosition(pos);
6961
7019
  }
6962
- _getAutoPlacement(pos, offset, anchor, width, height) {
6963
- const area = this._getAutoArea(), point = this._map.layerPointToContainerPoint(pos), x = point.x + offset.x + anchor.x, y = point.y + offset.y + anchor.y, space = {
6964
- right: area.max.x - x - width - tipSize,
6965
- left: point.x - offset.x - anchor.x - area.min.x - width - tipSize,
6966
- top: y - area.min.y - height - tipSize,
6967
- bottom: area.max.y - y - height - tipSize
7020
+ _getAutoPlacement(pos, offset, width, height) {
7021
+ const area = this._getAutoArea(), point = this._map.layerPointToContainerPoint(pos), at = {};
7022
+ for (const d of [
7023
+ "right",
7024
+ "left",
7025
+ "top",
7026
+ "bottom"
7027
+ ]) at[d] = point.add(this._getAnchor(d)).add(d === "left" ? [-offset.x, offset.y] : offset);
7028
+ const space = {
7029
+ right: area.max.x - at.right.x - width - tipSize,
7030
+ left: at.left.x - area.min.x - width - tipSize,
7031
+ top: at.top.y - area.min.y - height - tipSize,
7032
+ bottom: area.max.y - at.bottom.y - height - tipSize
6968
7033
  };
6969
7034
  if (!this._autoDirection) {
6970
7035
  const sides = point.x < (area.min.x + area.max.x) / 2 ? ["right", "left"] : ["left", "right"], fallback = space.right >= space.left ? "right" : "left";
@@ -6974,7 +7039,7 @@
6974
7039
  "bottom"
6975
7040
  ].find((d) => space[d] >= 0 && (d === "right" || d === "left" || width <= area.max.x - area.min.x)) ?? fallback;
6976
7041
  }
6977
- const direction = this._autoDirection;
7042
+ const direction = this._autoDirection, { x, y } = at[direction];
6978
7043
  return {
6979
7044
  direction,
6980
7045
  shift: direction === "top" || direction === "bottom" ? new Point(shiftInto(x - width / 2, width, area.min.x, area.max.x), 0) : new Point(0, shiftInto(y - height / 2, height, area.min.y, area.max.y))
@@ -6995,7 +7060,7 @@
6995
7060
  };
6996
7061
  }
6997
7062
  _updatePosition() {
6998
- const pos = this._map.latLngToLayerPoint(this._latlng)._round();
7063
+ const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
6999
7064
  this._setPosition(pos);
7000
7065
  }
7001
7066
  /**
@@ -7011,8 +7076,8 @@
7011
7076
  const pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
7012
7077
  this._setPosition(pos);
7013
7078
  }
7014
- _getAnchor() {
7015
- return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);
7079
+ _getAnchor(direction) {
7080
+ return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor(direction) : [0, 0]);
7016
7081
  }
7017
7082
  /**
7018
7083
  * Registers this default feature on the map class, called by `MaplairMap` itself.
@@ -7069,7 +7134,8 @@
7069
7134
  * @lends MaplairMapOptions
7070
7135
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
7071
7136
  * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
7072
- * instead.
7137
+ * instead. Paths in custom panes get their own renderer for that pane, of the same
7138
+ * class and with the same options as this one.
7073
7139
  */
7074
7140
  /**
7075
7141
  * Registers `getRenderer()` and related methods on the given map class, called by
@@ -7198,12 +7264,16 @@
7198
7264
  */
7199
7265
  addHooks() {
7200
7266
  on(this._map._container, "pointerdown", this._onPointerDown, this);
7267
+ this._map._container.classList.add("maplair-box-zoom");
7201
7268
  }
7202
7269
  /**
7203
7270
  * Called when the handler is disabled, removes the event hooks.
7204
7271
  */
7205
7272
  removeHooks() {
7206
7273
  off(this._map._container, "pointerdown", this._onPointerDown, this);
7274
+ this._map._container.classList.remove("maplair-box-zoom");
7275
+ this._finish();
7276
+ this._resetState();
7207
7277
  }
7208
7278
  /**
7209
7279
  * Returns `true` if a box has been drawn by the current or last interaction.
@@ -7354,9 +7424,13 @@
7354
7424
  * pointer drag).
7355
7425
  */
7356
7426
  /**
7357
- * The event object of `dragstart`, `predrag` and `drag` of `Draggable`.
7427
+ * The event object of `dragstart`, `predrag` and `drag` of `Draggable`, and of
7428
+ * `movestart` and `dragstart` of draggable markers.
7358
7429
  * @typedef {object} DraggableEvent
7359
- * @property {PointerEvent} originalEvent The DOM event of the pointer which drags.
7430
+ * @property {PointerEvent|KeyboardEvent} originalEvent The DOM event of the pointer which
7431
+ * drags: for `dragstart`, the `pointermove` that moved the pointer past `clickTolerance`
7432
+ * (not the `pointerdown`), or the `keydown` of an arrow key that moves a focused
7433
+ * draggable marker.
7360
7434
  * @extends MaplairEvent
7361
7435
  */
7362
7436
  /**
@@ -7416,13 +7490,13 @@
7416
7490
  }
7417
7491
  _onDown(e) {
7418
7492
  this._moved = false;
7419
- if (this._element.classList.contains("maplair-zoom-anim")) return;
7420
7493
  const pointers = getPointers().length;
7421
7494
  if (pointers > 1) {
7422
7495
  if (Draggable._dragging === this) this.finishDrag();
7423
7496
  return;
7424
7497
  }
7425
- if (Draggable._dragging || e.shiftKey || e.button !== 0 && e.pointerType !== "touch") return;
7498
+ const boxZoom = e.shiftKey && this._element.closest(".maplair-container")?.classList.contains("maplair-box-zoom");
7499
+ if (Draggable._dragging || boxZoom || e.button !== 0 && e.pointerType !== "touch") return;
7426
7500
  Draggable._dragging = this;
7427
7501
  disableImageDrag();
7428
7502
  if (this._moving) return;
@@ -7480,10 +7554,8 @@
7480
7554
  finishDrag(noInertia) {
7481
7555
  this._draggingContainer?.classList.remove("maplair-dragging");
7482
7556
  this._draggingContainer = null;
7483
- if (this._lastTarget) {
7484
- this._lastTarget.classList.remove("maplair-drag-target");
7485
- this._lastTarget = null;
7486
- }
7557
+ this._lastTarget?.classList.remove("maplair-drag-target");
7558
+ this._lastTarget = null;
7487
7559
  off(this._dragStartTarget, "pointermove", this._onMove, this);
7488
7560
  off(this._dragStartTarget, "pointerup pointercancel lostpointercapture", this._onUp, this);
7489
7561
  enableImageDrag();
@@ -7595,8 +7667,13 @@
7595
7667
  map._stop();
7596
7668
  map._setUserEvent(e.originalEvent);
7597
7669
  if (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) {
7598
- const bounds = LatLngBounds.from(this._map.options.maxBounds);
7599
- this._offsetLimit = new Bounds(this._map.latLngToContainerPoint(bounds.getNorthWest()).multiplyBy(-1), this._map.latLngToContainerPoint(bounds.getSouthEast()).multiplyBy(-1).add(this._map.getSize()));
7670
+ const bounds = LatLngBounds.from(this._map.options.maxBounds), { min, max } = new Bounds([
7671
+ bounds.getNorthWest(),
7672
+ bounds.getNorthEast(),
7673
+ bounds.getSouthEast(),
7674
+ bounds.getSouthWest()
7675
+ ].map((c) => this._map.latLngToContainerPoint(c)));
7676
+ this._offsetLimit = new Bounds(max.multiplyBy(-1), min.multiplyBy(-1).add(this._map.getSize()));
7600
7677
  this._viscosity = Math.min(1, Math.max(0, this._map.options.maxBoundsViscosity));
7601
7678
  } else this._offsetLimit = null;
7602
7679
  map.fire("movestart").fire("dragstart");
@@ -7742,7 +7819,7 @@
7742
7819
  const container = this._map._container;
7743
7820
  if (container.tabIndex <= 0) container.tabIndex = 0;
7744
7821
  const shortcuts = this._map.options.ariaKeyShortcuts;
7745
- if (shortcuts) container.ariaKeyShortcuts = shortcuts === true ? "ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -" : shortcuts;
7822
+ if (shortcuts) container.setAttribute("aria-keyshortcuts", shortcuts === true ? "ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -" : shortcuts);
7746
7823
  on(container, {
7747
7824
  focus: this._onFocus,
7748
7825
  blur: this._onBlur,
@@ -7798,7 +7875,7 @@
7798
7875
  return help;
7799
7876
  }
7800
7877
  _onPointerDown() {
7801
- if (this._focused) return;
7878
+ if (this._focused || this._map._container.contains(document.activeElement)) return;
7802
7879
  this._map._container.focus({
7803
7880
  preventScroll: true,
7804
7881
  focusVisible: false
@@ -7816,11 +7893,9 @@
7816
7893
  }
7817
7894
  _onContainerKeyDown(e) {
7818
7895
  const map = this._map, popup = map._popup;
7819
- if (e.key !== "Escape" || e.defaultPrevented || !popup?.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
7820
- const inPopup = popup._container.contains(e.target), icon = popup._source?._icon;
7896
+ if (e.key !== "Escape" || e.defaultPrevented || !popup?.isOpen() || !popup.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
7821
7897
  map.closePopup();
7822
7898
  e.preventDefault();
7823
- if (inPopup) (icon?.tabIndex >= 0 ? icon : map._container).focus();
7824
7899
  }
7825
7900
  _onKeyDown(e) {
7826
7901
  if (e.altKey || e.ctrlKey || e.metaKey) return;
@@ -7925,8 +8000,8 @@
7925
8000
  this._moved = false;
7926
8001
  this._zooming = true;
7927
8002
  map._stop();
7928
- on(this._map._container, "pointermove", this._onPointerMove, this);
7929
- on(this._map._container, "pointerup pointercancel", this._onPointerEnd, this);
8003
+ on(map._container, "pointermove", this._onPointerMove, this);
8004
+ on(map._container, "pointerup pointercancel", this._onPointerEnd, this);
7930
8005
  e.preventDefault();
7931
8006
  }
7932
8007
  _onPointerMove(e) {
@@ -7949,10 +8024,7 @@
7949
8024
  this._moved = true;
7950
8025
  }
7951
8026
  cancelAnimationFrame(this._animRequest);
7952
- const moveFn = map._move.bind(map, this._center, this._zoom, {
7953
- pinch: true,
7954
- round: false
7955
- }, void 0);
8027
+ const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
7956
8028
  this._animRequest = requestAnimationFrame(moveFn.bind(this));
7957
8029
  e.preventDefault();
7958
8030
  }
@@ -7968,7 +8040,7 @@
7968
8040
  }
7969
8041
  this._zooming = false;
7970
8042
  cancelAnimationFrame(this._animRequest);
7971
- if (this._map._zoomAnimated) this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);
8043
+ if (this._map._zoomAnimated) this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), this._map.options.zoomSnap);
7972
8044
  else this._map._resetView(this._center, this._map._limitZoom(this._zoom));
7973
8045
  }
7974
8046
  /**
@@ -8105,10 +8177,7 @@
8105
8177
  const frame = () => {
8106
8178
  const pinch = this._pinch, delta = pinch.zoom - pinch.shown;
8107
8179
  pinch.shown = eased && Math.abs(delta) > .01 ? pinch.shown + delta * .3 : pinch.zoom;
8108
- map._move(this._getPinchCenter(pinch.shown), pinch.shown, {
8109
- pinch: true,
8110
- round: false
8111
- });
8180
+ map._move(this._getPinchCenter(pinch.shown), pinch.shown, { pinch: true });
8112
8181
  if (pinch.shown !== pinch.zoom) this._pinchFrame = requestAnimationFrame(frame);
8113
8182
  };
8114
8183
  cancelAnimationFrame(this._pinchFrame);
@@ -8124,7 +8193,7 @@
8124
8193
  cancelAnimationFrame(this._pinchFrame);
8125
8194
  const map = this._map, zoom = map._limitZoom(this._pinch.zoom), center = this._getPinchCenter(zoom);
8126
8195
  this._pinch = null;
8127
- if (map.options.zoomAnimation && Math.abs(zoom - map.getZoom()) > 1e-9) map._animateZoom(center, zoom, true, map.options.zoomSnap);
8196
+ if (map.options.zoomAnimation && Math.abs(zoom - map.getZoom()) > 1e-9) map._animateZoom(center, zoom, map.options.zoomSnap);
8128
8197
  else map._move(center, zoom)._moveEnd(true);
8129
8198
  }
8130
8199
  _panBy(e) {
@@ -8172,9 +8241,9 @@
8172
8241
  stop(e);
8173
8242
  }
8174
8243
  _performZoom() {
8175
- const map = this._map, zoom = map.getZoom(), snap = this._map.options.zoomSnap ?? 0;
8244
+ const map = this._map, zoom = map.getZoom(), snap = map.options.zoomSnap ?? 0;
8176
8245
  map._stop();
8177
- 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;
8246
+ 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;
8178
8247
  this._delta = 0;
8179
8248
  this._startTime = null;
8180
8249
  if (!delta || map._zoomInputBlocked()) return;
@@ -8239,47 +8308,35 @@
8239
8308
  removeHooks() {
8240
8309
  off(this._map._container, "pointerdown", this._onDown, this);
8241
8310
  this._cancel();
8242
- this._cancelClickPrevent();
8243
8311
  this._stopPreventingNative();
8244
8312
  }
8245
8313
  _onDown(e) {
8246
8314
  clearTimeout(this._holdTimeout);
8247
8315
  if (getPointers().length !== 1 || e.pointerType === "mouse") return;
8248
- const el = this._map._container;
8249
- this._startPos = this._newPos = new Point(e.clientX, e.clientY);
8316
+ const el = this._map._container, start = new Point(e.clientX, e.clientY);
8250
8317
  this._holdTimeout = setTimeout((() => {
8251
8318
  this._cancel();
8252
- if (!this._isTapValid()) return;
8253
- on(el, "pointerup", preventDefault);
8254
- on(el, "pointerup pointercancel", this._cancelClickPrevent, this);
8319
+ const pointers = getPointers(), p = pointers[0];
8320
+ if (pointers.length !== 1 || start.distanceTo([p.clientX, p.clientY]) > this._map.options.tapTolerance) return;
8255
8321
  this._simulateEvent("contextmenu", e);
8256
8322
  el.addEventListener("contextmenu", stop, true);
8323
+ el.addEventListener("click", stop, true);
8257
8324
  el.addEventListener("pointerdown", this._stopPreventingNative, true);
8325
+ el.addEventListener("keydown", this._stopPreventingNative, true);
8258
8326
  }), tapHoldDelay);
8259
8327
  on(el, "pointerup pointercancel contextmenu", this._cancel, this);
8260
- on(el, "pointermove", this._onMove, this);
8261
- }
8262
- _cancelClickPrevent() {
8263
- const el = this._map._container;
8264
- off(el, "pointerup", preventDefault);
8265
- off(el, "pointerup pointercancel", this._cancelClickPrevent, this);
8266
8328
  }
8267
8329
  _stopPreventingNative = () => {
8268
8330
  const el = this._map._container;
8269
8331
  el.removeEventListener("contextmenu", stop, true);
8332
+ el.removeEventListener("click", stop, true);
8270
8333
  el.removeEventListener("pointerdown", this._stopPreventingNative, true);
8334
+ el.removeEventListener("keydown", this._stopPreventingNative, true);
8271
8335
  };
8272
8336
  _cancel() {
8273
8337
  clearTimeout(this._holdTimeout);
8274
8338
  const el = this._map._container;
8275
8339
  off(el, "pointerup pointercancel contextmenu", this._cancel, this);
8276
- off(el, "pointermove", this._onMove, this);
8277
- }
8278
- _onMove(e) {
8279
- this._newPos = new Point(e.clientX, e.clientY);
8280
- }
8281
- _isTapValid() {
8282
- return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
8283
8340
  }
8284
8341
  _simulateEvent(type, e) {
8285
8342
  const simulatedEvent = new MouseEvent(type, {
@@ -8420,10 +8477,7 @@
8420
8477
  this._moved = true;
8421
8478
  }
8422
8479
  cancelAnimationFrame(this._animRequest);
8423
- this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, {
8424
- pinch: true,
8425
- round: false
8426
- }));
8480
+ this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, { pinch: true }));
8427
8481
  e.preventDefault();
8428
8482
  }
8429
8483
  _onUp() {
@@ -8435,7 +8489,7 @@
8435
8489
  this._moved = false;
8436
8490
  cancelAnimationFrame(this._animRequest);
8437
8491
  const map = this._map, zoom = map._limitZoom(this._zoom);
8438
- if (map.options.zoomAnimation) map._animateZoom(this._center, zoom, true, map.options.zoomSnap);
8492
+ if (map.options.zoomAnimation) map._animateZoom(this._center, zoom, map.options.zoomSnap);
8439
8493
  else map._move(this._center, zoom)._moveEnd(true);
8440
8494
  }
8441
8495
  /**
@@ -8479,7 +8533,9 @@
8479
8533
  * user tries to pan outside the view. To set the restriction dynamically, use
8480
8534
  * [`setMaxBounds`](#map-setmaxbounds) method.
8481
8535
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
8482
- * map. `SVG` or `Canvas` by default depending on browser support.
8536
+ * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
8537
+ * instead. Paths in custom panes get their own renderer for that pane, of the same
8538
+ * class and with the same options as this one.
8483
8539
  * @property {boolean} [zoomAnimation=true] Whether the map zoom animation is enabled.
8484
8540
  * @property {number} [zoomAnimationThreshold=4] Won't animate zoom if the zoom
8485
8541
  * difference exceeds this value (or 1 if the user prefers
@@ -8563,15 +8619,25 @@
8563
8619
  /**
8564
8620
  * Options of the `MaplairMap` methods which modify the zoom level and the center.
8565
8621
  * @typedef {object} ZoomPanOptions
8622
+ * @property {boolean} [animate] Whether to animate the change: like `ZoomOptions.animate`
8623
+ * if the zoom level changes, and like `PanOptions.animate` otherwise. The `zoom` and
8624
+ * `pan` options can set it for each case separately.
8625
+ * @property {boolean} [reset] If `true`, the view is reset without animation.
8626
+ * @property {ZoomOptions} [zoom] Options for the zoom part of the change, taking
8627
+ * precedence over `animate`.
8628
+ * @property {PanOptions} [pan] Options for the pan part of the change, taking
8629
+ * precedence over `animate`.
8566
8630
  * @extends ZoomOptions, PanOptions
8567
8631
  */
8568
8632
  /**
8569
8633
  * Options of `MaplairMap.invalidateSize()`.
8570
8634
  * @typedef {object} InvalidateSizeOptions
8635
+ * @property {boolean} [animate=false] If `true`, the map pans to its new center with
8636
+ * animation.
8571
8637
  * @property {boolean} [pan=true] If `false`, panning will not occur.
8572
8638
  * @property {boolean} [debounceMoveend=false] If `true`, it will delay `moveend` event
8573
8639
  * so that it doesn't happen often even if the method is called many times in a row.
8574
- * @extends ZoomPanOptions
8640
+ * @extends PanOptions
8575
8641
  */
8576
8642
  /**
8577
8643
  * Padding options of `MaplairMap` methods, e.g. `panInside()`.
@@ -8619,7 +8685,9 @@
8619
8685
  * pressing a key or clicking a zoom button) have an `originalEvent` property with the
8620
8686
  * DOM event that started the change. It is `undefined` for changes made by code (e.g.
8621
8687
  * `setView()`), which allows to tell them apart, e.g. to avoid feedback loops when
8622
- * synchronizing the view.
8688
+ * synchronizing the view. The `move` and `zoom` events also have `flyTo: true` on each
8689
+ * [`flyTo`](#map-flyto) animation frame, and `pinch: true` while the user pinch-zooms
8690
+ * the map.
8623
8691
  *
8624
8692
  * @example
8625
8693
  * ```js
@@ -8719,6 +8787,7 @@
8719
8787
  this._handlers = [];
8720
8788
  this._layers = {};
8721
8789
  this._zoomBoundLayers = {};
8790
+ this._canvases = [];
8722
8791
  this._sizeChanged = true;
8723
8792
  this._initContainer(id);
8724
8793
  this._initLayout();
@@ -8749,10 +8818,23 @@
8749
8818
  * @returns {this}
8750
8819
  */
8751
8820
  setView(center, zoom, options) {
8752
- zoom = zoom === void 0 ? this._zoom : this._limitZoom(zoom);
8821
+ zoom = zoom === void 0 ? this._targetZoom() : this._limitZoom(zoom);
8822
+ const targetCenter = center;
8753
8823
  center = this._limitCenter(new LatLng(center), zoom, this.options.maxBounds);
8754
8824
  options ??= {};
8755
8825
  this._stop();
8826
+ this._targetView = {
8827
+ center: targetCenter,
8828
+ zoom
8829
+ };
8830
+ if (this._animatingZoom) {
8831
+ this._pendingView = {
8832
+ center,
8833
+ zoom,
8834
+ options
8835
+ };
8836
+ return this;
8837
+ }
8756
8838
  if (this._loaded && !options.reset && options !== true) {
8757
8839
  if (options.animate !== void 0) {
8758
8840
  options.zoom = {
@@ -8765,12 +8847,12 @@
8765
8847
  ...options.pan
8766
8848
  };
8767
8849
  }
8768
- if (this._zoom !== zoom ? this._tryAnimatedZoom && this._tryAnimatedZoom(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan)) {
8850
+ if (this._zoom !== zoom ? this._tryAnimatedZoom?.(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan)) {
8769
8851
  clearTimeout(this._sizeTimer);
8770
8852
  return this;
8771
8853
  }
8772
8854
  }
8773
- this._resetView(center, zoom, options.pan?.noMoveStart);
8855
+ this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, zoom, options.pan?.noMoveStart);
8774
8856
  return this;
8775
8857
  }
8776
8858
  /**
@@ -8785,7 +8867,7 @@
8785
8867
  this._zoom = zoom;
8786
8868
  return this;
8787
8869
  }
8788
- return this.setView(this.getCenter(), zoom, { zoom: options });
8870
+ return this.setView(this._targetView?.center ?? this.getCenter(), zoom, { zoom: options });
8789
8871
  }
8790
8872
  /**
8791
8873
  * Increases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
@@ -8796,7 +8878,7 @@
8796
8878
  */
8797
8879
  zoomIn(delta, options) {
8798
8880
  delta ??= this.options.zoomDelta;
8799
- return this.setZoom(this._zoom + delta, options);
8881
+ return this.setZoom(this._targetZoom() + delta, options);
8800
8882
  }
8801
8883
  /**
8802
8884
  * Decreases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
@@ -8807,7 +8889,7 @@
8807
8889
  */
8808
8890
  zoomOut(delta, options) {
8809
8891
  delta ??= this.options.zoomDelta;
8810
- return this.setZoom(this._zoom - delta, options);
8892
+ return this.setZoom(this._targetZoom() - delta, options);
8811
8893
  }
8812
8894
  /**
8813
8895
  * Zooms the map while keeping a specified geographical point on the map
@@ -8829,7 +8911,7 @@
8829
8911
  bounds = bounds.getBounds ? bounds.getBounds() : LatLngBounds.from(bounds);
8830
8912
  const paddingTL = Point.from(options.paddingTopLeft || options.padding || [0, 0]), paddingBR = Point.from(options.paddingBottomRight || options.padding || [0, 0]);
8831
8913
  let zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR));
8832
- zoom = typeof options.maxZoom === "number" ? Math.min(options.maxZoom, zoom) : zoom;
8914
+ zoom = Math.min(options.maxZoom ?? Infinity, zoom);
8833
8915
  if (zoom === Infinity) return {
8834
8916
  center: bounds.getCenter(),
8835
8917
  zoom
@@ -8872,7 +8954,7 @@
8872
8954
  * @returns {this}
8873
8955
  */
8874
8956
  panTo(center, options) {
8875
- return this.setView(center, this._zoom, { pan: options });
8957
+ return this.setView(center, void 0, { pan: options });
8876
8958
  }
8877
8959
  /**
8878
8960
  * Pans the map by a given number of pixels (animated unless `animate: false` is passed,
@@ -8884,24 +8966,18 @@
8884
8966
  * @returns {this}
8885
8967
  */
8886
8968
  panBy(offset, options) {
8887
- offset = Point.from(offset).round();
8969
+ const { center = this.getCenter(), zoom = this._zoom } = this._targetView ?? {}, newCenter = this.unproject(this.project(center, zoom).add(Point.from(offset).round()), zoom);
8970
+ return this.setView(newCenter, zoom, { pan: options });
8971
+ }
8972
+ _panBy(offset, options) {
8888
8973
  options ??= {};
8889
- if (!offset.x && !offset.y) return this.fire("moveend");
8890
- const size = this.getSize();
8891
- if (options.animate !== true && !size.contains(offset)) {
8892
- const center = this.unproject(this.project(this.getCenter()).add(offset));
8893
- this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, this.getZoom());
8894
- return this;
8895
- }
8896
- if (!this._panAnim) {
8897
- this._panAnim = new PosAnimation();
8898
- this._panAnim.on({
8899
- "step": this._onPanTransitionStep,
8900
- "end": this._onPanTransitionEnd
8901
- }, this);
8902
- }
8974
+ if (!offset.x && !offset.y) return this._moveStart(false, true)._moveEnd(false);
8975
+ if (!this._panAnim) this._panAnim = new PosAnimation().on({
8976
+ step: this._onPanTransitionStep,
8977
+ end: this._onPanTransitionEnd
8978
+ }, this);
8903
8979
  if (!options.noMoveStart) this.fire("movestart");
8904
- const tooFarForReducedMotion = this._prefersReducedMotion() && !size.divideBy(2).contains(offset);
8980
+ const tooFarForReducedMotion = this._prefersReducedMotion() && !this.getSize().divideBy(2).contains(offset);
8905
8981
  if (options.animate === true || options.animate !== false && !tooFarForReducedMotion) {
8906
8982
  this._mapPane.classList.add("maplair-pan-anim");
8907
8983
  const newPos = this._getMapPanePos().subtract(offset).round();
@@ -8909,7 +8985,7 @@
8909
8985
  } else {
8910
8986
  this._rawPanBy(offset);
8911
8987
  this._wrapWorldCopy();
8912
- this.fire("move").fire("moveend");
8988
+ this.fire("move")._moveEnd(false);
8913
8989
  }
8914
8990
  return this;
8915
8991
  }
@@ -8933,9 +9009,15 @@
8933
9009
  }
8934
9010
  });
8935
9011
  if (options.animate !== true && this._prefersReducedMotion()) return this.setView(targetCenter, targetZoom, options);
8936
- this._stop();
8937
- targetZoom = targetZoom === void 0 ? this._zoom : this._limitZoom(targetZoom);
9012
+ targetZoom = targetZoom === void 0 ? this._targetZoom() : this._limitZoom(targetZoom);
9013
+ const requestedCenter = targetCenter;
8938
9014
  targetCenter = this._limitCenter(new LatLng(targetCenter), targetZoom, this.options.maxBounds);
9015
+ this._stop();
9016
+ this._targetView = {
9017
+ center: requestedCenter,
9018
+ zoom: targetZoom
9019
+ };
9020
+ this._subpixelOrigin = true;
8939
9021
  const from = this.project(this.getCenter()), to = this.project(targetCenter), size = this.getSize(), startZoom = this._zoom;
8940
9022
  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;
8941
9023
  function r(i) {
@@ -8949,7 +9031,7 @@
8949
9031
  function easeOut(t) {
8950
9032
  return 1 - (1 - t) ** 1.5;
8951
9033
  }
8952
- const start = Date.now(), S = (r(1) - r0) / rho, duration = options.duration ? 1e3 * options.duration : 1e3 * S * .8;
9034
+ const start = Date.now(), S = (r(1) - r0) / rho, duration = 1e3 * (options.duration || S * .8);
8953
9035
  const frame = () => {
8954
9036
  const t = (Date.now() - start) / duration, s = easeOut(t) * S;
8955
9037
  if (t <= 1) {
@@ -8957,6 +9039,7 @@
8957
9039
  this._move(this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1)), startZoom), this.getScaleZoom(Math.cosh(r0 + rho * s) / Math.cosh(r0), startZoom), { flyTo: true });
8958
9040
  } else {
8959
9041
  const zoomChanged = this._zoom !== targetZoom;
9042
+ this._subpixelOrigin = false;
8960
9043
  this._move(targetCenter, targetZoom);
8961
9044
  if (!zoomChanged) this.fire("zoom");
8962
9045
  this._moveEnd(true);
@@ -9041,7 +9124,7 @@
9041
9124
  this.options.minZoom = zoom;
9042
9125
  if (this._loaded && oldZoom !== zoom) {
9043
9126
  this.fire("zoomlevelschange");
9044
- if (this.getZoom() < this.options.minZoom) return this.setZoom(zoom);
9127
+ if (this._targetZoom() < this.options.minZoom) return this.setZoom(zoom);
9045
9128
  }
9046
9129
  return this;
9047
9130
  }
@@ -9056,7 +9139,7 @@
9056
9139
  this.options.maxZoom = zoom;
9057
9140
  if (this._loaded && oldZoom !== zoom) {
9058
9141
  this.fire("zoomlevelschange");
9059
- if (this.getZoom() > this.options.maxZoom) return this.setZoom(zoom);
9142
+ if (this._targetZoom() > this.options.maxZoom) return this.setZoom(zoom);
9060
9143
  }
9061
9144
  return this;
9062
9145
  }
@@ -9101,8 +9184,8 @@
9101
9184
  }
9102
9185
  /**
9103
9186
  * Checks if the map container size changed and updates the map if so —
9104
- * call it after you've changed the map size dynamically, also animating
9105
- * pan by default. If `options.pan` is `false`, panning will not occur.
9187
+ * call it after you've changed the map size dynamically, also panning to
9188
+ * keep the center by default. If `options.pan` is `false`, panning will not occur.
9106
9189
  * If `options.debounceMoveend` is `true`, it will delay `moveend` event so
9107
9190
  * that it doesn't happen often even if the method is called many
9108
9191
  * times in a row. Passing `true` instead of options animates the panning.
@@ -9119,8 +9202,9 @@
9119
9202
  };
9120
9203
  const oldSize = this.getSize();
9121
9204
  this._sizeChanged = true;
9122
- this._lastCenter = null;
9123
- const newSize = this.getSize(), oldCenter = oldSize.divideBy(2).round(), newCenter = newSize.divideBy(2).round(), offset = oldCenter.subtract(newCenter);
9205
+ const newSize = this.getSize();
9206
+ if (!newSize.equals(oldSize)) this._lastCenter = null;
9207
+ const oldCenter = oldSize.divideBy(2).round(), newCenter = newSize.divideBy(2).round(), offset = oldCenter.subtract(newCenter);
9124
9208
  if (!offset.x && !offset.y) return this;
9125
9209
  if (options.animate && options.pan) this.panBy(offset);
9126
9210
  else {
@@ -9202,7 +9286,7 @@
9202
9286
  }
9203
9287
  _handleGeolocationResponse(pos) {
9204
9288
  if (!this._container._maplair_id) return;
9205
- const lat = pos.coords.latitude, lng = pos.coords.longitude, latlng = new LatLng(lat, lng), bounds = latlng.toBounds(pos.coords.accuracy * 2), options = this._locateOptions;
9289
+ const latlng = new LatLng(pos.coords.latitude, pos.coords.longitude), bounds = latlng.toBounds(pos.coords.accuracy * 2), options = this._locateOptions;
9206
9290
  if (options.setView) {
9207
9291
  const zoom = this.getBoundsZoom(bounds);
9208
9292
  this.setView(latlng, options.maxZoom ? Math.min(zoom, options.maxZoom) : zoom);
@@ -9236,7 +9320,7 @@
9236
9320
  */
9237
9321
  remove() {
9238
9322
  this._initEvents(true);
9239
- if (this.options.maxBounds) this.off("moveend", this._panInsideMaxBounds);
9323
+ this.off("moveend", this._panInsideMaxBounds);
9240
9324
  if (this._containerId !== this._container._maplair_id) throw new Error("Map container is being reused by another instance");
9241
9325
  delete this._container._maplair_id;
9242
9326
  delete this._containerId;
@@ -9335,7 +9419,12 @@
9335
9419
  bounds = LatLngBounds.from(bounds);
9336
9420
  padding = Point.from(padding ?? [0, 0]);
9337
9421
  let zoom = this.getZoom() ?? 0;
9338
- 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);
9422
+ const min = this.getMinZoom(), max = this.getMaxZoom(), size = this.getSize().subtract(padding), boundsSize = new Bounds([
9423
+ bounds.getNorthWest(),
9424
+ bounds.getNorthEast(),
9425
+ bounds.getSouthEast(),
9426
+ bounds.getSouthWest()
9427
+ ].map((c) => this.project(c, 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);
9339
9428
  zoom = this.getScaleZoom(scale, zoom);
9340
9429
  if (snap) {
9341
9430
  zoom = Math.round(zoom / (snap / 100)) * (snap / 100);
@@ -9574,7 +9663,18 @@
9574
9663
  * @returns {Point}
9575
9664
  */
9576
9665
  pointerEventToContainerPoint(e) {
9577
- return getPointerPosition(e, this._container);
9666
+ if (!this._animatingZoom) return getPointerPosition(e, this._container);
9667
+ if (!this._containerRect) {
9668
+ const el = this._container, { x, y, boundingClientRect: r } = getScale(el);
9669
+ this._containerRect = {
9670
+ x,
9671
+ y,
9672
+ left: r.left + el.clientLeft * x,
9673
+ top: r.top + el.clientTop * y
9674
+ };
9675
+ }
9676
+ const c = this._containerRect;
9677
+ return new Point((e.clientX - c.left) / c.x, (e.clientY - c.top) / c.y);
9578
9678
  }
9579
9679
  /**
9580
9680
  * Given a PointerEvent object, returns the pixel coordinate relative to
@@ -9739,18 +9839,25 @@
9739
9839
  this._lastCenterPanePos = this._getMapPanePos();
9740
9840
  this._pixelOrigin = this._getNewPixelOrigin(center);
9741
9841
  if (!suppressEvent) {
9742
- if (zoomChanged || data?.pinch) this.fire("zoom", data);
9842
+ if (zoomChanged || data?.pinch || data?.flyTo) this.fire("zoom", data);
9743
9843
  this.fire("move", data);
9744
9844
  } else if (data?.pinch) this.fire("zoom", data);
9745
9845
  return this;
9746
9846
  }
9747
9847
  _moveEnd(zoomChanged) {
9848
+ if (!this._pendingView) this._targetView = null;
9748
9849
  if (zoomChanged) this.fire("zoomend");
9749
9850
  return this.fire("moveend");
9750
9851
  }
9751
9852
  _stop() {
9853
+ this._pendingView = null;
9854
+ this._targetView = null;
9752
9855
  cancelAnimationFrame(this._flyToFrame);
9753
9856
  cancelAnimationFrame(this._zoomAnimFrame);
9857
+ if (this._subpixelOrigin) {
9858
+ this._subpixelOrigin = false;
9859
+ this._move(this._lastCenter, this._zoom, { flyTo: true });
9860
+ }
9754
9861
  this._panAnim?.stop();
9755
9862
  return this;
9756
9863
  }
@@ -9805,13 +9912,14 @@
9805
9912
  _findEventTargets(e, type) {
9806
9913
  let targets = [], target, src = e.target, dragging = false;
9807
9914
  const isHover = type === "pointerout" || type === "pointerover";
9915
+ const canEndDrag = (type === "click" || type === "preclick") && e.detail > 0;
9808
9916
  while (src) {
9809
9917
  target = this._targets[stamp(src)];
9810
- if (target && (type === "click" || type === "preclick") && this._draggableMoved(target)) {
9918
+ if (target && canEndDrag && this._draggableMoved(target)) {
9811
9919
  dragging = true;
9812
9920
  break;
9813
9921
  }
9814
- if (target && target.listens(type, true)) {
9922
+ if (target?.listens(type, true)) {
9815
9923
  if (isHover && !isExternalTarget(src, e)) break;
9816
9924
  targets.push(target);
9817
9925
  if (isHover) break;
@@ -9822,16 +9930,31 @@
9822
9930
  if (!targets.length && !dragging && !isHover && this.listens(type, true)) targets = [this];
9823
9931
  return targets;
9824
9932
  }
9825
- _isClickDisabled(el) {
9826
- while (el && el !== this._container) {
9827
- if (el["_maplair_disable_click"] || !el.parentNode) return true;
9828
- el = el.parentNode;
9829
- }
9830
- }
9831
9933
  _handleDOMEvent(e) {
9832
9934
  const el = e.target;
9833
- if (!this._loaded || el["_maplair_disable_events"] || e.type === "click" && this._isClickDisabled(el)) return;
9834
- this._fireDOMEvent(e, e.type);
9935
+ if (e.type === "click") simulateDblclick(e, this._container);
9936
+ if (!this._loaded || e.type === "click" && isClickDisabled(el, this._container)) return;
9937
+ const type = e.type, move = type === "pointermove", hovered = this._hoveredCanvasLayer, skip = type === "pointerover" || type === "pointerout" || type.startsWith("key") || this._animatingZoom || move && this.dragging?.moving(), leftMap = type === "pointerout" && !this._container.contains(e.relatedTarget);
9938
+ let layer = skip ? void 0 : this._canvasLayerAt(e, type === "click");
9939
+ if (type === "pointerdown") this._pressedCanvasLayer = skip ? void 0 : layer ?? null;
9940
+ else if (type === "click" && e.detail > 0 && this._pressedCanvasLayer !== void 0) {
9941
+ if (layer !== this._pressedCanvasLayer) layer = void 0;
9942
+ this._pressedCanvasLayer = void 0;
9943
+ }
9944
+ if (layer !== hovered && (move && !skip || leftMap)) {
9945
+ if (hovered) this._fireDOMEvent(e, "pointerout", [hovered]);
9946
+ this._container.classList.toggle("maplair-interactive", !!layer);
9947
+ this._hoveredCanvasLayer = layer;
9948
+ if (layer) this._fireDOMEvent(e, "pointerover", [layer]);
9949
+ }
9950
+ this._fireDOMEvent(e, type, layer && [layer]);
9951
+ }
9952
+ _canvasLayerAt(e, click) {
9953
+ for (let el = e.target; el !== this._container; el = el.parentNode) if (!el || el === this._controlContainer || this._targets[stamp(el)]) return;
9954
+ for (const renderer of this._canvases) {
9955
+ const layer = renderer._layerAt(e, click);
9956
+ if (layer) return layer;
9957
+ }
9835
9958
  }
9836
9959
  static _pointerEvents = [
9837
9960
  "click",
@@ -9842,7 +9965,7 @@
9842
9965
  ];
9843
9966
  _fireDOMEvent(e, type, canvasTargets) {
9844
9967
  if (type === "click") this._fireDOMEvent(e, "preclick", canvasTargets);
9845
- let targets = this._findEventTargets(e, type);
9968
+ let targets = canvasTargets && (type === "pointerover" || type === "pointerout") ? [] : this._findEventTargets(e, type);
9846
9969
  if (canvasTargets) targets = [...canvasTargets.filter((t) => t.listens(type, true)), ...targets];
9847
9970
  if (!targets.length) return;
9848
9971
  if (type === "contextmenu") e.preventDefault();
@@ -9886,7 +10009,11 @@
9886
10009
  }
9887
10010
  _getNewPixelOrigin(center, zoom) {
9888
10011
  const viewHalf = this.getSize()._divideBy(2);
9889
- return this.project(center, zoom)._subtract(viewHalf)._add(this._getMapPanePos())._round();
10012
+ const origin = this.project(center, zoom)._subtract(viewHalf)._add(this._getMapPanePos());
10013
+ return this._subpixelOrigin ? origin : origin._round();
10014
+ }
10015
+ _snapLayerPoint(point) {
10016
+ return this._subpixelOrigin ? point : point._round();
9890
10017
  }
9891
10018
  _latLngToNewLayerPoint(latlng, zoom, center) {
9892
10019
  const topLeft = this._getNewPixelOrigin(center, zoom);
@@ -9913,7 +10040,12 @@
9913
10040
  return offset.add(this._getBoundsOffset(newBounds, bounds));
9914
10041
  }
9915
10042
  _getBoundsOffset(pxBounds, maxBounds, zoom) {
9916
- const projectedMaxBounds = new Bounds(this.project(maxBounds.getNorthEast(), zoom), this.project(maxBounds.getSouthWest(), zoom)), minOffset = projectedMaxBounds.min.subtract(pxBounds.min), maxOffset = projectedMaxBounds.max.subtract(pxBounds.max);
10043
+ const projectedMaxBounds = new Bounds([
10044
+ maxBounds.getNorthWest(),
10045
+ maxBounds.getNorthEast(),
10046
+ maxBounds.getSouthEast(),
10047
+ maxBounds.getSouthWest()
10048
+ ].map((c) => this.project(c, zoom))), minOffset = projectedMaxBounds.min.subtract(pxBounds.min), maxOffset = projectedMaxBounds.max.subtract(pxBounds.max);
9917
10049
  return new Point(this._rebound(minOffset.x, -maxOffset.x), this._rebound(minOffset.y, -maxOffset.y));
9918
10050
  }
9919
10051
  _rebound(left, right) {
@@ -9930,17 +10062,17 @@
9930
10062
  _onPanTransitionEnd() {
9931
10063
  this._mapPane.classList.remove("maplair-pan-anim");
9932
10064
  this._wrapWorldCopy();
9933
- this.fire("moveend");
10065
+ this._moveEnd(false);
9934
10066
  }
9935
10067
  _tryAnimatedPan(center, options) {
9936
- const offset = this._getCenterOffset(center)._trunc();
10068
+ const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
9937
10069
  if (options?.animate !== true && !this.getSize().contains(offset)) return false;
9938
- this.panBy(offset, options);
10070
+ this._panBy(offset, options);
9939
10071
  return true;
9940
10072
  }
9941
10073
  _createAnimProxy() {
9942
10074
  this._proxy = create("div", "maplair-proxy maplair-zoom-animated");
9943
- this._panes.mapPane.appendChild(this._proxy);
10075
+ this._panes.mapPane.append(this._proxy);
9944
10076
  this.on("zoomanim", this._animateProxyZoom, this);
9945
10077
  this.on("load moveend", this._animMoveEnd, this);
9946
10078
  on(this._proxy, "transitionend", this._catchTransitionEnd, this);
@@ -9974,6 +10106,9 @@
9974
10106
  };
9975
10107
  this._flyToFrame = requestAnimationFrame(frame);
9976
10108
  }
10109
+ _targetZoom() {
10110
+ return this._targetView?.zoom ?? this._zoom;
10111
+ }
9977
10112
  _zoomInputBlocked() {
9978
10113
  return this._animatingZoom || Date.now() < this._instantZoomEnd;
9979
10114
  }
@@ -9992,18 +10127,16 @@
9992
10127
  this._zoomAnimFrame = requestAnimationFrame(() => {
9993
10128
  this._zoomAnimFrame = null;
9994
10129
  if (userEvent) this._setUserEvent(userEvent);
9995
- this._moveStart(true, options.noMoveStart ?? false)._animateZoom(center, zoom, true);
10130
+ this._moveStart(true, options.noMoveStart ?? false)._animateZoom(center, zoom);
9996
10131
  });
9997
10132
  return true;
9998
10133
  }
9999
- _animateZoom(center, zoom, startAnim, noUpdate) {
10134
+ _animateZoom(center, zoom, noUpdate) {
10000
10135
  if (!this._mapPane) return;
10001
- if (startAnim) {
10002
- this._animatingZoom = true;
10003
- this._animateToCenter = center;
10004
- this._animateToZoom = zoom;
10005
- this._mapPane.classList.add("maplair-zoom-anim");
10006
- }
10136
+ this._animatingZoom = true;
10137
+ this._animateToCenter = center;
10138
+ this._animateToZoom = zoom;
10139
+ this._mapPane.classList.add("maplair-zoom-anim");
10007
10140
  this.fire("zoomanim", {
10008
10141
  center,
10009
10142
  zoom,
@@ -10011,17 +10144,25 @@
10011
10144
  });
10012
10145
  if (!this._tempFireZoomEvent) this._tempFireZoomEvent = this._zoom !== this._animateToZoom;
10013
10146
  this._move(this._animateToCenter, this._animateToZoom, void 0, true);
10014
- this._transitionEndTimer = setTimeout(this._onZoomTransitionEnd.bind(this), zoomAnimDuration);
10147
+ clearTimeout(this._transitionEndTimer);
10148
+ this._transitionEndTimer = setTimeout(this._onZoomTransitionEnd.bind(this), 1e3);
10015
10149
  }
10016
10150
  _onZoomTransitionEnd() {
10017
10151
  if (!this._animatingZoom) return;
10152
+ clearTimeout(this._transitionEndTimer);
10153
+ this._containerRect = null;
10018
10154
  this._mapPane?.classList.remove("maplair-zoom-anim");
10019
10155
  this._animatingZoom = false;
10020
- this._move(this._animateToCenter, this._animateToZoom, void 0, true);
10156
+ this._move(this.getCenter(), this._animateToZoom, void 0, true);
10021
10157
  if (this._tempFireZoomEvent) this.fire("zoom");
10022
10158
  delete this._tempFireZoomEvent;
10023
10159
  this.fire("move");
10024
10160
  this._moveEnd(true);
10161
+ const view = this._pendingView;
10162
+ if (view) {
10163
+ this._pendingView = null;
10164
+ this.setView(view.center, view.zoom, view.options);
10165
+ }
10025
10166
  }
10026
10167
  };
10027
10168
  for (const feature of [
@@ -10141,9 +10282,9 @@
10141
10282
  closestLayerPoint(p) {
10142
10283
  p = Point.from(p);
10143
10284
  let minDistance = Infinity, minPoint = null, p1, p2;
10144
- const closest = _sqClosestPointOnSegment;
10145
- for (const points of this._parts) for (let i = 1, len = points.length; i < len; i++) {
10146
- p1 = points[i - 1];
10285
+ const closest = _sqClosestPointOnSegment, closed = this._isClosed();
10286
+ for (const points of this._parts) for (let i = closed ? 0 : 1, len = points.length; i < len; i++) {
10287
+ p1 = points[(i || len) - 1];
10147
10288
  p2 = points[i];
10148
10289
  const sqDist = closest(p, p1, p2, true);
10149
10290
  if (sqDist < minDistance) {
@@ -10216,7 +10357,7 @@
10216
10357
  }
10217
10358
  _projectLatlngs(latlngs, result, projectedBounds) {
10218
10359
  if (latlngs[0] instanceof LatLng) {
10219
- const ring = latlngs.map((latlng) => this._map.latLngToLayerPoint(latlng));
10360
+ const ring = latlngs.map((latlng) => this._renderer._latLngToLayerPoint(latlng));
10220
10361
  ring.forEach((r) => projectedBounds.extend(r));
10221
10362
  result.push(ring);
10222
10363
  } else latlngs.forEach((latlng) => this._projectLatlngs(latlng, result, projectedBounds));
@@ -10224,24 +10365,21 @@
10224
10365
  _clipPoints() {
10225
10366
  const bounds = this._renderer._bounds;
10226
10367
  this._parts = [];
10227
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
10368
+ if (!this._pxBounds?.intersects(bounds)) return;
10228
10369
  if (this.options.noClip) {
10229
10370
  this._parts = this._rings;
10230
10371
  return;
10231
10372
  }
10232
10373
  const parts = this._parts;
10233
- let i, j, k, len, len2, segment, points;
10234
- for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
10235
- points = this._rings[i];
10236
- for (j = 0, len2 = points.length; j < len2 - 1; j++) {
10237
- segment = clipSegment(points[j], points[j + 1], bounds, j);
10238
- if (!segment) continue;
10239
- parts[k] ??= [];
10240
- parts[k].push(segment[0]);
10241
- if (segment[1] !== points[j + 1] || j === len2 - 2) {
10242
- parts[k].push(segment[1]);
10243
- k++;
10244
- }
10374
+ let k = 0;
10375
+ for (const points of this._rings) for (let j = 0, len = points.length; j < len - 1; j++) {
10376
+ const segment = clipSegment(points[j], points[j + 1], bounds, j);
10377
+ if (!segment) continue;
10378
+ parts[k] ??= [];
10379
+ parts[k].push(segment[0]);
10380
+ if (segment[1] !== points[j + 1] || j === len - 2) {
10381
+ parts[k].push(segment[1]);
10382
+ k++;
10245
10383
  }
10246
10384
  }
10247
10385
  }
@@ -10258,17 +10396,13 @@
10258
10396
  _updatePath() {
10259
10397
  this._renderer._updatePoly(this);
10260
10398
  }
10399
+ _isClosed() {
10400
+ return false;
10401
+ }
10261
10402
  _containsPoint(p, closed) {
10262
- let i, j, k, len, len2, part;
10263
10403
  const w = this._clickTolerance();
10264
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
10265
- for (i = 0, len = this._parts.length; i < len; i++) {
10266
- part = this._parts[i];
10267
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
10268
- if (!closed && j === 0) continue;
10269
- if (pointToSegmentDistance(p, part[k], part[j]) <= w) return true;
10270
- }
10271
- }
10404
+ if (!this._pxBounds?.contains(p)) return false;
10405
+ 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;
10272
10406
  return false;
10273
10407
  }
10274
10408
  /**
@@ -10295,7 +10429,6 @@
10295
10429
  polygonCenter: () => polygonCenter
10296
10430
  });
10297
10431
  /** @import {LatLngExpression} from '../geo/LatLng.js' */
10298
- /** @import {Bounds} from './Bounds.js' */
10299
10432
  /** @import {CRS} from '../geo/crs/CRS.js' */
10300
10433
  /**
10301
10434
  * Clips the polygon geometry defined by the given `points` by the given bounds (using
@@ -10350,7 +10483,14 @@
10350
10483
  y += (p1.y + p2.y) * f;
10351
10484
  area += f;
10352
10485
  }
10353
- return crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));
10486
+ if (area !== 0) return crs.unproject(new Point(x / (3 * area), y / (3 * area))._add(origin));
10487
+ const mid = new Bounds(points).getCenter();
10488
+ let center = points[0];
10489
+ for (let i = 0, j = len - 1; i < len; j = i++) {
10490
+ const p = _sqClosestPointOnSegment(mid, points[j], points[i]);
10491
+ if (p.distanceTo(mid) < center.distanceTo(mid)) center = p;
10492
+ }
10493
+ return crs.unproject(center._add(origin));
10354
10494
  }
10355
10495
  /**
10356
10496
  * Returns the 'center of mass' of the passed LatLngs.
@@ -10465,10 +10605,10 @@
10465
10605
  }
10466
10606
  _clipPoints() {
10467
10607
  let bounds = this._renderer._bounds;
10468
- const w = this.options.weight, p = new Point(w, w);
10608
+ const w = +this.options.weight || 0, p = new Point(w, w);
10469
10609
  bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
10470
10610
  this._parts = [];
10471
- if (!this._pxBounds || !this._pxBounds.intersects(bounds)) return;
10611
+ if (!this._pxBounds?.intersects(bounds)) return;
10472
10612
  if (this.options.noClip) {
10473
10613
  this._parts = this._rings;
10474
10614
  return;
@@ -10481,16 +10621,15 @@
10481
10621
  _updatePath() {
10482
10622
  this._renderer._updatePoly(this, true);
10483
10623
  }
10624
+ _isClosed() {
10625
+ return true;
10626
+ }
10484
10627
  _containsPoint(p) {
10485
- let inside = false, part, p1, p2, i, j, k, len, len2;
10486
- if (!this._pxBounds || !this._pxBounds.contains(p)) return false;
10487
- for (i = 0, len = this._parts.length; i < len; i++) {
10488
- part = this._parts[i];
10489
- for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
10490
- p1 = part[j];
10491
- p2 = part[k];
10492
- 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
- }
10628
+ let inside = false;
10629
+ if (!this._pxBounds?.contains(p)) return false;
10630
+ for (const part of this._parts) for (let j = 0, len = part.length, k = len - 1; j < len; k = j++) {
10631
+ const p1 = part[j], p2 = part[k];
10632
+ 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;
10494
10633
  }
10495
10634
  return inside || super._containsPoint(p, true);
10496
10635
  }
@@ -10733,16 +10872,15 @@
10733
10872
  onAdd(map) {
10734
10873
  const className = "maplair-control-scale", container = create("div", className), options = this.options;
10735
10874
  this._addScales(options, `${className}-line`, container);
10736
- map.on(options.updateWhenIdle ? "moveend" : "move", this._update, this);
10737
10875
  map.whenReady(this._update, this);
10738
10876
  return container;
10739
10877
  }
10740
10878
  /**
10741
10879
  * @internal
10742
- * @param {MaplairMap} map
10880
+ * @returns {Record<string, Function>}
10743
10881
  */
10744
- onRemove(map) {
10745
- map.off(this.options.updateWhenIdle ? "moveend" : "move", this._update, this);
10882
+ getEvents() {
10883
+ return { [this.options.updateWhenIdle ? "moveend" : "move"]: this._update };
10746
10884
  }
10747
10885
  _addScales(options, className, container) {
10748
10886
  if (options.metric) this._mScale = create("div", className, container);
@@ -10775,13 +10913,13 @@
10775
10913
  }
10776
10914
  _updateScale(scale, text, ratio) {
10777
10915
  scale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;
10778
- scale.innerHTML = text;
10916
+ scale.textContent = text;
10779
10917
  }
10780
10918
  _getRoundNum(num) {
10781
- const pow10 = 10 ** (`${Math.floor(num)}`.length - 1);
10782
- let d = num / pow10;
10919
+ const exponent = num < 1 ? Math.floor(Math.log10(num)) : `${Math.floor(num)}`.length - 1;
10920
+ let d = num / 10 ** exponent;
10783
10921
  d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
10784
- return pow10 * d;
10922
+ return exponent < 0 ? d / 10 ** -exponent : d * 10 ** exponent;
10785
10923
  }
10786
10924
  };
10787
10925
  // src/layer/marker/Icon.js
@@ -10801,8 +10939,11 @@
10801
10939
  * can be set in CSS with negative margins.
10802
10940
  * @property {PointExpression} [popupAnchor=[0, 0]] The coordinates of the point from
10803
10941
  * which popups will "open", relative to the icon anchor.
10804
- * @property {PointExpression} [tooltipAnchor=[0, 0]] The coordinates of the point from
10805
- * which tooltips will "open", relative to the icon anchor.
10942
+ * @property {PointExpression} [tooltipAnchor=[0, 0]] Where tooltips opening to the side
10943
+ * attach, relative to the icon anchor: `x` is how far to the right (mirrored for tooltips
10944
+ * opening to the left) and `y` how far down. Tooltips opening to the top or bottom attach
10945
+ * to the middle of the icon's top or bottom edge, and `center` ones to the middle of the
10946
+ * icon at the `y` height.
10806
10947
  * @property {string} [shadowUrl] The URL to the icon shadow image. If not specified, no
10807
10948
  * shadow image will be created.
10808
10949
  * @property {string} [shadowRetinaUrl] The URL to a retina sized version of the shadow
@@ -10882,25 +11023,42 @@
10882
11023
  const img = this._createImg(src, oldIcon instanceof HTMLImageElement ? oldIcon : null);
10883
11024
  this._setIconStyles(img, name);
10884
11025
  if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
11026
+ else img.crossOrigin = null;
10885
11027
  return img;
10886
11028
  }
11029
+ _getBox(name) {
11030
+ const options = this.options;
11031
+ const sizeOption = options[`${name}Size`];
11032
+ const [width, height] = (typeof sizeOption === "number" ? [sizeOption, sizeOption] : Array.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);
11033
+ const anchorOption = name === "shadow" && options.shadowAnchor || options.iconAnchor;
11034
+ return {
11035
+ width,
11036
+ height,
11037
+ anchor: Point.validate(anchorOption) ? Point.from(anchorOption) : {
11038
+ x: Math.round(width / 2),
11039
+ y: Math.round(height / 2)
11040
+ }
11041
+ };
11042
+ }
11043
+ _getTooltipAnchor(direction) {
11044
+ const { x, y } = Point.from(this.options.tooltipAnchor);
11045
+ if (direction === "left") return new Point(-x, y);
11046
+ if (direction === "center") return new Point(0, y);
11047
+ if (direction !== "top" && direction !== "bottom") return new Point(x, y);
11048
+ const { height, anchor } = this._getBox("icon");
11049
+ return new Point(0, (direction === "top" ? -anchor.y : height - anchor.y) || 0);
11050
+ }
10887
11051
  _setIconStyles(img, name) {
10888
11052
  const options = this.options;
10889
- let sizeOption = options[`${name}Size`];
10890
- if (typeof sizeOption === "number") sizeOption = [sizeOption, sizeOption];
10891
- const size = Point.validate(sizeOption) && Point.from(sizeOption);
10892
- const anchorPosition = name === "shadow" && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
10893
- const anchor = Point.validate(anchorPosition) && Point.from(anchorPosition);
11053
+ const { width, height, anchor } = this._getBox(name);
10894
11054
  img.className = `maplair-marker-${name} ${options.className || ""}`;
10895
- if (anchor) {
10896
- img.style.marginLeft = `${-anchor.x}px`;
10897
- img.style.marginTop = `${-anchor.y}px`;
10898
- }
10899
- img.style.transformOrigin = anchor ? `${anchor.x}px ${anchor.y}px` : "0 0";
10900
- if (size) {
10901
- img.style.width = `${size.x}px`;
10902
- img.style.height = `${size.y}px`;
10903
- }
11055
+ const { style } = img;
11056
+ style.marginLeft = style.marginTop = style.width = style.height = "";
11057
+ if (!isNaN(anchor.x)) style.marginLeft = `${-anchor.x}px`;
11058
+ if (!isNaN(anchor.y)) style.marginTop = `${-anchor.y}px`;
11059
+ style.transformOrigin = !isNaN(anchor.x) && !isNaN(anchor.y) ? `${anchor.x}px ${anchor.y}px` : "0 0";
11060
+ if (!isNaN(width)) style.width = `${width}px`;
11061
+ if (!isNaN(height)) style.height = `${height}px`;
10904
11062
  }
10905
11063
  _createImg(src, el) {
10906
11064
  el ??= document.createElement("img");
@@ -10993,8 +11151,8 @@
10993
11151
  * The handler of `Marker` which makes the markers draggable, see the
10994
11152
  * [`dragging`](#marker-dragging) property of markers and its `draggable` option.
10995
11153
  *
10996
- * @fires Marker#dragstart {MaplairEvent} Fired when the user starts dragging the marker.
10997
- * @fires Marker#movestart {MaplairEvent} Fired when the marker starts moving (because of
11154
+ * @fires Marker#dragstart {DraggableEvent} Fired when the user starts dragging the marker.
11155
+ * @fires Marker#movestart {DraggableEvent} Fired when the marker starts moving (because of
10998
11156
  * dragging).
10999
11157
  * @fires Marker#drag {MarkerMoveEvent} Fired repeatedly while the user drags the marker.
11000
11158
  * @fires Marker#dragend {DragEndEvent} Fired when the user stops dragging the marker.
@@ -11048,10 +11206,10 @@
11048
11206
  return this._draggable?._moved;
11049
11207
  }
11050
11208
  _adjustPan(e) {
11051
- 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();
11052
- const panBounds = new Bounds(bounds.min._subtract(origin).add(padding), bounds.max._subtract(origin).subtract(padding));
11053
- if (!panBounds.contains(iconPos)) {
11054
- 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);
11209
+ 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);
11210
+ if (dx || dy) {
11211
+ const movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed), map.options.maxBounds)._round();
11212
+ if (!movement.x && !movement.y) return;
11055
11213
  map.panBy(movement, { animate: false });
11056
11214
  this._draggable._newPos._add(movement);
11057
11215
  this._draggable._startPos._add(movement);
@@ -11060,10 +11218,10 @@
11060
11218
  this._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));
11061
11219
  }
11062
11220
  }
11063
- _onDragStart() {
11221
+ _onDragStart({ originalEvent }) {
11064
11222
  this._oldLatLng = this._marker.getLatLng();
11065
11223
  this._marker.closePopup?.();
11066
- this._marker.fire("movestart").fire("dragstart");
11224
+ this._marker.fire("movestart", { originalEvent }).fire("dragstart", { originalEvent });
11067
11225
  }
11068
11226
  _onPreDrag(e) {
11069
11227
  if (this._marker.options.autoPan) {
@@ -11072,7 +11230,8 @@
11072
11230
  }
11073
11231
  }
11074
11232
  _onDrag(e) {
11075
- const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos);
11233
+ const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos), { alt } = this._oldLatLng;
11234
+ if (alt !== void 0) latlng.alt = alt;
11076
11235
  marker._positionElements(iconPos);
11077
11236
  marker._latlng = latlng;
11078
11237
  e.latlng = latlng;
@@ -11081,7 +11240,6 @@
11081
11240
  }
11082
11241
  _onDragEnd(e) {
11083
11242
  cancelAnimationFrame(this._panRequest);
11084
- delete this._oldLatLng;
11085
11243
  this._marker.fire("moveend").fire("dragend", e);
11086
11244
  }
11087
11245
  /** @param {KeyboardEvent|FocusEvent} e */
@@ -11100,7 +11258,7 @@
11100
11258
  draggable._startPos = getPosition(draggable._element);
11101
11259
  draggable._moved = draggable._moving = true;
11102
11260
  this._keyOffset = new Point(0, 0);
11103
- draggable.fire("dragstart");
11261
+ draggable.fire("dragstart", { originalEvent: k });
11104
11262
  }
11105
11263
  const offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);
11106
11264
  this._keyOffset = this._keyOffset.add(map._rotateToPane?.(offset) ?? offset);
@@ -11133,7 +11291,8 @@
11133
11291
  * @property {string} [title=''] Text for the browser tooltip that appear on marker hover
11134
11292
  * (no tooltip by default).
11135
11293
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
11136
- * @property {string} [alt='Marker'] Text for the `alt` attribute of the icon image.
11294
+ * @property {string} [alt] Text for the `alt` attribute of the icon image, the
11295
+ * translation of `'Marker'` by default.
11137
11296
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
11138
11297
  * @property {number} [zIndexOffset=0] By default, marker images zIndex is set
11139
11298
  * automatically based on its latitude. Use this option if you want to put the marker on
@@ -11145,9 +11304,9 @@
11145
11304
  * marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
11146
11305
  * under a tilted one. `null` means no rotation.
11147
11306
  * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
11148
- * others when you hover the pointer over it.
11149
- * @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`
11150
- * feature.
11307
+ * others while the pointer is over it. It always does while it has focus.
11308
+ * @property {number} [riseOffset=250] The z-index offset used when the marker gets on
11309
+ * top of others on hover or focus.
11151
11310
  * @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.
11152
11311
  * @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will
11153
11312
  * be added.
@@ -11200,7 +11359,7 @@
11200
11359
  interactive: true,
11201
11360
  keyboard: true,
11202
11361
  title: "",
11203
- alt: "Marker",
11362
+ alt: void 0,
11204
11363
  zIndexOffset: 0,
11205
11364
  opacity: 1,
11206
11365
  rotation: null,
@@ -11331,7 +11490,7 @@
11331
11490
  */
11332
11491
  update() {
11333
11492
  if (this._icon && this._map && !this._culled) {
11334
- const pos = this._map.latLngToLayerPoint(this._latlng)._round();
11493
+ const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
11335
11494
  this._setPos(pos);
11336
11495
  }
11337
11496
  return this;
@@ -11344,7 +11503,7 @@
11344
11503
  if (this._icon) this._removeIcon();
11345
11504
  addIcon = true;
11346
11505
  if (options.title) icon.title = options.title;
11347
- if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? "";
11506
+ if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? I18n.translate("Marker");
11348
11507
  }
11349
11508
  icon.classList.add(classToAdd);
11350
11509
  if (options.keyboard) {
@@ -11353,10 +11512,9 @@
11353
11512
  on(icon, "keydown", this._onKeyDown, this);
11354
11513
  }
11355
11514
  this._icon = icon;
11356
- if (options.riseOnHover) this.on({
11357
- pointerover: this._bringToFront,
11358
- pointerout: this._resetZIndex
11359
- });
11515
+ if (this._popup?._source === this) this._popup._updateSourceAria(this._popup.isOpen());
11516
+ on(icon, "focusin focusout", this._updateRise, this);
11517
+ if (options.riseOnHover) on(icon, "pointerover pointerout", this._updateRise, this);
11360
11518
  if (this.options.autoPanOnFocus) on(icon, "focus", this._panOnFocus, this);
11361
11519
  const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
11362
11520
  let addShadow = false;
@@ -11370,15 +11528,13 @@
11370
11528
  }
11371
11529
  this._shadow = newShadow;
11372
11530
  if (options.opacity < 1) this._updateOpacity();
11373
- if (addIcon) this.getPane().appendChild(this._icon);
11531
+ if (addIcon) this.getPane().append(this._icon);
11374
11532
  this._initInteraction();
11375
- if (newShadow && addShadow) this.getPane(options.shadowPane).appendChild(this._shadow);
11533
+ if (newShadow && addShadow) this.getPane(options.shadowPane).append(this._shadow);
11376
11534
  }
11377
11535
  _removeIcon() {
11378
- if (this.options.riseOnHover) this.off({
11379
- pointerover: this._bringToFront,
11380
- pointerout: this._resetZIndex
11381
- });
11536
+ off(this._icon, "pointerover pointerout focusin focusout", this._updateRise, this);
11537
+ this._hovered = this._focused = false;
11382
11538
  if (this.options.autoPanOnFocus) off(this._icon, "focus", this._panOnFocus, this);
11383
11539
  off(this._icon, "keydown", this._onKeyDown, this);
11384
11540
  this._icon.remove();
@@ -11391,8 +11547,8 @@
11391
11547
  if (visible === !this._culled) return;
11392
11548
  this._culled = !visible;
11393
11549
  if (visible) {
11394
- this.getPane().appendChild(this._icon);
11395
- if (this._shadow) this.getPane(this.options.shadowPane).appendChild(this._shadow);
11550
+ this.getPane().append(this._icon);
11551
+ if (this._shadow) this.getPane(this.options.shadowPane).append(this._shadow);
11396
11552
  this.update();
11397
11553
  } else {
11398
11554
  this._icon.remove();
@@ -11405,8 +11561,8 @@
11405
11561
  }
11406
11562
  _setPos(pos) {
11407
11563
  this._positionElements(pos);
11408
- this._zIndex = pos.y + this.options.zIndexOffset;
11409
- this._resetZIndex();
11564
+ this._zIndex = Math.round(pos.y) + this.options.zIndexOffset;
11565
+ this._updateRise();
11410
11566
  }
11411
11567
  _positionElements(pos) {
11412
11568
  const rotation = this.options.rotation;
@@ -11425,7 +11581,7 @@
11425
11581
  }
11426
11582
  _animateZoom(opt) {
11427
11583
  if (this._culled) return;
11428
- const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center)._round();
11584
+ const pos = this._map._snapLayerPoint(this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center));
11429
11585
  this._setPos(pos);
11430
11586
  }
11431
11587
  _updateInteractive() {
@@ -11448,33 +11604,31 @@
11448
11604
  if (!this.options.interactive) return;
11449
11605
  this._icon.classList.add("maplair-interactive");
11450
11606
  this.addInteractiveTarget(this._icon);
11451
- if (MarkerDrag) {
11452
- if (this.dragging?._draggable?._element === this._icon) {
11453
- this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
11454
- return;
11455
- }
11456
- let draggable = this.options.draggable;
11457
- if (this.dragging) {
11458
- draggable = this.dragging.enabled();
11459
- this.dragging.disable();
11460
- }
11461
- /**
11462
- * Marker dragging handler, see `Handler`. Only valid when the marker is on the
11463
- * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
11464
- *
11465
- * Interaction handlers are properties of a marker instance that allow you to
11466
- * control interaction behavior in runtime, enabling or disabling certain
11467
- * features such as dragging (see `Handler` methods). Example:
11468
- *
11469
- * ```js
11470
- * marker.dragging.disable();
11471
- * ```
11472
- * @group Interaction handlers
11473
- * @type {MarkerDrag}
11474
- */
11475
- this.dragging = new MarkerDrag(this);
11476
- if (draggable) this.dragging.enable();
11607
+ if (this.dragging?._draggable?._element === this._icon) {
11608
+ this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
11609
+ return;
11610
+ }
11611
+ let draggable = this.options.draggable;
11612
+ if (this.dragging) {
11613
+ draggable = this.dragging.enabled();
11614
+ this.dragging.disable();
11477
11615
  }
11616
+ /**
11617
+ * Marker dragging handler, see `Handler`. Only valid when the marker is on the
11618
+ * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
11619
+ *
11620
+ * Interaction handlers are properties of a marker instance that allow you to
11621
+ * control interaction behavior in runtime, enabling or disabling certain
11622
+ * features such as dragging (see `Handler` methods). Example:
11623
+ *
11624
+ * ```js
11625
+ * marker.dragging.disable();
11626
+ * ```
11627
+ * @group Interaction handlers
11628
+ * @type {MarkerDrag}
11629
+ */
11630
+ this.dragging = new MarkerDrag(this);
11631
+ if (draggable) this.dragging.enable();
11478
11632
  }
11479
11633
  /**
11480
11634
  * Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
@@ -11508,9 +11662,13 @@
11508
11662
  return this;
11509
11663
  }
11510
11664
  _updateOpacity() {
11511
- const opacity = this.options.opacity;
11512
- if (this._icon) this._icon.style.opacity = `${opacity}`;
11513
- if (this._shadow) this._shadow.style.opacity = `${opacity}`;
11665
+ for (const el of [this._icon, this._shadow]) if (el) el.style.opacity = `${this.options.opacity}`;
11666
+ }
11667
+ _updateRise(e) {
11668
+ if (e?.type.startsWith("pointer")) this._hovered = e.type === "pointerover";
11669
+ else if (e) this._focused = e.type === "focusin";
11670
+ if (this._hovered || this._focused) this._bringToFront();
11671
+ else this._resetZIndex();
11514
11672
  }
11515
11673
  _bringToFront() {
11516
11674
  this._updateZIndex(this.options.riseOffset);
@@ -11538,8 +11696,8 @@
11538
11696
  _getPopupAnchor() {
11539
11697
  return this._rotateAnchor(this.options.icon.options.popupAnchor);
11540
11698
  }
11541
- _getTooltipAnchor() {
11542
- return this._rotateAnchor(this.options.icon.options.tooltipAnchor);
11699
+ _getTooltipAnchor(direction) {
11700
+ return this._rotateAnchor(this.options.icon._getTooltipAnchor(direction));
11543
11701
  }
11544
11702
  _rotateAnchor(anchor) {
11545
11703
  const angle = this.options.rotation * Math.PI / 180;
@@ -12134,8 +12292,9 @@
12134
12292
  this.remove();
12135
12293
  this._map = map;
12136
12294
  this._container = this.onAdd(map);
12137
- map._container.appendChild(this._container);
12138
- map.on("unload", this.remove, this);
12295
+ map._container.append(this._container);
12296
+ this._mapEvents = { unload: this.remove };
12297
+ map.on(this._mapEvents, this);
12139
12298
  return this;
12140
12299
  }
12141
12300
  /**
@@ -13670,6 +13829,7 @@
13670
13829
  onAdd() {
13671
13830
  if (!this._image) {
13672
13831
  this._initImage();
13832
+ this._updateZIndex();
13673
13833
  if (this.options.opacity < 1) this._updateOpacity();
13674
13834
  }
13675
13835
  if (this.options.interactive) {
@@ -13677,7 +13837,7 @@
13677
13837
  this.addInteractiveTarget(this._image);
13678
13838
  }
13679
13839
  this._image.classList.toggle("maplair-pixelated", !!this.options.pixelated);
13680
- this.getPane().appendChild(this._image);
13840
+ this.getPane().append(this._image);
13681
13841
  this._reset();
13682
13842
  }
13683
13843
  /**
@@ -13710,7 +13870,7 @@
13710
13870
  * @returns {this}
13711
13871
  */
13712
13872
  setStyle(styleOpts) {
13713
- if (styleOpts.opacity) this.setOpacity(styleOpts.opacity);
13873
+ if (styleOpts.opacity != null) this.setOpacity(styleOpts.opacity);
13714
13874
  return this;
13715
13875
  }
13716
13876
  /**
@@ -13796,7 +13956,6 @@
13796
13956
  img.onerror = this._overlayOnError.bind(this);
13797
13957
  if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
13798
13958
  img.decoding = this.options.decoding;
13799
- if (this.options.zIndex) this._updateZIndex();
13800
13959
  if (wasElementSupplied) {
13801
13960
  this._url = img.src;
13802
13961
  return;
@@ -13809,7 +13968,7 @@
13809
13968
  setTransform(this._image, offset, scale);
13810
13969
  }
13811
13970
  _reset() {
13812
- const image = this._image, bounds = new Bounds(this._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(), this._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()), size = bounds.getSize();
13971
+ const image = this._image, map = this._map, bounds = new Bounds(map._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getNorthWest())), map._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getSouthEast()))), size = bounds.getSize();
13813
13972
  setPosition(image, bounds.min);
13814
13973
  image.style.width = `${size.x}px`;
13815
13974
  image.style.height = `${size.y}px`;
@@ -13818,7 +13977,7 @@
13818
13977
  this._image.style.opacity = `${this.options.opacity}`;
13819
13978
  }
13820
13979
  _updateZIndex() {
13821
- if (this._image && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._image.style.zIndex = `${this.options.zIndex}`;
13980
+ if (this._image && this.options.zIndex != null) this._image.style.zIndex = `${this.options.zIndex}`;
13822
13981
  }
13823
13982
  _overlayOnError() {
13824
13983
  this.fire("error");
@@ -13835,6 +13994,9 @@
13835
13994
  getCenter() {
13836
13995
  return this._bounds.getCenter();
13837
13996
  }
13997
+ _togglesPopupOnClick() {
13998
+ return false;
13999
+ }
13838
14000
  };
13839
14001
  // src/layer/VideoOverlay.js
13840
14002
  /** @import {ImageOverlayOptions} from './ImageOverlay.js' */
@@ -13915,7 +14077,7 @@
13915
14077
  return;
13916
14078
  }
13917
14079
  if (!Array.isArray(this._url)) this._url = [this._url];
13918
- if (!this.options.keepAspectRatio) vid.style["objectFit"] = "fill";
14080
+ if (!this.options.keepAspectRatio) vid.style.objectFit = "fill";
13919
14081
  vid.autoplay = !!this.options.autoplay;
13920
14082
  vid.controls = !!this.options.controls;
13921
14083
  vid.loop = !!this.options.loop;
@@ -13924,7 +14086,7 @@
13924
14086
  for (const url of this._url) {
13925
14087
  const source = create("source");
13926
14088
  source.src = url;
13927
- vid.appendChild(source);
14089
+ vid.append(source);
13928
14090
  }
13929
14091
  }
13930
14092
  };
@@ -14027,14 +14189,10 @@
14027
14189
  */
14028
14190
  createIcon(oldIcon) {
14029
14191
  const div = oldIcon instanceof HTMLDivElement ? oldIcon : document.createElement("div"), options = this.options;
14030
- if (options.html instanceof Element) {
14031
- div.replaceChildren();
14032
- div.appendChild(options.html);
14033
- } else div.innerHTML = options.html !== false ? options.html : "";
14034
- if (options.bgPos) {
14035
- const bgPos = Point.from(options.bgPos);
14036
- div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
14037
- }
14192
+ if (options.html instanceof Element) div.replaceChildren(options.html);
14193
+ else div.innerHTML = options.html !== false ? options.html : "";
14194
+ const bgPos = options.bgPos && Point.from(options.bgPos);
14195
+ div.style.backgroundPosition = bgPos ? `${-bgPos.x}px ${-bgPos.y}px` : "";
14038
14196
  this._setIconStyles(div, "icon");
14039
14197
  return div;
14040
14198
  }
@@ -14059,7 +14217,7 @@
14059
14217
  function svgElement(name, attributes, parent) {
14060
14218
  const el = document.createElementNS(svgNS, name);
14061
14219
  for (const [key, value] of Object.entries(attributes)) el.setAttribute(key, value);
14062
- parent?.appendChild(el);
14220
+ parent?.append(el);
14063
14221
  return el;
14064
14222
  }
14065
14223
  /**
@@ -14504,10 +14662,10 @@
14504
14662
  * @typedef {(error: any, tile: HTMLElement) => void} TileDoneCallback
14505
14663
  */
14506
14664
  /**
14507
- * Generic class for handling a tiled grid of HTML elements. This is the base class for
14508
- * all tile layers and replaces `TileLayer.Canvas`. GridLayer can be extended to create
14509
- * a tiled grid of HTML elements like `<canvas>`, `<img>` or `<div>`. GridLayer will
14510
- * handle creating and animating these DOM elements for you.
14665
+ * Generic class for handling a tiled grid of HTML elements, and the base class of all
14666
+ * tile layers. To show map tiles from a URL, use `TileLayer` (or `WMSTileLayer`).
14667
+ * Extend `GridLayer` to create a tiled grid of your own elements like `<canvas>`,
14668
+ * `<img>` or `<div>`; it handles creating and animating them for you.
14511
14669
  *
14512
14670
  * Layers extending `GridLayer` shall reimplement the [`createTile()`](#gridlayer-createtile)
14513
14671
  * method.
@@ -14703,7 +14861,7 @@
14703
14861
  redraw() {
14704
14862
  if (this._map) {
14705
14863
  this._removeAllTiles();
14706
- const tileZoom = this._clampZoom(Math.round(this._map.getZoom()));
14864
+ const tileZoom = this._getTileZoom(this._map.getZoom());
14707
14865
  if (tileZoom !== this._tileZoom) {
14708
14866
  this._tileZoom = tileZoom;
14709
14867
  this._updateLevels();
@@ -14754,7 +14912,7 @@
14754
14912
  return s instanceof Point ? s : new Point(s, s);
14755
14913
  }
14756
14914
  _updateZIndex() {
14757
- if (this._container && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._container.style.zIndex = `${this.options.zIndex}`;
14915
+ if (this._container && this.options.zIndex != null) this._container.style.zIndex = `${this.options.zIndex}`;
14758
14916
  }
14759
14917
  _setAutoZIndex(compare) {
14760
14918
  const layers = this.getPane().children;
@@ -14775,11 +14933,11 @@
14775
14933
  _onOpaqueTile() {}
14776
14934
  _initContainer() {
14777
14935
  if (this._container) return;
14778
- this._container = create("div", `maplair-layer ${this.options.className ?? ""}`);
14936
+ this._container = create("div", `maplair-layer maplair-zoom-animated ${this.options.className ?? ""}`);
14779
14937
  this._container.classList.toggle("maplair-pixelated", !!this.options.pixelated);
14780
14938
  this._updateZIndex();
14781
14939
  if (this.options.opacity < 1) this._updateOpacity();
14782
- this.getPane().appendChild(this._container);
14940
+ this.getPane().append(this._container);
14783
14941
  }
14784
14942
  _keepCurrentTiles() {
14785
14943
  const zoom = this._tileZoom, level = this._levels?.[zoom];
@@ -14842,7 +15000,6 @@
14842
15000
  level.origin = map.project(map.unproject(map.getPixelOrigin()), zoom).round();
14843
15001
  level.zoom = zoom;
14844
15002
  this._setZoomTransform(level, map.getCenter(), map.getZoom());
14845
- level.el.offsetWidth;
14846
15003
  this._onCreateLevel(level);
14847
15004
  }
14848
15005
  this._level = level;
@@ -14853,8 +15010,7 @@
14853
15010
  _onCreateLevel() {}
14854
15011
  _pruneTiles() {
14855
15012
  if (!this._map) return;
14856
- const zoom = this._map.getZoom();
14857
- if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
15013
+ if (this._getTileZoom(this._map.getZoom()) === void 0) {
14858
15014
  this._removeAllTiles();
14859
15015
  return;
14860
15016
  }
@@ -14907,7 +15063,15 @@
14907
15063
  this._setView(this._map.getCenter(), this._map.getZoom(), animating, animating);
14908
15064
  }
14909
15065
  _animateZoom(e) {
15066
+ const map = this._map, center = map.getCenter(), zoom = map.getZoom(), scale = map.getZoomScale(e.zoom, zoom);
14910
15067
  this._setView(e.center, e.zoom, true, e.noUpdate);
15068
+ this._setZoomTransforms(center, zoom);
15069
+ setTransform(this._container, map._getNewPixelOrigin(center, zoom).multiplyBy(scale).subtract(map._getNewPixelOrigin(e.center, e.zoom)), scale);
15070
+ }
15071
+ _getTileZoom(zoom) {
15072
+ const { minZoom, maxZoom = Infinity } = this.options;
15073
+ if (zoom < minZoom || zoom > maxZoom) return;
15074
+ return this._clampZoom(Math.round(zoom));
14911
15075
  }
14912
15076
  _clampZoom(zoom) {
14913
15077
  const options = this.options;
@@ -14916,13 +15080,11 @@
14916
15080
  return zoom;
14917
15081
  }
14918
15082
  _setView(center, zoom, noPrune, noUpdate) {
14919
- let tileZoom = Math.round(zoom);
14920
- if (this.options.maxZoom !== void 0 && tileZoom > this.options.maxZoom || this.options.minZoom !== void 0 && tileZoom < this.options.minZoom) tileZoom = void 0;
14921
- else tileZoom = this._clampZoom(tileZoom);
15083
+ const tileZoom = this._getTileZoom(zoom);
14922
15084
  const tileZoomChanged = this.options.updateWhenZooming && tileZoom !== this._tileZoom;
14923
15085
  if (!noUpdate || tileZoomChanged) {
14924
15086
  this._tileZoom = tileZoom;
14925
- if (this._abortLoading) this._abortLoading();
15087
+ this._abortLoading?.();
14926
15088
  this._updateLevels();
14927
15089
  this._resetGrid();
14928
15090
  if (tileZoom !== void 0) this._update(center);
@@ -14932,10 +15094,12 @@
14932
15094
  this._setZoomTransforms(center, zoom);
14933
15095
  }
14934
15096
  _setZoomTransforms(center, zoom) {
15097
+ if (this._container.style.transform) this._container.style.transform = "";
14935
15098
  for (const level of Object.values(this._levels)) this._setZoomTransform(level, center, zoom);
14936
15099
  }
14937
15100
  _setZoomTransform(level, center, zoom) {
14938
- const scale = this._map.getZoomScale(zoom, level.zoom), translate = level.origin.multiplyBy(scale).subtract(this._map._getNewPixelOrigin(center, zoom)).round();
15101
+ const scale = this._map.getZoomScale(zoom, level.zoom), translate = level.origin.multiplyBy(scale).subtract(this._map._getNewPixelOrigin(center, zoom));
15102
+ if (scale === 1) this._map._snapLayerPoint(translate);
14939
15103
  setTransform(level.el, translate, scale);
14940
15104
  }
14941
15105
  _resetGrid() {
@@ -14946,7 +15110,9 @@
14946
15110
  this._wrapY = crs.wrapLat && !this.options.noWrap && [Math.floor(map.project([crs.wrapLat[0], 0], tileZoom).y / tileSize.y), Math.ceil(map.project([crs.wrapLat[1], 0], tileZoom).y / tileSize.y)];
14947
15111
  }
14948
15112
  _onMoveEnd() {
14949
- if (!this._map || this._map._animatingZoom) return;
15113
+ const map = this._map;
15114
+ if (!map || map._animatingZoom) return;
15115
+ if (this._container.style.transform) this._setZoomTransforms(map.getCenter(), map.getZoom());
14950
15116
  this._update();
14951
15117
  }
14952
15118
  _onWorldCopyJump({ worlds }) {
@@ -14991,7 +15157,7 @@
14991
15157
  else queue.push(coords);
14992
15158
  }
14993
15159
  queue.sort((a, b) => a.distanceTo(tileCenter) - b.distanceTo(tileCenter));
14994
- if (queue.length !== 0) {
15160
+ if (queue.length) {
14995
15161
  if (!this._loading) {
14996
15162
  this._loading = true;
14997
15163
  this.fire("loading");
@@ -14999,7 +15165,7 @@
14999
15165
  }
15000
15166
  const fragment = document.createDocumentFragment();
15001
15167
  for (const q of queue) this._addTile(q, fragment);
15002
- this._level.el.appendChild(fragment);
15168
+ this._level.el.append(fragment);
15003
15169
  }
15004
15170
  }
15005
15171
  _isValidTile(coords) {
@@ -15053,7 +15219,7 @@
15053
15219
  coords,
15054
15220
  current: true
15055
15221
  };
15056
- container.appendChild(tile);
15222
+ container.append(tile);
15057
15223
  this.fire("tileloadstart", {
15058
15224
  tile,
15059
15225
  coords
@@ -15131,6 +15297,10 @@
15131
15297
  return osmHosts.some((osmHost) => host === osmHost || host.endsWith(`.${osmHost}`));
15132
15298
  }
15133
15299
  const upgradeOSMUrl = (url) => isOSMUrl(url) ? url.replace(httpRe, "https:") : url;
15300
+ function retinaLevel() {
15301
+ const dpr = window.devicePixelRatio;
15302
+ return dpr >= 1.5 ? 2 : dpr > 1 ? 1 : 0;
15303
+ }
15134
15304
  /**
15135
15305
  * Options of `TileLayer`.
15136
15306
  * @typedef {object} TileLayerOptions
@@ -15149,9 +15319,9 @@
15149
15319
  * this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).
15150
15320
  * @property {boolean} [zoomReverse=false] If set to true, the zoom number used in tile
15151
15321
  * URLs will be reversed (`maxZoom - zoom` instead of `zoom`).
15152
- * @property {boolean} [detectRetina=false] If `true` and user is on a retina display, it
15153
- * will request four tiles of half the specified size and a bigger zoom level in place
15154
- * of one to utilize the high resolution.
15322
+ * @property {boolean} [detectRetina=false] If `true` and the device pixel ratio is 1.5 or
15323
+ * higher, it will request four tiles of half the specified size and a bigger zoom level
15324
+ * in place of one to utilize the high resolution.
15155
15325
  * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will
15156
15326
  * be added to the tiles. If a String is provided, all tiles will have their crossOrigin
15157
15327
  * attribute set to the String provided. This is needed if you want to access tile pixel
@@ -15251,20 +15421,20 @@
15251
15421
  }
15252
15422
  _applyRetina() {
15253
15423
  Object.assign(this.options, this._nonRetinaOptions);
15254
- this._retina = window.devicePixelRatio > 1;
15255
- if (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {
15424
+ this._retina = retinaLevel();
15425
+ if (this.options.detectRetina && this._retina === 2 && this.options.maxZoom > 0) {
15256
15426
  const tileSize = this.options.tileSize;
15257
15427
  this.options.tileSize = tileSize instanceof Point ? tileSize.divideBy(2).floor() : Math.floor(tileSize / 2);
15258
15428
  if (!this.options.zoomReverse) {
15259
15429
  this.options.zoomOffset++;
15260
15430
  this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);
15261
- if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
15262
- if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
15263
15431
  } else {
15264
15432
  this.options.zoomOffset--;
15265
15433
  this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);
15266
15434
  }
15267
15435
  this.options.minZoom = Math.max(0, this.options.minZoom);
15436
+ if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
15437
+ if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
15268
15438
  } else if (!this.options.zoomReverse) this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);
15269
15439
  else this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);
15270
15440
  }
@@ -15278,7 +15448,7 @@
15278
15448
  return events;
15279
15449
  }
15280
15450
  _onPixelRatioChange() {
15281
- if (window.devicePixelRatio > 1 === this._retina) return;
15451
+ if (retinaLevel() === this._retina) return;
15282
15452
  const map = this._map;
15283
15453
  this._applyRetina();
15284
15454
  if (this.options.detectRetina) {
@@ -15360,16 +15530,17 @@
15360
15530
  * @returns {string}
15361
15531
  */
15362
15532
  getTileUrl(coords) {
15363
- const data = Object.create(this.options);
15533
+ const z = coords.z ?? this._tileZoom, data = Object.create(this.options);
15364
15534
  Object.assign(data, {
15365
15535
  r: window.devicePixelRatio > 1 ? "@2x" : "",
15366
15536
  s: this._getSubdomain(coords),
15367
15537
  x: coords.x,
15368
15538
  y: coords.y,
15369
- z: this._getZoomForUrl()
15539
+ z: this._getZoomForUrl(z)
15370
15540
  });
15371
- if (this._map && !this._map.options.crs.infinite) {
15372
- const invertedY = this._globalTileRange.max.y - coords.y;
15541
+ const worldBounds = this._map?.getPixelWorldBounds(z);
15542
+ if (worldBounds) {
15543
+ const invertedY = this._pxBoundsToTileRange(worldBounds).max.y - coords.y;
15373
15544
  if (this.options.tms) data["y"] = invertedY;
15374
15545
  data["-y"] = invertedY;
15375
15546
  }
@@ -15384,8 +15555,7 @@
15384
15555
  if (errorUrl && src !== errorUrl && (src || tile.isConnected)) tile.src = errorUrl;
15385
15556
  done(e, tile);
15386
15557
  }
15387
- _getZoomForUrl() {
15388
- let zoom = this._tileZoom;
15558
+ _getZoomForUrl(zoom) {
15389
15559
  const maxZoom = this.options.maxZoom, zoomReverse = this.options.zoomReverse, zoomOffset = this.options.zoomOffset;
15390
15560
  if (zoomReverse) zoom = maxZoom - zoom;
15391
15561
  return zoom + zoomOffset;
@@ -15418,7 +15588,7 @@
15418
15588
  return super._removeTile(key);
15419
15589
  }
15420
15590
  _tileReady(coords, err, tile) {
15421
- if (!this._map || tile && tile.getAttribute("src") === "") return;
15591
+ if (!this._map || tile?.getAttribute("src") === "") return;
15422
15592
  return super._tileReady(coords, err, tile);
15423
15593
  }
15424
15594
  _clampZoom(zoom) {
@@ -15502,7 +15672,7 @@
15502
15672
  this.callInitHooks(WMSTileLayer);
15503
15673
  }
15504
15674
  _updateWmsSize() {
15505
- const realRetina = this.options.detectRetina && window.devicePixelRatio > 1 ? 2 : 1;
15675
+ const realRetina = this.options.detectRetina && window.devicePixelRatio >= 1.5 ? 2 : 1;
15506
15676
  const tileSize = this.getTileSize();
15507
15677
  this.wmsParams.width = tileSize.x * realRetina;
15508
15678
  this.wmsParams.height = tileSize.y * realRetina;
@@ -15558,7 +15728,10 @@
15558
15728
  for (const [k, v] of Object.entries({
15559
15729
  ...this.wmsParams,
15560
15730
  bbox
15561
- })) url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);
15731
+ })) {
15732
+ if (v == null) continue;
15733
+ url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);
15734
+ }
15562
15735
  return url.toString();
15563
15736
  }
15564
15737
  /**
@@ -15586,7 +15759,8 @@
15586
15759
  /**
15587
15760
  * Merges an object with the new parameters and re-requests tiles on the current screen
15588
15761
  * (unless `noRedraw` was set to true). The current tiles stay visible until the new
15589
- * tiles have loaded, to avoid flickering.
15762
+ * tiles have loaded, to avoid flickering. Set a parameter to `undefined` or `null` to
15763
+ * leave it out of the requests.
15590
15764
  * @param {Record<string, any>} params
15591
15765
  * @param {boolean} [noRedraw]
15592
15766
  * @returns {this}
@@ -15672,22 +15846,21 @@
15672
15846
  */
15673
15847
  onAdd(map) {
15674
15848
  super.onAdd(map);
15849
+ const z = (r) => +getComputedStyle(r._container.parentNode).zIndex || 0;
15850
+ map._canvases.push(this);
15851
+ map._canvases.sort((a, b) => z(b) - z(a) || 1 - (a._container.compareDocumentPosition(b._container) & 2));
15675
15852
  this._draw();
15676
15853
  }
15854
+ _initContainer() {
15855
+ const container = this._container = document.createElement("canvas");
15856
+ this._ctx = container.getContext("2d");
15857
+ }
15677
15858
  /**
15678
15859
  * Removes the canvas from the map.
15679
15860
  */
15680
15861
  onRemove() {
15862
+ this._map._canvases = this._map._canvases.filter((r) => r !== this);
15681
15863
  super.onRemove();
15682
- clearTimeout(this._pointerHoverThrottleTimeout);
15683
- }
15684
- _initContainer() {
15685
- const container = this._container = document.createElement("canvas");
15686
- on(container, "pointermove", this._onPointerMove, this);
15687
- on(container, "click dblclick pointerdown pointerup contextmenu", this._onClick, this);
15688
- on(container, "pointerout", this._handlePointerOut, this);
15689
- container["_maplair_disable_events"] = true;
15690
- this._ctx = container.getContext("2d");
15691
15864
  }
15692
15865
  _destroyContainer() {
15693
15866
  cancelAnimationFrame(this._redrawRequest);
@@ -15723,26 +15896,13 @@
15723
15896
  _initPath(layer) {
15724
15897
  this._updateDashArray(layer);
15725
15898
  this._layers[stamp(layer)] = layer;
15726
- const order = layer._order = {
15727
- layer,
15728
- prev: this._drawLast,
15729
- next: null
15730
- };
15731
- if (this._drawLast) this._drawLast.next = order;
15732
- this._drawLast = order;
15733
- this._drawFirst ??= this._drawLast;
15899
+ this._append(layer._order = { layer });
15734
15900
  }
15735
15901
  _addPath(layer) {
15736
15902
  this._requestRedraw(layer);
15737
15903
  }
15738
15904
  _removePath(layer) {
15739
- const order = layer._order;
15740
- const next = order.next;
15741
- const prev = order.prev;
15742
- if (next) next.prev = prev;
15743
- else this._drawLast = prev;
15744
- if (prev) prev.next = next;
15745
- else this._drawFirst = next;
15905
+ this._unlink(layer._order);
15746
15906
  delete layer._order;
15747
15907
  delete this._layers[stamp(layer)];
15748
15908
  this._requestRedraw(layer);
@@ -15768,7 +15928,7 @@
15768
15928
  }
15769
15929
  _extendRedrawBounds(layer) {
15770
15930
  if (layer._pxBounds) {
15771
- const padding = (layer.options.weight ?? 0) + 1;
15931
+ const padding = (+layer.options.weight || 0) + 1;
15772
15932
  this._redrawBounds ??= new Bounds();
15773
15933
  this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
15774
15934
  this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
@@ -15810,7 +15970,7 @@
15810
15970
  this._drawing = true;
15811
15971
  for (let order = this._drawFirst; order; order = order.next) {
15812
15972
  layer = order.layer;
15813
- if (!bounds || layer._pxBounds && layer._pxBounds.intersects(bounds)) layer._updatePath();
15973
+ if (!bounds || layer._pxBounds?.intersects(bounds)) layer._updatePath();
15814
15974
  }
15815
15975
  this._drawing = false;
15816
15976
  this._ctx.restore();
@@ -15843,7 +16003,7 @@
15843
16003
  ctx.fillStyle = options.fillColor ?? options.color;
15844
16004
  ctx.fill(options.fillRule || "evenodd");
15845
16005
  }
15846
- if (options.stroke && options.weight !== 0) {
16006
+ if (options.stroke && +options.weight !== 0) {
15847
16007
  ctx.lineDashOffset = Number(options.dashOffset ?? 0);
15848
16008
  ctx.setLineDash(layer._dashArray ?? []);
15849
16009
  ctx.globalAlpha = options.opacity;
@@ -15855,84 +16015,50 @@
15855
16015
  }
15856
16016
  }
15857
16017
  _updateInteractive() {}
15858
- _onClick(e) {
16018
+ /**
16019
+ * Returns the topmost interactive layer under the pointer.
16020
+ * @param {MouseEvent} e
16021
+ * @param {boolean} [click] Skip layers that were just dragged, so the drag doesn't end with a click.
16022
+ * @returns {Path|undefined}
16023
+ */
16024
+ _layerAt(e, click) {
15859
16025
  const point = this._map.pointerEventToLayerPoint(e);
15860
- let layer, clickedLayer;
15861
- for (let order = this._drawFirst; order; order = order.next) {
15862
- layer = order.layer;
15863
- if (layer.options.interactive && layer._containsPoint(point)) {
15864
- if (!(e.type === "click" || e.type === "preclick") || !this._map._draggableMoved(layer)) clickedLayer = layer;
15865
- }
16026
+ for (let order = this._drawLast; order; order = order.prev) {
16027
+ const layer = order.layer;
16028
+ if (layer.options.interactive && layer._containsPoint(point) && !(click && this._map._draggableMoved(layer))) return layer;
15866
16029
  }
15867
- this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
15868
16030
  }
15869
- _onPointerMove(e) {
15870
- if (!this._map || this._map.dragging.moving() || this._map._animatingZoom) return;
15871
- const point = this._map.pointerEventToLayerPoint(e);
15872
- this._handlePointerHover(e, point);
15873
- }
15874
- _handlePointerOut(e) {
15875
- const layer = this._hoveredLayer;
15876
- if (layer) {
15877
- this._container.classList.remove("maplair-interactive");
15878
- this._fireEvent([layer], e, "pointerout");
15879
- this._hoveredLayer = null;
15880
- this._pointerHoverThrottled = false;
16031
+ _bringToFront(layer) {
16032
+ const order = layer._order;
16033
+ if (order?.next) {
16034
+ this._unlink(order);
16035
+ this._append(order);
16036
+ this._requestRedraw(layer);
15881
16037
  }
15882
16038
  }
15883
- _handlePointerHover(e, point) {
15884
- if (this._pointerHoverThrottled) return;
15885
- let layer, candidateHoveredLayer;
15886
- for (let order = this._drawFirst; order; order = order.next) {
15887
- layer = order.layer;
15888
- if (layer.options.interactive && layer._containsPoint(point)) candidateHoveredLayer = layer;
15889
- }
15890
- if (candidateHoveredLayer !== this._hoveredLayer) {
15891
- this._handlePointerOut(e);
15892
- if (candidateHoveredLayer) {
15893
- this._container.classList.add("maplair-interactive");
15894
- this._fireEvent([candidateHoveredLayer], e, "pointerover");
15895
- this._hoveredLayer = candidateHoveredLayer;
15896
- }
16039
+ _bringToBack(layer) {
16040
+ const order = layer._order;
16041
+ if (order?.prev) {
16042
+ this._unlink(order);
16043
+ order.prev = null;
16044
+ order.next = this._drawFirst;
16045
+ this._drawFirst.prev = order;
16046
+ this._drawFirst = order;
16047
+ this._requestRedraw(layer);
15897
16048
  }
15898
- this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
15899
- this._pointerHoverThrottled = true;
15900
- this._pointerHoverThrottleTimeout = setTimeout((() => {
15901
- this._pointerHoverThrottled = false;
15902
- }), 32);
15903
- }
15904
- _fireEvent(layers, e, type) {
15905
- this._map._fireDOMEvent(e, type || e.type, layers);
15906
16049
  }
15907
- _bringToFront(layer) {
15908
- const order = layer._order;
15909
- if (!order) return;
15910
- const next = order.next;
15911
- const prev = order.prev;
15912
- if (next) next.prev = prev;
15913
- else return;
15914
- if (prev) prev.next = next;
15915
- else if (next) this._drawFirst = next;
16050
+ _append(order) {
15916
16051
  order.prev = this._drawLast;
15917
- this._drawLast.next = order;
15918
16052
  order.next = null;
16053
+ if (this._drawLast) this._drawLast.next = order;
15919
16054
  this._drawLast = order;
15920
- this._requestRedraw(layer);
16055
+ this._drawFirst ??= order;
15921
16056
  }
15922
- _bringToBack(layer) {
15923
- const order = layer._order;
15924
- if (!order) return;
15925
- const next = order.next;
15926
- const prev = order.prev;
15927
- if (prev) prev.next = next;
15928
- else return;
16057
+ _unlink({ prev, next }) {
15929
16058
  if (next) next.prev = prev;
15930
- else if (prev) this._drawLast = prev;
15931
- order.prev = null;
15932
- order.next = this._drawFirst;
15933
- this._drawFirst.prev = order;
15934
- this._drawFirst = order;
15935
- this._requestRedraw(layer);
16059
+ else this._drawLast = prev;
16060
+ if (prev) prev.next = next;
16061
+ else this._drawFirst = next;
15936
16062
  }
15937
16063
  };
15938
16064
  // src/layer/vector/Circle.js
@@ -15966,7 +16092,6 @@
15966
16092
  constructor(latlng, options) {
15967
16093
  if (typeof options === "number") throw new Error("Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).");
15968
16094
  super(latlng, options);
15969
- if (isNaN(this.options.radius)) throw new Error("Circle radius cannot be NaN");
15970
16095
  this.callInitHooks(Circle);
15971
16096
  }
15972
16097
  /**
@@ -15980,18 +16105,18 @@
15980
16105
  return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half)));
15981
16106
  }
15982
16107
  _project() {
15983
- const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs;
16108
+ const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs, renderer = this._renderer, zoom = renderer._pathZoom;
15984
16109
  if (crs.distance === EarthCRS.distance) {
15985
- 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;
16110
+ 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;
15986
16111
  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;
15987
- if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(Math.PI / 180 * lat);
15988
- this._point = p.subtract(map.getPixelOrigin());
15989
- this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;
15990
- this._pxRadiusY = p.y - top.y;
16112
+ if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(lat * d);
16113
+ this._point = p.subtract(renderer._pathOrigin);
16114
+ this._pxRadius = isNaN(lngR) ? 0 : p.distanceTo(map.project([lat2, lng - lngR], zoom));
16115
+ this._pxRadiusY = p.distanceTo(top);
15991
16116
  } else {
15992
16117
  const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
15993
- this._point = map.latLngToLayerPoint(this._latlng);
15994
- this._pxRadius = Math.abs(this._point.x - map.latLngToLayerPoint(latlng2).x);
16118
+ this._point = renderer._latLngToLayerPoint(this._latlng);
16119
+ this._pxRadius = Math.abs(this._point.x - renderer._latLngToLayerPoint(latlng2).x);
15995
16120
  }
15996
16121
  this._updateBounds();
15997
16122
  }
@@ -16392,7 +16517,7 @@
16392
16517
  if (this._leader !== map) return;
16393
16518
  for (const other of this._followers(map)) if (other._zoomAnimated) {
16394
16519
  this._animating.add(other);
16395
- other._animateZoom(e.center, this._zoomFor(other, map, e.zoom), true, e.noUpdate);
16520
+ other._animateZoom(e.center, this._zoomFor(other, map, e.zoom), e.noUpdate);
16396
16521
  }
16397
16522
  }
16398
16523
  _onMoveEnd(map) {
@@ -16422,10 +16547,7 @@
16422
16547
  other._rawPanBy(offset);
16423
16548
  other.fire("move");
16424
16549
  }
16425
- } else other._move(center, zoom, during ? {
16426
- pinch: true,
16427
- round: false
16428
- } : void 0);
16550
+ } else other._move(center, zoom, during ? { pinch: true } : void 0);
16429
16551
  }
16430
16552
  _syncAll(map) {
16431
16553
  for (const other of this._maps.filter((m) => m !== map)) {
@@ -16557,6 +16679,7 @@
16557
16679
  * Called when the handler is enabled, adds the event hooks.
16558
16680
  */
16559
16681
  addHooks() {
16682
+ this._map._displaceHandler = this;
16560
16683
  this._map.on("zoomend", this.schedule, this);
16561
16684
  this._map.on("layeradd", this._onLayerAdd, this);
16562
16685
  this._map.on("layerremove", this._onLayerRemove, this);
@@ -16568,6 +16691,7 @@
16568
16691
  * true positions of the markers.
16569
16692
  */
16570
16693
  removeHooks() {
16694
+ if (this._map._displaceHandler === this) delete this._map._displaceHandler;
16571
16695
  this._map.off("zoomend", this.schedule, this);
16572
16696
  this._map.off("layeradd", this._onLayerAdd, this);
16573
16697
  this._map.off("layerremove", this._onLayerRemove, this);
@@ -16639,6 +16763,7 @@
16639
16763
  * @param {LatLng} latLng
16640
16764
  */
16641
16765
  _moveTo(marker, latLng) {
16766
+ if (marker.getLatLng().equals(latLng)) return;
16642
16767
  this._moving = true;
16643
16768
  try {
16644
16769
  marker.setLatLng(latLng);
@@ -16658,6 +16783,19 @@
16658
16783
  if (this._enabled && this._map.hasLayer(event.target)) this.schedule();
16659
16784
  }
16660
16785
  /**
16786
+ * Called by `CircleMarker#beforeAdd`: puts a marker whose `displaceId` already
16787
+ * has a displaced position at the current zoom (e.g. the same station on
16788
+ * another layer) there before it is drawn, instead of drawing it twice.
16789
+ * @param {CircleMarker} marker
16790
+ */
16791
+ _beforeMarkerAdd(marker) {
16792
+ if (!displaceable(marker)) return;
16793
+ this._track(marker);
16794
+ const { displaceId } = marker.options;
16795
+ const latLng = displaceId && this._displacedPositions.get(this._map.getZoom())?.get(displaceId);
16796
+ if (latLng) this._moveTo(marker, latLng);
16797
+ }
16798
+ /**
16661
16799
  * @param {LayerEvent} event
16662
16800
  */
16663
16801
  _onLayerAdd(event) {
@@ -16694,6 +16832,10 @@
16694
16832
  }
16695
16833
  };
16696
16834
  /**
16835
+ * Movement in pixels per pass below which `displace` stops early
16836
+ */
16837
+ const MIN_MOVE = .01;
16838
+ /**
16697
16839
  * Displaces overlapping points in pixel space until they are at least
16698
16840
  * `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed
16699
16841
  * apart by half of its overlap per pass. Neighbour lookup uses a grid (cell
@@ -16701,7 +16843,8 @@
16701
16843
  *
16702
16844
  * No point ends up further than `maxDisplacement` away from where it started.
16703
16845
  * Points which hit that limit stay overlapping – the limit wins over the
16704
- * separation.
16846
+ * separation. The relaxation stops early once the points are separated or
16847
+ * no point moves by more than a hundredth of a pixel per pass.
16705
16848
  *
16706
16849
  * @param {Point[]} points Pixel coordinates (modified in place)
16707
16850
  * @param {number} minSeparation Minimum distance between centers, in pixels
@@ -16721,49 +16864,62 @@
16721
16864
  for (let iter = 0; iter < iterations; iter++) {
16722
16865
  dx.fill(0);
16723
16866
  dy.fill(0);
16724
- /** @type {Map<string, number[]>} */
16867
+ /** @type {Map<number, Map<number, number[]>>} */
16725
16868
  const grid = /* @__PURE__ */ new Map();
16726
16869
  for (let i = 0; i < n; i++) {
16727
- const key = `${Math.floor(points[i].x / cell)},${Math.floor(points[i].y / cell)}`;
16728
- const bucket = grid.get(key);
16870
+ const cx = Math.floor(points[i].x / cell);
16871
+ const cy = Math.floor(points[i].y / cell);
16872
+ let column = grid.get(cx);
16873
+ if (!column) {
16874
+ column = /* @__PURE__ */ new Map();
16875
+ grid.set(cx, column);
16876
+ }
16877
+ const bucket = column.get(cy);
16729
16878
  if (bucket) bucket.push(i);
16730
- else grid.set(key, [i]);
16879
+ else column.set(cy, [i]);
16731
16880
  }
16732
16881
  let overlaps = 0;
16733
16882
  for (let i = 0; i < n; i++) {
16734
16883
  const cx = Math.floor(points[i].x / cell);
16735
16884
  const cy = Math.floor(points[i].y / cell);
16736
- for (let gx = cx - 1; gx <= cx + 1; gx++) for (let gy = cy - 1; gy <= cy + 1; gy++) {
16737
- const bucket = grid.get(`${gx},${gy}`);
16738
- if (!bucket) continue;
16739
- for (const j of bucket) {
16740
- if (j <= i) continue;
16741
- let vx = points[i].x - points[j].x;
16742
- let vy = points[i].y - points[j].y;
16743
- const distSq = vx * vx + vy * vy;
16744
- if (distSq >= sepSq) continue;
16745
- overlaps++;
16746
- let dist;
16747
- if (distSq === 0) {
16748
- const angle = i * 2.399963229728653;
16749
- vx = Math.cos(angle);
16750
- vy = Math.sin(angle);
16751
- dist = 1;
16752
- } else {
16753
- dist = Math.sqrt(distSq);
16754
- vx /= dist;
16755
- vy /= dist;
16885
+ for (let gx = cx - 1; gx <= cx + 1; gx++) {
16886
+ const column = grid.get(gx);
16887
+ if (!column) continue;
16888
+ for (let gy = cy - 1; gy <= cy + 1; gy++) {
16889
+ const bucket = column.get(gy);
16890
+ if (!bucket) continue;
16891
+ for (const j of bucket) {
16892
+ if (j <= i) continue;
16893
+ let vx = points[i].x - points[j].x;
16894
+ let vy = points[i].y - points[j].y;
16895
+ const distSq = vx * vx + vy * vy;
16896
+ if (distSq >= sepSq) continue;
16897
+ overlaps++;
16898
+ let dist;
16899
+ if (distSq === 0) {
16900
+ const angle = i * 2.399963229728653;
16901
+ vx = Math.cos(angle);
16902
+ vy = Math.sin(angle);
16903
+ dist = 1;
16904
+ } else {
16905
+ dist = Math.sqrt(distSq);
16906
+ vx /= dist;
16907
+ vy /= dist;
16908
+ }
16909
+ const push = (sep - dist) / 2;
16910
+ dx[i] += vx * push;
16911
+ dy[i] += vy * push;
16912
+ dx[j] -= vx * push;
16913
+ dy[j] -= vy * push;
16756
16914
  }
16757
- const push = (sep - dist) / 2;
16758
- dx[i] += vx * push;
16759
- dy[i] += vy * push;
16760
- dx[j] -= vx * push;
16761
- dy[j] -= vy * push;
16762
16915
  }
16763
16916
  }
16764
16917
  }
16765
16918
  if (overlaps === 0) break;
16919
+ let maxMoveSq = 0;
16766
16920
  for (let i = 0; i < n; i++) {
16921
+ const x = points[i].x;
16922
+ const y = points[i].y;
16767
16923
  points[i].x += dx[i];
16768
16924
  points[i].y += dy[i];
16769
16925
  const ox = points[i].x - ax[i];
@@ -16774,7 +16930,11 @@
16774
16930
  points[i].x = ax[i] + ox * scale;
16775
16931
  points[i].y = ay[i] + oy * scale;
16776
16932
  }
16933
+ const mx = points[i].x - x;
16934
+ const my = points[i].y - y;
16935
+ maxMoveSq = Math.max(maxMoveSq, mx * mx + my * my);
16777
16936
  }
16937
+ if (maxMoveSq < MIN_MOVE * MIN_MOVE) break;
16778
16938
  }
16779
16939
  return points;
16780
16940
  }
@@ -16844,7 +17004,6 @@
16844
17004
  disableClickPropagation(button);
16845
17005
  on(button, "click", stop);
16846
17006
  on(button, "click", this._resetNorth, this);
16847
- on(button, "click", this._refocusOnMap, this);
16848
17007
  this._update();
16849
17008
  map.on("rotate", this._update, this);
16850
17009
  return container;
@@ -16948,8 +17107,8 @@
16948
17107
  if (!this._rotatePane) {
16949
17108
  const rotatePane = this._rotatePane = create("div", "maplair-rotate-pane");
16950
17109
  rotatedMaps.set(rotatePane, this);
16951
- this._container.insertBefore(rotatePane, this._mapPane);
16952
- rotatePane.appendChild(this._mapPane);
17110
+ this._mapPane.before(rotatePane);
17111
+ rotatePane.append(this._mapPane);
16953
17112
  }
16954
17113
  if (bearing === this.getBearing()) return;
16955
17114
  this._bearing = bearing;
@@ -17038,9 +17197,9 @@
17038
17197
  return panBy.call(this, this._rotateToPane(Point.from(offset)), options);
17039
17198
  },
17040
17199
  _tryAnimatedPan(center, options) {
17041
- const offset = this._rotateToContainer(this._getCenterOffset(center)._trunc());
17042
- if (options?.animate !== true && !this.getSize().contains(offset)) return false;
17043
- this.panBy(offset, options);
17200
+ const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
17201
+ if (options?.animate !== true && !this.getSize().contains(this._rotateToContainer(offset))) return false;
17202
+ this._panBy(offset, options);
17044
17203
  return true;
17045
17204
  },
17046
17205
  /**
@@ -17098,7 +17257,8 @@
17098
17257
  /** @typedef {typeof blanketOverlayRotationMethods} BlanketOverlayMapRotationMethods */
17099
17258
  BlanketOverlay.include({
17100
17259
  _updateTransform(center, zoom) {
17101
- const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map._getViewSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom))._round();
17260
+ const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map._getViewSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom));
17261
+ if (scale === 1) this._map._snapLayerPoint(topLeftOffset);
17102
17262
  setTransform(this._container, topLeftOffset, scale);
17103
17263
  },
17104
17264
  _onMoveEnd(ev) {
@@ -17133,7 +17293,7 @@
17133
17293
  },
17134
17294
  _updatePosition() {
17135
17295
  if (!this._map) return;
17136
- const map = this._map, pos = map.latLngToLayerPoint(this._latlng)._round(), anchor = map._rotateToPane(new Point(this._getAnchor()));
17296
+ const map = this._map, pos = map._snapLayerPoint(map.latLngToLayerPoint(this._latlng)), anchor = map._rotateToPane(new Point(this._getAnchor()));
17137
17297
  let offset = Point.from(this.options.offset);
17138
17298
  const transformed = this._zoomAnimated || this.options.overflow || map._bearing;
17139
17299
  if (!transformed) offset = offset.add(pos).add(anchor);
@@ -17332,10 +17492,7 @@
17332
17492
  this._moved = true;
17333
17493
  }
17334
17494
  cancelAnimationFrame(this._animRequest);
17335
- const moveFn = map._move.bind(map, this._center, this._zoom, {
17336
- pinch: true,
17337
- round: false
17338
- }, void 0);
17495
+ const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
17339
17496
  this._animRequest = requestAnimationFrame(moveFn.bind(this));
17340
17497
  e.preventDefault();
17341
17498
  }
@@ -17903,7 +18060,10 @@ load(source, fetchOptions = this.options.fetchOptions) {
17903
18060
  });
17904
18061
  CircleMarker.include({ setRadius(radius) {
17905
18062
  this._takeZoomStyles({ radius });
17906
- return this._zoomStyles?.radius && this._map ? setRadius.call(this, evaluate(radius, this._map.getZoom())) : setRadius.call(this, radius);
18063
+ if (!this._zoomStyles?.radius) return setRadius.call(this, radius);
18064
+ if (this._map) return setRadius.call(this, evaluate(radius, this._map.getZoom()));
18065
+ this.options.radius = this._radius = radius;
18066
+ return this;
17907
18067
  } });
17908
18068
  Path.addInitHook(function() {
17909
18069
  this._takeZoomStyles(this.options);