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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transformation.js","names":[],"sources":["../../../src/geometry/Transformation.js"],"sourcesContent":["import {Point} from './Point.js';\n\n/**\n * Represents an affine transformation: a set of coefficients `a`, `b`, `c`, `d`\n * for transforming a point of a form `(x, y)` into `(a*x + b, c*y + d)` and doing\n * the reverse. Used by Maplair in its projections code.\n *\n * @example\n * ```js\n * const transformation = new Transformation(2, 5, -1, 10),\n * \tp = new Point(1, 2),\n * \tp2 = transformation.transform(p), // new Point(7, 8)\n * \tp3 = transformation.untransform(p2); // new Point(1, 2)\n * ```\n */\nexport class Transformation {\n\t/**\n\t * Instantiates a Transformation object with the given coefficients. Alternatively,\n\t * expects a coefficients array of the form `[a, b, c, d]`.\n\t * @param {number|[number, number, number, number]} a\n\t * @param {number} [b]\n\t * @param {number} [c]\n\t * @param {number} [d]\n\t */\n\tconstructor(a, b, c, d) {\n\t\tif (Array.isArray(a)) {
|
|
1
|
+
{"version":3,"file":"Transformation.js","names":[],"sources":["../../../src/geometry/Transformation.js"],"sourcesContent":["import {Point} from './Point.js';\n\n/**\n * Represents an affine transformation: a set of coefficients `a`, `b`, `c`, `d`\n * for transforming a point of a form `(x, y)` into `(a*x + b, c*y + d)` and doing\n * the reverse. Used by Maplair in its projections code.\n *\n * @example\n * ```js\n * const transformation = new Transformation(2, 5, -1, 10),\n * \tp = new Point(1, 2),\n * \tp2 = transformation.transform(p), // new Point(7, 8)\n * \tp3 = transformation.untransform(p2); // new Point(1, 2)\n * ```\n */\nexport class Transformation {\n\t/**\n\t * Instantiates a Transformation object with the given coefficients. Alternatively,\n\t * expects a coefficients array of the form `[a, b, c, d]`.\n\t * @param {number|[number, number, number, number]} a\n\t * @param {number} [b]\n\t * @param {number} [c]\n\t * @param {number} [d]\n\t */\n\tconstructor(a, b, c, d) {\n\t\tif (Array.isArray(a)) { [a, b, c, d] = a; }\n\t\tthis._a = a;\n\t\tthis._b = b;\n\t\tthis._c = c;\n\t\tthis._d = d;\n\t}\n\n\t/**\n\t * Returns a transformed point, optionally multiplied by the given scale.\n\t * Only accepts actual `Point` instances, not arrays.\n\t * @param {Point} point\n\t * @param {number} [scale]\n\t * @returns {Point}\n\t */\n\ttransform(point, scale) { // (Point, Number) -> Point\n\t\treturn this._transform(new Point(point), scale);\n\t}\n\n\t// destructive transform (faster)\n\t_transform(point, scale) {\n\t\tscale ||= 1;\n\t\tpoint.x = scale * (this._a * point.x + this._b);\n\t\tpoint.y = scale * (this._c * point.y + this._d);\n\t\treturn point;\n\t}\n\n\t/**\n\t * Returns the reverse transformation of the given point, optionally divided\n\t * by the given scale. Only accepts actual `Point` instances, not arrays.\n\t * @param {Point} point\n\t * @param {number} [scale]\n\t * @returns {Point}\n\t */\n\tuntransform(point, scale) {\n\t\tscale ||= 1;\n\t\treturn new Point(\n\t\t\t(point.x / scale - this._b) / this._a,\n\t\t\t(point.y / scale - this._d) / this._c);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,iBAAb,MAA4B;;;;;;;;;CAS3B,YAAY,GAAG,GAAG,GAAG,GAAG;EACvB,IAAI,MAAM,QAAQ,CAAC,GAAK,CAAC,GAAG,GAAG,GAAG,KAAK;EACvC,KAAK,KAAK;EACV,KAAK,KAAK;EACV,KAAK,KAAK;EACV,KAAK,KAAK;CACX;;;;;;;;CASA,UAAU,OAAO,OAAO;EACvB,OAAO,KAAK,WAAW,IAAI,MAAM,KAAK,GAAG,KAAK;CAC/C;CAGA,WAAW,OAAO,OAAO;EACxB,UAAU;EACV,MAAM,IAAI,SAAS,KAAK,KAAK,MAAM,IAAI,KAAK;EAC5C,MAAM,IAAI,SAAS,KAAK,KAAK,MAAM,IAAI,KAAK;EAC5C,OAAO;CACR;;;;;;;;CASA,YAAY,OAAO,OAAO;EACzB,UAAU;EACV,OAAO,IAAI,OACT,MAAM,IAAI,QAAQ,KAAK,MAAM,KAAK,KAClC,MAAM,IAAI,QAAQ,KAAK,MAAM,KAAK,EAAE;CACvC;AACD"}
|
|
@@ -64,7 +64,7 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
64
64
|
this._initContainer();
|
|
65
65
|
this._container.classList.add("maplair-zoom-animated");
|
|
66
66
|
}
|
|
67
|
-
this.getPane().
|
|
67
|
+
this.getPane().append(this._container);
|
|
68
68
|
this._resizeContainer();
|
|
69
69
|
this._onMoveEnd();
|
|
70
70
|
}
|
|
@@ -98,7 +98,8 @@ var BlanketOverlay = class BlanketOverlay extends Layer {
|
|
|
98
98
|
this._updateTransform(this._map.getCenter(), this._map.getZoom());
|
|
99
99
|
}
|
|
100
100
|
_updateTransform(center, zoom) {
|
|
101
|
-
const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map.getSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom))
|
|
101
|
+
const scale = this._map.getZoomScale(zoom, this._zoom), viewHalf = this._map.getSize().multiplyBy(.5 + this.options.padding), currentCenterPoint = this._map.project(this._center, zoom), topLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)._subtract(this._map._getNewPixelOrigin(center, zoom));
|
|
102
|
+
if (scale === 1) this._map._snapLayerPoint(topLeftOffset);
|
|
102
103
|
setTransform(this._container, topLeftOffset, scale);
|
|
103
104
|
}
|
|
104
105
|
_onMoveEnd(ev) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n/** @import {LayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener} from '../core/Events.js' */\n\n/**\n * Options of `BlanketOverlay`.\n * @typedef {object} BlanketOverlayOptions\n * @property {number} [padding=0.1] How much to extend the clip area around the map\n * view (relative to its size) e.g. 0.1 would be 10% of map view in each direction.\n * @property {boolean} [continuous=false] When `false`, the blanket will update its\n * position only when the map state settles (*after* a pan/zoom animation). When\n * `true`, it will update when the map state changes (*during* pan/zoom animations).\n * @extends LayerOptions\n */\n\n/**\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element.\n *\n * Subclasses must define the following methods:\n *\n * * `_initContainer()` must initialize the HTML element to use as blanket, and store\n * it as `this._container`. The base implementation creates a blank `<div>`.\n * * `_destroyContainer()` must destroy the HTML element in `this._container` and free\n * any other resources. The base implementation destroys the element and removes\n * any event handlers attached to it.\n * * `_resizeContainer(): Point`: the base implementation resizes the container\n * (based on the map's size and taking into account the padding), returning the new\n * size in CSS pixels. Subclass implementations shall reset container parameters and\n * data structures as needed.\n * * `_onZoomEnd(ev?: PointerEvent)` (optional) runs on the map's `zoomend` event.\n * * `_onViewReset(ev?: PointerEvent)` (optional) runs on the map's `viewreset` event.\n * * `_onSettled()` runs whenever the map state settles after changing (at the end of\n * pan/zoom animations, etc). This should trigger the bulk of any rendering logic.\n * If the `continuous` option is set to `true`, then this also runs on any map\n * state change (including *during* pan/zoom animations).\n */\nexport class BlanketOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tpadding: 0.1,\n\t\tcontinuous: false,\n\t};\n\n\t/**\n\t * @param {BlanketOverlayOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(BlanketOverlay);\n\t}\n\n\t/**\n\t * Adds the blanket to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._container) {\n\t\t\tthis._initContainer(); // defined by renderer implementations\n\n\t\t\t// always keep transform-origin as 0 0, #8794\n\t\t\tthis._container.classList.add('maplair-zoom-animated');\n\t\t}\n\n\t\tthis.getPane().
|
|
1
|
+
{"version":3,"file":"BlanketOverlay.js","names":["DomUtil.create"],"sources":["../../../src/layer/BlanketOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as Util from '../core/Util.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Bounds} from '../geometry/Bounds.js';\n/** @import {LayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener} from '../core/Events.js' */\n\n/**\n * Options of `BlanketOverlay`.\n * @typedef {object} BlanketOverlayOptions\n * @property {number} [padding=0.1] How much to extend the clip area around the map\n * view (relative to its size) e.g. 0.1 would be 10% of map view in each direction.\n * @property {boolean} [continuous=false] When `false`, the blanket will update its\n * position only when the map state settles (*after* a pan/zoom animation). When\n * `true`, it will update when the map state changes (*during* pan/zoom animations).\n * @extends LayerOptions\n */\n\n/**\n * Represents an HTML element that covers (\"blankets\") the entire surface\n * of the map.\n *\n * Do not use this class directly. It's meant for `Renderer`, and for plugins\n * that rely on one single HTML element.\n *\n * Subclasses must define the following methods:\n *\n * * `_initContainer()` must initialize the HTML element to use as blanket, and store\n * it as `this._container`. The base implementation creates a blank `<div>`.\n * * `_destroyContainer()` must destroy the HTML element in `this._container` and free\n * any other resources. The base implementation destroys the element and removes\n * any event handlers attached to it.\n * * `_resizeContainer(): Point`: the base implementation resizes the container\n * (based on the map's size and taking into account the padding), returning the new\n * size in CSS pixels. Subclass implementations shall reset container parameters and\n * data structures as needed.\n * * `_onZoomEnd(ev?: PointerEvent)` (optional) runs on the map's `zoomend` event.\n * * `_onViewReset(ev?: PointerEvent)` (optional) runs on the map's `viewreset` event.\n * * `_onSettled()` runs whenever the map state settles after changing (at the end of\n * pan/zoom animations, etc). This should trigger the bulk of any rendering logic.\n * If the `continuous` option is set to `true`, then this also runs on any map\n * state change (including *during* pan/zoom animations).\n */\nexport class BlanketOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tpadding: 0.1,\n\t\tcontinuous: false,\n\t};\n\n\t/**\n\t * @param {BlanketOverlayOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(BlanketOverlay);\n\t}\n\n\t/**\n\t * Adds the blanket to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._container) {\n\t\t\tthis._initContainer(); // defined by renderer implementations\n\n\t\t\t// always keep transform-origin as 0 0, #8794\n\t\t\tthis._container.classList.add('maplair-zoom-animated');\n\t\t}\n\n\t\tthis.getPane().append(this._container);\n\t\tthis._resizeContainer();\n\t\tthis._onMoveEnd();\n\t}\n\n\t/**\n\t * Removes the blanket from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._destroyContainer();\n\t}\n\n\t/**\n\t * Returns the map events the blanket listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tviewreset: this._reset,\n\t\t\tzoom: this._onZoom,\n\t\t\tmoveend: this._onMoveEnd,\n\t\t\tresize: this._resizeContainer,\n\t\t\tzoomend: this._onZoomEnd,\n\t\t\tzoomanim: this._onAnimZoom\n\t\t};\n\t\tif (this.options.continuous) {\n\t\t\tevents.move = this._onMoveEnd;\n\t\t}\n\t\treturn events;\n\t}\n\n\t_onAnimZoom(ev) {\n\t\tthis._updateTransform(ev.center, ev.zoom);\n\t}\n\n\t_onZoom() {\n\t\tthis._updateTransform(this._map.getCenter(), this._map.getZoom());\n\t}\n\n\t_updateTransform(center, zoom) {\n\t\tconst scale = this._map.getZoomScale(zoom, this._zoom),\n\t\tviewHalf = this._map.getSize().multiplyBy(0.5 + this.options.padding),\n\t\tcurrentCenterPoint = this._map.project(this._center, zoom),\n\t\ttopLeftOffset = viewHalf.multiplyBy(-scale)._add(currentCenterPoint)\n\t\t\t._subtract(this._map._getNewPixelOrigin(center, zoom));\n\n\t\t// a scaled container is resampled anyway, and rounding where its corner lands would make its content away\n\t\t// from the corner jitter against the zoom motion\n\t\tif (scale === 1) { this._map._snapLayerPoint(topLeftOffset); }\n\n\t\tDomUtil.setTransform(this._container, topLeftOffset, scale);\n\t}\n\n\t_onMoveEnd(ev) {\n\t\t// Update pixel bounds of renderer container (for positioning/sizing/clipping later)\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize(),\n\t\tmin = this._map.containerPointToLayerPoint(size.multiplyBy(-p)).round();\n\n\t\tthis._bounds = new Bounds(min, min.add(size.multiplyBy(1 + p * 2)).round());\n\n\t\tthis._center = this._map.getCenter();\n\t\tthis._zoom = this._map.getZoom();\n\t\tthis._updateTransform(this._center, this._zoom);\n\n\t\tthis._onSettled(ev);\n\t}\n\n\t_reset() {\n\t\tthis._onSettled();\n\t\tthis._updateTransform(this._center, this._zoom);\n\t\tthis._onViewReset();\n\t}\n\n\t// Subclass interface, see the class description.\n\t_initContainer() {\n\t\tthis._container = DomUtil.create('div');\n\t}\n\t_destroyContainer() {\n\t\tDomEvent.off(this._container);\n\t\tthis._container.remove();\n\t\tdelete this._container;\n\t}\n\t_resizeContainer() {\n\t\tconst p = this.options.padding,\n\t\tsize = this._map.getSize().multiplyBy(1 + p * 2).round();\n\t\tthis._container.style.width = `${size.x}px`;\n\t\tthis._container.style.height = `${size.y}px`;\n\t\treturn size;\n\t}\n\t_onZoomEnd() {}\n\t_onViewReset() {}\n\t_onSettled() {}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,iBAAb,MAAa,uBAAuB,MAAM;CAEzC,OAAO,iBAAiB;EACvB,SAAS;EACT,YAAY;CACb;;;;CAKA,YAAY,SAAS;EACpB,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,cAAc;CAClC;;;;;CAMA,QAAQ;EACP,IAAI,CAAC,KAAK,YAAY;GACrB,KAAK,eAAe;GAGpB,KAAK,WAAW,UAAU,IAAI,uBAAuB;EACtD;EAEA,KAAK,QAAQ,CAAC,CAAC,OAAO,KAAK,UAAU;EACrC,KAAK,iBAAiB;EACtB,KAAK,WAAW;CACjB;;;;;CAMA,WAAW;EACV,KAA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B;CAEA,SAAS;EACR,KAAK,WAAW;EAChB,KAAK,iBAAiB,KAAK,SAAS,KAAK,KAAK;EAC9C,KAAK,aAAa;CACnB;CAGA,iBAAiB;EAChB,KAAK,aAAaA,OAAe,KAAK;CACvC;CACA,oBAAoB;EACnB,IAAa,KAAK,UAAU;EAC5B,KAAK,WAAW,OAAO;EACvB,OAAO,KAAK;CACb;CACA,mBAAmB;EAClB,MAAM,IAAI,KAAK,QAAQ,SACvB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM;EACvD,KAAK,WAAW,MAAM,QAAQ,GAAG,KAAK,EAAE;EACxC,KAAK,WAAW,MAAM,SAAS,GAAG,KAAK,EAAE;EACzC,OAAO;CACR;CACA,aAAa,CAAC;CACd,eAAe,CAAC;CAChB,aAAa,CAAC;AACf"}
|
|
@@ -12,9 +12,12 @@ import { FeatureGroup } from "./FeatureGroup.js";
|
|
|
12
12
|
/** @import {EventListener, MaplairEvent} from '../core/Events.js' */
|
|
13
13
|
/**
|
|
14
14
|
* The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an
|
|
15
|
-
* `HTMLElement`, or a function receiving the source layer and
|
|
16
|
-
*
|
|
15
|
+
* `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and
|
|
16
|
+
* returning one of them.
|
|
17
|
+
* @typedef {string|HTMLElement|DocumentFragment|
|
|
18
|
+
* ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent
|
|
17
19
|
*/
|
|
20
|
+
const fragmentNodes = /* @__PURE__ */ new WeakMap();
|
|
18
21
|
/**
|
|
19
22
|
* Options of `DivOverlay`.
|
|
20
23
|
* @typedef {object} DivOverlayOptions
|
|
@@ -30,8 +33,8 @@ import { FeatureGroup } from "./FeatureGroup.js";
|
|
|
30
33
|
* in the DOM (for styling and events).
|
|
31
34
|
* @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while
|
|
32
35
|
* initializing. If a function is passed the source layer will be passed to the
|
|
33
|
-
* function. The function should return a `String` or `
|
|
34
|
-
* overlay. String content is rendered as HTML; sanitize untrusted input or pass an
|
|
36
|
+
* function. The function should return a `String`, `HTMLElement` or `DocumentFragment`
|
|
37
|
+
* to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an
|
|
35
38
|
* `HTMLElement` with safe `textContent` instead.
|
|
36
39
|
* @extends InteractiveLayerOptions
|
|
37
40
|
*/
|
|
@@ -63,7 +66,8 @@ const layerDivOverlayMethods = { _initOverlay(OverlayClass, old, content, option
|
|
|
63
66
|
} };
|
|
64
67
|
/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */
|
|
65
68
|
/**
|
|
66
|
-
* Base model for Popup and Tooltip
|
|
69
|
+
* Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit
|
|
70
|
+
* from it for custom overlays like plugins.
|
|
67
71
|
*
|
|
68
72
|
* @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.
|
|
69
73
|
*/
|
|
@@ -140,8 +144,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
140
144
|
else {
|
|
141
145
|
if (arguments.length) this._source = layer;
|
|
142
146
|
else layer = this._source;
|
|
143
|
-
this._prepareOpen();
|
|
144
|
-
this.openOn(layer._map);
|
|
147
|
+
if (this._prepareOpen()) this.openOn(layer._map);
|
|
145
148
|
}
|
|
146
149
|
return this;
|
|
147
150
|
}
|
|
@@ -153,7 +156,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
153
156
|
if (!this._container) this._initLayout();
|
|
154
157
|
if (map._fadeAnimated) this._container.style.opacity = "0";
|
|
155
158
|
clearTimeout(this._removeTimeout);
|
|
156
|
-
this.getPane().
|
|
159
|
+
this.getPane().append(this._container);
|
|
157
160
|
if (this.options.overflow) {
|
|
158
161
|
this._container.classList.add("maplair-overflow");
|
|
159
162
|
this._container.popover = "manual";
|
|
@@ -225,10 +228,11 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
225
228
|
}
|
|
226
229
|
/**
|
|
227
230
|
* Sets the HTML content of the overlay. A `String` argument is rendered as
|
|
228
|
-
* HTML; if it may contain untrusted input, sanitize it
|
|
229
|
-
*
|
|
230
|
-
* passed
|
|
231
|
-
* return a `String
|
|
231
|
+
* HTML; if it may contain untrusted input, sanitize it or pass an `HTMLElement`
|
|
232
|
+
* with safe `textContent` instead. A `DocumentFragment`
|
|
233
|
+
* can be passed as well. If a function is passed the source layer will be passed
|
|
234
|
+
* to the function. The function should return a `String`, `HTMLElement` or
|
|
235
|
+
* `DocumentFragment` to be used in the overlay.
|
|
232
236
|
* @param {DivOverlayContent} content
|
|
233
237
|
* @returns {this}
|
|
234
238
|
*/
|
|
@@ -276,7 +280,7 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
276
280
|
* @returns {boolean}
|
|
277
281
|
*/
|
|
278
282
|
isOpen() {
|
|
279
|
-
return !!this._map
|
|
283
|
+
return !!this._map?.hasLayer(this);
|
|
280
284
|
}
|
|
281
285
|
/**
|
|
282
286
|
* Brings this overlay in front of other overlays (in the same map pane).
|
|
@@ -320,30 +324,26 @@ var DivOverlay = class DivOverlay extends Layer {
|
|
|
320
324
|
if (!source) return false;
|
|
321
325
|
this._source = source;
|
|
322
326
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
else if (source.getLatLng) latlng = source.getLatLng();
|
|
326
|
-
else if (source.getBounds) latlng = source.getBounds().getCenter();
|
|
327
|
-
else throw new Error("Unable to get source layer LatLng.");
|
|
328
|
-
}
|
|
327
|
+
latlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();
|
|
328
|
+
if (!latlng) throw new Error("Unable to get source layer LatLng.");
|
|
329
329
|
this.setLatLng(latlng);
|
|
330
330
|
if (this._map) this.update();
|
|
331
331
|
return true;
|
|
332
332
|
}
|
|
333
333
|
_updateContent() {
|
|
334
|
-
if (
|
|
334
|
+
if (this._content == null) return;
|
|
335
335
|
const node = this._contentNode;
|
|
336
336
|
const content = typeof this._content === "function" ? this._content(this._source ?? this) : this._content;
|
|
337
337
|
if (typeof content === "string") node.innerHTML = content;
|
|
338
|
-
else {
|
|
339
|
-
|
|
340
|
-
node.
|
|
341
|
-
}
|
|
338
|
+
else if (content instanceof DocumentFragment) {
|
|
339
|
+
if (content.hasChildNodes()) fragmentNodes.set(content, [...content.childNodes]);
|
|
340
|
+
node.replaceChildren(...fragmentNodes.get(content) ?? []);
|
|
341
|
+
} else node.replaceChildren(content);
|
|
342
342
|
this.fire("contentupdate");
|
|
343
343
|
}
|
|
344
344
|
_updatePosition() {
|
|
345
345
|
if (!this._map) return;
|
|
346
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
346
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng)), offset = Point.from(this.options.offset);
|
|
347
347
|
this._setContainerPosition(pos.add(this._getAnchor()));
|
|
348
348
|
const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
|
|
349
349
|
if (this.options.overflow) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.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} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement`, or a function receiving the source layer and returning one of them.\n * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent\n */\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String` or `HTMLElement` to be used in the\n * overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay 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 {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\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\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t * passed the source layer will be passed to the function. The function should\n\t * return a `String` or `HTMLElement` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng)._round(),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [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(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IA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K,MAAM,KAAK,kBAAkB,CAAC,IAAI,OAAO;EAG5E,IAAI,KAAK,QAAQ,UAAU;GAE1B,KAAK,WAAW,MAAM,MAAM;GAC5B,KAAK,WAAW,MAAM,SAAS,eAAe,OAAO;EACtD,OACC,KAAK,WAAW,MAAM,SAAS,GAAG,OAAO;EAE1C,KAAK,WAAW,MAAM,OAAO,GAAG,KAAK;CACtC;CAIA,sBAAsB,KAAK;EAC1B,KAAK,gBAAgB;EACrB,IAAI,KAAK,QAAQ,UAAU;GAC1B,MAAM,eAAe,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
|
|
1
|
+
{"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.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} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and\n * returning one of them.\n * @typedef {string|HTMLElement|DocumentFragment|\n * ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent\n */\n\nconst fragmentNodes = new WeakMap();\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String`, `HTMLElement` or `DocumentFragment`\n * to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit\n * from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay 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 {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\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\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tif (this._prepareOpen()) {\n\t\t\t\t// open the overlay on the map\n\t\t\t\tthis.openOn(layer._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().append(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it or pass an `HTMLElement`\n\t * with safe `textContent` instead. A `DocumentFragment`\n\t * can be passed as well. If a function is passed the source layer will be passed\n\t * to the function. The function should return a `String`, `HTMLElement` or\n\t * `DocumentFragment` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map?.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tlatlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();\n\t\tif (!latlng) { throw new Error('Unable to get source layer LatLng.'); }\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (this._content == null) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else if (content instanceof DocumentFragment) {\n\t\t\t// inserting a fragment empties it, so keep its nodes to insert them again on later updates\n\t\t\tif (content.hasChildNodes()) { fragmentNodes.set(content, [...content.childNodes]); }\n\t\t\tnode.replaceChildren(...fragmentNodes.get(content) ?? []);\n\t\t} else {\n\t\t\tnode.replaceChildren(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng)),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [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(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAM,gCAAgB,IAAI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KAAK,KAAK,gBAAgB,KAAK,KAAK,mBAAmB,KAAK,OAAO,CAAC,GAChF,SAAS,MAAM,KAAK,KAAK,QAAQ,MAAM;EAEvC,KAAK,sBAAsB,IAAI,IAAI,KAAK,WAAW,CAAC,CAAC;EAErD,MAAM,SAAS,KAAK,mBAAmB,CAAC,OAAO,GAC/C,OAAO,KAAK,iBAAiB,CAAC,KAAK,MAAM,KAAK,kBAAkB,CAAC,IAAI,OAAO;EAG5E,IAAI,KAAK,QAAQ,UAAU;GAE1B,KAAK,WAAW,MAAM,MAAM;GAC5B,KAAK,WAAW,MAAM,SAAS,eAAe,OAAO;EACtD,OACC,KAAK,WAAW,MAAM,SAAS,GAAG,OAAO;EAE1C,KAAK,WAAW,MAAM,OAAO,GAAG,KAAK;CACtC;CAIA,sBAAsB,KAAK;EAC1B,KAAK,gBAAgB;EACrB,IAAI,KAAK,QAAQ,UAAU;GAC1B,MAAM,eAAe,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
|
|
@@ -87,6 +87,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
87
87
|
onAdd() {
|
|
88
88
|
if (!this._image) {
|
|
89
89
|
this._initImage();
|
|
90
|
+
this._updateZIndex();
|
|
90
91
|
if (this.options.opacity < 1) this._updateOpacity();
|
|
91
92
|
}
|
|
92
93
|
if (this.options.interactive) {
|
|
@@ -94,7 +95,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
94
95
|
this.addInteractiveTarget(this._image);
|
|
95
96
|
}
|
|
96
97
|
this._image.classList.toggle("maplair-pixelated", !!this.options.pixelated);
|
|
97
|
-
this.getPane().
|
|
98
|
+
this.getPane().append(this._image);
|
|
98
99
|
this._reset();
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
@@ -127,7 +128,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
127
128
|
* @returns {this}
|
|
128
129
|
*/
|
|
129
130
|
setStyle(styleOpts) {
|
|
130
|
-
if (styleOpts.opacity) this.setOpacity(styleOpts.opacity);
|
|
131
|
+
if (styleOpts.opacity != null) this.setOpacity(styleOpts.opacity);
|
|
131
132
|
return this;
|
|
132
133
|
}
|
|
133
134
|
/**
|
|
@@ -213,7 +214,6 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
213
214
|
img.onerror = this._overlayOnError.bind(this);
|
|
214
215
|
if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
|
|
215
216
|
img.decoding = this.options.decoding;
|
|
216
|
-
if (this.options.zIndex) this._updateZIndex();
|
|
217
217
|
if (wasElementSupplied) {
|
|
218
218
|
this._url = img.src;
|
|
219
219
|
return;
|
|
@@ -226,7 +226,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
226
226
|
setTransform(this._image, offset, scale);
|
|
227
227
|
}
|
|
228
228
|
_reset() {
|
|
229
|
-
const image = this._image, bounds = new Bounds(
|
|
229
|
+
const image = this._image, map = this._map, bounds = new Bounds(map._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getNorthWest())), map._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getSouthEast()))), size = bounds.getSize();
|
|
230
230
|
setPosition(image, bounds.min);
|
|
231
231
|
image.style.width = `${size.x}px`;
|
|
232
232
|
image.style.height = `${size.y}px`;
|
|
@@ -235,7 +235,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
235
235
|
this._image.style.opacity = `${this.options.opacity}`;
|
|
236
236
|
}
|
|
237
237
|
_updateZIndex() {
|
|
238
|
-
if (this._image && this.options.zIndex
|
|
238
|
+
if (this._image && this.options.zIndex != null) this._image.style.zIndex = `${this.options.zIndex}`;
|
|
239
239
|
}
|
|
240
240
|
_overlayOnError() {
|
|
241
241
|
this.fire("error");
|
|
@@ -252,6 +252,9 @@ var ImageOverlay = class ImageOverlay extends Layer {
|
|
|
252
252
|
getCenter() {
|
|
253
253
|
return this._bounds.getCenter();
|
|
254
254
|
}
|
|
255
|
+
_togglesPopupOnClick() {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
255
258
|
};
|
|
256
259
|
export { ImageOverlay };
|
|
257
260
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageOverlay.js","names":["DomUtil.create","Util.splitWords"],"sources":["../../../src/layer/ImageOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as Util from '../core/Util.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Bounds} from '../geometry/Bounds.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `ImageOverlay`.\n * @typedef {object} ImageOverlayOptions\n * @property {number} [opacity=1] The opacity of the image overlay.\n * @property {string} [alt=''] Text for the `alt` attribute of the image (useful for\n * accessibility).\n * @property {boolean} [interactive=false] If `true`, the image overlay will emit\n * [pointer events](#interactivelayeroptions) when clicked or hovered.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute\n * will be added to the image. If a String is provided, the image will have its\n * crossOrigin attribute set to the String provided. This is needed if you want to\n * access image pixel data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {string} [errorOverlayUrl=''] URL to the overlay image to show in place\n * of the overlay that failed to load.\n * @property {number} [zIndex=1] The explicit\n * [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index)\n * of the overlay layer.\n * @property {string} [className=''] A custom class name to assign to the image. Empty\n * by default.\n * @property {boolean} [pixelated=false] Whether to scale the image with\n * nearest-neighbour interpolation (`image-rendering: pixelated`) instead of smoothing\n * it, so that its pixels stay crisp when zoomed in. Useful for raster data, pixel art\n * or scientific imagery.\n * @property {string} [decoding='auto'] Tells the browser whether to decode the image\n * in a synchronous fashion, as per the\n * [`decoding` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding).\n * If the image overlay is flickering when being added/removed, set this option to\n * `'sync'`.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Used to load and display a single image over specific bounds of the map. Extends `Layer`.\n *\n * @example\n * ```js\n * const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',\n * \timageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];\n * new ImageOverlay(imageUrl, imageBounds).addTo(map);\n * ```\n *\n * @fires load {MaplairEvent} Fired when the ImageOverlay layer has loaded its image.\n * @fires error {MaplairEvent} Fired when the ImageOverlay layer fails to load its image.\n */\nexport class ImageOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\topacity: 1,\n\t\talt: '',\n\t\tinteractive: false,\n\t\tcrossOrigin: false,\n\t\terrorOverlayUrl: '',\n\t\tzIndex: 1,\n\t\tclassName: '',\n\t\tpixelated: false,\n\t\tdecoding: 'auto'\n\t};\n\n\t/**\n\t * Instantiates an image overlay object given the URL of the image (or an image\n\t * element) and the geographical bounds it is tied to.\n\t * @param {string|HTMLImageElement} url\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {ImageOverlayOptions} [options]\n\t */\n\tconstructor(url, bounds, options) { // (String, LatLngBounds, Object)\n\t\tsuper();\n\t\tthis._url = url;\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(ImageOverlay);\n\t}\n\n\t/**\n\t * Adds the image to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._image) {\n\t\t\tthis._initImage();\n\n\t\t\tif (this.options.opacity < 1) {\n\t\t\t\tthis._updateOpacity();\n\t\t\t}\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._image.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t}\n\t\tthis._image.classList.toggle('maplair-pixelated', !!this.options.pixelated);\n\n\t\tthis.getPane().appendChild(this._image);\n\t\tthis._reset();\n\t}\n\n\t/**\n\t * Removes the image from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._image.remove();\n\t\tif (this.options.interactive) {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._image.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay.\n\t * @param {number} opacity\n\t * @returns {this}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._image) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay from the given style options, e.g. by\n\t * `FeatureGroup.setStyle()`.\n\t * @param {{opacity?: number}} styleOpts\n\t * @returns {this}\n\t */\n\tsetStyle(styleOpts) {\n\t\tif (styleOpts.opacity) {\n\t\t\tthis.setOpacity(styleOpts.opacity);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all overlays.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all overlays.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes the URL of the image.\n\t * @param {string} url\n\t * @returns {this}\n\t */\n\tsetUrl(url) {\n\t\tthis._url = url;\n\n\t\tif (this._image) {\n\t\t\tthis._image.src = url;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Update the bounds that this ImageOverlay covers.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {this}\n\t */\n\tsetBounds(bounds) {\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tif (this._map) {\n\t\t\tthis._reset();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\treturn {\n\t\t\tzoom: this._reset,\n\t\t\tviewreset: this._reset,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\t}\n\n\t/**\n\t * Changes the [zIndex](#imageoverlay-zindex) of the image overlay.\n\t * @param {number} value\n\t * @returns {this}\n\t */\n\tsetZIndex(value) {\n\t\tthis.options.zIndex = value;\n\t\tthis._updateZIndex();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the bounds that this ImageOverlay covers.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Returns the instance of\n\t * [`HTMLImageElement`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement)\n\t * used by this overlay (`HTMLVideoElement` for `VideoOverlay`, `SVGElement` for\n\t * `SVGOverlay`).\n\t * @returns {HTMLElement|SVGElement}\n\t */\n\tgetElement() {\n\t\treturn this._image;\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url instanceof HTMLImageElement;\n\t\tconst img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');\n\n\t\timg.classList.add('maplair-image-layer', 'maplair-zoom-animated');\n\t\tif (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\timg.onload = this.fire.bind(this, 'load');\n\t\timg.onerror = this._overlayOnError.bind(this);\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\timg.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\timg.decoding = this.options.decoding;\n\n\t\tif (this.options.zIndex) {\n\t\t\tthis._updateZIndex();\n\t\t}\n\n\t\tif (wasElementSupplied) {\n\t\t\tthis._url = img.src;\n\t\t\treturn;\n\t\t}\n\n\t\timg.src = this._url;\n\t\timg.alt = this.options.alt;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst scale = this._map.getZoomScale(e.zoom),\n\t\toffset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center);\n\n\t\tDomUtil.setTransform(this._image, offset, scale);\n\t}\n\n\t_reset() {\n\t\tconst image = this._image,\n\t\tbounds = new Bounds(\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(),\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()),\n\t\tsize = bounds.getSize();\n\n\t\tDomUtil.setPosition(image, bounds.min);\n\n\t\timage.style.width = `${size.x}px`;\n\t\timage.style.height = `${size.y}px`;\n\t}\n\n\t_updateOpacity() {\n\t\tthis._image.style.opacity = `${this.options.opacity}`;\n\t}\n\n\t_updateZIndex() {\n\t\tif (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {\n\t\t\tthis._image.style.zIndex = `${this.options.zIndex}`;\n\t\t}\n\t}\n\n\t_overlayOnError() {\n\t\tthis.fire('error');\n\n\t\tconst errorUrl = this.options.errorOverlayUrl;\n\t\tif (errorUrl && this._url !== errorUrl) {\n\t\t\tthis._url = errorUrl;\n\t\t\tthis._image.src = errorUrl;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the center of the ImageOverlay.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn this._bounds.getCenter();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAa,qBAAqB,MAAM;CAEvC,OAAO,iBAAiB;EACvB,SAAS;EACT,KAAK;EACL,aAAa;EACb,aAAa;EACb,iBAAiB;EACjB,QAAQ;EACR,WAAW;EACX,WAAW;EACX,UAAU;CACX;;;;;;;;CASA,YAAY,KAAK,QAAQ,SAAS;EACjC,MAAM;EACN,KAAK,OAAO;EACZ,KAAK,UAAU,IAAI,aAAa,MAAM;EAEtC,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,YAAY;CAChC;;;;;CAMA,QAAQ;EACP,IAAI,CAAC,KAAK,QAAQ;GACjB,KAAK,WAAW;GAEhB,IAAI,KAAK,QAAQ,UAAU,GAC1B,KAAK,eAAe;EAEtB;EAEA,IAAI,KAAK,QAAQ,aAAa;GAC7B,KAAK,OAAO,UAAU,IAAI,qBAAqB;GAC/C,KAAK,qBAAqB,KAAK,MAAM;EACtC;EACA,KAAK,OAAO,UAAU,OAAO,qBAAqB,CAAC,CAAC,KAAK,QAAQ,SAAS;EAE1E,KAAK,QAAQ,CAAC,CAAC,YAAY,KAAK,MAAM;EACtC,KAAK,OAAO;CACb;;;;;CAMA,WAAW;EACV,KAAK,OAAO,OAAO;EACnB,IAAI,KAAK,QAAQ,aAChB,KAAK,wBAAwB,KAAK,MAAM;CAE1C;CAEA,qBAAqB;EACpB,KAAK,OAAO,UAAU,OAAO,uBAAuB,KAAK,QAAQ,WAAW;EAC5E,IAAI,KAAK,QAAQ,aAChB,KA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;EACX,OAAO,KAAK,QAAQ,UAAU;CAC/B;AACD"}
|
|
1
|
+
{"version":3,"file":"ImageOverlay.js","names":["DomUtil.create","Util.splitWords"],"sources":["../../../src/layer/ImageOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as Util from '../core/Util.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Bounds} from '../geometry/Bounds.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `ImageOverlay`.\n * @typedef {object} ImageOverlayOptions\n * @property {number} [opacity=1] The opacity of the image overlay.\n * @property {string} [alt=''] Text for the `alt` attribute of the image (useful for\n * accessibility).\n * @property {boolean} [interactive=false] If `true`, the image overlay will emit\n * [pointer events](#interactivelayeroptions) when clicked or hovered.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute\n * will be added to the image. If a String is provided, the image will have its\n * crossOrigin attribute set to the String provided. This is needed if you want to\n * access image pixel data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {string} [errorOverlayUrl=''] URL to the overlay image to show in place\n * of the overlay that failed to load.\n * @property {number} [zIndex=1] The explicit\n * [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index)\n * of the overlay layer.\n * @property {string} [className=''] A custom class name to assign to the image. Empty\n * by default.\n * @property {boolean} [pixelated=false] Whether to scale the image with\n * nearest-neighbour interpolation (`image-rendering: pixelated`) instead of smoothing\n * it, so that its pixels stay crisp when zoomed in. Useful for raster data, pixel art\n * or scientific imagery.\n * @property {string} [decoding='auto'] Tells the browser whether to decode the image\n * in a synchronous fashion, as per the\n * [`decoding` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding).\n * If the image overlay is flickering when being added/removed, set this option to\n * `'sync'`.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Used to load and display a single image over specific bounds of the map. Extends `Layer`.\n *\n * @example\n * ```js\n * const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',\n * \timageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];\n * new ImageOverlay(imageUrl, imageBounds).addTo(map);\n * ```\n *\n * @fires load {MaplairEvent} Fired when the ImageOverlay layer has loaded its image.\n * @fires error {MaplairEvent} Fired when the ImageOverlay layer fails to load its image.\n */\nexport class ImageOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\topacity: 1,\n\t\talt: '',\n\t\tinteractive: false,\n\t\tcrossOrigin: false,\n\t\terrorOverlayUrl: '',\n\t\tzIndex: 1,\n\t\tclassName: '',\n\t\tpixelated: false,\n\t\tdecoding: 'auto'\n\t};\n\n\t/**\n\t * Instantiates an image overlay object given the URL of the image (or an image\n\t * element) and the geographical bounds it is tied to.\n\t * @param {string|HTMLImageElement} url\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {ImageOverlayOptions} [options]\n\t */\n\tconstructor(url, bounds, options) { // (String, LatLngBounds, Object)\n\t\tsuper();\n\t\tthis._url = url;\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(ImageOverlay);\n\t}\n\n\t/**\n\t * Adds the image to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._image) {\n\t\t\tthis._initImage();\n\t\t\tthis._updateZIndex();\n\n\t\t\tif (this.options.opacity < 1) {\n\t\t\t\tthis._updateOpacity();\n\t\t\t}\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._image.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t}\n\t\tthis._image.classList.toggle('maplair-pixelated', !!this.options.pixelated);\n\n\t\tthis.getPane().append(this._image);\n\t\tthis._reset();\n\t}\n\n\t/**\n\t * Removes the image from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._image.remove();\n\t\tif (this.options.interactive) {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._image.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay.\n\t * @param {number} opacity\n\t * @returns {this}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._image) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay from the given style options, e.g. by\n\t * `FeatureGroup.setStyle()`.\n\t * @param {{opacity?: number}} styleOpts\n\t * @returns {this}\n\t */\n\tsetStyle(styleOpts) {\n\t\tif (styleOpts.opacity != null) {\n\t\t\tthis.setOpacity(styleOpts.opacity);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all overlays.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all overlays.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes the URL of the image.\n\t * @param {string} url\n\t * @returns {this}\n\t */\n\tsetUrl(url) {\n\t\tthis._url = url;\n\n\t\tif (this._image) {\n\t\t\tthis._image.src = url;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Update the bounds that this ImageOverlay covers.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {this}\n\t */\n\tsetBounds(bounds) {\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tif (this._map) {\n\t\t\tthis._reset();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\treturn {\n\t\t\tzoom: this._reset,\n\t\t\tviewreset: this._reset,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\t}\n\n\t/**\n\t * Changes the [zIndex](#imageoverlay-zindex) of the image overlay.\n\t * @param {number} value\n\t * @returns {this}\n\t */\n\tsetZIndex(value) {\n\t\tthis.options.zIndex = value;\n\t\tthis._updateZIndex();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the bounds that this ImageOverlay covers.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Returns the instance of\n\t * [`HTMLImageElement`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement)\n\t * used by this overlay (`HTMLVideoElement` for `VideoOverlay`, `SVGElement` for\n\t * `SVGOverlay`).\n\t * @returns {HTMLElement|SVGElement}\n\t */\n\tgetElement() {\n\t\treturn this._image;\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url instanceof HTMLImageElement;\n\t\tconst img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');\n\n\t\timg.classList.add('maplair-image-layer', 'maplair-zoom-animated');\n\t\tif (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\timg.onload = this.fire.bind(this, 'load');\n\t\timg.onerror = this._overlayOnError.bind(this);\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\timg.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\timg.decoding = this.options.decoding;\n\n\t\tif (wasElementSupplied) {\n\t\t\tthis._url = img.src;\n\t\t\treturn;\n\t\t}\n\n\t\timg.src = this._url;\n\t\timg.alt = this.options.alt;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst scale = this._map.getZoomScale(e.zoom),\n\t\toffset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center);\n\n\t\tDomUtil.setTransform(this._image, offset, scale);\n\t}\n\n\t_reset() {\n\t\tconst image = this._image,\n\t\tmap = this._map,\n\t\tbounds = new Bounds(\n\t\t\tmap._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getNorthWest())),\n\t\t\tmap._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getSouthEast()))),\n\t\tsize = bounds.getSize();\n\n\t\tDomUtil.setPosition(image, bounds.min);\n\n\t\timage.style.width = `${size.x}px`;\n\t\timage.style.height = `${size.y}px`;\n\t}\n\n\t_updateOpacity() {\n\t\tthis._image.style.opacity = `${this.options.opacity}`;\n\t}\n\n\t_updateZIndex() {\n\t\tif (this._image && this.options.zIndex != null) {\n\t\t\tthis._image.style.zIndex = `${this.options.zIndex}`;\n\t\t}\n\t}\n\n\t_overlayOnError() {\n\t\tthis.fire('error');\n\n\t\tconst errorUrl = this.options.errorOverlayUrl;\n\t\tif (errorUrl && this._url !== errorUrl) {\n\t\t\tthis._url = errorUrl;\n\t\t\tthis._image.src = errorUrl;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the center of the ImageOverlay.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn this._bounds.getCenter();\n\t}\n\n\t// like on paths, popups open where the overlay was clicked, so another click moves them\n\t_togglesPopupOnClick() {\n\t\treturn false;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAa,qBAAqB,MAAM;CAEvC,OAAO,iBAAiB;EACvB,SAAS;EACT,KAAK;EACL,aAAa;EACb,aAAa;EACb,iBAA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vF,aAAqB,KAAK,QAAQ,QAAQ,KAAK;CAChD;CAEA,SAAS;EACR,MAAM,QAAQ,KAAK,QACnB,MAAM,KAAK,MACX,SAAS,IAAI,OACZ,IAAI,gBAAgB,IAAI,mBAAmB,KAAK,QAAQ,aAAa,CAAC,CAAC,GACvE,IAAI,gBAAgB,IAAI,mBAAmB,KAAK,QAAQ,aAAa,CAAC,CAAC,CAAC,GACzE,OAAO,OAAO,QAAQ;EAEtB,YAAoB,OAAO,OAAO,GAAG;EAErC,MAAM,MAAM,QAAS,GAAG,KAAK,EAAE;EAC/B,MAAM,MAAM,SAAS,GAAG,KAAK,EAAE;CAChC;CAEA,iBAAiB;EAChB,KAAK,OAAO,MAAM,UAAU,GAAG,KAAK,QAAQ;CAC7C;CAEA,gBAAgB;EACf,IAAI,KAAK,UAAU,KAAK,QAAQ,UAAU,MACzC,KAAK,OAAO,MAAM,SAAS,GAAG,KAAK,QAAQ;CAE7C;CAEA,kBAAkB;EACjB,KAAK,KAAK,OAAO;EAEjB,MAAM,WAAW,KAAK,QAAQ;EAC9B,IAAI,YAAY,KAAK,SAAS,UAAU;GACvC,KAAK,OAAO;GACZ,KAAK,OAAO,MAAM;EACnB;CACD;;;;;CAMA,YAAY;EACX,OAAO,KAAK,QAAQ,UAAU;CAC/B;CAGA,uBAAuB;EACtB,OAAO;CACR;AACD"}
|
package/dist/esm/layer/Layer.js
CHANGED
|
@@ -136,13 +136,13 @@ const mapLayerMethods = {
|
|
|
136
136
|
const oldZoomSpan = this._getZoomSpan();
|
|
137
137
|
for (const l of Object.values(this._zoomBoundLayers)) {
|
|
138
138
|
const options = l.options;
|
|
139
|
-
minZoom = Math.min(minZoom, options.minZoom
|
|
140
|
-
maxZoom = Math.max(maxZoom, options.maxZoom
|
|
139
|
+
if (options.minZoom != null && !Number.isNaN(options.minZoom)) minZoom = Math.min(minZoom, options.minZoom);
|
|
140
|
+
if (options.maxZoom != null && !Number.isNaN(options.maxZoom)) maxZoom = Math.max(maxZoom, options.maxZoom);
|
|
141
141
|
}
|
|
142
142
|
this._layersMaxZoom = maxZoom === -Infinity ? void 0 : maxZoom;
|
|
143
143
|
this._layersMinZoom = minZoom === Infinity ? void 0 : minZoom;
|
|
144
144
|
if (oldZoomSpan !== this._getZoomSpan()) this.fire("zoomlevelschange");
|
|
145
|
-
if (this.options.maxZoom === void 0 && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) this.setZoom(this._layersMaxZoom);
|
|
145
|
+
if (this.options.maxZoom === void 0 && this._layersMaxZoom !== void 0 && this.getZoom() > this._layersMaxZoom) this.setZoom(this._layersMaxZoom);
|
|
146
146
|
if (this.options.minZoom === void 0 && this._layersMinZoom && this.getZoom() < this._layersMinZoom) this.setZoom(this._layersMinZoom);
|
|
147
147
|
}
|
|
148
148
|
};
|
|
@@ -259,8 +259,10 @@ var Layer = class extends Evented {
|
|
|
259
259
|
}
|
|
260
260
|
_updateInteractive() {}
|
|
261
261
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
262
|
+
* Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and
|
|
263
|
+
* keyboard events on it (or its descendants) fire on the layer and bubble through its
|
|
264
|
+
* parent groups to the map, the way they do for markers and paths. Custom layers call
|
|
265
|
+
* it in [`onAdd`](#layer-onadd), once the layer is on a map.
|
|
264
266
|
* @param {HTMLElement} targetEl
|
|
265
267
|
* @returns {this}
|
|
266
268
|
*/
|
|
@@ -269,8 +271,8 @@ var Layer = class extends Evented {
|
|
|
269
271
|
return this;
|
|
270
272
|
}
|
|
271
273
|
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
+
* Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in
|
|
275
|
+
* [`onRemove`](#layer-onremove).
|
|
274
276
|
* @param {HTMLElement} targetEl
|
|
275
277
|
* @returns {this}
|
|
276
278
|
*/
|
|
@@ -278,6 +280,9 @@ var Layer = class extends Evented {
|
|
|
278
280
|
delete this._map._targets[stamp(targetEl)];
|
|
279
281
|
return this;
|
|
280
282
|
}
|
|
283
|
+
_togglesPopupOnClick() {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
281
286
|
/**
|
|
282
287
|
* Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).
|
|
283
288
|
* @returns {string|null}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layer.js","names":["Util.stamp"],"sources":["../../../src/layer/Layer.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as Util from '../core/Util.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LayerGroup} from './LayerGroup.js' */\n/** @import {EventListener, MaplairEvent, MaplairPointerEvent, LayerEvent} from '../core/Events.js' */\n\n/**\n * Options of `Layer`, inherited by all layers.\n * @typedef {object} LayerOptions\n * @property {string} [pane='overlayPane'] By default the layer will be added to the\n * map's [overlay pane](#map-pane) (`overlayPane`). Overriding this option will cause the layer\n * to be placed on another pane by default. Not effective if the `renderer` option is\n * set (the `renderer` option will override the `pane` option).\n * @property {string|null} [attribution=null] String to be shown in the attribution\n * control, e.g. \"© OpenStreetMap contributors\". It describes the layer data and is\n * often a legal obligation towards copyright holders and tile providers.\n * @property {number} [attributionOrder=0] The position of the attribution in the\n * attribution control: attributions are sorted by it, then by the order of adding,\n * e.g. `1` keeps a legend last.\n */\n\n/**\n * Options of interactive layers. Some layers can be made interactive - when the user\n * interacts with such a layer, pointer events like `click` and `pointerover` can be\n * handled. Use the [event handling methods](#evented-method) to handle these events.\n * @typedef {object} InteractiveLayerOptions\n * @property {boolean} [interactive=true] If `false`, the layer will not emit pointer\n * events and will act as a part of the underlying map.\n * @property {boolean} [bubblingPointerEvents=true] When `true`, a pointer event on this\n * layer will trigger the same event on the map (unless\n * [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).\n * @extends LayerOptions\n * @fires Layer#click {MaplairPointerEvent} Fired when the user clicks (or taps) the\n * layer, if it is interactive.\n * @fires Layer#dblclick {MaplairPointerEvent} Fired when the user double-clicks (or\n * double-taps) the layer, if it is interactive.\n * @fires Layer#pointerdown {MaplairPointerEvent} Fired when the user pushes the pointer\n * on the layer, if it is interactive.\n * @fires Layer#pointerup {MaplairPointerEvent} Fired when the user releases the pointer\n * pushed on the layer, if it is interactive.\n * @fires Layer#pointerover {MaplairPointerEvent} Fired when the pointer enters the\n * layer, if it is interactive.\n * @fires Layer#pointerout {MaplairPointerEvent} Fired when the pointer leaves the layer,\n * if it is interactive.\n * @fires Layer#contextmenu {MaplairPointerEvent} Fired when the user right-clicks on\n * the layer, if it is interactive; prevents default browser context menu from showing\n * if there are listeners on this event. Also fired on mobile when the user holds a\n * single touch for a second (also called long press).\n */\n\n/**\n * Methods of `MaplairMap` for layers.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#layeradd {LayerEvent} Fired when a new layer is added to the map.\n * @fires MaplairMap#layerremove {LayerEvent} Fired when some layer is removed from the map.\n * @fires MaplairMap#zoomlevelschange {MaplairEvent} Fired when the number of zoomlevels\n * on the map is changed due to adding or removing a layer.\n */\nconst mapLayerMethods = {\n\t/**\n\t * Adds the given layer to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (!layer._layerAdd) {\n\t\t\tthrow new Error('The provided object is not a Layer.');\n\t\t}\n\n\t\tconst id = Util.stamp(layer);\n\t\tif (this._layers[id]) { return this; }\n\t\tthis._layers[id] = layer;\n\n\t\tlayer._mapToAdd = this;\n\n\t\tif (layer.beforeAdd) {\n\t\t\tlayer.beforeAdd(this);\n\t\t}\n\n\t\tthis.whenReady(layer._layerAdd, layer);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given layer from the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (!this._layers[id]) { return this; }\n\n\t\tif (this._loaded) {\n\t\t\tlayer.onRemove(this);\n\t\t}\n\n\t\tdelete this._layers[id];\n\n\t\tif (this._loaded) {\n\t\t\tthis.fire('layerremove', {layer});\n\t\t\tlayer.fire('remove');\n\t\t}\n\n\t\tlayer._map = layer._mapToAdd = null;\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the given layer is currently added to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {boolean}\n\t */\n\thasLayer(layer) {\n\t\treturn Util.stamp(layer) in this._layers;\n\t},\n\n\t/**\n\t * Iterates over the layers of the map, optionally specifying context of the iterator function.\n\t * ```js\n\t * map.eachLayer(function(layer){\n\t * layer.bindPopup('Hello');\n\t * });\n\t * ```\n\t * @group Methods for layers and controls\n\t * @param {(layer: Layer) => void} method\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\teachLayer(method, context) {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tmethod.call(context, layer);\n\t\t}\n\t\treturn this;\n\t},\n\n\t_addLayers(layers) {\n\t\tlayers = layers ? (Array.isArray(layers) ? layers : [layers]) : [];\n\n\t\tfor (const layer of layers) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\t},\n\n\t_addZoomLimit(layer) {\n\t\tif (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) {\n\t\t\tthis._zoomBoundLayers[Util.stamp(layer)] = layer;\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_removeZoomLimit(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (this._zoomBoundLayers[id]) {\n\t\t\tdelete this._zoomBoundLayers[id];\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_updateZoomLevels() {\n\t\tlet minZoom = Infinity,\n\t\tmaxZoom = -Infinity;\n\t\tconst oldZoomSpan = this._getZoomSpan();\n\n\t\tfor (const l of Object.values(this._zoomBoundLayers)) {\n\t\t\tconst options = l.options;\n\t\t\tminZoom = Math.min(minZoom, options.minZoom ?? Infinity);\n\t\t\tmaxZoom = Math.max(maxZoom, options.maxZoom ?? -Infinity);\n\t\t}\n\n\t\tthis._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;\n\t\tthis._layersMinZoom = minZoom === Infinity ? undefined : minZoom;\n\n\t\tif (oldZoomSpan !== this._getZoomSpan()) {\n\t\t\tthis.fire('zoomlevelschange');\n\t\t}\n\n\t\tif (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) {\n\t\t\tthis.setZoom(this._layersMaxZoom);\n\t\t}\n\t\tif (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {\n\t\t\tthis.setZoom(this._layersMinZoom);\n\t\t}\n\t}\n};\n/** @typedef {typeof mapLayerMethods} MapLayerMethods */\n\n/**\n * The methods which layers implement, see `Layer`.\n * @typedef {object} LayerExtensionMethods\n * @property {(map: MaplairMap) => void} [onAdd] Should contain code that creates DOM\n * elements for the layer, adds them to `map panes` where they should belong and puts\n * listeners on relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the layer's elements from the DOM and removes listeners previously added in\n * `onAdd`. Called on [`map.removeLayer(layer)`](#map-removelayer).\n * @property {() => Record<string, Function>} [getEvents] Should return an object\n * like `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * @property {() => HTMLElement|string} [getLegend] Should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * @property {(map: MaplairMap) => void} [beforeAdd] Called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map, before\n * events are initialized, without waiting until the map is in a usable state. Use for\n * early initialization only.\n * @lends Layer\n */\n\n/**\n * The base class of all Maplair layers, with the methods they share.\n *\n * Every layer should extend from `Layer` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): this` should contain code that creates DOM elements for\n * the layer, adds them to `map panes` where they should belong and puts listeners on\n * relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * * `onRemove(map: MaplairMap): this` should contain all clean up code that removes the\n * layer's elements from the DOM and removes listeners previously added in `onAdd`.\n * Called on [`map.removeLayer(layer)`](#map-removelayer).\n * * `getEvents(): Object` (optional) should return an object like\n * `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * * `getAttribution(): String` (optional) should return a string containing HTML to be\n * shown on the `Attribution control` whenever the layer is visible.\n * * `getLegend(): HTMLElement|String` (optional) should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * * `beforeAdd(map: MaplairMap): this` (optional) is called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map,\n * before events are initialized, without waiting until the map is in a usable state.\n * Use for early initialization only.\n *\n * @example\n * ```js\n * const layer = new Marker(latlng).addTo(map);\n * layer.addTo(map);\n * layer.remove();\n * ```\n *\n * @fires add {MaplairEvent} Fired after the layer is added to a map.\n * @fires remove {MaplairEvent} Fired after the layer is removed from a map.\n */\nexport class Layer extends Evented {\n\n\tstatic defaultOptions = {\n\t\tpane: 'overlayPane',\n\t\tattribution: null,\n\t\tattributionOrder: 0,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Adds the layer to the given map or layer group.\n\t * @param {MaplairMap|LayerGroup} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tmap.addLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the layer from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\treturn this.removeFrom(this._map || this._mapToAdd);\n\t}\n\n\t/**\n\t * Removes the layer from the given map or `LayerGroup`.\n\t * @param {MaplairMap|LayerGroup} obj\n\t * @returns {this}\n\t */\n\tremoveFrom(obj) {\n\t\tobj?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the `HTMLElement` representing the named pane on the map. If `name` is\n\t * omitted, returns the pane for this layer.\n\t * @param {string} [name]\n\t * @returns {HTMLElement}\n\t */\n\tgetPane(name) {\n\t\treturn this._map.getPane(name ? (this.options[name] || name) : this.options.pane);\n\t}\n\n\t/**\n\t * Changes the [`interactive`](#interactivelayeroptions-interactive) option of the\n\t * layer, e.g. to stop a layer from emitting pointer events while it is being edited.\n\t * @param {boolean} interactive\n\t * @returns {this}\n\t */\n\tsetInteractive(interactive) {\n\t\tinteractive = !!interactive;\n\t\tif (this.options.interactive !== interactive) {\n\t\t\tUtil.setOptions(this, {interactive});\n\t\t\tif (this._map) {\n\t\t\t\tthis._updateInteractive();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Applies a changed `interactive` option to a layer on the map, see `setInteractive()`.\n\t_updateInteractive() {}\n\n\t/**\n\t * Makes `targetEl` a target of pointer events of this layer.\n\t * @internal\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\taddInteractiveTarget(targetEl) {\n\t\tthis._map._targets[Util.stamp(targetEl)] = this;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Stops `targetEl` from being a target of pointer events of this layer.\n\t * @internal\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\tremoveInteractiveTarget(targetEl) {\n\t\tdelete this._map._targets[Util.stamp(targetEl)];\n\t\treturn this;\n\t}\n\n\t/**\n\t * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).\n\t * @returns {string|null}\n\t */\n\tgetAttribution() {\n\t\treturn this.options.attribution;\n\t}\n\n\t/**\n\t * Changes the [attribution option](#layeroptions-attribution), also in the\n\t * attribution control while the layer is on the map.\n\t * @param {string|null} attribution\n\t * @returns {this}\n\t */\n\tsetAttribution(attribution) {\n\t\tconst control = this._map?.attributionControl;\n\t\tcontrol?._removeLayer({layer: this});\n\t\tUtil.setOptions(this, {attribution});\n\t\tcontrol?._addLayer({layer: this});\n\t\treturn this;\n\t}\n\n\t_layerAdd(e) {\n\t\tconst map = e.target;\n\n\t\t// check in case layer gets added and then removed before the map is ready\n\t\tif (!map.hasLayer(this)) { return; }\n\n\t\tthis._map = map;\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (this.getEvents) {\n\t\t\tconst events = this.getEvents();\n\t\t\tmap.on(events, this);\n\t\t\tthis.once('remove', () => map.off(events, this));\n\t\t}\n\n\t\tthis.onAdd(map);\n\n\t\tthis.fire('add');\n\t\tmap.fire('layeradd', {layer: this});\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(mapLayerMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,kBAAkB;;;;;;;CAOvB,SAAS,OAAO;EACf,IAAI,CAAC,MAAM,WACV,MAAM,IAAI,MAAM,qCAAqC;EAGtD,MAAM,KAAKA,MAAW,KAAK;EAC3B,IAAI,KAAK,QAAQ,KAAO,OAAO;EAC/B,KAAK,QAAQ,MAAM;EAEnB,MAAM,YAAY;EAElB,IAAI,MAAM,WACT,MAAM,UAAU,IAAI;EAGrB,KAAK,UAAU,MAAM,WAAW,KAAK;EAErC,OAAO;CACR;;;;;;;CAQA,YAAY,OAAO;EAClB,MAAM,KAAKA,MAAW,KAAK;EAE3B,IAAI,CAAC,KAAK,QAAQ,KAAO,OAAO;EAEhC,IAAI,KAAK,SACR,MAAM,SAAS,IAAI;EAGpB,OAAO,KAAK,QAAQ;EAEpB,IAAI,KAAK,SAAS;GACjB,KAAK,KAAK,eAAe,EAAC,MAAK,CAAC;GAChC,MAAM,KAAK,QAAQ;EACpB;EAEA,MAAM,OAAO,MAAM,YAAY;EAE/B,OAAO;CACR;;;;;;;CAQA,SAAS,OAAO;EACf,OAAOA,MA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Gd,IAAI,CAAC,IAAI,SAAS,IAAI,GAAK;EAE3B,KAAK,OAAO;EACZ,KAAK,gBAAgB,IAAI;EAEzB,IAAI,KAAK,WAAW;GACnB,MAAM,SAAS,KAAK,UAAU;GAC9B,IAAI,GAAG,QAAQ,IAAI;GACnB,KAAK,KAAK,gBAAgB,IAAI,IAAI,QAAQ,IAAI,CAAC;EAChD;EAEA,KAAK,MAAM,GAAG;EAEd,KAAK,KAAK,KAAK;EACf,IAAI,KAAK,YAAY,EAAC,OAAO,KAAI,CAAC;CACnC;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,eAAe;CACnC;AACD"}
|
|
1
|
+
{"version":3,"file":"Layer.js","names":["Util.stamp"],"sources":["../../../src/layer/Layer.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as Util from '../core/Util.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LayerGroup} from './LayerGroup.js' */\n/** @import {EventListener, MaplairEvent, MaplairPointerEvent, LayerEvent} from '../core/Events.js' */\n\n/**\n * Options of `Layer`, inherited by all layers.\n * @typedef {object} LayerOptions\n * @property {string} [pane='overlayPane'] By default the layer will be added to the\n * map's [overlay pane](#map-pane) (`overlayPane`). Overriding this option will cause the layer\n * to be placed on another pane by default. Not effective if the `renderer` option is\n * set (the `renderer` option will override the `pane` option).\n * @property {string|null} [attribution=null] String to be shown in the attribution\n * control, e.g. \"© OpenStreetMap contributors\". It describes the layer data and is\n * often a legal obligation towards copyright holders and tile providers.\n * @property {number} [attributionOrder=0] The position of the attribution in the\n * attribution control: attributions are sorted by it, then by the order of adding,\n * e.g. `1` keeps a legend last.\n */\n\n/**\n * Options of interactive layers. Some layers can be made interactive - when the user\n * interacts with such a layer, pointer events like `click` and `pointerover` can be\n * handled. Use the [event handling methods](#evented-method) to handle these events.\n * @typedef {object} InteractiveLayerOptions\n * @property {boolean} [interactive=true] If `false`, the layer will not emit pointer\n * events and will act as a part of the underlying map.\n * @property {boolean} [bubblingPointerEvents=true] When `true`, a pointer event on this\n * layer will trigger the same event on the map (unless\n * [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).\n * @extends LayerOptions\n * @fires Layer#click {MaplairPointerEvent} Fired when the user clicks (or taps) the\n * layer, if it is interactive.\n * @fires Layer#dblclick {MaplairPointerEvent} Fired when the user double-clicks (or\n * double-taps) the layer, if it is interactive.\n * @fires Layer#pointerdown {MaplairPointerEvent} Fired when the user pushes the pointer\n * on the layer, if it is interactive.\n * @fires Layer#pointerup {MaplairPointerEvent} Fired when the user releases the pointer\n * pushed on the layer, if it is interactive.\n * @fires Layer#pointerover {MaplairPointerEvent} Fired when the pointer enters the\n * layer, if it is interactive.\n * @fires Layer#pointerout {MaplairPointerEvent} Fired when the pointer leaves the layer,\n * if it is interactive.\n * @fires Layer#contextmenu {MaplairPointerEvent} Fired when the user right-clicks on\n * the layer, if it is interactive; prevents default browser context menu from showing\n * if there are listeners on this event. Also fired on mobile when the user holds a\n * single touch for a second (also called long press).\n */\n\n/**\n * Methods of `MaplairMap` for layers.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#layeradd {LayerEvent} Fired when a new layer is added to the map.\n * @fires MaplairMap#layerremove {LayerEvent} Fired when some layer is removed from the map.\n * @fires MaplairMap#zoomlevelschange {MaplairEvent} Fired when the number of zoomlevels\n * on the map is changed due to adding or removing a layer.\n */\nconst mapLayerMethods = {\n\t/**\n\t * Adds the given layer to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (!layer._layerAdd) {\n\t\t\tthrow new Error('The provided object is not a Layer.');\n\t\t}\n\n\t\tconst id = Util.stamp(layer);\n\t\tif (this._layers[id]) { return this; }\n\t\tthis._layers[id] = layer;\n\n\t\tlayer._mapToAdd = this;\n\n\t\tif (layer.beforeAdd) {\n\t\t\tlayer.beforeAdd(this);\n\t\t}\n\n\t\tthis.whenReady(layer._layerAdd, layer);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given layer from the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (!this._layers[id]) { return this; }\n\n\t\tif (this._loaded) {\n\t\t\tlayer.onRemove(this);\n\t\t}\n\n\t\tdelete this._layers[id];\n\n\t\tif (this._loaded) {\n\t\t\tthis.fire('layerremove', {layer});\n\t\t\tlayer.fire('remove');\n\t\t}\n\n\t\tlayer._map = layer._mapToAdd = null;\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the given layer is currently added to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {boolean}\n\t */\n\thasLayer(layer) {\n\t\treturn Util.stamp(layer) in this._layers;\n\t},\n\n\t/**\n\t * Iterates over the layers of the map, optionally specifying context of the iterator function.\n\t * ```js\n\t * map.eachLayer(function(layer){\n\t * layer.bindPopup('Hello');\n\t * });\n\t * ```\n\t * @group Methods for layers and controls\n\t * @param {(layer: Layer) => void} method\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\teachLayer(method, context) {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tmethod.call(context, layer);\n\t\t}\n\t\treturn this;\n\t},\n\n\t_addLayers(layers) {\n\t\tlayers = layers ? (Array.isArray(layers) ? layers : [layers]) : [];\n\n\t\tfor (const layer of layers) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\t},\n\n\t_addZoomLimit(layer) {\n\t\tif (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) {\n\t\t\tthis._zoomBoundLayers[Util.stamp(layer)] = layer;\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_removeZoomLimit(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (this._zoomBoundLayers[id]) {\n\t\t\tdelete this._zoomBoundLayers[id];\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_updateZoomLevels() {\n\t\tlet minZoom = Infinity,\n\t\tmaxZoom = -Infinity;\n\t\tconst oldZoomSpan = this._getZoomSpan();\n\n\t\tfor (const l of Object.values(this._zoomBoundLayers)) {\n\t\t\tconst options = l.options;\n\t\t\tif (options.minZoom != null && !Number.isNaN(options.minZoom)) {\n\t\t\t\tminZoom = Math.min(minZoom, options.minZoom);\n\t\t\t}\n\t\t\tif (options.maxZoom != null && !Number.isNaN(options.maxZoom)) {\n\t\t\t\tmaxZoom = Math.max(maxZoom, options.maxZoom);\n\t\t\t}\n\t\t}\n\n\t\tthis._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;\n\t\tthis._layersMinZoom = minZoom === Infinity ? undefined : minZoom;\n\n\t\tif (oldZoomSpan !== this._getZoomSpan()) {\n\t\t\tthis.fire('zoomlevelschange');\n\t\t}\n\n\t\tif (this.options.maxZoom === undefined && this._layersMaxZoom !== undefined && this.getZoom() > this._layersMaxZoom) {\n\t\t\tthis.setZoom(this._layersMaxZoom);\n\t\t}\n\t\tif (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {\n\t\t\tthis.setZoom(this._layersMinZoom);\n\t\t}\n\t}\n};\n/** @typedef {typeof mapLayerMethods} MapLayerMethods */\n\n/**\n * The methods which layers implement, see `Layer`.\n * @typedef {object} LayerExtensionMethods\n * @property {(map: MaplairMap) => void} [onAdd] Should contain code that creates DOM\n * elements for the layer, adds them to `map panes` where they should belong and puts\n * listeners on relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the layer's elements from the DOM and removes listeners previously added in\n * `onAdd`. Called on [`map.removeLayer(layer)`](#map-removelayer).\n * @property {() => Record<string, Function>} [getEvents] Should return an object\n * like `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * @property {() => HTMLElement|string} [getLegend] Should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * @property {(map: MaplairMap) => void} [beforeAdd] Called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map, before\n * events are initialized, without waiting until the map is in a usable state. Use for\n * early initialization only.\n * @lends Layer\n */\n\n/**\n * The base class of all Maplair layers, with the methods they share.\n *\n * Every layer should extend from `Layer` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): this` should contain code that creates DOM elements for\n * the layer, adds them to `map panes` where they should belong and puts listeners on\n * relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * * `onRemove(map: MaplairMap): this` should contain all clean up code that removes the\n * layer's elements from the DOM and removes listeners previously added in `onAdd`.\n * Called on [`map.removeLayer(layer)`](#map-removelayer).\n * * `getEvents(): Object` (optional) should return an object like\n * `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * * `getAttribution(): String` (optional) should return a string containing HTML to be\n * shown on the `Attribution control` whenever the layer is visible.\n * * `getLegend(): HTMLElement|String` (optional) should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * * `beforeAdd(map: MaplairMap): this` (optional) is called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map,\n * before events are initialized, without waiting until the map is in a usable state.\n * Use for early initialization only.\n *\n * @example\n * ```js\n * const layer = new Marker(latlng).addTo(map);\n * layer.addTo(map);\n * layer.remove();\n * ```\n *\n * @fires add {MaplairEvent} Fired after the layer is added to a map.\n * @fires remove {MaplairEvent} Fired after the layer is removed from a map.\n */\nexport class Layer extends Evented {\n\n\tstatic defaultOptions = {\n\t\tpane: 'overlayPane',\n\t\tattribution: null,\n\t\tattributionOrder: 0,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Adds the layer to the given map or layer group.\n\t * @param {MaplairMap|LayerGroup} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tmap.addLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the layer from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\treturn this.removeFrom(this._map || this._mapToAdd);\n\t}\n\n\t/**\n\t * Removes the layer from the given map or `LayerGroup`.\n\t * @param {MaplairMap|LayerGroup} obj\n\t * @returns {this}\n\t */\n\tremoveFrom(obj) {\n\t\tobj?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the `HTMLElement` representing the named pane on the map. If `name` is\n\t * omitted, returns the pane for this layer.\n\t * @param {string} [name]\n\t * @returns {HTMLElement}\n\t */\n\tgetPane(name) {\n\t\treturn this._map.getPane(name ? (this.options[name] || name) : this.options.pane);\n\t}\n\n\t/**\n\t * Changes the [`interactive`](#interactivelayeroptions-interactive) option of the\n\t * layer, e.g. to stop a layer from emitting pointer events while it is being edited.\n\t * @param {boolean} interactive\n\t * @returns {this}\n\t */\n\tsetInteractive(interactive) {\n\t\tinteractive = !!interactive;\n\t\tif (this.options.interactive !== interactive) {\n\t\t\tUtil.setOptions(this, {interactive});\n\t\t\tif (this._map) {\n\t\t\t\tthis._updateInteractive();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Applies a changed `interactive` option to a layer on the map, see `setInteractive()`.\n\t_updateInteractive() {}\n\n\t/**\n\t * Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and\n\t * keyboard events on it (or its descendants) fire on the layer and bubble through its\n\t * parent groups to the map, the way they do for markers and paths. Custom layers call\n\t * it in [`onAdd`](#layer-onadd), once the layer is on a map.\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\taddInteractiveTarget(targetEl) {\n\t\tthis._map._targets[Util.stamp(targetEl)] = this;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in\n\t * [`onRemove`](#layer-onremove).\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\tremoveInteractiveTarget(targetEl) {\n\t\tdelete this._map._targets[Util.stamp(targetEl)];\n\t\treturn this;\n\t}\n\n\t// Whether clicking the layer again closes its popup, rather than moving it to the\n\t// clicked point like on paths, where the popup opens where they were clicked.\n\t_togglesPopupOnClick() {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).\n\t * @returns {string|null}\n\t */\n\tgetAttribution() {\n\t\treturn this.options.attribution;\n\t}\n\n\t/**\n\t * Changes the [attribution option](#layeroptions-attribution), also in the\n\t * attribution control while the layer is on the map.\n\t * @param {string|null} attribution\n\t * @returns {this}\n\t */\n\tsetAttribution(attribution) {\n\t\tconst control = this._map?.attributionControl;\n\t\tcontrol?._removeLayer({layer: this});\n\t\tUtil.setOptions(this, {attribution});\n\t\tcontrol?._addLayer({layer: this});\n\t\treturn this;\n\t}\n\n\t_layerAdd(e) {\n\t\tconst map = e.target;\n\n\t\t// check in case layer gets added and then removed before the map is ready\n\t\tif (!map.hasLayer(this)) { return; }\n\n\t\tthis._map = map;\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (this.getEvents) {\n\t\t\tconst events = this.getEvents();\n\t\t\tmap.on(events, this);\n\t\t\tthis.once('remove', () => map.off(events, this));\n\t\t}\n\n\t\tthis.onAdd(map);\n\n\t\tthis.fire('add');\n\t\tmap.fire('layeradd', {layer: this});\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(mapLayerMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,kBAAkB;;;;;;;CAOvB,SAAS,OAAO;EACf,IAAI,CAAC,MAAM,WACV,MAAM,IAAI,MAAM,qCAAqC;EAGtD,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