maplair 4.0.0-alpha.2 → 4.0.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 +22 -38
- package/LICENSE +1 -1
- package/README.md +10 -9
- package/dist/esm/control/SearchControl.js +1 -1
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/geo/LatLng.js +20 -2
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +19 -7
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +4 -3
- package/dist/esm/geo/crs/CRS.js.map +1 -1
- package/dist/esm/geo/projection/Projection.LonLat.js +2 -2
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
- package/dist/esm/geo/projection/Projection.Mercator.js +2 -2
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +2 -2
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +19 -7
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +23 -5
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +1 -1
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +1 -1
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/GeoJSON.js +1 -1
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/Popup.js +1 -1
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +1 -1
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +2 -2
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +1 -1
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +2 -2
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +1 -1
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +1 -1
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +5 -5
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +19 -19
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +1 -1
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +2 -2
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +134 -73
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +3 -3
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +134 -73
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.js +3 -3
- package/dist/maplair.js.map +1 -1
- package/package.json +4 -4
- package/src/control/SearchControl.js +2 -2
- package/src/geo/LatLng.js +21 -2
- package/src/geo/LatLngBounds.js +20 -7
- package/src/geo/crs/CRS.js +4 -3
- package/src/geo/projection/Projection.LonLat.js +2 -2
- package/src/geo/projection/Projection.Mercator.js +2 -2
- package/src/geo/projection/Projection.SphericalMercator.js +2 -2
- package/src/geometry/Bounds.js +20 -7
- package/src/geometry/Point.js +24 -5
- package/src/geometry/PolyUtil.js +1 -1
- package/src/layer/DivOverlay.js +1 -1
- package/src/layer/GeoJSON.js +1 -1
- package/src/layer/Popup.js +3 -3
- package/src/layer/marker/DivIcon.js +1 -1
- package/src/layer/marker/Icon.js +2 -2
- package/src/layer/marker/Marker.Move.js +1 -1
- package/src/layer/marker/Marker.js +2 -2
- package/src/layer/tile/GridLayer.js +1 -1
- package/src/layer/vector/Polyline.js +1 -1
- package/src/map/Map.Rotation.js +7 -7
- package/src/map/Map.js +21 -21
- package/src/map/handler/DragHandler.js +1 -1
- package/src/map/handler/KeyboardHandler.js +2 -2
package/dist/esm/layer/Popup.js
CHANGED
|
@@ -436,7 +436,7 @@ var Popup = class Popup extends DivOverlay {
|
|
|
436
436
|
}
|
|
437
437
|
const map = this._map, marginBottom = this._containerMarginBottom ?? (parseInt(getComputedStyle(this._container).marginBottom, 10) || 0), containerHeight = this._containerHeight + marginBottom, containerWidth = this._containerWidth, layerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom);
|
|
438
438
|
layerPos._add(this._getContainerPosition());
|
|
439
|
-
const containerPos = map.layerPointToContainerPoint(layerPos), padding =
|
|
439
|
+
const containerPos = map.layerPointToContainerPoint(layerPos), padding = Point.from(this.options.autoPanPadding), paddingTL = Point.from(this.options.autoPanPaddingTopLeft ?? padding), paddingBR = Point.from(this.options.autoPanPaddingBottomRight ?? padding), size = map.getSize();
|
|
440
440
|
let dx = 0, dy = 0;
|
|
441
441
|
if (containerPos.x + containerWidth + paddingBR.x > size.x) dx = containerPos.x + containerWidth - size.x + paddingBR.x;
|
|
442
442
|
if (containerPos.x - dx - paddingTL.x < 0) dx = containerPos.x - paddingTL.x;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Popup.js","names":["Browser","DomEvent.stopPropagation","DomUtil.create"],"sources":["../../../src/layer/Popup.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport Browser from '../core/Browser.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport {Path} from './vector/Path.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport {I18n} from '../core/I18n.js';\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent, PopupEvent} from '../core/Events.js' */\n\n/**\n * Options of `Popup`.\n * @typedef {object} PopupOptions\n * @property {string} [pane='popupPane'] `Map pane` where the popup will be added.\n * @property {PointExpression} [offset=[0, 7]] The offset of the popup position.\n * @property {number} [maxWidth=300] Max width of the popup, in pixels.\n * @property {number} [minWidth=50] Min width of the popup, in pixels.\n * @property {number|null} [maxHeight=null] If set, creates a scrollable container of\n * the given height inside a popup if its content exceeds it. The scrollable container\n * can be styled using the `maplair-popup-scrolled` CSS class selector.\n * @property {boolean} [autoPan] Set it to `false` if you don't want the map to do\n * panning animation to fit the opened popup. Defaults to `true`, unless the user\n * prefers reduced motion (`Browser.reducedMotion`).\n * @property {PointExpression|null} [autoPanPaddingTopLeft=null] The margin between the\n * popup and the top left corner of the map view after autopanning was performed.\n * @property {PointExpression|null} [autoPanPaddingBottomRight=null] The margin between\n * the popup and the bottom right corner of the map view after autopanning was\n * performed.\n * @property {PointExpression} [autoPanPadding=[5, 5]] Equivalent of setting both top\n * left and bottom right autopan padding to the same value.\n * @property {boolean} [keepInView=false] Set it to `true` if you want to prevent users\n * from panning the popup off of the screen while it is open.\n * @property {boolean} [closeButton=true] Controls the presence of a close button in\n * the popup.\n * @property {boolean} [autoClose=true] Set it to `false` if you want to override the\n * default behavior of the popup closing when another popup is opened.\n * @property {boolean} [closeOnEscapeKey=true] Set it to `false` if you want to\n * override the default behavior of the ESC key for closing of the popup.\n * @property {boolean} [closeOnClick] Set it if you want to override the default\n * behavior of the popup closing when user clicks on the map. Defaults to the map's\n * [`closePopupOnClick`](#map-closepopuponclick) option.\n * @property {string} [className=''] A custom CSS class name to assign to the popup.\n * @property {boolean} [trackResize=true] Whether the popup shall react to changes in\n * the size of its contents (e.g. when an image inside the popup loads) and reposition\n * itself.\n * @extends DivOverlayOptions\n */\n\n/**\n * Map options of `Popup`.\n * @typedef {object} PopupMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [closePopupOnClick=true] Set it to `false` if you don't want\n * popups to close when user clicks the map.\n */\n\n/**\n * Methods of `MaplairMap` for popups.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#popupopen {PopupEvent} Fired when a popup is opened in the map.\n * @fires MaplairMap#popupclose {PopupEvent} Fired when a popup in the map is closed.\n * @fires MaplairMap#autopanstart {MaplairEvent} Fired when the map starts autopanning\n * when opening a popup.\n */\nconst mapPopupMethods = {\n\t/**\n\t * Opens the specified popup while closing the previously opened (to make sure only\n\t * one is opened at one time for usability).\n\t *\n\t * Alternatively, creates a popup with the specified content and options and opens\n\t * it in the given point on a map. String content is rendered as HTML; sanitize\n\t * untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Popup|DivOverlayContent} popup The popup, or the content of a new popup.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\topenPopup(popup, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Popup, popup, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup previously opened with [openPopup](#map-openpopup) (or the\n\t * given one).\n\t * @group Methods for layers and controls\n\t * @param {Popup} [popup]\n\t * @returns {this}\n\t */\n\tclosePopup(popup) {\n\t\tpopup = arguments.length ? popup : this._popup;\n\t\tpopup?.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapPopupMethods} MapPopupMethods */\n\n/**\n * Methods of `Layer` for popups. All layers share a set of methods convenient for\n * binding popups to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindPopup('Hi There!').addTo(map);\n * layer.openPopup();\n * layer.closePopup();\n * ```\n *\n * Popups will also be automatically opened when the layer is clicked on and closed\n * when the layer is removed from the map or another popup is opened.\n *\n * @lends Layer.prototype\n * @fires Layer#popupopen {PopupEvent} Fired when a popup bound to this layer is opened.\n * @fires Layer#popupclose {PopupEvent} Fired when a popup bound to this layer is closed.\n */\nconst layerPopupMethods = {\n\t/**\n\t * Binds a popup to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an\n\t * `HTMLElement` with safe `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String` or `HTMLElement`.\n\t * @group Popup methods\n\t * @param {DivOverlayContent|Popup} content\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\tbindPopup(content, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._popup = this._initOverlay(Popup, this._popup, content, options);\n\t\tif (!this._popupHandlersAdded) {\n\t\t\tthis.on({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tkeypress: this._onKeyPress,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tthis._popupHandlersAdded = true;\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the popup previously bound with `bindPopup`.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tunbindPopup() {\n\t\tif (this._popup) {\n\t\t\tthis.off({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tkeypress: this._onKeyPress,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tthis._popupHandlersAdded = false;\n\t\t\tthis._popup = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens the bound popup at the specified `latlng` or at the default popup anchor\n\t * if no `latlng` is passed.\n\t * @group Popup methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenPopup(latlng) {\n\t\tif (this._popup) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._popup._source = this;\n\t\t\t}\n\t\t\tif (this._popup._prepareOpen(latlng || this._latlng)) {\n\t\t\t\t// open the popup on the map\n\t\t\t\tthis._popup.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup bound to this layer if it is open.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tclosePopup() {\n\t\tthis._popup?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the popup bound to this layer depending on its current state.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\ttogglePopup() {\n\t\tthis._popup?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the popup bound to this layer is currently open.\n\t * @group Popup methods\n\t * @returns {boolean}\n\t */\n\tisPopupOpen() {\n\t\treturn this._popup?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the popup bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Popup methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetPopupContent(content) {\n\t\tthis._popup?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the popup bound to this layer.\n\t * @group Popup methods\n\t * @returns {Popup|undefined}\n\t */\n\tgetPopup() {\n\t\treturn this._popup;\n\t},\n\n\t_openPopup(e) {\n\t\tif (!this._popup || !this._map) {\n\t\t\treturn;\n\t\t}\n\t\t// prevent map click\n\t\tDomEvent.stop(e);\n\n\t\tconst target = e.propagatedFrom ?? e.target;\n\t\tif (this._popup._source === target && !(target instanceof Path)) {\n\t\t\t// treat it like a marker and figure out\n\t\t\t// if we should toggle it open/closed\n\t\t\tif (this._map.hasLayer(this._popup)) {\n\t\t\t\tthis.closePopup();\n\t\t\t} else {\n\t\t\t\tthis.openPopup(e.latlng);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._popup._source = target;\n\t\tthis.openPopup(e.latlng);\n\t},\n\n\t_movePopup(e) {\n\t\tthis._popup.setLatLng(e.latlng);\n\t},\n\n\t_onKeyPress(e) {\n\t\tif (e.originalEvent.code === 'Enter') {\n\t\t\tthis._popup._openedByKeyboard = true;\n\t\t\tthis._openPopup(e);\n\t\t\tthis._popup._openedByKeyboard = false;\n\t\t}\n\t}\n};\n/** @typedef {typeof layerPopupMethods} LayerPopupMethods */\n\n/**\n * Used to open popups in certain places of the map. Use [Map.openPopup](#map-openpopup) to\n * open popups while making sure that only one popup is open at one time\n * (recommended for usability), or use [Map.addLayer](#map-addlayer) to open as many as you want.\n *\n * @example\n * If you want to just bind a popup to marker click and then open it, it's really easy:\n *\n * ```js\n * marker.bindPopup(popupContent).openPopup();\n * ```\n * Path overlays like polylines also have a `bindPopup` method.\n *\n * A popup can be also standalone:\n *\n * ```js\n * const popup = new Popup()\n * \t.setLatLng(latlng)\n * \t.setContent('<p>Hello world!<br />This is a nice popup.</p>')\n * \t.openOn(map);\n * ```\n * or\n * ```js\n * const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})\n * \t.openOn(map);\n * ```\n *\n * **Security note.** Popup string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or\n * build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindPopup(el);\n * ```\n */\nexport class Popup extends DivOverlay {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tpane: 'popupPane',\n\t\t\toffset: [0, 7],\n\t\t\tmaxWidth: 300,\n\t\t\tminWidth: 50,\n\t\t\tmaxHeight: null,\n\t\t\tautoPan: !Browser.reducedMotion,\n\t\t\tautoPanPaddingTopLeft: null,\n\t\t\tautoPanPaddingBottomRight: null,\n\t\t\tautoPanPadding: [5, 5],\n\t\t\tkeepInView: false,\n\t\t\tcloseButton: true,\n\t\t\tautoClose: true,\n\t\t\tcloseOnEscapeKey: true,\n\t\t\tclassName: '',\n\t\t\ttrackResize: true,\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a `Popup` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the popup with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {PopupOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Popup` object given `latlng` where the popup will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {PopupOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Popup);\n\t}\n\n\t/**\n\t * Alternative to `map.openPopup(popup)`.\n\t * Adds the popup to the map and closes the previous one.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\n\t\tif (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) {\n\t\t\tmap.removeLayer(map._popup);\n\t\t}\n\t\tmap._popup = this;\n\n\t\treturn super.openOn(map);\n\t}\n\n\t/**\n\t * Adds the popup to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\t// The element to return the focus to when closing the popup, e.g. a marker\n\t\tconst active = document.activeElement;\n\t\tthis._returnFocus = map._container.contains(active) && !this._container?.contains(active) ? active : null;\n\n\t\tsuper.onAdd(map);\n\n\t\tif (this._openedByKeyboard) {\n\t\t\t// Move the focus into the popup, so that its content is read and reachable\n\t\t\tif (!this._closeButton) {\n\t\t\t\tthis._container.tabIndex = -1;\n\t\t\t}\n\t\t\t(this._closeButton ?? this._container).focus({preventScroll: true});\n\t\t}\n\n\t\tmap.fire('popupopen', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupopen', {popup: this}, true);\n\t\t\t// For non-path layers, we toggle the popup when clicking\n\t\t\t// again the layer, so prevent the map to reopen it.\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.on('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the popup from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this._container.contains(document.activeElement) && this._returnFocus?.isConnected) {\n\t\t\tthis._returnFocus.focus({preventScroll: true});\n\t\t}\n\t\tthis._returnFocus = null;\n\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('popupclose', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupclose', {popup: this}, true);\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.off('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the popup listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (this.options.closeOnClick ?? this._map.options.closePopupOnClick) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\tif (this.options.keepInView) {\n\t\t\tevents.moveend = this._adjustPan;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-popup',\n\t\tcontainer = this._container = DomUtil.create('div', `${prefix} ${this.options.className || ''} maplair-zoom-animated`);\n\n\t\tconst wrapper = this._wrapper = DomUtil.create('div', `${prefix}-content-wrapper`, container);\n\t\tthis._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\t// The keyboard handler of the map does not get keys while the focus is in the popup\n\t\tDomEvent.on(container, 'keydown', (e) => {\n\t\t\tif (e.key === 'Escape' && this.options.closeOnEscapeKey) {\n\t\t\t\tthis.close();\n\t\t\t}\n\t\t});\n\t\tDomEvent.disableScrollPropagation(this._contentNode);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stopPropagation);\n\n\t\tthis._tipContainer = DomUtil.create('div', `${prefix}-tip-container`, container);\n\t\tthis._tip = DomUtil.create('div', `${prefix}-tip`, this._tipContainer);\n\n\t\tif (this.options.closeButton) {\n\t\t\tconst closeButton = this._closeButton = DomUtil.create('button', `${prefix}-close-button`, container);\n\t\t\tcloseButton.type = 'button';\n\t\t\tcloseButton.setAttribute('aria-label', I18n.translate('Close popup'));\n\n\t\t\tcloseButton.innerHTML = '<span aria-hidden=\"true\">×</span>';\n\n\t\t\tDomEvent.on(closeButton, 'click', (ev) => {\n\t\t\t\tev.preventDefault();\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.trackResize) {\n\t\t\tthis._resizeObserver = new ResizeObserver(((entries) => {\n\t\t\t\tif (!this._map) { return; }\n\t\t\t\tthis._containerWidth = entries[0]?.contentRect?.width;\n\t\t\t\tthis._containerHeight = entries[0]?.contentRect?.height;\n\n\t\t\t\tthis._updateLayout();\n\t\t\t\tthis._updatePosition();\n\t\t\t\tthis._adjustPan();\n\t\t\t}));\n\n\t\t\tthis._resizeObserver.observe(this._contentNode);\n\t\t}\n\t}\n\n\t_updateLayout() {\n\t\tconst container = this._contentNode,\n\t\tstyle = container.style;\n\n\t\tstyle.maxWidth = `${this.options.maxWidth}px`;\n\t\tstyle.minWidth = `${this.options.minWidth}px`;\n\n\t\tconst maxHeight = this.options.maxHeight,\n\t\tscrolledClass = 'maplair-popup-scrolled';\n\n\t\t// only measure the height (forcing a layout) if needed\n\t\tif (maxHeight && (this._containerHeight ?? container.offsetHeight) > maxHeight) {\n\t\t\tstyle.height = `${maxHeight}px`;\n\t\t\tcontainer.classList.add(scrolledClass);\n\t\t} else {\n\t\t\tcontainer.classList.remove(scrolledClass);\n\t\t}\n\n\t\tthis._containerWidth = this._container.offsetWidth;\n\t\tthis._containerHeight = this._container.offsetHeight;\n\t\t// read along with the size, so that _adjustPan doesn't force another style\n\t\t// recalculation and layout after the popup has been positioned\n\t\tthis._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center),\n\t\tanchor = this._getAnchor();\n\t\tthis._setContainerPosition(pos.add(anchor));\n\t}\n\n\t_adjustPan() {\n\t\tif (!this.options.autoPan) { return; }\n\t\tthis._map._panAnim?.stop();\n\n\t\t// We can endlessly recurse if keepInView is set and the view resets.\n\t\t// Let's guard against that by exiting early if we're responding to our own autopan.\n\t\tif (this._autopanning) {\n\t\t\tthis._autopanning = false;\n\t\t\treturn;\n\t\t}\n\n\t\tconst map = this._map,\n\t\tmarginBottom = this._containerMarginBottom ?? (parseInt(getComputedStyle(this._container).marginBottom, 10) || 0),\n\t\tcontainerHeight = this._containerHeight + marginBottom,\n\t\tcontainerWidth = this._containerWidth,\n\t\tlayerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom);\n\n\t\tlayerPos._add(this._getContainerPosition());\n\n\t\tconst containerPos = map.layerPointToContainerPoint(layerPos),\n\t\tpadding = new Point(this.options.autoPanPadding),\n\t\tpaddingTL = new Point(this.options.autoPanPaddingTopLeft ?? padding),\n\t\tpaddingBR = new Point(this.options.autoPanPaddingBottomRight ?? padding),\n\t\tsize = map.getSize();\n\t\tlet dx = 0,\n\t\tdy = 0;\n\n\t\tif (containerPos.x + containerWidth + paddingBR.x > size.x) { // right\n\t\t\tdx = containerPos.x + containerWidth - size.x + paddingBR.x;\n\t\t}\n\t\tif (containerPos.x - dx - paddingTL.x < 0) { // left\n\t\t\tdx = containerPos.x - paddingTL.x;\n\t\t}\n\t\tif (containerPos.y + containerHeight + paddingBR.y > size.y) { // bottom\n\t\t\tdy = containerPos.y + containerHeight - size.y + paddingBR.y;\n\t\t}\n\t\tif (containerPos.y - dy - paddingTL.y < 0) { // top\n\t\t\tdy = containerPos.y - paddingTL.y;\n\t\t}\n\n\t\tif (dx || dy) {\n\t\t\t// Track that we're autopanning, as this function will be re-ran on moveend\n\t\t\tif (this.options.keepInView) {\n\t\t\t\tthis._autopanning = true;\n\t\t\t}\n\n\t\t\tmap\n\t\t\t\t.fire('autopanstart')\n\t\t\t\t.panBy([dx, dy]);\n\t\t}\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the popup on the source layer?\n\t\treturn new Point(this._source?._getPopupAnchor ? this._source._getPopupAnchor() : [0, 0]);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tclosePopupOnClick: true\n\t\t});\n\n\t\tMaplairMap.include(mapPopupMethods);\n\n\t\tLayer.include(layerPopupMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,MAAM,kBAAkB;;;;;;;;;;;;;;CAcvB,UAAU,OAAO,QAAQ,SAAS;EAEjC,KAAK,aAAa,OAAO,OAAO,QAAQ,OAAO,CAAC,CAC9C,OAAO,IAAI;EAEb,OAAO;CACR;;;;;;;;CASA,WAAW,OAAO;EACjB,QAAQ,UAAU,SAAS,QAAQ,KAAK;EACxC,OAAO,MAAM;EACb,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;;;;;;;;;;;;;CAazB,UAAU,SAAS,SAAS;EAE3B,KAAK,SAAS,KAAK,aAAa,OAAO,KAAK,QAAQ,SAAS,OAAO;EACpE,IAAI,CAAC,KAAK,qBAAqB;GAC9B,KAAK,GAAG;IACP,OAAO,KAAK;IACZ,UAAU,KAAK;IACf,QAAQ,KAAK;IACb,MAAM,KAAK;GACZ,CAAC;GACD,KAAK,sBAAsB;EAC5B;EAEA,OAAO;CACR;;;;;;CAOA,cAAc;EACb,IAAI,KAAK,QAAQ;GAChB,KAAK,IAAI;IACR,OAAO,KAAK;IACZ,UAAU,KAAK;IACf,QAAQ,KAAK;IACb,MAAM,KAAK;GACZ,CAAC;GACD,KAAK,sBAAsB;GAC3B,KAAK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agation","DomUtil.create"],"sources":["../../../src/layer/Popup.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport Browser from '../core/Browser.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport {Path} from './vector/Path.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport {I18n} from '../core/I18n.js';\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent, PopupEvent} from '../core/Events.js' */\n\n/**\n * Options of `Popup`.\n * @typedef {object} PopupOptions\n * @property {string} [pane='popupPane'] `Map pane` where the popup will be added.\n * @property {PointExpression} [offset=[0, 7]] The offset of the popup position.\n * @property {number} [maxWidth=300] Max width of the popup, in pixels.\n * @property {number} [minWidth=50] Min width of the popup, in pixels.\n * @property {number|null} [maxHeight=null] If set, creates a scrollable container of\n * the given height inside a popup if its content exceeds it. The scrollable container\n * can be styled using the `maplair-popup-scrolled` CSS class selector.\n * @property {boolean} [autoPan] Set it to `false` if you don't want the map to do\n * panning animation to fit the opened popup. Defaults to `true`, unless the user\n * prefers reduced motion (`Browser.reducedMotion`).\n * @property {PointExpression|null} [autoPanPaddingTopLeft=null] The margin between the\n * popup and the top left corner of the map view after autopanning was performed.\n * @property {PointExpression|null} [autoPanPaddingBottomRight=null] The margin between\n * the popup and the bottom right corner of the map view after autopanning was\n * performed.\n * @property {PointExpression} [autoPanPadding=[5, 5]] Equivalent of setting both top\n * left and bottom right autopan padding to the same value.\n * @property {boolean} [keepInView=false] Set it to `true` if you want to prevent users\n * from panning the popup off of the screen while it is open.\n * @property {boolean} [closeButton=true] Controls the presence of a close button in\n * the popup.\n * @property {boolean} [autoClose=true] Set it to `false` if you want to override the\n * default behavior of the popup closing when another popup is opened.\n * @property {boolean} [closeOnEscapeKey=true] Set it to `false` if you want to\n * override the default behavior of the ESC key for closing of the popup.\n * @property {boolean} [closeOnClick] Set it if you want to override the default\n * behavior of the popup closing when user clicks on the map. Defaults to the map's\n * [`closePopupOnClick`](#map-closepopuponclick) option.\n * @property {string} [className=''] A custom CSS class name to assign to the popup.\n * @property {boolean} [trackResize=true] Whether the popup shall react to changes in\n * the size of its contents (e.g. when an image inside the popup loads) and reposition\n * itself.\n * @extends DivOverlayOptions\n */\n\n/**\n * Map options of `Popup`.\n * @typedef {object} PopupMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [closePopupOnClick=true] Set it to `false` if you don't want\n * popups to close when user clicks the map.\n */\n\n/**\n * Methods of `MaplairMap` for popups.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#popupopen {PopupEvent} Fired when a popup is opened in the map.\n * @fires MaplairMap#popupclose {PopupEvent} Fired when a popup in the map is closed.\n * @fires MaplairMap#autopanstart {MaplairEvent} Fired when the map starts autopanning\n * when opening a popup.\n */\nconst mapPopupMethods = {\n\t/**\n\t * Opens the specified popup while closing the previously opened (to make sure only\n\t * one is opened at one time for usability).\n\t *\n\t * Alternatively, creates a popup with the specified content and options and opens\n\t * it in the given point on a map. String content is rendered as HTML; sanitize\n\t * untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Popup|DivOverlayContent} popup The popup, or the content of a new popup.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\topenPopup(popup, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Popup, popup, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup previously opened with [openPopup](#map-openpopup) (or the\n\t * given one).\n\t * @group Methods for layers and controls\n\t * @param {Popup} [popup]\n\t * @returns {this}\n\t */\n\tclosePopup(popup) {\n\t\tpopup = arguments.length ? popup : this._popup;\n\t\tpopup?.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapPopupMethods} MapPopupMethods */\n\n/**\n * Methods of `Layer` for popups. All layers share a set of methods convenient for\n * binding popups to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindPopup('Hi There!').addTo(map);\n * layer.openPopup();\n * layer.closePopup();\n * ```\n *\n * Popups will also be automatically opened when the layer is clicked on and closed\n * when the layer is removed from the map or another popup is opened.\n *\n * @lends Layer.prototype\n * @fires Layer#popupopen {PopupEvent} Fired when a popup bound to this layer is opened.\n * @fires Layer#popupclose {PopupEvent} Fired when a popup bound to this layer is closed.\n */\nconst layerPopupMethods = {\n\t/**\n\t * Binds a popup to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an\n\t * `HTMLElement` with safe `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String` or `HTMLElement`.\n\t * @group Popup methods\n\t * @param {DivOverlayContent|Popup} content\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\tbindPopup(content, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._popup = this._initOverlay(Popup, this._popup, content, options);\n\t\tif (!this._popupHandlersAdded) {\n\t\t\tthis.on({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tkeypress: this._onKeyPress,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tthis._popupHandlersAdded = true;\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the popup previously bound with `bindPopup`.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tunbindPopup() {\n\t\tif (this._popup) {\n\t\t\tthis.off({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tkeypress: this._onKeyPress,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tthis._popupHandlersAdded = false;\n\t\t\tthis._popup = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens the bound popup at the specified `latlng` or at the default popup anchor\n\t * if no `latlng` is passed.\n\t * @group Popup methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenPopup(latlng) {\n\t\tif (this._popup) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._popup._source = this;\n\t\t\t}\n\t\t\tif (this._popup._prepareOpen(latlng || this._latlng)) {\n\t\t\t\t// open the popup on the map\n\t\t\t\tthis._popup.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup bound to this layer if it is open.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tclosePopup() {\n\t\tthis._popup?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the popup bound to this layer depending on its current state.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\ttogglePopup() {\n\t\tthis._popup?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the popup bound to this layer is currently open.\n\t * @group Popup methods\n\t * @returns {boolean}\n\t */\n\tisPopupOpen() {\n\t\treturn this._popup?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the popup bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Popup methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetPopupContent(content) {\n\t\tthis._popup?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the popup bound to this layer.\n\t * @group Popup methods\n\t * @returns {Popup|undefined}\n\t */\n\tgetPopup() {\n\t\treturn this._popup;\n\t},\n\n\t_openPopup(e) {\n\t\tif (!this._popup || !this._map) {\n\t\t\treturn;\n\t\t}\n\t\t// prevent map click\n\t\tDomEvent.stop(e);\n\n\t\tconst target = e.propagatedFrom ?? e.target;\n\t\tif (this._popup._source === target && !(target instanceof Path)) {\n\t\t\t// treat it like a marker and figure out\n\t\t\t// if we should toggle it open/closed\n\t\t\tif (this._map.hasLayer(this._popup)) {\n\t\t\t\tthis.closePopup();\n\t\t\t} else {\n\t\t\t\tthis.openPopup(e.latlng);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._popup._source = target;\n\t\tthis.openPopup(e.latlng);\n\t},\n\n\t_movePopup(e) {\n\t\tthis._popup.setLatLng(e.latlng);\n\t},\n\n\t_onKeyPress(e) {\n\t\tif (e.originalEvent.code === 'Enter') {\n\t\t\tthis._popup._openedByKeyboard = true;\n\t\t\tthis._openPopup(e);\n\t\t\tthis._popup._openedByKeyboard = false;\n\t\t}\n\t}\n};\n/** @typedef {typeof layerPopupMethods} LayerPopupMethods */\n\n/**\n * Used to open popups in certain places of the map. Use [Map.openPopup](#map-openpopup) to\n * open popups while making sure that only one popup is open at one time\n * (recommended for usability), or use [Map.addLayer](#map-addlayer) to open as many as you want.\n *\n * @example\n * If you want to just bind a popup to marker click and then open it, it's really easy:\n *\n * ```js\n * marker.bindPopup(popupContent).openPopup();\n * ```\n * Path overlays like polylines also have a `bindPopup` method.\n *\n * A popup can be also standalone:\n *\n * ```js\n * const popup = new Popup()\n * \t.setLatLng(latlng)\n * \t.setContent('<p>Hello world!<br />This is a nice popup.</p>')\n * \t.openOn(map);\n * ```\n * or\n * ```js\n * const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})\n * \t.openOn(map);\n * ```\n *\n * **Security note.** Popup string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or\n * build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindPopup(el);\n * ```\n */\nexport class Popup extends DivOverlay {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tpane: 'popupPane',\n\t\t\toffset: [0, 7],\n\t\t\tmaxWidth: 300,\n\t\t\tminWidth: 50,\n\t\t\tmaxHeight: null,\n\t\t\tautoPan: !Browser.reducedMotion,\n\t\t\tautoPanPaddingTopLeft: null,\n\t\t\tautoPanPaddingBottomRight: null,\n\t\t\tautoPanPadding: [5, 5],\n\t\t\tkeepInView: false,\n\t\t\tcloseButton: true,\n\t\t\tautoClose: true,\n\t\t\tcloseOnEscapeKey: true,\n\t\t\tclassName: '',\n\t\t\ttrackResize: true,\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a `Popup` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the popup with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {PopupOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Popup` object given `latlng` where the popup will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {PopupOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Popup);\n\t}\n\n\t/**\n\t * Alternative to `map.openPopup(popup)`.\n\t * Adds the popup to the map and closes the previous one.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\n\t\tif (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) {\n\t\t\tmap.removeLayer(map._popup);\n\t\t}\n\t\tmap._popup = this;\n\n\t\treturn super.openOn(map);\n\t}\n\n\t/**\n\t * Adds the popup to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\t// The element to return the focus to when closing the popup, e.g. a marker\n\t\tconst active = document.activeElement;\n\t\tthis._returnFocus = map._container.contains(active) && !this._container?.contains(active) ? active : null;\n\n\t\tsuper.onAdd(map);\n\n\t\tif (this._openedByKeyboard) {\n\t\t\t// Move the focus into the popup, so that its content is read and reachable\n\t\t\tif (!this._closeButton) {\n\t\t\t\tthis._container.tabIndex = -1;\n\t\t\t}\n\t\t\t(this._closeButton ?? this._container).focus({preventScroll: true});\n\t\t}\n\n\t\tmap.fire('popupopen', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupopen', {popup: this}, true);\n\t\t\t// For non-path layers, we toggle the popup when clicking\n\t\t\t// again the layer, so prevent the map to reopen it.\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.on('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the popup from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this._container.contains(document.activeElement) && this._returnFocus?.isConnected) {\n\t\t\tthis._returnFocus.focus({preventScroll: true});\n\t\t}\n\t\tthis._returnFocus = null;\n\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('popupclose', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupclose', {popup: this}, true);\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.off('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the popup listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (this.options.closeOnClick ?? this._map.options.closePopupOnClick) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\tif (this.options.keepInView) {\n\t\t\tevents.moveend = this._adjustPan;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-popup',\n\t\tcontainer = this._container = DomUtil.create('div', `${prefix} ${this.options.className || ''} maplair-zoom-animated`);\n\n\t\tconst wrapper = this._wrapper = DomUtil.create('div', `${prefix}-content-wrapper`, container);\n\t\tthis._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\t// The keyboard handler of the map does not get keys while the focus is in the popup\n\t\tDomEvent.on(container, 'keydown', (e) => {\n\t\t\tif (e.key === 'Escape' && this.options.closeOnEscapeKey) {\n\t\t\t\tthis.close();\n\t\t\t}\n\t\t});\n\t\tDomEvent.disableScrollPropagation(this._contentNode);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stopPropagation);\n\n\t\tthis._tipContainer = DomUtil.create('div', `${prefix}-tip-container`, container);\n\t\tthis._tip = DomUtil.create('div', `${prefix}-tip`, this._tipContainer);\n\n\t\tif (this.options.closeButton) {\n\t\t\tconst closeButton = this._closeButton = DomUtil.create('button', `${prefix}-close-button`, container);\n\t\t\tcloseButton.type = 'button';\n\t\t\tcloseButton.setAttribute('aria-label', I18n.translate('Close popup'));\n\n\t\t\tcloseButton.innerHTML = '<span aria-hidden=\"true\">×</span>';\n\n\t\t\tDomEvent.on(closeButton, 'click', (ev) => {\n\t\t\t\tev.preventDefault();\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.trackResize) {\n\t\t\tthis._resizeObserver = new ResizeObserver(((entries) => {\n\t\t\t\tif (!this._map) { return; }\n\t\t\t\tthis._containerWidth = entries[0]?.contentRect?.width;\n\t\t\t\tthis._containerHeight = entries[0]?.contentRect?.height;\n\n\t\t\t\tthis._updateLayout();\n\t\t\t\tthis._updatePosition();\n\t\t\t\tthis._adjustPan();\n\t\t\t}));\n\n\t\t\tthis._resizeObserver.observe(this._contentNode);\n\t\t}\n\t}\n\n\t_updateLayout() {\n\t\tconst container = this._contentNode,\n\t\tstyle = container.style;\n\n\t\tstyle.maxWidth = `${this.options.maxWidth}px`;\n\t\tstyle.minWidth = `${this.options.minWidth}px`;\n\n\t\tconst maxHeight = this.options.maxHeight,\n\t\tscrolledClass = 'maplair-popup-scrolled';\n\n\t\t// only measure the height (forcing a layout) if needed\n\t\tif (maxHeight && (this._containerHeight ?? container.offsetHeight) > maxHeight) {\n\t\t\tstyle.height = `${maxHeight}px`;\n\t\t\tcontainer.classList.add(scrolledClass);\n\t\t} else {\n\t\t\tcontainer.classList.remove(scrolledClass);\n\t\t}\n\n\t\tthis._containerWidth = this._container.offsetWidth;\n\t\tthis._containerHeight = this._container.offsetHeight;\n\t\t// read along with the size, so that _adjustPan doesn't force another style\n\t\t// recalculation and layout after the popup has been positioned\n\t\tthis._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center),\n\t\tanchor = this._getAnchor();\n\t\tthis._setContainerPosition(pos.add(anchor));\n\t}\n\n\t_adjustPan() {\n\t\tif (!this.options.autoPan) { return; }\n\t\tthis._map._panAnim?.stop();\n\n\t\t// We can endlessly recurse if keepInView is set and the view resets.\n\t\t// Let's guard against that by exiting early if we're responding to our own autopan.\n\t\tif (this._autopanning) {\n\t\t\tthis._autopanning = false;\n\t\t\treturn;\n\t\t}\n\n\t\tconst map = this._map,\n\t\tmarginBottom = this._containerMarginBottom ?? (parseInt(getComputedStyle(this._container).marginBottom, 10) || 0),\n\t\tcontainerHeight = this._containerHeight + marginBottom,\n\t\tcontainerWidth = this._containerWidth,\n\t\tlayerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom);\n\n\t\tlayerPos._add(this._getContainerPosition());\n\n\t\tconst containerPos = map.layerPointToContainerPoint(layerPos),\n\t\tpadding = Point.from(this.options.autoPanPadding),\n\t\tpaddingTL = Point.from(this.options.autoPanPaddingTopLeft ?? padding),\n\t\tpaddingBR = Point.from(this.options.autoPanPaddingBottomRight ?? padding),\n\t\tsize = map.getSize();\n\t\tlet dx = 0,\n\t\tdy = 0;\n\n\t\tif (containerPos.x + containerWidth + paddingBR.x > size.x) { // right\n\t\t\tdx = containerPos.x + containerWidth - size.x + paddingBR.x;\n\t\t}\n\t\tif (containerPos.x - dx - paddingTL.x < 0) { // left\n\t\t\tdx = containerPos.x - paddingTL.x;\n\t\t}\n\t\tif (containerPos.y + containerHeight + paddingBR.y > size.y) { // bottom\n\t\t\tdy = containerPos.y + containerHeight - size.y + paddingBR.y;\n\t\t}\n\t\tif (containerPos.y - dy - paddingTL.y < 0) { // top\n\t\t\tdy = containerPos.y - paddingTL.y;\n\t\t}\n\n\t\tif (dx || dy) {\n\t\t\t// Track that we're autopanning, as this function will be re-ran on moveend\n\t\t\tif (this.options.keepInView) {\n\t\t\t\tthis._autopanning = true;\n\t\t\t}\n\n\t\t\tmap\n\t\t\t\t.fire('autopanstart')\n\t\t\t\t.panBy([dx, dy]);\n\t\t}\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the popup on the source layer?\n\t\treturn new Point(this._source?._getPopupAnchor ? this._source._getPopupAnchor() : [0, 0]);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tclosePopupOnClick: true\n\t\t});\n\n\t\tMaplairMap.include(mapPopupMethods);\n\n\t\tLayer.include(layerPopupMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,MAAM,kBAAkB;;;;;;;;;;;;;;CAcvB,UAAU,OAAO,QAAQ,SAAS;EAEjC,KAAK,aAAa,OAAO,OAAO,QAAQ,OAAO,CAAC,CAC9C,OAAO,IAAI;EAEb,OAAO;CACR;;;;;;;;CASA,WAAW,OAAO;EACjB,QAAQ,UAAU,SAAS,QAAQ,KAAK;EACxC,OAAO,MAAM;EACb,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;;;;;;;;;;;;;CAazB,UAAU,SAAS,SAAS;EAE3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Q,YAChB,KAAK,eAAe;GAGrB,IACE,KAAK,cAAc,CAAC,CACpB,MAAM,CAAC,IAAI,EAAE,CAAC;EACjB;CACD;CAEA,aAAa;EAEZ,OAAO,IAAI,MAAM,KAAK,SAAS,kBAAkB,KAAK,QAAQ,gBAAgB,IAAI,CAAC,GAAG,CAAC,CAAC;CACzF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,mBAAmB,KACpB,CAAC;EAED,WAAW,QAAQ,eAAe;EAElC,MAAM,QAAQ,iBAAiB;CAChC;AACD"}
|
|
@@ -61,7 +61,7 @@ var DivIcon = class DivIcon extends Icon {
|
|
|
61
61
|
div.appendChild(options.html);
|
|
62
62
|
} else div.innerHTML = options.html !== false ? options.html : "";
|
|
63
63
|
if (options.bgPos) {
|
|
64
|
-
const bgPos =
|
|
64
|
+
const bgPos = Point.from(options.bgPos);
|
|
65
65
|
div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
|
|
66
66
|
}
|
|
67
67
|
this._setIconStyles(div, "icon");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DivIcon.js","names":[],"sources":["../../../../src/layer/marker/DivIcon.js"],"sourcesContent":["import {Icon} from './Icon.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {IconOptions} from './Icon.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n\n/**\n * Options of `DivIcon`.\n * @typedef {object} DivIconOptions\n * @property {PointExpression|number} [iconSize=[12, 12]] Size of the icon in pixels,\n * also can be set through CSS.\n * @property {string|HTMLElement|false} [html=false] Custom HTML code to put inside the\n * div element, empty by default. Alternatively, an instance of `HTMLElement`.\n * @property {PointExpression|null} [bgPos=null] Optional relative position of the\n * background, in pixels.\n * @property {string} [className='maplair-div-icon']\n * @extends IconOptions\n */\n\n/**\n * Represents a lightweight icon for markers that uses a simple `<div>`\n * element instead of an image. Inherits from `Icon` but ignores the `iconUrl` and\n * shadow options.\n *\n * By default, it has a 'maplair-div-icon' CSS class and is styled as a little white\n * square with a shadow.\n *\n * @example\n * ```js\n * const myIcon = new DivIcon({className: 'my-div-icon'});\n * // you can set .my-div-icon styles in CSS\n *\n * new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);\n * ```\n */\nexport class DivIcon extends Icon {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\ticonSize: [12, 12], // also can be set through CSS\n\n\t\t\t// iconAnchor: (Point),\n\t\t\t// popupAnchor: (Point),\n\n\t\t\thtml: false,\n\t\t\tbgPos: null,\n\t\t\tclassName: 'maplair-div-icon'\n\t\t});\n\t}\n\n\t/**\n\t * Creates a `DivIcon` instance with the given options.\n\t * @param {[options?: DivIconOptions]} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DivIcon);\n\t}\n\n\t/**\n\t * Called internally when the icon has to be shown, returns a `<div>` element\n\t * styled according to the options.\n\t * @param {HTMLElement} [oldIcon] The current element of the icon, to be reused if possible.\n\t * @returns {HTMLElement}\n\t */\n\tcreateIcon(oldIcon) {\n\t\tconst div = (oldIcon && oldIcon.tagName === 'DIV') ? oldIcon : document.createElement('div'),\n\t\toptions = this.options;\n\n\t\tif (options.html instanceof Element) {\n\t\t\tdiv.replaceChildren();\n\t\t\tdiv.appendChild(options.html);\n\t\t} else {\n\t\t\tdiv.innerHTML = options.html !== false ? options.html : '';\n\t\t}\n\n\t\tif (options.bgPos) {\n\t\t\tconst bgPos =
|
|
1
|
+
{"version":3,"file":"DivIcon.js","names":[],"sources":["../../../../src/layer/marker/DivIcon.js"],"sourcesContent":["import {Icon} from './Icon.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {IconOptions} from './Icon.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n\n/**\n * Options of `DivIcon`.\n * @typedef {object} DivIconOptions\n * @property {PointExpression|number} [iconSize=[12, 12]] Size of the icon in pixels,\n * also can be set through CSS.\n * @property {string|HTMLElement|false} [html=false] Custom HTML code to put inside the\n * div element, empty by default. Alternatively, an instance of `HTMLElement`.\n * @property {PointExpression|null} [bgPos=null] Optional relative position of the\n * background, in pixels.\n * @property {string} [className='maplair-div-icon']\n * @extends IconOptions\n */\n\n/**\n * Represents a lightweight icon for markers that uses a simple `<div>`\n * element instead of an image. Inherits from `Icon` but ignores the `iconUrl` and\n * shadow options.\n *\n * By default, it has a 'maplair-div-icon' CSS class and is styled as a little white\n * square with a shadow.\n *\n * @example\n * ```js\n * const myIcon = new DivIcon({className: 'my-div-icon'});\n * // you can set .my-div-icon styles in CSS\n *\n * new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);\n * ```\n */\nexport class DivIcon extends Icon {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\ticonSize: [12, 12], // also can be set through CSS\n\n\t\t\t// iconAnchor: (Point),\n\t\t\t// popupAnchor: (Point),\n\n\t\t\thtml: false,\n\t\t\tbgPos: null,\n\t\t\tclassName: 'maplair-div-icon'\n\t\t});\n\t}\n\n\t/**\n\t * Creates a `DivIcon` instance with the given options.\n\t * @param {[options?: DivIconOptions]} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DivIcon);\n\t}\n\n\t/**\n\t * Called internally when the icon has to be shown, returns a `<div>` element\n\t * styled according to the options.\n\t * @param {HTMLElement} [oldIcon] The current element of the icon, to be reused if possible.\n\t * @returns {HTMLElement}\n\t */\n\tcreateIcon(oldIcon) {\n\t\tconst div = (oldIcon && oldIcon.tagName === 'DIV') ? oldIcon : document.createElement('div'),\n\t\toptions = this.options;\n\n\t\tif (options.html instanceof Element) {\n\t\t\tdiv.replaceChildren();\n\t\t\tdiv.appendChild(options.html);\n\t\t} else {\n\t\t\tdiv.innerHTML = options.html !== false ? options.html : '';\n\t\t}\n\n\t\tif (options.bgPos) {\n\t\t\tconst bgPos = Point.from(options.bgPos);\n\t\t\tdiv.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;\n\t\t}\n\t\tthis._setIconStyles(div, 'icon');\n\n\t\treturn div;\n\t}\n\n\t/**\n\t * Returns `null`, a `DivIcon` has no shadow.\n\t * @returns {null}\n\t */\n\tcreateShadow() {\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,UAAb,MAAa,gBAAgB,KAAK;CAEjC;EACC,KAAK,kBAAkB;GACtB,UAAU,CAAC,IAAI,EAAE;GAKjB,MAAM;GACN,OAAO;GACP,WAAW;EACZ,CAAC;CACF;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,OAAO;CAC3B;;;;;;;CAQA,WAAW,SAAS;EACnB,MAAM,MAAO,WAAW,QAAQ,YAAY,QAAS,UAAU,SAAS,cAAc,KAAK,GAC3F,UAAU,KAAK;EAEf,IAAI,QAAQ,gBAAgB,SAAS;GACpC,IAAI,gBAAgB;GACpB,IAAI,YAAY,QAAQ,IAAI;EAC7B,OACC,IAAI,YAAY,QAAQ,SAAS,QAAQ,QAAQ,OAAO;EAGzD,IAAI,QAAQ,OAAO;GAClB,MAAM,QAAQ,MAAM,KAAK,QAAQ,KAAK;GACtC,IAAI,MAAM,qBAAqB,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;EAC1D;EACA,KAAK,eAAe,KAAK,MAAM;EAE/B,OAAO;CACR;;;;;CAMA,eAAe;EACd,OAAO;CACR;AACD"}
|
|
@@ -108,9 +108,9 @@ var Icon = class Icon extends Class {
|
|
|
108
108
|
const options = this.options;
|
|
109
109
|
let sizeOption = options[`${name}Size`];
|
|
110
110
|
if (typeof sizeOption === "number") sizeOption = [sizeOption, sizeOption];
|
|
111
|
-
const size = Point.validate(sizeOption) &&
|
|
111
|
+
const size = Point.validate(sizeOption) && Point.from(sizeOption);
|
|
112
112
|
const anchorPosition = name === "shadow" && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
|
|
113
|
-
const anchor = Point.validate(anchorPosition) &&
|
|
113
|
+
const anchor = Point.validate(anchorPosition) && Point.from(anchorPosition);
|
|
114
114
|
img.className = `maplair-marker-${name} ${options.className || ""}`;
|
|
115
115
|
if (anchor) {
|
|
116
116
|
img.style.marginLeft = `${-anchor.x}px`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","names":["Browser"],"sources":["../../../../src/layer/marker/Icon.js"],"sourcesContent":["import {Class} from '../../core/Class.js';\nimport {setOptions} from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.js';\nimport Browser from '../../core/Browser.js';\n\n/** @import {PointExpression} from '../../geometry/Point.js' */\n\n/**\n * Options of `Icon`.\n * @typedef {object} IconOptions\n * @property {string} [iconUrl] **(required)** The URL to the icon image (absolute or\n * relative to your script path).\n * @property {string} [iconRetinaUrl] The URL to a retina sized version of the icon\n * image (absolute or relative to your script path). Used for Retina screen devices.\n * @property {PointExpression|number} [iconSize] Size of the icon image in pixels (a\n * number for square icons).\n * @property {PointExpression} [iconAnchor] The coordinates of the \"tip\" of the icon\n * (relative to its top left corner). The icon will be aligned so that this point is at\n * the marker's geographical location. Centered by default if size is specified, also\n * can be set in CSS with negative margins.\n * @property {PointExpression} [popupAnchor=[0, 0]] The coordinates of the point from\n * which popups will \"open\", relative to the icon anchor.\n * @property {PointExpression} [tooltipAnchor=[0, 0]] The coordinates of the point from\n * which tooltips will \"open\", relative to the icon anchor.\n * @property {string} [shadowUrl] The URL to the icon shadow image. If not specified, no\n * shadow image will be created.\n * @property {string} [shadowRetinaUrl] The URL to a retina sized version of the shadow\n * image. Used for Retina screen devices.\n * @property {PointExpression|number} [shadowSize] Size of the shadow image in pixels.\n * @property {PointExpression} [shadowAnchor] The coordinates of the \"tip\" of the shadow\n * (relative to its top left corner) (the same as iconAnchor if not specified).\n * @property {string} [className] A custom class name to assign to both icon and shadow\n * images. Empty by default.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will\n * be added to the icon images. If a String is provided, all images will have their\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 */\n\n/**\n * Represents an icon to provide when creating a marker.\n *\n * `DefaultIcon` extends `Icon` and is the blue icon Maplair uses for markers by default.\n *\n * @example\n * ```js\n * const myIcon = new Icon({\n * iconUrl: 'my-icon.png',\n * iconRetinaUrl: 'my-icon@2x.png',\n * iconSize: [38, 95],\n * iconAnchor: [22, 94],\n * popupAnchor: [-3, -76],\n * shadowUrl: 'my-icon-shadow.png',\n * shadowRetinaUrl: 'my-icon-shadow@2x.png',\n * shadowSize: [68, 95],\n * shadowAnchor: [22, 94]\n * });\n *\n * new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);\n * ```\n */\nexport class Icon extends Class {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tpopupAnchor: [0, 0],\n\t\t\ttooltipAnchor: [0, 0],\n\t\t\tcrossOrigin: false\n\t\t});\n\t}\n\n\t/**\n\t * Creates an icon instance with the given options.\n\t * @param {IconOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tsetOptions(this, options);\n\n\t\tthis.callInitHooks(Icon);\n\t}\n\n\t/**\n\t * Called internally when the icon has to be shown, returns a `<img>` HTML element\n\t * styled according to the options.\n\t * @param {HTMLElement} [oldIcon] The current element of the icon, to be reused if possible.\n\t * @returns {HTMLElement}\n\t */\n\tcreateIcon(oldIcon) {\n\t\treturn this._createIcon('icon', oldIcon);\n\t}\n\n\t/**\n\t * As `createIcon`, but for the shadow beneath it. Returns `null` without a shadow.\n\t * @param {HTMLElement} [oldIcon] The current element of the shadow, to be reused if possible.\n\t * @returns {HTMLElement|null}\n\t */\n\tcreateShadow(oldIcon) {\n\t\treturn this._createIcon('shadow', oldIcon);\n\t}\n\n\t_createIcon(name, oldIcon) {\n\t\tconst src = this._getIconUrl(name);\n\n\t\tif (!src) {\n\t\t\tif (name === 'icon') {\n\t\t\t\tthrow new Error('iconUrl not set in Icon options (see the docs).');\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\n\t\tconst img = this._createImg(src, oldIcon && oldIcon.tagName === 'IMG' ? oldIcon : null);\n\t\tthis._setIconStyles(img, name);\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\treturn img;\n\t}\n\n\t_setIconStyles(img, name) {\n\t\tconst options = this.options;\n\t\tlet sizeOption = options[`${name}Size`];\n\n\t\tif (typeof sizeOption === 'number') {\n\t\t\tsizeOption = [sizeOption, sizeOption];\n\t\t}\n\n\t\tconst size = Point.validate(sizeOption) &&
|
|
1
|
+
{"version":3,"file":"Icon.js","names":["Browser"],"sources":["../../../../src/layer/marker/Icon.js"],"sourcesContent":["import {Class} from '../../core/Class.js';\nimport {setOptions} from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.js';\nimport Browser from '../../core/Browser.js';\n\n/** @import {PointExpression} from '../../geometry/Point.js' */\n\n/**\n * Options of `Icon`.\n * @typedef {object} IconOptions\n * @property {string} [iconUrl] **(required)** The URL to the icon image (absolute or\n * relative to your script path).\n * @property {string} [iconRetinaUrl] The URL to a retina sized version of the icon\n * image (absolute or relative to your script path). Used for Retina screen devices.\n * @property {PointExpression|number} [iconSize] Size of the icon image in pixels (a\n * number for square icons).\n * @property {PointExpression} [iconAnchor] The coordinates of the \"tip\" of the icon\n * (relative to its top left corner). The icon will be aligned so that this point is at\n * the marker's geographical location. Centered by default if size is specified, also\n * can be set in CSS with negative margins.\n * @property {PointExpression} [popupAnchor=[0, 0]] The coordinates of the point from\n * which popups will \"open\", relative to the icon anchor.\n * @property {PointExpression} [tooltipAnchor=[0, 0]] The coordinates of the point from\n * which tooltips will \"open\", relative to the icon anchor.\n * @property {string} [shadowUrl] The URL to the icon shadow image. If not specified, no\n * shadow image will be created.\n * @property {string} [shadowRetinaUrl] The URL to a retina sized version of the shadow\n * image. Used for Retina screen devices.\n * @property {PointExpression|number} [shadowSize] Size of the shadow image in pixels.\n * @property {PointExpression} [shadowAnchor] The coordinates of the \"tip\" of the shadow\n * (relative to its top left corner) (the same as iconAnchor if not specified).\n * @property {string} [className] A custom class name to assign to both icon and shadow\n * images. Empty by default.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will\n * be added to the icon images. If a String is provided, all images will have their\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 */\n\n/**\n * Represents an icon to provide when creating a marker.\n *\n * `DefaultIcon` extends `Icon` and is the blue icon Maplair uses for markers by default.\n *\n * @example\n * ```js\n * const myIcon = new Icon({\n * iconUrl: 'my-icon.png',\n * iconRetinaUrl: 'my-icon@2x.png',\n * iconSize: [38, 95],\n * iconAnchor: [22, 94],\n * popupAnchor: [-3, -76],\n * shadowUrl: 'my-icon-shadow.png',\n * shadowRetinaUrl: 'my-icon-shadow@2x.png',\n * shadowSize: [68, 95],\n * shadowAnchor: [22, 94]\n * });\n *\n * new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);\n * ```\n */\nexport class Icon extends Class {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tpopupAnchor: [0, 0],\n\t\t\ttooltipAnchor: [0, 0],\n\t\t\tcrossOrigin: false\n\t\t});\n\t}\n\n\t/**\n\t * Creates an icon instance with the given options.\n\t * @param {IconOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tsetOptions(this, options);\n\n\t\tthis.callInitHooks(Icon);\n\t}\n\n\t/**\n\t * Called internally when the icon has to be shown, returns a `<img>` HTML element\n\t * styled according to the options.\n\t * @param {HTMLElement} [oldIcon] The current element of the icon, to be reused if possible.\n\t * @returns {HTMLElement}\n\t */\n\tcreateIcon(oldIcon) {\n\t\treturn this._createIcon('icon', oldIcon);\n\t}\n\n\t/**\n\t * As `createIcon`, but for the shadow beneath it. Returns `null` without a shadow.\n\t * @param {HTMLElement} [oldIcon] The current element of the shadow, to be reused if possible.\n\t * @returns {HTMLElement|null}\n\t */\n\tcreateShadow(oldIcon) {\n\t\treturn this._createIcon('shadow', oldIcon);\n\t}\n\n\t_createIcon(name, oldIcon) {\n\t\tconst src = this._getIconUrl(name);\n\n\t\tif (!src) {\n\t\t\tif (name === 'icon') {\n\t\t\t\tthrow new Error('iconUrl not set in Icon options (see the docs).');\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\n\t\tconst img = this._createImg(src, oldIcon && oldIcon.tagName === 'IMG' ? oldIcon : null);\n\t\tthis._setIconStyles(img, name);\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\treturn img;\n\t}\n\n\t_setIconStyles(img, name) {\n\t\tconst options = this.options;\n\t\tlet sizeOption = options[`${name}Size`];\n\n\t\tif (typeof sizeOption === 'number') {\n\t\t\tsizeOption = [sizeOption, sizeOption];\n\t\t}\n\n\t\tconst size = Point.validate(sizeOption) && Point.from(sizeOption);\n\n\t\tconst anchorPosition = name === 'shadow' && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);\n\t\tconst anchor = Point.validate(anchorPosition) && Point.from(anchorPosition);\n\n\t\timg.className = `maplair-marker-${name} ${options.className || ''}`;\n\n\t\tif (anchor) {\n\t\t\timg.style.marginLeft = `${-anchor.x}px`;\n\t\t\timg.style.marginTop = `${-anchor.y}px`;\n\t\t}\n\n\t\tif (size) {\n\t\t\timg.style.width = `${size.x}px`;\n\t\t\timg.style.height = `${size.y}px`;\n\t\t}\n\t}\n\n\t_createImg(src, el) {\n\t\tel ??= document.createElement('img');\n\t\tel.src = src;\n\t\treturn el;\n\t}\n\n\t_getIconUrl(name) {\n\t\treturn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S,cAAc,KAAK,MAAM,KAAK,cAAc;EAE1E,IAAI,YAAY,kBAAkB,KAAK,GAAG,QAAQ,aAAa;EAE/D,IAAI,QAAQ;GACX,IAAI,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE;GACpC,IAAI,MAAM,YAAa,GAAG,CAAC,OAAO,EAAE;EACrC;EAEA,IAAI,MAAM;GACT,IAAI,MAAM,QAAS,GAAG,KAAK,EAAE;GAC7B,IAAI,MAAM,SAAS,GAAG,KAAK,EAAE;EAC9B;CACD;CAEA,WAAW,KAAK,IAAI;EACnB,OAAO,SAAS,cAAc,KAAK;EACnC,GAAG,MAAM;EACT,OAAO;CACR;CAEA,YAAY,MAAM;EACjB,OAAOA,gBAAQ,UAAU,KAAK,QAAQ,GAAG,KAAK,eAAe,KAAK,QAAQ,GAAG,KAAK;CACnF;AACD"}
|
|
@@ -44,7 +44,7 @@ Marker.include({
|
|
|
44
44
|
*/
|
|
45
45
|
moveAlong(latlngs, options = {}) {
|
|
46
46
|
this.stopMoving();
|
|
47
|
-
const points = [this._latlng, ...latlngs.map((latlng) =>
|
|
47
|
+
const points = [this._latlng, ...latlngs.map((latlng) => LatLng.from(latlng))], lengths = points.slice(1).map((point, i) => this._map?.distance(points[i], point) ?? points[i].distanceTo(point)), total = lengths.reduce((sum, length) => sum + length, 0), duration = options.speed ? total / options.speed * 1e3 : options.duration ?? 1e3, start = performance.now();
|
|
48
48
|
const frame = () => {
|
|
49
49
|
let distance = duration && !Browser_default.reducedMotion ? Math.min(1, (performance.now() - start) / duration) * total : total, i = 0;
|
|
50
50
|
const moved = distance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.Move.js","names":["Browser"],"sources":["../../../../src/layer/marker/Marker.Move.js"],"sourcesContent":["import {Marker} from './Marker.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Point} from '../../geometry/Point.js';\nimport Browser from '../../core/Browser.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * Options of the movement of markers, see `moveAlong()`.\n * @typedef {object} MarkerMovementOptions\n * @property {number} [duration=1000] The duration of the movement in milliseconds.\n * @property {number} [speed] The speed in meters (or units of the CRS) per second\n * instead of the `duration`.\n * @property {boolean} [rotate=false] Whether to set the `rotationAngle` of the icon to\n * the heading of the movement (for icons pointing up; needs the marker rotation, see\n * `rotationAngle`).\n */\n\n// The methods extended below\nconst {onRemove} = Marker.prototype;\n\n/**\n * Methods of `Marker` for the animated movement of markers, an optional feature: import\n * this module to add `moveTo()`, `moveAlong()`, `stopMoving()` and `isMoving()` to\n * `Marker`.\n *\n * ```js\n * import 'maplair/marker-movement';\n *\n * marker.moveAlong([[47.27, 11.40], [47.28, 11.42]], {duration: 5000});\n * ```\n *\n * Inspired by the [Leaflet.MovingMarker](https://github.com/ewoken/Leaflet.MovingMarker)\n * and [Leaflet.AnimatedMarker](https://github.com/openplans/Leaflet.AnimatedMarker) plugins.\n * @lends Marker.prototype\n * @fires Marker#moveend {MaplairEvent} Fired when the marker stops moving (after dragging\n * or `moveAlong()`).\n */\nconst markerMoveMethods = {\n\t/**\n\t * Moves the marker smoothly to `latlng`, see `moveAlong()`.\n\t * @group Marker movement\n\t * @param {LatLngExpression} latlng\n\t * @param {MarkerMovementOptions} [options]\n\t * @returns {this}\n\t */\n\tmoveTo(latlng, options) {\n\t\treturn this.moveAlong([latlng], options);\n\t},\n\n\t/**\n\t * Moves the marker smoothly along the given points, frame by frame at a constant\n\t * speed, e.g. to follow a vehicle or to replay a track. Fires `move` with each\n\t * frame and `moveend` at the end. A new movement or `stopMoving()` stops it; with\n\t * [reduced motion](https://developer.mozilla.org/docs/Web/CSS/@media/prefers-reduced-motion),\n\t * the marker jumps to the end.\n\t * Inspired by the [Leaflet.MovingMarker](https://github.com/ewoken/Leaflet.MovingMarker)\n\t * and [Leaflet.AnimatedMarker](https://github.com/openplans/Leaflet.AnimatedMarker) plugins.\n\t * @group Marker movement\n\t * @param {LatLngExpression[]} latlngs\n\t * @param {MarkerMovementOptions} [options]\n\t * @returns {this}\n\t */\n\tmoveAlong(latlngs, options = {}) {\n\t\tthis.stopMoving();\n\n\t\tconst points = [this._latlng, ...latlngs.map(latlng =>
|
|
1
|
+
{"version":3,"file":"Marker.Move.js","names":["Browser"],"sources":["../../../../src/layer/marker/Marker.Move.js"],"sourcesContent":["import {Marker} from './Marker.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Point} from '../../geometry/Point.js';\nimport Browser from '../../core/Browser.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * Options of the movement of markers, see `moveAlong()`.\n * @typedef {object} MarkerMovementOptions\n * @property {number} [duration=1000] The duration of the movement in milliseconds.\n * @property {number} [speed] The speed in meters (or units of the CRS) per second\n * instead of the `duration`.\n * @property {boolean} [rotate=false] Whether to set the `rotationAngle` of the icon to\n * the heading of the movement (for icons pointing up; needs the marker rotation, see\n * `rotationAngle`).\n */\n\n// The methods extended below\nconst {onRemove} = Marker.prototype;\n\n/**\n * Methods of `Marker` for the animated movement of markers, an optional feature: import\n * this module to add `moveTo()`, `moveAlong()`, `stopMoving()` and `isMoving()` to\n * `Marker`.\n *\n * ```js\n * import 'maplair/marker-movement';\n *\n * marker.moveAlong([[47.27, 11.40], [47.28, 11.42]], {duration: 5000});\n * ```\n *\n * Inspired by the [Leaflet.MovingMarker](https://github.com/ewoken/Leaflet.MovingMarker)\n * and [Leaflet.AnimatedMarker](https://github.com/openplans/Leaflet.AnimatedMarker) plugins.\n * @lends Marker.prototype\n * @fires Marker#moveend {MaplairEvent} Fired when the marker stops moving (after dragging\n * or `moveAlong()`).\n */\nconst markerMoveMethods = {\n\t/**\n\t * Moves the marker smoothly to `latlng`, see `moveAlong()`.\n\t * @group Marker movement\n\t * @param {LatLngExpression} latlng\n\t * @param {MarkerMovementOptions} [options]\n\t * @returns {this}\n\t */\n\tmoveTo(latlng, options) {\n\t\treturn this.moveAlong([latlng], options);\n\t},\n\n\t/**\n\t * Moves the marker smoothly along the given points, frame by frame at a constant\n\t * speed, e.g. to follow a vehicle or to replay a track. Fires `move` with each\n\t * frame and `moveend` at the end. A new movement or `stopMoving()` stops it; with\n\t * [reduced motion](https://developer.mozilla.org/docs/Web/CSS/@media/prefers-reduced-motion),\n\t * the marker jumps to the end.\n\t * Inspired by the [Leaflet.MovingMarker](https://github.com/ewoken/Leaflet.MovingMarker)\n\t * and [Leaflet.AnimatedMarker](https://github.com/openplans/Leaflet.AnimatedMarker) plugins.\n\t * @group Marker movement\n\t * @param {LatLngExpression[]} latlngs\n\t * @param {MarkerMovementOptions} [options]\n\t * @returns {this}\n\t */\n\tmoveAlong(latlngs, options = {}) {\n\t\tthis.stopMoving();\n\n\t\tconst points = [this._latlng, ...latlngs.map(latlng => LatLng.from(latlng))],\n\t\tlengths = points.slice(1).map((point, i) => this._map?.distance(points[i], point) ?? points[i].distanceTo(point)),\n\t\ttotal = lengths.reduce((sum, length) => sum + length, 0),\n\t\tduration = options.speed ? total / options.speed * 1000 : (options.duration ?? 1000),\n\t\tstart = performance.now();\n\n\t\tconst frame = () => {\n\t\t\t// the distance moved, at a constant speed\n\t\t\tlet distance = duration && !Browser.reducedMotion ? Math.min(1, (performance.now() - start) / duration) * total : total,\n\t\t\ti = 0;\n\t\t\tconst moved = distance;\n\t\t\twhile (i < lengths.length - 1 && distance > lengths[i]) {\n\t\t\t\tdistance -= lengths[i];\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tconst from = points[i], to = points[i + 1];\n\t\t\tif (options.rotate && !from.equals(to)) {\n\t\t\t\tthis.options.rotationAngle = this._heading(from, to);\n\t\t\t}\n\t\t\tthis.setLatLng(this._interpolate(from, to, lengths[i] ? Math.min(1, distance / lengths[i]) : 1));\n\n\t\t\tif (moved < total) {\n\t\t\t\tthis._moveFrame = requestAnimationFrame(frame);\n\t\t\t} else {\n\t\t\t\tthis._moveFrame = null;\n\t\t\t\tthis.fire('moveend');\n\t\t\t}\n\t\t};\n\t\tthis._moveFrame = requestAnimationFrame(frame);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Stops the movement of `moveTo()` or `moveAlong()`.\n\t * @group Marker movement\n\t * @returns {this}\n\t */\n\tstopMoving() {\n\t\tcancelAnimationFrame(this._moveFrame);\n\t\tthis._moveFrame = null;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` while the marker moves with `moveTo()` or `moveAlong()`.\n\t * @group Marker movement\n\t * @returns {boolean}\n\t */\n\tisMoving() {\n\t\treturn !!this._moveFrame;\n\t},\n\n\t// A straight line in the projection of the map (if any)\n\t_interpolate(from, to, t) {\n\t\tconst crs = this._map?.options.crs;\n\t\tif (!crs) {\n\t\t\treturn new LatLng(from.lat + (to.lat - from.lat) * t, from.lng + (to.lng - from.lng) * t);\n\t\t}\n\t\tconst a = crs.projection.project(from),\n\t\tb = crs.projection.project(to);\n\t\treturn crs.projection.unproject(a.add(b.subtract(a).multiplyBy(t)));\n\t},\n\n\t// The heading from `from` to `to` in degrees clockwise from north, relative to\n\t// the screen unless the icon rotates with the view\n\t_heading(from, to) {\n\t\tconst crs = this._map?.options.crs,\n\t\ta = crs ? crs.latLngToPoint(from, 0) : new Point(from.lng, -from.lat),\n\t\tb = crs ? crs.latLngToPoint(to, 0) : new Point(to.lng, -to.lat),\n\t\theading = Math.atan2(b.x - a.x, a.y - b.y) * 180 / Math.PI;\n\t\treturn heading - (this.options.rotateWithView ? 0 : (this._map?.getBearing?.() ?? 0));\n\t},\n\n\t/**\n\t * Stops the movement when the marker is removed from the map.\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tthis.stopMoving();\n\t\treturn onRemove.call(this, map);\n\t}\n};\n/** @typedef {typeof markerMoveMethods} MarkerMoveMethods */\n\nMarker.include(markerMoveMethods);\n"],"mappings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EACD;EACA,KAAK,aAAa,sBAAsB,KAAK;EAC7C,OAAO;CACR;;;;;;CAOA,aAAa;EACZ,qBAAqB,KAAK,UAAU;EACpC,KAAK,aAAa;EAClB,OAAO;CACR;;;;;;CAOA,WAAW;EACV,OAAO,CAAC,CAAC,KAAK;CACf;CAGA,aAAa,MAAM,IAAI,GAAG;EACzB,MAAM,MAAM,KAAK,MAAM,QAAQ;EAC/B,IAAI,CAAC,KACJ,OAAO,IAAI,OAAO,KAAK,OAAO,GAAG,MAAM,KAAK,OAAO,GAAG,KAAK,OAAO,GAAG,MAAM,KAAK,OAAO,CAAC;EAEzF,MAAM,IAAI,IAAI,WAAW,QAAQ,IAAI,GACrC,IAAI,IAAI,WAAW,QAAQ,EAAE;EAC7B,OAAO,IAAI,WAAW,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;CACnE;CAIA,SAAS,MAAM,IAAI;EAClB,MAAM,MAAM,KAAK,MAAM,QAAQ,KAC/B,IAAI,MAAM,IAAI,cAAc,MAAM,CAAC,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,KAAK,GAAG,GACpE,IAAI,MAAM,IAAI,cAAc,IAAI,CAAC,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,GAAG;EAE9D,OADU,KAAK,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,IAAI,MAAM,KAAK,MACtC,KAAK,QAAQ,iBAAiB,IAAK,KAAK,MAAM,aAAa,KAAK;CACnF;;;;;;CAOA,SAAS,KAAK;EACb,KAAK,WAAW;EAChB,OAAO,SAAS,KAAK,MAAM,GAAG;CAC/B;AAI8B,CAAC"}
|
|
@@ -369,8 +369,8 @@ var Marker = class Marker extends Layer {
|
|
|
369
369
|
const map = this._map;
|
|
370
370
|
if (!map) return;
|
|
371
371
|
const iconOpts = this.options.icon.options;
|
|
372
|
-
const size = iconOpts.iconSize ?
|
|
373
|
-
const anchor = iconOpts.iconAnchor ?
|
|
372
|
+
const size = iconOpts.iconSize ? Point.from(iconOpts.iconSize) : new Point(0, 0);
|
|
373
|
+
const anchor = iconOpts.iconAnchor ? Point.from(iconOpts.iconAnchor) : new Point(0, 0);
|
|
374
374
|
map.panInside(this._latlng, {
|
|
375
375
|
paddingTopLeft: anchor,
|
|
376
376
|
paddingBottomRight: size.subtract(anchor)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.js","names":[],"sources":["../../../../src/layer/marker/Marker.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport {DefaultIcon} from './DefaultIcon.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';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {MarkerDrag} from './Marker.Drag.js';\n/** @import {Icon} from './Icon.js' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n\n/**\n * Options of `Marker`.\n * @typedef {object} MarkerOptions\n * @property {Icon} [icon=new DefaultIcon()] Icon instance to use for rendering the\n * marker. See [Icon documentation](#Icon) for details on how to customize the marker\n * icon. If not specified, a common instance of `DefaultIcon` is used.\n * @property {boolean} [keyboard=true] Whether the marker can be tabbed to with a keyboard\n * and clicked by pressing enter.\n * @property {string} [title=''] Text for the browser tooltip that appear on marker hover\n * (no tooltip by default).\n * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).\n * @property {string} [alt='Marker'] Text for the `alt` attribute of the icon image.\n * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).\n * @property {number} [zIndexOffset=0] By default, marker images zIndex is set\n * automatically based on its latitude. Use this option if you want to put the marker on\n * top of all others (or below), specifying a high value like `1000` (or high negative\n * value, respectively).\n * @property {number} [opacity=1] The opacity of the marker.\n * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of\n * others when you hover the pointer over it.\n * @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`\n * feature.\n * @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.\n * @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will\n * be added.\n * @property {boolean} [shadow=true] Whether to show the shadow of the marker's icon. Each\n * shadow is an additional element on the page, so disabling shadows noticeably reduces\n * the browser's rendering work when showing many markers (e.g. several thousands),\n * especially while panning and zooming. To disable shadows for all markers, use\n * `Marker.mergeOptions({shadow: false})`.\n * @property {boolean} [bubblingPointerEvents=false] When `true`, a pointer event on this\n * marker will trigger the same event on the map (unless\n * [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).\n * @property {boolean} [autoPanOnFocus=true] When `true`, the map will pan whenever the\n * marker is focused (via e.g. pressing `tab` on the keyboard) to ensure the marker is\n * visible within the map's bounds.\n * @property {boolean} [draggable=false] Whether the marker is draggable with pointer or\n * not.\n * @property {boolean} [autoPan=false] Whether to pan the map when dragging this marker\n * near its edge or not.\n * @property {PointExpression} [autoPanPadding=[50, 50]] Distance (in pixels to the\n * left/right and to the top/bottom) of the map edge to start panning the map.\n * @property {number} [autoPanSpeed=10] Number of pixels the map should pan by.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * The event object of `move` and `drag` of markers.\n * @typedef {object} MarkerMoveEvent\n * @property {LatLng} latlng The new position of the marker.\n * @property {LatLng} [oldLatLng] The previous position of the marker.\n * @extends MaplairEvent\n */\n\n/**\n * Marker is used to display clickable/draggable icons on the map. Extends `Layer`.\n *\n * In addition to [shared layer methods](#Layer) like `addTo()` and `remove()` and\n * [popup methods](#Popup) like `bindPopup()` you can also use the methods below.\n *\n * @example\n * ```js\n * new Marker([50.5, 30.5]).addTo(map);\n * ```\n *\n * @fires move {MarkerMoveEvent} Fired when the marker is moved via\n * [`setLatLng`](#marker-setlatlng) or by [dragging](#marker-dragging). Old and new\n * coordinates are included in event arguments as `oldLatLng`, `latlng`.\n */\nexport class Marker extends Layer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\ticon: new DefaultIcon(),\n\n\t\t\t// Option inherited from \"Interactive layer\" abstract class\n\t\t\tinteractive: true,\n\n\t\t\tkeyboard: true,\n\t\t\ttitle: '',\n\t\t\talt: 'Marker',\n\t\t\tzIndexOffset: 0,\n\t\t\topacity: 1,\n\t\t\triseOnHover: false,\n\t\t\triseOffset: 250,\n\t\t\tpane: 'markerPane',\n\t\t\tshadowPane: 'shadowPane',\n\t\t\tshadow: true,\n\t\t\tbubblingPointerEvents: false,\n\t\t\tautoPanOnFocus: true,\n\t\t\tdraggable: false,\n\t\t\tautoPan: false,\n\t\t\tautoPanPadding: [50, 50],\n\t\t\tautoPanSpeed: 10\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a Marker object given a geographical point and optionally an options\n\t * object.\n\t * @param {LatLngExpression} latlng\n\t * @param {MarkerOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._latlng = new LatLng(latlng);\n\n\t\tthis.callInitHooks(Marker);\n\t}\n\n\t/**\n\t * Adds the icon (and shadow) of the marker to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._zoomAnimated = this._zoomAnimated && map.options.markerZoomAnimation;\n\n\t\tif (this._zoomAnimated) {\n\t\t\tmap.on('zoomanim', this._animateZoom, this);\n\t\t}\n\n\t\tthis._initIcon();\n\t\tthis.update();\n\n\t\tif (map.options.markerCulling) {\n\t\t\tthis._updateCulling();\n\t\t}\n\t}\n\n\t/**\n\t * Removes the icon (and shadow) of the marker from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.dragging?.enabled()) {\n\t\t\tthis.options.draggable = true;\n\t\t\tthis.dragging.removeHooks();\n\t\t}\n\t\tdelete this.dragging;\n\n\t\tif (this._zoomAnimated) {\n\t\t\tmap.off('zoomanim', this._animateZoom, this);\n\t\t}\n\n\t\tthis._removeIcon();\n\t\tthis._removeShadow();\n\t\tthis._culled = false;\n\t}\n\n\t/**\n\t * Returns the map events the marker listens to, see `Layer`.\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this.update,\n\t\t\tviewreset: this.update\n\t\t};\n\t\tif (this._map?.options.markerCulling) {\n\t\t\tevents.moveend = this._updateCulling;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns the current geographical position of the marker.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Changes the marker position to the given point.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map?.options.markerCulling) {\n\t\t\tthis._updateCulling();\n\t\t}\n\t\tthis.update();\n\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t/**\n\t * Changes the [zIndex offset](#markeroptions-zindexoffset) of the marker.\n\t * @param {number} offset\n\t * @returns {this}\n\t */\n\tsetZIndexOffset(offset) {\n\t\tthis.options.zIndexOffset = offset;\n\t\treturn this.update();\n\t}\n\n\t/**\n\t * Returns the current icon used by the marker.\n\t * @returns {Icon}\n\t */\n\tgetIcon() {\n\t\treturn this.options.icon;\n\t}\n\n\t/**\n\t * Changes the marker icon.\n\t * @param {Icon} icon\n\t * @returns {this}\n\t */\n\tsetIcon(icon) {\n\n\t\tthis.options.icon = icon;\n\n\t\tif (this._map) {\n\t\t\tthis._initIcon();\n\t\t\tthis.update();\n\t\t}\n\n\t\tif (this._popup) {\n\t\t\tthis.bindPopup(this._popup, this._popup.options);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the instance of [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement)\n\t * used by Marker layer.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._icon;\n\t}\n\n\t/**\n\t * Updates the position of the marker on the map, e.g. after a change of its options.\n\t * @returns {this}\n\t */\n\tupdate() {\n\n\t\tif (this._icon && this._map && !this._culled) {\n\t\t\tconst pos = this._map.latLngToLayerPoint(this._latlng).round();\n\t\t\tthis._setPos(pos);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t_initIcon() {\n\t\tconst options = this.options,\n\t\tclassToAdd = `maplair-zoom-${this._zoomAnimated ? 'animated' : 'hide'}`;\n\n\t\tconst icon = options.icon.createIcon(this._icon);\n\t\tlet addIcon = false;\n\n\t\t// if we're not reusing the icon, remove the old one and init new one\n\t\tif (icon !== this._icon) {\n\t\t\tif (this._icon) {\n\t\t\t\tthis._removeIcon();\n\t\t\t}\n\t\t\taddIcon = true;\n\n\t\t\tif (options.title) {\n\t\t\t\ticon.title = options.title;\n\t\t\t}\n\n\t\t\tif (icon.tagName === 'IMG') {\n\t\t\t\ticon.alt = options.alt ?? '';\n\t\t\t}\n\t\t}\n\n\t\ticon.classList.add(classToAdd);\n\n\t\tif (options.keyboard) {\n\t\t\ticon.tabIndex = '0';\n\t\t\ticon.setAttribute('role', 'button');\n\t\t}\n\n\t\tthis._icon = icon;\n\n\t\tif (options.riseOnHover) {\n\t\t\tthis.on({\n\t\t\t\tpointerover: this._bringToFront,\n\t\t\t\tpointerout: this._resetZIndex\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.autoPanOnFocus) {\n\t\t\tDomEvent.on(icon, 'focus', this._panOnFocus, this);\n\t\t}\n\n\t\tconst newShadow = options.shadow ? options.icon.createShadow(this._shadow) : null;\n\t\tlet addShadow = false;\n\n\t\tif (newShadow !== this._shadow) {\n\t\t\tthis._removeShadow();\n\t\t\taddShadow = true;\n\t\t}\n\n\t\tif (newShadow) {\n\t\t\tnewShadow.classList.add(classToAdd);\n\t\t\tnewShadow.alt = '';\n\t\t}\n\t\tthis._shadow = newShadow;\n\n\n\t\tif (options.opacity < 1) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\n\n\t\tif (addIcon) {\n\t\t\tthis.getPane().appendChild(this._icon);\n\t\t}\n\t\tthis._initInteraction();\n\t\tif (newShadow && addShadow) {\n\t\t\tthis.getPane(options.shadowPane).appendChild(this._shadow);\n\t\t}\n\t}\n\n\t_removeIcon() {\n\t\tif (this.options.riseOnHover) {\n\t\t\tthis.off({\n\t\t\t\tpointerover: this._bringToFront,\n\t\t\t\tpointerout: this._resetZIndex\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.autoPanOnFocus) {\n\t\t\tDomEvent.off(this._icon, 'focus', this._panOnFocus, this);\n\t\t}\n\n\t\tthis._icon.remove();\n\t\tthis.removeInteractiveTarget(this._icon);\n\n\t\tthis._icon = null;\n\t}\n\n\t// With the map's `markerCulling` option, takes the icon and shadow of a marker\n\t// far outside of the map view off the page (and puts them back when needed),\n\t// so that the browser doesn't need to render, and the marker doesn't need\n\t// to reposition, them while panning and zooming.\n\t_updateCulling() {\n\t\tif (!this._icon || !this._map) { return; }\n\n\t\tconst visible = this._map.getBounds().pad(0.5).contains(this._latlng) ||\n\t\t\t!!this.dragging?._draggable?._moving ||\n\t\t\tthis._icon.contains(document.activeElement);\n\n\t\tif (visible === !this._culled) { return; }\n\t\tthis._culled = !visible;\n\n\t\tif (visible) {\n\t\t\tthis.getPane().appendChild(this._icon);\n\t\t\tif (this._shadow) {\n\t\t\t\tthis.getPane(this.options.shadowPane).appendChild(this._shadow);\n\t\t\t}\n\t\t\tthis.update();\n\t\t} else {\n\t\t\tthis._icon.remove();\n\t\t\tthis._shadow?.remove();\n\t\t}\n\t}\n\n\t_removeShadow() {\n\t\tthis._shadow?.remove();\n\t\tthis._shadow = null;\n\t}\n\n\t_setPos(pos) {\n\n\t\tif (this._icon) {\n\t\t\tDomUtil.setPosition(this._icon, pos);\n\t\t}\n\n\t\tif (this._shadow) {\n\t\t\tDomUtil.setPosition(this._shadow, pos);\n\t\t}\n\n\t\tthis._zIndex = pos.y + this.options.zIndexOffset;\n\n\t\tthis._resetZIndex();\n\t}\n\n\t_updateZIndex(offset) {\n\t\tconst zIndex = String(this._zIndex + offset);\n\t\tif (this._icon && this._icon.style.zIndex !== zIndex) {\n\t\t\tthis._icon.style.zIndex = zIndex;\n\t\t}\n\t}\n\n\t_animateZoom(opt) {\n\t\tif (this._culled) { return; }\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).round();\n\n\t\tthis._setPos(pos);\n\t}\n\n\t_updateInteractive() {\n\t\tif (!this._icon) { return; }\n\t\tif (this.options.interactive) {\n\t\t\tthis._initInteraction();\n\t\t\tif (this._draggableBeforeNonInteractive) {\n\t\t\t\tthis.dragging?.enable();\n\t\t\t}\n\t\t} else {\n\t\t\tthis._icon.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._icon);\n\t\t\tthis._draggableBeforeNonInteractive = this.dragging?.enabled();\n\t\t\tthis.dragging?.disable();\n\t\t}\n\t}\n\n\t_initInteraction() {\n\n\t\tif (!this.options.interactive) { return; }\n\n\t\tthis._icon.classList.add('maplair-interactive');\n\n\t\tthis.addInteractiveTarget(this._icon);\n\n\t\tif (MarkerDrag) {\n\t\t\tlet draggable = this.options.draggable;\n\t\t\tif (this.dragging) {\n\t\t\t\tdraggable = this.dragging.enabled();\n\t\t\t\tthis.dragging.disable();\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Marker dragging handler, see `Handler`. Only valid when the marker is on the\n\t\t\t * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).\n\t\t\t *\n\t\t\t * Interaction handlers are properties of a marker instance that allow you to\n\t\t\t * control interaction behavior in runtime, enabling or disabling certain\n\t\t\t * features such as dragging (see `Handler` methods). Example:\n\t\t\t *\n\t\t\t * ```js\n\t\t\t * marker.dragging.disable();\n\t\t\t * ```\n\t\t\t * @group Interaction handlers\n\t\t\t * @type {MarkerDrag}\n\t\t\t */\n\t\t\tthis.dragging = new MarkerDrag(this);\n\n\t\t\tif (draggable) {\n\t\t\t\tthis.dragging.enable();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Changes the opacity of the marker.\n\t * @param {number} opacity\n\t * @returns {this}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\t\tif (this._map) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t_updateOpacity() {\n\t\tconst opacity = this.options.opacity;\n\n\t\tif (this._icon) {\n\t\t\tthis._icon.style.opacity = opacity;\n\t\t}\n\n\t\tif (this._shadow) {\n\t\t\tthis._shadow.style.opacity = opacity;\n\t\t}\n\t}\n\n\t_bringToFront() {\n\t\tthis._updateZIndex(this.options.riseOffset);\n\t}\n\n\t_resetZIndex() {\n\t\tthis._updateZIndex(0);\n\t}\n\n\t_panOnFocus() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; }\n\n\t\tconst iconOpts = this.options.icon.options;\n\t\tconst size = iconOpts.iconSize ? new Point(iconOpts.iconSize) : new Point(0, 0);\n\t\tconst anchor = iconOpts.iconAnchor ? new Point(iconOpts.iconAnchor) : new Point(0, 0);\n\n\t\tmap.panInside(this._latlng, {\n\t\t\tpaddingTopLeft: anchor,\n\t\t\tpaddingBottomRight: size.subtract(anchor)\n\t\t});\n\t}\n\n\t_getPopupAnchor() {\n\t\treturn this.options.icon.options.popupAnchor;\n\t}\n\n\t_getTooltipAnchor() {\n\t\treturn this.options.icon.options.tooltipAnchor;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,IAAa,SAAb,MAAa,eAAe,MAAM;CAEjC;EACC,KAAK,kBAAkB;GACtB,MAAM,IAAI,YAAY;GAGtB,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S;EACnB,KAAK,QAAQ,UAAU;EACvB,IAAI,KAAK,MACR,KAAK,eAAe;EAGrB,OAAO;CACR;CAEA,iBAAiB;EAChB,MAAM,UAAU,KAAK,QAAQ;EAE7B,IAAI,KAAK,OACR,KAAK,MAAM,MAAM,UAAU;EAG5B,IAAI,KAAK,SACR,KAAK,QAAQ,MAAM,UAAU;CAE/B;CAEA,gBAAgB;EACf,KAAK,cAAc,KAAK,QAAQ,UAAU;CAC3C;CAEA,eAAe;EACd,KAAK,cAAc,CAAC;CACrB;CAEA,cAAc;EACb,MAAM,MAAM,KAAK;EACjB,IAAI,CAAC,KAAO;EAEZ,MAAM,WAAW,KAAK,QAAQ,KAAK;EACnC,MAAM,OAAO,SAAS,WAAW,IAAI,MAAM,SAAS,QAAQ,IAAI,IAAI,MAAM,GAAG,CAAC;EAC9E,MAAM,SAAS,SAAS,aAAa,IAAI,MAAM,SAAS,UAAU,IAAI,IAAI,MAAM,GAAG,CAAC;EAEpF,IAAI,UAAU,KAAK,SAAS;GAC3B,gBAAgB;GAChB,oBAAoB,KAAK,SAAS,MAAM;EACzC,CAAC;CACF;CAEA,kBAAkB;EACjB,OAAO,KAAK,QAAQ,KAAK,QAAQ;CAClC;CAEA,oBAAoB;EACnB,OAAO,KAAK,QAAQ,KAAK,QAAQ;CAClC;AACD"}
|
|
1
|
+
{"version":3,"file":"Marker.js","names":[],"sources":["../../../../src/layer/marker/Marker.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport {DefaultIcon} from './DefaultIcon.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';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {MarkerDrag} from './Marker.Drag.js';\n/** @import {Icon} from './Icon.js' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n\n/**\n * Options of `Marker`.\n * @typedef {object} MarkerOptions\n * @property {Icon} [icon=new DefaultIcon()] Icon instance to use for rendering the\n * marker. See [Icon documentation](#Icon) for details on how to customize the marker\n * icon. If not specified, a common instance of `DefaultIcon` is used.\n * @property {boolean} [keyboard=true] Whether the marker can be tabbed to with a keyboard\n * and clicked by pressing enter.\n * @property {string} [title=''] Text for the browser tooltip that appear on marker hover\n * (no tooltip by default).\n * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).\n * @property {string} [alt='Marker'] Text for the `alt` attribute of the icon image.\n * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).\n * @property {number} [zIndexOffset=0] By default, marker images zIndex is set\n * automatically based on its latitude. Use this option if you want to put the marker on\n * top of all others (or below), specifying a high value like `1000` (or high negative\n * value, respectively).\n * @property {number} [opacity=1] The opacity of the marker.\n * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of\n * others when you hover the pointer over it.\n * @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`\n * feature.\n * @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.\n * @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will\n * be added.\n * @property {boolean} [shadow=true] Whether to show the shadow of the marker's icon. Each\n * shadow is an additional element on the page, so disabling shadows noticeably reduces\n * the browser's rendering work when showing many markers (e.g. several thousands),\n * especially while panning and zooming. To disable shadows for all markers, use\n * `Marker.mergeOptions({shadow: false})`.\n * @property {boolean} [bubblingPointerEvents=false] When `true`, a pointer event on this\n * marker will trigger the same event on the map (unless\n * [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).\n * @property {boolean} [autoPanOnFocus=true] When `true`, the map will pan whenever the\n * marker is focused (via e.g. pressing `tab` on the keyboard) to ensure the marker is\n * visible within the map's bounds.\n * @property {boolean} [draggable=false] Whether the marker is draggable with pointer or\n * not.\n * @property {boolean} [autoPan=false] Whether to pan the map when dragging this marker\n * near its edge or not.\n * @property {PointExpression} [autoPanPadding=[50, 50]] Distance (in pixels to the\n * left/right and to the top/bottom) of the map edge to start panning the map.\n * @property {number} [autoPanSpeed=10] Number of pixels the map should pan by.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * The event object of `move` and `drag` of markers.\n * @typedef {object} MarkerMoveEvent\n * @property {LatLng} latlng The new position of the marker.\n * @property {LatLng} [oldLatLng] The previous position of the marker.\n * @extends MaplairEvent\n */\n\n/**\n * Marker is used to display clickable/draggable icons on the map. Extends `Layer`.\n *\n * In addition to [shared layer methods](#Layer) like `addTo()` and `remove()` and\n * [popup methods](#Popup) like `bindPopup()` you can also use the methods below.\n *\n * @example\n * ```js\n * new Marker([50.5, 30.5]).addTo(map);\n * ```\n *\n * @fires move {MarkerMoveEvent} Fired when the marker is moved via\n * [`setLatLng`](#marker-setlatlng) or by [dragging](#marker-dragging). Old and new\n * coordinates are included in event arguments as `oldLatLng`, `latlng`.\n */\nexport class Marker extends Layer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\ticon: new DefaultIcon(),\n\n\t\t\t// Option inherited from \"Interactive layer\" abstract class\n\t\t\tinteractive: true,\n\n\t\t\tkeyboard: true,\n\t\t\ttitle: '',\n\t\t\talt: 'Marker',\n\t\t\tzIndexOffset: 0,\n\t\t\topacity: 1,\n\t\t\triseOnHover: false,\n\t\t\triseOffset: 250,\n\t\t\tpane: 'markerPane',\n\t\t\tshadowPane: 'shadowPane',\n\t\t\tshadow: true,\n\t\t\tbubblingPointerEvents: false,\n\t\t\tautoPanOnFocus: true,\n\t\t\tdraggable: false,\n\t\t\tautoPan: false,\n\t\t\tautoPanPadding: [50, 50],\n\t\t\tautoPanSpeed: 10\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a Marker object given a geographical point and optionally an options\n\t * object.\n\t * @param {LatLngExpression} latlng\n\t * @param {MarkerOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._latlng = new LatLng(latlng);\n\n\t\tthis.callInitHooks(Marker);\n\t}\n\n\t/**\n\t * Adds the icon (and shadow) of the marker to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._zoomAnimated = this._zoomAnimated && map.options.markerZoomAnimation;\n\n\t\tif (this._zoomAnimated) {\n\t\t\tmap.on('zoomanim', this._animateZoom, this);\n\t\t}\n\n\t\tthis._initIcon();\n\t\tthis.update();\n\n\t\tif (map.options.markerCulling) {\n\t\t\tthis._updateCulling();\n\t\t}\n\t}\n\n\t/**\n\t * Removes the icon (and shadow) of the marker from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.dragging?.enabled()) {\n\t\t\tthis.options.draggable = true;\n\t\t\tthis.dragging.removeHooks();\n\t\t}\n\t\tdelete this.dragging;\n\n\t\tif (this._zoomAnimated) {\n\t\t\tmap.off('zoomanim', this._animateZoom, this);\n\t\t}\n\n\t\tthis._removeIcon();\n\t\tthis._removeShadow();\n\t\tthis._culled = false;\n\t}\n\n\t/**\n\t * Returns the map events the marker listens to, see `Layer`.\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this.update,\n\t\t\tviewreset: this.update\n\t\t};\n\t\tif (this._map?.options.markerCulling) {\n\t\t\tevents.moveend = this._updateCulling;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns the current geographical position of the marker.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Changes the marker position to the given point.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map?.options.markerCulling) {\n\t\t\tthis._updateCulling();\n\t\t}\n\t\tthis.update();\n\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t/**\n\t * Changes the [zIndex offset](#markeroptions-zindexoffset) of the marker.\n\t * @param {number} offset\n\t * @returns {this}\n\t */\n\tsetZIndexOffset(offset) {\n\t\tthis.options.zIndexOffset = offset;\n\t\treturn this.update();\n\t}\n\n\t/**\n\t * Returns the current icon used by the marker.\n\t * @returns {Icon}\n\t */\n\tgetIcon() {\n\t\treturn this.options.icon;\n\t}\n\n\t/**\n\t * Changes the marker icon.\n\t * @param {Icon} icon\n\t * @returns {this}\n\t */\n\tsetIcon(icon) {\n\n\t\tthis.options.icon = icon;\n\n\t\tif (this._map) {\n\t\t\tthis._initIcon();\n\t\t\tthis.update();\n\t\t}\n\n\t\tif (this._popup) {\n\t\t\tthis.bindPopup(this._popup, this._popup.options);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the instance of [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement)\n\t * used by Marker layer.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._icon;\n\t}\n\n\t/**\n\t * Updates the position of the marker on the map, e.g. after a change of its options.\n\t * @returns {this}\n\t */\n\tupdate() {\n\n\t\tif (this._icon && this._map && !this._culled) {\n\t\t\tconst pos = this._map.latLngToLayerPoint(this._latlng).round();\n\t\t\tthis._setPos(pos);\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t_initIcon() {\n\t\tconst options = this.options,\n\t\tclassToAdd = `maplair-zoom-${this._zoomAnimated ? 'animated' : 'hide'}`;\n\n\t\tconst icon = options.icon.createIcon(this._icon);\n\t\tlet addIcon = false;\n\n\t\t// if we're not reusing the icon, remove the old one and init new one\n\t\tif (icon !== this._icon) {\n\t\t\tif (this._icon) {\n\t\t\t\tthis._removeIcon();\n\t\t\t}\n\t\t\taddIcon = true;\n\n\t\t\tif (options.title) {\n\t\t\t\ticon.title = options.title;\n\t\t\t}\n\n\t\t\tif (icon.tagName === 'IMG') {\n\t\t\t\ticon.alt = options.alt ?? '';\n\t\t\t}\n\t\t}\n\n\t\ticon.classList.add(classToAdd);\n\n\t\tif (options.keyboard) {\n\t\t\ticon.tabIndex = '0';\n\t\t\ticon.setAttribute('role', 'button');\n\t\t}\n\n\t\tthis._icon = icon;\n\n\t\tif (options.riseOnHover) {\n\t\t\tthis.on({\n\t\t\t\tpointerover: this._bringToFront,\n\t\t\t\tpointerout: this._resetZIndex\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.autoPanOnFocus) {\n\t\t\tDomEvent.on(icon, 'focus', this._panOnFocus, this);\n\t\t}\n\n\t\tconst newShadow = options.shadow ? options.icon.createShadow(this._shadow) : null;\n\t\tlet addShadow = false;\n\n\t\tif (newShadow !== this._shadow) {\n\t\t\tthis._removeShadow();\n\t\t\taddShadow = true;\n\t\t}\n\n\t\tif (newShadow) {\n\t\t\tnewShadow.classList.add(classToAdd);\n\t\t\tnewShadow.alt = '';\n\t\t}\n\t\tthis._shadow = newShadow;\n\n\n\t\tif (options.opacity < 1) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\n\n\t\tif (addIcon) {\n\t\t\tthis.getPane().appendChild(this._icon);\n\t\t}\n\t\tthis._initInteraction();\n\t\tif (newShadow && addShadow) {\n\t\t\tthis.getPane(options.shadowPane).appendChild(this._shadow);\n\t\t}\n\t}\n\n\t_removeIcon() {\n\t\tif (this.options.riseOnHover) {\n\t\t\tthis.off({\n\t\t\t\tpointerover: this._bringToFront,\n\t\t\t\tpointerout: this._resetZIndex\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.autoPanOnFocus) {\n\t\t\tDomEvent.off(this._icon, 'focus', this._panOnFocus, this);\n\t\t}\n\n\t\tthis._icon.remove();\n\t\tthis.removeInteractiveTarget(this._icon);\n\n\t\tthis._icon = null;\n\t}\n\n\t// With the map's `markerCulling` option, takes the icon and shadow of a marker\n\t// far outside of the map view off the page (and puts them back when needed),\n\t// so that the browser doesn't need to render, and the marker doesn't need\n\t// to reposition, them while panning and zooming.\n\t_updateCulling() {\n\t\tif (!this._icon || !this._map) { return; }\n\n\t\tconst visible = this._map.getBounds().pad(0.5).contains(this._latlng) ||\n\t\t\t!!this.dragging?._draggable?._moving ||\n\t\t\tthis._icon.contains(document.activeElement);\n\n\t\tif (visible === !this._culled) { return; }\n\t\tthis._culled = !visible;\n\n\t\tif (visible) {\n\t\t\tthis.getPane().appendChild(this._icon);\n\t\t\tif (this._shadow) {\n\t\t\t\tthis.getPane(this.options.shadowPane).appendChild(this._shadow);\n\t\t\t}\n\t\t\tthis.update();\n\t\t} else {\n\t\t\tthis._icon.remove();\n\t\t\tthis._shadow?.remove();\n\t\t}\n\t}\n\n\t_removeShadow() {\n\t\tthis._shadow?.remove();\n\t\tthis._shadow = null;\n\t}\n\n\t_setPos(pos) {\n\n\t\tif (this._icon) {\n\t\t\tDomUtil.setPosition(this._icon, pos);\n\t\t}\n\n\t\tif (this._shadow) {\n\t\t\tDomUtil.setPosition(this._shadow, pos);\n\t\t}\n\n\t\tthis._zIndex = pos.y + this.options.zIndexOffset;\n\n\t\tthis._resetZIndex();\n\t}\n\n\t_updateZIndex(offset) {\n\t\tconst zIndex = String(this._zIndex + offset);\n\t\tif (this._icon && this._icon.style.zIndex !== zIndex) {\n\t\t\tthis._icon.style.zIndex = zIndex;\n\t\t}\n\t}\n\n\t_animateZoom(opt) {\n\t\tif (this._culled) { return; }\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).round();\n\n\t\tthis._setPos(pos);\n\t}\n\n\t_updateInteractive() {\n\t\tif (!this._icon) { return; }\n\t\tif (this.options.interactive) {\n\t\t\tthis._initInteraction();\n\t\t\tif (this._draggableBeforeNonInteractive) {\n\t\t\t\tthis.dragging?.enable();\n\t\t\t}\n\t\t} else {\n\t\t\tthis._icon.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._icon);\n\t\t\tthis._draggableBeforeNonInteractive = this.dragging?.enabled();\n\t\t\tthis.dragging?.disable();\n\t\t}\n\t}\n\n\t_initInteraction() {\n\n\t\tif (!this.options.interactive) { return; }\n\n\t\tthis._icon.classList.add('maplair-interactive');\n\n\t\tthis.addInteractiveTarget(this._icon);\n\n\t\tif (MarkerDrag) {\n\t\t\tlet draggable = this.options.draggable;\n\t\t\tif (this.dragging) {\n\t\t\t\tdraggable = this.dragging.enabled();\n\t\t\t\tthis.dragging.disable();\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * Marker dragging handler, see `Handler`. Only valid when the marker is on the\n\t\t\t * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).\n\t\t\t *\n\t\t\t * Interaction handlers are properties of a marker instance that allow you to\n\t\t\t * control interaction behavior in runtime, enabling or disabling certain\n\t\t\t * features such as dragging (see `Handler` methods). Example:\n\t\t\t *\n\t\t\t * ```js\n\t\t\t * marker.dragging.disable();\n\t\t\t * ```\n\t\t\t * @group Interaction handlers\n\t\t\t * @type {MarkerDrag}\n\t\t\t */\n\t\t\tthis.dragging = new MarkerDrag(this);\n\n\t\t\tif (draggable) {\n\t\t\t\tthis.dragging.enable();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Changes the opacity of the marker.\n\t * @param {number} opacity\n\t * @returns {this}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\t\tif (this._map) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t_updateOpacity() {\n\t\tconst opacity = this.options.opacity;\n\n\t\tif (this._icon) {\n\t\t\tthis._icon.style.opacity = opacity;\n\t\t}\n\n\t\tif (this._shadow) {\n\t\t\tthis._shadow.style.opacity = opacity;\n\t\t}\n\t}\n\n\t_bringToFront() {\n\t\tthis._updateZIndex(this.options.riseOffset);\n\t}\n\n\t_resetZIndex() {\n\t\tthis._updateZIndex(0);\n\t}\n\n\t_panOnFocus() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; }\n\n\t\tconst iconOpts = this.options.icon.options;\n\t\tconst size = iconOpts.iconSize ? Point.from(iconOpts.iconSize) : new Point(0, 0);\n\t\tconst anchor = iconOpts.iconAnchor ? Point.from(iconOpts.iconAnchor) : new Point(0, 0);\n\n\t\tmap.panInside(this._latlng, {\n\t\t\tpaddingTopLeft: anchor,\n\t\t\tpaddingBottomRight: size.subtract(anchor)\n\t\t});\n\t}\n\n\t_getPopupAnchor() {\n\t\treturn this.options.icon.options.popupAnchor;\n\t}\n\n\t_getTooltipAnchor() {\n\t\treturn this.options.icon.options.tooltipAnchor;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoFA,IAAa,SAAb,MAAa,eAAe,MAAM;CAEjC;EACC,KAAK,kBAAkB;GACtB,MAAM,IAAI,YAAY;GAGtB,aAAa;GAEb,UAAU;GACV,OAAO;GACP,KAAK;GACL,cAAc;GACd,SAAS;GACT,aAAa;GACb,YAAY;GACZ,MAAM;GACN,YAAY;GACZ,QAAQ;GACR,uBAAuB;GACvB,gBAAgB;GAChB,WAAW;GACX,SAAS;GACT,gBAAgB,CAAC,IAAI,EAAE;GACvB,cAAc;EACf,CAAC;CACF;;;;;;;CAQA,YAAY,QAAQ,SAAS;EAC5B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,UAAU,IAAI,OAAO,MAAM;EAEhC,KAAK,cAAc,MAAM;CAC1B;;;;;CAMA,MAAM,KAAK;EACV,KAAK,gBAAgB,KAAK,iBAAiB,IAAI,QAAQ;EAEvD,IAAI,KAAK,eACR,IAAI,GAAG,YAAY,KAAK,cAAc,IAAI;EAG3C,KAAK,UAAU;EACf,KAAK,OAAO;EAEZ,IAAI,IAAI,QAAQ,eACf,KAAK,eAAe;CAEtB;;;;;CAMA,SAAS,KAAK;EACb,IAAI,KAAK,UAAU,QAAQ,GAAG;GAC7B,KAAK,QAAQ,YAAY;GACzB,K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ACzC,CAAC;CACF;CAEA,kBAAkB;EACjB,OAAO,KAAK,QAAQ,KAAK,QAAQ;CAClC;CAEA,oBAAoB;EACnB,OAAO,KAAK,QAAQ,KAAK,QAAQ;CAClC;AACD"}
|
|
@@ -578,7 +578,7 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
578
578
|
}
|
|
579
579
|
if (!this.options.bounds) return true;
|
|
580
580
|
const tileBounds = this._tileCoordsToBounds(coords);
|
|
581
|
-
return
|
|
581
|
+
return LatLngBounds.from(this.options.bounds).overlaps(tileBounds);
|
|
582
582
|
}
|
|
583
583
|
_keyToBounds(key) {
|
|
584
584
|
return this._tileCoordsToBounds(this._keyToTileCoords(key));
|