maplair 4.2.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -8
- package/dist/esm/control/AttributionControl.js +10 -10
- 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 +13 -9
- 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 +4 -5
- 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 +13 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +4 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +16 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +55 -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 +4 -6
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +23 -34
- 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 +12 -17
- package/dist/esm/geometry/Point.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 +1 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +23 -23
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +7 -4
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +11 -6
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +30 -11
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +18 -35
- 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 +16 -15
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +6 -7
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +49 -48
- 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 +18 -16
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +9 -9
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +44 -93
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +8 -7
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +9 -1
- package/dist/esm/layer/vector/CircleMarker.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 +6 -9
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +104 -49
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -4
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +2 -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/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +3 -6
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -4
- 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 +700 -687
- 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 +700 -687
- 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 +2 -1
- package/src/control/AttributionControl.js +9 -9
- 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 +14 -10
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +4 -5
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +10 -13
- package/src/core/Events.js +8 -2
- package/src/core/Util.js +16 -3
- package/src/dom/DomEvent.PointerEvents.js +47 -1
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +5 -6
- package/src/geo/LatLng.js +22 -36
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +18 -26
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +1 -1
- package/src/layer/DivOverlay.js +28 -30
- package/src/layer/ImageOverlay.js +9 -7
- package/src/layer/Layer.js +18 -6
- package/src/layer/Popup.js +38 -17
- package/src/layer/Tooltip.js +17 -44
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +19 -18
- package/src/layer/marker/Marker.Drag.js +16 -18
- package/src/layer/marker/Marker.js +66 -59
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +21 -23
- package/src/layer/tile/TileLayer.js +17 -14
- package/src/layer/vector/Canvas.js +52 -148
- package/src/layer/vector/Circle.js +14 -9
- package/src/layer/vector/CircleMarker.js +11 -1
- 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 +7 -6
- package/src/map/Map.js +135 -54
- package/src/map/MapSync.js +1 -1
- package/src/map/handler/BoxZoomHandler.js +2 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +3 -3
- package/src/map/handler/ScrollWheelZoomHandler.js +3 -3
- package/src/map/handler/TapDragZoomHandler.js +1 -1
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +38 -9
- 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/src/layer/Tooltip.js
CHANGED
|
@@ -6,7 +6,8 @@ import * as DomEvent from '../dom/DomEvent.js';
|
|
|
6
6
|
import * as Util from '../core/Util.js';
|
|
7
7
|
import {FeatureGroup} from './FeatureGroup.js';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// which point of the tooltip (as a fraction of its width and height) sits at the anchor, for each direction
|
|
10
|
+
const directions = {top: [0.5, 1], bottom: [0.5, 0], center: [0.5, 0.5], right: [0, 0.5], left: [1, 0.5]};
|
|
10
11
|
|
|
11
12
|
// The size of the tooltip tip (see `.maplair-tooltip-top` etc. in maplair.css) and
|
|
12
13
|
// the minimum distance of an `auto` tooltip to the edge of the map.
|
|
@@ -114,7 +115,7 @@ const layerTooltipMethods = {
|
|
|
114
115
|
* may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
|
|
115
116
|
* `HTMLElement` with safe `textContent` instead. If a `Function` is passed
|
|
116
117
|
* it will receive the layer as the first argument and should return a
|
|
117
|
-
* `String` or `
|
|
118
|
+
* `String`, `HTMLElement` or `DocumentFragment`.
|
|
118
119
|
* @group Tooltip methods
|
|
119
120
|
* @param {DivOverlayContent|Tooltip} content
|
|
120
121
|
* @param {TooltipOptions} [options]
|
|
@@ -133,7 +134,7 @@ const layerTooltipMethods = {
|
|
|
133
134
|
this._tooltip = this._initOverlay(Tooltip, old, content, options);
|
|
134
135
|
this._initTooltipInteractions();
|
|
135
136
|
|
|
136
|
-
if (this._tooltip.options.permanent && this._map
|
|
137
|
+
if (this._tooltip.options.permanent && this._map?.hasLayer(this)) {
|
|
137
138
|
this.openTooltip();
|
|
138
139
|
}
|
|
139
140
|
|
|
@@ -193,12 +194,6 @@ const layerTooltipMethods = {
|
|
|
193
194
|
if (this._tooltip._prepareOpen(latlng)) {
|
|
194
195
|
// open the tooltip on the map
|
|
195
196
|
this._tooltip.openOn(this._map);
|
|
196
|
-
|
|
197
|
-
if (this.getElement) {
|
|
198
|
-
this._setAriaDescribedByOnLayer(this);
|
|
199
|
-
} else if (this.eachLayer) {
|
|
200
|
-
this.eachLayer(this._setAriaDescribedByOnLayer, this);
|
|
201
|
-
}
|
|
202
197
|
}
|
|
203
198
|
}
|
|
204
199
|
return this;
|
|
@@ -272,8 +267,10 @@ const layerTooltipMethods = {
|
|
|
272
267
|
// Remove focus listener, if already existing
|
|
273
268
|
el._maplair_focus_handler && DomEvent.off(el, 'focus', el._maplair_focus_handler, this);
|
|
274
269
|
|
|
270
|
+
// open only on keyboard focus: an element clicked with the mouse keeps focus and gets it again whenever
|
|
271
|
+
// the window is refocused or a popup closes, which would open the tooltip without the pointer over it
|
|
275
272
|
el._maplair_focus_handler = () => {
|
|
276
|
-
if (this._tooltip) {
|
|
273
|
+
if (this._tooltip && el.matches(':focus-visible')) {
|
|
277
274
|
this._tooltip._source = layer;
|
|
278
275
|
this.openTooltip();
|
|
279
276
|
}
|
|
@@ -289,11 +286,6 @@ const layerTooltipMethods = {
|
|
|
289
286
|
}
|
|
290
287
|
},
|
|
291
288
|
|
|
292
|
-
_setAriaDescribedByOnLayer(layer) {
|
|
293
|
-
const el = typeof layer.getElement === 'function' && layer.getElement();
|
|
294
|
-
el?.setAttribute?.('aria-describedby', this._tooltip._container.id);
|
|
295
|
-
},
|
|
296
|
-
|
|
297
289
|
_openTooltip(e) {
|
|
298
290
|
if (!this._tooltip || !this._map) {
|
|
299
291
|
return;
|
|
@@ -317,13 +309,8 @@ const layerTooltipMethods = {
|
|
|
317
309
|
},
|
|
318
310
|
|
|
319
311
|
_moveTooltip(e) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
|
|
323
|
-
layerPoint = this._map.containerPointToLayerPoint(containerPoint);
|
|
324
|
-
latlng = this._map.layerPointToLatLng(layerPoint);
|
|
325
|
-
}
|
|
326
|
-
this._tooltip.setLatLng(latlng);
|
|
312
|
+
this._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ?
|
|
313
|
+
this._map.pointerEventToLatLng(e.originalEvent) : e.latlng);
|
|
327
314
|
}
|
|
328
315
|
};
|
|
329
316
|
/** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */
|
|
@@ -418,6 +405,7 @@ export class Tooltip extends DivOverlay {
|
|
|
418
405
|
|
|
419
406
|
if (this._source) {
|
|
420
407
|
this.addEventParent(this._source);
|
|
408
|
+
this._source.getElement?.()?.setAttribute('aria-describedby', this._container.id);
|
|
421
409
|
|
|
422
410
|
this._source.fire('tooltipopen', {tooltip: this}, true);
|
|
423
411
|
}
|
|
@@ -460,7 +448,7 @@ export class Tooltip extends DivOverlay {
|
|
|
460
448
|
this._contentNode = this._container = DomUtil.create('div', className);
|
|
461
449
|
|
|
462
450
|
this._container.setAttribute('role', 'tooltip');
|
|
463
|
-
this._container.
|
|
451
|
+
this._container.id = `maplair-tooltip-${Util.stamp(this)}`;
|
|
464
452
|
}
|
|
465
453
|
|
|
466
454
|
_updateLayout() {}
|
|
@@ -487,7 +475,7 @@ export class Tooltip extends DivOverlay {
|
|
|
487
475
|
offset = new Point(this.options.offset),
|
|
488
476
|
anchor = this._getAnchor();
|
|
489
477
|
|
|
490
|
-
if (!
|
|
478
|
+
if (!(direction in directions)) {
|
|
491
479
|
({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));
|
|
492
480
|
if (direction === 'left') {
|
|
493
481
|
// mirror the offset and anchor, which are meant for the right side
|
|
@@ -496,27 +484,12 @@ export class Tooltip extends DivOverlay {
|
|
|
496
484
|
}
|
|
497
485
|
}
|
|
498
486
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (direction === 'top') {
|
|
502
|
-
subY = tooltipHeight;
|
|
503
|
-
} else if (direction === 'bottom') {
|
|
504
|
-
subY = 0;
|
|
505
|
-
} else if (direction === 'right') {
|
|
506
|
-
subX = 0;
|
|
507
|
-
} else if (direction === 'left') {
|
|
508
|
-
subX = tooltipWidth;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor).add(shift);
|
|
487
|
+
const [fx, fy] = directions[direction];
|
|
488
|
+
pos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);
|
|
512
489
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
'maplair-tooltip-top',
|
|
517
|
-
'maplair-tooltip-bottom'
|
|
518
|
-
);
|
|
519
|
-
container.classList.add(`maplair-tooltip-${direction}`);
|
|
490
|
+
for (const d in directions) {
|
|
491
|
+
container.classList.toggle(`maplair-tooltip-${d}`, d === direction);
|
|
492
|
+
}
|
|
520
493
|
|
|
521
494
|
// Let the tip point at the source despite the shift
|
|
522
495
|
const tipShift = direction === 'top' || direction === 'bottom' ?
|
|
@@ -96,7 +96,7 @@ export class VideoOverlay extends ImageOverlay {
|
|
|
96
96
|
if (!Array.isArray(this._url)) { this._url = [this._url]; }
|
|
97
97
|
|
|
98
98
|
if (!this.options.keepAspectRatio) {
|
|
99
|
-
vid.style
|
|
99
|
+
vid.style.objectFit = 'fill';
|
|
100
100
|
}
|
|
101
101
|
vid.autoplay = !!this.options.autoplay;
|
|
102
102
|
vid.controls = !!this.options.controls;
|
|
@@ -106,7 +106,7 @@ export class VideoOverlay extends ImageOverlay {
|
|
|
106
106
|
for (const url of this._url) {
|
|
107
107
|
const source = DomUtil.create('source');
|
|
108
108
|
source.src = url;
|
|
109
|
-
vid.
|
|
109
|
+
vid.append(source);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -65,16 +65,13 @@ export class DivIcon extends Icon {
|
|
|
65
65
|
options = this.options;
|
|
66
66
|
|
|
67
67
|
if (options.html instanceof Element) {
|
|
68
|
-
div.replaceChildren();
|
|
69
|
-
div.appendChild(options.html);
|
|
68
|
+
div.replaceChildren(options.html);
|
|
70
69
|
} else {
|
|
71
70
|
div.innerHTML = options.html !== false ? options.html : '';
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
|
|
77
|
-
}
|
|
73
|
+
const bgPos = options.bgPos && Point.from(options.bgPos);
|
|
74
|
+
div.style.backgroundPosition = bgPos ? `${-bgPos.x}px ${-bgPos.y}px` : '';
|
|
78
75
|
this._setIconStyles(div, 'icon');
|
|
79
76
|
|
|
80
77
|
return div;
|
package/src/layer/marker/Icon.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Class} from '../../core/Class.js';
|
|
2
|
-
import {setOptions} from '../../core/Util.js';
|
|
2
|
+
import {setOptions, toNumber} from '../../core/Util.js';
|
|
3
3
|
import {Point} from '../../geometry/Point.js';
|
|
4
4
|
|
|
5
5
|
/** @import {PointExpression} from '../../geometry/Point.js' */
|
|
@@ -113,6 +113,8 @@ export class Icon extends Class {
|
|
|
113
113
|
|
|
114
114
|
if (this.options.crossOrigin || this.options.crossOrigin === '') {
|
|
115
115
|
img.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;
|
|
116
|
+
} else {
|
|
117
|
+
img.crossOrigin = null;
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
return img;
|
|
@@ -120,30 +122,29 @@ export class Icon extends Class {
|
|
|
120
122
|
|
|
121
123
|
_setIconStyles(img, name) {
|
|
122
124
|
const options = this.options;
|
|
123
|
-
|
|
125
|
+
const sizeOption = options[`${name}Size`];
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const size = Point.validate(sizeOption) && Point.from(sizeOption);
|
|
127
|
+
// a side that isn't a number, like 'auto' in [100, 'auto'], is left to CSS
|
|
128
|
+
const [width, height] = (typeof sizeOption === 'number' ? [sizeOption, sizeOption] :
|
|
129
|
+
Array.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);
|
|
130
130
|
|
|
131
|
-
const
|
|
132
|
-
const anchor = Point.validate(
|
|
131
|
+
const anchorOption = name === 'shadow' && options.shadowAnchor || options.iconAnchor;
|
|
132
|
+
const anchor = Point.validate(anchorOption) ? Point.from(anchorOption) :
|
|
133
|
+
{x: Math.round(width / 2), y: Math.round(height / 2)};
|
|
133
134
|
|
|
134
135
|
img.className = `maplair-marker-${name} ${options.className || ''}`;
|
|
135
136
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
// a marker reuses the element of its previous icon, which may have set any of these
|
|
138
|
+
const {style} = img;
|
|
139
|
+
style.marginLeft = style.marginTop = style.width = style.height = '';
|
|
140
|
+
|
|
141
|
+
if (!isNaN(anchor.x)) { style.marginLeft = `${-anchor.x}px`; }
|
|
142
|
+
if (!isNaN(anchor.y)) { style.marginTop = `${-anchor.y}px`; }
|
|
140
143
|
// the origin of the marker rotation: the anchor, which is the top left corner without one
|
|
141
|
-
|
|
144
|
+
style.transformOrigin = !isNaN(anchor.x) && !isNaN(anchor.y) ? `${anchor.x}px ${anchor.y}px` : '0 0';
|
|
142
145
|
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
img.style.height = `${size.y}px`;
|
|
146
|
-
}
|
|
146
|
+
if (!isNaN(width)) { style.width = `${width}px`; }
|
|
147
|
+
if (!isNaN(height)) { style.height = `${height}px`; }
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
_createImg(src, el) {
|
|
@@ -2,7 +2,6 @@ import {Handler} from '../../core/Handler.js';
|
|
|
2
2
|
import * as DomEvent from '../../dom/DomEvent.js';
|
|
3
3
|
import * as DomUtil from '../../dom/DomUtil.js';
|
|
4
4
|
import {Draggable} from '../../dom/Draggable.js';
|
|
5
|
-
import {Bounds} from '../../geometry/Bounds.js';
|
|
6
5
|
import {Point} from '../../geometry/Point.js';
|
|
7
6
|
|
|
8
7
|
/** @import {Marker, MarkerMoveEvent} from './Marker.js' */
|
|
@@ -87,25 +86,22 @@ export class MarkerDrag extends Handler {
|
|
|
87
86
|
const marker = this._marker,
|
|
88
87
|
map = marker._map,
|
|
89
88
|
speed = this._marker.options.autoPanSpeed,
|
|
90
|
-
padding = this._marker.options.autoPanPadding,
|
|
89
|
+
padding = new Point(this._marker.options.autoPanPadding),
|
|
91
90
|
iconPos = DomUtil.getPosition(marker._icon),
|
|
92
91
|
bounds = map.getPixelBounds(),
|
|
93
|
-
origin = map.getPixelOrigin()
|
|
92
|
+
origin = map.getPixelOrigin(),
|
|
93
|
+
min = bounds.min._subtract(origin)._add(padding),
|
|
94
|
+
max = bounds.max._subtract(origin)._subtract(padding),
|
|
95
|
+
// how far the icon is past the padded bounds on each axis (0 if within)
|
|
96
|
+
dx = Math.max(iconPos.x - max.x, 0) + Math.min(iconPos.x - min.x, 0),
|
|
97
|
+
dy = Math.max(iconPos.y - max.y, 0) + Math.min(iconPos.y - min.y, 0);
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
if (dx || dy) {
|
|
100
|
+
// pan faster the deeper the icon goes into the padding, but not past maxBounds
|
|
101
|
+
const movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed),
|
|
102
|
+
map.options.maxBounds)._round();
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
// Compute incremental movement
|
|
102
|
-
const movement = new Point(
|
|
103
|
-
(Math.max(panBounds.max.x, iconPos.x) - panBounds.max.x) / (bounds.max.x - panBounds.max.x) -
|
|
104
|
-
(Math.min(panBounds.min.x, iconPos.x) - panBounds.min.x) / (bounds.min.x - panBounds.min.x),
|
|
105
|
-
|
|
106
|
-
(Math.max(panBounds.max.y, iconPos.y) - panBounds.max.y) / (bounds.max.y - panBounds.max.y) -
|
|
107
|
-
(Math.min(panBounds.min.y, iconPos.y) - panBounds.min.y) / (bounds.min.y - panBounds.min.y)
|
|
108
|
-
).multiplyBy(speed);
|
|
104
|
+
if (!movement.x && !movement.y) { return; }
|
|
109
105
|
|
|
110
106
|
map.panBy(movement, {animate: false});
|
|
111
107
|
|
|
@@ -140,7 +136,10 @@ export class MarkerDrag extends Handler {
|
|
|
140
136
|
_onDrag(e) {
|
|
141
137
|
const marker = this._marker,
|
|
142
138
|
iconPos = DomUtil.getPosition(marker._icon),
|
|
143
|
-
latlng = marker._map.layerPointToLatLng(iconPos)
|
|
139
|
+
latlng = marker._map.layerPointToLatLng(iconPos),
|
|
140
|
+
{alt} = this._oldLatLng;
|
|
141
|
+
|
|
142
|
+
if (alt !== undefined) { latlng.alt = alt; }
|
|
144
143
|
|
|
145
144
|
// Draggable only moved the icon and dropped its rotation
|
|
146
145
|
marker._positionElements(iconPos);
|
|
@@ -157,7 +156,6 @@ export class MarkerDrag extends Handler {
|
|
|
157
156
|
_onDragEnd(e) {
|
|
158
157
|
cancelAnimationFrame(this._panRequest);
|
|
159
158
|
|
|
160
|
-
delete this._oldLatLng;
|
|
161
159
|
this._marker
|
|
162
160
|
.fire('moveend')
|
|
163
161
|
.fire('dragend', e);
|
|
@@ -5,6 +5,7 @@ import {LatLng} from '../../geo/LatLng.js';
|
|
|
5
5
|
import {Point} from '../../geometry/Point.js';
|
|
6
6
|
import * as DomUtil from '../../dom/DomUtil.js';
|
|
7
7
|
import * as DomEvent from '../../dom/DomEvent.js';
|
|
8
|
+
import {I18n} from '../../core/I18n.js';
|
|
8
9
|
import {MarkerDrag} from './Marker.Drag.js';
|
|
9
10
|
import {pointToGeoJSON} from '../GeoJSONUtil.js';
|
|
10
11
|
/** @import {Feature} from 'geojson' */
|
|
@@ -26,7 +27,8 @@ import {pointToGeoJSON} from '../GeoJSONUtil.js';
|
|
|
26
27
|
* @property {string} [title=''] Text for the browser tooltip that appear on marker hover
|
|
27
28
|
* (no tooltip by default).
|
|
28
29
|
* [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
29
|
-
* @property {string} [alt
|
|
30
|
+
* @property {string} [alt] Text for the `alt` attribute of the icon image, the
|
|
31
|
+
* translation of `'Marker'` by default.
|
|
30
32
|
* [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
31
33
|
* @property {number} [zIndexOffset=0] By default, marker images zIndex is set
|
|
32
34
|
* automatically based on its latitude. Use this option if you want to put the marker on
|
|
@@ -38,9 +40,9 @@ import {pointToGeoJSON} from '../GeoJSONUtil.js';
|
|
|
38
40
|
* marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
|
|
39
41
|
* under a tilted one. `null` means no rotation.
|
|
40
42
|
* @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
|
|
41
|
-
* others
|
|
42
|
-
* @property {number} [riseOffset=250] The z-index offset used
|
|
43
|
-
*
|
|
43
|
+
* others while the pointer is over it. It always does while it has focus.
|
|
44
|
+
* @property {number} [riseOffset=250] The z-index offset used when the marker gets on
|
|
45
|
+
* top of others on hover or focus.
|
|
44
46
|
* @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.
|
|
45
47
|
* @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will
|
|
46
48
|
* be added.
|
|
@@ -99,7 +101,7 @@ export class Marker extends Layer {
|
|
|
99
101
|
|
|
100
102
|
keyboard: true,
|
|
101
103
|
title: '',
|
|
102
|
-
alt:
|
|
104
|
+
alt: undefined,
|
|
103
105
|
zIndexOffset: 0,
|
|
104
106
|
opacity: 1,
|
|
105
107
|
rotation: null,
|
|
@@ -286,7 +288,7 @@ export class Marker extends Layer {
|
|
|
286
288
|
}
|
|
287
289
|
|
|
288
290
|
if (icon instanceof HTMLImageElement) {
|
|
289
|
-
icon.alt = options.alt ?? '';
|
|
291
|
+
icon.alt = options.alt ?? I18n.translate('Marker');
|
|
290
292
|
}
|
|
291
293
|
}
|
|
292
294
|
|
|
@@ -302,11 +304,13 @@ export class Marker extends Layer {
|
|
|
302
304
|
|
|
303
305
|
this._icon = icon;
|
|
304
306
|
|
|
307
|
+
if (this._popup?._source === this) {
|
|
308
|
+
this._popup._updateSourceAria(this._popup.isOpen());
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
DomEvent.on(icon, 'focusin focusout', this._updateRise, this);
|
|
305
312
|
if (options.riseOnHover) {
|
|
306
|
-
|
|
307
|
-
pointerover: this._bringToFront,
|
|
308
|
-
pointerout: this._resetZIndex
|
|
309
|
-
});
|
|
313
|
+
DomEvent.on(icon, 'pointerover pointerout', this._updateRise, this);
|
|
310
314
|
}
|
|
311
315
|
|
|
312
316
|
if (this.options.autoPanOnFocus) {
|
|
@@ -334,21 +338,17 @@ export class Marker extends Layer {
|
|
|
334
338
|
|
|
335
339
|
|
|
336
340
|
if (addIcon) {
|
|
337
|
-
this.getPane().
|
|
341
|
+
this.getPane().append(this._icon);
|
|
338
342
|
}
|
|
339
343
|
this._initInteraction();
|
|
340
344
|
if (newShadow && addShadow) {
|
|
341
|
-
this.getPane(options.shadowPane).
|
|
345
|
+
this.getPane(options.shadowPane).append(this._shadow);
|
|
342
346
|
}
|
|
343
347
|
}
|
|
344
348
|
|
|
345
349
|
_removeIcon() {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
pointerover: this._bringToFront,
|
|
349
|
-
pointerout: this._resetZIndex
|
|
350
|
-
});
|
|
351
|
-
}
|
|
350
|
+
DomEvent.off(this._icon, 'pointerover pointerout focusin focusout', this._updateRise, this);
|
|
351
|
+
this._hovered = this._focused = false;
|
|
352
352
|
|
|
353
353
|
if (this.options.autoPanOnFocus) {
|
|
354
354
|
DomEvent.off(this._icon, 'focus', this._panOnFocus, this);
|
|
@@ -379,9 +379,9 @@ export class Marker extends Layer {
|
|
|
379
379
|
this._culled = !visible;
|
|
380
380
|
|
|
381
381
|
if (visible) {
|
|
382
|
-
this.getPane().
|
|
382
|
+
this.getPane().append(this._icon);
|
|
383
383
|
if (this._shadow) {
|
|
384
|
-
this.getPane(this.options.shadowPane).
|
|
384
|
+
this.getPane(this.options.shadowPane).append(this._shadow);
|
|
385
385
|
}
|
|
386
386
|
this.update();
|
|
387
387
|
} else {
|
|
@@ -400,7 +400,7 @@ export class Marker extends Layer {
|
|
|
400
400
|
|
|
401
401
|
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
402
402
|
|
|
403
|
-
this.
|
|
403
|
+
this._updateRise();
|
|
404
404
|
}
|
|
405
405
|
|
|
406
406
|
_positionElements(pos) {
|
|
@@ -463,40 +463,38 @@ export class Marker extends Layer {
|
|
|
463
463
|
|
|
464
464
|
this.addInteractiveTarget(this._icon);
|
|
465
465
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
466
|
+
// When the icon element is reused, the drag handler still refers to it. Keep that handler, because
|
|
467
|
+
// replacing it ends a drag in progress and forgets that the marker has just been dragged.
|
|
468
|
+
if (this.dragging?._draggable?._element === this._icon) {
|
|
469
|
+
// the icon has reset the class names of the element
|
|
470
|
+
this._icon.classList.toggle('maplair-marker-draggable', this.dragging.enabled());
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
474
473
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
474
|
+
let draggable = this.options.draggable;
|
|
475
|
+
if (this.dragging) {
|
|
476
|
+
draggable = this.dragging.enabled();
|
|
477
|
+
this.dragging.disable();
|
|
478
|
+
}
|
|
480
479
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
480
|
+
/**
|
|
481
|
+
* Marker dragging handler, see `Handler`. Only valid when the marker is on the
|
|
482
|
+
* map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
|
|
483
|
+
*
|
|
484
|
+
* Interaction handlers are properties of a marker instance that allow you to
|
|
485
|
+
* control interaction behavior in runtime, enabling or disabling certain
|
|
486
|
+
* features such as dragging (see `Handler` methods). Example:
|
|
487
|
+
*
|
|
488
|
+
* ```js
|
|
489
|
+
* marker.dragging.disable();
|
|
490
|
+
* ```
|
|
491
|
+
* @group Interaction handlers
|
|
492
|
+
* @type {MarkerDrag}
|
|
493
|
+
*/
|
|
494
|
+
this.dragging = new MarkerDrag(this);
|
|
495
|
+
|
|
496
|
+
if (draggable) {
|
|
497
|
+
this.dragging.enable();
|
|
500
498
|
}
|
|
501
499
|
}
|
|
502
500
|
|
|
@@ -539,14 +537,23 @@ export class Marker extends Layer {
|
|
|
539
537
|
}
|
|
540
538
|
|
|
541
539
|
_updateOpacity() {
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
540
|
+
for (const el of [this._icon, this._shadow]) {
|
|
541
|
+
if (el) {
|
|
542
|
+
el.style.opacity = `${this.options.opacity}`;
|
|
543
|
+
}
|
|
546
544
|
}
|
|
545
|
+
}
|
|
547
546
|
|
|
548
|
-
|
|
549
|
-
|
|
547
|
+
_updateRise(e) {
|
|
548
|
+
if (e?.type.startsWith('pointer')) {
|
|
549
|
+
this._hovered = e.type === 'pointerover';
|
|
550
|
+
} else if (e) {
|
|
551
|
+
this._focused = e.type === 'focusin';
|
|
552
|
+
}
|
|
553
|
+
if (this._hovered || this._focused) {
|
|
554
|
+
this._bringToFront();
|
|
555
|
+
} else {
|
|
556
|
+
this._resetZIndex();
|
|
550
557
|
}
|
|
551
558
|
}
|
|
552
559
|
|
|
@@ -65,10 +65,10 @@ import {LatLngBounds} from '../../geo/LatLngBounds.js';
|
|
|
65
65
|
*/
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* Generic class for handling a tiled grid of HTML elements
|
|
69
|
-
*
|
|
70
|
-
* a tiled grid of
|
|
71
|
-
*
|
|
68
|
+
* Generic class for handling a tiled grid of HTML elements, and the base class of all
|
|
69
|
+
* tile layers. To show map tiles from a URL, use `TileLayer` (or `WMSTileLayer`).
|
|
70
|
+
* Extend `GridLayer` to create a tiled grid of your own elements like `<canvas>`,
|
|
71
|
+
* `<img>` or `<div>`; it handles creating and animating them for you.
|
|
72
72
|
*
|
|
73
73
|
* Layers extending `GridLayer` shall reimplement the [`createTile()`](#gridlayer-createtile)
|
|
74
74
|
* method.
|
|
@@ -280,7 +280,7 @@ export class GridLayer extends Layer {
|
|
|
280
280
|
redraw() {
|
|
281
281
|
if (this._map) {
|
|
282
282
|
this._removeAllTiles();
|
|
283
|
-
const tileZoom = this.
|
|
283
|
+
const tileZoom = this._getTileZoom(this._map.getZoom());
|
|
284
284
|
if (tileZoom !== this._tileZoom) {
|
|
285
285
|
this._tileZoom = tileZoom;
|
|
286
286
|
this._updateLevels();
|
|
@@ -343,7 +343,7 @@ export class GridLayer extends Layer {
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
_updateZIndex() {
|
|
346
|
-
if (this._container && this.options.zIndex
|
|
346
|
+
if (this._container && this.options.zIndex != null) {
|
|
347
347
|
this._container.style.zIndex = `${this.options.zIndex}`;
|
|
348
348
|
}
|
|
349
349
|
}
|
|
@@ -387,7 +387,7 @@ export class GridLayer extends Layer {
|
|
|
387
387
|
this._updateOpacity();
|
|
388
388
|
}
|
|
389
389
|
|
|
390
|
-
this.getPane().
|
|
390
|
+
this.getPane().append(this._container);
|
|
391
391
|
}
|
|
392
392
|
|
|
393
393
|
// Keeps the loaded tiles of the current level visible below the tiles loaded
|
|
@@ -498,9 +498,7 @@ export class GridLayer extends Layer {
|
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
|
|
502
|
-
if (zoom > this.options.maxZoom ||
|
|
503
|
-
zoom < this.options.minZoom) {
|
|
501
|
+
if (this._getTileZoom(this._map.getZoom()) === undefined) {
|
|
504
502
|
this._removeAllTiles();
|
|
505
503
|
return;
|
|
506
504
|
}
|
|
@@ -590,6 +588,14 @@ export class GridLayer extends Layer {
|
|
|
590
588
|
this._setView(e.center, e.zoom, true, e.noUpdate);
|
|
591
589
|
}
|
|
592
590
|
|
|
591
|
+
// The zoom of the tiles for the map zoom `zoom`, or undefined outside of the
|
|
592
|
+
// `minZoom` and `maxZoom` of the layer, also between levels.
|
|
593
|
+
_getTileZoom(zoom) {
|
|
594
|
+
const {minZoom, maxZoom = Infinity} = this.options;
|
|
595
|
+
if (zoom < minZoom || zoom > maxZoom) { return undefined; }
|
|
596
|
+
return this._clampZoom(Math.round(zoom));
|
|
597
|
+
}
|
|
598
|
+
|
|
593
599
|
_clampZoom(zoom) {
|
|
594
600
|
const options = this.options;
|
|
595
601
|
|
|
@@ -605,13 +611,7 @@ export class GridLayer extends Layer {
|
|
|
605
611
|
}
|
|
606
612
|
|
|
607
613
|
_setView(center, zoom, noPrune, noUpdate) {
|
|
608
|
-
|
|
609
|
-
if ((this.options.maxZoom !== undefined && tileZoom > this.options.maxZoom) ||
|
|
610
|
-
(this.options.minZoom !== undefined && tileZoom < this.options.minZoom)) {
|
|
611
|
-
tileZoom = undefined;
|
|
612
|
-
} else {
|
|
613
|
-
tileZoom = this._clampZoom(tileZoom);
|
|
614
|
-
}
|
|
614
|
+
const tileZoom = this._getTileZoom(zoom);
|
|
615
615
|
|
|
616
616
|
const tileZoomChanged = this.options.updateWhenZooming && (tileZoom !== this._tileZoom);
|
|
617
617
|
|
|
@@ -619,9 +619,7 @@ export class GridLayer extends Layer {
|
|
|
619
619
|
|
|
620
620
|
this._tileZoom = tileZoom;
|
|
621
621
|
|
|
622
|
-
|
|
623
|
-
this._abortLoading();
|
|
624
|
-
}
|
|
622
|
+
this._abortLoading?.();
|
|
625
623
|
|
|
626
624
|
this._updateLevels();
|
|
627
625
|
this._resetGrid();
|
|
@@ -769,7 +767,7 @@ export class GridLayer extends Layer {
|
|
|
769
767
|
// sort tile queue to load tiles in order of their distance to center
|
|
770
768
|
queue.sort((a, b) => a.distanceTo(tileCenter) - b.distanceTo(tileCenter));
|
|
771
769
|
|
|
772
|
-
if (queue.length
|
|
770
|
+
if (queue.length) {
|
|
773
771
|
// if it's the first batch of tiles to load
|
|
774
772
|
if (!this._loading) {
|
|
775
773
|
this._loading = true;
|
|
@@ -784,7 +782,7 @@ export class GridLayer extends Layer {
|
|
|
784
782
|
this._addTile(q, fragment);
|
|
785
783
|
}
|
|
786
784
|
|
|
787
|
-
this._level.el.
|
|
785
|
+
this._level.el.append(fragment);
|
|
788
786
|
}
|
|
789
787
|
}
|
|
790
788
|
|
|
@@ -882,7 +880,7 @@ export class GridLayer extends Layer {
|
|
|
882
880
|
current: true
|
|
883
881
|
};
|
|
884
882
|
|
|
885
|
-
container.
|
|
883
|
+
container.append(tile);
|
|
886
884
|
this.fire('tileloadstart', {
|
|
887
885
|
tile,
|
|
888
886
|
coords
|