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/src/layer/DivOverlay.js
CHANGED
|
@@ -12,10 +12,14 @@ import * as DomUtil from '../dom/DomUtil.js';
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an
|
|
15
|
-
* `HTMLElement`, or a function receiving the source layer and
|
|
16
|
-
*
|
|
15
|
+
* `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and
|
|
16
|
+
* returning one of them.
|
|
17
|
+
* @typedef {string|HTMLElement|DocumentFragment|
|
|
18
|
+
* ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent
|
|
17
19
|
*/
|
|
18
20
|
|
|
21
|
+
const fragmentNodes = new WeakMap();
|
|
22
|
+
|
|
19
23
|
/**
|
|
20
24
|
* Options of `DivOverlay`.
|
|
21
25
|
* @typedef {object} DivOverlayOptions
|
|
@@ -31,8 +35,8 @@ import * as DomUtil from '../dom/DomUtil.js';
|
|
|
31
35
|
* in the DOM (for styling and events).
|
|
32
36
|
* @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while
|
|
33
37
|
* initializing. If a function is passed the source layer will be passed to the
|
|
34
|
-
* function. The function should return a `String` or `
|
|
35
|
-
* overlay. String content is rendered as HTML; sanitize untrusted input or pass an
|
|
38
|
+
* function. The function should return a `String`, `HTMLElement` or `DocumentFragment`
|
|
39
|
+
* to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an
|
|
36
40
|
* `HTMLElement` with safe `textContent` instead.
|
|
37
41
|
* @extends InteractiveLayerOptions
|
|
38
42
|
*/
|
|
@@ -75,7 +79,8 @@ const layerDivOverlayMethods = {
|
|
|
75
79
|
/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
|
-
* Base model for Popup and Tooltip
|
|
82
|
+
* Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit
|
|
83
|
+
* from it for custom overlays like plugins.
|
|
79
84
|
*
|
|
80
85
|
* @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
|
|
81
86
|
*/
|
|
@@ -166,10 +171,10 @@ export class DivOverlay extends Layer {
|
|
|
166
171
|
} else {
|
|
167
172
|
layer = this._source;
|
|
168
173
|
}
|
|
169
|
-
this._prepareOpen()
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
if (this._prepareOpen()) {
|
|
175
|
+
// open the overlay on the map
|
|
176
|
+
this.openOn(layer._map);
|
|
177
|
+
}
|
|
173
178
|
}
|
|
174
179
|
return this;
|
|
175
180
|
}
|
|
@@ -188,7 +193,7 @@ export class DivOverlay extends Layer {
|
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
clearTimeout(this._removeTimeout);
|
|
191
|
-
this.getPane().
|
|
196
|
+
this.getPane().append(this._container);
|
|
192
197
|
if (this.options.overflow) {
|
|
193
198
|
this._container.classList.add('maplair-overflow');
|
|
194
199
|
this._container.popover = 'manual';
|
|
@@ -279,10 +284,11 @@ export class DivOverlay extends Layer {
|
|
|
279
284
|
|
|
280
285
|
/**
|
|
281
286
|
* Sets the HTML content of the overlay. A `String` argument is rendered as
|
|
282
|
-
* HTML; if it may contain untrusted input, sanitize it
|
|
283
|
-
*
|
|
284
|
-
* passed
|
|
285
|
-
* return a `String
|
|
287
|
+
* HTML; if it may contain untrusted input, sanitize it or pass an `HTMLElement`
|
|
288
|
+
* with safe `textContent` instead. A `DocumentFragment`
|
|
289
|
+
* can be passed as well. If a function is passed the source layer will be passed
|
|
290
|
+
* to the function. The function should return a `String`, `HTMLElement` or
|
|
291
|
+
* `DocumentFragment` to be used in the overlay.
|
|
286
292
|
* @param {DivOverlayContent} content
|
|
287
293
|
* @returns {this}
|
|
288
294
|
*/
|
|
@@ -341,7 +347,7 @@ export class DivOverlay extends Layer {
|
|
|
341
347
|
* @returns {boolean}
|
|
342
348
|
*/
|
|
343
349
|
isOpen() {
|
|
344
|
-
return !!this._map
|
|
350
|
+
return !!this._map?.hasLayer(this);
|
|
345
351
|
}
|
|
346
352
|
|
|
347
353
|
/**
|
|
@@ -401,17 +407,8 @@ export class DivOverlay extends Layer {
|
|
|
401
407
|
this._source = source;
|
|
402
408
|
}
|
|
403
409
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
latlng = source.getCenter();
|
|
407
|
-
} else if (source.getLatLng) {
|
|
408
|
-
latlng = source.getLatLng();
|
|
409
|
-
} else if (source.getBounds) {
|
|
410
|
-
latlng = source.getBounds().getCenter();
|
|
411
|
-
} else {
|
|
412
|
-
throw new Error('Unable to get source layer LatLng.');
|
|
413
|
-
}
|
|
414
|
-
}
|
|
410
|
+
latlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();
|
|
411
|
+
if (!latlng) { throw new Error('Unable to get source layer LatLng.'); }
|
|
415
412
|
this.setLatLng(latlng);
|
|
416
413
|
|
|
417
414
|
if (this._map) {
|
|
@@ -423,18 +420,19 @@ export class DivOverlay extends Layer {
|
|
|
423
420
|
}
|
|
424
421
|
|
|
425
422
|
_updateContent() {
|
|
426
|
-
if (
|
|
423
|
+
if (this._content == null) { return; }
|
|
427
424
|
|
|
428
425
|
const node = this._contentNode;
|
|
429
426
|
const content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;
|
|
430
427
|
|
|
431
428
|
if (typeof content === 'string') {
|
|
432
429
|
node.innerHTML = content;
|
|
430
|
+
} else if (content instanceof DocumentFragment) {
|
|
431
|
+
// inserting a fragment empties it, so keep its nodes to insert them again on later updates
|
|
432
|
+
if (content.hasChildNodes()) { fragmentNodes.set(content, [...content.childNodes]); }
|
|
433
|
+
node.replaceChildren(...fragmentNodes.get(content) ?? []);
|
|
433
434
|
} else {
|
|
434
|
-
|
|
435
|
-
node.removeChild(node.firstChild);
|
|
436
|
-
}
|
|
437
|
-
node.appendChild(content);
|
|
435
|
+
node.replaceChildren(content);
|
|
438
436
|
}
|
|
439
437
|
|
|
440
438
|
this.fire('contentupdate');
|
|
@@ -443,7 +441,7 @@ export class DivOverlay extends Layer {
|
|
|
443
441
|
_updatePosition() {
|
|
444
442
|
if (!this._map) { return; }
|
|
445
443
|
|
|
446
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
444
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng)),
|
|
447
445
|
offset = Point.from(this.options.offset);
|
|
448
446
|
|
|
449
447
|
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
@@ -94,6 +94,7 @@ export class ImageOverlay extends Layer {
|
|
|
94
94
|
onAdd() {
|
|
95
95
|
if (!this._image) {
|
|
96
96
|
this._initImage();
|
|
97
|
+
this._updateZIndex();
|
|
97
98
|
|
|
98
99
|
if (this.options.opacity < 1) {
|
|
99
100
|
this._updateOpacity();
|
|
@@ -106,7 +107,7 @@ export class ImageOverlay extends Layer {
|
|
|
106
107
|
}
|
|
107
108
|
this._image.classList.toggle('maplair-pixelated', !!this.options.pixelated);
|
|
108
109
|
|
|
109
|
-
this.getPane().
|
|
110
|
+
this.getPane().append(this._image);
|
|
110
111
|
this._reset();
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -151,7 +152,7 @@ export class ImageOverlay extends Layer {
|
|
|
151
152
|
* @returns {this}
|
|
152
153
|
*/
|
|
153
154
|
setStyle(styleOpts) {
|
|
154
|
-
if (styleOpts.opacity) {
|
|
155
|
+
if (styleOpts.opacity != null) {
|
|
155
156
|
this.setOpacity(styleOpts.opacity);
|
|
156
157
|
}
|
|
157
158
|
return this;
|
|
@@ -265,10 +266,6 @@ export class ImageOverlay extends Layer {
|
|
|
265
266
|
|
|
266
267
|
img.decoding = this.options.decoding;
|
|
267
268
|
|
|
268
|
-
if (this.options.zIndex) {
|
|
269
|
-
this._updateZIndex();
|
|
270
|
-
}
|
|
271
|
-
|
|
272
269
|
if (wasElementSupplied) {
|
|
273
270
|
this._url = img.src;
|
|
274
271
|
return;
|
|
@@ -287,9 +284,10 @@ export class ImageOverlay extends Layer {
|
|
|
287
284
|
|
|
288
285
|
_reset() {
|
|
289
286
|
const image = this._image,
|
|
287
|
+
map = this._map,
|
|
290
288
|
bounds = new Bounds(
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
map._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getNorthWest())),
|
|
290
|
+
map._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getSouthEast()))),
|
|
293
291
|
size = bounds.getSize();
|
|
294
292
|
|
|
295
293
|
DomUtil.setPosition(image, bounds.min);
|
|
@@ -303,7 +301,7 @@ export class ImageOverlay extends Layer {
|
|
|
303
301
|
}
|
|
304
302
|
|
|
305
303
|
_updateZIndex() {
|
|
306
|
-
if (this._image && this.options.zIndex
|
|
304
|
+
if (this._image && this.options.zIndex != null) {
|
|
307
305
|
this._image.style.zIndex = `${this.options.zIndex}`;
|
|
308
306
|
}
|
|
309
307
|
}
|
|
@@ -325,4 +323,9 @@ export class ImageOverlay extends Layer {
|
|
|
325
323
|
getCenter() {
|
|
326
324
|
return this._bounds.getCenter();
|
|
327
325
|
}
|
|
326
|
+
|
|
327
|
+
// like on paths, popups open where the overlay was clicked, so another click moves them
|
|
328
|
+
_togglesPopupOnClick() {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
328
331
|
}
|
package/src/layer/Layer.js
CHANGED
|
@@ -170,8 +170,12 @@ const mapLayerMethods = {
|
|
|
170
170
|
|
|
171
171
|
for (const l of Object.values(this._zoomBoundLayers)) {
|
|
172
172
|
const options = l.options;
|
|
173
|
-
minZoom
|
|
174
|
-
|
|
173
|
+
if (options.minZoom != null && !Number.isNaN(options.minZoom)) {
|
|
174
|
+
minZoom = Math.min(minZoom, options.minZoom);
|
|
175
|
+
}
|
|
176
|
+
if (options.maxZoom != null && !Number.isNaN(options.maxZoom)) {
|
|
177
|
+
maxZoom = Math.max(maxZoom, options.maxZoom);
|
|
178
|
+
}
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
this._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;
|
|
@@ -181,7 +185,7 @@ const mapLayerMethods = {
|
|
|
181
185
|
this.fire('zoomlevelschange');
|
|
182
186
|
}
|
|
183
187
|
|
|
184
|
-
if (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) {
|
|
188
|
+
if (this.options.maxZoom === undefined && this._layersMaxZoom !== undefined && this.getZoom() > this._layersMaxZoom) {
|
|
185
189
|
this.setZoom(this._layersMaxZoom);
|
|
186
190
|
}
|
|
187
191
|
if (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {
|
|
@@ -315,8 +319,10 @@ export class Layer extends Evented {
|
|
|
315
319
|
_updateInteractive() {}
|
|
316
320
|
|
|
317
321
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
322
|
+
* Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and
|
|
323
|
+
* keyboard events on it (or its descendants) fire on the layer and bubble through its
|
|
324
|
+
* parent groups to the map, the way they do for markers and paths. Custom layers call
|
|
325
|
+
* it in [`onAdd`](#layer-onadd), once the layer is on a map.
|
|
320
326
|
* @param {HTMLElement} targetEl
|
|
321
327
|
* @returns {this}
|
|
322
328
|
*/
|
|
@@ -326,8 +332,8 @@ export class Layer extends Evented {
|
|
|
326
332
|
}
|
|
327
333
|
|
|
328
334
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
335
|
+
* Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in
|
|
336
|
+
* [`onRemove`](#layer-onremove).
|
|
331
337
|
* @param {HTMLElement} targetEl
|
|
332
338
|
* @returns {this}
|
|
333
339
|
*/
|
|
@@ -336,6 +342,12 @@ export class Layer extends Evented {
|
|
|
336
342
|
return this;
|
|
337
343
|
}
|
|
338
344
|
|
|
345
|
+
// Whether clicking the layer again closes its popup, rather than moving it to the
|
|
346
|
+
// clicked point like on paths, where the popup opens where they were clicked.
|
|
347
|
+
_togglesPopupOnClick() {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
|
|
339
351
|
/**
|
|
340
352
|
* Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).
|
|
341
353
|
* @returns {string|null}
|
package/src/layer/Popup.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {DivOverlay} from './DivOverlay.js';
|
|
2
2
|
import * as DomEvent from '../dom/DomEvent.js';
|
|
3
3
|
import * as DomUtil from '../dom/DomUtil.js';
|
|
4
|
+
import * as Util from '../core/Util.js';
|
|
4
5
|
import {Point} from '../geometry/Point.js';
|
|
5
6
|
import {Layer} from './Layer.js';
|
|
6
|
-
import {Path} from './vector/Path.js';
|
|
7
7
|
import {FeatureGroup} from './FeatureGroup.js';
|
|
8
8
|
import {I18n} from '../core/I18n.js';
|
|
9
9
|
|
|
@@ -124,10 +124,10 @@ const layerPopupMethods = {
|
|
|
124
124
|
/**
|
|
125
125
|
* Binds a popup to the layer with the passed `content` and sets up the
|
|
126
126
|
* necessary event listeners. A `String` argument is rendered as HTML; if it
|
|
127
|
-
* may contain untrusted input, sanitize it
|
|
128
|
-
* `
|
|
127
|
+
* may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
|
|
128
|
+
* `textContent` instead. If a `Function` is passed
|
|
129
129
|
* it will receive the layer as the first argument and should return a
|
|
130
|
-
* `String` or `
|
|
130
|
+
* `String`, `HTMLElement` or `DocumentFragment`.
|
|
131
131
|
* @group Popup methods
|
|
132
132
|
* @param {DivOverlayContent|Popup} content
|
|
133
133
|
* @param {PopupOptions} [options]
|
|
@@ -136,6 +136,7 @@ const layerPopupMethods = {
|
|
|
136
136
|
bindPopup(content, options) {
|
|
137
137
|
// eslint-disable-next-line no-use-before-define -- defined below, used when called
|
|
138
138
|
this._popup = this._initOverlay(Popup, this._popup, content, options);
|
|
139
|
+
this._popup._updateSourceAria(this._popup.isOpen());
|
|
139
140
|
this.on({
|
|
140
141
|
click: this._openPopup,
|
|
141
142
|
remove: this.closePopup,
|
|
@@ -157,6 +158,9 @@ const layerPopupMethods = {
|
|
|
157
158
|
remove: this.closePopup,
|
|
158
159
|
move: this._movePopup
|
|
159
160
|
});
|
|
161
|
+
const el = this.getElement?.();
|
|
162
|
+
el?.removeAttribute('aria-expanded');
|
|
163
|
+
el?.removeAttribute('aria-controls');
|
|
160
164
|
this._popup = null;
|
|
161
165
|
}
|
|
162
166
|
return this;
|
|
@@ -241,14 +245,9 @@ const layerPopupMethods = {
|
|
|
241
245
|
DomEvent.stopPropagation(e);
|
|
242
246
|
|
|
243
247
|
const target = e.propagatedFrom ?? e.target;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (this._map.hasLayer(this._popup)) {
|
|
248
|
-
this.closePopup();
|
|
249
|
-
} else {
|
|
250
|
-
this.openPopup(e.latlng);
|
|
251
|
-
}
|
|
248
|
+
// clicking a marker-like source again toggles its popup closed
|
|
249
|
+
if (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {
|
|
250
|
+
this.closePopup();
|
|
252
251
|
return;
|
|
253
252
|
}
|
|
254
253
|
this._popup._source = target;
|
|
@@ -290,8 +289,7 @@ const layerPopupMethods = {
|
|
|
290
289
|
*
|
|
291
290
|
* **Security note.** Popup string content is rendered as HTML. If your content
|
|
292
291
|
* may include untrusted input (e.g. data from users or external APIs), sanitize
|
|
293
|
-
* it
|
|
294
|
-
* build a DOM element using `textContent` to render it as plain text:
|
|
292
|
+
* it first, or build a DOM element using `textContent` to render it as plain text:
|
|
295
293
|
*
|
|
296
294
|
* ```js
|
|
297
295
|
* const el = document.createElement('div');
|
|
@@ -351,12 +349,14 @@ export class Popup extends DivOverlay {
|
|
|
351
349
|
openOn(map) {
|
|
352
350
|
map = arguments.length ? map : this._source._map; // experimental, not the part of public api
|
|
353
351
|
|
|
354
|
-
if (!map.hasLayer(this) && map._popup
|
|
352
|
+
if (!map.hasLayer(this) && map._popup?.options.autoClose) {
|
|
355
353
|
map.removeLayer(map._popup);
|
|
356
354
|
}
|
|
357
355
|
map._popup = this;
|
|
358
356
|
|
|
359
|
-
|
|
357
|
+
super.openOn(map);
|
|
358
|
+
this._updateSourceAria(true); // the source may have changed while open, e.g. within a FeatureGroup
|
|
359
|
+
return this;
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
/**
|
|
@@ -379,12 +379,13 @@ export class Popup extends DivOverlay {
|
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
map.fire('popupopen', {popup: this});
|
|
382
|
+
this._updateSourceAria(true);
|
|
382
383
|
|
|
383
384
|
if (this._source) {
|
|
384
385
|
this._source.fire('popupopen', {popup: this}, true);
|
|
385
386
|
// For non-path layers, we toggle the popup when clicking
|
|
386
387
|
// again the layer, so prevent the map to reopen it.
|
|
387
|
-
if (
|
|
388
|
+
if (this._source._togglesPopupOnClick()) {
|
|
388
389
|
this._source.on('preclick', DomEvent.stopPropagation);
|
|
389
390
|
}
|
|
390
391
|
}
|
|
@@ -395,18 +396,23 @@ export class Popup extends DivOverlay {
|
|
|
395
396
|
* @param {MaplairMap} map
|
|
396
397
|
*/
|
|
397
398
|
onRemove(map) {
|
|
398
|
-
|
|
399
|
-
|
|
399
|
+
// closing removes the focused element, which would send focus back to the start of the page
|
|
400
|
+
if (this._container.contains(document.activeElement)) {
|
|
401
|
+
const el = this._source?.getElement?.();
|
|
402
|
+
const target = this._returnFocus?.isConnected ? this._returnFocus :
|
|
403
|
+
el?.tabIndex >= 0 ? el : map._container;
|
|
404
|
+
target.focus({preventScroll: true});
|
|
400
405
|
}
|
|
401
406
|
this._returnFocus = null;
|
|
402
407
|
|
|
403
408
|
super.onRemove(map);
|
|
404
409
|
|
|
405
410
|
map.fire('popupclose', {popup: this});
|
|
411
|
+
this._updateSourceAria(false);
|
|
406
412
|
|
|
407
413
|
if (this._source) {
|
|
408
414
|
this._source.fire('popupclose', {popup: this}, true);
|
|
409
|
-
if (
|
|
415
|
+
if (this._source._togglesPopupOnClick()) {
|
|
410
416
|
this._source.off('preclick', DomEvent.stopPropagation);
|
|
411
417
|
}
|
|
412
418
|
}
|
|
@@ -430,10 +436,24 @@ export class Popup extends DivOverlay {
|
|
|
430
436
|
return events;
|
|
431
437
|
}
|
|
432
438
|
|
|
439
|
+
// Marks a source that acts as a button (e.g. a keyboard-accessible marker) as a
|
|
440
|
+
// disclosure for the popup.
|
|
441
|
+
_updateSourceAria(open) {
|
|
442
|
+
this._ariaSource?.setAttribute('aria-expanded', 'false');
|
|
443
|
+
this._ariaSource?.removeAttribute('aria-controls');
|
|
444
|
+
|
|
445
|
+
const el = this._source?.getElement?.();
|
|
446
|
+
this._ariaSource = el?.getAttribute('role') === 'button' ? el : null;
|
|
447
|
+
this._ariaSource?.setAttribute('aria-expanded', String(open));
|
|
448
|
+
if (open) { this._ariaSource?.setAttribute('aria-controls', this._container.id); }
|
|
449
|
+
}
|
|
450
|
+
|
|
433
451
|
_initLayout() {
|
|
434
452
|
const prefix = 'maplair-popup',
|
|
435
453
|
container = this._container = DomUtil.create('div', `${prefix} ${this.options.className || ''} maplair-zoom-animated`);
|
|
436
454
|
|
|
455
|
+
container.id = `maplair-popup-${Util.stamp(this)}`;
|
|
456
|
+
|
|
437
457
|
const wrapper = this._wrapper = DomUtil.create('div', `${prefix}-content-wrapper`, container);
|
|
438
458
|
this._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);
|
|
439
459
|
|
|
@@ -449,7 +469,7 @@ export class Popup extends DivOverlay {
|
|
|
449
469
|
closeButton.type = 'button';
|
|
450
470
|
closeButton.setAttribute('aria-label', I18n.translate('Close popup'));
|
|
451
471
|
|
|
452
|
-
closeButton.
|
|
472
|
+
closeButton.textContent = '\u00D7';
|
|
453
473
|
|
|
454
474
|
DomEvent.on(closeButton, 'click', (ev) => {
|
|
455
475
|
ev.preventDefault();
|
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.
|
|
@@ -34,7 +35,8 @@ function clampTip(tipShift, size) {
|
|
|
34
35
|
* Options of `Tooltip`.
|
|
35
36
|
* @typedef {object} TooltipOptions
|
|
36
37
|
* @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.
|
|
37
|
-
* @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position
|
|
38
|
+
* @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position, in
|
|
39
|
+
* pixels. Mirrored horizontally when an `auto` tooltip opens to the left.
|
|
38
40
|
* @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']
|
|
39
41
|
* Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,
|
|
40
42
|
* `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when
|
|
@@ -111,10 +113,10 @@ const layerTooltipMethods = {
|
|
|
111
113
|
/**
|
|
112
114
|
* Binds a tooltip to the layer with the passed `content` and sets up the
|
|
113
115
|
* necessary event listeners. A `String` argument is rendered as HTML; if it
|
|
114
|
-
* may contain untrusted input, sanitize it
|
|
115
|
-
* `
|
|
116
|
+
* may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
|
|
117
|
+
* `textContent` instead. If a `Function` is passed
|
|
116
118
|
* it will receive the layer as the first argument and should return a
|
|
117
|
-
* `String` or `
|
|
119
|
+
* `String`, `HTMLElement` or `DocumentFragment`.
|
|
118
120
|
* @group Tooltip methods
|
|
119
121
|
* @param {DivOverlayContent|Tooltip} content
|
|
120
122
|
* @param {TooltipOptions} [options]
|
|
@@ -133,7 +135,7 @@ const layerTooltipMethods = {
|
|
|
133
135
|
this._tooltip = this._initOverlay(Tooltip, old, content, options);
|
|
134
136
|
this._initTooltipInteractions();
|
|
135
137
|
|
|
136
|
-
if (this._tooltip.options.permanent && this._map
|
|
138
|
+
if (this._tooltip.options.permanent && this._map?.hasLayer(this)) {
|
|
137
139
|
this.openTooltip();
|
|
138
140
|
}
|
|
139
141
|
|
|
@@ -193,12 +195,6 @@ const layerTooltipMethods = {
|
|
|
193
195
|
if (this._tooltip._prepareOpen(latlng)) {
|
|
194
196
|
// open the tooltip on the map
|
|
195
197
|
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
198
|
}
|
|
203
199
|
}
|
|
204
200
|
return this;
|
|
@@ -272,8 +268,10 @@ const layerTooltipMethods = {
|
|
|
272
268
|
// Remove focus listener, if already existing
|
|
273
269
|
el._maplair_focus_handler && DomEvent.off(el, 'focus', el._maplair_focus_handler, this);
|
|
274
270
|
|
|
271
|
+
// open only on keyboard focus: an element clicked with the mouse keeps focus and gets it again whenever
|
|
272
|
+
// the window is refocused or a popup closes, which would open the tooltip without the pointer over it
|
|
275
273
|
el._maplair_focus_handler = () => {
|
|
276
|
-
if (this._tooltip) {
|
|
274
|
+
if (this._tooltip && el.matches(':focus-visible')) {
|
|
277
275
|
this._tooltip._source = layer;
|
|
278
276
|
this.openTooltip();
|
|
279
277
|
}
|
|
@@ -289,11 +287,6 @@ const layerTooltipMethods = {
|
|
|
289
287
|
}
|
|
290
288
|
},
|
|
291
289
|
|
|
292
|
-
_setAriaDescribedByOnLayer(layer) {
|
|
293
|
-
const el = typeof layer.getElement === 'function' && layer.getElement();
|
|
294
|
-
el?.setAttribute?.('aria-describedby', this._tooltip._container.id);
|
|
295
|
-
},
|
|
296
|
-
|
|
297
290
|
_openTooltip(e) {
|
|
298
291
|
if (!this._tooltip || !this._map) {
|
|
299
292
|
return;
|
|
@@ -317,13 +310,8 @@ const layerTooltipMethods = {
|
|
|
317
310
|
},
|
|
318
311
|
|
|
319
312
|
_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);
|
|
313
|
+
this._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ?
|
|
314
|
+
this._map.pointerEventToLatLng(e.originalEvent) : e.latlng);
|
|
327
315
|
}
|
|
328
316
|
};
|
|
329
317
|
/** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */
|
|
@@ -355,8 +343,7 @@ const layerTooltipMethods = {
|
|
|
355
343
|
*
|
|
356
344
|
* **Security note.** Tooltip string content is rendered as HTML. If your content
|
|
357
345
|
* may include untrusted input (e.g. data from users or external APIs), sanitize
|
|
358
|
-
* it
|
|
359
|
-
* build a DOM element using `textContent` to render it as plain text:
|
|
346
|
+
* it first, or build a DOM element using `textContent` to render it as plain text:
|
|
360
347
|
*
|
|
361
348
|
* ```js
|
|
362
349
|
* const el = document.createElement('div');
|
|
@@ -418,6 +405,8 @@ export class Tooltip extends DivOverlay {
|
|
|
418
405
|
|
|
419
406
|
if (this._source) {
|
|
420
407
|
this.addEventParent(this._source);
|
|
408
|
+
this._ariaSource = this._source.getElement?.();
|
|
409
|
+
this._ariaSource?.setAttribute('aria-describedby', this._container.id);
|
|
421
410
|
|
|
422
411
|
this._source.fire('tooltipopen', {tooltip: this}, true);
|
|
423
412
|
}
|
|
@@ -435,6 +424,11 @@ export class Tooltip extends DivOverlay {
|
|
|
435
424
|
if (this._source) {
|
|
436
425
|
this.removeEventParent(this._source);
|
|
437
426
|
|
|
427
|
+
// drop the reference to the removed tooltip unless something else replaced it since
|
|
428
|
+
const el = this._ariaSource;
|
|
429
|
+
if (el?.getAttribute('aria-describedby') === this._container.id) { el.removeAttribute('aria-describedby'); }
|
|
430
|
+
this._ariaSource = null;
|
|
431
|
+
|
|
438
432
|
this._source.fire('tooltipclose', {tooltip: this}, true);
|
|
439
433
|
}
|
|
440
434
|
}
|
|
@@ -460,7 +454,7 @@ export class Tooltip extends DivOverlay {
|
|
|
460
454
|
this._contentNode = this._container = DomUtil.create('div', className);
|
|
461
455
|
|
|
462
456
|
this._container.setAttribute('role', 'tooltip');
|
|
463
|
-
this._container.
|
|
457
|
+
this._container.id = `maplair-tooltip-${Util.stamp(this)}`;
|
|
464
458
|
}
|
|
465
459
|
|
|
466
460
|
_updateLayout() {}
|
|
@@ -484,39 +478,21 @@ export class Tooltip extends DivOverlay {
|
|
|
484
478
|
const container = this._container,
|
|
485
479
|
tooltipWidth = container.offsetWidth,
|
|
486
480
|
tooltipHeight = container.offsetHeight,
|
|
487
|
-
offset = new Point(this.options.offset)
|
|
488
|
-
anchor = this._getAnchor();
|
|
489
|
-
|
|
490
|
-
if (!directions.includes(direction)) {
|
|
491
|
-
({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));
|
|
492
|
-
if (direction === 'left') {
|
|
493
|
-
// mirror the offset and anchor, which are meant for the right side
|
|
494
|
-
offset.x = -offset.x;
|
|
495
|
-
anchor.x = -anchor.x;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
481
|
+
offset = new Point(this.options.offset);
|
|
498
482
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
} else if (direction === 'bottom') {
|
|
504
|
-
subY = 0;
|
|
505
|
-
} else if (direction === 'right') {
|
|
506
|
-
subX = 0;
|
|
507
|
-
} else if (direction === 'left') {
|
|
508
|
-
subX = tooltipWidth;
|
|
483
|
+
if (!(direction in directions)) {
|
|
484
|
+
({direction, shift} = this._getAutoPlacement(pos, offset, tooltipWidth, tooltipHeight));
|
|
485
|
+
// mirror the offset, which is meant for the right side
|
|
486
|
+
if (direction === 'left') { offset.x = -offset.x; }
|
|
509
487
|
}
|
|
488
|
+
const anchor = this._getAnchor(direction);
|
|
510
489
|
|
|
511
|
-
|
|
490
|
+
const [fx, fy] = directions[direction];
|
|
491
|
+
pos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);
|
|
512
492
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
'maplair-tooltip-top',
|
|
517
|
-
'maplair-tooltip-bottom'
|
|
518
|
-
);
|
|
519
|
-
container.classList.add(`maplair-tooltip-${direction}`);
|
|
493
|
+
for (const d in directions) {
|
|
494
|
+
container.classList.toggle(`maplair-tooltip-${d}`, d === direction);
|
|
495
|
+
}
|
|
520
496
|
|
|
521
497
|
// Let the tip point at the source despite the shift
|
|
522
498
|
const tipShift = direction === 'top' || direction === 'bottom' ?
|
|
@@ -534,17 +510,20 @@ export class Tooltip extends DivOverlay {
|
|
|
534
510
|
// Chooses the direction of an `auto` tooltip by the available space:
|
|
535
511
|
// preferably the side towards the center, otherwise the opposite side,
|
|
536
512
|
// above or below. The tooltip is shifted along that side to stay in view.
|
|
537
|
-
_getAutoPlacement(pos, offset,
|
|
513
|
+
_getAutoPlacement(pos, offset, width, height) {
|
|
538
514
|
const area = this._getAutoArea(),
|
|
539
515
|
point = this._map.layerPointToContainerPoint(pos),
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
516
|
+
// where the tooltip attaches for each direction, with the offset mirrored on the left side
|
|
517
|
+
at = {};
|
|
518
|
+
for (const d of ['right', 'left', 'top', 'bottom']) {
|
|
519
|
+
at[d] = point.add(this._getAnchor(d)).add(d === 'left' ? [-offset.x, offset.y] : offset);
|
|
520
|
+
}
|
|
521
|
+
// the space for each direction
|
|
522
|
+
const space = {
|
|
523
|
+
right: area.max.x - at.right.x - width - tipSize,
|
|
524
|
+
left: at.left.x - area.min.x - width - tipSize,
|
|
525
|
+
top: at.top.y - area.min.y - height - tipSize,
|
|
526
|
+
bottom: area.max.y - at.bottom.y - height - tipSize
|
|
548
527
|
};
|
|
549
528
|
|
|
550
529
|
if (!this._autoDirection) {
|
|
@@ -556,6 +535,7 @@ export class Tooltip extends DivOverlay {
|
|
|
556
535
|
}
|
|
557
536
|
|
|
558
537
|
const direction = this._autoDirection,
|
|
538
|
+
{x, y} = at[direction],
|
|
559
539
|
shift = direction === 'top' || direction === 'bottom' ?
|
|
560
540
|
new Point(shiftInto(x - width / 2, width, area.min.x, area.max.x), 0) :
|
|
561
541
|
new Point(0, shiftInto(y - height / 2, height, area.min.y, area.max.y));
|
|
@@ -582,7 +562,7 @@ export class Tooltip extends DivOverlay {
|
|
|
582
562
|
}
|
|
583
563
|
|
|
584
564
|
_updatePosition() {
|
|
585
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
565
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
|
|
586
566
|
this._setPosition(pos);
|
|
587
567
|
}
|
|
588
568
|
|
|
@@ -604,9 +584,9 @@ export class Tooltip extends DivOverlay {
|
|
|
604
584
|
this._setPosition(pos);
|
|
605
585
|
}
|
|
606
586
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);
|
|
587
|
+
// Where the tooltip opening in the given direction attaches on the source layer
|
|
588
|
+
_getAnchor(direction) {
|
|
589
|
+
return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor(direction) : [0, 0]);
|
|
610
590
|
}
|
|
611
591
|
|
|
612
592
|
/**
|