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/esm/layer/Popup.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { stamp } from "../core/Util.js";
|
|
1
2
|
import { Point } from "../geometry/Point.js";
|
|
2
3
|
import { disableClickPropagation, disableScrollPropagation, on, stopPropagation } from "../dom/DomEvent.js";
|
|
3
4
|
import { create } from "../dom/DomUtil.js";
|
|
4
5
|
import { I18n } from "../core/I18n.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 { DivOverlay } from "./DivOverlay.js";
|
|
9
9
|
// src/layer/Popup.js
|
|
@@ -116,10 +116,10 @@ const layerPopupMethods = {
|
|
|
116
116
|
/**
|
|
117
117
|
* Binds a popup to the layer with the passed `content` and sets up the
|
|
118
118
|
* necessary event listeners. A `String` argument is rendered as HTML; if it
|
|
119
|
-
* may contain untrusted input, sanitize it
|
|
120
|
-
* `
|
|
119
|
+
* may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
|
|
120
|
+
* `textContent` instead. If a `Function` is passed
|
|
121
121
|
* it will receive the layer as the first argument and should return a
|
|
122
|
-
* `String` or `
|
|
122
|
+
* `String`, `HTMLElement` or `DocumentFragment`.
|
|
123
123
|
* @group Popup methods
|
|
124
124
|
* @param {DivOverlayContent|Popup} content
|
|
125
125
|
* @param {PopupOptions} [options]
|
|
@@ -127,6 +127,7 @@ const layerPopupMethods = {
|
|
|
127
127
|
*/
|
|
128
128
|
bindPopup(content, options) {
|
|
129
129
|
this._popup = this._initOverlay(Popup, this._popup, content, options);
|
|
130
|
+
this._popup._updateSourceAria(this._popup.isOpen());
|
|
130
131
|
this.on({
|
|
131
132
|
click: this._openPopup,
|
|
132
133
|
remove: this.closePopup,
|
|
@@ -146,6 +147,9 @@ const layerPopupMethods = {
|
|
|
146
147
|
remove: this.closePopup,
|
|
147
148
|
move: this._movePopup
|
|
148
149
|
});
|
|
150
|
+
const el = this.getElement?.();
|
|
151
|
+
el?.removeAttribute("aria-expanded");
|
|
152
|
+
el?.removeAttribute("aria-controls");
|
|
149
153
|
this._popup = null;
|
|
150
154
|
}
|
|
151
155
|
return this;
|
|
@@ -214,9 +218,8 @@ const layerPopupMethods = {
|
|
|
214
218
|
if (!this._popup || !this._map) return;
|
|
215
219
|
stopPropagation(e);
|
|
216
220
|
const target = e.propagatedFrom ?? e.target;
|
|
217
|
-
if (this._popup._source === target &&
|
|
218
|
-
|
|
219
|
-
else this.openPopup(e.latlng);
|
|
221
|
+
if (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {
|
|
222
|
+
this.closePopup();
|
|
220
223
|
return;
|
|
221
224
|
}
|
|
222
225
|
this._popup._source = target;
|
|
@@ -256,8 +259,7 @@ const layerPopupMethods = {
|
|
|
256
259
|
*
|
|
257
260
|
* **Security note.** Popup string content is rendered as HTML. If your content
|
|
258
261
|
* may include untrusted input (e.g. data from users or external APIs), sanitize
|
|
259
|
-
* it
|
|
260
|
-
* build a DOM element using `textContent` to render it as plain text:
|
|
262
|
+
* it first, or build a DOM element using `textContent` to render it as plain text:
|
|
261
263
|
*
|
|
262
264
|
* ```js
|
|
263
265
|
* const el = document.createElement('div');
|
|
@@ -313,9 +315,11 @@ var Popup = class Popup extends DivOverlay {
|
|
|
313
315
|
*/
|
|
314
316
|
openOn(map) {
|
|
315
317
|
map = arguments.length ? map : this._source._map;
|
|
316
|
-
if (!map.hasLayer(this) && map._popup
|
|
318
|
+
if (!map.hasLayer(this) && map._popup?.options.autoClose) map.removeLayer(map._popup);
|
|
317
319
|
map._popup = this;
|
|
318
|
-
|
|
320
|
+
super.openOn(map);
|
|
321
|
+
this._updateSourceAria(true);
|
|
322
|
+
return this;
|
|
319
323
|
}
|
|
320
324
|
/**
|
|
321
325
|
* Adds the popup to the map.
|
|
@@ -330,9 +334,10 @@ var Popup = class Popup extends DivOverlay {
|
|
|
330
334
|
(this._closeButton ?? this._container).focus({ preventScroll: true });
|
|
331
335
|
}
|
|
332
336
|
map.fire("popupopen", { popup: this });
|
|
337
|
+
this._updateSourceAria(true);
|
|
333
338
|
if (this._source) {
|
|
334
339
|
this._source.fire("popupopen", { popup: this }, true);
|
|
335
|
-
if (
|
|
340
|
+
if (this._source._togglesPopupOnClick()) this._source.on("preclick", stopPropagation);
|
|
336
341
|
}
|
|
337
342
|
}
|
|
338
343
|
/**
|
|
@@ -340,13 +345,17 @@ var Popup = class Popup extends DivOverlay {
|
|
|
340
345
|
* @param {MaplairMap} map
|
|
341
346
|
*/
|
|
342
347
|
onRemove(map) {
|
|
343
|
-
if (this._container.contains(document.activeElement)
|
|
348
|
+
if (this._container.contains(document.activeElement)) {
|
|
349
|
+
const el = this._source?.getElement?.();
|
|
350
|
+
(this._returnFocus?.isConnected ? this._returnFocus : el?.tabIndex >= 0 ? el : map._container).focus({ preventScroll: true });
|
|
351
|
+
}
|
|
344
352
|
this._returnFocus = null;
|
|
345
353
|
super.onRemove(map);
|
|
346
354
|
map.fire("popupclose", { popup: this });
|
|
355
|
+
this._updateSourceAria(false);
|
|
347
356
|
if (this._source) {
|
|
348
357
|
this._source.fire("popupclose", { popup: this }, true);
|
|
349
|
-
if (
|
|
358
|
+
if (this._source._togglesPopupOnClick()) this._source.off("preclick", stopPropagation);
|
|
350
359
|
}
|
|
351
360
|
}
|
|
352
361
|
/**
|
|
@@ -359,8 +368,17 @@ var Popup = class Popup extends DivOverlay {
|
|
|
359
368
|
if (this.options.keepInView) events.moveend = this._adjustPan;
|
|
360
369
|
return events;
|
|
361
370
|
}
|
|
371
|
+
_updateSourceAria(open) {
|
|
372
|
+
this._ariaSource?.setAttribute("aria-expanded", "false");
|
|
373
|
+
this._ariaSource?.removeAttribute("aria-controls");
|
|
374
|
+
const el = this._source?.getElement?.();
|
|
375
|
+
this._ariaSource = el?.getAttribute("role") === "button" ? el : null;
|
|
376
|
+
this._ariaSource?.setAttribute("aria-expanded", String(open));
|
|
377
|
+
if (open) this._ariaSource?.setAttribute("aria-controls", this._container.id);
|
|
378
|
+
}
|
|
362
379
|
_initLayout() {
|
|
363
380
|
const prefix = "maplair-popup", container = this._container = create("div", `${prefix} ${this.options.className || ""} maplair-zoom-animated`);
|
|
381
|
+
container.id = `maplair-popup-${stamp(this)}`;
|
|
364
382
|
const wrapper = this._wrapper = create("div", `${prefix}-content-wrapper`, container);
|
|
365
383
|
this._contentNode = create("div", `${prefix}-content`, wrapper);
|
|
366
384
|
disableClickPropagation(container);
|
|
@@ -372,7 +390,7 @@ var Popup = class Popup extends DivOverlay {
|
|
|
372
390
|
const closeButton = this._closeButton = create("button", `${prefix}-close-button`, container);
|
|
373
391
|
closeButton.type = "button";
|
|
374
392
|
closeButton.setAttribute("aria-label", I18n.translate("Close popup"));
|
|
375
|
-
closeButton.
|
|
393
|
+
closeButton.textContent = "×";
|
|
376
394
|
on(closeButton, "click", (ev) => {
|
|
377
395
|
ev.preventDefault();
|
|
378
396
|
this.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popup.js","names":["DomEvent.stopPropagation","DomUtil.create"],"sources":["../../../src/layer/Popup.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport {Path} from './vector/Path.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport {I18n} from '../core/I18n.js';\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent, PopupEvent} from '../core/Events.js' */\n\n/**\n * Options of `Popup`.\n * @typedef {object} PopupOptions\n * @property {string} [pane='popupPane'] `Map pane` where the popup will be added.\n * @property {PointExpression} [offset=[0, 7]] The offset of the popup position.\n * @property {number} [maxWidth=300] Max width of the popup, in pixels.\n * @property {number} [minWidth=50] Min width of the popup, in pixels.\n * @property {number|null} [maxHeight=null] If set, creates a scrollable container of\n * the given height inside a popup if its content exceeds it. The scrollable container\n * can be styled using the `maplair-popup-scrolled` CSS class selector.\n * @property {boolean} [autoPan=true] Set it to `false` if you don't want the map to do\n * panning animation to fit the opened popup.\n * @property {PointExpression|null} [autoPanPaddingTopLeft=null] The margin between the\n * popup and the top left corner of the map view after autopanning was performed.\n * @property {PointExpression|null} [autoPanPaddingBottomRight=null] The margin between\n * the popup and the bottom right corner of the map view after autopanning was\n * performed.\n * @property {PointExpression} [autoPanPadding=[5, 5]] Equivalent of setting both top\n * left and bottom right autopan padding to the same value.\n * @property {boolean} [keepInView=false] Set it to `true` if you want to prevent users\n * from panning the popup off of the screen while it is open.\n * @property {boolean} [closeButton=true] Controls the presence of a close button in\n * the popup.\n * @property {boolean} [autoClose=true] Set it to `false` if you want to override the\n * default behavior of the popup closing when another popup is opened.\n * @property {boolean} [closeOnEscapeKey=true] Set it to `false` if you want to\n * override the default behavior of the ESC key for closing of the popup.\n * @property {boolean} [closeOnClick] Set it if you want to override the default\n * behavior of the popup closing when user clicks on the map. Defaults to the map's\n * [`closePopupOnClick`](#map-closepopuponclick) option.\n * @property {string} [className=''] A custom CSS class name to assign to the popup.\n * @property {boolean} [trackResize=true] Whether the popup shall react to changes in\n * the size of its contents (e.g. when an image inside the popup loads) and reposition\n * itself.\n * @extends DivOverlayOptions\n */\n\n/**\n * Map options of `Popup`.\n * @typedef {object} PopupMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [closePopupOnClick=true] Set it to `false` if you don't want\n * popups to close when user clicks the map.\n */\n\n/**\n * Methods of `MaplairMap` for popups.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#popupopen {PopupEvent} Fired when a popup is opened in the map.\n * @fires MaplairMap#popupclose {PopupEvent} Fired when a popup in the map is closed.\n * @fires MaplairMap#autopanstart {MaplairEvent} Fired when the map starts autopanning\n * when opening a popup.\n */\nconst mapPopupMethods = {\n\t/**\n\t * Opens the specified popup while closing the previously opened (to make sure only\n\t * one is opened at one time for usability).\n\t *\n\t * Alternatively, creates a popup with the specified content and options and opens\n\t * it in the given point on a map. String content is rendered as HTML; sanitize\n\t * untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Popup|DivOverlayContent} popup The popup, or the content of a new popup.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\topenPopup(popup, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Popup, popup, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup previously opened with [openPopup](#map-openpopup) (or the\n\t * given one).\n\t * @group Methods for layers and controls\n\t * @param {Popup} [popup]\n\t * @returns {this}\n\t */\n\tclosePopup(popup) {\n\t\tpopup = arguments.length ? popup : this._popup;\n\t\tpopup?.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapPopupMethods} MapPopupMethods */\n\n/**\n * Methods of `Layer` for popups. All layers share a set of methods convenient for\n * binding popups to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindPopup('Hi There!').addTo(map);\n * layer.openPopup();\n * layer.closePopup();\n * ```\n *\n * Popups will also be automatically opened when the layer is clicked on and closed\n * when the layer is removed from the map or another popup is opened.\n *\n * @lends Layer.prototype\n * @fires Layer#popupopen {PopupEvent} Fired when a popup bound to this layer is opened.\n * @fires Layer#popupclose {PopupEvent} Fired when a popup bound to this layer is closed.\n */\nconst layerPopupMethods = {\n\t/**\n\t * Binds a popup to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an\n\t * `HTMLElement` with safe `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String` or `HTMLElement`.\n\t * @group Popup methods\n\t * @param {DivOverlayContent|Popup} content\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\tbindPopup(content, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._popup = this._initOverlay(Popup, this._popup, content, options);\n\t\tthis.on({\n\t\t\tclick: this._openPopup,\n\t\t\tremove: this.closePopup,\n\t\t\tmove: this._movePopup\n\t\t});\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the popup previously bound with `bindPopup`.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tunbindPopup() {\n\t\tif (this._popup) {\n\t\t\tthis.off({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tthis._popup = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens the bound popup at the specified `latlng` or at the default popup anchor\n\t * if no `latlng` is passed.\n\t * @group Popup methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenPopup(latlng) {\n\t\tif (this._popup) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._popup._source = this;\n\t\t\t}\n\t\t\tif (this._popup._prepareOpen(latlng || this._latlng)) {\n\t\t\t\t// open the popup on the map\n\t\t\t\tthis._popup.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup bound to this layer if it is open.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tclosePopup() {\n\t\tthis._popup?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the popup bound to this layer depending on its current state.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\ttogglePopup() {\n\t\tthis._popup?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the popup bound to this layer is currently open.\n\t * @group Popup methods\n\t * @returns {boolean}\n\t */\n\tisPopupOpen() {\n\t\treturn this._popup?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the popup bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Popup methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetPopupContent(content) {\n\t\tthis._popup?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the popup bound to this layer.\n\t * @group Popup methods\n\t * @returns {Popup|undefined}\n\t */\n\tgetPopup() {\n\t\treturn this._popup;\n\t},\n\n\t_openPopup(e) {\n\t\tif (!this._popup || !this._map) {\n\t\t\treturn;\n\t\t}\n\t\t// prevent map click\n\t\tDomEvent.stopPropagation(e);\n\n\t\tconst target = e.propagatedFrom ?? e.target;\n\t\tif (this._popup._source === target && !(target instanceof Path)) {\n\t\t\t// treat it like a marker and figure out\n\t\t\t// if we should toggle it open/closed\n\t\t\tif (this._map.hasLayer(this._popup)) {\n\t\t\t\tthis.closePopup();\n\t\t\t} else {\n\t\t\t\tthis.openPopup(e.latlng);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._popup._source = target;\n\t\tthis.openPopup(e.latlng);\n\t},\n\n\t_movePopup(e) {\n\t\tthis._popup.setLatLng(e.latlng);\n\t}\n};\n/** @typedef {typeof layerPopupMethods} LayerPopupMethods */\n\n/**\n * Used to open popups in certain places of the map. Use [Map.openPopup](#map-openpopup) to\n * open popups while making sure that only one popup is open at one time\n * (recommended for usability), or use [Map.addLayer](#map-addlayer) to open as many as you want.\n *\n * @example\n * If you want to just bind a popup to marker click and then open it, it's really easy:\n *\n * ```js\n * marker.bindPopup(popupContent).openPopup();\n * ```\n * Path overlays like polylines also have a `bindPopup` method.\n *\n * A popup can be also standalone:\n *\n * ```js\n * const popup = new Popup()\n * \t.setLatLng(latlng)\n * \t.setContent('<p>Hello world!<br />This is a nice popup.</p>')\n * \t.openOn(map);\n * ```\n * or\n * ```js\n * const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})\n * \t.openOn(map);\n * ```\n *\n * **Security note.** Popup string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or\n * build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindPopup(el);\n * ```\n */\nexport class Popup extends DivOverlay {\n\n\tstatic defaultOptions = {\n\t\tpane: 'popupPane',\n\t\toffset: [0, 7],\n\t\tmaxWidth: 300,\n\t\tminWidth: 50,\n\t\tmaxHeight: null,\n\t\tautoPan: true,\n\t\tautoPanPaddingTopLeft: null,\n\t\tautoPanPaddingBottomRight: null,\n\t\tautoPanPadding: [5, 5],\n\t\tkeepInView: false,\n\t\tcloseButton: true,\n\t\tautoClose: true,\n\t\tcloseOnEscapeKey: true,\n\t\tclassName: '',\n\t\ttrackResize: true,\n\t};\n\n\t/**\n\t * Instantiates a `Popup` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the popup with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {PopupOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Popup` object given `latlng` where the popup will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {PopupOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Popup);\n\t}\n\n\t/**\n\t * Alternative to `map.openPopup(popup)`.\n\t * Adds the popup to the map and closes the previous one.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\n\t\tif (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) {\n\t\t\tmap.removeLayer(map._popup);\n\t\t}\n\t\tmap._popup = this;\n\n\t\treturn super.openOn(map);\n\t}\n\n\t/**\n\t * Adds the popup to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\t// The element to return the focus to when closing the popup, e.g. a marker\n\t\tconst active = document.activeElement;\n\t\tthis._returnFocus = map._container.contains(active) && !this._container?.contains(active) ? active : null;\n\n\t\tsuper.onAdd(map);\n\n\t\tif (this._source?._clickedByKeyboard) {\n\t\t\t// Move the focus into the popup, so that its content is read and reachable\n\t\t\tif (!this._closeButton) {\n\t\t\t\tthis._container.tabIndex = -1;\n\t\t\t}\n\t\t\t(this._closeButton ?? this._container).focus({preventScroll: true});\n\t\t}\n\n\t\tmap.fire('popupopen', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupopen', {popup: this}, true);\n\t\t\t// For non-path layers, we toggle the popup when clicking\n\t\t\t// again the layer, so prevent the map to reopen it.\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.on('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the popup from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this._container.contains(document.activeElement) && this._returnFocus?.isConnected) {\n\t\t\tthis._returnFocus.focus({preventScroll: true});\n\t\t}\n\t\tthis._returnFocus = null;\n\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('popupclose', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupclose', {popup: this}, true);\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.off('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the popup listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (this.options.closeOnClick ?? this._map.options.closePopupOnClick) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\tif (this.options.keepInView) {\n\t\t\tevents.moveend = this._adjustPan;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-popup',\n\t\tcontainer = this._container = DomUtil.create('div', `${prefix} ${this.options.className || ''} maplair-zoom-animated`);\n\n\t\tconst wrapper = this._wrapper = DomUtil.create('div', `${prefix}-content-wrapper`, container);\n\t\tthis._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(this._contentNode);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stopPropagation);\n\n\t\tthis._tipContainer = DomUtil.create('div', `${prefix}-tip-container`, container);\n\t\tthis._tip = DomUtil.create('div', `${prefix}-tip`, this._tipContainer);\n\n\t\tif (this.options.closeButton) {\n\t\t\tconst closeButton = this._closeButton = DomUtil.create('button', `${prefix}-close-button`, container);\n\t\t\tcloseButton.type = 'button';\n\t\t\tcloseButton.setAttribute('aria-label', I18n.translate('Close popup'));\n\n\t\t\tcloseButton.innerHTML = '<span aria-hidden=\"true\">×</span>';\n\n\t\t\tDomEvent.on(closeButton, 'click', (ev) => {\n\t\t\t\tev.preventDefault();\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.trackResize) {\n\t\t\tthis._resizeObserver = new ResizeObserver(() => {\n\t\t\t\tif (!this._map) { return; }\n\t\t\t\tthis._updateLayout();\n\t\t\t\tthis._updatePosition();\n\t\t\t\tthis._adjustPan();\n\t\t\t});\n\n\t\t\tthis._resizeObserver.observe(this._contentNode);\n\t\t}\n\t}\n\n\t_updateLayout() {\n\t\tconst container = this._contentNode,\n\t\tstyle = container.style;\n\n\t\tstyle.maxWidth = `${this.options.maxWidth}px`;\n\t\tstyle.minWidth = `${this.options.minWidth}px`;\n\n\t\tstyle.height = '';\n\n\t\t// only measure the height of the content (forcing a layout) if needed\n\t\tconst maxHeight = this.options.maxHeight,\n\t\tscrolled = !!maxHeight && container.offsetHeight > maxHeight;\n\t\tif (scrolled) {\n\t\t\tstyle.height = `${maxHeight}px`;\n\t\t}\n\t\tcontainer.classList.toggle('maplair-popup-scrolled', scrolled);\n\n\t\tthis._containerWidth = this._container.offsetWidth;\n\t\tthis._containerHeight = this._container.offsetHeight;\n\t\t// read along with the size, so that _adjustPan doesn't force another style\n\t\t// recalculation and layout after the popup has been positioned\n\t\tthis._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center),\n\t\tanchor = this._getAnchor();\n\t\tthis._setContainerPosition(pos.add(anchor));\n\t}\n\n\t_adjustPan() {\n\t\tif (!this.options.autoPan) { return; }\n\t\tthis._map._panAnim?.stop();\n\n\t\t// Stopping the pan fires `moveend`, whose listeners may have removed this popup.\n\t\tif (!this._map) { return; }\n\n\t\t// We can endlessly recurse if keepInView is set and the view resets.\n\t\t// Let's guard against that by exiting early if we're responding to our own autopan.\n\t\tif (this._autopanning) {\n\t\t\tthis._autopanning = false;\n\t\t\treturn;\n\t\t}\n\n\t\tconst map = this._map,\n\t\tmarginBottom = this._containerMarginBottom ?? (parseInt(getComputedStyle(this._container).marginBottom, 10) || 0),\n\t\tcontainerHeight = this._containerHeight + marginBottom,\n\t\tcontainerWidth = this._containerWidth,\n\t\tlayerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom);\n\n\t\tlayerPos._add(this._getContainerPosition());\n\n\t\tconst containerPos = map.layerPointToContainerPoint(layerPos),\n\t\tpadding = Point.from(this.options.autoPanPadding),\n\t\tpaddingTL = Point.from(this.options.autoPanPaddingTopLeft ?? padding),\n\t\tpaddingBR = Point.from(this.options.autoPanPaddingBottomRight ?? padding),\n\t\tsize = map.getSize();\n\t\tlet dx = 0,\n\t\tdy = 0;\n\n\t\tif (containerPos.x + containerWidth + paddingBR.x > size.x) { // right\n\t\t\tdx = containerPos.x + containerWidth - size.x + paddingBR.x;\n\t\t}\n\t\tif (containerPos.x - dx - paddingTL.x < 0) { // left\n\t\t\tdx = containerPos.x - paddingTL.x;\n\t\t}\n\t\tif (containerPos.y + containerHeight + paddingBR.y > size.y) { // bottom\n\t\t\tdy = containerPos.y + containerHeight - size.y + paddingBR.y;\n\t\t}\n\t\tif (containerPos.y - dy - paddingTL.y < 0) { // top\n\t\t\tdy = containerPos.y - paddingTL.y;\n\t\t}\n\n\t\tif (dx || dy) {\n\t\t\t// Track that we're autopanning, as this function will be re-ran on moveend\n\t\t\tif (this.options.keepInView) {\n\t\t\t\tthis._autopanning = true;\n\t\t\t}\n\n\t\t\tmap\n\t\t\t\t.fire('autopanstart')\n\t\t\t\t.panBy([dx, dy]);\n\t\t}\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the popup on the source layer?\n\t\treturn new Point(this._source?._getPopupAnchor ? this._source._getPopupAnchor() : [0, 0]);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tclosePopupOnClick: true\n\t\t});\n\n\t\tMaplairMap.include(mapPopupMethods);\n\n\t\tLayer.include(layerPopupMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,kBAAkB;;;;;;;;;;;;;;CAcvB,UAAU,OAAO,QAAQ,SAAS;EAEjC,KAAK,aAAa,OAAO,OAAO,QAAQ,OAAO,CAAC,CAC9C,OAAO,IAAI;EAEb,OAAO;CACR;;;;;;;;CASA,WAAW,OAAO;EACjB,QAAQ,UAAU,SAAS,QAAQ,KAAK;EACxC,OAAO,MAAM;EACb,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;;;;;;;;;;;;;CAazB,UAAU,SAAS,SAAS;EAE3B,KAAK,SAAS,KAAK,aAAa,OAAO,KAAK,QAAQ,SAAS,OAAO;EACpE,KAAK,GAAG;GACP,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,MAAM,KAAK;EACZ,CAAC;EAED,OAAO;CACR;;;;;;CAOA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AU,MAAM,KAAK,KAAK,QAAQ,cAAc,GAChD,YAAY,MAAM,KAAK,KAAK,QAAQ,yBAAyB,OAAO,GACpE,YAAY,MAAM,KAAK,KAAK,QAAQ,6BAA6B,OAAO,GACxE,OAAO,IAAI,QAAQ;EACnB,IAAI,KAAK,GACT,KAAK;EAEL,IAAI,aAAa,IAAI,iBAAiB,UAAU,IAAI,KAAK,GACxD,KAAK,aAAa,IAAI,iBAAiB,KAAK,IAAI,UAAU;EAE3D,IAAI,aAAa,IAAI,KAAK,UAAU,IAAI,GACvC,KAAK,aAAa,IAAI,UAAU;EAEjC,IAAI,aAAa,IAAI,kBAAkB,UAAU,IAAI,KAAK,GACzD,KAAK,aAAa,IAAI,kBAAkB,KAAK,IAAI,UAAU;EAE5D,IAAI,aAAa,IAAI,KAAK,UAAU,IAAI,GACvC,KAAK,aAAa,IAAI,UAAU;EAGjC,IAAI,MAAM,IAAI;GAEb,IAAI,KAAK,QAAQ,YAChB,KAAK,eAAe;GAGrB,IACE,KAAK,cAAc,CAAC,CACpB,MAAM,CAAC,IAAI,EAAE,CAAC;EACjB;CACD;CAEA,aAAa;EAEZ,OAAO,IAAI,MAAM,KAAK,SAAS,kBAAkB,KAAK,QAAQ,gBAAgB,IAAI,CAAC,GAAG,CAAC,CAAC;CACzF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,mBAAmB,KACpB,CAAC;EAED,WAAW,QAAQ,eAAe;EAElC,MAAM,QAAQ,iBAAiB;CAChC;AACD"}
|
|
1
|
+
{"version":3,"file":"Popup.js","names":["DomEvent.stopPropagation","DomUtil.create","Util.stamp"],"sources":["../../../src/layer/Popup.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport {I18n} from '../core/I18n.js';\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent, PopupEvent} from '../core/Events.js' */\n\n/**\n * Options of `Popup`.\n * @typedef {object} PopupOptions\n * @property {string} [pane='popupPane'] `Map pane` where the popup will be added.\n * @property {PointExpression} [offset=[0, 7]] The offset of the popup position.\n * @property {number} [maxWidth=300] Max width of the popup, in pixels.\n * @property {number} [minWidth=50] Min width of the popup, in pixels.\n * @property {number|null} [maxHeight=null] If set, creates a scrollable container of\n * the given height inside a popup if its content exceeds it. The scrollable container\n * can be styled using the `maplair-popup-scrolled` CSS class selector.\n * @property {boolean} [autoPan=true] Set it to `false` if you don't want the map to do\n * panning animation to fit the opened popup.\n * @property {PointExpression|null} [autoPanPaddingTopLeft=null] The margin between the\n * popup and the top left corner of the map view after autopanning was performed.\n * @property {PointExpression|null} [autoPanPaddingBottomRight=null] The margin between\n * the popup and the bottom right corner of the map view after autopanning was\n * performed.\n * @property {PointExpression} [autoPanPadding=[5, 5]] Equivalent of setting both top\n * left and bottom right autopan padding to the same value.\n * @property {boolean} [keepInView=false] Set it to `true` if you want to prevent users\n * from panning the popup off of the screen while it is open.\n * @property {boolean} [closeButton=true] Controls the presence of a close button in\n * the popup.\n * @property {boolean} [autoClose=true] Set it to `false` if you want to override the\n * default behavior of the popup closing when another popup is opened.\n * @property {boolean} [closeOnEscapeKey=true] Set it to `false` if you want to\n * override the default behavior of the ESC key for closing of the popup.\n * @property {boolean} [closeOnClick] Set it if you want to override the default\n * behavior of the popup closing when user clicks on the map. Defaults to the map's\n * [`closePopupOnClick`](#map-closepopuponclick) option.\n * @property {string} [className=''] A custom CSS class name to assign to the popup.\n * @property {boolean} [trackResize=true] Whether the popup shall react to changes in\n * the size of its contents (e.g. when an image inside the popup loads) and reposition\n * itself.\n * @extends DivOverlayOptions\n */\n\n/**\n * Map options of `Popup`.\n * @typedef {object} PopupMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [closePopupOnClick=true] Set it to `false` if you don't want\n * popups to close when user clicks the map.\n */\n\n/**\n * Methods of `MaplairMap` for popups.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#popupopen {PopupEvent} Fired when a popup is opened in the map.\n * @fires MaplairMap#popupclose {PopupEvent} Fired when a popup in the map is closed.\n * @fires MaplairMap#autopanstart {MaplairEvent} Fired when the map starts autopanning\n * when opening a popup.\n */\nconst mapPopupMethods = {\n\t/**\n\t * Opens the specified popup while closing the previously opened (to make sure only\n\t * one is opened at one time for usability).\n\t *\n\t * Alternatively, creates a popup with the specified content and options and opens\n\t * it in the given point on a map. String content is rendered as HTML; sanitize\n\t * untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Popup|DivOverlayContent} popup The popup, or the content of a new popup.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\topenPopup(popup, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Popup, popup, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup previously opened with [openPopup](#map-openpopup) (or the\n\t * given one).\n\t * @group Methods for layers and controls\n\t * @param {Popup} [popup]\n\t * @returns {this}\n\t */\n\tclosePopup(popup) {\n\t\tpopup = arguments.length ? popup : this._popup;\n\t\tpopup?.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapPopupMethods} MapPopupMethods */\n\n/**\n * Methods of `Layer` for popups. All layers share a set of methods convenient for\n * binding popups to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindPopup('Hi There!').addTo(map);\n * layer.openPopup();\n * layer.closePopup();\n * ```\n *\n * Popups will also be automatically opened when the layer is clicked on and closed\n * when the layer is removed from the map or another popup is opened.\n *\n * @lends Layer.prototype\n * @fires Layer#popupopen {PopupEvent} Fired when a popup bound to this layer is opened.\n * @fires Layer#popupclose {PopupEvent} Fired when a popup bound to this layer is closed.\n */\nconst layerPopupMethods = {\n\t/**\n\t * Binds a popup to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it or pass an `HTMLElement` with safe\n\t * `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String`, `HTMLElement` or `DocumentFragment`.\n\t * @group Popup methods\n\t * @param {DivOverlayContent|Popup} content\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\tbindPopup(content, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._popup = this._initOverlay(Popup, this._popup, content, options);\n\t\tthis._popup._updateSourceAria(this._popup.isOpen());\n\t\tthis.on({\n\t\t\tclick: this._openPopup,\n\t\t\tremove: this.closePopup,\n\t\t\tmove: this._movePopup\n\t\t});\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the popup previously bound with `bindPopup`.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tunbindPopup() {\n\t\tif (this._popup) {\n\t\t\tthis.off({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tconst el = this.getElement?.();\n\t\t\tel?.removeAttribute('aria-expanded');\n\t\t\tel?.removeAttribute('aria-controls');\n\t\t\tthis._popup = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens the bound popup at the specified `latlng` or at the default popup anchor\n\t * if no `latlng` is passed.\n\t * @group Popup methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenPopup(latlng) {\n\t\tif (this._popup) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._popup._source = this;\n\t\t\t}\n\t\t\tif (this._popup._prepareOpen(latlng || this._latlng)) {\n\t\t\t\t// open the popup on the map\n\t\t\t\tthis._popup.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup bound to this layer if it is open.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tclosePopup() {\n\t\tthis._popup?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the popup bound to this layer depending on its current state.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\ttogglePopup() {\n\t\tthis._popup?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the popup bound to this layer is currently open.\n\t * @group Popup methods\n\t * @returns {boolean}\n\t */\n\tisPopupOpen() {\n\t\treturn this._popup?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the popup bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Popup methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetPopupContent(content) {\n\t\tthis._popup?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the popup bound to this layer.\n\t * @group Popup methods\n\t * @returns {Popup|undefined}\n\t */\n\tgetPopup() {\n\t\treturn this._popup;\n\t},\n\n\t_openPopup(e) {\n\t\tif (!this._popup || !this._map) {\n\t\t\treturn;\n\t\t}\n\t\t// prevent map click\n\t\tDomEvent.stopPropagation(e);\n\n\t\tconst target = e.propagatedFrom ?? e.target;\n\t\t// clicking a marker-like source again toggles its popup closed\n\t\tif (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {\n\t\t\tthis.closePopup();\n\t\t\treturn;\n\t\t}\n\t\tthis._popup._source = target;\n\t\tthis.openPopup(e.latlng);\n\t},\n\n\t_movePopup(e) {\n\t\tthis._popup.setLatLng(e.latlng);\n\t}\n};\n/** @typedef {typeof layerPopupMethods} LayerPopupMethods */\n\n/**\n * Used to open popups in certain places of the map. Use [Map.openPopup](#map-openpopup) to\n * open popups while making sure that only one popup is open at one time\n * (recommended for usability), or use [Map.addLayer](#map-addlayer) to open as many as you want.\n *\n * @example\n * If you want to just bind a popup to marker click and then open it, it's really easy:\n *\n * ```js\n * marker.bindPopup(popupContent).openPopup();\n * ```\n * Path overlays like polylines also have a `bindPopup` method.\n *\n * A popup can be also standalone:\n *\n * ```js\n * const popup = new Popup()\n * \t.setLatLng(latlng)\n * \t.setContent('<p>Hello world!<br />This is a nice popup.</p>')\n * \t.openOn(map);\n * ```\n * or\n * ```js\n * const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})\n * \t.openOn(map);\n * ```\n *\n * **Security note.** Popup string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it first, or build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindPopup(el);\n * ```\n */\nexport class Popup extends DivOverlay {\n\n\tstatic defaultOptions = {\n\t\tpane: 'popupPane',\n\t\toffset: [0, 7],\n\t\tmaxWidth: 300,\n\t\tminWidth: 50,\n\t\tmaxHeight: null,\n\t\tautoPan: true,\n\t\tautoPanPaddingTopLeft: null,\n\t\tautoPanPaddingBottomRight: null,\n\t\tautoPanPadding: [5, 5],\n\t\tkeepInView: false,\n\t\tcloseButton: true,\n\t\tautoClose: true,\n\t\tcloseOnEscapeKey: true,\n\t\tclassName: '',\n\t\ttrackResize: true,\n\t};\n\n\t/**\n\t * Instantiates a `Popup` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the popup with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {PopupOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Popup` object given `latlng` where the popup will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {PopupOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Popup);\n\t}\n\n\t/**\n\t * Alternative to `map.openPopup(popup)`.\n\t * Adds the popup to the map and closes the previous one.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\n\t\tif (!map.hasLayer(this) && map._popup?.options.autoClose) {\n\t\t\tmap.removeLayer(map._popup);\n\t\t}\n\t\tmap._popup = this;\n\n\t\tsuper.openOn(map);\n\t\tthis._updateSourceAria(true); // the source may have changed while open, e.g. within a FeatureGroup\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the popup to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\t// The element to return the focus to when closing the popup, e.g. a marker\n\t\tconst active = document.activeElement;\n\t\tthis._returnFocus = map._container.contains(active) && !this._container?.contains(active) ? active : null;\n\n\t\tsuper.onAdd(map);\n\n\t\tif (this._source?._clickedByKeyboard) {\n\t\t\t// Move the focus into the popup, so that its content is read and reachable\n\t\t\tif (!this._closeButton) {\n\t\t\t\tthis._container.tabIndex = -1;\n\t\t\t}\n\t\t\t(this._closeButton ?? this._container).focus({preventScroll: true});\n\t\t}\n\n\t\tmap.fire('popupopen', {popup: this});\n\t\tthis._updateSourceAria(true);\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupopen', {popup: this}, true);\n\t\t\t// For non-path layers, we toggle the popup when clicking\n\t\t\t// again the layer, so prevent the map to reopen it.\n\t\t\tif (this._source._togglesPopupOnClick()) {\n\t\t\t\tthis._source.on('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the popup from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\t// closing removes the focused element, which would send focus back to the start of the page\n\t\tif (this._container.contains(document.activeElement)) {\n\t\t\tconst el = this._source?.getElement?.();\n\t\t\tconst target = this._returnFocus?.isConnected ? this._returnFocus :\n\t\t\t\tel?.tabIndex >= 0 ? el : map._container;\n\t\t\ttarget.focus({preventScroll: true});\n\t\t}\n\t\tthis._returnFocus = null;\n\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('popupclose', {popup: this});\n\t\tthis._updateSourceAria(false);\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupclose', {popup: this}, true);\n\t\t\tif (this._source._togglesPopupOnClick()) {\n\t\t\t\tthis._source.off('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the popup listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (this.options.closeOnClick ?? this._map.options.closePopupOnClick) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\tif (this.options.keepInView) {\n\t\t\tevents.moveend = this._adjustPan;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t// Marks a source that acts as a button (e.g. a keyboard-accessible marker) as a\n\t// disclosure for the popup.\n\t_updateSourceAria(open) {\n\t\tthis._ariaSource?.setAttribute('aria-expanded', 'false');\n\t\tthis._ariaSource?.removeAttribute('aria-controls');\n\n\t\tconst el = this._source?.getElement?.();\n\t\tthis._ariaSource = el?.getAttribute('role') === 'button' ? el : null;\n\t\tthis._ariaSource?.setAttribute('aria-expanded', String(open));\n\t\tif (open) { this._ariaSource?.setAttribute('aria-controls', this._container.id); }\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-popup',\n\t\tcontainer = this._container = DomUtil.create('div', `${prefix} ${this.options.className || ''} maplair-zoom-animated`);\n\n\t\tcontainer.id = `maplair-popup-${Util.stamp(this)}`;\n\n\t\tconst wrapper = this._wrapper = DomUtil.create('div', `${prefix}-content-wrapper`, container);\n\t\tthis._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(this._contentNode);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stopPropagation);\n\n\t\tthis._tipContainer = DomUtil.create('div', `${prefix}-tip-container`, container);\n\t\tthis._tip = DomUtil.create('div', `${prefix}-tip`, this._tipContainer);\n\n\t\tif (this.options.closeButton) {\n\t\t\tconst closeButton = this._closeButton = DomUtil.create('button', `${prefix}-close-button`, container);\n\t\t\tcloseButton.type = 'button';\n\t\t\tcloseButton.setAttribute('aria-label', I18n.translate('Close popup'));\n\n\t\t\tcloseButton.textContent = '\\u00D7';\n\n\t\t\tDomEvent.on(closeButton, 'click', (ev) => {\n\t\t\t\tev.preventDefault();\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.trackResize) {\n\t\t\tthis._resizeObserver = new ResizeObserver(() => {\n\t\t\t\tif (!this._map) { return; }\n\t\t\t\tthis._updateLayout();\n\t\t\t\tthis._updatePosition();\n\t\t\t\tthis._adjustPan();\n\t\t\t});\n\n\t\t\tthis._resizeObserver.observe(this._contentNode);\n\t\t}\n\t}\n\n\t_updateLayout() {\n\t\tconst container = this._contentNode,\n\t\tstyle = container.style;\n\n\t\tstyle.maxWidth = `${this.options.maxWidth}px`;\n\t\tstyle.minWidth = `${this.options.minWidth}px`;\n\n\t\tstyle.height = '';\n\n\t\t// only measure the height of the content (forcing a layout) if needed\n\t\tconst maxHeight = this.options.maxHeight,\n\t\tscrolled = !!maxHeight && container.offsetHeight > maxHeight;\n\t\tif (scrolled) {\n\t\t\tstyle.height = `${maxHeight}px`;\n\t\t}\n\t\tcontainer.classList.toggle('maplair-popup-scrolled', scrolled);\n\n\t\tthis._containerWidth = this._container.offsetWidth;\n\t\tthis._containerHeight = this._container.offsetHeight;\n\t\t// read along with the size, so that _adjustPan doesn't force another style\n\t\t// recalculation and layout after the popup has been positioned\n\t\tthis._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center),\n\t\tanchor = this._getAnchor();\n\t\tthis._setContainerPosition(pos.add(anchor));\n\t}\n\n\t_adjustPan() {\n\t\tif (!this.options.autoPan) { return; }\n\t\tthis._map._panAnim?.stop();\n\n\t\t// Stopping the pan fires `moveend`, whose listeners may have removed this popup.\n\t\tif (!this._map) { return; }\n\n\t\t// We can endlessly recurse if keepInView is set and the view resets.\n\t\t// Let's guard against that by exiting early if we're responding to our own autopan.\n\t\tif (this._autopanning) {\n\t\t\tthis._autopanning = false;\n\t\t\treturn;\n\t\t}\n\n\t\tconst map = this._map,\n\t\tmarginBottom = this._containerMarginBottom ?? (parseInt(getComputedStyle(this._container).marginBottom, 10) || 0),\n\t\tcontainerHeight = this._containerHeight + marginBottom,\n\t\tcontainerWidth = this._containerWidth,\n\t\tlayerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom);\n\n\t\tlayerPos._add(this._getContainerPosition());\n\n\t\tconst containerPos = map.layerPointToContainerPoint(layerPos),\n\t\tpadding = Point.from(this.options.autoPanPadding),\n\t\tpaddingTL = Point.from(this.options.autoPanPaddingTopLeft ?? padding),\n\t\tpaddingBR = Point.from(this.options.autoPanPaddingBottomRight ?? padding),\n\t\tsize = map.getSize();\n\t\tlet dx = 0,\n\t\tdy = 0;\n\n\t\tif (containerPos.x + containerWidth + paddingBR.x > size.x) { // right\n\t\t\tdx = containerPos.x + containerWidth - size.x + paddingBR.x;\n\t\t}\n\t\tif (containerPos.x - dx - paddingTL.x < 0) { // left\n\t\t\tdx = containerPos.x - paddingTL.x;\n\t\t}\n\t\tif (containerPos.y + containerHeight + paddingBR.y > size.y) { // bottom\n\t\t\tdy = containerPos.y + containerHeight - size.y + paddingBR.y;\n\t\t}\n\t\tif (containerPos.y - dy - paddingTL.y < 0) { // top\n\t\t\tdy = containerPos.y - paddingTL.y;\n\t\t}\n\n\t\tif (dx || dy) {\n\t\t\t// Track that we're autopanning, as this function will be re-ran on moveend\n\t\t\tif (this.options.keepInView) {\n\t\t\t\tthis._autopanning = true;\n\t\t\t}\n\n\t\t\tmap\n\t\t\t\t.fire('autopanstart')\n\t\t\t\t.panBy([dx, dy]);\n\t\t}\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the popup on the source layer?\n\t\treturn new Point(this._source?._getPopupAnchor ? this._source._getPopupAnchor() : [0, 0]);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tclosePopupOnClick: true\n\t\t});\n\n\t\tMaplairMap.include(mapPopupMethods);\n\n\t\tLayer.include(layerPopupMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,kBAAkB;;;;;;;;;;;;;;CAcvB,UAAU,OAAO,QAAQ,SAAS;EAEjC,KAAK,aAAa,OAAO,OAAO,QAAQ,OAAO,CAAC,CAC9C,OAAO,IAAI;EAEb,OAAO;CACR;;;;;;;;CASA,WAAW,OAAO;EACjB,QAAQ,UAAU,SAAS,QAAQ,KAAK;EACxC,OAAO,MAAM;EACb,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;;;;;;;;;;;;;CAazB,UAAU,SAAS,SAAS;EAE3B,KAAK,SAAS,KAAK,aAAa,OAAO,KAAK,QAAQ,SAAS,OAAO;EACpE,KAAK,OAAO,kBAAkB,KAAK,OAAO,OAAO,CAAC;EAClD,KAAK,GAAG;GACP,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,MAAM,KAAK;EACZ,CAAC;EAED,OAAO;CACR;;;;;;CAOA,cAAc;EACb,IAAI,KAAK,QAAQ;GAChB,KAAK,IAAI;IACR,OAAO,KAAK;IACZ,QAAQ,KAAK;IAC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,gBAAgB,IAAI,CAAC,GAAG,CAAC,CAAC;CACzF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,mBAAmB,KACpB,CAAC;EAED,WAAW,QAAQ,eAAe;EAElC,MAAM,QAAQ,iBAAiB;CAChC;AACD"}
|
|
@@ -6,13 +6,13 @@ import { Layer } from "./Layer.js";
|
|
|
6
6
|
import { FeatureGroup } from "./FeatureGroup.js";
|
|
7
7
|
import { DivOverlay } from "./DivOverlay.js";
|
|
8
8
|
// src/layer/Tooltip.js
|
|
9
|
-
const directions =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const directions = {
|
|
10
|
+
top: [.5, 1],
|
|
11
|
+
bottom: [.5, 0],
|
|
12
|
+
center: [.5, .5],
|
|
13
|
+
right: [0, .5],
|
|
14
|
+
left: [1, .5]
|
|
15
|
+
};
|
|
16
16
|
const tipSize = 6;
|
|
17
17
|
const autoPadding = 4;
|
|
18
18
|
function shiftInto(start, size, min, max) {
|
|
@@ -31,7 +31,8 @@ function clampTip(tipShift, size) {
|
|
|
31
31
|
* Options of `Tooltip`.
|
|
32
32
|
* @typedef {object} TooltipOptions
|
|
33
33
|
* @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.
|
|
34
|
-
* @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position
|
|
34
|
+
* @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position, in
|
|
35
|
+
* pixels. Mirrored horizontally when an `auto` tooltip opens to the left.
|
|
35
36
|
* @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']
|
|
36
37
|
* Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,
|
|
37
38
|
* `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when
|
|
@@ -102,10 +103,10 @@ const layerTooltipMethods = {
|
|
|
102
103
|
/**
|
|
103
104
|
* Binds a tooltip to the layer with the passed `content` and sets up the
|
|
104
105
|
* necessary event listeners. A `String` argument is rendered as HTML; if it
|
|
105
|
-
* may contain untrusted input, sanitize it
|
|
106
|
-
* `
|
|
106
|
+
* may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
|
|
107
|
+
* `textContent` instead. If a `Function` is passed
|
|
107
108
|
* it will receive the layer as the first argument and should return a
|
|
108
|
-
* `String` or `
|
|
109
|
+
* `String`, `HTMLElement` or `DocumentFragment`.
|
|
109
110
|
* @group Tooltip methods
|
|
110
111
|
* @param {DivOverlayContent|Tooltip} content
|
|
111
112
|
* @param {TooltipOptions} [options]
|
|
@@ -116,7 +117,7 @@ const layerTooltipMethods = {
|
|
|
116
117
|
if (this._tooltip) this.unbindTooltip();
|
|
117
118
|
this._tooltip = this._initOverlay(Tooltip, old, content, options);
|
|
118
119
|
this._initTooltipInteractions();
|
|
119
|
-
if (this._tooltip.options.permanent && this._map
|
|
120
|
+
if (this._tooltip.options.permanent && this._map?.hasLayer(this)) this.openTooltip();
|
|
120
121
|
return this;
|
|
121
122
|
},
|
|
122
123
|
/**
|
|
@@ -158,11 +159,7 @@ const layerTooltipMethods = {
|
|
|
158
159
|
openTooltip(latlng) {
|
|
159
160
|
if (this._tooltip) {
|
|
160
161
|
if (!(this instanceof FeatureGroup)) this._tooltip._source = this;
|
|
161
|
-
if (this._tooltip._prepareOpen(latlng))
|
|
162
|
-
this._tooltip.openOn(this._map);
|
|
163
|
-
if (this.getElement) this._setAriaDescribedByOnLayer(this);
|
|
164
|
-
else if (this.eachLayer) this.eachLayer(this._setAriaDescribedByOnLayer, this);
|
|
165
|
-
}
|
|
162
|
+
if (this._tooltip._prepareOpen(latlng)) this._tooltip.openOn(this._map);
|
|
166
163
|
}
|
|
167
164
|
return this;
|
|
168
165
|
},
|
|
@@ -223,7 +220,7 @@ const layerTooltipMethods = {
|
|
|
223
220
|
if (!remove) {
|
|
224
221
|
el._maplair_focus_handler && off(el, "focus", el._maplair_focus_handler, this);
|
|
225
222
|
el._maplair_focus_handler = () => {
|
|
226
|
-
if (this._tooltip) {
|
|
223
|
+
if (this._tooltip && el.matches(":focus-visible")) {
|
|
227
224
|
this._tooltip._source = layer;
|
|
228
225
|
this.openTooltip();
|
|
229
226
|
}
|
|
@@ -234,9 +231,6 @@ const layerTooltipMethods = {
|
|
|
234
231
|
if (remove) delete el._maplair_focus_handler;
|
|
235
232
|
}
|
|
236
233
|
},
|
|
237
|
-
_setAriaDescribedByOnLayer(layer) {
|
|
238
|
-
(typeof layer.getElement === "function" && layer.getElement())?.setAttribute?.("aria-describedby", this._tooltip._container.id);
|
|
239
|
-
},
|
|
240
234
|
_openTooltip(e) {
|
|
241
235
|
if (!this._tooltip || !this._map) return;
|
|
242
236
|
if (this._map.dragging?.moving()) {
|
|
@@ -253,13 +247,7 @@ const layerTooltipMethods = {
|
|
|
253
247
|
this.openTooltip(this._tooltip.options.sticky ? e.latlng : void 0);
|
|
254
248
|
},
|
|
255
249
|
_moveTooltip(e) {
|
|
256
|
-
|
|
257
|
-
if (this._tooltip.options.sticky && e.originalEvent) {
|
|
258
|
-
containerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);
|
|
259
|
-
layerPoint = this._map.containerPointToLayerPoint(containerPoint);
|
|
260
|
-
latlng = this._map.layerPointToLatLng(layerPoint);
|
|
261
|
-
}
|
|
262
|
-
this._tooltip.setLatLng(latlng);
|
|
250
|
+
this._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ? this._map.pointerEventToLatLng(e.originalEvent) : e.latlng);
|
|
263
251
|
}
|
|
264
252
|
};
|
|
265
253
|
/** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */
|
|
@@ -290,8 +278,7 @@ const layerTooltipMethods = {
|
|
|
290
278
|
*
|
|
291
279
|
* **Security note.** Tooltip string content is rendered as HTML. If your content
|
|
292
280
|
* 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:
|
|
281
|
+
* it first, or build a DOM element using `textContent` to render it as plain text:
|
|
295
282
|
*
|
|
296
283
|
* ```js
|
|
297
284
|
* const el = document.createElement('div');
|
|
@@ -348,6 +335,8 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
348
335
|
map.fire("tooltipopen", { tooltip: this });
|
|
349
336
|
if (this._source) {
|
|
350
337
|
this.addEventParent(this._source);
|
|
338
|
+
this._ariaSource = this._source.getElement?.();
|
|
339
|
+
this._ariaSource?.setAttribute("aria-describedby", this._container.id);
|
|
351
340
|
this._source.fire("tooltipopen", { tooltip: this }, true);
|
|
352
341
|
}
|
|
353
342
|
}
|
|
@@ -360,6 +349,9 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
360
349
|
map.fire("tooltipclose", { tooltip: this });
|
|
361
350
|
if (this._source) {
|
|
362
351
|
this.removeEventParent(this._source);
|
|
352
|
+
const el = this._ariaSource;
|
|
353
|
+
if (el?.getAttribute("aria-describedby") === this._container.id) el.removeAttribute("aria-describedby");
|
|
354
|
+
this._ariaSource = null;
|
|
363
355
|
this._source.fire("tooltipclose", { tooltip: this }, true);
|
|
364
356
|
}
|
|
365
357
|
}
|
|
@@ -376,7 +368,7 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
376
368
|
const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-animated`;
|
|
377
369
|
this._contentNode = this._container = create("div", className);
|
|
378
370
|
this._container.setAttribute("role", "tooltip");
|
|
379
|
-
this._container.
|
|
371
|
+
this._container.id = `maplair-tooltip-${stamp(this)}`;
|
|
380
372
|
}
|
|
381
373
|
_updateLayout() {}
|
|
382
374
|
_adjustPan() {}
|
|
@@ -390,33 +382,33 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
390
382
|
}
|
|
391
383
|
_setPosition(pos) {
|
|
392
384
|
let direction = this.options.direction, shift = new Point(0, 0);
|
|
393
|
-
const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset)
|
|
394
|
-
if (!
|
|
395
|
-
({direction, shift} = this._getAutoPlacement(pos, offset,
|
|
396
|
-
if (direction === "left")
|
|
397
|
-
offset.x = -offset.x;
|
|
398
|
-
anchor.x = -anchor.x;
|
|
399
|
-
}
|
|
385
|
+
const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset);
|
|
386
|
+
if (!(direction in directions)) {
|
|
387
|
+
({direction, shift} = this._getAutoPlacement(pos, offset, tooltipWidth, tooltipHeight));
|
|
388
|
+
if (direction === "left") offset.x = -offset.x;
|
|
400
389
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
else if (direction === "left") subX = tooltipWidth;
|
|
406
|
-
pos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor).add(shift);
|
|
407
|
-
container.classList.remove("maplair-tooltip-right", "maplair-tooltip-left", "maplair-tooltip-top", "maplair-tooltip-bottom");
|
|
408
|
-
container.classList.add(`maplair-tooltip-${direction}`);
|
|
390
|
+
const anchor = this._getAnchor(direction);
|
|
391
|
+
const [fx, fy] = directions[direction];
|
|
392
|
+
pos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);
|
|
393
|
+
for (const d in directions) container.classList.toggle(`maplair-tooltip-${d}`, d === direction);
|
|
409
394
|
const tipShift = direction === "top" || direction === "bottom" ? clampTip(-shift.x, tooltipWidth) : clampTip(-shift.y, tooltipHeight);
|
|
410
395
|
if (tipShift) container.style.setProperty("--maplair-tooltip-tip-shift", `${tipShift}px`);
|
|
411
396
|
else container.style.removeProperty("--maplair-tooltip-tip-shift");
|
|
412
397
|
this._setContainerPosition(pos);
|
|
413
398
|
}
|
|
414
|
-
_getAutoPlacement(pos, offset,
|
|
415
|
-
const area = this._getAutoArea(), point = this._map.layerPointToContainerPoint(pos),
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
399
|
+
_getAutoPlacement(pos, offset, width, height) {
|
|
400
|
+
const area = this._getAutoArea(), point = this._map.layerPointToContainerPoint(pos), at = {};
|
|
401
|
+
for (const d of [
|
|
402
|
+
"right",
|
|
403
|
+
"left",
|
|
404
|
+
"top",
|
|
405
|
+
"bottom"
|
|
406
|
+
]) at[d] = point.add(this._getAnchor(d)).add(d === "left" ? [-offset.x, offset.y] : offset);
|
|
407
|
+
const space = {
|
|
408
|
+
right: area.max.x - at.right.x - width - tipSize,
|
|
409
|
+
left: at.left.x - area.min.x - width - tipSize,
|
|
410
|
+
top: at.top.y - area.min.y - height - tipSize,
|
|
411
|
+
bottom: area.max.y - at.bottom.y - height - tipSize
|
|
420
412
|
};
|
|
421
413
|
if (!this._autoDirection) {
|
|
422
414
|
const sides = point.x < (area.min.x + area.max.x) / 2 ? ["right", "left"] : ["left", "right"], fallback = space.right >= space.left ? "right" : "left";
|
|
@@ -426,7 +418,7 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
426
418
|
"bottom"
|
|
427
419
|
].find((d) => space[d] >= 0 && (d === "right" || d === "left" || width <= area.max.x - area.min.x)) ?? fallback;
|
|
428
420
|
}
|
|
429
|
-
const direction = this._autoDirection;
|
|
421
|
+
const direction = this._autoDirection, { x, y } = at[direction];
|
|
430
422
|
return {
|
|
431
423
|
direction,
|
|
432
424
|
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))
|
|
@@ -447,7 +439,7 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
447
439
|
};
|
|
448
440
|
}
|
|
449
441
|
_updatePosition() {
|
|
450
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
442
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
|
|
451
443
|
this._setPosition(pos);
|
|
452
444
|
}
|
|
453
445
|
/**
|
|
@@ -463,8 +455,8 @@ var Tooltip = class Tooltip extends DivOverlay {
|
|
|
463
455
|
const pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
|
|
464
456
|
this._setPosition(pos);
|
|
465
457
|
}
|
|
466
|
-
_getAnchor() {
|
|
467
|
-
return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);
|
|
458
|
+
_getAnchor(direction) {
|
|
459
|
+
return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor(direction) : [0, 0]);
|
|
468
460
|
}
|
|
469
461
|
/**
|
|
470
462
|
* Registers this default feature on the map class, called by `MaplairMap` itself.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","names":["DomEvent.off","DomEvent.on","DomUtil.create","Util.stamp"],"sources":["../../../src/layer/Tooltip.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as Util from '../core/Util.js';\nimport {FeatureGroup} from './FeatureGroup.js';\n\nconst directions = ['top', 'bottom', 'center', 'right', 'left'];\n\n// The size of the tooltip tip (see `.maplair-tooltip-top` etc. in maplair.css) and\n// the minimum distance of an `auto` tooltip to the edge of the map.\nconst tipSize = 6,\nautoPadding = 4;\n\n// The shift moving a box from `start` with `size` into the range `[min, max]`.\nfunction shiftInto(start, size, min, max) {\n\treturn Math.max(0, min - start) - Math.max(0, start + size - max);\n}\n\n// Keeps the shifted tip off the rounded corners of the tooltip.\nfunction clampTip(tipShift, size) {\n\tconst max = Math.max(0, size / 2 - 2 * tipSize);\n\treturn Math.round(Math.min(max, Math.max(-max, tipShift)));\n}\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, TooltipEvent} from '../core/Events.js' */\n\n/**\n * Options of `Tooltip`.\n * @typedef {object} TooltipOptions\n * @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.\n * @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position.\n * @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']\n * Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,\n * `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when\n * opening the tooltip: preferably the side towards the center of the map (`right` or\n * `left`), otherwise the opposite side, `top` or `bottom`. The tooltip is shifted\n * along that side to stay within the map (within the viewport if `overflow` is set),\n * its tip still pointing at the source.\n * @property {boolean} [permanent=false] Whether to open the tooltip permanently or only\n * on pointerover.\n * @property {boolean} [sticky=false] If true, the tooltip will follow the pointer\n * instead of being fixed at the feature center.\n * @property {number} [opacity=0.9] Tooltip container opacity.\n * @extends DivOverlayOptions\n */\n\n/**\n * Methods of `MaplairMap` for tooltips.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#tooltipopen {TooltipEvent} Fired when a tooltip is opened in the map.\n * @fires MaplairMap#tooltipclose {TooltipEvent} Fired when a tooltip in the map is closed.\n */\nconst mapTooltipMethods = {\n\t/**\n\t * Opens the specified tooltip.\n\t *\n\t * Alternatively, creates a tooltip with the specified content and options and\n\t * opens it. String content is rendered as HTML; sanitize untrusted input or pass\n\t * an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Tooltip|DivOverlayContent} tooltip The tooltip, or the content of a new\n\t * tooltip.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {TooltipOptions} [options]\n\t * @returns {this}\n\t */\n\topenTooltip(tooltip, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Tooltip, tooltip, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the tooltip given as parameter.\n\t * @group Methods for layers and controls\n\t * @param {Tooltip} tooltip\n\t * @returns {this}\n\t */\n\tcloseTooltip(tooltip) {\n\t\ttooltip.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapTooltipMethods} MapTooltipMethods */\n\n/**\n * Methods of `Layer` for tooltips. All layers share a set of methods convenient for\n * binding tooltips to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindTooltip('Hi There!').addTo(map);\n * layer.openTooltip();\n * layer.closeTooltip();\n * ```\n *\n * @lends Layer.prototype\n * @fires Layer#tooltipopen {TooltipEvent} Fired when a tooltip bound to this layer is\n * opened.\n * @fires Layer#tooltipclose {TooltipEvent} Fired when a tooltip bound to this layer is\n * closed.\n */\nconst layerTooltipMethods = {\n\t/**\n\t * Binds a tooltip to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an\n\t * `HTMLElement` with safe `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String` or `HTMLElement`.\n\t * @group Tooltip methods\n\t * @param {DivOverlayContent|Tooltip} content\n\t * @param {TooltipOptions} [options]\n\t * @returns {this}\n\t */\n\tbindTooltip(content, options) {\n\t\t// an open tooltip is replaced, a closed one reused\n\t\tconst old = this.isTooltipOpen() ? null : this._tooltip;\n\n\t\t// the handlers depend on the old options, so they go before the new ones are applied\n\t\tif (this._tooltip) {\n\t\t\tthis.unbindTooltip();\n\t\t}\n\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._tooltip = this._initOverlay(Tooltip, old, content, options);\n\t\tthis._initTooltipInteractions();\n\n\t\tif (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) {\n\t\t\tthis.openTooltip();\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the tooltip previously bound with `bindTooltip`.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\tunbindTooltip() {\n\t\tif (this._tooltip) {\n\t\t\tthis._initTooltipInteractions(true);\n\t\t\tthis.closeTooltip();\n\t\t\tthis._tooltip = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t_initTooltipInteractions(remove) {\n\t\tconst {permanent, sticky} = this._tooltip.options,\n\t\tevents = {\n\t\t\tremove: this.closeTooltip,\n\t\t\tmove: this._moveTooltip\n\t\t};\n\t\tif (permanent) {\n\t\t\tevents.add = this._openTooltip;\n\t\t} else {\n\t\t\tevents.pointerover = this._openTooltip;\n\t\t\tevents.pointerout = this.closeTooltip;\n\t\t\tevents.click = this._openTooltip;\n\t\t\t// layer elements can be recreated on every add\n\t\t\tevents.add = this._toggleFocusListeners;\n\t\t\tif (this._map) {\n\t\t\t\tthis._toggleFocusListeners(!remove);\n\t\t\t}\n\t\t}\n\t\tif (sticky) {\n\t\t\tevents.pointermove = this._moveTooltip;\n\t\t}\n\t\tthis[remove ? 'off' : 'on'](events);\n\t},\n\n\t/**\n\t * Opens the bound tooltip at the specified `latlng` or at the default tooltip\n\t * anchor if no `latlng` is passed.\n\t * @group Tooltip methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenTooltip(latlng) {\n\t\tif (this._tooltip) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._tooltip._source = this;\n\t\t\t}\n\t\t\tif (this._tooltip._prepareOpen(latlng)) {\n\t\t\t\t// open the tooltip on the map\n\t\t\t\tthis._tooltip.openOn(this._map);\n\n\t\t\t\tif (this.getElement) {\n\t\t\t\t\tthis._setAriaDescribedByOnLayer(this);\n\t\t\t\t} else if (this.eachLayer) {\n\t\t\t\t\tthis.eachLayer(this._setAriaDescribedByOnLayer, this);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the tooltip bound to this layer if it is open.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\tcloseTooltip() {\n\t\tthis._tooltip?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the tooltip bound to this layer depending on its current state.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\ttoggleTooltip() {\n\t\tthis._tooltip?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the tooltip bound to this layer is currently open.\n\t * @group Tooltip methods\n\t * @returns {boolean}\n\t */\n\tisTooltipOpen() {\n\t\treturn this._tooltip?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the tooltip bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Tooltip methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetTooltipContent(content) {\n\t\tthis._tooltip?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the tooltip bound to this layer.\n\t * @group Tooltip methods\n\t * @returns {Tooltip|undefined}\n\t */\n\tgetTooltip() {\n\t\treturn this._tooltip;\n\t},\n\n\t// also the `add` listener, so any truthy argument adds\n\t_toggleFocusListeners(add) {\n\t\tif (this.getElement) {\n\t\t\tthis._addFocusListenersOnLayer(this, !add);\n\t\t} else if (this.eachLayer) {\n\t\t\tthis.eachLayer(layer => this._addFocusListenersOnLayer(layer, !add), this);\n\t\t}\n\t},\n\n\t_addFocusListenersOnLayer(layer, remove) {\n\t\tconst el = typeof layer.getElement === 'function' && layer.getElement();\n\t\tif (el) {\n\t\t\tconst toggle = remove ? DomEvent.off : DomEvent.on;\n\t\t\tif (!remove) {\n\t\t\t\t// Remove focus listener, if already existing\n\t\t\t\tel._maplair_focus_handler && DomEvent.off(el, 'focus', el._maplair_focus_handler, this);\n\n\t\t\t\tel._maplair_focus_handler = () => {\n\t\t\t\t\tif (this._tooltip) {\n\t\t\t\t\t\tthis._tooltip._source = layer;\n\t\t\t\t\t\tthis.openTooltip();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tel._maplair_focus_handler && toggle(el, 'focus', el._maplair_focus_handler, this);\n\t\t\ttoggle(el, 'blur', this.closeTooltip, this);\n\n\t\t\tif (remove) {\n\t\t\t\tdelete el._maplair_focus_handler;\n\t\t\t}\n\t\t}\n\t},\n\n\t_setAriaDescribedByOnLayer(layer) {\n\t\tconst el = typeof layer.getElement === 'function' && layer.getElement();\n\t\tel?.setAttribute?.('aria-describedby', this._tooltip._container.id);\n\t},\n\n\t_openTooltip(e) {\n\t\tif (!this._tooltip || !this._map) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the map is moving, we will show the tooltip after it's done.\n\t\tif (this._map.dragging?.moving()) {\n\t\t\tif (e.type === 'add' && !this._moveEndOpensTooltip) {\n\t\t\t\tthis._moveEndOpensTooltip = true;\n\t\t\t\tthis._map.once('moveend', () => {\n\t\t\t\t\tthis._moveEndOpensTooltip = false;\n\t\t\t\t\tthis._openTooltip(e);\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tthis._tooltip._source = e.propagatedFrom ?? e.target;\n\n\t\tthis.openTooltip(this._tooltip.options.sticky ? e.latlng : undefined);\n\t},\n\n\t_moveTooltip(e) {\n\t\tlet latlng = e.latlng, containerPoint, layerPoint;\n\t\tif (this._tooltip.options.sticky && e.originalEvent) {\n\t\t\tcontainerPoint = this._map.pointerEventToContainerPoint(e.originalEvent);\n\t\t\tlayerPoint = this._map.containerPointToLayerPoint(containerPoint);\n\t\t\tlatlng = this._map.layerPointToLatLng(layerPoint);\n\t\t}\n\t\tthis._tooltip.setLatLng(latlng);\n\t}\n};\n/** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */\n\n/**\n * Used to display small texts on top of map layers.\n *\n * @example\n * If you want to just bind a tooltip to marker:\n *\n * ```js\n * marker.bindTooltip(\"my tooltip text\").openTooltip();\n * ```\n * Path overlays like polylines also have a `bindTooltip` method.\n *\n * A tooltip can be also standalone:\n *\n * ```js\n * const tooltip = new Tooltip()\n * \t.setLatLng(latlng)\n * \t.setContent('Hello world!<br />This is a nice tooltip.')\n * \t.addTo(map);\n * ```\n * or\n * ```js\n * const tooltip = new Tooltip(latlng, {content: 'Hello world!<br />This is a nice tooltip.'})\n * \t.addTo(map);\n * ```\n *\n * **Security note.** Tooltip string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or\n * build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindTooltip(el);\n * ```\n *\n * Note about tooltip offset. Maplair takes two options in consideration\n * for computing tooltip offsetting:\n * - the `offset` Tooltip option: it defaults to [0, 0], and it's specific to one tooltip.\n * Add a positive x offset to move the tooltip to the right, and a positive y offset to\n * move it to the bottom. Negatives will move to the left and top.\n * - the `tooltipAnchor` Icon option: this will only be considered for Marker. You\n * should adapt this value if you use a custom icon.\n */\nexport class Tooltip extends DivOverlay {\n\n\tstatic defaultOptions = {\n\t\tpane: 'tooltipPane',\n\t\toffset: [0, 0],\n\t\tdirection: 'auto',\n\t\tpermanent: false,\n\t\tsticky: false,\n\t\topacity: 0.9\n\t};\n\n\t/**\n\t * Instantiates a `Tooltip` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the tooltip with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {TooltipOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Tooltip` object given `latlng` where the tooltip will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {TooltipOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Tooltip);\n\t}\n\n\t/**\n\t * Adds the tooltip to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\t\tthis.setOpacity(this.options.opacity);\n\n\t\tmap.fire('tooltipopen', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.addEventParent(this._source);\n\n\t\t\tthis._source.fire('tooltipopen', {tooltip: this}, true);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the tooltip from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('tooltipclose', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.removeEventParent(this._source);\n\n\t\t\tthis._source.fire('tooltipclose', {tooltip: this}, true);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the tooltip listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (!this.options.permanent) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-tooltip',\n\t\tclassName = `${prefix} ${this.options.className || ''} maplair-zoom-animated`;\n\n\t\tthis._contentNode = this._container = DomUtil.create('div', className);\n\n\t\tthis._container.setAttribute('role', 'tooltip');\n\t\tthis._container.setAttribute('id', `maplair-tooltip-${Util.stamp(this)}`);\n\t}\n\n\t_updateLayout() {}\n\n\t_adjustPan() {}\n\n\t/**\n\t * Updates the tooltip content, layout and position.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\t// The automatic direction is chosen once per opening and content, so that\n\t\t// the tooltip does not flip sides while the map or the pointer moves.\n\t\tthis._autoDirection = undefined;\n\t\tsuper.update();\n\t}\n\n\t_setPosition(pos) {\n\t\tlet direction = this.options.direction,\n\t\tshift = new Point(0, 0);\n\t\tconst container = this._container,\n\t\ttooltipWidth = container.offsetWidth,\n\t\ttooltipHeight = container.offsetHeight,\n\t\toffset = new Point(this.options.offset),\n\t\tanchor = this._getAnchor();\n\n\t\tif (!directions.includes(direction)) {\n\t\t\t({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));\n\t\t\tif (direction === 'left') {\n\t\t\t\t// mirror the offset and anchor, which are meant for the right side\n\t\t\t\toffset.x = -offset.x;\n\t\t\t\tanchor.x = -anchor.x;\n\t\t\t}\n\t\t}\n\n\t\tlet subX = tooltipWidth / 2,\n\t\tsubY = tooltipHeight / 2;\n\t\tif (direction === 'top') {\n\t\t\tsubY = tooltipHeight;\n\t\t} else if (direction === 'bottom') {\n\t\t\tsubY = 0;\n\t\t} else if (direction === 'right') {\n\t\t\tsubX = 0;\n\t\t} else if (direction === 'left') {\n\t\t\tsubX = tooltipWidth;\n\t\t}\n\n\t\tpos = pos.subtract(new Point(subX, subY, true)).add(offset).add(anchor).add(shift);\n\n\t\tcontainer.classList.remove(\n\t\t\t'maplair-tooltip-right',\n\t\t\t'maplair-tooltip-left',\n\t\t\t'maplair-tooltip-top',\n\t\t\t'maplair-tooltip-bottom'\n\t\t);\n\t\tcontainer.classList.add(`maplair-tooltip-${direction}`);\n\n\t\t// Let the tip point at the source despite the shift\n\t\tconst tipShift = direction === 'top' || direction === 'bottom' ?\n\t\t\tclampTip(-shift.x, tooltipWidth) :\n\t\t\tclampTip(-shift.y, tooltipHeight);\n\t\tif (tipShift) {\n\t\t\tcontainer.style.setProperty('--maplair-tooltip-tip-shift', `${tipShift}px`);\n\t\t} else {\n\t\t\tcontainer.style.removeProperty('--maplair-tooltip-tip-shift');\n\t\t}\n\n\t\tthis._setContainerPosition(pos);\n\t}\n\n\t// Chooses the direction of an `auto` tooltip by the available space:\n\t// preferably the side towards the center, otherwise the opposite side,\n\t// above or below. The tooltip is shifted along that side to stay in view.\n\t_getAutoPlacement(pos, offset, anchor, width, height) {\n\t\tconst area = this._getAutoArea(),\n\t\tpoint = this._map.layerPointToContainerPoint(pos),\n\t\tx = point.x + offset.x + anchor.x,\n\t\ty = point.y + offset.y + anchor.y,\n\t\t// the space for each direction, see `direction` for the mirrored left side\n\t\tspace = {\n\t\t\tright: area.max.x - x - width - tipSize,\n\t\t\tleft: point.x - offset.x - anchor.x - area.min.x - width - tipSize,\n\t\t\ttop: y - area.min.y - height - tipSize,\n\t\t\tbottom: area.max.y - y - height - tipSize\n\t\t};\n\n\t\tif (!this._autoDirection) {\n\t\t\tconst sides = point.x < (area.min.x + area.max.x) / 2 ? ['right', 'left'] : ['left', 'right'],\n\t\t\tfallback = space.right >= space.left ? 'right' : 'left';\n\t\t\tthis._autoDirection = [...sides, 'top', 'bottom'].find(d => space[d] >= 0 &&\n\t\t\t\t// above or below, the tooltip has to fit horizontally\n\t\t\t\t(d === 'right' || d === 'left' || width <= area.max.x - area.min.x)) ?? fallback;\n\t\t}\n\n\t\tconst direction = this._autoDirection,\n\t\tshift = direction === 'top' || direction === 'bottom' ?\n\t\t\tnew Point(shiftInto(x - width / 2, width, area.min.x, area.max.x), 0) :\n\t\t\tnew Point(0, shiftInto(y - height / 2, height, area.min.y, area.max.y));\n\n\t\treturn {direction, shift};\n\t}\n\n\t// The area in container points an `auto` tooltip should stay within:\n\t// the map, or the viewport for an overflowing tooltip.\n\t_getAutoArea() {\n\t\tconst map = this._map;\n\t\tlet min = new Point(0, 0),\n\t\tmax = map.getSize();\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = map._container,\n\t\t\trect = mapContainer.getBoundingClientRect(),\n\t\t\torigin = new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop),\n\t\t\tviewport = document.documentElement;\n\t\t\tmin = min.subtract(origin);\n\t\t\tmax = new Point(viewport.clientWidth, viewport.clientHeight).subtract(origin);\n\t\t}\n\t\tconst padding = new Point(autoPadding, autoPadding);\n\t\treturn {min: min.add(padding), max: max.subtract(padding)};\n\t}\n\n\t_updatePosition() {\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng)._round();\n\t\tthis._setPosition(pos);\n\t}\n\n\t/**\n\t * Sets the opacity of the tooltip.\n\t * @param {number} opacity\n\t * @returns {void}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._container) {\n\t\t\tthis._container.style.opacity = `${opacity}`;\n\t\t}\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);\n\t\tthis._setPosition(pos);\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the tooltip on the source layer?\n\t\treturn new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapTooltipMethods);\n\n\t\tLayer.include(layerTooltipMethods);\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,aAAa;CAAC;CAAO;CAAU;CAAU;CAAS;AAAM;AAI9D,MAAM,UAAU;AAChB,MAAA,cAAc;AAGd,SAAS,UAAU,OAAO,MAAM,KAAK,KAAK;CACzC,OAAO,KAAK,IAAI,GAAG,MAAM,KAAK,IAAI,KAAK,IAAI,GAAG,QAAQ,OAAO,GAAG;AACjE;AAGA,SAAS,SAAS,UAAU,MAAM;CACjC,MAAM,MAAM,KAAK,IAAI,GAAG,OAAO,IAAI,EAAW;CAC9C,OAAO,KAAK,MAAM,KAAK,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC;AAC1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,oBAAoB;;;;;;;;;;;;;;CAczB,YAAY,SAAS,QAAQ,SAAS;EAErC,KAAK,aAAa,SAAS,SAAS,QAAQ,OAAO,CAAC,CAClD,OAAO,IAAI;EAEb,OAAO;CACR;;;;;;;CAQA,aAAa,SAAS;EACrB,QAAQ,MAAM;EACd,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;AAmBA,MAAM,sBAAsB;;;;;;;;;;;;;CAa3B,YAAY,SAAS,SAAS;EAE7B,MAAM,MAAM,KAAK,c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/Tooltip.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as Util from '../core/Util.js';\nimport {FeatureGroup} from './FeatureGroup.js';\n\n// which point of the tooltip (as a fraction of its width and height) sits at the anchor, for each direction\nconst directions = {top: [0.5, 1], bottom: [0.5, 0], center: [0.5, 0.5], right: [0, 0.5], left: [1, 0.5]};\n\n// The size of the tooltip tip (see `.maplair-tooltip-top` etc. in maplair.css) and\n// the minimum distance of an `auto` tooltip to the edge of the map.\nconst tipSize = 6,\nautoPadding = 4;\n\n// The shift moving a box from `start` with `size` into the range `[min, max]`.\nfunction shiftInto(start, size, min, max) {\n\treturn Math.max(0, min - start) - Math.max(0, start + size - max);\n}\n\n// Keeps the shifted tip off the rounded corners of the tooltip.\nfunction clampTip(tipShift, size) {\n\tconst max = Math.max(0, size / 2 - 2 * tipSize);\n\treturn Math.round(Math.min(max, Math.max(-max, tipShift)));\n}\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, TooltipEvent} from '../core/Events.js' */\n\n/**\n * Options of `Tooltip`.\n * @typedef {object} TooltipOptions\n * @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.\n * @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position, in\n * pixels. Mirrored horizontally when an `auto` tooltip opens to the left.\n * @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']\n * Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,\n * `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when\n * opening the tooltip: preferably the side towards the center of the map (`right` or\n * `left`), otherwise the opposite side, `top` or `bottom`. The tooltip is shifted\n * along that side to stay within the map (within the viewport if `overflow` is set),\n * its tip still pointing at the source.\n * @property {boolean} [permanent=false] Whether to open the tooltip permanently or only\n * on pointerover.\n * @property {boolean} [sticky=false] If true, the tooltip will follow the pointer\n * instead of being fixed at the feature center.\n * @property {number} [opacity=0.9] Tooltip container opacity.\n * @extends DivOverlayOptions\n */\n\n/**\n * Methods of `MaplairMap` for tooltips.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#tooltipopen {TooltipEvent} Fired when a tooltip is opened in the map.\n * @fires MaplairMap#tooltipclose {TooltipEvent} Fired when a tooltip in the map is closed.\n */\nconst mapTooltipMethods = {\n\t/**\n\t * Opens the specified tooltip.\n\t *\n\t * Alternatively, creates a tooltip with the specified content and options and\n\t * opens it. String content is rendered as HTML; sanitize untrusted input or pass\n\t * an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Tooltip|DivOverlayContent} tooltip The tooltip, or the content of a new\n\t * tooltip.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {TooltipOptions} [options]\n\t * @returns {this}\n\t */\n\topenTooltip(tooltip, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Tooltip, tooltip, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the tooltip given as parameter.\n\t * @group Methods for layers and controls\n\t * @param {Tooltip} tooltip\n\t * @returns {this}\n\t */\n\tcloseTooltip(tooltip) {\n\t\ttooltip.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapTooltipMethods} MapTooltipMethods */\n\n/**\n * Methods of `Layer` for tooltips. All layers share a set of methods convenient for\n * binding tooltips to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindTooltip('Hi There!').addTo(map);\n * layer.openTooltip();\n * layer.closeTooltip();\n * ```\n *\n * @lends Layer.prototype\n * @fires Layer#tooltipopen {TooltipEvent} Fired when a tooltip bound to this layer is\n * opened.\n * @fires Layer#tooltipclose {TooltipEvent} Fired when a tooltip bound to this layer is\n * closed.\n */\nconst layerTooltipMethods = {\n\t/**\n\t * Binds a tooltip to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it or pass an `HTMLElement` with safe\n\t * `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String`, `HTMLElement` or `DocumentFragment`.\n\t * @group Tooltip methods\n\t * @param {DivOverlayContent|Tooltip} content\n\t * @param {TooltipOptions} [options]\n\t * @returns {this}\n\t */\n\tbindTooltip(content, options) {\n\t\t// an open tooltip is replaced, a closed one reused\n\t\tconst old = this.isTooltipOpen() ? null : this._tooltip;\n\n\t\t// the handlers depend on the old options, so they go before the new ones are applied\n\t\tif (this._tooltip) {\n\t\t\tthis.unbindTooltip();\n\t\t}\n\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._tooltip = this._initOverlay(Tooltip, old, content, options);\n\t\tthis._initTooltipInteractions();\n\n\t\tif (this._tooltip.options.permanent && this._map?.hasLayer(this)) {\n\t\t\tthis.openTooltip();\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the tooltip previously bound with `bindTooltip`.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\tunbindTooltip() {\n\t\tif (this._tooltip) {\n\t\t\tthis._initTooltipInteractions(true);\n\t\t\tthis.closeTooltip();\n\t\t\tthis._tooltip = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t_initTooltipInteractions(remove) {\n\t\tconst {permanent, sticky} = this._tooltip.options,\n\t\tevents = {\n\t\t\tremove: this.closeTooltip,\n\t\t\tmove: this._moveTooltip\n\t\t};\n\t\tif (permanent) {\n\t\t\tevents.add = this._openTooltip;\n\t\t} else {\n\t\t\tevents.pointerover = this._openTooltip;\n\t\t\tevents.pointerout = this.closeTooltip;\n\t\t\tevents.click = this._openTooltip;\n\t\t\t// layer elements can be recreated on every add\n\t\t\tevents.add = this._toggleFocusListeners;\n\t\t\tif (this._map) {\n\t\t\t\tthis._toggleFocusListeners(!remove);\n\t\t\t}\n\t\t}\n\t\tif (sticky) {\n\t\t\tevents.pointermove = this._moveTooltip;\n\t\t}\n\t\tthis[remove ? 'off' : 'on'](events);\n\t},\n\n\t/**\n\t * Opens the bound tooltip at the specified `latlng` or at the default tooltip\n\t * anchor if no `latlng` is passed.\n\t * @group Tooltip methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenTooltip(latlng) {\n\t\tif (this._tooltip) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._tooltip._source = this;\n\t\t\t}\n\t\t\tif (this._tooltip._prepareOpen(latlng)) {\n\t\t\t\t// open the tooltip on the map\n\t\t\t\tthis._tooltip.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the tooltip bound to this layer if it is open.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\tcloseTooltip() {\n\t\tthis._tooltip?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the tooltip bound to this layer depending on its current state.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\ttoggleTooltip() {\n\t\tthis._tooltip?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the tooltip bound to this layer is currently open.\n\t * @group Tooltip methods\n\t * @returns {boolean}\n\t */\n\tisTooltipOpen() {\n\t\treturn this._tooltip?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the tooltip bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Tooltip methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetTooltipContent(content) {\n\t\tthis._tooltip?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the tooltip bound to this layer.\n\t * @group Tooltip methods\n\t * @returns {Tooltip|undefined}\n\t */\n\tgetTooltip() {\n\t\treturn this._tooltip;\n\t},\n\n\t// also the `add` listener, so any truthy argument adds\n\t_toggleFocusListeners(add) {\n\t\tif (this.getElement) {\n\t\t\tthis._addFocusListenersOnLayer(this, !add);\n\t\t} else if (this.eachLayer) {\n\t\t\tthis.eachLayer(layer => this._addFocusListenersOnLayer(layer, !add), this);\n\t\t}\n\t},\n\n\t_addFocusListenersOnLayer(layer, remove) {\n\t\tconst el = typeof layer.getElement === 'function' && layer.getElement();\n\t\tif (el) {\n\t\t\tconst toggle = remove ? DomEvent.off : DomEvent.on;\n\t\t\tif (!remove) {\n\t\t\t\t// Remove focus listener, if already existing\n\t\t\t\tel._maplair_focus_handler && DomEvent.off(el, 'focus', el._maplair_focus_handler, this);\n\n\t\t\t\t// open only on keyboard focus: an element clicked with the mouse keeps focus and gets it again whenever\n\t\t\t\t// the window is refocused or a popup closes, which would open the tooltip without the pointer over it\n\t\t\t\tel._maplair_focus_handler = () => {\n\t\t\t\t\tif (this._tooltip && el.matches(':focus-visible')) {\n\t\t\t\t\t\tthis._tooltip._source = layer;\n\t\t\t\t\t\tthis.openTooltip();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tel._maplair_focus_handler && toggle(el, 'focus', el._maplair_focus_handler, this);\n\t\t\ttoggle(el, 'blur', this.closeTooltip, this);\n\n\t\t\tif (remove) {\n\t\t\t\tdelete el._maplair_focus_handler;\n\t\t\t}\n\t\t}\n\t},\n\n\t_openTooltip(e) {\n\t\tif (!this._tooltip || !this._map) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the map is moving, we will show the tooltip after it's done.\n\t\tif (this._map.dragging?.moving()) {\n\t\t\tif (e.type === 'add' && !this._moveEndOpensTooltip) {\n\t\t\t\tthis._moveEndOpensTooltip = true;\n\t\t\t\tthis._map.once('moveend', () => {\n\t\t\t\t\tthis._moveEndOpensTooltip = false;\n\t\t\t\t\tthis._openTooltip(e);\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tthis._tooltip._source = e.propagatedFrom ?? e.target;\n\n\t\tthis.openTooltip(this._tooltip.options.sticky ? e.latlng : undefined);\n\t},\n\n\t_moveTooltip(e) {\n\t\tthis._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ?\n\t\t\tthis._map.pointerEventToLatLng(e.originalEvent) : e.latlng);\n\t}\n};\n/** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */\n\n/**\n * Used to display small texts on top of map layers.\n *\n * @example\n * If you want to just bind a tooltip to marker:\n *\n * ```js\n * marker.bindTooltip(\"my tooltip text\").openTooltip();\n * ```\n * Path overlays like polylines also have a `bindTooltip` method.\n *\n * A tooltip can be also standalone:\n *\n * ```js\n * const tooltip = new Tooltip()\n * \t.setLatLng(latlng)\n * \t.setContent('Hello world!<br />This is a nice tooltip.')\n * \t.addTo(map);\n * ```\n * or\n * ```js\n * const tooltip = new Tooltip(latlng, {content: 'Hello world!<br />This is a nice tooltip.'})\n * \t.addTo(map);\n * ```\n *\n * **Security note.** Tooltip string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it first, or build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindTooltip(el);\n * ```\n *\n * Note about tooltip offset. Maplair takes two options in consideration\n * for computing tooltip offsetting:\n * - the `offset` Tooltip option: it defaults to [0, 0], and it's specific to one tooltip.\n * Add a positive x offset to move the tooltip to the right, and a positive y offset to\n * move it to the bottom. Negatives will move to the left and top.\n * - the `tooltipAnchor` Icon option: this will only be considered for Marker. You\n * should adapt this value if you use a custom icon.\n */\nexport class Tooltip extends DivOverlay {\n\n\tstatic defaultOptions = {\n\t\tpane: 'tooltipPane',\n\t\toffset: [0, 0],\n\t\tdirection: 'auto',\n\t\tpermanent: false,\n\t\tsticky: false,\n\t\topacity: 0.9\n\t};\n\n\t/**\n\t * Instantiates a `Tooltip` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the tooltip with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {TooltipOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Tooltip` object given `latlng` where the tooltip will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {TooltipOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Tooltip);\n\t}\n\n\t/**\n\t * Adds the tooltip to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\t\tthis.setOpacity(this.options.opacity);\n\n\t\tmap.fire('tooltipopen', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.addEventParent(this._source);\n\t\t\tthis._ariaSource = this._source.getElement?.();\n\t\t\tthis._ariaSource?.setAttribute('aria-describedby', this._container.id);\n\n\t\t\tthis._source.fire('tooltipopen', {tooltip: this}, true);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the tooltip from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('tooltipclose', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.removeEventParent(this._source);\n\n\t\t\t// drop the reference to the removed tooltip unless something else replaced it since\n\t\t\tconst el = this._ariaSource;\n\t\t\tif (el?.getAttribute('aria-describedby') === this._container.id) { el.removeAttribute('aria-describedby'); }\n\t\t\tthis._ariaSource = null;\n\n\t\t\tthis._source.fire('tooltipclose', {tooltip: this}, true);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the tooltip listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (!this.options.permanent) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-tooltip',\n\t\tclassName = `${prefix} ${this.options.className || ''} maplair-zoom-animated`;\n\n\t\tthis._contentNode = this._container = DomUtil.create('div', className);\n\n\t\tthis._container.setAttribute('role', 'tooltip');\n\t\tthis._container.id = `maplair-tooltip-${Util.stamp(this)}`;\n\t}\n\n\t_updateLayout() {}\n\n\t_adjustPan() {}\n\n\t/**\n\t * Updates the tooltip content, layout and position.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\t// The automatic direction is chosen once per opening and content, so that\n\t\t// the tooltip does not flip sides while the map or the pointer moves.\n\t\tthis._autoDirection = undefined;\n\t\tsuper.update();\n\t}\n\n\t_setPosition(pos) {\n\t\tlet direction = this.options.direction,\n\t\tshift = new Point(0, 0);\n\t\tconst container = this._container,\n\t\ttooltipWidth = container.offsetWidth,\n\t\ttooltipHeight = container.offsetHeight,\n\t\toffset = new Point(this.options.offset);\n\n\t\tif (!(direction in directions)) {\n\t\t\t({direction, shift} = this._getAutoPlacement(pos, offset, tooltipWidth, tooltipHeight));\n\t\t\t// mirror the offset, which is meant for the right side\n\t\t\tif (direction === 'left') { offset.x = -offset.x; }\n\t\t}\n\t\tconst anchor = this._getAnchor(direction);\n\n\t\tconst [fx, fy] = directions[direction];\n\t\tpos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);\n\n\t\tfor (const d in directions) {\n\t\t\tcontainer.classList.toggle(`maplair-tooltip-${d}`, d === direction);\n\t\t}\n\n\t\t// Let the tip point at the source despite the shift\n\t\tconst tipShift = direction === 'top' || direction === 'bottom' ?\n\t\t\tclampTip(-shift.x, tooltipWidth) :\n\t\t\tclampTip(-shift.y, tooltipHeight);\n\t\tif (tipShift) {\n\t\t\tcontainer.style.setProperty('--maplair-tooltip-tip-shift', `${tipShift}px`);\n\t\t} else {\n\t\t\tcontainer.style.removeProperty('--maplair-tooltip-tip-shift');\n\t\t}\n\n\t\tthis._setContainerPosition(pos);\n\t}\n\n\t// Chooses the direction of an `auto` tooltip by the available space:\n\t// preferably the side towards the center, otherwise the opposite side,\n\t// above or below. The tooltip is shifted along that side to stay in view.\n\t_getAutoPlacement(pos, offset, width, height) {\n\t\tconst area = this._getAutoArea(),\n\t\tpoint = this._map.layerPointToContainerPoint(pos),\n\t\t// where the tooltip attaches for each direction, with the offset mirrored on the left side\n\t\tat = {};\n\t\tfor (const d of ['right', 'left', 'top', 'bottom']) {\n\t\t\tat[d] = point.add(this._getAnchor(d)).add(d === 'left' ? [-offset.x, offset.y] : offset);\n\t\t}\n\t\t// the space for each direction\n\t\tconst space = {\n\t\t\tright: area.max.x - at.right.x - width - tipSize,\n\t\t\tleft: at.left.x - area.min.x - width - tipSize,\n\t\t\ttop: at.top.y - area.min.y - height - tipSize,\n\t\t\tbottom: area.max.y - at.bottom.y - height - tipSize\n\t\t};\n\n\t\tif (!this._autoDirection) {\n\t\t\tconst sides = point.x < (area.min.x + area.max.x) / 2 ? ['right', 'left'] : ['left', 'right'],\n\t\t\tfallback = space.right >= space.left ? 'right' : 'left';\n\t\t\tthis._autoDirection = [...sides, 'top', 'bottom'].find(d => space[d] >= 0 &&\n\t\t\t\t// above or below, the tooltip has to fit horizontally\n\t\t\t\t(d === 'right' || d === 'left' || width <= area.max.x - area.min.x)) ?? fallback;\n\t\t}\n\n\t\tconst direction = this._autoDirection,\n\t\t{x, y} = at[direction],\n\t\tshift = direction === 'top' || direction === 'bottom' ?\n\t\t\tnew Point(shiftInto(x - width / 2, width, area.min.x, area.max.x), 0) :\n\t\t\tnew Point(0, shiftInto(y - height / 2, height, area.min.y, area.max.y));\n\n\t\treturn {direction, shift};\n\t}\n\n\t// The area in container points an `auto` tooltip should stay within:\n\t// the map, or the viewport for an overflowing tooltip.\n\t_getAutoArea() {\n\t\tconst map = this._map;\n\t\tlet min = new Point(0, 0),\n\t\tmax = map.getSize();\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = map._container,\n\t\t\trect = mapContainer.getBoundingClientRect(),\n\t\t\torigin = new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop),\n\t\t\tviewport = document.documentElement;\n\t\t\tmin = min.subtract(origin);\n\t\t\tmax = new Point(viewport.clientWidth, viewport.clientHeight).subtract(origin);\n\t\t}\n\t\tconst padding = new Point(autoPadding, autoPadding);\n\t\treturn {min: min.add(padding), max: max.subtract(padding)};\n\t}\n\n\t_updatePosition() {\n\t\tconst pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));\n\t\tthis._setPosition(pos);\n\t}\n\n\t/**\n\t * Sets the opacity of the tooltip.\n\t * @param {number} opacity\n\t * @returns {void}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._container) {\n\t\t\tthis._container.style.opacity = `${opacity}`;\n\t\t}\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);\n\t\tthis._setPosition(pos);\n\t}\n\n\t// Where the tooltip opening in the given direction attaches on the source layer\n\t_getAnchor(direction) {\n\t\treturn new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor(direction) : [0, 0]);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapTooltipMethods);\n\n\t\tLayer.include(layerTooltipMethods);\n\t}\n}\n"],"mappings":";;;;;;;;AASA,MAAM,aAAa;CAAC,KAAK,CAAC,IAAK,CAAC;CAAG,QAAQ,CAAC,IAAK,CAAC;CAAG,QAAQ,CAAC,IAAK,EAAG;CAAG,OAAO,CAAC,GAAG,EAAG;CAAG,MAAM,CAAC,GAAG,EAAG;AAAC;AAIxG,MAAM,UAAU;AAChB,MAAA,cAAc;AAGd,SAAS,UAAU,OAAO,MAAM,KA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