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.
- package/CHANGELOG.md +151 -8
- package/dist/esm/control/AttributionControl.js +30 -13
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +0 -1
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -1
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +16 -11
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +0 -1
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +46 -27
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +0 -1
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -8
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +3 -2
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +14 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +3 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +17 -5
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +4 -7
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +5 -5
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +10 -8
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +24 -35
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +6 -3
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +2 -2
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +16 -19
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +10 -3
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -7
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +3 -2
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +25 -25
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +8 -5
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +12 -7
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +33 -15
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +48 -56
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +2 -2
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +4 -8
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +37 -17
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +11 -12
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +54 -53
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +1 -1
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +29 -21
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +19 -15
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +45 -94
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +8 -9
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +15 -4
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +10 -5
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +10 -11
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +19 -26
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +16 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +3 -3
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +9 -11
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +158 -71
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +2 -5
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +68 -30
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +7 -2
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +8 -20
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +970 -810
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +970 -810
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/en.json +1 -0
- package/package.json +1 -1
- package/src/control/AttributionControl.js +37 -11
- package/src/control/ButtonControl.js +0 -1
- package/src/control/ContextMenu.js +1 -1
- package/src/control/Control.js +13 -16
- package/src/control/FullscreenControl.js +0 -1
- package/src/control/LayersControl.js +61 -37
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +10 -8
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +11 -13
- package/src/core/Events.js +6 -2
- package/src/core/Util.js +17 -4
- package/src/dom/DomEvent.PointerEvents.js +68 -2
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +11 -8
- package/src/geo/LatLng.js +24 -37
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +22 -28
- package/src/geometry/PolyUtil.js +12 -3
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +6 -3
- package/src/layer/DivOverlay.js +30 -32
- package/src/layer/ImageOverlay.js +12 -9
- package/src/layer/Layer.js +19 -7
- package/src/layer/Popup.js +41 -21
- package/src/layer/Tooltip.js +50 -70
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +41 -20
- package/src/layer/marker/Marker.Drag.js +22 -24
- package/src/layer/marker/Marker.js +71 -64
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +41 -30
- package/src/layer/tile/TileLayer.js +31 -21
- package/src/layer/tile/WMSTileLayer.js +4 -2
- package/src/layer/vector/Canvas.js +53 -149
- package/src/layer/vector/Circle.js +13 -13
- package/src/layer/vector/CircleMarker.js +16 -3
- package/src/layer/vector/Path.ZoomStyles.js +5 -3
- package/src/layer/vector/Path.js +11 -5
- package/src/layer/vector/Polygon.js +11 -10
- package/src/layer/vector/Polyline.js +20 -21
- package/src/layer/vector/Renderer.getRenderer.js +2 -1
- package/src/layer/vector/Renderer.js +21 -3
- package/src/layer/vector/SVG.js +3 -3
- package/src/map/Map.Rotation.js +13 -9
- package/src/map/Map.js +195 -83
- package/src/map/MapSync.js +2 -2
- package/src/map/handler/BoxZoomHandler.js +5 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/DragHandler.js +5 -5
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +4 -4
- package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
- package/src/map/handler/TapDragZoomHandler.js +2 -2
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +50 -10
- package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
- package/src/dom/DomEvent.DoubleTap.js +0 -143
package/dist/maplair-src.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @preserve
|
|
2
|
-
* Maplair 4.
|
|
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
|
|
|
@@ -15,7 +15,7 @@ var __exportAll = (all, no_symbols) => {
|
|
|
15
15
|
return target;
|
|
16
16
|
};
|
|
17
17
|
// package.json
|
|
18
|
-
var version$1 = "4.
|
|
18
|
+
var version$1 = "4.5.0";
|
|
19
19
|
// src/core/Util.js
|
|
20
20
|
var Util_exports = /* @__PURE__ */ __exportAll({
|
|
21
21
|
falseFn: () => falseFn,
|
|
@@ -26,6 +26,7 @@ var Util_exports = /* @__PURE__ */ __exportAll({
|
|
|
26
26
|
stamp: () => stamp,
|
|
27
27
|
template: () => template,
|
|
28
28
|
throttle: () => throttle,
|
|
29
|
+
toNumber: () => toNumber,
|
|
29
30
|
wrapNum: () => wrapNum
|
|
30
31
|
});
|
|
31
32
|
/**
|
|
@@ -100,11 +101,21 @@ function falseFn() {
|
|
|
100
101
|
* @param {number|false} [precision]
|
|
101
102
|
* @returns {number}
|
|
102
103
|
*/
|
|
103
|
-
function formatNum(num, precision) {
|
|
104
|
+
function formatNum(num, precision = 6) {
|
|
104
105
|
if (precision === false) return num;
|
|
105
|
-
const pow = 10 **
|
|
106
|
+
const pow = 10 ** precision;
|
|
106
107
|
return Math.round(num * pow) / pow;
|
|
107
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns `value` if it's a number (including `Infinity`), converts it if it's a
|
|
111
|
+
* numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns
|
|
112
|
+
* `''`, `null` and booleans into `0` or `1`.
|
|
113
|
+
* @param {unknown} value
|
|
114
|
+
* @returns {number}
|
|
115
|
+
*/
|
|
116
|
+
function toNumber(value) {
|
|
117
|
+
return typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? +value : NaN;
|
|
118
|
+
}
|
|
108
119
|
const WHITESPACE_RE = /\s+/;
|
|
109
120
|
/**
|
|
110
121
|
* Trims and splits the string on whitespace and returns the array of parts.
|
|
@@ -112,7 +123,8 @@ const WHITESPACE_RE = /\s+/;
|
|
|
112
123
|
* @returns {string[]}
|
|
113
124
|
*/
|
|
114
125
|
function splitWords(str) {
|
|
115
|
-
|
|
126
|
+
const trimmed = str.trim();
|
|
127
|
+
return WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];
|
|
116
128
|
}
|
|
117
129
|
/**
|
|
118
130
|
* Merges the given properties to the `options` of the `obj` object, returning the
|
|
@@ -138,7 +150,7 @@ function getDefaultOptions(cls) {
|
|
|
138
150
|
}
|
|
139
151
|
return defaults;
|
|
140
152
|
}
|
|
141
|
-
const templateRe = /\{ *([\w_ -]
|
|
153
|
+
const templateRe = /\{ *([\w_ -]+?) *\}/g;
|
|
142
154
|
/**
|
|
143
155
|
* Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`
|
|
144
156
|
* and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string
|
|
@@ -419,31 +431,25 @@ var Point = class Point {
|
|
|
419
431
|
* @param {boolean} [round]
|
|
420
432
|
*/
|
|
421
433
|
constructor(x, y, round) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if (x instanceof Point) {
|
|
425
|
-
_x = x.x;
|
|
426
|
-
_y = x.y;
|
|
427
|
-
} else if (Array.isArray(x)) {
|
|
434
|
+
let _x = x, _y = y;
|
|
435
|
+
if (Array.isArray(x)) {
|
|
428
436
|
_x = x[0];
|
|
429
437
|
_y = x[1];
|
|
430
|
-
} else if (typeof x === "object" &&
|
|
438
|
+
} else if (typeof x === "object" && x !== null) {
|
|
431
439
|
_x = x.x;
|
|
432
440
|
_y = x.y;
|
|
433
|
-
} else {
|
|
434
|
-
_x = x;
|
|
435
|
-
_y = y;
|
|
436
441
|
}
|
|
437
442
|
/**
|
|
438
443
|
* The `x` coordinate of the point.
|
|
439
444
|
* @type {number}
|
|
440
445
|
*/
|
|
441
|
-
this.x = round ? Math.round(_x) : _x;
|
|
446
|
+
this.x = round ? Math.round(toNumber(_x)) : toNumber(_x);
|
|
442
447
|
/**
|
|
443
448
|
* The `y` coordinate of the point.
|
|
444
449
|
* @type {number}
|
|
445
450
|
*/
|
|
446
|
-
this.y = round ? Math.round(_y) : _y;
|
|
451
|
+
this.y = round ? Math.round(toNumber(_y)) : toNumber(_y);
|
|
452
|
+
if (this.x !== this.x || this.y !== this.y) throw new Error(`Invalid Point object: (${_x}, ${_y})`);
|
|
447
453
|
}
|
|
448
454
|
/**
|
|
449
455
|
* Returns the given `Point` object as it is (unless `round` is set), or else a new
|
|
@@ -471,10 +477,11 @@ var Point = class Point {
|
|
|
471
477
|
* @returns {boolean}
|
|
472
478
|
*/
|
|
473
479
|
static validate(x, y) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
480
|
+
try {
|
|
481
|
+
return !!new Point(x, y);
|
|
482
|
+
} catch {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
478
485
|
}
|
|
479
486
|
/**
|
|
480
487
|
* Returns the result of addition of the current and the given points.
|
|
@@ -533,19 +540,21 @@ var Point = class Point {
|
|
|
533
540
|
* `scale`. In linear algebra terms, multiply the point by the
|
|
534
541
|
* [scaling matrix](https://en.wikipedia.org/wiki/Scaling_%28geometry%29#Matrix_representation)
|
|
535
542
|
* defined by `scale`.
|
|
536
|
-
* @param {
|
|
543
|
+
* @param {PointExpression} point The scale.
|
|
537
544
|
* @returns {Point}
|
|
538
545
|
*/
|
|
539
546
|
scaleBy(point) {
|
|
547
|
+
point = Point.from(point);
|
|
540
548
|
return new Point(this.x * point.x, this.y * point.y);
|
|
541
549
|
}
|
|
542
550
|
/**
|
|
543
551
|
* Inverse of `scaleBy`. Divide each coordinate of the current point by
|
|
544
552
|
* each coordinate of `scale`.
|
|
545
|
-
* @param {
|
|
553
|
+
* @param {PointExpression} point The scale.
|
|
546
554
|
* @returns {Point}
|
|
547
555
|
*/
|
|
548
556
|
unscaleBy(point) {
|
|
557
|
+
point = Point.from(point);
|
|
549
558
|
return new Point(this.x / point.x, this.y / point.y);
|
|
550
559
|
}
|
|
551
560
|
/**
|
|
@@ -634,100 +643,16 @@ var Point = class Point {
|
|
|
634
643
|
return `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;
|
|
635
644
|
}
|
|
636
645
|
};
|
|
637
|
-
// src/dom/DomEvent.DoubleTap.js
|
|
638
|
-
function makeDblclick(ev) {
|
|
639
|
-
const init = {
|
|
640
|
-
bubbles: ev.bubbles,
|
|
641
|
-
cancelable: ev.cancelable,
|
|
642
|
-
composed: ev.composed,
|
|
643
|
-
detail: 2,
|
|
644
|
-
view: ev.view,
|
|
645
|
-
screenX: ev.screenX,
|
|
646
|
-
screenY: ev.screenY,
|
|
647
|
-
clientX: ev.clientX,
|
|
648
|
-
clientY: ev.clientY,
|
|
649
|
-
ctrlKey: ev.ctrlKey,
|
|
650
|
-
shiftKey: ev.shiftKey,
|
|
651
|
-
altKey: ev.altKey,
|
|
652
|
-
metaKey: ev.metaKey,
|
|
653
|
-
button: ev.button,
|
|
654
|
-
buttons: ev.buttons,
|
|
655
|
-
relatedTarget: ev.relatedTarget,
|
|
656
|
-
region: ev.region
|
|
657
|
-
};
|
|
658
|
-
let newEvent;
|
|
659
|
-
if (ev instanceof PointerEvent) newEvent = new PointerEvent("dblclick", {
|
|
660
|
-
...init,
|
|
661
|
-
pointerId: ev.pointerId,
|
|
662
|
-
width: ev.width,
|
|
663
|
-
height: ev.height,
|
|
664
|
-
pressure: ev.pressure,
|
|
665
|
-
tangentialPressure: ev.tangentialPressure,
|
|
666
|
-
tiltX: ev.tiltX,
|
|
667
|
-
tiltY: ev.tiltY,
|
|
668
|
-
twist: ev.twist,
|
|
669
|
-
pointerType: ev.pointerType,
|
|
670
|
-
isPrimary: ev.isPrimary
|
|
671
|
-
});
|
|
672
|
-
else newEvent = new MouseEvent("dblclick", init);
|
|
673
|
-
return newEvent;
|
|
674
|
-
}
|
|
675
|
-
const delay$1 = 200;
|
|
676
|
-
/**
|
|
677
|
-
* Adds a `dblclick` listener which also handles double taps (simulating `dblclick`
|
|
678
|
-
* on platforms which don't fire it for touch events).
|
|
679
|
-
* @param {EventTarget} obj
|
|
680
|
-
* @param {(ev: MouseEvent) => void} handler
|
|
681
|
-
* @returns {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}}
|
|
682
|
-
* The listeners to pass to `removeDoubleTapListener`.
|
|
683
|
-
*/
|
|
684
|
-
function addDoubleTapListener(obj, handler) {
|
|
685
|
-
obj.addEventListener("dblclick", handler);
|
|
686
|
-
let last = 0, detail, pointerType;
|
|
687
|
-
function onPointerDown(ev) {
|
|
688
|
-
pointerType = ev.pointerType;
|
|
689
|
-
}
|
|
690
|
-
function simDblclick(ev) {
|
|
691
|
-
if (ev.detail !== 1) {
|
|
692
|
-
detail = ev.detail;
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
if (pointerType === "mouse" || ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents) return;
|
|
696
|
-
const path = ev.composedPath();
|
|
697
|
-
if (path.some((el) => el instanceof HTMLLabelElement && el.htmlFor) && !path.some((el) => el instanceof HTMLInputElement || el instanceof HTMLSelectElement)) return;
|
|
698
|
-
const now = Date.now();
|
|
699
|
-
if (now - last <= delay$1) {
|
|
700
|
-
detail++;
|
|
701
|
-
if (detail === 2) ev.target.dispatchEvent(makeDblclick(ev));
|
|
702
|
-
} else detail = 1;
|
|
703
|
-
last = now;
|
|
704
|
-
}
|
|
705
|
-
obj.addEventListener("pointerdown", onPointerDown, true);
|
|
706
|
-
obj.addEventListener("click", simDblclick);
|
|
707
|
-
return {
|
|
708
|
-
dblclick: handler,
|
|
709
|
-
onPointerDown,
|
|
710
|
-
simDblclick
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Removes the listeners added by `addDoubleTapListener`.
|
|
715
|
-
* @param {EventTarget} obj
|
|
716
|
-
* @param {{dblclick: (ev: MouseEvent) => void, simDblclick: (ev: PointerEvent) => void}} handlers
|
|
717
|
-
* @returns {void}
|
|
718
|
-
*/
|
|
719
|
-
function removeDoubleTapListener(obj, handlers) {
|
|
720
|
-
obj.removeEventListener("dblclick", handlers.dblclick);
|
|
721
|
-
obj.removeEventListener("pointerdown", handlers.onPointerDown, true);
|
|
722
|
-
obj.removeEventListener("click", handlers.simDblclick);
|
|
723
|
-
}
|
|
724
646
|
// src/dom/DomEvent.PointerEvents.js
|
|
725
647
|
var DomEvent_PointerEvents_exports = /* @__PURE__ */ __exportAll({
|
|
726
648
|
disablePointerDetection: () => disablePointerDetection,
|
|
727
649
|
enablePointerDetection: () => enablePointerDetection,
|
|
728
|
-
getPointers: () => getPointers
|
|
650
|
+
getPointers: () => getPointers,
|
|
651
|
+
isClickDisabled: () => isClickDisabled,
|
|
652
|
+
simulateDblclick: () => simulateDblclick
|
|
729
653
|
});
|
|
730
654
|
const activePointers = /* @__PURE__ */ new Map();
|
|
655
|
+
let lastPointerType;
|
|
731
656
|
/**
|
|
732
657
|
* Enables pointer detection and capture for the document.
|
|
733
658
|
* @group Pointer detection
|
|
@@ -753,7 +678,24 @@ function disablePointerDetection(el) {
|
|
|
753
678
|
el.removeEventListener("pointerup", _onDelete, { capture: true });
|
|
754
679
|
el.removeEventListener("pointercancel", _onDelete, { capture: true });
|
|
755
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Whether `el` is inside an element that `DomEvent.disableClickPropagation` was called
|
|
683
|
+
* on (before reaching `container`), or detached from the DOM.
|
|
684
|
+
* @internal
|
|
685
|
+
* @param {Node|null} el
|
|
686
|
+
* @param {EventTarget|null} container
|
|
687
|
+
* @returns {boolean}
|
|
688
|
+
*/
|
|
689
|
+
function isClickDisabled(el, container) {
|
|
690
|
+
while (el && el !== container) {
|
|
691
|
+
if (el["_maplair_disable_click"] || !el.parentNode) return true;
|
|
692
|
+
el = el.parentNode;
|
|
693
|
+
}
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
756
696
|
function _onSet(e) {
|
|
697
|
+
lastPointerType = e.pointerType;
|
|
698
|
+
if (isClickDisabled(e.target, e.currentTarget)) return;
|
|
757
699
|
if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
|
|
758
700
|
activePointers.set(e.pointerId, e);
|
|
759
701
|
}
|
|
@@ -772,6 +714,56 @@ function _onDelete(e) {
|
|
|
772
714
|
function getPointers() {
|
|
773
715
|
return [...activePointers.values()];
|
|
774
716
|
}
|
|
717
|
+
const dblclickProps = [
|
|
718
|
+
"bubbles",
|
|
719
|
+
"cancelable",
|
|
720
|
+
"composed",
|
|
721
|
+
"view",
|
|
722
|
+
"screenX",
|
|
723
|
+
"screenY",
|
|
724
|
+
"clientX",
|
|
725
|
+
"clientY",
|
|
726
|
+
"ctrlKey",
|
|
727
|
+
"shiftKey",
|
|
728
|
+
"altKey",
|
|
729
|
+
"metaKey",
|
|
730
|
+
"button",
|
|
731
|
+
"buttons",
|
|
732
|
+
"relatedTarget"
|
|
733
|
+
];
|
|
734
|
+
let lastClickTime = 0;
|
|
735
|
+
let lastClick;
|
|
736
|
+
let lastClickMap;
|
|
737
|
+
let clickCount = 0;
|
|
738
|
+
/**
|
|
739
|
+
* Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),
|
|
740
|
+
* which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The
|
|
741
|
+
* pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on
|
|
742
|
+
* clicks from touch (WebKit bug 282988). Called by the map for clicks in it.
|
|
743
|
+
* @internal
|
|
744
|
+
* @param {MouseEvent} e
|
|
745
|
+
* @param {HTMLElement} mapContainer The container of the map, two taps make a double
|
|
746
|
+
* tap only in the same map.
|
|
747
|
+
* @returns {void}
|
|
748
|
+
*/
|
|
749
|
+
function simulateDblclick(e, mapContainer) {
|
|
750
|
+
if (e === lastClick) return;
|
|
751
|
+
lastClick = e;
|
|
752
|
+
const target = e.target;
|
|
753
|
+
if (e.detail !== 1 || lastPointerType === "mouse" || target.closest("label")) {
|
|
754
|
+
clickCount = 0;
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
const now = Date.now();
|
|
758
|
+
clickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;
|
|
759
|
+
lastClickTime = now;
|
|
760
|
+
lastClickMap = mapContainer;
|
|
761
|
+
if (clickCount === 2) {
|
|
762
|
+
const init = { detail: 2 };
|
|
763
|
+
for (const prop of dblclickProps) init[prop] = e[prop];
|
|
764
|
+
target.dispatchEvent(new MouseEvent("dblclick", init));
|
|
765
|
+
}
|
|
766
|
+
}
|
|
775
767
|
// src/dom/DomEvent.js
|
|
776
768
|
var DomEvent_exports = /* @__PURE__ */ __exportAll({
|
|
777
769
|
PointerEvents: () => DomEvent_PointerEvents_exports,
|
|
@@ -839,11 +831,10 @@ function batchRemove(obj, filterFn) {
|
|
|
839
831
|
function addOne(obj, type, fn, context) {
|
|
840
832
|
const id = type + stamp(fn) + (context ? `_${stamp(context)}` : "");
|
|
841
833
|
if (obj[eventsKey] && obj[eventsKey][id]) return;
|
|
842
|
-
|
|
834
|
+
const handler = function(e) {
|
|
843
835
|
return fn.call(context || obj, e);
|
|
844
836
|
};
|
|
845
|
-
|
|
846
|
-
else obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
|
|
837
|
+
obj.addEventListener(type, handler, type === "wheel" ? { passive: false } : false);
|
|
847
838
|
obj[eventsKey] ??= {};
|
|
848
839
|
obj[eventsKey][id] = handler;
|
|
849
840
|
}
|
|
@@ -851,8 +842,7 @@ function removeOne(obj, type, fn, context, id) {
|
|
|
851
842
|
id ??= type + stamp(fn) + (context ? `_${stamp(context)}` : "");
|
|
852
843
|
const handler = obj[eventsKey] && obj[eventsKey][id];
|
|
853
844
|
if (!handler) return;
|
|
854
|
-
|
|
855
|
-
else obj.removeEventListener(type, handler, false);
|
|
845
|
+
obj.removeEventListener(type, handler, false);
|
|
856
846
|
obj[eventsKey][id] = null;
|
|
857
847
|
}
|
|
858
848
|
/**
|
|
@@ -938,7 +928,7 @@ function getWheelPxFactor() {
|
|
|
938
928
|
* @returns {number}
|
|
939
929
|
*/
|
|
940
930
|
function getWheelDelta(e) {
|
|
941
|
-
return e.deltaY
|
|
931
|
+
return -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;
|
|
942
932
|
}
|
|
943
933
|
/**
|
|
944
934
|
* Checks if the pointer really left/entered the element `el` (for
|
|
@@ -985,7 +975,7 @@ function get(id) {
|
|
|
985
975
|
function create(tagName, className, container) {
|
|
986
976
|
const el = document.createElement(tagName);
|
|
987
977
|
el.className = className ?? "";
|
|
988
|
-
container?.
|
|
978
|
+
container?.append(el);
|
|
989
979
|
return el;
|
|
990
980
|
}
|
|
991
981
|
/**
|
|
@@ -997,8 +987,8 @@ function create(tagName, className, container) {
|
|
|
997
987
|
function toFront(el) {
|
|
998
988
|
const parent = el.parentNode;
|
|
999
989
|
if (!parent || parent.lastChild === el) return;
|
|
1000
|
-
if (el.matches(":hover")) while (el.nextSibling)
|
|
1001
|
-
else parent.
|
|
990
|
+
if (el.matches(":hover")) while (el.nextSibling) el.before(el.nextSibling);
|
|
991
|
+
else parent.append(el);
|
|
1002
992
|
}
|
|
1003
993
|
/**
|
|
1004
994
|
* Makes `el` the first child of its parent, so it renders behind the other children.
|
|
@@ -1008,8 +998,8 @@ function toFront(el) {
|
|
|
1008
998
|
function toBack(el) {
|
|
1009
999
|
const parent = el.parentNode;
|
|
1010
1000
|
if (!parent || parent.firstChild === el) return;
|
|
1011
|
-
if (el.matches(":hover")) while (el.previousSibling)
|
|
1012
|
-
else parent.
|
|
1001
|
+
if (el.matches(":hover")) while (el.previousSibling) el.after(el.previousSibling);
|
|
1002
|
+
else parent.prepend(el);
|
|
1013
1003
|
}
|
|
1014
1004
|
/**
|
|
1015
1005
|
* Resets the 3D CSS transform of `el` so it is translated by `offset` pixels
|
|
@@ -1148,12 +1138,16 @@ const mapControlMethods = {
|
|
|
1148
1138
|
* @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that
|
|
1149
1139
|
* removes the listeners previously added in `onAdd`. Called on
|
|
1150
1140
|
* [`control.remove()`](#control-remove).
|
|
1141
|
+
* @property {() => Record<string, Function>} [getEvents] Should return an object like
|
|
1142
|
+
* `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this object
|
|
1143
|
+
* will be automatically added and removed from the map with your control.
|
|
1151
1144
|
* @lends Control
|
|
1152
1145
|
*/
|
|
1153
1146
|
const controlOrders = /* @__PURE__ */ new WeakMap();
|
|
1154
1147
|
/**
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1148
|
+
* Base class for map controls such as `ZoomControl`, `AttributionControl`,
|
|
1149
|
+
* `LayersControl` and `ScaleControl`, which handles positioning them. Extend it to
|
|
1150
|
+
* create your own controls.
|
|
1157
1151
|
*
|
|
1158
1152
|
* Every control should extend from `Control` and (re-)implement the following methods:
|
|
1159
1153
|
*
|
|
@@ -1163,6 +1157,9 @@ const controlOrders = /* @__PURE__ */ new WeakMap();
|
|
|
1163
1157
|
* * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes
|
|
1164
1158
|
* the listeners previously added in [`onAdd`](#control-onadd). Called on
|
|
1165
1159
|
* [`control.remove()`](#control-remove).
|
|
1160
|
+
* * `getEvents(): Object` (optional) should return an object like
|
|
1161
|
+
* `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this
|
|
1162
|
+
* object will be automatically added and removed from the map with your control.
|
|
1166
1163
|
*/
|
|
1167
1164
|
var Control = class Control extends Class {
|
|
1168
1165
|
static defaultOptions = {
|
|
@@ -1216,7 +1213,11 @@ var Control = class Control extends Class {
|
|
|
1216
1213
|
const order = this.options.order ?? 0, bottom = pos.includes("bottom"), children = [...corner.children];
|
|
1217
1214
|
controlOrders.set(container, order);
|
|
1218
1215
|
corner.insertBefore(container, children.find((el) => bottom ? (controlOrders.get(el) ?? 0) <= order : (controlOrders.get(el) ?? 0) > order) ?? null);
|
|
1219
|
-
this.
|
|
1216
|
+
this._mapEvents = {
|
|
1217
|
+
...this.getEvents?.(),
|
|
1218
|
+
unload: this.remove
|
|
1219
|
+
};
|
|
1220
|
+
map.on(this._mapEvents, this);
|
|
1220
1221
|
return this;
|
|
1221
1222
|
}
|
|
1222
1223
|
/**
|
|
@@ -1226,17 +1227,11 @@ var Control = class Control extends Class {
|
|
|
1226
1227
|
remove() {
|
|
1227
1228
|
if (!this._map) return this;
|
|
1228
1229
|
this._container.remove();
|
|
1229
|
-
|
|
1230
|
-
this.
|
|
1230
|
+
this._map.off(this._mapEvents, this);
|
|
1231
|
+
this.onRemove?.(this._map);
|
|
1231
1232
|
this._map = null;
|
|
1232
1233
|
return this;
|
|
1233
1234
|
}
|
|
1234
|
-
_refocusOnMap(e) {
|
|
1235
|
-
if (this._map && e && !(e.screenX === 0 && e.screenY === 0)) this._map.getContainer().focus({
|
|
1236
|
-
preventScroll: true,
|
|
1237
|
-
focusVisible: false
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
1235
|
/**
|
|
1241
1236
|
* Registers this default feature on the map class, called by `MaplairMap` itself.
|
|
1242
1237
|
* @internal
|
|
@@ -1369,6 +1364,7 @@ var AttributionControl = class AttributionControl extends Control {
|
|
|
1369
1364
|
this._attributions = {};
|
|
1370
1365
|
this._orders = {};
|
|
1371
1366
|
this._layerAttributions = /* @__PURE__ */ new Map();
|
|
1367
|
+
this._shownLayers = /* @__PURE__ */ new Set();
|
|
1372
1368
|
this.callInitHooks(AttributionControl);
|
|
1373
1369
|
}
|
|
1374
1370
|
/**
|
|
@@ -1382,33 +1378,50 @@ var AttributionControl = class AttributionControl extends Control {
|
|
|
1382
1378
|
disableClickPropagation(this._container);
|
|
1383
1379
|
if (map._loaded) map.eachLayer((layer) => this._addLayer({ layer }));
|
|
1384
1380
|
this._update();
|
|
1385
|
-
map.on({
|
|
1386
|
-
layeradd: this._addLayer,
|
|
1387
|
-
layerremove: this._removeLayer
|
|
1388
|
-
}, this);
|
|
1389
1381
|
return this._container;
|
|
1390
1382
|
}
|
|
1391
1383
|
/**
|
|
1392
1384
|
* @internal
|
|
1393
|
-
* @
|
|
1385
|
+
* @returns {Record<string, Function>}
|
|
1394
1386
|
*/
|
|
1395
|
-
|
|
1396
|
-
|
|
1387
|
+
getEvents() {
|
|
1388
|
+
return {
|
|
1397
1389
|
layeradd: this._addLayer,
|
|
1398
|
-
layerremove: this._removeLayer
|
|
1399
|
-
|
|
1390
|
+
layerremove: this._removeLayer,
|
|
1391
|
+
zoomend: this._onZoomEnd
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* @internal
|
|
1396
|
+
*/
|
|
1397
|
+
onRemove() {
|
|
1400
1398
|
for (const layer of this._layerAttributions.keys()) this._removeLayer({ layer });
|
|
1401
1399
|
}
|
|
1402
1400
|
_addLayer({ layer }) {
|
|
1403
1401
|
const text = layer.getAttribution?.();
|
|
1404
1402
|
if (!text || this._layerAttributions.has(layer)) return;
|
|
1405
1403
|
this._layerAttributions.set(layer, text);
|
|
1406
|
-
this.
|
|
1404
|
+
this._updateLayer(layer);
|
|
1407
1405
|
}
|
|
1408
1406
|
_removeLayer({ layer }) {
|
|
1409
|
-
this.removeAttribution(this._layerAttributions.get(layer));
|
|
1407
|
+
if (this._shownLayers.delete(layer)) this.removeAttribution(this._layerAttributions.get(layer));
|
|
1410
1408
|
this._layerAttributions.delete(layer);
|
|
1411
1409
|
}
|
|
1410
|
+
_onZoomEnd() {
|
|
1411
|
+
for (const layer of this._layerAttributions.keys()) this._updateLayer(layer);
|
|
1412
|
+
}
|
|
1413
|
+
_updateLayer(layer) {
|
|
1414
|
+
const { minZoom = -Infinity, maxZoom = Infinity } = layer.options ?? {}, zoom = this._map.getZoom(), show = zoom >= minZoom && zoom <= maxZoom;
|
|
1415
|
+
if (show === this._shownLayers.has(layer)) return;
|
|
1416
|
+
const text = this._layerAttributions.get(layer);
|
|
1417
|
+
if (show) {
|
|
1418
|
+
this._shownLayers.add(layer);
|
|
1419
|
+
this.addAttribution(text, layer.options?.attributionOrder);
|
|
1420
|
+
} else {
|
|
1421
|
+
this._shownLayers.delete(layer);
|
|
1422
|
+
this.removeAttribution(text);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1412
1425
|
/**
|
|
1413
1426
|
* The HTML text shown before the attributions. Pass `false` to disable.
|
|
1414
1427
|
* @param {string|false} prefix
|
|
@@ -1430,8 +1443,7 @@ var AttributionControl = class AttributionControl extends Control {
|
|
|
1430
1443
|
addAttribution(text, order = 0) {
|
|
1431
1444
|
if (!text) return this;
|
|
1432
1445
|
this._orders[text] = order;
|
|
1433
|
-
|
|
1434
|
-
this._attributions[text]++;
|
|
1446
|
+
this._attributions[text] = (this._attributions[text] || 0) + 1;
|
|
1435
1447
|
this._update();
|
|
1436
1448
|
return this;
|
|
1437
1449
|
}
|
|
@@ -1566,7 +1578,6 @@ var ButtonControl = class ButtonControl extends Control {
|
|
|
1566
1578
|
disableClickPropagation(button);
|
|
1567
1579
|
on(button, "click", stop);
|
|
1568
1580
|
on(button, "click", this._onClick, this);
|
|
1569
|
-
on(button, "click", this._refocusOnMap, this);
|
|
1570
1581
|
this._update();
|
|
1571
1582
|
return button;
|
|
1572
1583
|
}
|
|
@@ -1928,8 +1939,9 @@ var Evented = class Evented extends Class {
|
|
|
1928
1939
|
};
|
|
1929
1940
|
if (_once) newListener.once = true;
|
|
1930
1941
|
this._events ??= {};
|
|
1931
|
-
this._events[type] ??= /* @__PURE__ */ new Set();
|
|
1932
|
-
this._events[type]
|
|
1942
|
+
let listeners = this._events[type] ??= /* @__PURE__ */ new Set();
|
|
1943
|
+
if (this._firingCount) this._events[type] = listeners = new Set(listeners);
|
|
1944
|
+
listeners.add(newListener);
|
|
1933
1945
|
if (contexts) contexts.set(context, newListener);
|
|
1934
1946
|
else this._listenerIndex[type].set(fn, /* @__PURE__ */ new Map([[context, newListener]]));
|
|
1935
1947
|
}
|
|
@@ -2204,13 +2216,13 @@ const mapLayerMethods = {
|
|
|
2204
2216
|
const oldZoomSpan = this._getZoomSpan();
|
|
2205
2217
|
for (const l of Object.values(this._zoomBoundLayers)) {
|
|
2206
2218
|
const options = l.options;
|
|
2207
|
-
minZoom = Math.min(minZoom, options.minZoom
|
|
2208
|
-
maxZoom = Math.max(maxZoom, options.maxZoom
|
|
2219
|
+
if (options.minZoom != null && !Number.isNaN(options.minZoom)) minZoom = Math.min(minZoom, options.minZoom);
|
|
2220
|
+
if (options.maxZoom != null && !Number.isNaN(options.maxZoom)) maxZoom = Math.max(maxZoom, options.maxZoom);
|
|
2209
2221
|
}
|
|
2210
2222
|
this._layersMaxZoom = maxZoom === -Infinity ? void 0 : maxZoom;
|
|
2211
2223
|
this._layersMinZoom = minZoom === Infinity ? void 0 : minZoom;
|
|
2212
2224
|
if (oldZoomSpan !== this._getZoomSpan()) this.fire("zoomlevelschange");
|
|
2213
|
-
if (this.options.maxZoom === void 0 && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) this.setZoom(this._layersMaxZoom);
|
|
2225
|
+
if (this.options.maxZoom === void 0 && this._layersMaxZoom !== void 0 && this.getZoom() > this._layersMaxZoom) this.setZoom(this._layersMaxZoom);
|
|
2214
2226
|
if (this.options.minZoom === void 0 && this._layersMinZoom && this.getZoom() < this._layersMinZoom) this.setZoom(this._layersMinZoom);
|
|
2215
2227
|
}
|
|
2216
2228
|
};
|
|
@@ -2327,8 +2339,10 @@ var Layer = class extends Evented {
|
|
|
2327
2339
|
}
|
|
2328
2340
|
_updateInteractive() {}
|
|
2329
2341
|
/**
|
|
2330
|
-
*
|
|
2331
|
-
*
|
|
2342
|
+
* Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and
|
|
2343
|
+
* keyboard events on it (or its descendants) fire on the layer and bubble through its
|
|
2344
|
+
* parent groups to the map, the way they do for markers and paths. Custom layers call
|
|
2345
|
+
* it in [`onAdd`](#layer-onadd), once the layer is on a map.
|
|
2332
2346
|
* @param {HTMLElement} targetEl
|
|
2333
2347
|
* @returns {this}
|
|
2334
2348
|
*/
|
|
@@ -2337,8 +2351,8 @@ var Layer = class extends Evented {
|
|
|
2337
2351
|
return this;
|
|
2338
2352
|
}
|
|
2339
2353
|
/**
|
|
2340
|
-
*
|
|
2341
|
-
*
|
|
2354
|
+
* Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in
|
|
2355
|
+
* [`onRemove`](#layer-onremove).
|
|
2342
2356
|
* @param {HTMLElement} targetEl
|
|
2343
2357
|
* @returns {this}
|
|
2344
2358
|
*/
|
|
@@ -2346,6 +2360,9 @@ var Layer = class extends Evented {
|
|
|
2346
2360
|
delete this._map._targets[stamp(targetEl)];
|
|
2347
2361
|
return this;
|
|
2348
2362
|
}
|
|
2363
|
+
_togglesPopupOnClick() {
|
|
2364
|
+
return true;
|
|
2365
|
+
}
|
|
2349
2366
|
/**
|
|
2350
2367
|
* Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).
|
|
2351
2368
|
* @returns {string|null}
|
|
@@ -2513,7 +2530,7 @@ var ContextMenu = class ContextMenu extends Class {
|
|
|
2513
2530
|
}
|
|
2514
2531
|
_createMenu(parent) {
|
|
2515
2532
|
const container = this._container ??= create("div", `maplair-contextmenu ${this.options.className}`);
|
|
2516
|
-
if (container.parentNode !== parent) parent.
|
|
2533
|
+
if (container.parentNode !== parent) parent.append(container);
|
|
2517
2534
|
container.popover = "auto";
|
|
2518
2535
|
container.setAttribute("role", "menu");
|
|
2519
2536
|
container.replaceChildren();
|
|
@@ -2680,7 +2697,6 @@ var FullscreenControl = class FullscreenControl extends Control {
|
|
|
2680
2697
|
disableClickPropagation(button);
|
|
2681
2698
|
on(button, "click", stop);
|
|
2682
2699
|
on(button, "click", this._toggleFullscreen, this);
|
|
2683
|
-
on(button, "click", this._refocusOnMap, this);
|
|
2684
2700
|
this._update();
|
|
2685
2701
|
map.on("fullscreenchange", this._update, this);
|
|
2686
2702
|
return container;
|
|
@@ -2764,6 +2780,8 @@ var FullscreenControl = class FullscreenControl extends Control {
|
|
|
2764
2780
|
* `maplair-control-layers-group-name` element, and each entry shows only its label.
|
|
2765
2781
|
* Events like `baselayerchange` still carry the full `name`. When combined with
|
|
2766
2782
|
* `sortLayers`, the entries are sorted first and grouped afterwards.
|
|
2783
|
+
* @property {string} [title] The title of the toggle button and the accessible label
|
|
2784
|
+
* of the layers list, the translation of `'Layers'` by default.
|
|
2767
2785
|
* @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
|
|
2768
2786
|
* collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
|
|
2769
2787
|
* element. String content is rendered as HTML; do not pass untrusted input.
|
|
@@ -2848,6 +2866,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
2848
2866
|
collapsed: true,
|
|
2849
2867
|
inline: false,
|
|
2850
2868
|
groupBy: void 0,
|
|
2869
|
+
title: void 0,
|
|
2851
2870
|
toggleContent: void 0,
|
|
2852
2871
|
collapseDelay: 0,
|
|
2853
2872
|
position: "topright",
|
|
@@ -2874,6 +2893,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
2874
2893
|
this._lastZIndex = 0;
|
|
2875
2894
|
this._handlingClick = false;
|
|
2876
2895
|
this._preventClick = false;
|
|
2896
|
+
this._needsUpdate = false;
|
|
2877
2897
|
for (const [name, layer] of Object.entries(baseLayers ?? {})) this._addLayer(layer, name);
|
|
2878
2898
|
for (const [name, layer] of Object.entries(overlays ?? {})) this._addLayer(layer, name, true);
|
|
2879
2899
|
this.callInitHooks(LayersControl);
|
|
@@ -2959,6 +2979,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
2959
2979
|
* @returns {this}
|
|
2960
2980
|
*/
|
|
2961
2981
|
selectLayer(layer) {
|
|
2982
|
+
if (this._needsUpdate) this._update(true);
|
|
2962
2983
|
const input = this._layerControlInputs.find((input) => input._layer === layer);
|
|
2963
2984
|
if (input && !input.checked) {
|
|
2964
2985
|
input.checked = true;
|
|
@@ -2973,6 +2994,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
2973
2994
|
expand() {
|
|
2974
2995
|
clearTimeout(this._collapseDelayTimeout);
|
|
2975
2996
|
this._container.classList.add("maplair-control-layers-expanded");
|
|
2997
|
+
if (this._needsUpdate) this._update();
|
|
2976
2998
|
this._section.style.height = "";
|
|
2977
2999
|
const acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
|
|
2978
3000
|
if (acceptableHeight < this._section.clientHeight) {
|
|
@@ -2988,19 +3010,40 @@ var LayersControl = class LayersControl extends Control {
|
|
|
2988
3010
|
*/
|
|
2989
3011
|
collapse() {
|
|
2990
3012
|
if (this.options.inline) return this;
|
|
3013
|
+
clearTimeout(this._collapseDelayTimeout);
|
|
2991
3014
|
if (this.options.collapseDelay > 0) this._collapseDelayTimeout = setTimeout(() => {
|
|
2992
3015
|
this._container.classList.remove("maplair-control-layers-expanded");
|
|
2993
3016
|
}, this.options.collapseDelay);
|
|
2994
3017
|
else this._container.classList.remove("maplair-control-layers-expanded");
|
|
2995
3018
|
return this;
|
|
2996
3019
|
}
|
|
3020
|
+
_getTitle() {
|
|
3021
|
+
return this.options.title ?? I18n.translate("Layers");
|
|
3022
|
+
}
|
|
2997
3023
|
_initLayout() {
|
|
2998
3024
|
const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this._isCollapsible();
|
|
2999
3025
|
if (this.options.inline) container.classList.add(`${className}-inline`);
|
|
3000
3026
|
disableClickPropagation(container);
|
|
3001
3027
|
disableScrollPropagation(container);
|
|
3002
3028
|
const section = this._section = create("fieldset", `${className}-list`);
|
|
3003
|
-
section.setAttribute("aria-label",
|
|
3029
|
+
section.setAttribute("aria-label", this._getTitle());
|
|
3030
|
+
section.tabIndex = -1;
|
|
3031
|
+
let link;
|
|
3032
|
+
if (!this.options.inline) {
|
|
3033
|
+
link = this._layersLink = create("button", `${className}-toggle`, container);
|
|
3034
|
+
link.type = "button";
|
|
3035
|
+
link.title = this._getTitle();
|
|
3036
|
+
link.setAttribute("aria-label", link.title);
|
|
3037
|
+
const { toggleContent } = this.options;
|
|
3038
|
+
if (typeof toggleContent === "string") link.innerHTML = toggleContent;
|
|
3039
|
+
else if (toggleContent) link.replaceChildren(toggleContent);
|
|
3040
|
+
on(link, "click", (e) => {
|
|
3041
|
+
e.preventDefault();
|
|
3042
|
+
const focused = document.activeElement === link;
|
|
3043
|
+
this._expandSafely();
|
|
3044
|
+
if (focused) section.focus();
|
|
3045
|
+
});
|
|
3046
|
+
}
|
|
3004
3047
|
if (collapsed) {
|
|
3005
3048
|
this._map.on("click", this.collapse, this);
|
|
3006
3049
|
on(container, {
|
|
@@ -3009,30 +3052,19 @@ var LayersControl = class LayersControl extends Control {
|
|
|
3009
3052
|
if (e.pointerType !== "touch") this.collapse();
|
|
3010
3053
|
}
|
|
3011
3054
|
}, this);
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
link.setAttribute("aria-label", I18n.translate("Layers"));
|
|
3018
|
-
const { toggleContent } = this.options;
|
|
3019
|
-
if (typeof toggleContent === "string") link.innerHTML = toggleContent;
|
|
3020
|
-
else if (toggleContent) link.replaceChildren(toggleContent);
|
|
3021
|
-
on(link, {
|
|
3022
|
-
keydown(e) {
|
|
3023
|
-
if (e.code === "Enter") this._expandSafely();
|
|
3024
|
-
},
|
|
3025
|
-
click(e) {
|
|
3055
|
+
on(section, "keydown", (e) => {
|
|
3056
|
+
if (e.key === "Escape") {
|
|
3057
|
+
clearTimeout(this._collapseDelayTimeout);
|
|
3058
|
+
container.classList.remove(`${className}-expanded`);
|
|
3059
|
+
link.focus();
|
|
3026
3060
|
e.preventDefault();
|
|
3027
|
-
this._expandSafely();
|
|
3028
3061
|
}
|
|
3029
|
-
}
|
|
3030
|
-
}
|
|
3031
|
-
if (!collapsed) this.expand();
|
|
3062
|
+
});
|
|
3063
|
+
} else this.expand();
|
|
3032
3064
|
this._baseLayersList = create("div", `${className}-base`, section);
|
|
3033
3065
|
this._separator = create("div", `${className}-separator`, section);
|
|
3034
3066
|
this._overlaysList = create("div", `${className}-overlays`, section);
|
|
3035
|
-
container.
|
|
3067
|
+
container.append(section);
|
|
3036
3068
|
}
|
|
3037
3069
|
_addLayer(layer, name, overlay) {
|
|
3038
3070
|
if (this._map) layer.on("add remove", this._onLayerChange, this);
|
|
@@ -3048,8 +3080,13 @@ var LayersControl = class LayersControl extends Control {
|
|
|
3048
3080
|
}
|
|
3049
3081
|
this._expandIfNotCollapsed();
|
|
3050
3082
|
}
|
|
3051
|
-
_update() {
|
|
3083
|
+
_update(force) {
|
|
3052
3084
|
if (!this._container) return this;
|
|
3085
|
+
if (!force && !this._container.classList.contains("maplair-control-layers-expanded")) {
|
|
3086
|
+
this._needsUpdate = true;
|
|
3087
|
+
return this;
|
|
3088
|
+
}
|
|
3089
|
+
this._needsUpdate = false;
|
|
3053
3090
|
this._baseLayersList.replaceChildren();
|
|
3054
3091
|
this._overlaysList.replaceChildren();
|
|
3055
3092
|
this._layerControlInputs = [];
|
|
@@ -3066,6 +3103,7 @@ var LayersControl = class LayersControl extends Control {
|
|
|
3066
3103
|
this._baseLayersList.style.display = baseLayersPresent ? "" : "none";
|
|
3067
3104
|
}
|
|
3068
3105
|
this._separator.style.display = overlaysPresent && baseLayersPresent ? "" : "none";
|
|
3106
|
+
this._checkDisabledLayers();
|
|
3069
3107
|
return this;
|
|
3070
3108
|
}
|
|
3071
3109
|
_onLayerChange(e) {
|
|
@@ -3091,12 +3129,10 @@ var LayersControl = class LayersControl extends Control {
|
|
|
3091
3129
|
const name = document.createElement("span");
|
|
3092
3130
|
name.innerHTML = ` ${group ? group.label : obj.name}`;
|
|
3093
3131
|
const holder = document.createElement("span");
|
|
3094
|
-
label.
|
|
3095
|
-
holder.
|
|
3096
|
-
holder.appendChild(name);
|
|
3132
|
+
label.append(holder);
|
|
3133
|
+
holder.append(input, name);
|
|
3097
3134
|
const list = obj.overlay ? this._overlaysList : this._baseLayersList;
|
|
3098
|
-
(group ? this._getGroupContainer(list, group.group) : list).
|
|
3099
|
-
this._checkDisabledLayers();
|
|
3135
|
+
(group ? this._getGroupContainer(list, group.group) : list).append(label);
|
|
3100
3136
|
return label;
|
|
3101
3137
|
}
|
|
3102
3138
|
/**
|
|
@@ -3136,7 +3172,6 @@ var LayersControl = class LayersControl extends Control {
|
|
|
3136
3172
|
this._update();
|
|
3137
3173
|
break;
|
|
3138
3174
|
}
|
|
3139
|
-
this._refocusOnMap(e);
|
|
3140
3175
|
}
|
|
3141
3176
|
_checkDisabledLayers() {
|
|
3142
3177
|
const inputs = this._layerControlInputs, zoom = this._map.getZoom();
|
|
@@ -3329,7 +3364,7 @@ var Bounds = class Bounds {
|
|
|
3329
3364
|
*/
|
|
3330
3365
|
overlaps(bounds) {
|
|
3331
3366
|
bounds = Bounds.from(bounds);
|
|
3332
|
-
const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xOverlaps =
|
|
3367
|
+
const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xOverlaps = Math.max(min.x, min2.x) < Math.min(max.x, max2.x), yOverlaps = Math.max(min.y, min2.y) < Math.min(max.y, max2.y);
|
|
3333
3368
|
return xOverlaps && yOverlaps;
|
|
3334
3369
|
}
|
|
3335
3370
|
/**
|
|
@@ -3362,7 +3397,7 @@ var Bounds = class Bounds {
|
|
|
3362
3397
|
}
|
|
3363
3398
|
};
|
|
3364
3399
|
function isPointExpression(obj) {
|
|
3365
|
-
return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0]
|
|
3400
|
+
return obj instanceof Point || (Array.isArray(obj) ? obj.length > 0 && typeof obj[0] !== "object" : "x" in obj);
|
|
3366
3401
|
}
|
|
3367
3402
|
// src/layer/BlanketOverlay.js
|
|
3368
3403
|
/** @import {LayerOptions} from './Layer.js' */
|
|
@@ -3425,7 +3460,7 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
3425
3460
|
this._initContainer();
|
|
3426
3461
|
this._container.classList.add("maplair-zoom-animated");
|
|
3427
3462
|
}
|
|
3428
|
-
this.getPane().
|
|
3463
|
+
this.getPane().append(this._container);
|
|
3429
3464
|
this._resizeContainer();
|
|
3430
3465
|
this._onMoveEnd();
|
|
3431
3466
|
}
|
|
@@ -3459,7 +3494,8 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
3459
3494
|
this._updateTransform(this._map.getCenter(), this._map.getZoom());
|
|
3460
3495
|
}
|
|
3461
3496
|
_updateTransform(center, zoom) {
|
|
3462
|
-
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))
|
|
3497
|
+
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));
|
|
3498
|
+
if (scale === 1) this._map._snapLayerPoint(topLeftOffset);
|
|
3463
3499
|
setTransform(this._container, topLeftOffset, scale);
|
|
3464
3500
|
}
|
|
3465
3501
|
_onMoveEnd(ev) {
|
|
@@ -3497,6 +3533,8 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
3497
3533
|
/** @import {BlanketOverlayOptions} from '../BlanketOverlay.js' */
|
|
3498
3534
|
/** @import {MaplairEvent} from '../../core/Events.js' */
|
|
3499
3535
|
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
3536
|
+
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
3537
|
+
/** @import {Point} from '../../geometry/Point.js' */
|
|
3500
3538
|
/**
|
|
3501
3539
|
* Options of `Renderer`, `SVG` and `Canvas`. The `continuous` option inherited from
|
|
3502
3540
|
* `BlanketOverlay` cannot be set to `true`.
|
|
@@ -3538,6 +3576,7 @@ var Renderer = class Renderer extends BlanketOverlay {
|
|
|
3538
3576
|
* @param {MaplairMap} map
|
|
3539
3577
|
*/
|
|
3540
3578
|
onAdd(map) {
|
|
3579
|
+
this._setPathView();
|
|
3541
3580
|
super.onAdd(map);
|
|
3542
3581
|
this.on("update", this._updatePaths, this);
|
|
3543
3582
|
}
|
|
@@ -3549,12 +3588,25 @@ var Renderer = class Renderer extends BlanketOverlay {
|
|
|
3549
3588
|
this.off("update", this._updatePaths, this);
|
|
3550
3589
|
}
|
|
3551
3590
|
_onZoomEnd() {
|
|
3591
|
+
this._setPathView();
|
|
3552
3592
|
for (const layer of Object.values(this._layers)) layer._project();
|
|
3553
3593
|
}
|
|
3594
|
+
_setPathView() {
|
|
3595
|
+
this._pathZoom = this._map.getZoom();
|
|
3596
|
+
this._pathOrigin = this._map.getPixelOrigin();
|
|
3597
|
+
}
|
|
3598
|
+
/**
|
|
3599
|
+
* @param {LatLngExpression} latlng
|
|
3600
|
+
* @returns {Point}
|
|
3601
|
+
*/
|
|
3602
|
+
_latLngToLayerPoint(latlng) {
|
|
3603
|
+
return this._map.project(latlng, this._pathZoom)._subtract(this._pathOrigin);
|
|
3604
|
+
}
|
|
3554
3605
|
_updatePaths() {
|
|
3555
3606
|
for (const layer of Object.values(this._layers)) layer._update();
|
|
3556
3607
|
}
|
|
3557
3608
|
_onViewReset() {
|
|
3609
|
+
this._setPathView();
|
|
3558
3610
|
for (const layer of Object.values(this._layers)) layer._reset();
|
|
3559
3611
|
}
|
|
3560
3612
|
_onSettled() {
|
|
@@ -3604,7 +3656,7 @@ var SVG = class SVG extends Renderer {
|
|
|
3604
3656
|
this._container = SVG.create("svg");
|
|
3605
3657
|
this._container.setAttribute("pointer-events", "none");
|
|
3606
3658
|
this._rootGroup = SVG.create("g");
|
|
3607
|
-
this._container.
|
|
3659
|
+
this._container.append(this._rootGroup);
|
|
3608
3660
|
}
|
|
3609
3661
|
_destroyContainer() {
|
|
3610
3662
|
super._destroyContainer();
|
|
@@ -3613,7 +3665,7 @@ var SVG = class SVG extends Renderer {
|
|
|
3613
3665
|
}
|
|
3614
3666
|
_resizeContainer() {
|
|
3615
3667
|
const size = super._resizeContainer();
|
|
3616
|
-
if (!this._svgSize
|
|
3668
|
+
if (!this._svgSize?.equals(size)) {
|
|
3617
3669
|
this._svgSize = size;
|
|
3618
3670
|
this._container.setAttribute("width", `${size.x}`);
|
|
3619
3671
|
this._container.setAttribute("height", `${size.y}`);
|
|
@@ -3649,7 +3701,7 @@ var SVG = class SVG extends Renderer {
|
|
|
3649
3701
|
}
|
|
3650
3702
|
_addPath(layer) {
|
|
3651
3703
|
if (!this._rootGroup) this._initContainer();
|
|
3652
|
-
this._rootGroup.
|
|
3704
|
+
this._rootGroup.append(layer._path);
|
|
3653
3705
|
layer.addInteractiveTarget(layer._path);
|
|
3654
3706
|
}
|
|
3655
3707
|
_removePath(layer) {
|
|
@@ -3758,13 +3810,15 @@ function num(v) {
|
|
|
3758
3810
|
* Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
|
|
3759
3811
|
* afterwards.
|
|
3760
3812
|
* @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
|
|
3761
|
-
* path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
|
|
3762
|
-
*
|
|
3813
|
+
* path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer)
|
|
3814
|
+
* (`SVG` by default), or in a custom pane, a renderer of the same kind created for
|
|
3815
|
+
* that pane. If set, it overrides the `pane` option.
|
|
3763
3816
|
* @extends InteractiveLayerOptions
|
|
3764
3817
|
*/
|
|
3765
3818
|
/**
|
|
3766
|
-
* An abstract class that contains options and
|
|
3767
|
-
*
|
|
3819
|
+
* An abstract class that contains options and methods shared between vector overlays
|
|
3820
|
+
* (`Polyline`, `Polygon`, `Rectangle`, `Circle`, `CircleMarker`). Do not use it
|
|
3821
|
+
* directly. Extends `Layer`.
|
|
3768
3822
|
*/
|
|
3769
3823
|
var Path = class extends Layer {
|
|
3770
3824
|
static defaultOptions = {
|
|
@@ -3861,8 +3915,11 @@ var Path = class extends Layer {
|
|
|
3861
3915
|
this._project();
|
|
3862
3916
|
this._update();
|
|
3863
3917
|
}
|
|
3918
|
+
_togglesPopupOnClick() {
|
|
3919
|
+
return false;
|
|
3920
|
+
}
|
|
3864
3921
|
_clickTolerance() {
|
|
3865
|
-
return (this.options.stroke ? this.options.weight / 2 : 0) + (this._renderer.options.tolerance || 0);
|
|
3922
|
+
return (this.options.stroke ? this.options.weight / 2 || 0 : 0) + (this._renderer.options.tolerance || 0);
|
|
3866
3923
|
}
|
|
3867
3924
|
};
|
|
3868
3925
|
// src/geo/LatLngBounds.js
|
|
@@ -3950,7 +4007,7 @@ var LatLngBounds = class LatLngBounds {
|
|
|
3950
4007
|
({_southWest: sw2, _northEast: ne2} = obj);
|
|
3951
4008
|
if (!sw2) return this;
|
|
3952
4009
|
} else if (!obj) return this;
|
|
3953
|
-
else if (
|
|
4010
|
+
else if (isLatLngExpression(obj)) sw2 = ne2 = LatLng.from(obj);
|
|
3954
4011
|
else return this.extend(LatLngBounds.from(obj));
|
|
3955
4012
|
if (!sw) {
|
|
3956
4013
|
this._southWest = new LatLng(sw2.lat, sw2.lng);
|
|
@@ -4043,7 +4100,7 @@ var LatLngBounds = class LatLngBounds {
|
|
|
4043
4100
|
* @returns {boolean}
|
|
4044
4101
|
*/
|
|
4045
4102
|
contains(obj) {
|
|
4046
|
-
if (
|
|
4103
|
+
if (isLatLngExpression(obj)) obj = LatLng.from(obj);
|
|
4047
4104
|
else obj = LatLngBounds.from(obj);
|
|
4048
4105
|
const sw = this._southWest, ne = this._northEast;
|
|
4049
4106
|
let sw2, ne2;
|
|
@@ -4072,7 +4129,7 @@ var LatLngBounds = class LatLngBounds {
|
|
|
4072
4129
|
*/
|
|
4073
4130
|
overlaps(bounds) {
|
|
4074
4131
|
bounds = LatLngBounds.from(bounds);
|
|
4075
|
-
const sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), ne2 = bounds.getNorthEast(), latOverlaps =
|
|
4132
|
+
const sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), ne2 = bounds.getNorthEast(), latOverlaps = Math.max(sw.lat, sw2.lat) < Math.min(ne.lat, ne2.lat), lngOverlaps = Math.max(sw.lng, sw2.lng) < Math.min(ne.lng, ne2.lng);
|
|
4076
4133
|
return latOverlaps && lngOverlaps;
|
|
4077
4134
|
}
|
|
4078
4135
|
/**
|
|
@@ -4110,6 +4167,9 @@ var LatLngBounds = class LatLngBounds {
|
|
|
4110
4167
|
return !!(this._southWest && this._northEast);
|
|
4111
4168
|
}
|
|
4112
4169
|
};
|
|
4170
|
+
function isLatLngExpression(obj) {
|
|
4171
|
+
return obj instanceof LatLng || (Array.isArray(obj) ? obj.length > 0 && typeof obj[0] !== "object" : typeof obj === "object" && obj !== null && "lat" in obj);
|
|
4172
|
+
}
|
|
4113
4173
|
// src/geo/LatLng.js
|
|
4114
4174
|
const coordinate = String.raw`([+-]?\d+(?:\.\d+)?)\s*°?`;
|
|
4115
4175
|
const separator = String.raw`(?:\s*[,;]\s*|\s+)`;
|
|
@@ -4159,46 +4219,36 @@ var LatLng = class LatLng {
|
|
|
4159
4219
|
* @param {number} [alt] Altitude in meters.
|
|
4160
4220
|
*/
|
|
4161
4221
|
constructor(lat, lng, alt) {
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
if (lat
|
|
4165
|
-
_lat = lat.lat;
|
|
4166
|
-
_lng = lat
|
|
4167
|
-
_alt = lat
|
|
4168
|
-
} else if (
|
|
4169
|
-
if (lat.length === 3) {
|
|
4170
|
-
_lat = lat[0];
|
|
4171
|
-
_lng = lat[1];
|
|
4172
|
-
_alt = lat[2];
|
|
4173
|
-
} else if (lat.length === 2) {
|
|
4174
|
-
_lat = lat[0];
|
|
4175
|
-
_lng = lat[1];
|
|
4176
|
-
}
|
|
4177
|
-
} else if (typeof lat === "object" && "lat" in lat) {
|
|
4222
|
+
let _lat = lat, _lng = lng, _alt = alt;
|
|
4223
|
+
if (lat instanceof LatLng) ({lat: _lat, lng: _lng, alt: _alt} = lat);
|
|
4224
|
+
else if (Array.isArray(lat)) {
|
|
4225
|
+
_lat = lat.length <= 3 ? lat[0] : NaN;
|
|
4226
|
+
_lng = lat[1];
|
|
4227
|
+
_alt = lat[2];
|
|
4228
|
+
} else if (typeof lat === "object" && lat !== null) {
|
|
4178
4229
|
_lat = lat.lat;
|
|
4179
4230
|
_lng = "lng" in lat ? lat.lng : lat.lon;
|
|
4180
4231
|
_alt = lat.alt;
|
|
4181
|
-
} else {
|
|
4182
|
-
_lat = lat;
|
|
4183
|
-
_lng = lng;
|
|
4184
|
-
_alt = alt;
|
|
4185
4232
|
}
|
|
4186
4233
|
/**
|
|
4187
4234
|
* Latitude in degrees.
|
|
4188
4235
|
* @type {number}
|
|
4189
4236
|
*/
|
|
4190
|
-
this.lat =
|
|
4237
|
+
this.lat = toNumber(_lat);
|
|
4191
4238
|
/**
|
|
4192
4239
|
* Longitude in degrees.
|
|
4193
4240
|
* @type {number}
|
|
4194
4241
|
*/
|
|
4195
|
-
this.lng =
|
|
4196
|
-
if (
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4242
|
+
this.lng = toNumber(_lng);
|
|
4243
|
+
if (isNaN(this.lat) || isNaN(this.lng)) throw new Error(`Invalid LatLng object: (${_lat}, ${_lng})`);
|
|
4244
|
+
if (_alt != null) {
|
|
4245
|
+
/**
|
|
4246
|
+
* Altitude in meters (optional).
|
|
4247
|
+
* @type {number|undefined}
|
|
4248
|
+
*/
|
|
4249
|
+
this.alt = toNumber(_alt);
|
|
4250
|
+
if (isNaN(this.alt)) throw new Error(`Invalid LatLng altitude: ${_alt}`);
|
|
4251
|
+
}
|
|
4202
4252
|
}
|
|
4203
4253
|
/**
|
|
4204
4254
|
* Returns the given `LatLng` object as it is, or else a new `LatLng` object created
|
|
@@ -4227,12 +4277,11 @@ var LatLng = class LatLng {
|
|
|
4227
4277
|
* @returns {boolean}
|
|
4228
4278
|
*/
|
|
4229
4279
|
static validate(lat, lng, alt) {
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4280
|
+
try {
|
|
4281
|
+
return !!new LatLng(lat, lng, alt);
|
|
4282
|
+
} catch {
|
|
4233
4283
|
return false;
|
|
4234
|
-
}
|
|
4235
|
-
return false;
|
|
4284
|
+
}
|
|
4236
4285
|
}
|
|
4237
4286
|
/**
|
|
4238
4287
|
* Parses coordinates in decimal degrees: a pair of numbers (latitude first), e.g.
|
|
@@ -4327,7 +4376,7 @@ var LatLng = class LatLng {
|
|
|
4327
4376
|
* @returns {number}
|
|
4328
4377
|
*/
|
|
4329
4378
|
function haversineDistance(latlng1, latlng2, R) {
|
|
4330
|
-
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;
|
|
4379
|
+
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);
|
|
4331
4380
|
return R * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)));
|
|
4332
4381
|
}
|
|
4333
4382
|
// src/geometry/LineUtil.js
|
|
@@ -4622,6 +4671,7 @@ function pointToGeoJSON(layer, precision) {
|
|
|
4622
4671
|
});
|
|
4623
4672
|
}
|
|
4624
4673
|
// src/layer/vector/CircleMarker.js
|
|
4674
|
+
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
4625
4675
|
/** @import {Feature} from 'geojson' */
|
|
4626
4676
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
4627
4677
|
/** @import {MaplairEvent} from '../../core/Events.js' */
|
|
@@ -4662,10 +4712,17 @@ var CircleMarker = class CircleMarker extends Path {
|
|
|
4662
4712
|
super();
|
|
4663
4713
|
setOptions(this, options);
|
|
4664
4714
|
this._latlng = new LatLng(latlng);
|
|
4665
|
-
this.
|
|
4715
|
+
this.setRadius(this.options.radius);
|
|
4666
4716
|
this.callInitHooks(CircleMarker);
|
|
4667
4717
|
}
|
|
4668
4718
|
/**
|
|
4719
|
+
* @param {MaplairMap} map
|
|
4720
|
+
*/
|
|
4721
|
+
beforeAdd(map) {
|
|
4722
|
+
super.beforeAdd(map);
|
|
4723
|
+
map._displaceHandler?._beforeMarkerAdd(this);
|
|
4724
|
+
}
|
|
4725
|
+
/**
|
|
4669
4726
|
* Sets the position of a circle marker to a new location.
|
|
4670
4727
|
* @param {LatLngExpression} latlng
|
|
4671
4728
|
* @returns {this}
|
|
@@ -4692,7 +4749,10 @@ var CircleMarker = class CircleMarker extends Path {
|
|
|
4692
4749
|
* @returns {this}
|
|
4693
4750
|
*/
|
|
4694
4751
|
setRadius(radius) {
|
|
4695
|
-
|
|
4752
|
+
const r = toNumber(radius);
|
|
4753
|
+
if (isNaN(r)) throw new Error(`Invalid radius: ${radius}`);
|
|
4754
|
+
/** @type {number} */
|
|
4755
|
+
this._radius = this.options.radius = r;
|
|
4696
4756
|
return this.redraw();
|
|
4697
4757
|
}
|
|
4698
4758
|
/**
|
|
@@ -4713,7 +4773,7 @@ var CircleMarker = class CircleMarker extends Path {
|
|
|
4713
4773
|
return this;
|
|
4714
4774
|
}
|
|
4715
4775
|
_project() {
|
|
4716
|
-
this._point = this.
|
|
4776
|
+
this._point = this._renderer._latLngToLayerPoint(this._latlng)._round();
|
|
4717
4777
|
this._pxRadius = this._radius;
|
|
4718
4778
|
this._updateBounds();
|
|
4719
4779
|
}
|
|
@@ -5190,13 +5250,7 @@ var Transformation = class {
|
|
|
5190
5250
|
* @param {number} [d]
|
|
5191
5251
|
*/
|
|
5192
5252
|
constructor(a, b, c, d) {
|
|
5193
|
-
if (Array.isArray(a))
|
|
5194
|
-
this._a = a[0];
|
|
5195
|
-
this._b = a[1];
|
|
5196
|
-
this._c = a[2];
|
|
5197
|
-
this._d = a[3];
|
|
5198
|
-
return;
|
|
5199
|
-
}
|
|
5253
|
+
if (Array.isArray(a)) [a, b, c, d] = a;
|
|
5200
5254
|
this._a = a;
|
|
5201
5255
|
this._b = b;
|
|
5202
5256
|
this._c = c;
|
|
@@ -5340,10 +5394,10 @@ var PosAnimation = class PosAnimation extends Evented {
|
|
|
5340
5394
|
* @property {string} [position='topleft'] The position of the control (one of the map
|
|
5341
5395
|
* corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
|
|
5342
5396
|
* `'bottomright'`.
|
|
5343
|
-
* @property {string} [zoomInText
|
|
5344
|
-
*
|
|
5345
|
-
* @property {string} [zoomOutText
|
|
5346
|
-
*
|
|
5397
|
+
* @property {string} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn
|
|
5398
|
+
* in SVG by default.
|
|
5399
|
+
* @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign
|
|
5400
|
+
* drawn in SVG by default.
|
|
5347
5401
|
* @extends ControlOptions
|
|
5348
5402
|
*/
|
|
5349
5403
|
/**
|
|
@@ -5367,8 +5421,8 @@ var PosAnimation = class PosAnimation extends Evented {
|
|
|
5367
5421
|
var ZoomControl = class ZoomControl extends Control {
|
|
5368
5422
|
static defaultOptions = {
|
|
5369
5423
|
position: "topleft",
|
|
5370
|
-
zoomInText: "<
|
|
5371
|
-
zoomOutText: "<
|
|
5424
|
+
zoomInText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12M6 0v12\"/></svg>",
|
|
5425
|
+
zoomOutText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12\"/></svg>"
|
|
5372
5426
|
};
|
|
5373
5427
|
/**
|
|
5374
5428
|
* Creates a zoom control.
|
|
@@ -5380,23 +5434,24 @@ var ZoomControl = class ZoomControl extends Control {
|
|
|
5380
5434
|
}
|
|
5381
5435
|
/**
|
|
5382
5436
|
* @internal
|
|
5383
|
-
* @param {MaplairMap} map
|
|
5384
5437
|
* @returns {HTMLElement}
|
|
5385
5438
|
*/
|
|
5386
|
-
onAdd(
|
|
5439
|
+
onAdd() {
|
|
5387
5440
|
const zoomName = "maplair-control-zoom", container = create("div", `${zoomName} maplair-bar`), options = this.options;
|
|
5388
5441
|
this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, (e) => this._zoom(e, 1));
|
|
5389
5442
|
this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, (e) => this._zoom(e, -1));
|
|
5390
5443
|
this._updateDisabled();
|
|
5391
|
-
map.on("zoomend zoomlevelschange", this._updateDisabled, this);
|
|
5392
5444
|
return container;
|
|
5393
5445
|
}
|
|
5394
5446
|
/**
|
|
5395
5447
|
* @internal
|
|
5396
|
-
* @
|
|
5448
|
+
* @returns {Record<string, Function>}
|
|
5397
5449
|
*/
|
|
5398
|
-
|
|
5399
|
-
|
|
5450
|
+
getEvents() {
|
|
5451
|
+
return {
|
|
5452
|
+
zoomend: this._updateDisabled,
|
|
5453
|
+
zoomlevelschange: this._updateDisabled
|
|
5454
|
+
};
|
|
5400
5455
|
}
|
|
5401
5456
|
/**
|
|
5402
5457
|
* Disables the zoom buttons.
|
|
@@ -5433,12 +5488,12 @@ var ZoomControl = class ZoomControl extends Control {
|
|
|
5433
5488
|
on(link, "click", (e) => {
|
|
5434
5489
|
stop(e);
|
|
5435
5490
|
fn.call(this, e);
|
|
5436
|
-
this._refocusOnMap(e);
|
|
5437
5491
|
});
|
|
5438
5492
|
return link;
|
|
5439
5493
|
}
|
|
5440
5494
|
_updateDisabled() {
|
|
5441
5495
|
const map = this._map;
|
|
5496
|
+
if (!map) return;
|
|
5442
5497
|
for (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {
|
|
5443
5498
|
const disabled = this._disabled || map._zoom === limit;
|
|
5444
5499
|
button.classList.toggle("maplair-disabled", disabled);
|
|
@@ -5753,9 +5808,12 @@ var FeatureGroup = class FeatureGroup extends LayerGroup {
|
|
|
5753
5808
|
/** @import {EventListener, MaplairEvent} from '../core/Events.js' */
|
|
5754
5809
|
/**
|
|
5755
5810
|
* The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an
|
|
5756
|
-
* `HTMLElement`, or a function receiving the source layer and
|
|
5757
|
-
*
|
|
5811
|
+
* `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and
|
|
5812
|
+
* returning one of them.
|
|
5813
|
+
* @typedef {string|HTMLElement|DocumentFragment|
|
|
5814
|
+
* ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent
|
|
5758
5815
|
*/
|
|
5816
|
+
const fragmentNodes = /* @__PURE__ */ new WeakMap();
|
|
5759
5817
|
/**
|
|
5760
5818
|
* Options of `DivOverlay`.
|
|
5761
5819
|
* @typedef {object} DivOverlayOptions
|
|
@@ -5771,8 +5829,8 @@ var FeatureGroup = class FeatureGroup extends LayerGroup {
|
|
|
5771
5829
|
* in the DOM (for styling and events).
|
|
5772
5830
|
* @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while
|
|
5773
5831
|
* initializing. If a function is passed the source layer will be passed to the
|
|
5774
|
-
* function. The function should return a `String` or `
|
|
5775
|
-
* overlay. String content is rendered as HTML; sanitize untrusted input or pass an
|
|
5832
|
+
* function. The function should return a `String`, `HTMLElement` or `DocumentFragment`
|
|
5833
|
+
* to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an
|
|
5776
5834
|
* `HTMLElement` with safe `textContent` instead.
|
|
5777
5835
|
* @extends InteractiveLayerOptions
|
|
5778
5836
|
*/
|
|
@@ -5804,7 +5862,8 @@ const layerDivOverlayMethods = { _initOverlay(OverlayClass, old, content, option
|
|
|
5804
5862
|
} };
|
|
5805
5863
|
/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */
|
|
5806
5864
|
/**
|
|
5807
|
-
* Base model for Popup and Tooltip
|
|
5865
|
+
* Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit
|
|
5866
|
+
* from it for custom overlays like plugins.
|
|
5808
5867
|
*
|
|
5809
5868
|
* @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
|
|
5810
5869
|
*/
|
|
@@ -5881,8 +5940,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
5881
5940
|
else {
|
|
5882
5941
|
if (arguments.length) this._source = layer;
|
|
5883
5942
|
else layer = this._source;
|
|
5884
|
-
this._prepareOpen();
|
|
5885
|
-
this.openOn(layer._map);
|
|
5943
|
+
if (this._prepareOpen()) this.openOn(layer._map);
|
|
5886
5944
|
}
|
|
5887
5945
|
return this;
|
|
5888
5946
|
}
|
|
@@ -5894,7 +5952,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
5894
5952
|
if (!this._container) this._initLayout();
|
|
5895
5953
|
if (map._fadeAnimated) this._container.style.opacity = "0";
|
|
5896
5954
|
clearTimeout(this._removeTimeout);
|
|
5897
|
-
this.getPane().
|
|
5955
|
+
this.getPane().append(this._container);
|
|
5898
5956
|
if (this.options.overflow) {
|
|
5899
5957
|
this._container.classList.add("maplair-overflow");
|
|
5900
5958
|
this._container.popover = "manual";
|
|
@@ -5966,10 +6024,11 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
5966
6024
|
}
|
|
5967
6025
|
/**
|
|
5968
6026
|
* Sets the HTML content of the overlay. A `String` argument is rendered as
|
|
5969
|
-
* HTML; if it may contain untrusted input, sanitize it
|
|
5970
|
-
*
|
|
5971
|
-
* passed
|
|
5972
|
-
* return a `String
|
|
6027
|
+
* HTML; if it may contain untrusted input, sanitize it or pass an `HTMLElement`
|
|
6028
|
+
* with safe `textContent` instead. A `DocumentFragment`
|
|
6029
|
+
* can be passed as well. If a function is passed the source layer will be passed
|
|
6030
|
+
* to the function. The function should return a `String`, `HTMLElement` or
|
|
6031
|
+
* `DocumentFragment` to be used in the overlay.
|
|
5973
6032
|
* @param {DivOverlayContent} content
|
|
5974
6033
|
* @returns {this}
|
|
5975
6034
|
*/
|
|
@@ -6017,7 +6076,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
6017
6076
|
* @returns {boolean}
|
|
6018
6077
|
*/
|
|
6019
6078
|
isOpen() {
|
|
6020
|
-
return !!this._map
|
|
6079
|
+
return !!this._map?.hasLayer(this);
|
|
6021
6080
|
}
|
|
6022
6081
|
/**
|
|
6023
6082
|
* Brings this overlay in front of other overlays (in the same map pane).
|
|
@@ -6061,30 +6120,26 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
6061
6120
|
if (!source) return false;
|
|
6062
6121
|
this._source = source;
|
|
6063
6122
|
}
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
else if (source.getLatLng) latlng = source.getLatLng();
|
|
6067
|
-
else if (source.getBounds) latlng = source.getBounds().getCenter();
|
|
6068
|
-
else throw new Error("Unable to get source layer LatLng.");
|
|
6069
|
-
}
|
|
6123
|
+
latlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();
|
|
6124
|
+
if (!latlng) throw new Error("Unable to get source layer LatLng.");
|
|
6070
6125
|
this.setLatLng(latlng);
|
|
6071
6126
|
if (this._map) this.update();
|
|
6072
6127
|
return true;
|
|
6073
6128
|
}
|
|
6074
6129
|
_updateContent() {
|
|
6075
|
-
if (
|
|
6130
|
+
if (this._content == null) return;
|
|
6076
6131
|
const node = this._contentNode;
|
|
6077
6132
|
const content = typeof this._content === "function" ? this._content(this._source ?? this) : this._content;
|
|
6078
6133
|
if (typeof content === "string") node.innerHTML = content;
|
|
6079
|
-
else {
|
|
6080
|
-
|
|
6081
|
-
node.
|
|
6082
|
-
}
|
|
6134
|
+
else if (content instanceof DocumentFragment) {
|
|
6135
|
+
if (content.hasChildNodes()) fragmentNodes.set(content, [...content.childNodes]);
|
|
6136
|
+
node.replaceChildren(...fragmentNodes.get(content) ?? []);
|
|
6137
|
+
} else node.replaceChildren(content);
|
|
6083
6138
|
this.fire("contentupdate");
|
|
6084
6139
|
}
|
|
6085
6140
|
_updatePosition() {
|
|
6086
6141
|
if (!this._map) return;
|
|
6087
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
6142
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng)), offset = Point.from(this.options.offset);
|
|
6088
6143
|
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
6089
6144
|
const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
|
|
6090
6145
|
if (this.options.overflow) {
|
|
@@ -6227,10 +6282,10 @@ const layerPopupMethods = {
|
|
|
6227
6282
|
/**
|
|
6228
6283
|
* Binds a popup to the layer with the passed `content` and sets up the
|
|
6229
6284
|
* necessary event listeners. A `String` argument is rendered as HTML; if it
|
|
6230
|
-
* may contain untrusted input, sanitize it
|
|
6231
|
-
* `
|
|
6285
|
+
* may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
|
|
6286
|
+
* `textContent` instead. If a `Function` is passed
|
|
6232
6287
|
* it will receive the layer as the first argument and should return a
|
|
6233
|
-
* `String` or `
|
|
6288
|
+
* `String`, `HTMLElement` or `DocumentFragment`.
|
|
6234
6289
|
* @group Popup methods
|
|
6235
6290
|
* @param {DivOverlayContent|Popup} content
|
|
6236
6291
|
* @param {PopupOptions} [options]
|
|
@@ -6238,6 +6293,7 @@ const layerPopupMethods = {
|
|
|
6238
6293
|
*/
|
|
6239
6294
|
bindPopup(content, options) {
|
|
6240
6295
|
this._popup = this._initOverlay(Popup, this._popup, content, options);
|
|
6296
|
+
this._popup._updateSourceAria(this._popup.isOpen());
|
|
6241
6297
|
this.on({
|
|
6242
6298
|
click: this._openPopup,
|
|
6243
6299
|
remove: this.closePopup,
|
|
@@ -6257,6 +6313,9 @@ const layerPopupMethods = {
|
|
|
6257
6313
|
remove: this.closePopup,
|
|
6258
6314
|
move: this._movePopup
|
|
6259
6315
|
});
|
|
6316
|
+
const el = this.getElement?.();
|
|
6317
|
+
el?.removeAttribute("aria-expanded");
|
|
6318
|
+
el?.removeAttribute("aria-controls");
|
|
6260
6319
|
this._popup = null;
|
|
6261
6320
|
}
|
|
6262
6321
|
return this;
|
|
@@ -6325,9 +6384,8 @@ const layerPopupMethods = {
|
|
|
6325
6384
|
if (!this._popup || !this._map) return;
|
|
6326
6385
|
stopPropagation(e);
|
|
6327
6386
|
const target = e.propagatedFrom ?? e.target;
|
|
6328
|
-
if (this._popup._source === target &&
|
|
6329
|
-
|
|
6330
|
-
else this.openPopup(e.latlng);
|
|
6387
|
+
if (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {
|
|
6388
|
+
this.closePopup();
|
|
6331
6389
|
return;
|
|
6332
6390
|
}
|
|
6333
6391
|
this._popup._source = target;
|
|
@@ -6367,8 +6425,7 @@ const layerPopupMethods = {
|
|
|
6367
6425
|
*
|
|
6368
6426
|
* **Security note.** Popup string content is rendered as HTML. If your content
|
|
6369
6427
|
* may include untrusted input (e.g. data from users or external APIs), sanitize
|
|
6370
|
-
* it
|
|
6371
|
-
* build a DOM element using `textContent` to render it as plain text:
|
|
6428
|
+
* it first, or build a DOM element using `textContent` to render it as plain text:
|
|
6372
6429
|
*
|
|
6373
6430
|
* ```js
|
|
6374
6431
|
* const el = document.createElement('div');
|
|
@@ -6424,9 +6481,11 @@ var Popup = class Popup extends DivOverlay {
|
|
|
6424
6481
|
*/
|
|
6425
6482
|
openOn(map) {
|
|
6426
6483
|
map = arguments.length ? map : this._source._map;
|
|
6427
|
-
if (!map.hasLayer(this) && map._popup
|
|
6484
|
+
if (!map.hasLayer(this) && map._popup?.options.autoClose) map.removeLayer(map._popup);
|
|
6428
6485
|
map._popup = this;
|
|
6429
|
-
|
|
6486
|
+
super.openOn(map);
|
|
6487
|
+
this._updateSourceAria(true);
|
|
6488
|
+
return this;
|
|
6430
6489
|
}
|
|
6431
6490
|
/**
|
|
6432
6491
|
* Adds the popup to the map.
|
|
@@ -6441,9 +6500,10 @@ var Popup = class Popup extends DivOverlay {
|
|
|
6441
6500
|
(this._closeButton ?? this._container).focus({ preventScroll: true });
|
|
6442
6501
|
}
|
|
6443
6502
|
map.fire("popupopen", { popup: this });
|
|
6503
|
+
this._updateSourceAria(true);
|
|
6444
6504
|
if (this._source) {
|
|
6445
6505
|
this._source.fire("popupopen", { popup: this }, true);
|
|
6446
|
-
if (
|
|
6506
|
+
if (this._source._togglesPopupOnClick()) this._source.on("preclick", stopPropagation);
|
|
6447
6507
|
}
|
|
6448
6508
|
}
|
|
6449
6509
|
/**
|
|
@@ -6451,13 +6511,17 @@ var Popup = class Popup extends DivOverlay {
|
|
|
6451
6511
|
* @param {MaplairMap} map
|
|
6452
6512
|
*/
|
|
6453
6513
|
onRemove(map) {
|
|
6454
|
-
if (this._container.contains(document.activeElement)
|
|
6514
|
+
if (this._container.contains(document.activeElement)) {
|
|
6515
|
+
const el = this._source?.getElement?.();
|
|
6516
|
+
(this._returnFocus?.isConnected ? this._returnFocus : el?.tabIndex >= 0 ? el : map._container).focus({ preventScroll: true });
|
|
6517
|
+
}
|
|
6455
6518
|
this._returnFocus = null;
|
|
6456
6519
|
super.onRemove(map);
|
|
6457
6520
|
map.fire("popupclose", { popup: this });
|
|
6521
|
+
this._updateSourceAria(false);
|
|
6458
6522
|
if (this._source) {
|
|
6459
6523
|
this._source.fire("popupclose", { popup: this }, true);
|
|
6460
|
-
if (
|
|
6524
|
+
if (this._source._togglesPopupOnClick()) this._source.off("preclick", stopPropagation);
|
|
6461
6525
|
}
|
|
6462
6526
|
}
|
|
6463
6527
|
/**
|
|
@@ -6470,8 +6534,17 @@ var Popup = class Popup extends DivOverlay {
|
|
|
6470
6534
|
if (this.options.keepInView) events.moveend = this._adjustPan;
|
|
6471
6535
|
return events;
|
|
6472
6536
|
}
|
|
6537
|
+
_updateSourceAria(open) {
|
|
6538
|
+
this._ariaSource?.setAttribute("aria-expanded", "false");
|
|
6539
|
+
this._ariaSource?.removeAttribute("aria-controls");
|
|
6540
|
+
const el = this._source?.getElement?.();
|
|
6541
|
+
this._ariaSource = el?.getAttribute("role") === "button" ? el : null;
|
|
6542
|
+
this._ariaSource?.setAttribute("aria-expanded", String(open));
|
|
6543
|
+
if (open) this._ariaSource?.setAttribute("aria-controls", this._container.id);
|
|
6544
|
+
}
|
|
6473
6545
|
_initLayout() {
|
|
6474
6546
|
const prefix = "maplair-popup", container = this._container = create("div", `${prefix} ${this.options.className || ""} maplair-zoom-animated`);
|
|
6547
|
+
container.id = `maplair-popup-${stamp(this)}`;
|
|
6475
6548
|
const wrapper = this._wrapper = create("div", `${prefix}-content-wrapper`, container);
|
|
6476
6549
|
this._contentNode = create("div", `${prefix}-content`, wrapper);
|
|
6477
6550
|
disableClickPropagation(container);
|
|
@@ -6483,7 +6556,7 @@ var Popup = class Popup extends DivOverlay {
|
|
|
6483
6556
|
const closeButton = this._closeButton = create("button", `${prefix}-close-button`, container);
|
|
6484
6557
|
closeButton.type = "button";
|
|
6485
6558
|
closeButton.setAttribute("aria-label", I18n.translate("Close popup"));
|
|
6486
|
-
closeButton.
|
|
6559
|
+
closeButton.textContent = "×";
|
|
6487
6560
|
on(closeButton, "click", (ev) => {
|
|
6488
6561
|
ev.preventDefault();
|
|
6489
6562
|
this.close();
|
|
@@ -6551,13 +6624,13 @@ var Popup = class Popup extends DivOverlay {
|
|
|
6551
6624
|
}
|
|
6552
6625
|
};
|
|
6553
6626
|
// src/layer/Tooltip.js
|
|
6554
|
-
const directions =
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6627
|
+
const directions = {
|
|
6628
|
+
top: [.5, 1],
|
|
6629
|
+
bottom: [.5, 0],
|
|
6630
|
+
center: [.5, .5],
|
|
6631
|
+
right: [0, .5],
|
|
6632
|
+
left: [1, .5]
|
|
6633
|
+
};
|
|
6561
6634
|
const tipSize = 6;
|
|
6562
6635
|
const autoPadding = 4;
|
|
6563
6636
|
function shiftInto(start, size, min, max) {
|
|
@@ -6576,7 +6649,8 @@ function clampTip(tipShift, size) {
|
|
|
6576
6649
|
* Options of `Tooltip`.
|
|
6577
6650
|
* @typedef {object} TooltipOptions
|
|
6578
6651
|
* @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.
|
|
6579
|
-
* @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position
|
|
6652
|
+
* @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position, in
|
|
6653
|
+
* pixels. Mirrored horizontally when an `auto` tooltip opens to the left.
|
|
6580
6654
|
* @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']
|
|
6581
6655
|
* Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,
|
|
6582
6656
|
* `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when
|
|
@@ -6647,10 +6721,10 @@ const layerTooltipMethods = {
|
|
|
6647
6721
|
/**
|
|
6648
6722
|
* Binds a tooltip to the layer with the passed `content` and sets up the
|
|
6649
6723
|
* necessary event listeners. A `String` argument is rendered as HTML; if it
|
|
6650
|
-
* may contain untrusted input, sanitize it
|
|
6651
|
-
* `
|
|
6724
|
+
* may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
|
|
6725
|
+
* `textContent` instead. If a `Function` is passed
|
|
6652
6726
|
* it will receive the layer as the first argument and should return a
|
|
6653
|
-
* `String` or `
|
|
6727
|
+
* `String`, `HTMLElement` or `DocumentFragment`.
|
|
6654
6728
|
* @group Tooltip methods
|
|
6655
6729
|
* @param {DivOverlayContent|Tooltip} content
|
|
6656
6730
|
* @param {TooltipOptions} [options]
|
|
@@ -6661,7 +6735,7 @@ const layerTooltipMethods = {
|
|
|
6661
6735
|
if (this._tooltip) this.unbindTooltip();
|
|
6662
6736
|
this._tooltip = this._initOverlay(Tooltip, old, content, options);
|
|
6663
6737
|
this._initTooltipInteractions();
|
|
6664
|
-
if (this._tooltip.options.permanent && this._map
|
|
6738
|
+
if (this._tooltip.options.permanent && this._map?.hasLayer(this)) this.openTooltip();
|
|
6665
6739
|
return this;
|
|
6666
6740
|
},
|
|
6667
6741
|
/**
|
|
@@ -6703,11 +6777,7 @@ const layerTooltipMethods = {
|
|
|
6703
6777
|
openTooltip(latlng) {
|
|
6704
6778
|
if (this._tooltip) {
|
|
6705
6779
|
if (!(this instanceof FeatureGroup)) this._tooltip._source = this;
|
|
6706
|
-
if (this._tooltip._prepareOpen(latlng))
|
|
6707
|
-
this._tooltip.openOn(this._map);
|
|
6708
|
-
if (this.getElement) this._setAriaDescribedByOnLayer(this);
|
|
6709
|
-
else if (this.eachLayer) this.eachLayer(this._setAriaDescribedByOnLayer, this);
|
|
6710
|
-
}
|
|
6780
|
+
if (this._tooltip._prepareOpen(latlng)) this._tooltip.openOn(this._map);
|
|
6711
6781
|
}
|
|
6712
6782
|
return this;
|
|
6713
6783
|
},
|
|
@@ -6768,7 +6838,7 @@ const layerTooltipMethods = {
|
|
|
6768
6838
|
if (!remove) {
|
|
6769
6839
|
el._maplair_focus_handler && off(el, "focus", el._maplair_focus_handler, this);
|
|
6770
6840
|
el._maplair_focus_handler = () => {
|
|
6771
|
-
if (this._tooltip) {
|
|
6841
|
+
if (this._tooltip && el.matches(":focus-visible")) {
|
|
6772
6842
|
this._tooltip._source = layer;
|
|
6773
6843
|
this.openTooltip();
|
|
6774
6844
|
}
|
|
@@ -6779,9 +6849,6 @@ const layerTooltipMethods = {
|
|
|
6779
6849
|
if (remove) delete el._maplair_focus_handler;
|
|
6780
6850
|
}
|
|
6781
6851
|
},
|
|
6782
|
-
_setAriaDescribedByOnLayer(layer) {
|
|
6783
|
-
(typeof layer.getElement === "function" && layer.getElement())?.setAttribute?.("aria-describedby", this._tooltip._container.id);
|
|
6784
|
-
},
|
|
6785
6852
|
_openTooltip(e) {
|
|
6786
6853
|
if (!this._tooltip || !this._map) return;
|
|
6787
6854
|
if (this._map.dragging?.moving()) {
|
|
@@ -6798,13 +6865,7 @@ const layerTooltipMethods = {
|
|
|
6798
6865
|
this.openTooltip(this._tooltip.options.sticky ? e.latlng : void 0);
|
|
6799
6866
|
},
|
|
6800
6867
|
_moveTooltip(e) {
|
|
6801
|
-
|
|
6802
|
-
if (this._tooltip.options.sticky && e.originalEvent) {
|
|
6803
|
-
containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
|
|
6804
|
-
layerPoint = this._map.containerPointToLayerPoint(containerPoint);
|
|
6805
|
-
latlng = this._map.layerPointToLatLng(layerPoint);
|
|
6806
|
-
}
|
|
6807
|
-
this._tooltip.setLatLng(latlng);
|
|
6868
|
+
this._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ? this._map.pointerEventToLatLng(e.originalEvent) : e.latlng);
|
|
6808
6869
|
}
|
|
6809
6870
|
};
|
|
6810
6871
|
/** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */
|
|
@@ -6835,8 +6896,7 @@ const layerTooltipMethods = {
|
|
|
6835
6896
|
*
|
|
6836
6897
|
* **Security note.** Tooltip string content is rendered as HTML. If your content
|
|
6837
6898
|
* may include untrusted input (e.g. data from users or external APIs), sanitize
|
|
6838
|
-
* it
|
|
6839
|
-
* build a DOM element using `textContent` to render it as plain text:
|
|
6899
|
+
* it first, or build a DOM element using `textContent` to render it as plain text:
|
|
6840
6900
|
*
|
|
6841
6901
|
* ```js
|
|
6842
6902
|
* const el = document.createElement('div');
|
|
@@ -6893,6 +6953,8 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
6893
6953
|
map.fire("tooltipopen", { tooltip: this });
|
|
6894
6954
|
if (this._source) {
|
|
6895
6955
|
this.addEventParent(this._source);
|
|
6956
|
+
this._ariaSource = this._source.getElement?.();
|
|
6957
|
+
this._ariaSource?.setAttribute("aria-describedby", this._container.id);
|
|
6896
6958
|
this._source.fire("tooltipopen", { tooltip: this }, true);
|
|
6897
6959
|
}
|
|
6898
6960
|
}
|
|
@@ -6905,6 +6967,9 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
6905
6967
|
map.fire("tooltipclose", { tooltip: this });
|
|
6906
6968
|
if (this._source) {
|
|
6907
6969
|
this.removeEventParent(this._source);
|
|
6970
|
+
const el = this._ariaSource;
|
|
6971
|
+
if (el?.getAttribute("aria-describedby") === this._container.id) el.removeAttribute("aria-describedby");
|
|
6972
|
+
this._ariaSource = null;
|
|
6908
6973
|
this._source.fire("tooltipclose", { tooltip: this }, true);
|
|
6909
6974
|
}
|
|
6910
6975
|
}
|
|
@@ -6921,7 +6986,7 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
6921
6986
|
const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-animated`;
|
|
6922
6987
|
this._contentNode = this._container = create("div", className);
|
|
6923
6988
|
this._container.setAttribute("role", "tooltip");
|
|
6924
|
-
this._container.
|
|
6989
|
+
this._container.id = `maplair-tooltip-${stamp(this)}`;
|
|
6925
6990
|
}
|
|
6926
6991
|
_updateLayout() {}
|
|
6927
6992
|
_adjustPan() {}
|
|
@@ -6935,33 +7000,33 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
6935
7000
|
}
|
|
6936
7001
|
_setPosition(pos) {
|
|
6937
7002
|
let direction = this.options.direction, shift = new Point(0, 0);
|
|
6938
|
-
const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset)
|
|
6939
|
-
if (!
|
|
6940
|
-
({direction, shift} = this._getAutoPlacement(pos, offset,
|
|
6941
|
-
if (direction === "left")
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
if (direction === "top") subY = tooltipHeight;
|
|
6948
|
-
else if (direction === "bottom") subY = 0;
|
|
6949
|
-
else if (direction === "right") subX = 0;
|
|
6950
|
-
else if (direction === "left") subX = tooltipWidth;
|
|
6951
|
-
pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor).add(shift);
|
|
6952
|
-
container.classList.remove("maplair-tooltip-right", "maplair-tooltip-left", "maplair-tooltip-top", "maplair-tooltip-bottom");
|
|
6953
|
-
container.classList.add(`maplair-tooltip-${direction}`);
|
|
7003
|
+
const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset);
|
|
7004
|
+
if (!(direction in directions)) {
|
|
7005
|
+
({direction, shift} = this._getAutoPlacement(pos, offset, tooltipWidth, tooltipHeight));
|
|
7006
|
+
if (direction === "left") offset.x = -offset.x;
|
|
7007
|
+
}
|
|
7008
|
+
const anchor = this._getAnchor(direction);
|
|
7009
|
+
const [fx, fy] = directions[direction];
|
|
7010
|
+
pos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);
|
|
7011
|
+
for (const d in directions) container.classList.toggle(`maplair-tooltip-${d}`, d === direction);
|
|
6954
7012
|
const tipShift = direction === "top" || direction === "bottom" ? clampTip(-shift.x, tooltipWidth) : clampTip(-shift.y, tooltipHeight);
|
|
6955
7013
|
if (tipShift) container.style.setProperty("--maplair-tooltip-tip-shift", `${tipShift}px`);
|
|
6956
7014
|
else container.style.removeProperty("--maplair-tooltip-tip-shift");
|
|
6957
7015
|
this._setContainerPosition(pos);
|
|
6958
7016
|
}
|
|
6959
|
-
_getAutoPlacement(pos, offset,
|
|
6960
|
-
const area = this._getAutoArea(), point = this._map.layerPointToContainerPoint(pos),
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
7017
|
+
_getAutoPlacement(pos, offset, width, height) {
|
|
7018
|
+
const area = this._getAutoArea(), point = this._map.layerPointToContainerPoint(pos), at = {};
|
|
7019
|
+
for (const d of [
|
|
7020
|
+
"right",
|
|
7021
|
+
"left",
|
|
7022
|
+
"top",
|
|
7023
|
+
"bottom"
|
|
7024
|
+
]) at[d] = point.add(this._getAnchor(d)).add(d === "left" ? [-offset.x, offset.y] : offset);
|
|
7025
|
+
const space = {
|
|
7026
|
+
right: area.max.x - at.right.x - width - tipSize,
|
|
7027
|
+
left: at.left.x - area.min.x - width - tipSize,
|
|
7028
|
+
top: at.top.y - area.min.y - height - tipSize,
|
|
7029
|
+
bottom: area.max.y - at.bottom.y - height - tipSize
|
|
6965
7030
|
};
|
|
6966
7031
|
if (!this._autoDirection) {
|
|
6967
7032
|
const sides = point.x < (area.min.x + area.max.x) / 2 ? ["right", "left"] : ["left", "right"], fallback = space.right >= space.left ? "right" : "left";
|
|
@@ -6971,7 +7036,7 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
6971
7036
|
"bottom"
|
|
6972
7037
|
].find((d) => space[d] >= 0 && (d === "right" || d === "left" || width <= area.max.x - area.min.x)) ?? fallback;
|
|
6973
7038
|
}
|
|
6974
|
-
const direction = this._autoDirection;
|
|
7039
|
+
const direction = this._autoDirection, { x, y } = at[direction];
|
|
6975
7040
|
return {
|
|
6976
7041
|
direction,
|
|
6977
7042
|
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))
|
|
@@ -6992,7 +7057,7 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
6992
7057
|
};
|
|
6993
7058
|
}
|
|
6994
7059
|
_updatePosition() {
|
|
6995
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
7060
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
|
|
6996
7061
|
this._setPosition(pos);
|
|
6997
7062
|
}
|
|
6998
7063
|
/**
|
|
@@ -7008,8 +7073,8 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
7008
7073
|
const pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
|
|
7009
7074
|
this._setPosition(pos);
|
|
7010
7075
|
}
|
|
7011
|
-
_getAnchor() {
|
|
7012
|
-
return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);
|
|
7076
|
+
_getAnchor(direction) {
|
|
7077
|
+
return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor(direction) : [0, 0]);
|
|
7013
7078
|
}
|
|
7014
7079
|
/**
|
|
7015
7080
|
* Registers this default feature on the map class, called by `MaplairMap` itself.
|
|
@@ -7066,7 +7131,8 @@ const mapRendererMethods = {
|
|
|
7066
7131
|
* @lends MaplairMapOptions
|
|
7067
7132
|
* @property {Renderer} [renderer] The default method for drawing vector layers on the
|
|
7068
7133
|
* map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
|
|
7069
|
-
* instead.
|
|
7134
|
+
* instead. Paths in custom panes get their own renderer for that pane, of the same
|
|
7135
|
+
* class and with the same options as this one.
|
|
7070
7136
|
*/
|
|
7071
7137
|
/**
|
|
7072
7138
|
* Registers `getRenderer()` and related methods on the given map class, called by
|
|
@@ -7195,12 +7261,16 @@ var BoxZoomHandler = class BoxZoomHandler extends Handler {
|
|
|
7195
7261
|
*/
|
|
7196
7262
|
addHooks() {
|
|
7197
7263
|
on(this._map._container, "pointerdown", this._onPointerDown, this);
|
|
7264
|
+
this._map._container.classList.add("maplair-box-zoom");
|
|
7198
7265
|
}
|
|
7199
7266
|
/**
|
|
7200
7267
|
* Called when the handler is disabled, removes the event hooks.
|
|
7201
7268
|
*/
|
|
7202
7269
|
removeHooks() {
|
|
7203
7270
|
off(this._map._container, "pointerdown", this._onPointerDown, this);
|
|
7271
|
+
this._map._container.classList.remove("maplair-box-zoom");
|
|
7272
|
+
this._finish();
|
|
7273
|
+
this._resetState();
|
|
7204
7274
|
}
|
|
7205
7275
|
/**
|
|
7206
7276
|
* Returns `true` if a box has been drawn by the current or last interaction.
|
|
@@ -7351,9 +7421,13 @@ var DoubleClickZoomHandler = class DoubleClickZoomHandler extends Handler {
|
|
|
7351
7421
|
* pointer drag).
|
|
7352
7422
|
*/
|
|
7353
7423
|
/**
|
|
7354
|
-
* The event object of `dragstart`, `predrag` and `drag` of `Draggable
|
|
7424
|
+
* The event object of `dragstart`, `predrag` and `drag` of `Draggable`, and of
|
|
7425
|
+
* `movestart` and `dragstart` of draggable markers.
|
|
7355
7426
|
* @typedef {object} DraggableEvent
|
|
7356
|
-
* @property {PointerEvent} originalEvent The DOM event of the pointer which
|
|
7427
|
+
* @property {PointerEvent|KeyboardEvent} originalEvent The DOM event of the pointer which
|
|
7428
|
+
* drags: for `dragstart`, the `pointermove` that moved the pointer past `clickTolerance`
|
|
7429
|
+
* (not the `pointerdown`), or the `keydown` of an arrow key that moves a focused
|
|
7430
|
+
* draggable marker.
|
|
7357
7431
|
* @extends MaplairEvent
|
|
7358
7432
|
*/
|
|
7359
7433
|
/**
|
|
@@ -7413,13 +7487,13 @@ var Draggable = class Draggable extends Evented {
|
|
|
7413
7487
|
}
|
|
7414
7488
|
_onDown(e) {
|
|
7415
7489
|
this._moved = false;
|
|
7416
|
-
if (this._element.classList.contains("maplair-zoom-anim")) return;
|
|
7417
7490
|
const pointers = getPointers().length;
|
|
7418
7491
|
if (pointers > 1) {
|
|
7419
7492
|
if (Draggable._dragging === this) this.finishDrag();
|
|
7420
7493
|
return;
|
|
7421
7494
|
}
|
|
7422
|
-
|
|
7495
|
+
const boxZoom = e.shiftKey && this._element.closest(".maplair-container")?.classList.contains("maplair-box-zoom");
|
|
7496
|
+
if (Draggable._dragging || boxZoom || e.button !== 0 && e.pointerType !== "touch") return;
|
|
7423
7497
|
Draggable._dragging = this;
|
|
7424
7498
|
disableImageDrag();
|
|
7425
7499
|
if (this._moving) return;
|
|
@@ -7477,10 +7551,8 @@ var Draggable = class Draggable extends Evented {
|
|
|
7477
7551
|
finishDrag(noInertia) {
|
|
7478
7552
|
this._draggingContainer?.classList.remove("maplair-dragging");
|
|
7479
7553
|
this._draggingContainer = null;
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
this._lastTarget = null;
|
|
7483
|
-
}
|
|
7554
|
+
this._lastTarget?.classList.remove("maplair-drag-target");
|
|
7555
|
+
this._lastTarget = null;
|
|
7484
7556
|
off(this._dragStartTarget, "pointermove", this._onMove, this);
|
|
7485
7557
|
off(this._dragStartTarget, "pointerup pointercancel lostpointercapture", this._onUp, this);
|
|
7486
7558
|
enableImageDrag();
|
|
@@ -7592,8 +7664,13 @@ var DragHandler = class DragHandler extends Handler {
|
|
|
7592
7664
|
map._stop();
|
|
7593
7665
|
map._setUserEvent(e.originalEvent);
|
|
7594
7666
|
if (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) {
|
|
7595
|
-
const bounds = LatLngBounds.from(this._map.options.maxBounds)
|
|
7596
|
-
|
|
7667
|
+
const bounds = LatLngBounds.from(this._map.options.maxBounds), { min, max } = new Bounds([
|
|
7668
|
+
bounds.getNorthWest(),
|
|
7669
|
+
bounds.getNorthEast(),
|
|
7670
|
+
bounds.getSouthEast(),
|
|
7671
|
+
bounds.getSouthWest()
|
|
7672
|
+
].map((c) => this._map.latLngToContainerPoint(c)));
|
|
7673
|
+
this._offsetLimit = new Bounds(max.multiplyBy(-1), min.multiplyBy(-1).add(this._map.getSize()));
|
|
7597
7674
|
this._viscosity = Math.min(1, Math.max(0, this._map.options.maxBoundsViscosity));
|
|
7598
7675
|
} else this._offsetLimit = null;
|
|
7599
7676
|
map.fire("movestart").fire("dragstart");
|
|
@@ -7739,7 +7816,7 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
7739
7816
|
const container = this._map._container;
|
|
7740
7817
|
if (container.tabIndex <= 0) container.tabIndex = 0;
|
|
7741
7818
|
const shortcuts = this._map.options.ariaKeyShortcuts;
|
|
7742
|
-
if (shortcuts) container.
|
|
7819
|
+
if (shortcuts) container.setAttribute("aria-keyshortcuts", shortcuts === true ? "ArrowLeft ArrowRight ArrowUp ArrowDown = Plus -" : shortcuts);
|
|
7743
7820
|
on(container, {
|
|
7744
7821
|
focus: this._onFocus,
|
|
7745
7822
|
blur: this._onBlur,
|
|
@@ -7795,7 +7872,7 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
7795
7872
|
return help;
|
|
7796
7873
|
}
|
|
7797
7874
|
_onPointerDown() {
|
|
7798
|
-
if (this._focused) return;
|
|
7875
|
+
if (this._focused || this._map._container.contains(document.activeElement)) return;
|
|
7799
7876
|
this._map._container.focus({
|
|
7800
7877
|
preventScroll: true,
|
|
7801
7878
|
focusVisible: false
|
|
@@ -7813,11 +7890,9 @@ var KeyboardHandler = class KeyboardHandler extends Handler {
|
|
|
7813
7890
|
}
|
|
7814
7891
|
_onContainerKeyDown(e) {
|
|
7815
7892
|
const map = this._map, popup = map._popup;
|
|
7816
|
-
if (e.key !== "Escape" || e.defaultPrevented || !popup?.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
|
|
7817
|
-
const inPopup = popup._container.contains(e.target), icon = popup._source?._icon;
|
|
7893
|
+
if (e.key !== "Escape" || e.defaultPrevented || !popup?.isOpen() || !popup.options.closeOnEscapeKey || map._controlContainer?.contains(e.target)) return;
|
|
7818
7894
|
map.closePopup();
|
|
7819
7895
|
e.preventDefault();
|
|
7820
|
-
if (inPopup) (icon?.tabIndex >= 0 ? icon : map._container).focus();
|
|
7821
7896
|
}
|
|
7822
7897
|
_onKeyDown(e) {
|
|
7823
7898
|
if (e.altKey || e.ctrlKey || e.metaKey) return;
|
|
@@ -7922,8 +7997,8 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
|
|
|
7922
7997
|
this._moved = false;
|
|
7923
7998
|
this._zooming = true;
|
|
7924
7999
|
map._stop();
|
|
7925
|
-
on(
|
|
7926
|
-
on(
|
|
8000
|
+
on(map._container, "pointermove", this._onPointerMove, this);
|
|
8001
|
+
on(map._container, "pointerup pointercancel", this._onPointerEnd, this);
|
|
7927
8002
|
e.preventDefault();
|
|
7928
8003
|
}
|
|
7929
8004
|
_onPointerMove(e) {
|
|
@@ -7946,10 +8021,7 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
|
|
|
7946
8021
|
this._moved = true;
|
|
7947
8022
|
}
|
|
7948
8023
|
cancelAnimationFrame(this._animRequest);
|
|
7949
|
-
const moveFn = map._move.bind(map, this._center, this._zoom, {
|
|
7950
|
-
pinch: true,
|
|
7951
|
-
round: false
|
|
7952
|
-
}, void 0);
|
|
8024
|
+
const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
|
|
7953
8025
|
this._animRequest = requestAnimationFrame(moveFn.bind(this));
|
|
7954
8026
|
e.preventDefault();
|
|
7955
8027
|
}
|
|
@@ -7965,7 +8037,7 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
|
|
|
7965
8037
|
}
|
|
7966
8038
|
this._zooming = false;
|
|
7967
8039
|
cancelAnimationFrame(this._animRequest);
|
|
7968
|
-
if (this._map._zoomAnimated) this._map._animateZoom(this._center, this._map._limitZoom(this._zoom),
|
|
8040
|
+
if (this._map._zoomAnimated) this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), this._map.options.zoomSnap);
|
|
7969
8041
|
else this._map._resetView(this._center, this._map._limitZoom(this._zoom));
|
|
7970
8042
|
}
|
|
7971
8043
|
/**
|
|
@@ -8102,10 +8174,7 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
|
|
|
8102
8174
|
const frame = () => {
|
|
8103
8175
|
const pinch = this._pinch, delta = pinch.zoom - pinch.shown;
|
|
8104
8176
|
pinch.shown = eased && Math.abs(delta) > .01 ? pinch.shown + delta * .3 : pinch.zoom;
|
|
8105
|
-
map._move(this._getPinchCenter(pinch.shown), pinch.shown, {
|
|
8106
|
-
pinch: true,
|
|
8107
|
-
round: false
|
|
8108
|
-
});
|
|
8177
|
+
map._move(this._getPinchCenter(pinch.shown), pinch.shown, { pinch: true });
|
|
8109
8178
|
if (pinch.shown !== pinch.zoom) this._pinchFrame = requestAnimationFrame(frame);
|
|
8110
8179
|
};
|
|
8111
8180
|
cancelAnimationFrame(this._pinchFrame);
|
|
@@ -8121,7 +8190,7 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
|
|
|
8121
8190
|
cancelAnimationFrame(this._pinchFrame);
|
|
8122
8191
|
const map = this._map, zoom = map._limitZoom(this._pinch.zoom), center = this._getPinchCenter(zoom);
|
|
8123
8192
|
this._pinch = null;
|
|
8124
|
-
if (map.options.zoomAnimation && Math.abs(zoom - map.getZoom()) > 1e-9) map._animateZoom(center, zoom,
|
|
8193
|
+
if (map.options.zoomAnimation && Math.abs(zoom - map.getZoom()) > 1e-9) map._animateZoom(center, zoom, map.options.zoomSnap);
|
|
8125
8194
|
else map._move(center, zoom)._moveEnd(true);
|
|
8126
8195
|
}
|
|
8127
8196
|
_panBy(e) {
|
|
@@ -8169,9 +8238,9 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
|
|
|
8169
8238
|
stop(e);
|
|
8170
8239
|
}
|
|
8171
8240
|
_performZoom() {
|
|
8172
|
-
const map = this._map, zoom = map.getZoom(), snap =
|
|
8241
|
+
const map = this._map, zoom = map.getZoom(), snap = map.options.zoomSnap ?? 0;
|
|
8173
8242
|
map._stop();
|
|
8174
|
-
const d2 = this._delta / (
|
|
8243
|
+
const d2 = this._delta / (map.options.wheelPxPerZoomLevel * 4), d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2, d4 = snap ? Math.ceil(d3 / snap) * snap : d3, d5 = map._prefersReducedMotion() ? Math.min(d4, 1) : d4, delta = map._limitZoom(zoom + (this._delta > 0 ? d5 : -d5)) - zoom;
|
|
8175
8244
|
this._delta = 0;
|
|
8176
8245
|
this._startTime = null;
|
|
8177
8246
|
if (!delta || map._zoomInputBlocked()) return;
|
|
@@ -8236,47 +8305,35 @@ var TapHoldHandler = class TapHoldHandler extends Handler {
|
|
|
8236
8305
|
removeHooks() {
|
|
8237
8306
|
off(this._map._container, "pointerdown", this._onDown, this);
|
|
8238
8307
|
this._cancel();
|
|
8239
|
-
this._cancelClickPrevent();
|
|
8240
8308
|
this._stopPreventingNative();
|
|
8241
8309
|
}
|
|
8242
8310
|
_onDown(e) {
|
|
8243
8311
|
clearTimeout(this._holdTimeout);
|
|
8244
8312
|
if (getPointers().length !== 1 || e.pointerType === "mouse") return;
|
|
8245
|
-
const el = this._map._container;
|
|
8246
|
-
this._startPos = this._newPos = new Point(e.clientX, e.clientY);
|
|
8313
|
+
const el = this._map._container, start = new Point(e.clientX, e.clientY);
|
|
8247
8314
|
this._holdTimeout = setTimeout((() => {
|
|
8248
8315
|
this._cancel();
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
on(el, "pointerup pointercancel", this._cancelClickPrevent, this);
|
|
8316
|
+
const pointers = getPointers(), p = pointers[0];
|
|
8317
|
+
if (pointers.length !== 1 || start.distanceTo([p.clientX, p.clientY]) > this._map.options.tapTolerance) return;
|
|
8252
8318
|
this._simulateEvent("contextmenu", e);
|
|
8253
8319
|
el.addEventListener("contextmenu", stop, true);
|
|
8320
|
+
el.addEventListener("click", stop, true);
|
|
8254
8321
|
el.addEventListener("pointerdown", this._stopPreventingNative, true);
|
|
8322
|
+
el.addEventListener("keydown", this._stopPreventingNative, true);
|
|
8255
8323
|
}), tapHoldDelay);
|
|
8256
8324
|
on(el, "pointerup pointercancel contextmenu", this._cancel, this);
|
|
8257
|
-
on(el, "pointermove", this._onMove, this);
|
|
8258
|
-
}
|
|
8259
|
-
_cancelClickPrevent() {
|
|
8260
|
-
const el = this._map._container;
|
|
8261
|
-
off(el, "pointerup", preventDefault);
|
|
8262
|
-
off(el, "pointerup pointercancel", this._cancelClickPrevent, this);
|
|
8263
8325
|
}
|
|
8264
8326
|
_stopPreventingNative = () => {
|
|
8265
8327
|
const el = this._map._container;
|
|
8266
8328
|
el.removeEventListener("contextmenu", stop, true);
|
|
8329
|
+
el.removeEventListener("click", stop, true);
|
|
8267
8330
|
el.removeEventListener("pointerdown", this._stopPreventingNative, true);
|
|
8331
|
+
el.removeEventListener("keydown", this._stopPreventingNative, true);
|
|
8268
8332
|
};
|
|
8269
8333
|
_cancel() {
|
|
8270
8334
|
clearTimeout(this._holdTimeout);
|
|
8271
8335
|
const el = this._map._container;
|
|
8272
8336
|
off(el, "pointerup pointercancel contextmenu", this._cancel, this);
|
|
8273
|
-
off(el, "pointermove", this._onMove, this);
|
|
8274
|
-
}
|
|
8275
|
-
_onMove(e) {
|
|
8276
|
-
this._newPos = new Point(e.clientX, e.clientY);
|
|
8277
|
-
}
|
|
8278
|
-
_isTapValid() {
|
|
8279
|
-
return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
|
|
8280
8337
|
}
|
|
8281
8338
|
_simulateEvent(type, e) {
|
|
8282
8339
|
const simulatedEvent = new MouseEvent(type, {
|
|
@@ -8417,10 +8474,7 @@ var TapDragZoomHandler = class TapDragZoomHandler extends Handler {
|
|
|
8417
8474
|
this._moved = true;
|
|
8418
8475
|
}
|
|
8419
8476
|
cancelAnimationFrame(this._animRequest);
|
|
8420
|
-
this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, {
|
|
8421
|
-
pinch: true,
|
|
8422
|
-
round: false
|
|
8423
|
-
}));
|
|
8477
|
+
this._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, { pinch: true }));
|
|
8424
8478
|
e.preventDefault();
|
|
8425
8479
|
}
|
|
8426
8480
|
_onUp() {
|
|
@@ -8432,7 +8486,7 @@ var TapDragZoomHandler = class TapDragZoomHandler extends Handler {
|
|
|
8432
8486
|
this._moved = false;
|
|
8433
8487
|
cancelAnimationFrame(this._animRequest);
|
|
8434
8488
|
const map = this._map, zoom = map._limitZoom(this._zoom);
|
|
8435
|
-
if (map.options.zoomAnimation) map._animateZoom(this._center, zoom,
|
|
8489
|
+
if (map.options.zoomAnimation) map._animateZoom(this._center, zoom, map.options.zoomSnap);
|
|
8436
8490
|
else map._move(this._center, zoom)._moveEnd(true);
|
|
8437
8491
|
}
|
|
8438
8492
|
/**
|
|
@@ -8476,7 +8530,9 @@ const zoomAnimDuration = 250;
|
|
|
8476
8530
|
* user tries to pan outside the view. To set the restriction dynamically, use
|
|
8477
8531
|
* [`setMaxBounds`](#map-setmaxbounds) method.
|
|
8478
8532
|
* @property {Renderer} [renderer] The default method for drawing vector layers on the
|
|
8479
|
-
* map. `SVG`
|
|
8533
|
+
* map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
|
|
8534
|
+
* instead. Paths in custom panes get their own renderer for that pane, of the same
|
|
8535
|
+
* class and with the same options as this one.
|
|
8480
8536
|
* @property {boolean} [zoomAnimation=true] Whether the map zoom animation is enabled.
|
|
8481
8537
|
* @property {number} [zoomAnimationThreshold=4] Won't animate zoom if the zoom
|
|
8482
8538
|
* difference exceeds this value (or 1 if the user prefers
|
|
@@ -8560,15 +8616,25 @@ const zoomAnimDuration = 250;
|
|
|
8560
8616
|
/**
|
|
8561
8617
|
* Options of the `MaplairMap` methods which modify the zoom level and the center.
|
|
8562
8618
|
* @typedef {object} ZoomPanOptions
|
|
8619
|
+
* @property {boolean} [animate] Whether to animate the change: like `ZoomOptions.animate`
|
|
8620
|
+
* if the zoom level changes, and like `PanOptions.animate` otherwise. The `zoom` and
|
|
8621
|
+
* `pan` options can set it for each case separately.
|
|
8622
|
+
* @property {boolean} [reset] If `true`, the view is reset without animation.
|
|
8623
|
+
* @property {ZoomOptions} [zoom] Options for the zoom part of the change, taking
|
|
8624
|
+
* precedence over `animate`.
|
|
8625
|
+
* @property {PanOptions} [pan] Options for the pan part of the change, taking
|
|
8626
|
+
* precedence over `animate`.
|
|
8563
8627
|
* @extends ZoomOptions, PanOptions
|
|
8564
8628
|
*/
|
|
8565
8629
|
/**
|
|
8566
8630
|
* Options of `MaplairMap.invalidateSize()`.
|
|
8567
8631
|
* @typedef {object} InvalidateSizeOptions
|
|
8632
|
+
* @property {boolean} [animate=false] If `true`, the map pans to its new center with
|
|
8633
|
+
* animation.
|
|
8568
8634
|
* @property {boolean} [pan=true] If `false`, panning will not occur.
|
|
8569
8635
|
* @property {boolean} [debounceMoveend=false] If `true`, it will delay `moveend` event
|
|
8570
8636
|
* so that it doesn't happen often even if the method is called many times in a row.
|
|
8571
|
-
* @extends
|
|
8637
|
+
* @extends PanOptions
|
|
8572
8638
|
*/
|
|
8573
8639
|
/**
|
|
8574
8640
|
* Padding options of `MaplairMap` methods, e.g. `panInside()`.
|
|
@@ -8616,7 +8682,9 @@ const zoomAnimDuration = 250;
|
|
|
8616
8682
|
* pressing a key or clicking a zoom button) have an `originalEvent` property with the
|
|
8617
8683
|
* DOM event that started the change. It is `undefined` for changes made by code (e.g.
|
|
8618
8684
|
* `setView()`), which allows to tell them apart, e.g. to avoid feedback loops when
|
|
8619
|
-
* synchronizing the view.
|
|
8685
|
+
* synchronizing the view. The `move` and `zoom` events also have `flyTo: true` on each
|
|
8686
|
+
* [`flyTo`](#map-flyto) animation frame, and `pinch: true` while the user pinch-zooms
|
|
8687
|
+
* the map.
|
|
8620
8688
|
*
|
|
8621
8689
|
* @example
|
|
8622
8690
|
* ```js
|
|
@@ -8716,6 +8784,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8716
8784
|
this._handlers = [];
|
|
8717
8785
|
this._layers = {};
|
|
8718
8786
|
this._zoomBoundLayers = {};
|
|
8787
|
+
this._canvases = [];
|
|
8719
8788
|
this._sizeChanged = true;
|
|
8720
8789
|
this._initContainer(id);
|
|
8721
8790
|
this._initLayout();
|
|
@@ -8746,10 +8815,23 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8746
8815
|
* @returns {this}
|
|
8747
8816
|
*/
|
|
8748
8817
|
setView(center, zoom, options) {
|
|
8749
|
-
zoom = zoom === void 0 ? this.
|
|
8818
|
+
zoom = zoom === void 0 ? this._targetZoom() : this._limitZoom(zoom);
|
|
8819
|
+
const targetCenter = center;
|
|
8750
8820
|
center = this._limitCenter(new LatLng(center), zoom, this.options.maxBounds);
|
|
8751
8821
|
options ??= {};
|
|
8752
8822
|
this._stop();
|
|
8823
|
+
this._targetView = {
|
|
8824
|
+
center: targetCenter,
|
|
8825
|
+
zoom
|
|
8826
|
+
};
|
|
8827
|
+
if (this._animatingZoom) {
|
|
8828
|
+
this._pendingView = {
|
|
8829
|
+
center,
|
|
8830
|
+
zoom,
|
|
8831
|
+
options
|
|
8832
|
+
};
|
|
8833
|
+
return this;
|
|
8834
|
+
}
|
|
8753
8835
|
if (this._loaded && !options.reset && options !== true) {
|
|
8754
8836
|
if (options.animate !== void 0) {
|
|
8755
8837
|
options.zoom = {
|
|
@@ -8762,12 +8844,12 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8762
8844
|
...options.pan
|
|
8763
8845
|
};
|
|
8764
8846
|
}
|
|
8765
|
-
if (this._zoom !== zoom ? this._tryAnimatedZoom
|
|
8847
|
+
if (this._zoom !== zoom ? this._tryAnimatedZoom?.(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan)) {
|
|
8766
8848
|
clearTimeout(this._sizeTimer);
|
|
8767
8849
|
return this;
|
|
8768
8850
|
}
|
|
8769
8851
|
}
|
|
8770
|
-
this._resetView(center, zoom, options.pan?.noMoveStart);
|
|
8852
|
+
this._resetView(this.options.worldCopyJump ? this.wrapLatLng(center) : center, zoom, options.pan?.noMoveStart);
|
|
8771
8853
|
return this;
|
|
8772
8854
|
}
|
|
8773
8855
|
/**
|
|
@@ -8782,7 +8864,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8782
8864
|
this._zoom = zoom;
|
|
8783
8865
|
return this;
|
|
8784
8866
|
}
|
|
8785
|
-
return this.setView(this.getCenter(), zoom, { zoom: options });
|
|
8867
|
+
return this.setView(this._targetView?.center ?? this.getCenter(), zoom, { zoom: options });
|
|
8786
8868
|
}
|
|
8787
8869
|
/**
|
|
8788
8870
|
* Increases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
|
|
@@ -8793,7 +8875,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8793
8875
|
*/
|
|
8794
8876
|
zoomIn(delta, options) {
|
|
8795
8877
|
delta ??= this.options.zoomDelta;
|
|
8796
|
-
return this.setZoom(this.
|
|
8878
|
+
return this.setZoom(this._targetZoom() + delta, options);
|
|
8797
8879
|
}
|
|
8798
8880
|
/**
|
|
8799
8881
|
* Decreases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
|
|
@@ -8804,7 +8886,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8804
8886
|
*/
|
|
8805
8887
|
zoomOut(delta, options) {
|
|
8806
8888
|
delta ??= this.options.zoomDelta;
|
|
8807
|
-
return this.setZoom(this.
|
|
8889
|
+
return this.setZoom(this._targetZoom() - delta, options);
|
|
8808
8890
|
}
|
|
8809
8891
|
/**
|
|
8810
8892
|
* Zooms the map while keeping a specified geographical point on the map
|
|
@@ -8826,7 +8908,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8826
8908
|
bounds = bounds.getBounds ? bounds.getBounds() : LatLngBounds.from(bounds);
|
|
8827
8909
|
const paddingTL = Point.from(options.paddingTopLeft || options.padding || [0, 0]), paddingBR = Point.from(options.paddingBottomRight || options.padding || [0, 0]);
|
|
8828
8910
|
let zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR));
|
|
8829
|
-
zoom =
|
|
8911
|
+
zoom = Math.min(options.maxZoom ?? Infinity, zoom);
|
|
8830
8912
|
if (zoom === Infinity) return {
|
|
8831
8913
|
center: bounds.getCenter(),
|
|
8832
8914
|
zoom
|
|
@@ -8869,7 +8951,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8869
8951
|
* @returns {this}
|
|
8870
8952
|
*/
|
|
8871
8953
|
panTo(center, options) {
|
|
8872
|
-
return this.setView(center,
|
|
8954
|
+
return this.setView(center, void 0, { pan: options });
|
|
8873
8955
|
}
|
|
8874
8956
|
/**
|
|
8875
8957
|
* Pans the map by a given number of pixels (animated unless `animate: false` is passed,
|
|
@@ -8881,24 +8963,18 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8881
8963
|
* @returns {this}
|
|
8882
8964
|
*/
|
|
8883
8965
|
panBy(offset, options) {
|
|
8884
|
-
|
|
8966
|
+
const { center = this.getCenter(), zoom = this._zoom } = this._targetView ?? {}, newCenter = this.unproject(this.project(center, zoom).add(Point.from(offset).round()), zoom);
|
|
8967
|
+
return this.setView(newCenter, zoom, { pan: options });
|
|
8968
|
+
}
|
|
8969
|
+
_panBy(offset, options) {
|
|
8885
8970
|
options ??= {};
|
|
8886
|
-
if (!offset.x && !offset.y) return this.
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
return this;
|
|
8892
|
-
}
|
|
8893
|
-
if (!this._panAnim) {
|
|
8894
|
-
this._panAnim = new PosAnimation();
|
|
8895
|
-
this._panAnim.on({
|
|
8896
|
-
"step": this._onPanTransitionStep,
|
|
8897
|
-
"end": this._onPanTransitionEnd
|
|
8898
|
-
}, this);
|
|
8899
|
-
}
|
|
8971
|
+
if (!offset.x && !offset.y) return this._moveStart(false, true)._moveEnd(false);
|
|
8972
|
+
if (!this._panAnim) this._panAnim = new PosAnimation().on({
|
|
8973
|
+
step: this._onPanTransitionStep,
|
|
8974
|
+
end: this._onPanTransitionEnd
|
|
8975
|
+
}, this);
|
|
8900
8976
|
if (!options.noMoveStart) this.fire("movestart");
|
|
8901
|
-
const tooFarForReducedMotion = this._prefersReducedMotion() && !
|
|
8977
|
+
const tooFarForReducedMotion = this._prefersReducedMotion() && !this.getSize().divideBy(2).contains(offset);
|
|
8902
8978
|
if (options.animate === true || options.animate !== false && !tooFarForReducedMotion) {
|
|
8903
8979
|
this._mapPane.classList.add("maplair-pan-anim");
|
|
8904
8980
|
const newPos = this._getMapPanePos().subtract(offset).round();
|
|
@@ -8906,7 +8982,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8906
8982
|
} else {
|
|
8907
8983
|
this._rawPanBy(offset);
|
|
8908
8984
|
this._wrapWorldCopy();
|
|
8909
|
-
this.fire("move").
|
|
8985
|
+
this.fire("move")._moveEnd(false);
|
|
8910
8986
|
}
|
|
8911
8987
|
return this;
|
|
8912
8988
|
}
|
|
@@ -8930,9 +9006,15 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8930
9006
|
}
|
|
8931
9007
|
});
|
|
8932
9008
|
if (options.animate !== true && this._prefersReducedMotion()) return this.setView(targetCenter, targetZoom, options);
|
|
8933
|
-
this.
|
|
8934
|
-
|
|
9009
|
+
targetZoom = targetZoom === void 0 ? this._targetZoom() : this._limitZoom(targetZoom);
|
|
9010
|
+
const requestedCenter = targetCenter;
|
|
8935
9011
|
targetCenter = this._limitCenter(new LatLng(targetCenter), targetZoom, this.options.maxBounds);
|
|
9012
|
+
this._stop();
|
|
9013
|
+
this._targetView = {
|
|
9014
|
+
center: requestedCenter,
|
|
9015
|
+
zoom: targetZoom
|
|
9016
|
+
};
|
|
9017
|
+
this._subpixelOrigin = true;
|
|
8936
9018
|
const from = this.project(this.getCenter()), to = this.project(targetCenter), size = this.getSize(), startZoom = this._zoom;
|
|
8937
9019
|
const w0 = Math.max(size.x, size.y), w1 = w0 * this.getZoomScale(startZoom, targetZoom), u1 = to.distanceTo(from) || 1, rho = 1.42, rho2 = rho * rho;
|
|
8938
9020
|
function r(i) {
|
|
@@ -8946,7 +9028,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8946
9028
|
function easeOut(t) {
|
|
8947
9029
|
return 1 - (1 - t) ** 1.5;
|
|
8948
9030
|
}
|
|
8949
|
-
const start = Date.now(), S = (r(1) - r0) / rho, duration =
|
|
9031
|
+
const start = Date.now(), S = (r(1) - r0) / rho, duration = 1e3 * (options.duration || S * .8);
|
|
8950
9032
|
const frame = () => {
|
|
8951
9033
|
const t = (Date.now() - start) / duration, s = easeOut(t) * S;
|
|
8952
9034
|
if (t <= 1) {
|
|
@@ -8954,6 +9036,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
8954
9036
|
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 });
|
|
8955
9037
|
} else {
|
|
8956
9038
|
const zoomChanged = this._zoom !== targetZoom;
|
|
9039
|
+
this._subpixelOrigin = false;
|
|
8957
9040
|
this._move(targetCenter, targetZoom);
|
|
8958
9041
|
if (!zoomChanged) this.fire("zoom");
|
|
8959
9042
|
this._moveEnd(true);
|
|
@@ -9038,7 +9121,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9038
9121
|
this.options.minZoom = zoom;
|
|
9039
9122
|
if (this._loaded && oldZoom !== zoom) {
|
|
9040
9123
|
this.fire("zoomlevelschange");
|
|
9041
|
-
if (this.
|
|
9124
|
+
if (this._targetZoom() < this.options.minZoom) return this.setZoom(zoom);
|
|
9042
9125
|
}
|
|
9043
9126
|
return this;
|
|
9044
9127
|
}
|
|
@@ -9053,7 +9136,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9053
9136
|
this.options.maxZoom = zoom;
|
|
9054
9137
|
if (this._loaded && oldZoom !== zoom) {
|
|
9055
9138
|
this.fire("zoomlevelschange");
|
|
9056
|
-
if (this.
|
|
9139
|
+
if (this._targetZoom() > this.options.maxZoom) return this.setZoom(zoom);
|
|
9057
9140
|
}
|
|
9058
9141
|
return this;
|
|
9059
9142
|
}
|
|
@@ -9098,8 +9181,8 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9098
9181
|
}
|
|
9099
9182
|
/**
|
|
9100
9183
|
* Checks if the map container size changed and updates the map if so —
|
|
9101
|
-
* call it after you've changed the map size dynamically, also
|
|
9102
|
-
*
|
|
9184
|
+
* call it after you've changed the map size dynamically, also panning to
|
|
9185
|
+
* keep the center by default. If `options.pan` is `false`, panning will not occur.
|
|
9103
9186
|
* If `options.debounceMoveend` is `true`, it will delay `moveend` event so
|
|
9104
9187
|
* that it doesn't happen often even if the method is called many
|
|
9105
9188
|
* times in a row. Passing `true` instead of options animates the panning.
|
|
@@ -9116,8 +9199,9 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9116
9199
|
};
|
|
9117
9200
|
const oldSize = this.getSize();
|
|
9118
9201
|
this._sizeChanged = true;
|
|
9119
|
-
|
|
9120
|
-
|
|
9202
|
+
const newSize = this.getSize();
|
|
9203
|
+
if (!newSize.equals(oldSize)) this._lastCenter = null;
|
|
9204
|
+
const oldCenter = oldSize.divideBy(2).round(), newCenter = newSize.divideBy(2).round(), offset = oldCenter.subtract(newCenter);
|
|
9121
9205
|
if (!offset.x && !offset.y) return this;
|
|
9122
9206
|
if (options.animate && options.pan) this.panBy(offset);
|
|
9123
9207
|
else {
|
|
@@ -9199,7 +9283,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9199
9283
|
}
|
|
9200
9284
|
_handleGeolocationResponse(pos) {
|
|
9201
9285
|
if (!this._container._maplair_id) return;
|
|
9202
|
-
const
|
|
9286
|
+
const latlng = new LatLng(pos.coords.latitude, pos.coords.longitude), bounds = latlng.toBounds(pos.coords.accuracy * 2), options = this._locateOptions;
|
|
9203
9287
|
if (options.setView) {
|
|
9204
9288
|
const zoom = this.getBoundsZoom(bounds);
|
|
9205
9289
|
this.setView(latlng, options.maxZoom ? Math.min(zoom, options.maxZoom) : zoom);
|
|
@@ -9233,7 +9317,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9233
9317
|
*/
|
|
9234
9318
|
remove() {
|
|
9235
9319
|
this._initEvents(true);
|
|
9236
|
-
|
|
9320
|
+
this.off("moveend", this._panInsideMaxBounds);
|
|
9237
9321
|
if (this._containerId !== this._container._maplair_id) throw new Error("Map container is being reused by another instance");
|
|
9238
9322
|
delete this._container._maplair_id;
|
|
9239
9323
|
delete this._containerId;
|
|
@@ -9332,7 +9416,12 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9332
9416
|
bounds = LatLngBounds.from(bounds);
|
|
9333
9417
|
padding = Point.from(padding ?? [0, 0]);
|
|
9334
9418
|
let zoom = this.getZoom() ?? 0;
|
|
9335
|
-
const min = this.getMinZoom(), max = this.getMaxZoom(),
|
|
9419
|
+
const min = this.getMinZoom(), max = this.getMaxZoom(), size = this.getSize().subtract(padding), boundsSize = new Bounds([
|
|
9420
|
+
bounds.getNorthWest(),
|
|
9421
|
+
bounds.getNorthEast(),
|
|
9422
|
+
bounds.getSouthEast(),
|
|
9423
|
+
bounds.getSouthWest()
|
|
9424
|
+
].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);
|
|
9336
9425
|
zoom = this.getScaleZoom(scale, zoom);
|
|
9337
9426
|
if (snap) {
|
|
9338
9427
|
zoom = Math.round(zoom / (snap / 100)) * (snap / 100);
|
|
@@ -9571,7 +9660,18 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9571
9660
|
* @returns {Point}
|
|
9572
9661
|
*/
|
|
9573
9662
|
pointerEventToContainerPoint(e) {
|
|
9574
|
-
return getPointerPosition(e, this._container);
|
|
9663
|
+
if (!this._animatingZoom) return getPointerPosition(e, this._container);
|
|
9664
|
+
if (!this._containerRect) {
|
|
9665
|
+
const el = this._container, { x, y, boundingClientRect: r } = getScale(el);
|
|
9666
|
+
this._containerRect = {
|
|
9667
|
+
x,
|
|
9668
|
+
y,
|
|
9669
|
+
left: r.left + el.clientLeft * x,
|
|
9670
|
+
top: r.top + el.clientTop * y
|
|
9671
|
+
};
|
|
9672
|
+
}
|
|
9673
|
+
const c = this._containerRect;
|
|
9674
|
+
return new Point((e.clientX - c.left) / c.x, (e.clientY - c.top) / c.y);
|
|
9575
9675
|
}
|
|
9576
9676
|
/**
|
|
9577
9677
|
* Given a PointerEvent object, returns the pixel coordinate relative to
|
|
@@ -9736,18 +9836,25 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9736
9836
|
this._lastCenterPanePos = this._getMapPanePos();
|
|
9737
9837
|
this._pixelOrigin = this._getNewPixelOrigin(center);
|
|
9738
9838
|
if (!suppressEvent) {
|
|
9739
|
-
if (zoomChanged || data?.pinch) this.fire("zoom", data);
|
|
9839
|
+
if (zoomChanged || data?.pinch || data?.flyTo) this.fire("zoom", data);
|
|
9740
9840
|
this.fire("move", data);
|
|
9741
9841
|
} else if (data?.pinch) this.fire("zoom", data);
|
|
9742
9842
|
return this;
|
|
9743
9843
|
}
|
|
9744
9844
|
_moveEnd(zoomChanged) {
|
|
9845
|
+
if (!this._pendingView) this._targetView = null;
|
|
9745
9846
|
if (zoomChanged) this.fire("zoomend");
|
|
9746
9847
|
return this.fire("moveend");
|
|
9747
9848
|
}
|
|
9748
9849
|
_stop() {
|
|
9850
|
+
this._pendingView = null;
|
|
9851
|
+
this._targetView = null;
|
|
9749
9852
|
cancelAnimationFrame(this._flyToFrame);
|
|
9750
9853
|
cancelAnimationFrame(this._zoomAnimFrame);
|
|
9854
|
+
if (this._subpixelOrigin) {
|
|
9855
|
+
this._subpixelOrigin = false;
|
|
9856
|
+
this._move(this._lastCenter, this._zoom, { flyTo: true });
|
|
9857
|
+
}
|
|
9751
9858
|
this._panAnim?.stop();
|
|
9752
9859
|
return this;
|
|
9753
9860
|
}
|
|
@@ -9802,13 +9909,14 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9802
9909
|
_findEventTargets(e, type) {
|
|
9803
9910
|
let targets = [], target, src = e.target, dragging = false;
|
|
9804
9911
|
const isHover = type === "pointerout" || type === "pointerover";
|
|
9912
|
+
const canEndDrag = (type === "click" || type === "preclick") && e.detail > 0;
|
|
9805
9913
|
while (src) {
|
|
9806
9914
|
target = this._targets[stamp(src)];
|
|
9807
|
-
if (target &&
|
|
9915
|
+
if (target && canEndDrag && this._draggableMoved(target)) {
|
|
9808
9916
|
dragging = true;
|
|
9809
9917
|
break;
|
|
9810
9918
|
}
|
|
9811
|
-
if (target
|
|
9919
|
+
if (target?.listens(type, true)) {
|
|
9812
9920
|
if (isHover && !isExternalTarget(src, e)) break;
|
|
9813
9921
|
targets.push(target);
|
|
9814
9922
|
if (isHover) break;
|
|
@@ -9819,16 +9927,31 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9819
9927
|
if (!targets.length && !dragging && !isHover && this.listens(type, true)) targets = [this];
|
|
9820
9928
|
return targets;
|
|
9821
9929
|
}
|
|
9822
|
-
_isClickDisabled(el) {
|
|
9823
|
-
while (el && el !== this._container) {
|
|
9824
|
-
if (el["_maplair_disable_click"] || !el.parentNode) return true;
|
|
9825
|
-
el = el.parentNode;
|
|
9826
|
-
}
|
|
9827
|
-
}
|
|
9828
9930
|
_handleDOMEvent(e) {
|
|
9829
9931
|
const el = e.target;
|
|
9830
|
-
if (
|
|
9831
|
-
this.
|
|
9932
|
+
if (e.type === "click") simulateDblclick(e, this._container);
|
|
9933
|
+
if (!this._loaded || e.type === "click" && isClickDisabled(el, this._container)) return;
|
|
9934
|
+
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);
|
|
9935
|
+
let layer = skip ? void 0 : this._canvasLayerAt(e, type === "click");
|
|
9936
|
+
if (type === "pointerdown") this._pressedCanvasLayer = skip ? void 0 : layer ?? null;
|
|
9937
|
+
else if (type === "click" && e.detail > 0 && this._pressedCanvasLayer !== void 0) {
|
|
9938
|
+
if (layer !== this._pressedCanvasLayer) layer = void 0;
|
|
9939
|
+
this._pressedCanvasLayer = void 0;
|
|
9940
|
+
}
|
|
9941
|
+
if (layer !== hovered && (move && !skip || leftMap)) {
|
|
9942
|
+
if (hovered) this._fireDOMEvent(e, "pointerout", [hovered]);
|
|
9943
|
+
this._container.classList.toggle("maplair-interactive", !!layer);
|
|
9944
|
+
this._hoveredCanvasLayer = layer;
|
|
9945
|
+
if (layer) this._fireDOMEvent(e, "pointerover", [layer]);
|
|
9946
|
+
}
|
|
9947
|
+
this._fireDOMEvent(e, type, layer && [layer]);
|
|
9948
|
+
}
|
|
9949
|
+
_canvasLayerAt(e, click) {
|
|
9950
|
+
for (let el = e.target; el !== this._container; el = el.parentNode) if (!el || el === this._controlContainer || this._targets[stamp(el)]) return;
|
|
9951
|
+
for (const renderer of this._canvases) {
|
|
9952
|
+
const layer = renderer._layerAt(e, click);
|
|
9953
|
+
if (layer) return layer;
|
|
9954
|
+
}
|
|
9832
9955
|
}
|
|
9833
9956
|
static _pointerEvents = [
|
|
9834
9957
|
"click",
|
|
@@ -9839,7 +9962,7 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9839
9962
|
];
|
|
9840
9963
|
_fireDOMEvent(e, type, canvasTargets) {
|
|
9841
9964
|
if (type === "click") this._fireDOMEvent(e, "preclick", canvasTargets);
|
|
9842
|
-
let targets = this._findEventTargets(e, type);
|
|
9965
|
+
let targets = canvasTargets && (type === "pointerover" || type === "pointerout") ? [] : this._findEventTargets(e, type);
|
|
9843
9966
|
if (canvasTargets) targets = [...canvasTargets.filter((t) => t.listens(type, true)), ...targets];
|
|
9844
9967
|
if (!targets.length) return;
|
|
9845
9968
|
if (type === "contextmenu") e.preventDefault();
|
|
@@ -9883,7 +10006,11 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9883
10006
|
}
|
|
9884
10007
|
_getNewPixelOrigin(center, zoom) {
|
|
9885
10008
|
const viewHalf = this.getSize()._divideBy(2);
|
|
9886
|
-
|
|
10009
|
+
const origin = this.project(center, zoom)._subtract(viewHalf)._add(this._getMapPanePos());
|
|
10010
|
+
return this._subpixelOrigin ? origin : origin._round();
|
|
10011
|
+
}
|
|
10012
|
+
_snapLayerPoint(point) {
|
|
10013
|
+
return this._subpixelOrigin ? point : point._round();
|
|
9887
10014
|
}
|
|
9888
10015
|
_latLngToNewLayerPoint(latlng, zoom, center) {
|
|
9889
10016
|
const topLeft = this._getNewPixelOrigin(center, zoom);
|
|
@@ -9910,7 +10037,12 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9910
10037
|
return offset.add(this._getBoundsOffset(newBounds, bounds));
|
|
9911
10038
|
}
|
|
9912
10039
|
_getBoundsOffset(pxBounds, maxBounds, zoom) {
|
|
9913
|
-
const projectedMaxBounds = new Bounds(
|
|
10040
|
+
const projectedMaxBounds = new Bounds([
|
|
10041
|
+
maxBounds.getNorthWest(),
|
|
10042
|
+
maxBounds.getNorthEast(),
|
|
10043
|
+
maxBounds.getSouthEast(),
|
|
10044
|
+
maxBounds.getSouthWest()
|
|
10045
|
+
].map((c) => this.project(c, zoom))), minOffset = projectedMaxBounds.min.subtract(pxBounds.min), maxOffset = projectedMaxBounds.max.subtract(pxBounds.max);
|
|
9914
10046
|
return new Point(this._rebound(minOffset.x, -maxOffset.x), this._rebound(minOffset.y, -maxOffset.y));
|
|
9915
10047
|
}
|
|
9916
10048
|
_rebound(left, right) {
|
|
@@ -9927,17 +10059,17 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9927
10059
|
_onPanTransitionEnd() {
|
|
9928
10060
|
this._mapPane.classList.remove("maplair-pan-anim");
|
|
9929
10061
|
this._wrapWorldCopy();
|
|
9930
|
-
this.
|
|
10062
|
+
this._moveEnd(false);
|
|
9931
10063
|
}
|
|
9932
10064
|
_tryAnimatedPan(center, options) {
|
|
9933
|
-
const offset = this.
|
|
10065
|
+
const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
|
|
9934
10066
|
if (options?.animate !== true && !this.getSize().contains(offset)) return false;
|
|
9935
|
-
this.
|
|
10067
|
+
this._panBy(offset, options);
|
|
9936
10068
|
return true;
|
|
9937
10069
|
}
|
|
9938
10070
|
_createAnimProxy() {
|
|
9939
10071
|
this._proxy = create("div", "maplair-proxy maplair-zoom-animated");
|
|
9940
|
-
this._panes.mapPane.
|
|
10072
|
+
this._panes.mapPane.append(this._proxy);
|
|
9941
10073
|
this.on("zoomanim", this._animateProxyZoom, this);
|
|
9942
10074
|
this.on("load moveend", this._animMoveEnd, this);
|
|
9943
10075
|
on(this._proxy, "transitionend", this._catchTransitionEnd, this);
|
|
@@ -9971,6 +10103,9 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9971
10103
|
};
|
|
9972
10104
|
this._flyToFrame = requestAnimationFrame(frame);
|
|
9973
10105
|
}
|
|
10106
|
+
_targetZoom() {
|
|
10107
|
+
return this._targetView?.zoom ?? this._zoom;
|
|
10108
|
+
}
|
|
9974
10109
|
_zoomInputBlocked() {
|
|
9975
10110
|
return this._animatingZoom || Date.now() < this._instantZoomEnd;
|
|
9976
10111
|
}
|
|
@@ -9989,18 +10124,16 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
9989
10124
|
this._zoomAnimFrame = requestAnimationFrame(() => {
|
|
9990
10125
|
this._zoomAnimFrame = null;
|
|
9991
10126
|
if (userEvent) this._setUserEvent(userEvent);
|
|
9992
|
-
this._moveStart(true, options.noMoveStart ?? false)._animateZoom(center, zoom
|
|
10127
|
+
this._moveStart(true, options.noMoveStart ?? false)._animateZoom(center, zoom);
|
|
9993
10128
|
});
|
|
9994
10129
|
return true;
|
|
9995
10130
|
}
|
|
9996
|
-
_animateZoom(center, zoom,
|
|
10131
|
+
_animateZoom(center, zoom, noUpdate) {
|
|
9997
10132
|
if (!this._mapPane) return;
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
this._mapPane.classList.add("maplair-zoom-anim");
|
|
10003
|
-
}
|
|
10133
|
+
this._animatingZoom = true;
|
|
10134
|
+
this._animateToCenter = center;
|
|
10135
|
+
this._animateToZoom = zoom;
|
|
10136
|
+
this._mapPane.classList.add("maplair-zoom-anim");
|
|
10004
10137
|
this.fire("zoomanim", {
|
|
10005
10138
|
center,
|
|
10006
10139
|
zoom,
|
|
@@ -10008,17 +10141,25 @@ var MaplairMap = class MaplairMap extends Evented {
|
|
|
10008
10141
|
});
|
|
10009
10142
|
if (!this._tempFireZoomEvent) this._tempFireZoomEvent = this._zoom !== this._animateToZoom;
|
|
10010
10143
|
this._move(this._animateToCenter, this._animateToZoom, void 0, true);
|
|
10011
|
-
this._transitionEndTimer
|
|
10144
|
+
clearTimeout(this._transitionEndTimer);
|
|
10145
|
+
this._transitionEndTimer = setTimeout(this._onZoomTransitionEnd.bind(this), 1e3);
|
|
10012
10146
|
}
|
|
10013
10147
|
_onZoomTransitionEnd() {
|
|
10014
10148
|
if (!this._animatingZoom) return;
|
|
10149
|
+
clearTimeout(this._transitionEndTimer);
|
|
10150
|
+
this._containerRect = null;
|
|
10015
10151
|
this._mapPane?.classList.remove("maplair-zoom-anim");
|
|
10016
10152
|
this._animatingZoom = false;
|
|
10017
|
-
this._move(this.
|
|
10153
|
+
this._move(this.getCenter(), this._animateToZoom, void 0, true);
|
|
10018
10154
|
if (this._tempFireZoomEvent) this.fire("zoom");
|
|
10019
10155
|
delete this._tempFireZoomEvent;
|
|
10020
10156
|
this.fire("move");
|
|
10021
10157
|
this._moveEnd(true);
|
|
10158
|
+
const view = this._pendingView;
|
|
10159
|
+
if (view) {
|
|
10160
|
+
this._pendingView = null;
|
|
10161
|
+
this.setView(view.center, view.zoom, view.options);
|
|
10162
|
+
}
|
|
10022
10163
|
}
|
|
10023
10164
|
};
|
|
10024
10165
|
for (const feature of [
|
|
@@ -10138,9 +10279,9 @@ var Polyline = class Polyline extends Path {
|
|
|
10138
10279
|
closestLayerPoint(p) {
|
|
10139
10280
|
p = Point.from(p);
|
|
10140
10281
|
let minDistance = Infinity, minPoint = null, p1, p2;
|
|
10141
|
-
const closest = _sqClosestPointOnSegment;
|
|
10142
|
-
for (const points of this._parts) for (let i = 1, len = points.length; i < len; i++) {
|
|
10143
|
-
p1 = points[i - 1];
|
|
10282
|
+
const closest = _sqClosestPointOnSegment, closed = this._isClosed();
|
|
10283
|
+
for (const points of this._parts) for (let i = closed ? 0 : 1, len = points.length; i < len; i++) {
|
|
10284
|
+
p1 = points[(i || len) - 1];
|
|
10144
10285
|
p2 = points[i];
|
|
10145
10286
|
const sqDist = closest(p, p1, p2, true);
|
|
10146
10287
|
if (sqDist < minDistance) {
|
|
@@ -10213,7 +10354,7 @@ var Polyline = class Polyline extends Path {
|
|
|
10213
10354
|
}
|
|
10214
10355
|
_projectLatlngs(latlngs, result, projectedBounds) {
|
|
10215
10356
|
if (latlngs[0] instanceof LatLng) {
|
|
10216
|
-
const ring = latlngs.map((latlng) => this.
|
|
10357
|
+
const ring = latlngs.map((latlng) => this._renderer._latLngToLayerPoint(latlng));
|
|
10217
10358
|
ring.forEach((r) => projectedBounds.extend(r));
|
|
10218
10359
|
result.push(ring);
|
|
10219
10360
|
} else latlngs.forEach((latlng) => this._projectLatlngs(latlng, result, projectedBounds));
|
|
@@ -10221,24 +10362,21 @@ var Polyline = class Polyline extends Path {
|
|
|
10221
10362
|
_clipPoints() {
|
|
10222
10363
|
const bounds = this._renderer._bounds;
|
|
10223
10364
|
this._parts = [];
|
|
10224
|
-
if (!this._pxBounds
|
|
10365
|
+
if (!this._pxBounds?.intersects(bounds)) return;
|
|
10225
10366
|
if (this.options.noClip) {
|
|
10226
10367
|
this._parts = this._rings;
|
|
10227
10368
|
return;
|
|
10228
10369
|
}
|
|
10229
10370
|
const parts = this._parts;
|
|
10230
|
-
let
|
|
10231
|
-
for (
|
|
10232
|
-
|
|
10233
|
-
|
|
10234
|
-
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
parts[k].push(segment[
|
|
10238
|
-
|
|
10239
|
-
parts[k].push(segment[1]);
|
|
10240
|
-
k++;
|
|
10241
|
-
}
|
|
10371
|
+
let k = 0;
|
|
10372
|
+
for (const points of this._rings) for (let j = 0, len = points.length; j < len - 1; j++) {
|
|
10373
|
+
const segment = clipSegment(points[j], points[j + 1], bounds, j);
|
|
10374
|
+
if (!segment) continue;
|
|
10375
|
+
parts[k] ??= [];
|
|
10376
|
+
parts[k].push(segment[0]);
|
|
10377
|
+
if (segment[1] !== points[j + 1] || j === len - 2) {
|
|
10378
|
+
parts[k].push(segment[1]);
|
|
10379
|
+
k++;
|
|
10242
10380
|
}
|
|
10243
10381
|
}
|
|
10244
10382
|
}
|
|
@@ -10255,17 +10393,13 @@ var Polyline = class Polyline extends Path {
|
|
|
10255
10393
|
_updatePath() {
|
|
10256
10394
|
this._renderer._updatePoly(this);
|
|
10257
10395
|
}
|
|
10396
|
+
_isClosed() {
|
|
10397
|
+
return false;
|
|
10398
|
+
}
|
|
10258
10399
|
_containsPoint(p, closed) {
|
|
10259
|
-
let i, j, k, len, len2, part;
|
|
10260
10400
|
const w = this._clickTolerance();
|
|
10261
|
-
if (!this._pxBounds
|
|
10262
|
-
for (
|
|
10263
|
-
part = this._parts[i];
|
|
10264
|
-
for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
|
|
10265
|
-
if (!closed && j === 0) continue;
|
|
10266
|
-
if (pointToSegmentDistance(p, part[k], part[j]) <= w) return true;
|
|
10267
|
-
}
|
|
10268
|
-
}
|
|
10401
|
+
if (!this._pxBounds?.contains(p)) return false;
|
|
10402
|
+
for (const part of this._parts) for (let j = closed ? 0 : 1, len = part.length; j < len; j++) if (pointToSegmentDistance(p, part[(j || len) - 1], part[j]) <= w) return true;
|
|
10269
10403
|
return false;
|
|
10270
10404
|
}
|
|
10271
10405
|
/**
|
|
@@ -10292,7 +10426,6 @@ var PolyUtil_exports = /* @__PURE__ */ __exportAll({
|
|
|
10292
10426
|
polygonCenter: () => polygonCenter
|
|
10293
10427
|
});
|
|
10294
10428
|
/** @import {LatLngExpression} from '../geo/LatLng.js' */
|
|
10295
|
-
/** @import {Bounds} from './Bounds.js' */
|
|
10296
10429
|
/** @import {CRS} from '../geo/crs/CRS.js' */
|
|
10297
10430
|
/**
|
|
10298
10431
|
* Clips the polygon geometry defined by the given `points` by the given bounds (using
|
|
@@ -10347,7 +10480,14 @@ function polygonCenter(latlngs, crs) {
|
|
|
10347
10480
|
y += (p1.y + p2.y) * f;
|
|
10348
10481
|
area += f;
|
|
10349
10482
|
}
|
|
10350
|
-
|
|
10483
|
+
if (area !== 0) return crs.unproject(new Point(x / (3 * area), y / (3 * area))._add(origin));
|
|
10484
|
+
const mid = new Bounds(points).getCenter();
|
|
10485
|
+
let center = points[0];
|
|
10486
|
+
for (let i = 0, j = len - 1; i < len; j = i++) {
|
|
10487
|
+
const p = _sqClosestPointOnSegment(mid, points[j], points[i]);
|
|
10488
|
+
if (p.distanceTo(mid) < center.distanceTo(mid)) center = p;
|
|
10489
|
+
}
|
|
10490
|
+
return crs.unproject(center._add(origin));
|
|
10351
10491
|
}
|
|
10352
10492
|
/**
|
|
10353
10493
|
* Returns the 'center of mass' of the passed LatLngs.
|
|
@@ -10462,10 +10602,10 @@ var Polygon = class Polygon extends Polyline {
|
|
|
10462
10602
|
}
|
|
10463
10603
|
_clipPoints() {
|
|
10464
10604
|
let bounds = this._renderer._bounds;
|
|
10465
|
-
const w = this.options.weight, p = new Point(w, w);
|
|
10605
|
+
const w = +this.options.weight || 0, p = new Point(w, w);
|
|
10466
10606
|
bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
|
|
10467
10607
|
this._parts = [];
|
|
10468
|
-
if (!this._pxBounds
|
|
10608
|
+
if (!this._pxBounds?.intersects(bounds)) return;
|
|
10469
10609
|
if (this.options.noClip) {
|
|
10470
10610
|
this._parts = this._rings;
|
|
10471
10611
|
return;
|
|
@@ -10478,16 +10618,15 @@ var Polygon = class Polygon extends Polyline {
|
|
|
10478
10618
|
_updatePath() {
|
|
10479
10619
|
this._renderer._updatePoly(this, true);
|
|
10480
10620
|
}
|
|
10621
|
+
_isClosed() {
|
|
10622
|
+
return true;
|
|
10623
|
+
}
|
|
10481
10624
|
_containsPoint(p) {
|
|
10482
|
-
let inside = false
|
|
10483
|
-
if (!this._pxBounds
|
|
10484
|
-
for (
|
|
10485
|
-
part =
|
|
10486
|
-
|
|
10487
|
-
p1 = part[j];
|
|
10488
|
-
p2 = part[k];
|
|
10489
|
-
if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) inside = !inside;
|
|
10490
|
-
}
|
|
10625
|
+
let inside = false;
|
|
10626
|
+
if (!this._pxBounds?.contains(p)) return false;
|
|
10627
|
+
for (const part of this._parts) for (let j = 0, len = part.length, k = len - 1; j < len; k = j++) {
|
|
10628
|
+
const p1 = part[j], p2 = part[k];
|
|
10629
|
+
if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) inside = !inside;
|
|
10491
10630
|
}
|
|
10492
10631
|
return inside || super._containsPoint(p, true);
|
|
10493
10632
|
}
|
|
@@ -10730,16 +10869,15 @@ var ScaleControl = class ScaleControl extends Control {
|
|
|
10730
10869
|
onAdd(map) {
|
|
10731
10870
|
const className = "maplair-control-scale", container = create("div", className), options = this.options;
|
|
10732
10871
|
this._addScales(options, `${className}-line`, container);
|
|
10733
|
-
map.on(options.updateWhenIdle ? "moveend" : "move", this._update, this);
|
|
10734
10872
|
map.whenReady(this._update, this);
|
|
10735
10873
|
return container;
|
|
10736
10874
|
}
|
|
10737
10875
|
/**
|
|
10738
10876
|
* @internal
|
|
10739
|
-
* @
|
|
10877
|
+
* @returns {Record<string, Function>}
|
|
10740
10878
|
*/
|
|
10741
|
-
|
|
10742
|
-
|
|
10879
|
+
getEvents() {
|
|
10880
|
+
return { [this.options.updateWhenIdle ? "moveend" : "move"]: this._update };
|
|
10743
10881
|
}
|
|
10744
10882
|
_addScales(options, className, container) {
|
|
10745
10883
|
if (options.metric) this._mScale = create("div", className, container);
|
|
@@ -10772,13 +10910,13 @@ var ScaleControl = class ScaleControl extends Control {
|
|
|
10772
10910
|
}
|
|
10773
10911
|
_updateScale(scale, text, ratio) {
|
|
10774
10912
|
scale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;
|
|
10775
|
-
scale.
|
|
10913
|
+
scale.textContent = text;
|
|
10776
10914
|
}
|
|
10777
10915
|
_getRoundNum(num) {
|
|
10778
|
-
const
|
|
10779
|
-
let d = num /
|
|
10916
|
+
const exponent = num < 1 ? Math.floor(Math.log10(num)) : `${Math.floor(num)}`.length - 1;
|
|
10917
|
+
let d = num / 10 ** exponent;
|
|
10780
10918
|
d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
|
|
10781
|
-
return
|
|
10919
|
+
return exponent < 0 ? d / 10 ** -exponent : d * 10 ** exponent;
|
|
10782
10920
|
}
|
|
10783
10921
|
};
|
|
10784
10922
|
// src/layer/marker/Icon.js
|
|
@@ -10798,8 +10936,11 @@ var ScaleControl = class ScaleControl extends Control {
|
|
|
10798
10936
|
* can be set in CSS with negative margins.
|
|
10799
10937
|
* @property {PointExpression} [popupAnchor=[0, 0]] The coordinates of the point from
|
|
10800
10938
|
* which popups will "open", relative to the icon anchor.
|
|
10801
|
-
* @property {PointExpression} [tooltipAnchor=[0, 0]]
|
|
10802
|
-
*
|
|
10939
|
+
* @property {PointExpression} [tooltipAnchor=[0, 0]] Where tooltips opening to the side
|
|
10940
|
+
* attach, relative to the icon anchor: `x` is how far to the right (mirrored for tooltips
|
|
10941
|
+
* opening to the left) and `y` how far down. Tooltips opening to the top or bottom attach
|
|
10942
|
+
* to the middle of the icon's top or bottom edge, and `center` ones to the middle of the
|
|
10943
|
+
* icon at the `y` height.
|
|
10803
10944
|
* @property {string} [shadowUrl] The URL to the icon shadow image. If not specified, no
|
|
10804
10945
|
* shadow image will be created.
|
|
10805
10946
|
* @property {string} [shadowRetinaUrl] The URL to a retina sized version of the shadow
|
|
@@ -10879,25 +11020,42 @@ var Icon = class Icon extends Class {
|
|
|
10879
11020
|
const img = this._createImg(src, oldIcon instanceof HTMLImageElement ? oldIcon : null);
|
|
10880
11021
|
this._setIconStyles(img, name);
|
|
10881
11022
|
if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
|
|
11023
|
+
else img.crossOrigin = null;
|
|
10882
11024
|
return img;
|
|
10883
11025
|
}
|
|
11026
|
+
_getBox(name) {
|
|
11027
|
+
const options = this.options;
|
|
11028
|
+
const sizeOption = options[`${name}Size`];
|
|
11029
|
+
const [width, height] = (typeof sizeOption === "number" ? [sizeOption, sizeOption] : Array.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);
|
|
11030
|
+
const anchorOption = name === "shadow" && options.shadowAnchor || options.iconAnchor;
|
|
11031
|
+
return {
|
|
11032
|
+
width,
|
|
11033
|
+
height,
|
|
11034
|
+
anchor: Point.validate(anchorOption) ? Point.from(anchorOption) : {
|
|
11035
|
+
x: Math.round(width / 2),
|
|
11036
|
+
y: Math.round(height / 2)
|
|
11037
|
+
}
|
|
11038
|
+
};
|
|
11039
|
+
}
|
|
11040
|
+
_getTooltipAnchor(direction) {
|
|
11041
|
+
const { x, y } = Point.from(this.options.tooltipAnchor);
|
|
11042
|
+
if (direction === "left") return new Point(-x, y);
|
|
11043
|
+
if (direction === "center") return new Point(0, y);
|
|
11044
|
+
if (direction !== "top" && direction !== "bottom") return new Point(x, y);
|
|
11045
|
+
const { height, anchor } = this._getBox("icon");
|
|
11046
|
+
return new Point(0, (direction === "top" ? -anchor.y : height - anchor.y) || 0);
|
|
11047
|
+
}
|
|
10884
11048
|
_setIconStyles(img, name) {
|
|
10885
11049
|
const options = this.options;
|
|
10886
|
-
|
|
10887
|
-
if (typeof sizeOption === "number") sizeOption = [sizeOption, sizeOption];
|
|
10888
|
-
const size = Point.validate(sizeOption) && Point.from(sizeOption);
|
|
10889
|
-
const anchorPosition = name === "shadow" && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
|
|
10890
|
-
const anchor = Point.validate(anchorPosition) && Point.from(anchorPosition);
|
|
11050
|
+
const { width, height, anchor } = this._getBox(name);
|
|
10891
11051
|
img.className = `maplair-marker-${name} ${options.className || ""}`;
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
}
|
|
10896
|
-
|
|
10897
|
-
if (
|
|
10898
|
-
|
|
10899
|
-
img.style.height = `${size.y}px`;
|
|
10900
|
-
}
|
|
11052
|
+
const { style } = img;
|
|
11053
|
+
style.marginLeft = style.marginTop = style.width = style.height = "";
|
|
11054
|
+
if (!isNaN(anchor.x)) style.marginLeft = `${-anchor.x}px`;
|
|
11055
|
+
if (!isNaN(anchor.y)) style.marginTop = `${-anchor.y}px`;
|
|
11056
|
+
style.transformOrigin = !isNaN(anchor.x) && !isNaN(anchor.y) ? `${anchor.x}px ${anchor.y}px` : "0 0";
|
|
11057
|
+
if (!isNaN(width)) style.width = `${width}px`;
|
|
11058
|
+
if (!isNaN(height)) style.height = `${height}px`;
|
|
10901
11059
|
}
|
|
10902
11060
|
_createImg(src, el) {
|
|
10903
11061
|
el ??= document.createElement("img");
|
|
@@ -10990,8 +11148,8 @@ const arrows = {
|
|
|
10990
11148
|
* The handler of `Marker` which makes the markers draggable, see the
|
|
10991
11149
|
* [`dragging`](#marker-dragging) property of markers and its `draggable` option.
|
|
10992
11150
|
*
|
|
10993
|
-
* @fires Marker#dragstart {
|
|
10994
|
-
* @fires Marker#movestart {
|
|
11151
|
+
* @fires Marker#dragstart {DraggableEvent} Fired when the user starts dragging the marker.
|
|
11152
|
+
* @fires Marker#movestart {DraggableEvent} Fired when the marker starts moving (because of
|
|
10995
11153
|
* dragging).
|
|
10996
11154
|
* @fires Marker#drag {MarkerMoveEvent} Fired repeatedly while the user drags the marker.
|
|
10997
11155
|
* @fires Marker#dragend {DragEndEvent} Fired when the user stops dragging the marker.
|
|
@@ -11045,10 +11203,10 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
11045
11203
|
return this._draggable?._moved;
|
|
11046
11204
|
}
|
|
11047
11205
|
_adjustPan(e) {
|
|
11048
|
-
const marker = this._marker, map = marker._map, speed = this._marker.options.autoPanSpeed, padding = this._marker.options.autoPanPadding, iconPos = getPosition(marker._icon), bounds = map.getPixelBounds(), origin = map.getPixelOrigin();
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11206
|
+
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);
|
|
11207
|
+
if (dx || dy) {
|
|
11208
|
+
const movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed), map.options.maxBounds)._round();
|
|
11209
|
+
if (!movement.x && !movement.y) return;
|
|
11052
11210
|
map.panBy(movement, { animate: false });
|
|
11053
11211
|
this._draggable._newPos._add(movement);
|
|
11054
11212
|
this._draggable._startPos._add(movement);
|
|
@@ -11057,10 +11215,10 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
11057
11215
|
this._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));
|
|
11058
11216
|
}
|
|
11059
11217
|
}
|
|
11060
|
-
_onDragStart() {
|
|
11218
|
+
_onDragStart({ originalEvent }) {
|
|
11061
11219
|
this._oldLatLng = this._marker.getLatLng();
|
|
11062
11220
|
this._marker.closePopup?.();
|
|
11063
|
-
this._marker.fire("movestart").fire("dragstart");
|
|
11221
|
+
this._marker.fire("movestart", { originalEvent }).fire("dragstart", { originalEvent });
|
|
11064
11222
|
}
|
|
11065
11223
|
_onPreDrag(e) {
|
|
11066
11224
|
if (this._marker.options.autoPan) {
|
|
@@ -11069,7 +11227,8 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
11069
11227
|
}
|
|
11070
11228
|
}
|
|
11071
11229
|
_onDrag(e) {
|
|
11072
|
-
const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos);
|
|
11230
|
+
const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos), { alt } = this._oldLatLng;
|
|
11231
|
+
if (alt !== void 0) latlng.alt = alt;
|
|
11073
11232
|
marker._positionElements(iconPos);
|
|
11074
11233
|
marker._latlng = latlng;
|
|
11075
11234
|
e.latlng = latlng;
|
|
@@ -11078,7 +11237,6 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
11078
11237
|
}
|
|
11079
11238
|
_onDragEnd(e) {
|
|
11080
11239
|
cancelAnimationFrame(this._panRequest);
|
|
11081
|
-
delete this._oldLatLng;
|
|
11082
11240
|
this._marker.fire("moveend").fire("dragend", e);
|
|
11083
11241
|
}
|
|
11084
11242
|
/** @param {KeyboardEvent|FocusEvent} e */
|
|
@@ -11097,7 +11255,7 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
11097
11255
|
draggable._startPos = getPosition(draggable._element);
|
|
11098
11256
|
draggable._moved = draggable._moving = true;
|
|
11099
11257
|
this._keyOffset = new Point(0, 0);
|
|
11100
|
-
draggable.fire("dragstart");
|
|
11258
|
+
draggable.fire("dragstart", { originalEvent: k });
|
|
11101
11259
|
}
|
|
11102
11260
|
const offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);
|
|
11103
11261
|
this._keyOffset = this._keyOffset.add(map._rotateToPane?.(offset) ?? offset);
|
|
@@ -11130,7 +11288,8 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
11130
11288
|
* @property {string} [title=''] Text for the browser tooltip that appear on marker hover
|
|
11131
11289
|
* (no tooltip by default).
|
|
11132
11290
|
* [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
11133
|
-
* @property {string} [alt
|
|
11291
|
+
* @property {string} [alt] Text for the `alt` attribute of the icon image, the
|
|
11292
|
+
* translation of `'Marker'` by default.
|
|
11134
11293
|
* [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
11135
11294
|
* @property {number} [zIndexOffset=0] By default, marker images zIndex is set
|
|
11136
11295
|
* automatically based on its latitude. Use this option if you want to put the marker on
|
|
@@ -11142,9 +11301,9 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
11142
11301
|
* marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
|
|
11143
11302
|
* under a tilted one. `null` means no rotation.
|
|
11144
11303
|
* @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
|
|
11145
|
-
* others
|
|
11146
|
-
* @property {number} [riseOffset=250] The z-index offset used
|
|
11147
|
-
*
|
|
11304
|
+
* others while the pointer is over it. It always does while it has focus.
|
|
11305
|
+
* @property {number} [riseOffset=250] The z-index offset used when the marker gets on
|
|
11306
|
+
* top of others on hover or focus.
|
|
11148
11307
|
* @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.
|
|
11149
11308
|
* @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will
|
|
11150
11309
|
* be added.
|
|
@@ -11197,7 +11356,7 @@ var Marker = class Marker extends Layer {
|
|
|
11197
11356
|
interactive: true,
|
|
11198
11357
|
keyboard: true,
|
|
11199
11358
|
title: "",
|
|
11200
|
-
alt:
|
|
11359
|
+
alt: void 0,
|
|
11201
11360
|
zIndexOffset: 0,
|
|
11202
11361
|
opacity: 1,
|
|
11203
11362
|
rotation: null,
|
|
@@ -11328,7 +11487,7 @@ var Marker = class Marker extends Layer {
|
|
|
11328
11487
|
*/
|
|
11329
11488
|
update() {
|
|
11330
11489
|
if (this._icon && this._map && !this._culled) {
|
|
11331
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
11490
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
|
|
11332
11491
|
this._setPos(pos);
|
|
11333
11492
|
}
|
|
11334
11493
|
return this;
|
|
@@ -11341,7 +11500,7 @@ var Marker = class Marker extends Layer {
|
|
|
11341
11500
|
if (this._icon) this._removeIcon();
|
|
11342
11501
|
addIcon = true;
|
|
11343
11502
|
if (options.title) icon.title = options.title;
|
|
11344
|
-
if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? "";
|
|
11503
|
+
if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? I18n.translate("Marker");
|
|
11345
11504
|
}
|
|
11346
11505
|
icon.classList.add(classToAdd);
|
|
11347
11506
|
if (options.keyboard) {
|
|
@@ -11350,10 +11509,9 @@ var Marker = class Marker extends Layer {
|
|
|
11350
11509
|
on(icon, "keydown", this._onKeyDown, this);
|
|
11351
11510
|
}
|
|
11352
11511
|
this._icon = icon;
|
|
11353
|
-
if (
|
|
11354
|
-
|
|
11355
|
-
|
|
11356
|
-
});
|
|
11512
|
+
if (this._popup?._source === this) this._popup._updateSourceAria(this._popup.isOpen());
|
|
11513
|
+
on(icon, "focusin focusout", this._updateRise, this);
|
|
11514
|
+
if (options.riseOnHover) on(icon, "pointerover pointerout", this._updateRise, this);
|
|
11357
11515
|
if (this.options.autoPanOnFocus) on(icon, "focus", this._panOnFocus, this);
|
|
11358
11516
|
const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
|
|
11359
11517
|
let addShadow = false;
|
|
@@ -11367,15 +11525,13 @@ var Marker = class Marker extends Layer {
|
|
|
11367
11525
|
}
|
|
11368
11526
|
this._shadow = newShadow;
|
|
11369
11527
|
if (options.opacity < 1) this._updateOpacity();
|
|
11370
|
-
if (addIcon) this.getPane().
|
|
11528
|
+
if (addIcon) this.getPane().append(this._icon);
|
|
11371
11529
|
this._initInteraction();
|
|
11372
|
-
if (newShadow && addShadow) this.getPane(options.shadowPane).
|
|
11530
|
+
if (newShadow && addShadow) this.getPane(options.shadowPane).append(this._shadow);
|
|
11373
11531
|
}
|
|
11374
11532
|
_removeIcon() {
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
pointerout: this._resetZIndex
|
|
11378
|
-
});
|
|
11533
|
+
off(this._icon, "pointerover pointerout focusin focusout", this._updateRise, this);
|
|
11534
|
+
this._hovered = this._focused = false;
|
|
11379
11535
|
if (this.options.autoPanOnFocus) off(this._icon, "focus", this._panOnFocus, this);
|
|
11380
11536
|
off(this._icon, "keydown", this._onKeyDown, this);
|
|
11381
11537
|
this._icon.remove();
|
|
@@ -11388,8 +11544,8 @@ var Marker = class Marker extends Layer {
|
|
|
11388
11544
|
if (visible === !this._culled) return;
|
|
11389
11545
|
this._culled = !visible;
|
|
11390
11546
|
if (visible) {
|
|
11391
|
-
this.getPane().
|
|
11392
|
-
if (this._shadow) this.getPane(this.options.shadowPane).
|
|
11547
|
+
this.getPane().append(this._icon);
|
|
11548
|
+
if (this._shadow) this.getPane(this.options.shadowPane).append(this._shadow);
|
|
11393
11549
|
this.update();
|
|
11394
11550
|
} else {
|
|
11395
11551
|
this._icon.remove();
|
|
@@ -11402,8 +11558,8 @@ var Marker = class Marker extends Layer {
|
|
|
11402
11558
|
}
|
|
11403
11559
|
_setPos(pos) {
|
|
11404
11560
|
this._positionElements(pos);
|
|
11405
|
-
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
11406
|
-
this.
|
|
11561
|
+
this._zIndex = Math.round(pos.y) + this.options.zIndexOffset;
|
|
11562
|
+
this._updateRise();
|
|
11407
11563
|
}
|
|
11408
11564
|
_positionElements(pos) {
|
|
11409
11565
|
const rotation = this.options.rotation;
|
|
@@ -11422,7 +11578,7 @@ var Marker = class Marker extends Layer {
|
|
|
11422
11578
|
}
|
|
11423
11579
|
_animateZoom(opt) {
|
|
11424
11580
|
if (this._culled) return;
|
|
11425
|
-
const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center)
|
|
11581
|
+
const pos = this._map._snapLayerPoint(this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center));
|
|
11426
11582
|
this._setPos(pos);
|
|
11427
11583
|
}
|
|
11428
11584
|
_updateInteractive() {
|
|
@@ -11445,33 +11601,31 @@ var Marker = class Marker extends Layer {
|
|
|
11445
11601
|
if (!this.options.interactive) return;
|
|
11446
11602
|
this._icon.classList.add("maplair-interactive");
|
|
11447
11603
|
this.addInteractiveTarget(this._icon);
|
|
11448
|
-
if (
|
|
11449
|
-
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
11454
|
-
|
|
11455
|
-
|
|
11456
|
-
this.dragging.disable();
|
|
11457
|
-
}
|
|
11458
|
-
/**
|
|
11459
|
-
* Marker dragging handler, see `Handler`. Only valid when the marker is on the
|
|
11460
|
-
* map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
|
|
11461
|
-
*
|
|
11462
|
-
* Interaction handlers are properties of a marker instance that allow you to
|
|
11463
|
-
* control interaction behavior in runtime, enabling or disabling certain
|
|
11464
|
-
* features such as dragging (see `Handler` methods). Example:
|
|
11465
|
-
*
|
|
11466
|
-
* ```js
|
|
11467
|
-
* marker.dragging.disable();
|
|
11468
|
-
* ```
|
|
11469
|
-
* @group Interaction handlers
|
|
11470
|
-
* @type {MarkerDrag}
|
|
11471
|
-
*/
|
|
11472
|
-
this.dragging = new MarkerDrag(this);
|
|
11473
|
-
if (draggable) this.dragging.enable();
|
|
11604
|
+
if (this.dragging?._draggable?._element === this._icon) {
|
|
11605
|
+
this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
|
|
11606
|
+
return;
|
|
11607
|
+
}
|
|
11608
|
+
let draggable = this.options.draggable;
|
|
11609
|
+
if (this.dragging) {
|
|
11610
|
+
draggable = this.dragging.enabled();
|
|
11611
|
+
this.dragging.disable();
|
|
11474
11612
|
}
|
|
11613
|
+
/**
|
|
11614
|
+
* Marker dragging handler, see `Handler`. Only valid when the marker is on the
|
|
11615
|
+
* map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
|
|
11616
|
+
*
|
|
11617
|
+
* Interaction handlers are properties of a marker instance that allow you to
|
|
11618
|
+
* control interaction behavior in runtime, enabling or disabling certain
|
|
11619
|
+
* features such as dragging (see `Handler` methods). Example:
|
|
11620
|
+
*
|
|
11621
|
+
* ```js
|
|
11622
|
+
* marker.dragging.disable();
|
|
11623
|
+
* ```
|
|
11624
|
+
* @group Interaction handlers
|
|
11625
|
+
* @type {MarkerDrag}
|
|
11626
|
+
*/
|
|
11627
|
+
this.dragging = new MarkerDrag(this);
|
|
11628
|
+
if (draggable) this.dragging.enable();
|
|
11475
11629
|
}
|
|
11476
11630
|
/**
|
|
11477
11631
|
* Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
|
|
@@ -11505,9 +11659,13 @@ var Marker = class Marker extends Layer {
|
|
|
11505
11659
|
return this;
|
|
11506
11660
|
}
|
|
11507
11661
|
_updateOpacity() {
|
|
11508
|
-
const opacity = this.options.opacity
|
|
11509
|
-
|
|
11510
|
-
|
|
11662
|
+
for (const el of [this._icon, this._shadow]) if (el) el.style.opacity = `${this.options.opacity}`;
|
|
11663
|
+
}
|
|
11664
|
+
_updateRise(e) {
|
|
11665
|
+
if (e?.type.startsWith("pointer")) this._hovered = e.type === "pointerover";
|
|
11666
|
+
else if (e) this._focused = e.type === "focusin";
|
|
11667
|
+
if (this._hovered || this._focused) this._bringToFront();
|
|
11668
|
+
else this._resetZIndex();
|
|
11511
11669
|
}
|
|
11512
11670
|
_bringToFront() {
|
|
11513
11671
|
this._updateZIndex(this.options.riseOffset);
|
|
@@ -11535,8 +11693,8 @@ var Marker = class Marker extends Layer {
|
|
|
11535
11693
|
_getPopupAnchor() {
|
|
11536
11694
|
return this._rotateAnchor(this.options.icon.options.popupAnchor);
|
|
11537
11695
|
}
|
|
11538
|
-
_getTooltipAnchor() {
|
|
11539
|
-
return this._rotateAnchor(this.options.icon.
|
|
11696
|
+
_getTooltipAnchor(direction) {
|
|
11697
|
+
return this._rotateAnchor(this.options.icon._getTooltipAnchor(direction));
|
|
11540
11698
|
}
|
|
11541
11699
|
_rotateAnchor(anchor) {
|
|
11542
11700
|
const angle = this.options.rotation * Math.PI / 180;
|
|
@@ -12131,8 +12289,9 @@ var SideBySideControl = class SideBySideControl extends Control {
|
|
|
12131
12289
|
this.remove();
|
|
12132
12290
|
this._map = map;
|
|
12133
12291
|
this._container = this.onAdd(map);
|
|
12134
|
-
map._container.
|
|
12135
|
-
|
|
12292
|
+
map._container.append(this._container);
|
|
12293
|
+
this._mapEvents = { unload: this.remove };
|
|
12294
|
+
map.on(this._mapEvents, this);
|
|
12136
12295
|
return this;
|
|
12137
12296
|
}
|
|
12138
12297
|
/**
|
|
@@ -13667,6 +13826,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
13667
13826
|
onAdd() {
|
|
13668
13827
|
if (!this._image) {
|
|
13669
13828
|
this._initImage();
|
|
13829
|
+
this._updateZIndex();
|
|
13670
13830
|
if (this.options.opacity < 1) this._updateOpacity();
|
|
13671
13831
|
}
|
|
13672
13832
|
if (this.options.interactive) {
|
|
@@ -13674,7 +13834,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
13674
13834
|
this.addInteractiveTarget(this._image);
|
|
13675
13835
|
}
|
|
13676
13836
|
this._image.classList.toggle("maplair-pixelated", !!this.options.pixelated);
|
|
13677
|
-
this.getPane().
|
|
13837
|
+
this.getPane().append(this._image);
|
|
13678
13838
|
this._reset();
|
|
13679
13839
|
}
|
|
13680
13840
|
/**
|
|
@@ -13707,7 +13867,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
13707
13867
|
* @returns {this}
|
|
13708
13868
|
*/
|
|
13709
13869
|
setStyle(styleOpts) {
|
|
13710
|
-
if (styleOpts.opacity) this.setOpacity(styleOpts.opacity);
|
|
13870
|
+
if (styleOpts.opacity != null) this.setOpacity(styleOpts.opacity);
|
|
13711
13871
|
return this;
|
|
13712
13872
|
}
|
|
13713
13873
|
/**
|
|
@@ -13793,7 +13953,6 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
13793
13953
|
img.onerror = this._overlayOnError.bind(this);
|
|
13794
13954
|
if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
|
|
13795
13955
|
img.decoding = this.options.decoding;
|
|
13796
|
-
if (this.options.zIndex) this._updateZIndex();
|
|
13797
13956
|
if (wasElementSupplied) {
|
|
13798
13957
|
this._url = img.src;
|
|
13799
13958
|
return;
|
|
@@ -13806,7 +13965,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
13806
13965
|
setTransform(this._image, offset, scale);
|
|
13807
13966
|
}
|
|
13808
13967
|
_reset() {
|
|
13809
|
-
const image = this._image, bounds = new Bounds(
|
|
13968
|
+
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();
|
|
13810
13969
|
setPosition(image, bounds.min);
|
|
13811
13970
|
image.style.width = `${size.x}px`;
|
|
13812
13971
|
image.style.height = `${size.y}px`;
|
|
@@ -13815,7 +13974,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
13815
13974
|
this._image.style.opacity = `${this.options.opacity}`;
|
|
13816
13975
|
}
|
|
13817
13976
|
_updateZIndex() {
|
|
13818
|
-
if (this._image && this.options.zIndex
|
|
13977
|
+
if (this._image && this.options.zIndex != null) this._image.style.zIndex = `${this.options.zIndex}`;
|
|
13819
13978
|
}
|
|
13820
13979
|
_overlayOnError() {
|
|
13821
13980
|
this.fire("error");
|
|
@@ -13832,6 +13991,9 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
13832
13991
|
getCenter() {
|
|
13833
13992
|
return this._bounds.getCenter();
|
|
13834
13993
|
}
|
|
13994
|
+
_togglesPopupOnClick() {
|
|
13995
|
+
return false;
|
|
13996
|
+
}
|
|
13835
13997
|
};
|
|
13836
13998
|
// src/layer/VideoOverlay.js
|
|
13837
13999
|
/** @import {ImageOverlayOptions} from './ImageOverlay.js' */
|
|
@@ -13912,7 +14074,7 @@ var VideoOverlay = class VideoOverlay extends ImageOverlay {
|
|
|
13912
14074
|
return;
|
|
13913
14075
|
}
|
|
13914
14076
|
if (!Array.isArray(this._url)) this._url = [this._url];
|
|
13915
|
-
if (!this.options.keepAspectRatio) vid.style
|
|
14077
|
+
if (!this.options.keepAspectRatio) vid.style.objectFit = "fill";
|
|
13916
14078
|
vid.autoplay = !!this.options.autoplay;
|
|
13917
14079
|
vid.controls = !!this.options.controls;
|
|
13918
14080
|
vid.loop = !!this.options.loop;
|
|
@@ -13921,7 +14083,7 @@ var VideoOverlay = class VideoOverlay extends ImageOverlay {
|
|
|
13921
14083
|
for (const url of this._url) {
|
|
13922
14084
|
const source = create("source");
|
|
13923
14085
|
source.src = url;
|
|
13924
|
-
vid.
|
|
14086
|
+
vid.append(source);
|
|
13925
14087
|
}
|
|
13926
14088
|
}
|
|
13927
14089
|
};
|
|
@@ -14024,14 +14186,10 @@ var DivIcon = class DivIcon extends Icon {
|
|
|
14024
14186
|
*/
|
|
14025
14187
|
createIcon(oldIcon) {
|
|
14026
14188
|
const div = oldIcon instanceof HTMLDivElement ? oldIcon : document.createElement("div"), options = this.options;
|
|
14027
|
-
if (options.html instanceof Element)
|
|
14028
|
-
|
|
14029
|
-
|
|
14030
|
-
|
|
14031
|
-
if (options.bgPos) {
|
|
14032
|
-
const bgPos = Point.from(options.bgPos);
|
|
14033
|
-
div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
|
|
14034
|
-
}
|
|
14189
|
+
if (options.html instanceof Element) div.replaceChildren(options.html);
|
|
14190
|
+
else div.innerHTML = options.html !== false ? options.html : "";
|
|
14191
|
+
const bgPos = options.bgPos && Point.from(options.bgPos);
|
|
14192
|
+
div.style.backgroundPosition = bgPos ? `${-bgPos.x}px ${-bgPos.y}px` : "";
|
|
14035
14193
|
this._setIconStyles(div, "icon");
|
|
14036
14194
|
return div;
|
|
14037
14195
|
}
|
|
@@ -14056,7 +14214,7 @@ const glyphSize = 230;
|
|
|
14056
14214
|
function svgElement(name, attributes, parent) {
|
|
14057
14215
|
const el = document.createElementNS(svgNS, name);
|
|
14058
14216
|
for (const [key, value] of Object.entries(attributes)) el.setAttribute(key, value);
|
|
14059
|
-
parent?.
|
|
14217
|
+
parent?.append(el);
|
|
14060
14218
|
return el;
|
|
14061
14219
|
}
|
|
14062
14220
|
/**
|
|
@@ -14501,10 +14659,10 @@ var MarkerClusterGroup = class MarkerClusterGroup extends FeatureGroup {
|
|
|
14501
14659
|
* @typedef {(error: any, tile: HTMLElement) => void} TileDoneCallback
|
|
14502
14660
|
*/
|
|
14503
14661
|
/**
|
|
14504
|
-
* Generic class for handling a tiled grid of HTML elements
|
|
14505
|
-
*
|
|
14506
|
-
* a tiled grid of
|
|
14507
|
-
*
|
|
14662
|
+
* Generic class for handling a tiled grid of HTML elements, and the base class of all
|
|
14663
|
+
* tile layers. To show map tiles from a URL, use `TileLayer` (or `WMSTileLayer`).
|
|
14664
|
+
* Extend `GridLayer` to create a tiled grid of your own elements like `<canvas>`,
|
|
14665
|
+
* `<img>` or `<div>`; it handles creating and animating them for you.
|
|
14508
14666
|
*
|
|
14509
14667
|
* Layers extending `GridLayer` shall reimplement the [`createTile()`](#gridlayer-createtile)
|
|
14510
14668
|
* method.
|
|
@@ -14700,7 +14858,7 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14700
14858
|
redraw() {
|
|
14701
14859
|
if (this._map) {
|
|
14702
14860
|
this._removeAllTiles();
|
|
14703
|
-
const tileZoom = this.
|
|
14861
|
+
const tileZoom = this._getTileZoom(this._map.getZoom());
|
|
14704
14862
|
if (tileZoom !== this._tileZoom) {
|
|
14705
14863
|
this._tileZoom = tileZoom;
|
|
14706
14864
|
this._updateLevels();
|
|
@@ -14751,7 +14909,7 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14751
14909
|
return s instanceof Point ? s : new Point(s, s);
|
|
14752
14910
|
}
|
|
14753
14911
|
_updateZIndex() {
|
|
14754
|
-
if (this._container && this.options.zIndex
|
|
14912
|
+
if (this._container && this.options.zIndex != null) this._container.style.zIndex = `${this.options.zIndex}`;
|
|
14755
14913
|
}
|
|
14756
14914
|
_setAutoZIndex(compare) {
|
|
14757
14915
|
const layers = this.getPane().children;
|
|
@@ -14772,11 +14930,11 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14772
14930
|
_onOpaqueTile() {}
|
|
14773
14931
|
_initContainer() {
|
|
14774
14932
|
if (this._container) return;
|
|
14775
|
-
this._container = create("div", `maplair-layer ${this.options.className ?? ""}`);
|
|
14933
|
+
this._container = create("div", `maplair-layer maplair-zoom-animated ${this.options.className ?? ""}`);
|
|
14776
14934
|
this._container.classList.toggle("maplair-pixelated", !!this.options.pixelated);
|
|
14777
14935
|
this._updateZIndex();
|
|
14778
14936
|
if (this.options.opacity < 1) this._updateOpacity();
|
|
14779
|
-
this.getPane().
|
|
14937
|
+
this.getPane().append(this._container);
|
|
14780
14938
|
}
|
|
14781
14939
|
_keepCurrentTiles() {
|
|
14782
14940
|
const zoom = this._tileZoom, level = this._levels?.[zoom];
|
|
@@ -14839,7 +14997,6 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14839
14997
|
level.origin = map.project(map.unproject(map.getPixelOrigin()), zoom).round();
|
|
14840
14998
|
level.zoom = zoom;
|
|
14841
14999
|
this._setZoomTransform(level, map.getCenter(), map.getZoom());
|
|
14842
|
-
level.el.offsetWidth;
|
|
14843
15000
|
this._onCreateLevel(level);
|
|
14844
15001
|
}
|
|
14845
15002
|
this._level = level;
|
|
@@ -14850,8 +15007,7 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14850
15007
|
_onCreateLevel() {}
|
|
14851
15008
|
_pruneTiles() {
|
|
14852
15009
|
if (!this._map) return;
|
|
14853
|
-
|
|
14854
|
-
if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
|
|
15010
|
+
if (this._getTileZoom(this._map.getZoom()) === void 0) {
|
|
14855
15011
|
this._removeAllTiles();
|
|
14856
15012
|
return;
|
|
14857
15013
|
}
|
|
@@ -14904,7 +15060,15 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14904
15060
|
this._setView(this._map.getCenter(), this._map.getZoom(), animating, animating);
|
|
14905
15061
|
}
|
|
14906
15062
|
_animateZoom(e) {
|
|
15063
|
+
const map = this._map, center = map.getCenter(), zoom = map.getZoom(), scale = map.getZoomScale(e.zoom, zoom);
|
|
14907
15064
|
this._setView(e.center, e.zoom, true, e.noUpdate);
|
|
15065
|
+
this._setZoomTransforms(center, zoom);
|
|
15066
|
+
setTransform(this._container, map._getNewPixelOrigin(center, zoom).multiplyBy(scale).subtract(map._getNewPixelOrigin(e.center, e.zoom)), scale);
|
|
15067
|
+
}
|
|
15068
|
+
_getTileZoom(zoom) {
|
|
15069
|
+
const { minZoom, maxZoom = Infinity } = this.options;
|
|
15070
|
+
if (zoom < minZoom || zoom > maxZoom) return;
|
|
15071
|
+
return this._clampZoom(Math.round(zoom));
|
|
14908
15072
|
}
|
|
14909
15073
|
_clampZoom(zoom) {
|
|
14910
15074
|
const options = this.options;
|
|
@@ -14913,13 +15077,11 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14913
15077
|
return zoom;
|
|
14914
15078
|
}
|
|
14915
15079
|
_setView(center, zoom, noPrune, noUpdate) {
|
|
14916
|
-
|
|
14917
|
-
if (this.options.maxZoom !== void 0 && tileZoom > this.options.maxZoom || this.options.minZoom !== void 0 && tileZoom < this.options.minZoom) tileZoom = void 0;
|
|
14918
|
-
else tileZoom = this._clampZoom(tileZoom);
|
|
15080
|
+
const tileZoom = this._getTileZoom(zoom);
|
|
14919
15081
|
const tileZoomChanged = this.options.updateWhenZooming && tileZoom !== this._tileZoom;
|
|
14920
15082
|
if (!noUpdate || tileZoomChanged) {
|
|
14921
15083
|
this._tileZoom = tileZoom;
|
|
14922
|
-
|
|
15084
|
+
this._abortLoading?.();
|
|
14923
15085
|
this._updateLevels();
|
|
14924
15086
|
this._resetGrid();
|
|
14925
15087
|
if (tileZoom !== void 0) this._update(center);
|
|
@@ -14929,10 +15091,12 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14929
15091
|
this._setZoomTransforms(center, zoom);
|
|
14930
15092
|
}
|
|
14931
15093
|
_setZoomTransforms(center, zoom) {
|
|
15094
|
+
if (this._container.style.transform) this._container.style.transform = "";
|
|
14932
15095
|
for (const level of Object.values(this._levels)) this._setZoomTransform(level, center, zoom);
|
|
14933
15096
|
}
|
|
14934
15097
|
_setZoomTransform(level, center, zoom) {
|
|
14935
|
-
const scale = this._map.getZoomScale(zoom, level.zoom), translate = level.origin.multiplyBy(scale).subtract(this._map._getNewPixelOrigin(center, zoom))
|
|
15098
|
+
const scale = this._map.getZoomScale(zoom, level.zoom), translate = level.origin.multiplyBy(scale).subtract(this._map._getNewPixelOrigin(center, zoom));
|
|
15099
|
+
if (scale === 1) this._map._snapLayerPoint(translate);
|
|
14936
15100
|
setTransform(level.el, translate, scale);
|
|
14937
15101
|
}
|
|
14938
15102
|
_resetGrid() {
|
|
@@ -14943,7 +15107,9 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14943
15107
|
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)];
|
|
14944
15108
|
}
|
|
14945
15109
|
_onMoveEnd() {
|
|
14946
|
-
|
|
15110
|
+
const map = this._map;
|
|
15111
|
+
if (!map || map._animatingZoom) return;
|
|
15112
|
+
if (this._container.style.transform) this._setZoomTransforms(map.getCenter(), map.getZoom());
|
|
14947
15113
|
this._update();
|
|
14948
15114
|
}
|
|
14949
15115
|
_onWorldCopyJump({ worlds }) {
|
|
@@ -14988,7 +15154,7 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14988
15154
|
else queue.push(coords);
|
|
14989
15155
|
}
|
|
14990
15156
|
queue.sort((a, b) => a.distanceTo(tileCenter) - b.distanceTo(tileCenter));
|
|
14991
|
-
if (queue.length
|
|
15157
|
+
if (queue.length) {
|
|
14992
15158
|
if (!this._loading) {
|
|
14993
15159
|
this._loading = true;
|
|
14994
15160
|
this.fire("loading");
|
|
@@ -14996,7 +15162,7 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
14996
15162
|
}
|
|
14997
15163
|
const fragment = document.createDocumentFragment();
|
|
14998
15164
|
for (const q of queue) this._addTile(q, fragment);
|
|
14999
|
-
this._level.el.
|
|
15165
|
+
this._level.el.append(fragment);
|
|
15000
15166
|
}
|
|
15001
15167
|
}
|
|
15002
15168
|
_isValidTile(coords) {
|
|
@@ -15050,7 +15216,7 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
15050
15216
|
coords,
|
|
15051
15217
|
current: true
|
|
15052
15218
|
};
|
|
15053
|
-
container.
|
|
15219
|
+
container.append(tile);
|
|
15054
15220
|
this.fire("tileloadstart", {
|
|
15055
15221
|
tile,
|
|
15056
15222
|
coords
|
|
@@ -15128,6 +15294,10 @@ function isOSMUrl(url) {
|
|
|
15128
15294
|
return osmHosts.some((osmHost) => host === osmHost || host.endsWith(`.${osmHost}`));
|
|
15129
15295
|
}
|
|
15130
15296
|
const upgradeOSMUrl = (url) => isOSMUrl(url) ? url.replace(httpRe, "https:") : url;
|
|
15297
|
+
function retinaLevel() {
|
|
15298
|
+
const dpr = window.devicePixelRatio;
|
|
15299
|
+
return dpr >= 1.5 ? 2 : dpr > 1 ? 1 : 0;
|
|
15300
|
+
}
|
|
15131
15301
|
/**
|
|
15132
15302
|
* Options of `TileLayer`.
|
|
15133
15303
|
* @typedef {object} TileLayerOptions
|
|
@@ -15146,9 +15316,9 @@ const upgradeOSMUrl = (url) => isOSMUrl(url) ? url.replace(httpRe, "https:") : u
|
|
|
15146
15316
|
* this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).
|
|
15147
15317
|
* @property {boolean} [zoomReverse=false] If set to true, the zoom number used in tile
|
|
15148
15318
|
* URLs will be reversed (`maxZoom - zoom` instead of `zoom`).
|
|
15149
|
-
* @property {boolean} [detectRetina=false] If `true` and
|
|
15150
|
-
* will request four tiles of half the specified size and a bigger zoom level
|
|
15151
|
-
* of one to utilize the high resolution.
|
|
15319
|
+
* @property {boolean} [detectRetina=false] If `true` and the device pixel ratio is 1.5 or
|
|
15320
|
+
* higher, it will request four tiles of half the specified size and a bigger zoom level
|
|
15321
|
+
* in place of one to utilize the high resolution.
|
|
15152
15322
|
* @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will
|
|
15153
15323
|
* be added to the tiles. If a String is provided, all tiles will have their crossOrigin
|
|
15154
15324
|
* attribute set to the String provided. This is needed if you want to access tile pixel
|
|
@@ -15248,20 +15418,20 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
15248
15418
|
}
|
|
15249
15419
|
_applyRetina() {
|
|
15250
15420
|
Object.assign(this.options, this._nonRetinaOptions);
|
|
15251
|
-
this._retina =
|
|
15252
|
-
if (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {
|
|
15421
|
+
this._retina = retinaLevel();
|
|
15422
|
+
if (this.options.detectRetina && this._retina === 2 && this.options.maxZoom > 0) {
|
|
15253
15423
|
const tileSize = this.options.tileSize;
|
|
15254
15424
|
this.options.tileSize = tileSize instanceof Point ? tileSize.divideBy(2).floor() : Math.floor(tileSize / 2);
|
|
15255
15425
|
if (!this.options.zoomReverse) {
|
|
15256
15426
|
this.options.zoomOffset++;
|
|
15257
15427
|
this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);
|
|
15258
|
-
if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
|
|
15259
|
-
if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
|
|
15260
15428
|
} else {
|
|
15261
15429
|
this.options.zoomOffset--;
|
|
15262
15430
|
this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);
|
|
15263
15431
|
}
|
|
15264
15432
|
this.options.minZoom = Math.max(0, this.options.minZoom);
|
|
15433
|
+
if (this.options.maxNativeZoom !== void 0) this.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);
|
|
15434
|
+
if (this.options.minNativeZoom !== void 0) this.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);
|
|
15265
15435
|
} else if (!this.options.zoomReverse) this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);
|
|
15266
15436
|
else this.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);
|
|
15267
15437
|
}
|
|
@@ -15275,7 +15445,7 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
15275
15445
|
return events;
|
|
15276
15446
|
}
|
|
15277
15447
|
_onPixelRatioChange() {
|
|
15278
|
-
if (
|
|
15448
|
+
if (retinaLevel() === this._retina) return;
|
|
15279
15449
|
const map = this._map;
|
|
15280
15450
|
this._applyRetina();
|
|
15281
15451
|
if (this.options.detectRetina) {
|
|
@@ -15357,16 +15527,17 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
15357
15527
|
* @returns {string}
|
|
15358
15528
|
*/
|
|
15359
15529
|
getTileUrl(coords) {
|
|
15360
|
-
const data = Object.create(this.options);
|
|
15530
|
+
const z = coords.z ?? this._tileZoom, data = Object.create(this.options);
|
|
15361
15531
|
Object.assign(data, {
|
|
15362
15532
|
r: window.devicePixelRatio > 1 ? "@2x" : "",
|
|
15363
15533
|
s: this._getSubdomain(coords),
|
|
15364
15534
|
x: coords.x,
|
|
15365
15535
|
y: coords.y,
|
|
15366
|
-
z: this._getZoomForUrl()
|
|
15536
|
+
z: this._getZoomForUrl(z)
|
|
15367
15537
|
});
|
|
15368
|
-
|
|
15369
|
-
|
|
15538
|
+
const worldBounds = this._map?.getPixelWorldBounds(z);
|
|
15539
|
+
if (worldBounds) {
|
|
15540
|
+
const invertedY = this._pxBoundsToTileRange(worldBounds).max.y - coords.y;
|
|
15370
15541
|
if (this.options.tms) data["y"] = invertedY;
|
|
15371
15542
|
data["-y"] = invertedY;
|
|
15372
15543
|
}
|
|
@@ -15381,8 +15552,7 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
15381
15552
|
if (errorUrl && src !== errorUrl && (src || tile.isConnected)) tile.src = errorUrl;
|
|
15382
15553
|
done(e, tile);
|
|
15383
15554
|
}
|
|
15384
|
-
_getZoomForUrl() {
|
|
15385
|
-
let zoom = this._tileZoom;
|
|
15555
|
+
_getZoomForUrl(zoom) {
|
|
15386
15556
|
const maxZoom = this.options.maxZoom, zoomReverse = this.options.zoomReverse, zoomOffset = this.options.zoomOffset;
|
|
15387
15557
|
if (zoomReverse) zoom = maxZoom - zoom;
|
|
15388
15558
|
return zoom + zoomOffset;
|
|
@@ -15415,7 +15585,7 @@ var TileLayer = class TileLayer extends GridLayer {
|
|
|
15415
15585
|
return super._removeTile(key);
|
|
15416
15586
|
}
|
|
15417
15587
|
_tileReady(coords, err, tile) {
|
|
15418
|
-
if (!this._map || tile
|
|
15588
|
+
if (!this._map || tile?.getAttribute("src") === "") return;
|
|
15419
15589
|
return super._tileReady(coords, err, tile);
|
|
15420
15590
|
}
|
|
15421
15591
|
_clampZoom(zoom) {
|
|
@@ -15499,7 +15669,7 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
|
15499
15669
|
this.callInitHooks(WMSTileLayer);
|
|
15500
15670
|
}
|
|
15501
15671
|
_updateWmsSize() {
|
|
15502
|
-
const realRetina = this.options.detectRetina && window.devicePixelRatio
|
|
15672
|
+
const realRetina = this.options.detectRetina && window.devicePixelRatio >= 1.5 ? 2 : 1;
|
|
15503
15673
|
const tileSize = this.getTileSize();
|
|
15504
15674
|
this.wmsParams.width = tileSize.x * realRetina;
|
|
15505
15675
|
this.wmsParams.height = tileSize.y * realRetina;
|
|
@@ -15555,7 +15725,10 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
|
15555
15725
|
for (const [k, v] of Object.entries({
|
|
15556
15726
|
...this.wmsParams,
|
|
15557
15727
|
bbox
|
|
15558
|
-
}))
|
|
15728
|
+
})) {
|
|
15729
|
+
if (v == null) continue;
|
|
15730
|
+
url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);
|
|
15731
|
+
}
|
|
15559
15732
|
return url.toString();
|
|
15560
15733
|
}
|
|
15561
15734
|
/**
|
|
@@ -15583,7 +15756,8 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
|
|
|
15583
15756
|
/**
|
|
15584
15757
|
* Merges an object with the new parameters and re-requests tiles on the current screen
|
|
15585
15758
|
* (unless `noRedraw` was set to true). The current tiles stay visible until the new
|
|
15586
|
-
* tiles have loaded, to avoid flickering.
|
|
15759
|
+
* tiles have loaded, to avoid flickering. Set a parameter to `undefined` or `null` to
|
|
15760
|
+
* leave it out of the requests.
|
|
15587
15761
|
* @param {Record<string, any>} params
|
|
15588
15762
|
* @param {boolean} [noRedraw]
|
|
15589
15763
|
* @returns {this}
|
|
@@ -15669,22 +15843,21 @@ var Canvas = class Canvas extends Renderer {
|
|
|
15669
15843
|
*/
|
|
15670
15844
|
onAdd(map) {
|
|
15671
15845
|
super.onAdd(map);
|
|
15846
|
+
const z = (r) => +getComputedStyle(r._container.parentNode).zIndex || 0;
|
|
15847
|
+
map._canvases.push(this);
|
|
15848
|
+
map._canvases.sort((a, b) => z(b) - z(a) || 1 - (a._container.compareDocumentPosition(b._container) & 2));
|
|
15672
15849
|
this._draw();
|
|
15673
15850
|
}
|
|
15851
|
+
_initContainer() {
|
|
15852
|
+
const container = this._container = document.createElement("canvas");
|
|
15853
|
+
this._ctx = container.getContext("2d");
|
|
15854
|
+
}
|
|
15674
15855
|
/**
|
|
15675
15856
|
* Removes the canvas from the map.
|
|
15676
15857
|
*/
|
|
15677
15858
|
onRemove() {
|
|
15859
|
+
this._map._canvases = this._map._canvases.filter((r) => r !== this);
|
|
15678
15860
|
super.onRemove();
|
|
15679
|
-
clearTimeout(this._pointerHoverThrottleTimeout);
|
|
15680
|
-
}
|
|
15681
|
-
_initContainer() {
|
|
15682
|
-
const container = this._container = document.createElement("canvas");
|
|
15683
|
-
on(container, "pointermove", this._onPointerMove, this);
|
|
15684
|
-
on(container, "click dblclick pointerdown pointerup contextmenu", this._onClick, this);
|
|
15685
|
-
on(container, "pointerout", this._handlePointerOut, this);
|
|
15686
|
-
container["_maplair_disable_events"] = true;
|
|
15687
|
-
this._ctx = container.getContext("2d");
|
|
15688
15861
|
}
|
|
15689
15862
|
_destroyContainer() {
|
|
15690
15863
|
cancelAnimationFrame(this._redrawRequest);
|
|
@@ -15720,26 +15893,13 @@ var Canvas = class Canvas extends Renderer {
|
|
|
15720
15893
|
_initPath(layer) {
|
|
15721
15894
|
this._updateDashArray(layer);
|
|
15722
15895
|
this._layers[stamp(layer)] = layer;
|
|
15723
|
-
|
|
15724
|
-
layer,
|
|
15725
|
-
prev: this._drawLast,
|
|
15726
|
-
next: null
|
|
15727
|
-
};
|
|
15728
|
-
if (this._drawLast) this._drawLast.next = order;
|
|
15729
|
-
this._drawLast = order;
|
|
15730
|
-
this._drawFirst ??= this._drawLast;
|
|
15896
|
+
this._append(layer._order = { layer });
|
|
15731
15897
|
}
|
|
15732
15898
|
_addPath(layer) {
|
|
15733
15899
|
this._requestRedraw(layer);
|
|
15734
15900
|
}
|
|
15735
15901
|
_removePath(layer) {
|
|
15736
|
-
|
|
15737
|
-
const next = order.next;
|
|
15738
|
-
const prev = order.prev;
|
|
15739
|
-
if (next) next.prev = prev;
|
|
15740
|
-
else this._drawLast = prev;
|
|
15741
|
-
if (prev) prev.next = next;
|
|
15742
|
-
else this._drawFirst = next;
|
|
15902
|
+
this._unlink(layer._order);
|
|
15743
15903
|
delete layer._order;
|
|
15744
15904
|
delete this._layers[stamp(layer)];
|
|
15745
15905
|
this._requestRedraw(layer);
|
|
@@ -15765,7 +15925,7 @@ var Canvas = class Canvas extends Renderer {
|
|
|
15765
15925
|
}
|
|
15766
15926
|
_extendRedrawBounds(layer) {
|
|
15767
15927
|
if (layer._pxBounds) {
|
|
15768
|
-
const padding = (layer.options.weight
|
|
15928
|
+
const padding = (+layer.options.weight || 0) + 1;
|
|
15769
15929
|
this._redrawBounds ??= new Bounds();
|
|
15770
15930
|
this._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));
|
|
15771
15931
|
this._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));
|
|
@@ -15807,7 +15967,7 @@ var Canvas = class Canvas extends Renderer {
|
|
|
15807
15967
|
this._drawing = true;
|
|
15808
15968
|
for (let order = this._drawFirst; order; order = order.next) {
|
|
15809
15969
|
layer = order.layer;
|
|
15810
|
-
if (!bounds || layer._pxBounds
|
|
15970
|
+
if (!bounds || layer._pxBounds?.intersects(bounds)) layer._updatePath();
|
|
15811
15971
|
}
|
|
15812
15972
|
this._drawing = false;
|
|
15813
15973
|
this._ctx.restore();
|
|
@@ -15840,7 +16000,7 @@ var Canvas = class Canvas extends Renderer {
|
|
|
15840
16000
|
ctx.fillStyle = options.fillColor ?? options.color;
|
|
15841
16001
|
ctx.fill(options.fillRule || "evenodd");
|
|
15842
16002
|
}
|
|
15843
|
-
if (options.stroke && options.weight !== 0) {
|
|
16003
|
+
if (options.stroke && +options.weight !== 0) {
|
|
15844
16004
|
ctx.lineDashOffset = Number(options.dashOffset ?? 0);
|
|
15845
16005
|
ctx.setLineDash(layer._dashArray ?? []);
|
|
15846
16006
|
ctx.globalAlpha = options.opacity;
|
|
@@ -15852,84 +16012,50 @@ var Canvas = class Canvas extends Renderer {
|
|
|
15852
16012
|
}
|
|
15853
16013
|
}
|
|
15854
16014
|
_updateInteractive() {}
|
|
15855
|
-
|
|
16015
|
+
/**
|
|
16016
|
+
* Returns the topmost interactive layer under the pointer.
|
|
16017
|
+
* @param {MouseEvent} e
|
|
16018
|
+
* @param {boolean} [click] Skip layers that were just dragged, so the drag doesn't end with a click.
|
|
16019
|
+
* @returns {Path|undefined}
|
|
16020
|
+
*/
|
|
16021
|
+
_layerAt(e, click) {
|
|
15856
16022
|
const point = this._map.pointerEventToLayerPoint(e);
|
|
15857
|
-
let
|
|
15858
|
-
|
|
15859
|
-
layer
|
|
15860
|
-
if (layer.options.interactive && layer._containsPoint(point)) {
|
|
15861
|
-
if (!(e.type === "click" || e.type === "preclick") || !this._map._draggableMoved(layer)) clickedLayer = layer;
|
|
15862
|
-
}
|
|
16023
|
+
for (let order = this._drawLast; order; order = order.prev) {
|
|
16024
|
+
const layer = order.layer;
|
|
16025
|
+
if (layer.options.interactive && layer._containsPoint(point) && !(click && this._map._draggableMoved(layer))) return layer;
|
|
15863
16026
|
}
|
|
15864
|
-
this._fireEvent(clickedLayer ? [clickedLayer] : false, e);
|
|
15865
16027
|
}
|
|
15866
|
-
|
|
15867
|
-
|
|
15868
|
-
|
|
15869
|
-
|
|
15870
|
-
|
|
15871
|
-
|
|
15872
|
-
const layer = this._hoveredLayer;
|
|
15873
|
-
if (layer) {
|
|
15874
|
-
this._container.classList.remove("maplair-interactive");
|
|
15875
|
-
this._fireEvent([layer], e, "pointerout");
|
|
15876
|
-
this._hoveredLayer = null;
|
|
15877
|
-
this._pointerHoverThrottled = false;
|
|
16028
|
+
_bringToFront(layer) {
|
|
16029
|
+
const order = layer._order;
|
|
16030
|
+
if (order?.next) {
|
|
16031
|
+
this._unlink(order);
|
|
16032
|
+
this._append(order);
|
|
16033
|
+
this._requestRedraw(layer);
|
|
15878
16034
|
}
|
|
15879
16035
|
}
|
|
15880
|
-
|
|
15881
|
-
|
|
15882
|
-
|
|
15883
|
-
|
|
15884
|
-
|
|
15885
|
-
|
|
15886
|
-
|
|
15887
|
-
|
|
15888
|
-
this.
|
|
15889
|
-
if (candidateHoveredLayer) {
|
|
15890
|
-
this._container.classList.add("maplair-interactive");
|
|
15891
|
-
this._fireEvent([candidateHoveredLayer], e, "pointerover");
|
|
15892
|
-
this._hoveredLayer = candidateHoveredLayer;
|
|
15893
|
-
}
|
|
16036
|
+
_bringToBack(layer) {
|
|
16037
|
+
const order = layer._order;
|
|
16038
|
+
if (order?.prev) {
|
|
16039
|
+
this._unlink(order);
|
|
16040
|
+
order.prev = null;
|
|
16041
|
+
order.next = this._drawFirst;
|
|
16042
|
+
this._drawFirst.prev = order;
|
|
16043
|
+
this._drawFirst = order;
|
|
16044
|
+
this._requestRedraw(layer);
|
|
15894
16045
|
}
|
|
15895
|
-
this._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);
|
|
15896
|
-
this._pointerHoverThrottled = true;
|
|
15897
|
-
this._pointerHoverThrottleTimeout = setTimeout((() => {
|
|
15898
|
-
this._pointerHoverThrottled = false;
|
|
15899
|
-
}), 32);
|
|
15900
|
-
}
|
|
15901
|
-
_fireEvent(layers, e, type) {
|
|
15902
|
-
this._map._fireDOMEvent(e, type || e.type, layers);
|
|
15903
16046
|
}
|
|
15904
|
-
|
|
15905
|
-
const order = layer._order;
|
|
15906
|
-
if (!order) return;
|
|
15907
|
-
const next = order.next;
|
|
15908
|
-
const prev = order.prev;
|
|
15909
|
-
if (next) next.prev = prev;
|
|
15910
|
-
else return;
|
|
15911
|
-
if (prev) prev.next = next;
|
|
15912
|
-
else if (next) this._drawFirst = next;
|
|
16047
|
+
_append(order) {
|
|
15913
16048
|
order.prev = this._drawLast;
|
|
15914
|
-
this._drawLast.next = order;
|
|
15915
16049
|
order.next = null;
|
|
16050
|
+
if (this._drawLast) this._drawLast.next = order;
|
|
15916
16051
|
this._drawLast = order;
|
|
15917
|
-
this.
|
|
16052
|
+
this._drawFirst ??= order;
|
|
15918
16053
|
}
|
|
15919
|
-
|
|
15920
|
-
const order = layer._order;
|
|
15921
|
-
if (!order) return;
|
|
15922
|
-
const next = order.next;
|
|
15923
|
-
const prev = order.prev;
|
|
15924
|
-
if (prev) prev.next = next;
|
|
15925
|
-
else return;
|
|
16054
|
+
_unlink({ prev, next }) {
|
|
15926
16055
|
if (next) next.prev = prev;
|
|
15927
|
-
else
|
|
15928
|
-
|
|
15929
|
-
|
|
15930
|
-
this._drawFirst.prev = order;
|
|
15931
|
-
this._drawFirst = order;
|
|
15932
|
-
this._requestRedraw(layer);
|
|
16056
|
+
else this._drawLast = prev;
|
|
16057
|
+
if (prev) prev.next = next;
|
|
16058
|
+
else this._drawFirst = next;
|
|
15933
16059
|
}
|
|
15934
16060
|
};
|
|
15935
16061
|
// src/layer/vector/Circle.js
|
|
@@ -15963,7 +16089,6 @@ var Circle = class Circle extends CircleMarker {
|
|
|
15963
16089
|
constructor(latlng, options) {
|
|
15964
16090
|
if (typeof options === "number") throw new Error("Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).");
|
|
15965
16091
|
super(latlng, options);
|
|
15966
|
-
if (isNaN(this.options.radius)) throw new Error("Circle radius cannot be NaN");
|
|
15967
16092
|
this.callInitHooks(Circle);
|
|
15968
16093
|
}
|
|
15969
16094
|
/**
|
|
@@ -15977,18 +16102,18 @@ var Circle = class Circle extends CircleMarker {
|
|
|
15977
16102
|
return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half)));
|
|
15978
16103
|
}
|
|
15979
16104
|
_project() {
|
|
15980
|
-
const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs;
|
|
16105
|
+
const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs, renderer = this._renderer, zoom = renderer._pathZoom;
|
|
15981
16106
|
if (crs.distance === EarthCRS.distance) {
|
|
15982
|
-
const d = Math.PI / 180, latR = this._radius / EarthCRS.R / d, top = map.project([lat + latR, lng]), bottom = map.project([lat - latR, lng]), p = top.add(bottom).divideBy(2), lat2 = map.unproject(p).lat;
|
|
16107
|
+
const d = Math.PI / 180, latR = this._radius / EarthCRS.R / d, top = map.project([lat + latR, lng], zoom), bottom = map.project([lat - latR, lng], zoom), p = top.add(bottom).divideBy(2), lat2 = map.unproject(p, zoom).lat;
|
|
15983
16108
|
let lngR = 2 * Math.asin(Math.sqrt((Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) / (Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;
|
|
15984
|
-
if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(
|
|
15985
|
-
this._point = p.subtract(
|
|
15986
|
-
this._pxRadius = isNaN(lngR) ? 0 : p.
|
|
15987
|
-
this._pxRadiusY = p.
|
|
16109
|
+
if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(lat * d);
|
|
16110
|
+
this._point = p.subtract(renderer._pathOrigin);
|
|
16111
|
+
this._pxRadius = isNaN(lngR) ? 0 : p.distanceTo(map.project([lat2, lng - lngR], zoom));
|
|
16112
|
+
this._pxRadiusY = p.distanceTo(top);
|
|
15988
16113
|
} else {
|
|
15989
16114
|
const latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));
|
|
15990
|
-
this._point =
|
|
15991
|
-
this._pxRadius = Math.abs(this._point.x -
|
|
16115
|
+
this._point = renderer._latLngToLayerPoint(this._latlng);
|
|
16116
|
+
this._pxRadius = Math.abs(this._point.x - renderer._latLngToLayerPoint(latlng2).x);
|
|
15992
16117
|
}
|
|
15993
16118
|
this._updateBounds();
|
|
15994
16119
|
}
|
|
@@ -16389,7 +16514,7 @@ var MapSync = class {
|
|
|
16389
16514
|
if (this._leader !== map) return;
|
|
16390
16515
|
for (const other of this._followers(map)) if (other._zoomAnimated) {
|
|
16391
16516
|
this._animating.add(other);
|
|
16392
|
-
other._animateZoom(e.center, this._zoomFor(other, map, e.zoom),
|
|
16517
|
+
other._animateZoom(e.center, this._zoomFor(other, map, e.zoom), e.noUpdate);
|
|
16393
16518
|
}
|
|
16394
16519
|
}
|
|
16395
16520
|
_onMoveEnd(map) {
|
|
@@ -16419,10 +16544,7 @@ var MapSync = class {
|
|
|
16419
16544
|
other._rawPanBy(offset);
|
|
16420
16545
|
other.fire("move");
|
|
16421
16546
|
}
|
|
16422
|
-
} else other._move(center, zoom, during ? {
|
|
16423
|
-
pinch: true,
|
|
16424
|
-
round: false
|
|
16425
|
-
} : void 0);
|
|
16547
|
+
} else other._move(center, zoom, during ? { pinch: true } : void 0);
|
|
16426
16548
|
}
|
|
16427
16549
|
_syncAll(map) {
|
|
16428
16550
|
for (const other of this._maps.filter((m) => m !== map)) {
|
|
@@ -16554,6 +16676,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
|
|
|
16554
16676
|
* Called when the handler is enabled, adds the event hooks.
|
|
16555
16677
|
*/
|
|
16556
16678
|
addHooks() {
|
|
16679
|
+
this._map._displaceHandler = this;
|
|
16557
16680
|
this._map.on("zoomend", this.schedule, this);
|
|
16558
16681
|
this._map.on("layeradd", this._onLayerAdd, this);
|
|
16559
16682
|
this._map.on("layerremove", this._onLayerRemove, this);
|
|
@@ -16565,6 +16688,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
|
|
|
16565
16688
|
* true positions of the markers.
|
|
16566
16689
|
*/
|
|
16567
16690
|
removeHooks() {
|
|
16691
|
+
if (this._map._displaceHandler === this) delete this._map._displaceHandler;
|
|
16568
16692
|
this._map.off("zoomend", this.schedule, this);
|
|
16569
16693
|
this._map.off("layeradd", this._onLayerAdd, this);
|
|
16570
16694
|
this._map.off("layerremove", this._onLayerRemove, this);
|
|
@@ -16636,6 +16760,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
|
|
|
16636
16760
|
* @param {LatLng} latLng
|
|
16637
16761
|
*/
|
|
16638
16762
|
_moveTo(marker, latLng) {
|
|
16763
|
+
if (marker.getLatLng().equals(latLng)) return;
|
|
16639
16764
|
this._moving = true;
|
|
16640
16765
|
try {
|
|
16641
16766
|
marker.setLatLng(latLng);
|
|
@@ -16655,6 +16780,19 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
|
|
|
16655
16780
|
if (this._enabled && this._map.hasLayer(event.target)) this.schedule();
|
|
16656
16781
|
}
|
|
16657
16782
|
/**
|
|
16783
|
+
* Called by `CircleMarker#beforeAdd`: puts a marker whose `displaceId` already
|
|
16784
|
+
* has a displaced position at the current zoom (e.g. the same station on
|
|
16785
|
+
* another layer) there before it is drawn, instead of drawing it twice.
|
|
16786
|
+
* @param {CircleMarker} marker
|
|
16787
|
+
*/
|
|
16788
|
+
_beforeMarkerAdd(marker) {
|
|
16789
|
+
if (!displaceable(marker)) return;
|
|
16790
|
+
this._track(marker);
|
|
16791
|
+
const { displaceId } = marker.options;
|
|
16792
|
+
const latLng = displaceId && this._displacedPositions.get(this._map.getZoom())?.get(displaceId);
|
|
16793
|
+
if (latLng) this._moveTo(marker, latLng);
|
|
16794
|
+
}
|
|
16795
|
+
/**
|
|
16658
16796
|
* @param {LayerEvent} event
|
|
16659
16797
|
*/
|
|
16660
16798
|
_onLayerAdd(event) {
|
|
@@ -16691,6 +16829,10 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
|
|
|
16691
16829
|
}
|
|
16692
16830
|
};
|
|
16693
16831
|
/**
|
|
16832
|
+
* Movement in pixels per pass below which `displace` stops early
|
|
16833
|
+
*/
|
|
16834
|
+
const MIN_MOVE = .01;
|
|
16835
|
+
/**
|
|
16694
16836
|
* Displaces overlapping points in pixel space until they are at least
|
|
16695
16837
|
* `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed
|
|
16696
16838
|
* apart by half of its overlap per pass. Neighbour lookup uses a grid (cell
|
|
@@ -16698,7 +16840,8 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
|
|
|
16698
16840
|
*
|
|
16699
16841
|
* No point ends up further than `maxDisplacement` away from where it started.
|
|
16700
16842
|
* Points which hit that limit stay overlapping – the limit wins over the
|
|
16701
|
-
* separation.
|
|
16843
|
+
* separation. The relaxation stops early once the points are separated or
|
|
16844
|
+
* no point moves by more than a hundredth of a pixel per pass.
|
|
16702
16845
|
*
|
|
16703
16846
|
* @param {Point[]} points Pixel coordinates (modified in place)
|
|
16704
16847
|
* @param {number} minSeparation Minimum distance between centers, in pixels
|
|
@@ -16718,49 +16861,62 @@ function displace(points, minSeparation, { iterations = DisplaceHandler.defaultO
|
|
|
16718
16861
|
for (let iter = 0; iter < iterations; iter++) {
|
|
16719
16862
|
dx.fill(0);
|
|
16720
16863
|
dy.fill(0);
|
|
16721
|
-
/** @type {Map<
|
|
16864
|
+
/** @type {Map<number, Map<number, number[]>>} */
|
|
16722
16865
|
const grid = /* @__PURE__ */ new Map();
|
|
16723
16866
|
for (let i = 0; i < n; i++) {
|
|
16724
|
-
const
|
|
16725
|
-
const
|
|
16867
|
+
const cx = Math.floor(points[i].x / cell);
|
|
16868
|
+
const cy = Math.floor(points[i].y / cell);
|
|
16869
|
+
let column = grid.get(cx);
|
|
16870
|
+
if (!column) {
|
|
16871
|
+
column = /* @__PURE__ */ new Map();
|
|
16872
|
+
grid.set(cx, column);
|
|
16873
|
+
}
|
|
16874
|
+
const bucket = column.get(cy);
|
|
16726
16875
|
if (bucket) bucket.push(i);
|
|
16727
|
-
else
|
|
16876
|
+
else column.set(cy, [i]);
|
|
16728
16877
|
}
|
|
16729
16878
|
let overlaps = 0;
|
|
16730
16879
|
for (let i = 0; i < n; i++) {
|
|
16731
16880
|
const cx = Math.floor(points[i].x / cell);
|
|
16732
16881
|
const cy = Math.floor(points[i].y / cell);
|
|
16733
|
-
for (let gx = cx - 1; gx <= cx + 1; gx++)
|
|
16734
|
-
const
|
|
16735
|
-
if (!
|
|
16736
|
-
for (
|
|
16737
|
-
|
|
16738
|
-
|
|
16739
|
-
|
|
16740
|
-
|
|
16741
|
-
|
|
16742
|
-
|
|
16743
|
-
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
|
|
16749
|
-
|
|
16750
|
-
|
|
16751
|
-
|
|
16752
|
-
|
|
16882
|
+
for (let gx = cx - 1; gx <= cx + 1; gx++) {
|
|
16883
|
+
const column = grid.get(gx);
|
|
16884
|
+
if (!column) continue;
|
|
16885
|
+
for (let gy = cy - 1; gy <= cy + 1; gy++) {
|
|
16886
|
+
const bucket = column.get(gy);
|
|
16887
|
+
if (!bucket) continue;
|
|
16888
|
+
for (const j of bucket) {
|
|
16889
|
+
if (j <= i) continue;
|
|
16890
|
+
let vx = points[i].x - points[j].x;
|
|
16891
|
+
let vy = points[i].y - points[j].y;
|
|
16892
|
+
const distSq = vx * vx + vy * vy;
|
|
16893
|
+
if (distSq >= sepSq) continue;
|
|
16894
|
+
overlaps++;
|
|
16895
|
+
let dist;
|
|
16896
|
+
if (distSq === 0) {
|
|
16897
|
+
const angle = i * 2.399963229728653;
|
|
16898
|
+
vx = Math.cos(angle);
|
|
16899
|
+
vy = Math.sin(angle);
|
|
16900
|
+
dist = 1;
|
|
16901
|
+
} else {
|
|
16902
|
+
dist = Math.sqrt(distSq);
|
|
16903
|
+
vx /= dist;
|
|
16904
|
+
vy /= dist;
|
|
16905
|
+
}
|
|
16906
|
+
const push = (sep - dist) / 2;
|
|
16907
|
+
dx[i] += vx * push;
|
|
16908
|
+
dy[i] += vy * push;
|
|
16909
|
+
dx[j] -= vx * push;
|
|
16910
|
+
dy[j] -= vy * push;
|
|
16753
16911
|
}
|
|
16754
|
-
const push = (sep - dist) / 2;
|
|
16755
|
-
dx[i] += vx * push;
|
|
16756
|
-
dy[i] += vy * push;
|
|
16757
|
-
dx[j] -= vx * push;
|
|
16758
|
-
dy[j] -= vy * push;
|
|
16759
16912
|
}
|
|
16760
16913
|
}
|
|
16761
16914
|
}
|
|
16762
16915
|
if (overlaps === 0) break;
|
|
16916
|
+
let maxMoveSq = 0;
|
|
16763
16917
|
for (let i = 0; i < n; i++) {
|
|
16918
|
+
const x = points[i].x;
|
|
16919
|
+
const y = points[i].y;
|
|
16764
16920
|
points[i].x += dx[i];
|
|
16765
16921
|
points[i].y += dy[i];
|
|
16766
16922
|
const ox = points[i].x - ax[i];
|
|
@@ -16771,7 +16927,11 @@ function displace(points, minSeparation, { iterations = DisplaceHandler.defaultO
|
|
|
16771
16927
|
points[i].x = ax[i] + ox * scale;
|
|
16772
16928
|
points[i].y = ay[i] + oy * scale;
|
|
16773
16929
|
}
|
|
16930
|
+
const mx = points[i].x - x;
|
|
16931
|
+
const my = points[i].y - y;
|
|
16932
|
+
maxMoveSq = Math.max(maxMoveSq, mx * mx + my * my);
|
|
16774
16933
|
}
|
|
16934
|
+
if (maxMoveSq < MIN_MOVE * MIN_MOVE) break;
|
|
16775
16935
|
}
|
|
16776
16936
|
return points;
|
|
16777
16937
|
}
|
|
@@ -16841,7 +17001,6 @@ var RotateControl = class RotateControl extends Control {
|
|
|
16841
17001
|
disableClickPropagation(button);
|
|
16842
17002
|
on(button, "click", stop);
|
|
16843
17003
|
on(button, "click", this._resetNorth, this);
|
|
16844
|
-
on(button, "click", this._refocusOnMap, this);
|
|
16845
17004
|
this._update();
|
|
16846
17005
|
map.on("rotate", this._update, this);
|
|
16847
17006
|
return container;
|
|
@@ -16945,8 +17104,8 @@ MaplairMap.include({
|
|
|
16945
17104
|
if (!this._rotatePane) {
|
|
16946
17105
|
const rotatePane = this._rotatePane = create("div", "maplair-rotate-pane");
|
|
16947
17106
|
rotatedMaps.set(rotatePane, this);
|
|
16948
|
-
this.
|
|
16949
|
-
rotatePane.
|
|
17107
|
+
this._mapPane.before(rotatePane);
|
|
17108
|
+
rotatePane.append(this._mapPane);
|
|
16950
17109
|
}
|
|
16951
17110
|
if (bearing === this.getBearing()) return;
|
|
16952
17111
|
this._bearing = bearing;
|
|
@@ -17035,9 +17194,9 @@ MaplairMap.include({
|
|
|
17035
17194
|
return panBy.call(this, this._rotateToPane(Point.from(offset)), options);
|
|
17036
17195
|
},
|
|
17037
17196
|
_tryAnimatedPan(center, options) {
|
|
17038
|
-
const offset = this.
|
|
17039
|
-
if (options?.animate !== true && !this.getSize().contains(offset)) return false;
|
|
17040
|
-
this.
|
|
17197
|
+
const offset = this.latLngToLayerPoint(center)._subtract(this._getCenterLayerPoint())._round();
|
|
17198
|
+
if (options?.animate !== true && !this.getSize().contains(this._rotateToContainer(offset))) return false;
|
|
17199
|
+
this._panBy(offset, options);
|
|
17041
17200
|
return true;
|
|
17042
17201
|
},
|
|
17043
17202
|
/**
|
|
@@ -17095,7 +17254,8 @@ GridLayer.include({ _getTiledPixelBounds(center) {
|
|
|
17095
17254
|
/** @typedef {typeof blanketOverlayRotationMethods} BlanketOverlayMapRotationMethods */
|
|
17096
17255
|
BlanketOverlay.include({
|
|
17097
17256
|
_updateTransform(center, zoom) {
|
|
17098
|
-
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))
|
|
17257
|
+
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));
|
|
17258
|
+
if (scale === 1) this._map._snapLayerPoint(topLeftOffset);
|
|
17099
17259
|
setTransform(this._container, topLeftOffset, scale);
|
|
17100
17260
|
},
|
|
17101
17261
|
_onMoveEnd(ev) {
|
|
@@ -17130,7 +17290,7 @@ DivOverlay.include({
|
|
|
17130
17290
|
},
|
|
17131
17291
|
_updatePosition() {
|
|
17132
17292
|
if (!this._map) return;
|
|
17133
|
-
const map = this._map, pos = map.latLngToLayerPoint(this._latlng)
|
|
17293
|
+
const map = this._map, pos = map._snapLayerPoint(map.latLngToLayerPoint(this._latlng)), anchor = map._rotateToPane(new Point(this._getAnchor()));
|
|
17134
17294
|
let offset = Point.from(this.options.offset);
|
|
17135
17295
|
const transformed = this._zoomAnimated || this.options.overflow || map._bearing;
|
|
17136
17296
|
if (!transformed) offset = offset.add(pos).add(anchor);
|
|
@@ -17329,10 +17489,7 @@ PinchZoomHandler.include({
|
|
|
17329
17489
|
this._moved = true;
|
|
17330
17490
|
}
|
|
17331
17491
|
cancelAnimationFrame(this._animRequest);
|
|
17332
|
-
const moveFn = map._move.bind(map, this._center, this._zoom, {
|
|
17333
|
-
pinch: true,
|
|
17334
|
-
round: false
|
|
17335
|
-
}, void 0);
|
|
17492
|
+
const moveFn = map._move.bind(map, this._center, this._zoom, { pinch: true }, void 0);
|
|
17336
17493
|
this._animRequest = requestAnimationFrame(moveFn.bind(this));
|
|
17337
17494
|
e.preventDefault();
|
|
17338
17495
|
}
|
|
@@ -17900,7 +18057,10 @@ Path.include({
|
|
|
17900
18057
|
});
|
|
17901
18058
|
CircleMarker.include({ setRadius(radius) {
|
|
17902
18059
|
this._takeZoomStyles({ radius });
|
|
17903
|
-
|
|
18060
|
+
if (!this._zoomStyles?.radius) return setRadius.call(this, radius);
|
|
18061
|
+
if (this._map) return setRadius.call(this, evaluate(radius, this._map.getZoom()));
|
|
18062
|
+
this.options.radius = this._radius = radius;
|
|
18063
|
+
return this;
|
|
17904
18064
|
} });
|
|
17905
18065
|
Path.addInitHook(function() {
|
|
17906
18066
|
this._takeZoomStyles(this.options);
|