maplair 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/dist/esm/control/AttributionControl.js +20 -3
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +35 -20
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +3 -3
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +1 -0
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Util.js +1 -1
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +19 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/Draggable.js +6 -2
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +1 -1
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +1 -1
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +1 -1
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +4 -2
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +10 -3
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +2 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +3 -3
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +1 -1
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +1 -1
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +3 -4
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +31 -22
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +25 -6
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +5 -5
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +5 -5
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +11 -5
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +10 -6
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +2 -2
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +2 -3
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +6 -3
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +3 -2
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +58 -26
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -1
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +7 -2
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +289 -140
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +289 -140
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/package.json +1 -1
- package/src/control/AttributionControl.js +29 -3
- package/src/control/LayersControl.js +47 -27
- package/src/control/ScaleControl.js +6 -3
- package/src/control/ZoomControl.js +1 -0
- package/src/core/Util.js +1 -1
- package/src/dom/DomEvent.PointerEvents.js +22 -2
- package/src/dom/Draggable.js +6 -2
- package/src/geo/LatLng.js +2 -1
- package/src/geo/LatLngBounds.js +1 -1
- package/src/geometry/Bounds.js +1 -1
- package/src/geometry/Point.js +4 -2
- package/src/geometry/PolyUtil.js +12 -3
- package/src/layer/BlanketOverlay.js +5 -2
- package/src/layer/DivOverlay.js +3 -3
- package/src/layer/ImageOverlay.js +3 -2
- package/src/layer/Layer.js +1 -1
- package/src/layer/Popup.js +3 -4
- package/src/layer/Tooltip.js +34 -27
- package/src/layer/marker/Icon.js +25 -5
- package/src/layer/marker/Marker.Drag.js +6 -6
- package/src/layer/marker/Marker.js +5 -5
- package/src/layer/tile/GridLayer.js +20 -7
- package/src/layer/tile/TileLayer.js +14 -7
- package/src/layer/tile/WMSTileLayer.js +4 -2
- package/src/layer/vector/Canvas.js +2 -2
- package/src/layer/vector/Circle.js +3 -5
- package/src/layer/vector/CircleMarker.js +5 -2
- package/src/layer/vector/Path.ZoomStyles.js +5 -3
- package/src/map/Map.Rotation.js +6 -3
- package/src/map/Map.js +63 -32
- package/src/map/MapSync.js +1 -1
- package/src/map/handler/BoxZoomHandler.js +3 -0
- package/src/map/handler/DragHandler.js +5 -5
- package/src/map/handler/PinchZoomHandler.js +1 -1
- package/src/map/handler/ScrollWheelZoomHandler.js +1 -1
- package/src/map/handler/TapDragZoomHandler.js +1 -1
- package/src/maplair.css +12 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","names":["DomEvent.off","DomEvent.on","DomUtil.create","Util.stamp"],"sources":["../../../src/layer/Tooltip.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as Util from '../core/Util.js';\nimport {FeatureGroup} from './FeatureGroup.js';\n\n// which point of the tooltip (as a fraction of its width and height) sits at the anchor, for each direction\nconst directions = {top: [0.5, 1], bottom: [0.5, 0], center: [0.5, 0.5], right: [0, 0.5], left: [1, 0.5]};\n\n// The size of the tooltip tip (see `.maplair-tooltip-top` etc. in maplair.css) and\n// the minimum distance of an `auto` tooltip to the edge of the map.\nconst tipSize = 6,\nautoPadding = 4;\n\n// The shift moving a box from `start` with `size` into the range `[min, max]`.\nfunction shiftInto(start, size, min, max) {\n\treturn Math.max(0, min - start) - Math.max(0, start + size - max);\n}\n\n// Keeps the shifted tip off the rounded corners of the tooltip.\nfunction clampTip(tipShift, size) {\n\tconst max = Math.max(0, size / 2 - 2 * tipSize);\n\treturn Math.round(Math.min(max, Math.max(-max, tipShift)));\n}\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, TooltipEvent} from '../core/Events.js' */\n\n/**\n * Options of `Tooltip`.\n * @typedef {object} TooltipOptions\n * @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.\n * @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position.\n * @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']\n * Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,\n * `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when\n * opening the tooltip: preferably the side towards the center of the map (`right` or\n * `left`), otherwise the opposite side, `top` or `bottom`. The tooltip is shifted\n * along that side to stay within the map (within the viewport if `overflow` is set),\n * its tip still pointing at the source.\n * @property {boolean} [permanent=false] Whether to open the tooltip permanently or only\n * on pointerover.\n * @property {boolean} [sticky=false] If true, the tooltip will follow the pointer\n * instead of being fixed at the feature center.\n * @property {number} [opacity=0.9] Tooltip container opacity.\n * @extends DivOverlayOptions\n */\n\n/**\n * Methods of `MaplairMap` for tooltips.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#tooltipopen {TooltipEvent} Fired when a tooltip is opened in the map.\n * @fires MaplairMap#tooltipclose {TooltipEvent} Fired when a tooltip in the map is closed.\n */\nconst mapTooltipMethods = {\n\t/**\n\t * Opens the specified tooltip.\n\t *\n\t * Alternatively, creates a tooltip with the specified content and options and\n\t * opens it. String content is rendered as HTML; sanitize untrusted input or pass\n\t * an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Tooltip|DivOverlayContent} tooltip The tooltip, or the content of a new\n\t * tooltip.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {TooltipOptions} [options]\n\t * @returns {this}\n\t */\n\topenTooltip(tooltip, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Tooltip, tooltip, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the tooltip given as parameter.\n\t * @group Methods for layers and controls\n\t * @param {Tooltip} tooltip\n\t * @returns {this}\n\t */\n\tcloseTooltip(tooltip) {\n\t\ttooltip.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapTooltipMethods} MapTooltipMethods */\n\n/**\n * Methods of `Layer` for tooltips. All layers share a set of methods convenient for\n * binding tooltips to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindTooltip('Hi There!').addTo(map);\n * layer.openTooltip();\n * layer.closeTooltip();\n * ```\n *\n * @lends Layer.prototype\n * @fires Layer#tooltipopen {TooltipEvent} Fired when a tooltip bound to this layer is\n * opened.\n * @fires Layer#tooltipclose {TooltipEvent} Fired when a tooltip bound to this layer is\n * closed.\n */\nconst layerTooltipMethods = {\n\t/**\n\t * Binds a tooltip to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an\n\t * `HTMLElement` with safe `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String`, `HTMLElement` or `DocumentFragment`.\n\t * @group Tooltip methods\n\t * @param {DivOverlayContent|Tooltip} content\n\t * @param {TooltipOptions} [options]\n\t * @returns {this}\n\t */\n\tbindTooltip(content, options) {\n\t\t// an open tooltip is replaced, a closed one reused\n\t\tconst old = this.isTooltipOpen() ? null : this._tooltip;\n\n\t\t// the handlers depend on the old options, so they go before the new ones are applied\n\t\tif (this._tooltip) {\n\t\t\tthis.unbindTooltip();\n\t\t}\n\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._tooltip = this._initOverlay(Tooltip, old, content, options);\n\t\tthis._initTooltipInteractions();\n\n\t\tif (this._tooltip.options.permanent && this._map?.hasLayer(this)) {\n\t\t\tthis.openTooltip();\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the tooltip previously bound with `bindTooltip`.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\tunbindTooltip() {\n\t\tif (this._tooltip) {\n\t\t\tthis._initTooltipInteractions(true);\n\t\t\tthis.closeTooltip();\n\t\t\tthis._tooltip = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t_initTooltipInteractions(remove) {\n\t\tconst {permanent, sticky} = this._tooltip.options,\n\t\tevents = {\n\t\t\tremove: this.closeTooltip,\n\t\t\tmove: this._moveTooltip\n\t\t};\n\t\tif (permanent) {\n\t\t\tevents.add = this._openTooltip;\n\t\t} else {\n\t\t\tevents.pointerover = this._openTooltip;\n\t\t\tevents.pointerout = this.closeTooltip;\n\t\t\tevents.click = this._openTooltip;\n\t\t\t// layer elements can be recreated on every add\n\t\t\tevents.add = this._toggleFocusListeners;\n\t\t\tif (this._map) {\n\t\t\t\tthis._toggleFocusListeners(!remove);\n\t\t\t}\n\t\t}\n\t\tif (sticky) {\n\t\t\tevents.pointermove = this._moveTooltip;\n\t\t}\n\t\tthis[remove ? 'off' : 'on'](events);\n\t},\n\n\t/**\n\t * Opens the bound tooltip at the specified `latlng` or at the default tooltip\n\t * anchor if no `latlng` is passed.\n\t * @group Tooltip methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenTooltip(latlng) {\n\t\tif (this._tooltip) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._tooltip._source = this;\n\t\t\t}\n\t\t\tif (this._tooltip._prepareOpen(latlng)) {\n\t\t\t\t// open the tooltip on the map\n\t\t\t\tthis._tooltip.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the tooltip bound to this layer if it is open.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\tcloseTooltip() {\n\t\tthis._tooltip?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the tooltip bound to this layer depending on its current state.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\ttoggleTooltip() {\n\t\tthis._tooltip?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the tooltip bound to this layer is currently open.\n\t * @group Tooltip methods\n\t * @returns {boolean}\n\t */\n\tisTooltipOpen() {\n\t\treturn this._tooltip?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the tooltip bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Tooltip methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetTooltipContent(content) {\n\t\tthis._tooltip?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the tooltip bound to this layer.\n\t * @group Tooltip methods\n\t * @returns {Tooltip|undefined}\n\t */\n\tgetTooltip() {\n\t\treturn this._tooltip;\n\t},\n\n\t// also the `add` listener, so any truthy argument adds\n\t_toggleFocusListeners(add) {\n\t\tif (this.getElement) {\n\t\t\tthis._addFocusListenersOnLayer(this, !add);\n\t\t} else if (this.eachLayer) {\n\t\t\tthis.eachLayer(layer => this._addFocusListenersOnLayer(layer, !add), this);\n\t\t}\n\t},\n\n\t_addFocusListenersOnLayer(layer, remove) {\n\t\tconst el = typeof layer.getElement === 'function' && layer.getElement();\n\t\tif (el) {\n\t\t\tconst toggle = remove ? DomEvent.off : DomEvent.on;\n\t\t\tif (!remove) {\n\t\t\t\t// Remove focus listener, if already existing\n\t\t\t\tel._maplair_focus_handler && DomEvent.off(el, 'focus', el._maplair_focus_handler, this);\n\n\t\t\t\t// open only on keyboard focus: an element clicked with the mouse keeps focus and gets it again whenever\n\t\t\t\t// the window is refocused or a popup closes, which would open the tooltip without the pointer over it\n\t\t\t\tel._maplair_focus_handler = () => {\n\t\t\t\t\tif (this._tooltip && el.matches(':focus-visible')) {\n\t\t\t\t\t\tthis._tooltip._source = layer;\n\t\t\t\t\t\tthis.openTooltip();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tel._maplair_focus_handler && toggle(el, 'focus', el._maplair_focus_handler, this);\n\t\t\ttoggle(el, 'blur', this.closeTooltip, this);\n\n\t\t\tif (remove) {\n\t\t\t\tdelete el._maplair_focus_handler;\n\t\t\t}\n\t\t}\n\t},\n\n\t_openTooltip(e) {\n\t\tif (!this._tooltip || !this._map) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the map is moving, we will show the tooltip after it's done.\n\t\tif (this._map.dragging?.moving()) {\n\t\t\tif (e.type === 'add' && !this._moveEndOpensTooltip) {\n\t\t\t\tthis._moveEndOpensTooltip = true;\n\t\t\t\tthis._map.once('moveend', () => {\n\t\t\t\t\tthis._moveEndOpensTooltip = false;\n\t\t\t\t\tthis._openTooltip(e);\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tthis._tooltip._source = e.propagatedFrom ?? e.target;\n\n\t\tthis.openTooltip(this._tooltip.options.sticky ? e.latlng : undefined);\n\t},\n\n\t_moveTooltip(e) {\n\t\tthis._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ?\n\t\t\tthis._map.pointerEventToLatLng(e.originalEvent) : e.latlng);\n\t}\n};\n/** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */\n\n/**\n * Used to display small texts on top of map layers.\n *\n * @example\n * If you want to just bind a tooltip to marker:\n *\n * ```js\n * marker.bindTooltip(\"my tooltip text\").openTooltip();\n * ```\n * Path overlays like polylines also have a `bindTooltip` method.\n *\n * A tooltip can be also standalone:\n *\n * ```js\n * const tooltip = new Tooltip()\n * \t.setLatLng(latlng)\n * \t.setContent('Hello world!<br />This is a nice tooltip.')\n * \t.addTo(map);\n * ```\n * or\n * ```js\n * const tooltip = new Tooltip(latlng, {content: 'Hello world!<br />This is a nice tooltip.'})\n * \t.addTo(map);\n * ```\n *\n * **Security note.** Tooltip string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or\n * build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindTooltip(el);\n * ```\n *\n * Note about tooltip offset. Maplair takes two options in consideration\n * for computing tooltip offsetting:\n * - the `offset` Tooltip option: it defaults to [0, 0], and it's specific to one tooltip.\n * Add a positive x offset to move the tooltip to the right, and a positive y offset to\n * move it to the bottom. Negatives will move to the left and top.\n * - the `tooltipAnchor` Icon option: this will only be considered for Marker. You\n * should adapt this value if you use a custom icon.\n */\nexport class Tooltip extends DivOverlay {\n\n\tstatic defaultOptions = {\n\t\tpane: 'tooltipPane',\n\t\toffset: [0, 0],\n\t\tdirection: 'auto',\n\t\tpermanent: false,\n\t\tsticky: false,\n\t\topacity: 0.9\n\t};\n\n\t/**\n\t * Instantiates a `Tooltip` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the tooltip with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {TooltipOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Tooltip` object given `latlng` where the tooltip will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {TooltipOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Tooltip);\n\t}\n\n\t/**\n\t * Adds the tooltip to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\t\tthis.setOpacity(this.options.opacity);\n\n\t\tmap.fire('tooltipopen', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.addEventParent(this._source);\n\t\t\tthis._source.getElement?.()?.setAttribute('aria-describedby', this._container.id);\n\n\t\t\tthis._source.fire('tooltipopen', {tooltip: this}, true);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the tooltip from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('tooltipclose', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.removeEventParent(this._source);\n\n\t\t\tthis._source.fire('tooltipclose', {tooltip: this}, true);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the tooltip listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (!this.options.permanent) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-tooltip',\n\t\tclassName = `${prefix} ${this.options.className || ''} maplair-zoom-animated`;\n\n\t\tthis._contentNode = this._container = DomUtil.create('div', className);\n\n\t\tthis._container.setAttribute('role', 'tooltip');\n\t\tthis._container.id = `maplair-tooltip-${Util.stamp(this)}`;\n\t}\n\n\t_updateLayout() {}\n\n\t_adjustPan() {}\n\n\t/**\n\t * Updates the tooltip content, layout and position.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\t// The automatic direction is chosen once per opening and content, so that\n\t\t// the tooltip does not flip sides while the map or the pointer moves.\n\t\tthis._autoDirection = undefined;\n\t\tsuper.update();\n\t}\n\n\t_setPosition(pos) {\n\t\tlet direction = this.options.direction,\n\t\tshift = new Point(0, 0);\n\t\tconst container = this._container,\n\t\ttooltipWidth = container.offsetWidth,\n\t\ttooltipHeight = container.offsetHeight,\n\t\toffset = new Point(this.options.offset),\n\t\tanchor = this._getAnchor();\n\n\t\tif (!(direction in directions)) {\n\t\t\t({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));\n\t\t\tif (direction === 'left') {\n\t\t\t\t// mirror the offset and anchor, which are meant for the right side\n\t\t\t\toffset.x = -offset.x;\n\t\t\t\tanchor.x = -anchor.x;\n\t\t\t}\n\t\t}\n\n\t\tconst [fx, fy] = directions[direction];\n\t\tpos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);\n\n\t\tfor (const d in directions) {\n\t\t\tcontainer.classList.toggle(`maplair-tooltip-${d}`, d === direction);\n\t\t}\n\n\t\t// Let the tip point at the source despite the shift\n\t\tconst tipShift = direction === 'top' || direction === 'bottom' ?\n\t\t\tclampTip(-shift.x, tooltipWidth) :\n\t\t\tclampTip(-shift.y, tooltipHeight);\n\t\tif (tipShift) {\n\t\t\tcontainer.style.setProperty('--maplair-tooltip-tip-shift', `${tipShift}px`);\n\t\t} else {\n\t\t\tcontainer.style.removeProperty('--maplair-tooltip-tip-shift');\n\t\t}\n\n\t\tthis._setContainerPosition(pos);\n\t}\n\n\t// Chooses the direction of an `auto` tooltip by the available space:\n\t// preferably the side towards the center, otherwise the opposite side,\n\t// above or below. The tooltip is shifted along that side to stay in view.\n\t_getAutoPlacement(pos, offset, anchor, width, height) {\n\t\tconst area = this._getAutoArea(),\n\t\tpoint = this._map.layerPointToContainerPoint(pos),\n\t\tx = point.x + offset.x + anchor.x,\n\t\ty = point.y + offset.y + anchor.y,\n\t\t// the space for each direction, see `direction` for the mirrored left side\n\t\tspace = {\n\t\t\tright: area.max.x - x - width - tipSize,\n\t\t\tleft: point.x - offset.x - anchor.x - area.min.x - width - tipSize,\n\t\t\ttop: y - area.min.y - height - tipSize,\n\t\t\tbottom: area.max.y - y - height - tipSize\n\t\t};\n\n\t\tif (!this._autoDirection) {\n\t\t\tconst sides = point.x < (area.min.x + area.max.x) / 2 ? ['right', 'left'] : ['left', 'right'],\n\t\t\tfallback = space.right >= space.left ? 'right' : 'left';\n\t\t\tthis._autoDirection = [...sides, 'top', 'bottom'].find(d => space[d] >= 0 &&\n\t\t\t\t// above or below, the tooltip has to fit horizontally\n\t\t\t\t(d === 'right' || d === 'left' || width <= area.max.x - area.min.x)) ?? fallback;\n\t\t}\n\n\t\tconst direction = this._autoDirection,\n\t\tshift = direction === 'top' || direction === 'bottom' ?\n\t\t\tnew Point(shiftInto(x - width / 2, width, area.min.x, area.max.x), 0) :\n\t\t\tnew Point(0, shiftInto(y - height / 2, height, area.min.y, area.max.y));\n\n\t\treturn {direction, shift};\n\t}\n\n\t// The area in container points an `auto` tooltip should stay within:\n\t// the map, or the viewport for an overflowing tooltip.\n\t_getAutoArea() {\n\t\tconst map = this._map;\n\t\tlet min = new Point(0, 0),\n\t\tmax = map.getSize();\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = map._container,\n\t\t\trect = mapContainer.getBoundingClientRect(),\n\t\t\torigin = new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop),\n\t\t\tviewport = document.documentElement;\n\t\t\tmin = min.subtract(origin);\n\t\t\tmax = new Point(viewport.clientWidth, viewport.clientHeight).subtract(origin);\n\t\t}\n\t\tconst padding = new Point(autoPadding, autoPadding);\n\t\treturn {min: min.add(padding), max: max.subtract(padding)};\n\t}\n\n\t_updatePosition() {\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng)._round();\n\t\tthis._setPosition(pos);\n\t}\n\n\t/**\n\t * Sets the opacity of the tooltip.\n\t * @param {number} opacity\n\t * @returns {void}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._container) {\n\t\t\tthis._container.style.opacity = `${opacity}`;\n\t\t}\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);\n\t\tthis._setPosition(pos);\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the tooltip on the source layer?\n\t\treturn new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapTooltipMethods);\n\n\t\tLayer.include(layerTooltipMethods);\n\t}\n}\n"],"mappings":";;;;;;;;AASA,MAAM,aAAa;CAAC,KAAK,CAAC,IAAK,CAAC;CAAG,QAAQ,CAAC,IAAK,CAAC;CAAG,QAAQ,CAAC,IAAK,EAAG;CAAG,OAAO,CAAC,GAAG,EAAG;CAAG,MAAM,CAAC,GAAG,EAAG;AAAC;AAIxG,MAAM,UAAU;AAChB,MAAA,cAAc;AAGd,SAAS,UAAU,OAAO,MAAM,KAAK,KAAK;CACzC,OAAO,KAAK,IAAI,GAAG,MAAM,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AC3B,WAAW,QAAQ,iBAAiB;EAEpC,MAAM,QAAQ,mBAAmB;CAClC;AACD"}
|
|
1
|
+
{"version":3,"file":"Tooltip.js","names":["DomEvent.off","DomEvent.on","DomUtil.create","Util.stamp"],"sources":["../../../src/layer/Tooltip.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as Util from '../core/Util.js';\nimport {FeatureGroup} from './FeatureGroup.js';\n\n// which point of the tooltip (as a fraction of its width and height) sits at the anchor, for each direction\nconst directions = {top: [0.5, 1], bottom: [0.5, 0], center: [0.5, 0.5], right: [0, 0.5], left: [1, 0.5]};\n\n// The size of the tooltip tip (see `.maplair-tooltip-top` etc. in maplair.css) and\n// the minimum distance of an `auto` tooltip to the edge of the map.\nconst tipSize = 6,\nautoPadding = 4;\n\n// The shift moving a box from `start` with `size` into the range `[min, max]`.\nfunction shiftInto(start, size, min, max) {\n\treturn Math.max(0, min - start) - Math.max(0, start + size - max);\n}\n\n// Keeps the shifted tip off the rounded corners of the tooltip.\nfunction clampTip(tipShift, size) {\n\tconst max = Math.max(0, size / 2 - 2 * tipSize);\n\treturn Math.round(Math.min(max, Math.max(-max, tipShift)));\n}\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, TooltipEvent} from '../core/Events.js' */\n\n/**\n * Options of `Tooltip`.\n * @typedef {object} TooltipOptions\n * @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.\n * @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position, in\n * pixels. Mirrored horizontally when an `auto` tooltip opens to the left.\n * @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']\n * Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,\n * `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when\n * opening the tooltip: preferably the side towards the center of the map (`right` or\n * `left`), otherwise the opposite side, `top` or `bottom`. The tooltip is shifted\n * along that side to stay within the map (within the viewport if `overflow` is set),\n * its tip still pointing at the source.\n * @property {boolean} [permanent=false] Whether to open the tooltip permanently or only\n * on pointerover.\n * @property {boolean} [sticky=false] If true, the tooltip will follow the pointer\n * instead of being fixed at the feature center.\n * @property {number} [opacity=0.9] Tooltip container opacity.\n * @extends DivOverlayOptions\n */\n\n/**\n * Methods of `MaplairMap` for tooltips.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#tooltipopen {TooltipEvent} Fired when a tooltip is opened in the map.\n * @fires MaplairMap#tooltipclose {TooltipEvent} Fired when a tooltip in the map is closed.\n */\nconst mapTooltipMethods = {\n\t/**\n\t * Opens the specified tooltip.\n\t *\n\t * Alternatively, creates a tooltip with the specified content and options and\n\t * opens it. String content is rendered as HTML; sanitize untrusted input or pass\n\t * an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Tooltip|DivOverlayContent} tooltip The tooltip, or the content of a new\n\t * tooltip.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {TooltipOptions} [options]\n\t * @returns {this}\n\t */\n\topenTooltip(tooltip, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Tooltip, tooltip, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the tooltip given as parameter.\n\t * @group Methods for layers and controls\n\t * @param {Tooltip} tooltip\n\t * @returns {this}\n\t */\n\tcloseTooltip(tooltip) {\n\t\ttooltip.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapTooltipMethods} MapTooltipMethods */\n\n/**\n * Methods of `Layer` for tooltips. All layers share a set of methods convenient for\n * binding tooltips to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindTooltip('Hi There!').addTo(map);\n * layer.openTooltip();\n * layer.closeTooltip();\n * ```\n *\n * @lends Layer.prototype\n * @fires Layer#tooltipopen {TooltipEvent} Fired when a tooltip bound to this layer is\n * opened.\n * @fires Layer#tooltipclose {TooltipEvent} Fired when a tooltip bound to this layer is\n * closed.\n */\nconst layerTooltipMethods = {\n\t/**\n\t * Binds a tooltip to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it or pass an `HTMLElement` with safe\n\t * `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String`, `HTMLElement` or `DocumentFragment`.\n\t * @group Tooltip methods\n\t * @param {DivOverlayContent|Tooltip} content\n\t * @param {TooltipOptions} [options]\n\t * @returns {this}\n\t */\n\tbindTooltip(content, options) {\n\t\t// an open tooltip is replaced, a closed one reused\n\t\tconst old = this.isTooltipOpen() ? null : this._tooltip;\n\n\t\t// the handlers depend on the old options, so they go before the new ones are applied\n\t\tif (this._tooltip) {\n\t\t\tthis.unbindTooltip();\n\t\t}\n\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._tooltip = this._initOverlay(Tooltip, old, content, options);\n\t\tthis._initTooltipInteractions();\n\n\t\tif (this._tooltip.options.permanent && this._map?.hasLayer(this)) {\n\t\t\tthis.openTooltip();\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the tooltip previously bound with `bindTooltip`.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\tunbindTooltip() {\n\t\tif (this._tooltip) {\n\t\t\tthis._initTooltipInteractions(true);\n\t\t\tthis.closeTooltip();\n\t\t\tthis._tooltip = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t_initTooltipInteractions(remove) {\n\t\tconst {permanent, sticky} = this._tooltip.options,\n\t\tevents = {\n\t\t\tremove: this.closeTooltip,\n\t\t\tmove: this._moveTooltip\n\t\t};\n\t\tif (permanent) {\n\t\t\tevents.add = this._openTooltip;\n\t\t} else {\n\t\t\tevents.pointerover = this._openTooltip;\n\t\t\tevents.pointerout = this.closeTooltip;\n\t\t\tevents.click = this._openTooltip;\n\t\t\t// layer elements can be recreated on every add\n\t\t\tevents.add = this._toggleFocusListeners;\n\t\t\tif (this._map) {\n\t\t\t\tthis._toggleFocusListeners(!remove);\n\t\t\t}\n\t\t}\n\t\tif (sticky) {\n\t\t\tevents.pointermove = this._moveTooltip;\n\t\t}\n\t\tthis[remove ? 'off' : 'on'](events);\n\t},\n\n\t/**\n\t * Opens the bound tooltip at the specified `latlng` or at the default tooltip\n\t * anchor if no `latlng` is passed.\n\t * @group Tooltip methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenTooltip(latlng) {\n\t\tif (this._tooltip) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._tooltip._source = this;\n\t\t\t}\n\t\t\tif (this._tooltip._prepareOpen(latlng)) {\n\t\t\t\t// open the tooltip on the map\n\t\t\t\tthis._tooltip.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the tooltip bound to this layer if it is open.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\tcloseTooltip() {\n\t\tthis._tooltip?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the tooltip bound to this layer depending on its current state.\n\t * @group Tooltip methods\n\t * @returns {this}\n\t */\n\ttoggleTooltip() {\n\t\tthis._tooltip?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the tooltip bound to this layer is currently open.\n\t * @group Tooltip methods\n\t * @returns {boolean}\n\t */\n\tisTooltipOpen() {\n\t\treturn this._tooltip?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the tooltip bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Tooltip methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetTooltipContent(content) {\n\t\tthis._tooltip?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the tooltip bound to this layer.\n\t * @group Tooltip methods\n\t * @returns {Tooltip|undefined}\n\t */\n\tgetTooltip() {\n\t\treturn this._tooltip;\n\t},\n\n\t// also the `add` listener, so any truthy argument adds\n\t_toggleFocusListeners(add) {\n\t\tif (this.getElement) {\n\t\t\tthis._addFocusListenersOnLayer(this, !add);\n\t\t} else if (this.eachLayer) {\n\t\t\tthis.eachLayer(layer => this._addFocusListenersOnLayer(layer, !add), this);\n\t\t}\n\t},\n\n\t_addFocusListenersOnLayer(layer, remove) {\n\t\tconst el = typeof layer.getElement === 'function' && layer.getElement();\n\t\tif (el) {\n\t\t\tconst toggle = remove ? DomEvent.off : DomEvent.on;\n\t\t\tif (!remove) {\n\t\t\t\t// Remove focus listener, if already existing\n\t\t\t\tel._maplair_focus_handler && DomEvent.off(el, 'focus', el._maplair_focus_handler, this);\n\n\t\t\t\t// open only on keyboard focus: an element clicked with the mouse keeps focus and gets it again whenever\n\t\t\t\t// the window is refocused or a popup closes, which would open the tooltip without the pointer over it\n\t\t\t\tel._maplair_focus_handler = () => {\n\t\t\t\t\tif (this._tooltip && el.matches(':focus-visible')) {\n\t\t\t\t\t\tthis._tooltip._source = layer;\n\t\t\t\t\t\tthis.openTooltip();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tel._maplair_focus_handler && toggle(el, 'focus', el._maplair_focus_handler, this);\n\t\t\ttoggle(el, 'blur', this.closeTooltip, this);\n\n\t\t\tif (remove) {\n\t\t\t\tdelete el._maplair_focus_handler;\n\t\t\t}\n\t\t}\n\t},\n\n\t_openTooltip(e) {\n\t\tif (!this._tooltip || !this._map) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the map is moving, we will show the tooltip after it's done.\n\t\tif (this._map.dragging?.moving()) {\n\t\t\tif (e.type === 'add' && !this._moveEndOpensTooltip) {\n\t\t\t\tthis._moveEndOpensTooltip = true;\n\t\t\t\tthis._map.once('moveend', () => {\n\t\t\t\t\tthis._moveEndOpensTooltip = false;\n\t\t\t\t\tthis._openTooltip(e);\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tthis._tooltip._source = e.propagatedFrom ?? e.target;\n\n\t\tthis.openTooltip(this._tooltip.options.sticky ? e.latlng : undefined);\n\t},\n\n\t_moveTooltip(e) {\n\t\tthis._tooltip.setLatLng(this._tooltip.options.sticky && e.originalEvent ?\n\t\t\tthis._map.pointerEventToLatLng(e.originalEvent) : e.latlng);\n\t}\n};\n/** @typedef {typeof layerTooltipMethods} LayerTooltipMethods */\n\n/**\n * Used to display small texts on top of map layers.\n *\n * @example\n * If you want to just bind a tooltip to marker:\n *\n * ```js\n * marker.bindTooltip(\"my tooltip text\").openTooltip();\n * ```\n * Path overlays like polylines also have a `bindTooltip` method.\n *\n * A tooltip can be also standalone:\n *\n * ```js\n * const tooltip = new Tooltip()\n * \t.setLatLng(latlng)\n * \t.setContent('Hello world!<br />This is a nice tooltip.')\n * \t.addTo(map);\n * ```\n * or\n * ```js\n * const tooltip = new Tooltip(latlng, {content: 'Hello world!<br />This is a nice tooltip.'})\n * \t.addTo(map);\n * ```\n *\n * **Security note.** Tooltip string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it first, or build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindTooltip(el);\n * ```\n *\n * Note about tooltip offset. Maplair takes two options in consideration\n * for computing tooltip offsetting:\n * - the `offset` Tooltip option: it defaults to [0, 0], and it's specific to one tooltip.\n * Add a positive x offset to move the tooltip to the right, and a positive y offset to\n * move it to the bottom. Negatives will move to the left and top.\n * - the `tooltipAnchor` Icon option: this will only be considered for Marker. You\n * should adapt this value if you use a custom icon.\n */\nexport class Tooltip extends DivOverlay {\n\n\tstatic defaultOptions = {\n\t\tpane: 'tooltipPane',\n\t\toffset: [0, 0],\n\t\tdirection: 'auto',\n\t\tpermanent: false,\n\t\tsticky: false,\n\t\topacity: 0.9\n\t};\n\n\t/**\n\t * Instantiates a `Tooltip` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the tooltip with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {TooltipOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Tooltip` object given `latlng` where the tooltip will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {TooltipOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Tooltip);\n\t}\n\n\t/**\n\t * Adds the tooltip to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\t\tthis.setOpacity(this.options.opacity);\n\n\t\tmap.fire('tooltipopen', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.addEventParent(this._source);\n\t\t\tthis._ariaSource = this._source.getElement?.();\n\t\t\tthis._ariaSource?.setAttribute('aria-describedby', this._container.id);\n\n\t\t\tthis._source.fire('tooltipopen', {tooltip: this}, true);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the tooltip from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('tooltipclose', {tooltip: this});\n\n\t\tif (this._source) {\n\t\t\tthis.removeEventParent(this._source);\n\n\t\t\t// drop the reference to the removed tooltip unless something else replaced it since\n\t\t\tconst el = this._ariaSource;\n\t\t\tif (el?.getAttribute('aria-describedby') === this._container.id) { el.removeAttribute('aria-describedby'); }\n\t\t\tthis._ariaSource = null;\n\n\t\t\tthis._source.fire('tooltipclose', {tooltip: this}, true);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the tooltip listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (!this.options.permanent) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-tooltip',\n\t\tclassName = `${prefix} ${this.options.className || ''} maplair-zoom-animated`;\n\n\t\tthis._contentNode = this._container = DomUtil.create('div', className);\n\n\t\tthis._container.setAttribute('role', 'tooltip');\n\t\tthis._container.id = `maplair-tooltip-${Util.stamp(this)}`;\n\t}\n\n\t_updateLayout() {}\n\n\t_adjustPan() {}\n\n\t/**\n\t * Updates the tooltip content, layout and position.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\t// The automatic direction is chosen once per opening and content, so that\n\t\t// the tooltip does not flip sides while the map or the pointer moves.\n\t\tthis._autoDirection = undefined;\n\t\tsuper.update();\n\t}\n\n\t_setPosition(pos) {\n\t\tlet direction = this.options.direction,\n\t\tshift = new Point(0, 0);\n\t\tconst container = this._container,\n\t\ttooltipWidth = container.offsetWidth,\n\t\ttooltipHeight = container.offsetHeight,\n\t\toffset = new Point(this.options.offset);\n\n\t\tif (!(direction in directions)) {\n\t\t\t({direction, shift} = this._getAutoPlacement(pos, offset, tooltipWidth, tooltipHeight));\n\t\t\t// mirror the offset, which is meant for the right side\n\t\t\tif (direction === 'left') { offset.x = -offset.x; }\n\t\t}\n\t\tconst anchor = this._getAnchor(direction);\n\n\t\tconst [fx, fy] = directions[direction];\n\t\tpos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);\n\n\t\tfor (const d in directions) {\n\t\t\tcontainer.classList.toggle(`maplair-tooltip-${d}`, d === direction);\n\t\t}\n\n\t\t// Let the tip point at the source despite the shift\n\t\tconst tipShift = direction === 'top' || direction === 'bottom' ?\n\t\t\tclampTip(-shift.x, tooltipWidth) :\n\t\t\tclampTip(-shift.y, tooltipHeight);\n\t\tif (tipShift) {\n\t\t\tcontainer.style.setProperty('--maplair-tooltip-tip-shift', `${tipShift}px`);\n\t\t} else {\n\t\t\tcontainer.style.removeProperty('--maplair-tooltip-tip-shift');\n\t\t}\n\n\t\tthis._setContainerPosition(pos);\n\t}\n\n\t// Chooses the direction of an `auto` tooltip by the available space:\n\t// preferably the side towards the center, otherwise the opposite side,\n\t// above or below. The tooltip is shifted along that side to stay in view.\n\t_getAutoPlacement(pos, offset, width, height) {\n\t\tconst area = this._getAutoArea(),\n\t\tpoint = this._map.layerPointToContainerPoint(pos),\n\t\t// where the tooltip attaches for each direction, with the offset mirrored on the left side\n\t\tat = {};\n\t\tfor (const d of ['right', 'left', 'top', 'bottom']) {\n\t\t\tat[d] = point.add(this._getAnchor(d)).add(d === 'left' ? [-offset.x, offset.y] : offset);\n\t\t}\n\t\t// the space for each direction\n\t\tconst space = {\n\t\t\tright: area.max.x - at.right.x - width - tipSize,\n\t\t\tleft: at.left.x - area.min.x - width - tipSize,\n\t\t\ttop: at.top.y - area.min.y - height - tipSize,\n\t\t\tbottom: area.max.y - at.bottom.y - height - tipSize\n\t\t};\n\n\t\tif (!this._autoDirection) {\n\t\t\tconst sides = point.x < (area.min.x + area.max.x) / 2 ? ['right', 'left'] : ['left', 'right'],\n\t\t\tfallback = space.right >= space.left ? 'right' : 'left';\n\t\t\tthis._autoDirection = [...sides, 'top', 'bottom'].find(d => space[d] >= 0 &&\n\t\t\t\t// above or below, the tooltip has to fit horizontally\n\t\t\t\t(d === 'right' || d === 'left' || width <= area.max.x - area.min.x)) ?? fallback;\n\t\t}\n\n\t\tconst direction = this._autoDirection,\n\t\t{x, y} = at[direction],\n\t\tshift = direction === 'top' || direction === 'bottom' ?\n\t\t\tnew Point(shiftInto(x - width / 2, width, area.min.x, area.max.x), 0) :\n\t\t\tnew Point(0, shiftInto(y - height / 2, height, area.min.y, area.max.y));\n\n\t\treturn {direction, shift};\n\t}\n\n\t// The area in container points an `auto` tooltip should stay within:\n\t// the map, or the viewport for an overflowing tooltip.\n\t_getAutoArea() {\n\t\tconst map = this._map;\n\t\tlet min = new Point(0, 0),\n\t\tmax = map.getSize();\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = map._container,\n\t\t\trect = mapContainer.getBoundingClientRect(),\n\t\t\torigin = new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop),\n\t\t\tviewport = document.documentElement;\n\t\t\tmin = min.subtract(origin);\n\t\t\tmax = new Point(viewport.clientWidth, viewport.clientHeight).subtract(origin);\n\t\t}\n\t\tconst padding = new Point(autoPadding, autoPadding);\n\t\treturn {min: min.add(padding), max: max.subtract(padding)};\n\t}\n\n\t_updatePosition() {\n\t\tconst pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));\n\t\tthis._setPosition(pos);\n\t}\n\n\t/**\n\t * Sets the opacity of the tooltip.\n\t * @param {number} opacity\n\t * @returns {void}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._container) {\n\t\t\tthis._container.style.opacity = `${opacity}`;\n\t\t}\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);\n\t\tthis._setPosition(pos);\n\t}\n\n\t// Where the tooltip opening in the given direction attaches on the source layer\n\t_getAnchor(direction) {\n\t\treturn new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor(direction) : [0, 0]);\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapTooltipMethods);\n\n\t\tLayer.include(layerTooltipMethods);\n\t}\n}\n"],"mappings":";;;;;;;;AASA,MAAM,aAAa;CAAC,KAAK,CAAC,IAAK,CAAC;CAAG,QAAQ,CAAC,IAAK,CAAC;CAAG,Q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K,gBAAgB,KAAK,KAAK,mBAAmB,KAAK,OAAO,CAAC;EAChF,KAAK,aAAa,GAAG;CACtB;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,QAAQ,UAAU;EAEvB,IAAI,KAAK,YACR,KAAK,WAAW,MAAM,UAAU,GAAG;CAErC;CAEA,aAAa,GAAG;EACf,MAAM,MAAM,KAAK,KAAK,uBAAuB,KAAK,SAAS,EAAE,MAAM,EAAE,MAAM;EAC3E,KAAK,aAAa,GAAG;CACtB;CAGA,WAAW,WAAW;EACrB,OAAO,IAAI,MAAM,KAAK,SAAS,qBAAqB,CAAC,KAAK,QAAQ,SAAS,KAAK,QAAQ,kBAAkB,SAAS,IAAI,CAAC,GAAG,CAAC,CAAC;CAC9H;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,iBAAiB;EAEpC,MAAM,QAAQ,mBAAmB;CAClC;AACD"}
|
|
@@ -18,8 +18,11 @@ import { Point } from "../../geometry/Point.js";
|
|
|
18
18
|
* can be set in CSS with negative margins.
|
|
19
19
|
* @property {PointExpression} [popupAnchor=[0, 0]] The coordinates of the point from
|
|
20
20
|
* which popups will "open", relative to the icon anchor.
|
|
21
|
-
* @property {PointExpression} [tooltipAnchor=[0, 0]]
|
|
22
|
-
*
|
|
21
|
+
* @property {PointExpression} [tooltipAnchor=[0, 0]] Where tooltips opening to the side
|
|
22
|
+
* attach, relative to the icon anchor: `x` is how far to the right (mirrored for tooltips
|
|
23
|
+
* opening to the left) and `y` how far down. Tooltips opening to the top or bottom attach
|
|
24
|
+
* to the middle of the icon's top or bottom edge, and `center` ones to the middle of the
|
|
25
|
+
* icon at the `y` height.
|
|
23
26
|
* @property {string} [shadowUrl] The URL to the icon shadow image. If not specified, no
|
|
24
27
|
* shadow image will be created.
|
|
25
28
|
* @property {string} [shadowRetinaUrl] The URL to a retina sized version of the shadow
|
|
@@ -102,15 +105,31 @@ var Icon = class Icon extends Class {
|
|
|
102
105
|
else img.crossOrigin = null;
|
|
103
106
|
return img;
|
|
104
107
|
}
|
|
105
|
-
|
|
108
|
+
_getBox(name) {
|
|
106
109
|
const options = this.options;
|
|
107
110
|
const sizeOption = options[`${name}Size`];
|
|
108
111
|
const [width, height] = (typeof sizeOption === "number" ? [sizeOption, sizeOption] : Array.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);
|
|
109
112
|
const anchorOption = name === "shadow" && options.shadowAnchor || options.iconAnchor;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
+
return {
|
|
114
|
+
width,
|
|
115
|
+
height,
|
|
116
|
+
anchor: Point.validate(anchorOption) ? Point.from(anchorOption) : {
|
|
117
|
+
x: Math.round(width / 2),
|
|
118
|
+
y: Math.round(height / 2)
|
|
119
|
+
}
|
|
113
120
|
};
|
|
121
|
+
}
|
|
122
|
+
_getTooltipAnchor(direction) {
|
|
123
|
+
const { x, y } = Point.from(this.options.tooltipAnchor);
|
|
124
|
+
if (direction === "left") return new Point(-x, y);
|
|
125
|
+
if (direction === "center") return new Point(0, y);
|
|
126
|
+
if (direction !== "top" && direction !== "bottom") return new Point(x, y);
|
|
127
|
+
const { height, anchor } = this._getBox("icon");
|
|
128
|
+
return new Point(0, (direction === "top" ? -anchor.y : height - anchor.y) || 0);
|
|
129
|
+
}
|
|
130
|
+
_setIconStyles(img, name) {
|
|
131
|
+
const options = this.options;
|
|
132
|
+
const { width, height, anchor } = this._getBox(name);
|
|
114
133
|
img.className = `maplair-marker-${name} ${options.className || ""}`;
|
|
115
134
|
const { style } = img;
|
|
116
135
|
style.marginLeft = style.marginTop = style.width = style.height = "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","names":[],"sources":["../../../../src/layer/marker/Icon.js"],"sourcesContent":["import {Class} from '../../core/Class.js';\nimport {setOptions, toNumber} from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.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]]
|
|
1
|
+
{"version":3,"file":"Icon.js","names":[],"sources":["../../../../src/layer/marker/Icon.js"],"sourcesContent":["import {Class} from '../../core/Class.js';\nimport {setOptions, toNumber} from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.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]] Where tooltips opening to the side\n * attach, relative to the icon anchor: `x` is how far to the right (mirrored for tooltips\n * opening to the left) and `y` how far down. Tooltips opening to the top or bottom attach\n * to the middle of the icon's top or bottom edge, and `center` ones to the middle of the\n * icon at the `y` height.\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 defaultOptions = {\n\t\tpopupAnchor: [0, 0],\n\t\ttooltipAnchor: [0, 0],\n\t\tcrossOrigin: false\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 instanceof HTMLImageElement ? 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} else {\n\t\t\timg.crossOrigin = null;\n\t\t}\n\n\t\treturn img;\n\t}\n\n\t// The size and anchor of the icon or shadow in pixels; a side that isn't a number, like\n\t// 'auto' in [100, 'auto'], is left to CSS and comes out as NaN.\n\t_getBox(name) {\n\t\tconst options = this.options;\n\t\tconst sizeOption = options[`${name}Size`];\n\t\tconst [width, height] = (typeof sizeOption === 'number' ? [sizeOption, sizeOption] :\n\t\t\tArray.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);\n\n\t\tconst anchorOption = name === 'shadow' && options.shadowAnchor || options.iconAnchor;\n\t\tconst anchor = Point.validate(anchorOption) ? Point.from(anchorOption) :\n\t\t\t{x: Math.round(width / 2), y: Math.round(height / 2)};\n\t\treturn {width, height, anchor};\n\t}\n\n\t// Where a tooltip opening in the given direction attaches, relative to the icon anchor.\n\t_getTooltipAnchor(direction) {\n\t\tconst {x, y} = Point.from(this.options.tooltipAnchor);\n\t\tif (direction === 'left') { return new Point(-x, y); }\n\t\tif (direction === 'center') { return new Point(0, y); }\n\t\tif (direction !== 'top' && direction !== 'bottom') { return new Point(x, y); }\n\n\t\tconst {height, anchor} = this._getBox('icon');\n\t\treturn new Point(0, (direction === 'top' ? -anchor.y : height - anchor.y) || 0);\n\t}\n\n\t_setIconStyles(img, name) {\n\t\tconst options = this.options;\n\t\tconst {width, height, anchor} = this._getBox(name);\n\n\t\timg.className = `maplair-marker-${name} ${options.className || ''}`;\n\n\t\t// a marker reuses the element of its previous icon, which may have set any of these\n\t\tconst {style} = img;\n\t\tstyle.marginLeft = style.marginTop = style.width = style.height = '';\n\n\t\tif (!isNaN(anchor.x)) { style.marginLeft = `${-anchor.x}px`; }\n\t\tif (!isNaN(anchor.y)) { style.marginTop = `${-anchor.y}px`; }\n\t\t// the origin of the marker rotation: the anchor, which is the top left corner without one\n\t\tstyle.transformOrigin = !isNaN(anchor.x) && !isNaN(anchor.y) ? `${anchor.x}px ${anchor.y}px` : '0 0';\n\n\t\tif (!isNaN(width)) { style.width = `${width}px`; }\n\t\tif (!isNaN(height)) { style.height = `${height}px`; }\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 window.devicePixelRatio > 1 && this.options[`${name}RetinaUrl`] || this.options[`${name}Url`];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAa,OAAb,MAAa,aAAa,MAAM;CAE/B,OAAO,iBAAiB;EACvB,aAAa,CAAC,GAAG,CAAC;EAClB,eAAe,CAAC,GAAG,CAAC;EACpB,aAAa;CACd;;;;;CAMA,YAAY,SAAS;EACpB,MAAM;EACN,WAAW,MAAM,OAAO;EAExB,KAAK,cAAc,IAAI;CACxB;;;;;;;CAQA,WAAW,SAAS;EACnB,OAAO,KAAK,YAAY,QAAQ,OAAO;CACxC;;;;;;CAOA,aAAa,SAAS;EACrB,OAAO,KAA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IAAI,MAAM,IAAI,cAAc,QAAQ,CAAC,OAAO,IAAI,SAAS,OAAO,MAAM,CAAC;CAC/E;CAEA,eAAe,KAAK,MAAM;EACzB,MAAM,UAAU,KAAK;EACrB,MAAM,EAAC,OAAO,QAAQ,WAAU,KAAK,QAAQ,IAAI;EAEjD,IAAI,YAAY,kBAAkB,KAAK,GAAG,QAAQ,aAAa;EAG/D,MAAM,EAAC,UAAS;EAChB,MAAM,aAAa,MAAM,YAAY,MAAM,QAAQ,MAAM,SAAS;EAElE,IAAI,CAAC,MAAM,OAAO,CAAC,GAAK,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE;EACxD,IAAI,CAAC,MAAM,OAAO,CAAC,GAAK,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE;EAEvD,MAAM,kBAAkB,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,OAAO,CAAC,IAAI,GAAG,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM;EAE/F,IAAI,CAAC,MAAM,KAAK,GAAK,MAAM,QAAQ,GAAG,MAAM;EAC5C,IAAI,CAAC,MAAM,MAAM,GAAK,MAAM,SAAS,GAAG,OAAO;CAChD;CAEA,WAAW,KAAK,IAAI;EACnB,OAAO,SAAS,cAAc,KAAK;EACnC,GAAG,MAAM;EACT,OAAO;CACR;CAEA,YAAY,MAAM;EACjB,OAAO,OAAO,mBAAmB,KAAK,KAAK,QAAQ,GAAG,KAAK,eAAe,KAAK,QAAQ,GAAG,KAAK;CAChG;AACD"}
|
|
@@ -17,8 +17,8 @@ const arrows = {
|
|
|
17
17
|
* The handler of `Marker` which makes the markers draggable, see the
|
|
18
18
|
* [`dragging`](#marker-dragging) property of markers and its `draggable` option.
|
|
19
19
|
*
|
|
20
|
-
* @fires Marker#dragstart {
|
|
21
|
-
* @fires Marker#movestart {
|
|
20
|
+
* @fires Marker#dragstart {DraggableEvent} Fired when the user starts dragging the marker.
|
|
21
|
+
* @fires Marker#movestart {DraggableEvent} Fired when the marker starts moving (because of
|
|
22
22
|
* dragging).
|
|
23
23
|
* @fires Marker#drag {MarkerMoveEvent} Fired repeatedly while the user drags the marker.
|
|
24
24
|
* @fires Marker#dragend {DragEndEvent} Fired when the user stops dragging the marker.
|
|
@@ -84,10 +84,10 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
84
84
|
this._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
_onDragStart() {
|
|
87
|
+
_onDragStart({ originalEvent }) {
|
|
88
88
|
this._oldLatLng = this._marker.getLatLng();
|
|
89
89
|
this._marker.closePopup?.();
|
|
90
|
-
this._marker.fire("movestart").fire("dragstart");
|
|
90
|
+
this._marker.fire("movestart", { originalEvent }).fire("dragstart", { originalEvent });
|
|
91
91
|
}
|
|
92
92
|
_onPreDrag(e) {
|
|
93
93
|
if (this._marker.options.autoPan) {
|
|
@@ -124,7 +124,7 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
124
124
|
draggable._startPos = getPosition(draggable._element);
|
|
125
125
|
draggable._moved = draggable._moving = true;
|
|
126
126
|
this._keyOffset = new Point(0, 0);
|
|
127
|
-
draggable.fire("dragstart");
|
|
127
|
+
draggable.fire("dragstart", { originalEvent: k });
|
|
128
128
|
}
|
|
129
129
|
const offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);
|
|
130
130
|
this._keyOffset = this._keyOffset.add(map._rotateToPane?.(offset) ?? offset);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.Drag.js","names":["DomUtil.getPosition"],"sources":["../../../../src/layer/marker/Marker.Drag.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Marker, MarkerMoveEvent} from './Marker.js' */\n/** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */\n\n/** @type {Record<string, [number, number]>} */\nconst arrows = {ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1]};\n\n/**\n * The handler of `Marker` which makes the markers draggable, see the\n * [`dragging`](#marker-dragging) property of markers and its `draggable` option.\n *\n * @fires Marker#dragstart {MaplairEvent} Fired when the user starts dragging the marker.\n * @fires Marker#movestart {MaplairEvent} Fired when the marker starts moving (because of\n * dragging).\n * @fires Marker#drag {MarkerMoveEvent} Fired repeatedly while the user drags the marker.\n * @fires Marker#dragend {DragEndEvent} Fired when the user stops dragging the marker.\n * @fires Marker#moveend {MaplairEvent} Fired when the marker stops moving (because of\n * dragging).\n */\nexport class MarkerDrag extends Handler {\n\t/**\n\t * Creates the dragging handler of the given marker.\n\t * @param {Marker} marker\n\t */\n\tconstructor(marker) {\n\t\tsuper(marker._map);\n\t\tthis._marker = marker;\n\n\t\tthis.callInitHooks(MarkerDrag);\n\t}\n\n\t/**\n\t * Makes the icon of the marker draggable, called by `enable()`.\n\t */\n\taddHooks() {\n\t\tconst icon = this._marker._icon;\n\n\t\tif (!this._draggable) {\n\t\t\tthis._draggable = new Draggable(icon);\n\t\t}\n\n\t\tthis._draggable.on({\n\t\t\tdragstart: this._onDragStart,\n\t\t\tpredrag: this._onPreDrag,\n\t\t\tdrag: this._onDrag,\n\t\t\tdragend: this._onDragEnd\n\t\t}, this).enable();\n\n\t\tDomEvent.on(icon, 'keydown keyup blur', this._onKey, this);\n\n\t\ticon.classList.add('maplair-marker-draggable');\n\t}\n\n\t/**\n\t * Makes the icon of the marker undraggable, called by `disable()`.\n\t */\n\tremoveHooks() {\n\t\tthis._keyOffset = null; // disabling the Draggable below ends a keyboard drag in progress, as it does a pointer drag\n\n\t\tthis._draggable.off({\n\t\t\tdragstart: this._onDragStart,\n\t\t\tpredrag: this._onPreDrag,\n\t\t\tdrag: this._onDrag,\n\t\t\tdragend: this._onDragEnd\n\t\t}, this).disable();\n\n\t\tDomEvent.off(this._draggable._element, 'keydown keyup blur', this._onKey, this);\n\n\t\tthis._marker._icon?.classList.remove('maplair-marker-draggable');\n\t}\n\n\t/**\n\t * Returns `true` if the marker has been moved by the current or last drag.\n\t * @returns {boolean}\n\t */\n\tmoved() {\n\t\treturn this._draggable?._moved;\n\t}\n\n\t_adjustPan(e) {\n\t\tconst marker = this._marker,\n\t\tmap = marker._map,\n\t\tspeed = this._marker.options.autoPanSpeed,\n\t\tpadding = new Point(this._marker.options.autoPanPadding),\n\t\ticonPos = DomUtil.getPosition(marker._icon),\n\t\tbounds = map.getPixelBounds(),\n\t\torigin = map.getPixelOrigin(),\n\t\tmin = bounds.min._subtract(origin)._add(padding),\n\t\tmax = bounds.max._subtract(origin)._subtract(padding),\n\t\t// how far the icon is past the padded bounds on each axis (0 if within)\n\t\tdx = Math.max(iconPos.x - max.x, 0) + Math.min(iconPos.x - min.x, 0),\n\t\tdy = Math.max(iconPos.y - max.y, 0) + Math.min(iconPos.y - min.y, 0);\n\n\t\tif (dx || dy) {\n\t\t\t// pan faster the deeper the icon goes into the padding, but not past maxBounds\n\t\t\tconst movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed),\n\t\t\t\tmap.options.maxBounds)._round();\n\n\t\t\tif (!movement.x && !movement.y) { return; }\n\n\t\t\tmap.panBy(movement, {animate: false});\n\n\t\t\tthis._draggable._newPos._add(movement);\n\t\t\tthis._draggable._startPos._add(movement);\n\n\t\t\tDomUtil.setPosition(marker._icon, this._draggable._newPos);\n\t\t\tthis._onDrag(e);\n\n\t\t\tthis._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));\n\t\t}\n\t}\n\n\t_onDragStart() {\n\t\tthis._oldLatLng = this._marker.getLatLng();\n\n\t\t// When using ES6 imports it could not be set when `Popup` was not imported as well\n\t\tthis._marker.closePopup?.();\n\n\t\tthis._marker\n\t\t\t.fire('movestart')\n\t\t\t.fire('dragstart');\n\t}\n\n\t_onPreDrag(e) {\n\t\tif (this._marker.options.autoPan) {\n\t\t\tcancelAnimationFrame(this._panRequest);\n\t\t\tthis._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));\n\t\t}\n\t}\n\n\t_onDrag(e) {\n\t\tconst marker = this._marker,\n\t\ticonPos = DomUtil.getPosition(marker._icon),\n\t\tlatlng = marker._map.layerPointToLatLng(iconPos),\n\t\t{alt} = this._oldLatLng;\n\n\t\tif (alt !== undefined) { latlng.alt = alt; }\n\n\t\t// Draggable only moved the icon and dropped its rotation\n\t\tmarker._positionElements(iconPos);\n\n\t\tmarker._latlng = latlng;\n\t\te.latlng = latlng;\n\t\te.oldLatLng = this._oldLatLng;\n\n\t\tmarker\n\t\t\t.fire('move', e)\n\t\t\t.fire('drag', e);\n\t}\n\n\t_onDragEnd(e) {\n\t\tcancelAnimationFrame(this._panRequest);\n\n\t\tthis._marker\n\t\t\t.fire('moveend')\n\t\t\t.fire('dragend', e);\n\t}\n\n\t// Arrow keys move a focused marker. Holding a key down is one drag, driven through the Draggable like a pointer\n\t// drag (so the two can't overlap), and ends on keyup or blur.\n\t/** @param {KeyboardEvent|FocusEvent} e */\n\t_onKey(e) {\n\t\tconst k = /** @type {KeyboardEvent} */ (e), // all but blur\n\t\tdir = arrows[k.key],\n\t\tdraggable = this._draggable,\n\t\t{options, _map: map} = this._marker;\n\n\t\tif (e.type !== 'keydown') {\n\t\t\tif (this._keyOffset) {\n\t\t\t\tthis._keyOffset = null;\n\t\t\t\tdraggable.finishDrag();\n\t\t\t}\n\n\t\t} else if (dir && k.target === draggable._element && !(k.altKey || k.ctrlKey || k.metaKey)) {\n\t\t\te.preventDefault(); // don't scroll the page\n\n\t\t\tif (!this._keyOffset) {\n\t\t\t\tif (Draggable._dragging) { return; }\n\t\t\t\tDraggable._dragging = draggable;\n\t\t\t\tdraggable._startPos = DomUtil.getPosition(draggable._element);\n\t\t\t\tdraggable._moved = draggable._moving = true;\n\t\t\t\tthis._keyOffset = new Point(0, 0);\n\t\t\t\tdraggable.fire('dragstart');\n\t\t\t}\n\n\t\t\t// in container pixels, which the map rotation (if any) turns to the frame of the rotated pane\n\t\t\tconst offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);\n\t\t\tthis._keyOffset = this._keyOffset.add(map._rotateToPane?.(offset) ?? offset);\n\t\t\t// not through _updatePosition, whose predrag would start the pointer autoPan loop\n\t\t\tdraggable._newPos = draggable._startPos.add(this._keyOffset);\n\t\t\tDomUtil.setPosition(draggable._element, draggable._newPos);\n\t\t\tdraggable.fire('drag', {originalEvent: k});\n\n\t\t\tif (options.autoPan) {\n\t\t\t\tmap.panInside(this._marker._latlng, {padding: options.autoPanPadding, animate: false});\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,MAAM,SAAS;CAAC,WAAW,CAAC,IAAI,CAAC;CAAG,YAAY,CAAC,GAAG,CAAC;CAAG,SAAS,CAAC,GAAG,EAAE;CAAG,WAAW,CAAC,GAAG,CAAC;AAAC;;;;;;;;;;;;;AAc3F,IAAa,aAAb,MAAa,mBAAmB,QAAQ;;;;;CAKvC,YAAY,QAAQ;EACnB,MAAM,OAAO,IAAI;EACjB,KAAK,UAAU;EAEf,KAAK,cAAc,UAAU;CAC9B;;;;CAKA,WAAW;EACV,MAAM,OAAO,KAAK,QAAQ;EAE1B,IAAI,CAAC,KAAK,YACT,KAAK,aAAa,IAAI,UAAU,IAAI;EAGrC,KAAK,WAAW,GAAG;GAClB,WAAW,KAAK;GAChB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,SAAS,KAAK;EACf,GAAG,IAAI,CAAC,CAAC,OAAO;EAEhB,GAAY,MAAM,sBAAsB,KAAK,QAAQ,IAAI;EAEzD,KAAK,UAAU,IAAI,0BAA0B;CAC9C;;;;CAKA,cAAc;EACb,KAAK,aAAa;EAElB,KAAK,WAAW,IAAI;GACnB,WAAW,KAAK;GAChB,SAAS,KAAK;GACd,MAAM,KAAK;GACX,SAAS,KAAK;EACf,GAAG,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,KAAK,WAAW;GAC3B;GAGA,MAAM,SAAS,IAAI,MAAM,GAAG,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,KAAK,EAAE;GAChE,KAAK,aAAa,KAAK,WAAW,IAAI,IAAI,gBAAgB,MAAM,KAAK,MAAM;GAE3E,UAAU,UAAU,UAAU,UAAU,IAAI,KAAK,UAAU;GAC3D,YAAoB,UAAU,UAAU,UAAU,OAAO;GACzD,UAAU,KAAK,QAAQ,EAAC,eAAe,EAAC,CAAC;GAEzC,IAAI,QAAQ,SACX,IAAI,UAAU,KAAK,QAAQ,SAAS;IAAC,SAAS,QAAQ;IAAgB,SAAS;GAAK,CAAC;EAEvF;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"Marker.Drag.js","names":["DomUtil.getPosition"],"sources":["../../../../src/layer/marker/Marker.Drag.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Marker, MarkerMoveEvent} from './Marker.js' */\n/** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */\n\n/** @type {Record<string, [number, number]>} */\nconst arrows = {ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1]};\n\n/**\n * The handler of `Marker` which makes the markers draggable, see the\n * [`dragging`](#marker-dragging) property of markers and its `draggable` option.\n *\n * @fires Marker#dragstart {DraggableEvent} Fired when the user starts dragging the marker.\n * @fires Marker#movestart {DraggableEvent} Fired when the marker starts moving (because of\n * dragging).\n * @fires Marker#drag {MarkerMoveEvent} Fired repeatedly while the user drags the marker.\n * @fires Marker#dragend {DragEndEvent} Fired when the user stops dragging the marker.\n * @fires Marker#moveend {MaplairEvent} Fired when the marker stops moving (because of\n * dragging).\n */\nexport class MarkerDrag extends Handler {\n\t/**\n\t * Creates the dragging handler of the given marker.\n\t * @param {Marker} marker\n\t */\n\tconstructor(marker) {\n\t\tsuper(marker._map);\n\t\tthis._marker = marker;\n\n\t\tthis.callInitHooks(MarkerDrag);\n\t}\n\n\t/**\n\t * Makes the icon of the marker draggable, called by `enable()`.\n\t */\n\taddHooks() {\n\t\tconst icon = this._marker._icon;\n\n\t\tif (!this._draggable) {\n\t\t\tthis._draggable = new Draggable(icon);\n\t\t}\n\n\t\tthis._draggable.on({\n\t\t\tdragstart: this._onDragStart,\n\t\t\tpredrag: this._onPreDrag,\n\t\t\tdrag: this._onDrag,\n\t\t\tdragend: this._onDragEnd\n\t\t}, this).enable();\n\n\t\tDomEvent.on(icon, 'keydown keyup blur', this._onKey, this);\n\n\t\ticon.classList.add('maplair-marker-draggable');\n\t}\n\n\t/**\n\t * Makes the icon of the marker undraggable, called by `disable()`.\n\t */\n\tremoveHooks() {\n\t\tthis._keyOffset = null; // disabling the Draggable below ends a keyboard drag in progress, as it does a pointer drag\n\n\t\tthis._draggable.off({\n\t\t\tdragstart: this._onDragStart,\n\t\t\tpredrag: this._onPreDrag,\n\t\t\tdrag: this._onDrag,\n\t\t\tdragend: this._onDragEnd\n\t\t}, this).disable();\n\n\t\tDomEvent.off(this._draggable._element, 'keydown keyup blur', this._onKey, this);\n\n\t\tthis._marker._icon?.classList.remove('maplair-marker-draggable');\n\t}\n\n\t/**\n\t * Returns `true` if the marker has been moved by the current or last drag.\n\t * @returns {boolean}\n\t */\n\tmoved() {\n\t\treturn this._draggable?._moved;\n\t}\n\n\t_adjustPan(e) {\n\t\tconst marker = this._marker,\n\t\tmap = marker._map,\n\t\tspeed = this._marker.options.autoPanSpeed,\n\t\tpadding = new Point(this._marker.options.autoPanPadding),\n\t\ticonPos = DomUtil.getPosition(marker._icon),\n\t\tbounds = map.getPixelBounds(),\n\t\torigin = map.getPixelOrigin(),\n\t\tmin = bounds.min._subtract(origin)._add(padding),\n\t\tmax = bounds.max._subtract(origin)._subtract(padding),\n\t\t// how far the icon is past the padded bounds on each axis (0 if within)\n\t\tdx = Math.max(iconPos.x - max.x, 0) + Math.min(iconPos.x - min.x, 0),\n\t\tdy = Math.max(iconPos.y - max.y, 0) + Math.min(iconPos.y - min.y, 0);\n\n\t\tif (dx || dy) {\n\t\t\t// pan faster the deeper the icon goes into the padding, but not past maxBounds\n\t\t\tconst movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed),\n\t\t\t\tmap.options.maxBounds)._round();\n\n\t\t\tif (!movement.x && !movement.y) { return; }\n\n\t\t\tmap.panBy(movement, {animate: false});\n\n\t\t\tthis._draggable._newPos._add(movement);\n\t\t\tthis._draggable._startPos._add(movement);\n\n\t\t\tDomUtil.setPosition(marker._icon, this._draggable._newPos);\n\t\t\tthis._onDrag(e);\n\n\t\t\tthis._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));\n\t\t}\n\t}\n\n\t_onDragStart({originalEvent}) {\n\t\tthis._oldLatLng = this._marker.getLatLng();\n\n\t\t// When using ES6 imports it could not be set when `Popup` was not imported as well\n\t\tthis._marker.closePopup?.();\n\n\t\tthis._marker\n\t\t\t.fire('movestart', {originalEvent})\n\t\t\t.fire('dragstart', {originalEvent});\n\t}\n\n\t_onPreDrag(e) {\n\t\tif (this._marker.options.autoPan) {\n\t\t\tcancelAnimationFrame(this._panRequest);\n\t\t\tthis._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));\n\t\t}\n\t}\n\n\t_onDrag(e) {\n\t\tconst marker = this._marker,\n\t\ticonPos = DomUtil.getPosition(marker._icon),\n\t\tlatlng = marker._map.layerPointToLatLng(iconPos),\n\t\t{alt} = this._oldLatLng;\n\n\t\tif (alt !== undefined) { latlng.alt = alt; }\n\n\t\t// Draggable only moved the icon and dropped its rotation\n\t\tmarker._positionElements(iconPos);\n\n\t\tmarker._latlng = latlng;\n\t\te.latlng = latlng;\n\t\te.oldLatLng = this._oldLatLng;\n\n\t\tmarker\n\t\t\t.fire('move', e)\n\t\t\t.fire('drag', e);\n\t}\n\n\t_onDragEnd(e) {\n\t\tcancelAnimationFrame(this._panRequest);\n\n\t\tthis._marker\n\t\t\t.fire('moveend')\n\t\t\t.fire('dragend', e);\n\t}\n\n\t// Arrow keys move a focused marker. Holding a key down is one drag, driven through the Draggable like a pointer\n\t// drag (so the two can't overlap), and ends on keyup or blur.\n\t/** @param {KeyboardEvent|FocusEvent} e */\n\t_onKey(e) {\n\t\tconst k = /** @type {KeyboardEvent} */ (e), // all but blur\n\t\tdir = arrows[k.key],\n\t\tdraggable = this._draggable,\n\t\t{options, _map: map} = this._marker;\n\n\t\tif (e.type !== 'keydown') {\n\t\t\tif (this._keyOffset) {\n\t\t\t\tthis._keyOffset = null;\n\t\t\t\tdraggable.finishDrag();\n\t\t\t}\n\n\t\t} else if (dir && k.target === draggable._element && !(k.altKey || k.ctrlKey || k.metaKey)) {\n\t\t\te.preventDefault(); // don't scroll the page\n\n\t\t\tif (!this._keyOffset) {\n\t\t\t\tif (Draggable._dragging) { return; }\n\t\t\t\tDraggable._dragging = draggable;\n\t\t\t\tdraggable._startPos = DomUtil.getPosition(draggable._element);\n\t\t\t\tdraggable._moved = draggable._moving = true;\n\t\t\t\tthis._keyOffset = new Point(0, 0);\n\t\t\t\tdraggable.fire('dragstart', {originalEvent: k});\n\t\t\t}\n\n\t\t\t// in container pixels, which the map rotation (if any) turns to the frame of the rotated pane\n\t\t\tconst offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);\n\t\t\tthis._keyOffset = this._keyOffset.add(map._rotateToPane?.(offset) ?? offset);\n\t\t\t// not through _updatePosition, whose predrag would start the pointer autoPan loop\n\t\t\tdraggable._newPos = draggable._startPos.add(this._keyOffset);\n\t\t\tDomUtil.setPosition(draggable._element, draggable._newPos);\n\t\t\tdraggable.fire('drag', {originalEvent: k});\n\n\t\t\tif (options.autoPan) {\n\t\t\t\tmap.panInside(this._marker._latlng, {padding: options.autoPanPadding, animate: false});\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;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AS;GAAK,CAAC;EAEvF;CACD;AACD"}
|
|
@@ -226,7 +226,7 @@ var Marker = class Marker extends Layer {
|
|
|
226
226
|
*/
|
|
227
227
|
update() {
|
|
228
228
|
if (this._icon && this._map && !this._culled) {
|
|
229
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
229
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
|
|
230
230
|
this._setPos(pos);
|
|
231
231
|
}
|
|
232
232
|
return this;
|
|
@@ -297,7 +297,7 @@ var Marker = class Marker extends Layer {
|
|
|
297
297
|
}
|
|
298
298
|
_setPos(pos) {
|
|
299
299
|
this._positionElements(pos);
|
|
300
|
-
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
300
|
+
this._zIndex = Math.round(pos.y) + this.options.zIndexOffset;
|
|
301
301
|
this._updateRise();
|
|
302
302
|
}
|
|
303
303
|
_positionElements(pos) {
|
|
@@ -317,7 +317,7 @@ var Marker = class Marker extends Layer {
|
|
|
317
317
|
}
|
|
318
318
|
_animateZoom(opt) {
|
|
319
319
|
if (this._culled) return;
|
|
320
|
-
const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center)
|
|
320
|
+
const pos = this._map._snapLayerPoint(this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center));
|
|
321
321
|
this._setPos(pos);
|
|
322
322
|
}
|
|
323
323
|
_updateInteractive() {
|
|
@@ -432,8 +432,8 @@ var Marker = class Marker extends Layer {
|
|
|
432
432
|
_getPopupAnchor() {
|
|
433
433
|
return this._rotateAnchor(this.options.icon.options.popupAnchor);
|
|
434
434
|
}
|
|
435
|
-
_getTooltipAnchor() {
|
|
436
|
-
return this._rotateAnchor(this.options.icon.
|
|
435
|
+
_getTooltipAnchor(direction) {
|
|
436
|
+
return this._rotateAnchor(this.options.icon._getTooltipAnchor(direction));
|
|
437
437
|
}
|
|
438
438
|
_rotateAnchor(anchor) {
|
|
439
439
|
const angle = this.options.rotation * Math.PI / 180;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.js","names":["DomUtil.getPosition"],"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 {I18n} from '../../core/I18n.js';\nimport {MarkerDrag} from './Marker.Drag.js';\nimport {pointToGeoJSON} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\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, if interactive, clicked by pressing Enter or Space.\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] Text for the `alt` attribute of the icon image, the\n * translation of `'Marker'` by default.\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 {number|null} [rotation=null] Rotation of the marker icon in degrees,\n * clockwise, around the icon anchor, e.g. for the heading of a vehicle. A rotated\n * marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong\n * under a tilted one. `null` means no rotation.\n * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of\n * others while the pointer is over it. It always does while it has focus.\n * @property {number} [riseOffset=250] The z-index offset used when the marker gets on\n * top of others on hover or focus.\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. A focused draggable marker can also be moved with the arrow keys, by 10 pixels\n * or 30 with Shift.\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 defaultOptions = {\n\t\ticon: /* @__PURE__ */ new DefaultIcon(),\n\n\t\t// Option inherited from \"Interactive layer\" abstract class\n\t\tinteractive: true,\n\n\t\tkeyboard: true,\n\t\ttitle: '',\n\t\talt: undefined,\n\t\tzIndexOffset: 0,\n\t\topacity: 1,\n\t\trotation: null,\n\t\triseOnHover: false,\n\t\triseOffset: 250,\n\t\tpane: 'markerPane',\n\t\tshadowPane: 'shadowPane',\n\t\tshadow: true,\n\t\tbubblingPointerEvents: false,\n\t\tautoPanOnFocus: true,\n\t\tdraggable: false,\n\t\tautoPan: false,\n\t\tautoPanPadding: [50, 50],\n\t\tautoPanSpeed: 10\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) {\n\t\t\t// remember whether dragging is on or off (`dragging.disable()`) for when the marker is added again\n\t\t\tthis.options.draggable = this.dragging.enabled();\n\t\t\tif (this.options.draggable) { this.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\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 instanceof HTMLImageElement) {\n\t\t\t\ticon.alt = options.alt ?? I18n.translate('Marker');\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\tif (options.interactive) {\n\t\t\t\ticon.setAttribute('role', 'button');\n\t\t\t}\n\t\t\tDomEvent.on(icon, 'keydown', this._onKeyDown, this);\n\t\t}\n\n\t\tthis._icon = icon;\n\n\t\tif (this._popup?._source === this) {\n\t\t\tthis._popup._updateSourceAria(this._popup.isOpen());\n\t\t}\n\n\t\tDomEvent.on(icon, 'focusin focusout', this._updateRise, this);\n\t\tif (options.riseOnHover) {\n\t\t\tDomEvent.on(icon, 'pointerover pointerout', this._updateRise, this);\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 : 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().append(this._icon);\n\t\t}\n\t\tthis._initInteraction();\n\t\tif (newShadow && addShadow) {\n\t\t\tthis.getPane(options.shadowPane).append(this._shadow);\n\t\t}\n\t}\n\n\t_removeIcon() {\n\t\tDomEvent.off(this._icon, 'pointerover pointerout focusin focusout', this._updateRise, this);\n\t\tthis._hovered = this._focused = false;\n\n\t\tif (this.options.autoPanOnFocus) {\n\t\t\tDomEvent.off(this._icon, 'focus', this._panOnFocus, this);\n\t\t}\n\t\tDomEvent.off(this._icon, 'keydown', this._onKeyDown, this);\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 map = this._map,\n\t\t// computed once per view for all markers, reset by the map on `move`\n\t\tbounds = map._cullingBounds ??= map.getBounds().pad(0.5),\n\t\tvisible = bounds.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().append(this._icon);\n\t\t\tif (this._shadow) {\n\t\t\t\tthis.getPane(this.options.shadowPane).append(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\t\tthis._positionElements(pos);\n\n\t\tthis._zIndex = pos.y + this.options.zIndexOffset;\n\n\t\tthis._updateRise();\n\t}\n\n\t_positionElements(pos) {\n\t\tconst rotation = this.options.rotation;\n\n\t\tif (this._icon) {\n\t\t\tDomUtil.setPosition(this._icon, pos);\n\t\t\tif (rotation != null) {\n\t\t\t\tthis._icon.style.transform += ` rotate(${rotation}deg)`;\n\t\t\t}\n\t\t}\n\n\t\tif (this._shadow) {\n\t\t\tDomUtil.setPosition(this._shadow, pos);\n\t\t\tthis._shadow.style.display = rotation == null ? '' : 'none';\n\t\t}\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.keyboard) {\n\t\t\tif (this.options.interactive) {\n\t\t\t\tthis._icon.setAttribute('role', 'button');\n\t\t\t} else {\n\t\t\t\tthis._icon.removeAttribute('role');\n\t\t\t}\n\t\t}\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\t// When the icon element is reused, the drag handler still refers to it. Keep that handler, because\n\t\t// replacing it ends a drag in progress and forgets that the marker has just been dragged.\n\t\tif (this.dragging?._draggable?._element === this._icon) {\n\t\t\t// the icon has reset the class names of the element\n\t\t\tthis._icon.classList.toggle('maplair-marker-draggable', this.dragging.enabled());\n\t\t\treturn;\n\t\t}\n\n\t\tlet draggable = this.options.draggable;\n\t\tif (this.dragging) {\n\t\t\tdraggable = this.dragging.enabled();\n\t\t\tthis.dragging.disable();\n\t\t}\n\n\t\t/**\n\t\t * Marker dragging handler, see `Handler`. Only valid when the marker is on the\n\t\t * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).\n\t\t *\n\t\t * Interaction handlers are properties of a marker instance that allow you to\n\t\t * control interaction behavior in runtime, enabling or disabling certain\n\t\t * features such as dragging (see `Handler` methods). Example:\n\t\t *\n\t\t * ```js\n\t\t * marker.dragging.disable();\n\t\t * ```\n\t\t * @group Interaction handlers\n\t\t * @type {MarkerDrag}\n\t\t */\n\t\tthis.dragging = new MarkerDrag(this);\n\n\t\tif (draggable) {\n\t\t\tthis.dragging.enable();\n\t\t}\n\t}\n\n\t/**\n\t * Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.\n\t * @returns {number|null}\n\t */\n\tgetRotation() {\n\t\treturn this.options.rotation;\n\t}\n\n\t/**\n\t * Changes the [rotation](#markeroptions-rotation) of the marker; `null` removes it.\n\t * @param {number|null} rotation\n\t * @returns {this}\n\t */\n\tsetRotation(rotation) {\n\t\tthis.options.rotation = rotation;\n\t\t// mid-zoom, the icon is transitioning to a position that update() can't compute yet; the zoom end applies it\n\t\tif (this._icon && !this._map._animatingZoom) {\n\t\t\tthis._positionElements(DomUtil.getPosition(this._icon));\n\t\t\tthis._popup?._updatePosition();\n\t\t\tthis._tooltip?._updatePosition();\n\t\t}\n\t\treturn this;\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\tfor (const el of [this._icon, this._shadow]) {\n\t\t\tif (el) {\n\t\t\t\tel.style.opacity = `${this.options.opacity}`;\n\t\t\t}\n\t\t}\n\t}\n\n\t_updateRise(e) {\n\t\tif (e?.type.startsWith('pointer')) {\n\t\t\tthis._hovered = e.type === 'pointerover';\n\t\t} else if (e) {\n\t\t\tthis._focused = e.type === 'focusin';\n\t\t}\n\t\tif (this._hovered || this._focused) {\n\t\t\tthis._bringToFront();\n\t\t} else {\n\t\t\tthis._resetZIndex();\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_onKeyDown(e) {\n\t\t// a key pressed on a focusable element inside a DivIcon (e.g. a <button>) already clicks it natively\n\t\tif (this.options.interactive && e.target === this._icon && !e.repeat && (e.key === 'Enter' || e.key === ' ')) {\n\t\t\te.preventDefault(); // stop Space from scrolling the page\n\t\t\t// lets a popup opened by the click take the focus, see Popup.onAdd()\n\t\t\tthis._clickedByKeyboard = true;\n\t\t\tthis._icon.click();\n\t\t\tthis._clickedByKeyboard = false;\n\t\t}\n\t}\n\n\t_panOnFocus() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; }\n\n\t\tconst icon = this._icon,\n\t\tstyle = getComputedStyle(icon),\n\t\tanchor = new Point(-parseFloat(style.marginLeft) || 0, -parseFloat(style.marginTop) || 0),\n\t\tsize = new Point(icon.offsetWidth, icon.offsetHeight);\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._rotateAnchor(this.options.icon.options.popupAnchor);\n\t}\n\n\t_getTooltipAnchor() {\n\t\treturn this._rotateAnchor(this.options.icon.options.tooltipAnchor);\n\t}\n\n\t// anchors are offsets from the icon anchor, which is also the rotation origin\n\t_rotateAnchor(anchor) {\n\t\tconst angle = this.options.rotation * Math.PI / 180;\n\t\tif (!angle || !anchor) { return anchor; }\n\n\t\tconst {x, y} = Point.from(anchor),\n\t\tcos = Math.cos(angle),\n\t\tsin = Math.sin(angle);\n\t\treturn new Point(x * cos - y * sin, x * sin + y * cos);\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the marker (as a GeoJSON `Point` Feature).\n\t * @group Other methods\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn pointToGeoJSON(this, precision);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,IAAa,SAAb,MAAa,eAAe,MAAM;CAEjC,OAAO,iBAAiB;EACvB,sBAAsB,IAAI,YAAY;EAGtC,aAAa;EAEb,UAAU;EACV,OAAO;EACP,KAAK,KAAA;EACL,cAAc;EACd,SAAS;EACT,UAAU;EACV,aAAa;EACb,YAAY;EACZ,MAAM;EACN,YAAY;EACZ,QAAQ;EACR,uBAAuB;EACvB,gBAAgB;EAChB,WAAW;EACX,SAAS;EACT,gBAAgB,CAAC,IAAI,EAAE;EACvB,cAAc;CACf;;;;;;;CAQA,YAAY,QAAQ,SA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,KAAK,QAAQ,eAAe,EAAE,WAAW,KAAK,SAAS,CAAC,EAAE,WAAW,EAAE,QAAQ,WAAW,EAAE,QAAQ,MAAM;GAC7G,EAAE,eAAe;GAEjB,KAAK,qBAAqB;GAC1B,KAAK,MAAM,MAAM;GACjB,KAAK,qBAAqB;EAC3B;CACD;CAEA,cAAc;EACb,MAAM,MAAM,KAAK;EACjB,IAAI,CAAC,KAAO;EAEZ,MAAM,OAAO,KAAK,OAClB,QAAQ,iBAAiB,IAAI,GAC7B,SAAS,IAAI,MAAM,CAAC,WAAW,MAAM,UAAU,KAAK,GAAG,CAAC,WAAW,MAAM,SAAS,KAAK,CAAC,GACxF,OAAO,IAAI,MAAM,KAAK,aAAa,KAAK,YAAY;EAEpD,IAAI,UAAU,KAAK,SAAS;GAC3B,gBAAgB;GAChB,oBAAoB,KAAK,SAAS,MAAM;EACzC,CAAC;CACF;CAEA,kBAAkB;EACjB,OAAO,KAAK,cAAc,KAAK,QAAQ,KAAK,QAAQ,WAAW;CAChE;CAEA,oBAAoB;EACnB,OAAO,KAAK,cAAc,KAAK,QAAQ,KAAK,QAAQ,aAAa;CAClE;CAGA,cAAc,QAAQ;EACrB,MAAM,QAAQ,KAAK,QAAQ,WAAW,KAAK,KAAK;EAChD,IAAI,CAAC,SAAS,CAAC,QAAU,OAAO;EAEhC,MAAM,EAAC,GAAG,MAAK,MAAM,KAAK,MAAM,GAChC,MAAM,KAAK,IAAI,KAAK,GACpB,MAAM,KAAK,IAAI,KAAK;EACpB,OAAO,IAAI,MAAM,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,IAAI,GAAG;CACtD;;;;;;;;;CAUA,UAAU,WAAW;EACpB,OAAO,eAAe,MAAM,SAAS;CACtC;AACD"}
|
|
1
|
+
{"version":3,"file":"Marker.js","names":["DomUtil.getPosition"],"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 {I18n} from '../../core/I18n.js';\nimport {MarkerDrag} from './Marker.Drag.js';\nimport {pointToGeoJSON} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\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, if interactive, clicked by pressing Enter or Space.\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] Text for the `alt` attribute of the icon image, the\n * translation of `'Marker'` by default.\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 {number|null} [rotation=null] Rotation of the marker icon in degrees,\n * clockwise, around the icon anchor, e.g. for the heading of a vehicle. A rotated\n * marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong\n * under a tilted one. `null` means no rotation.\n * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of\n * others while the pointer is over it. It always does while it has focus.\n * @property {number} [riseOffset=250] The z-index offset used when the marker gets on\n * top of others on hover or focus.\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. A focused draggable marker can also be moved with the arrow keys, by 10 pixels\n * or 30 with Shift.\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 defaultOptions = {\n\t\ticon: /* @__PURE__ */ new DefaultIcon(),\n\n\t\t// Option inherited from \"Interactive layer\" abstract class\n\t\tinteractive: true,\n\n\t\tkeyboard: true,\n\t\ttitle: '',\n\t\talt: undefined,\n\t\tzIndexOffset: 0,\n\t\topacity: 1,\n\t\trotation: null,\n\t\triseOnHover: false,\n\t\triseOffset: 250,\n\t\tpane: 'markerPane',\n\t\tshadowPane: 'shadowPane',\n\t\tshadow: true,\n\t\tbubblingPointerEvents: false,\n\t\tautoPanOnFocus: true,\n\t\tdraggable: false,\n\t\tautoPan: false,\n\t\tautoPanPadding: [50, 50],\n\t\tautoPanSpeed: 10\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) {\n\t\t\t// remember whether dragging is on or off (`dragging.disable()`) for when the marker is added again\n\t\t\tthis.options.draggable = this.dragging.enabled();\n\t\t\tif (this.options.draggable) { this.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\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._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));\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 instanceof HTMLImageElement) {\n\t\t\t\ticon.alt = options.alt ?? I18n.translate('Marker');\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\tif (options.interactive) {\n\t\t\t\ticon.setAttribute('role', 'button');\n\t\t\t}\n\t\t\tDomEvent.on(icon, 'keydown', this._onKeyDown, this);\n\t\t}\n\n\t\tthis._icon = icon;\n\n\t\tif (this._popup?._source === this) {\n\t\t\tthis._popup._updateSourceAria(this._popup.isOpen());\n\t\t}\n\n\t\tDomEvent.on(icon, 'focusin focusout', this._updateRise, this);\n\t\tif (options.riseOnHover) {\n\t\t\tDomEvent.on(icon, 'pointerover pointerout', this._updateRise, this);\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 : 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().append(this._icon);\n\t\t}\n\t\tthis._initInteraction();\n\t\tif (newShadow && addShadow) {\n\t\t\tthis.getPane(options.shadowPane).append(this._shadow);\n\t\t}\n\t}\n\n\t_removeIcon() {\n\t\tDomEvent.off(this._icon, 'pointerover pointerout focusin focusout', this._updateRise, this);\n\t\tthis._hovered = this._focused = false;\n\n\t\tif (this.options.autoPanOnFocus) {\n\t\t\tDomEvent.off(this._icon, 'focus', this._panOnFocus, this);\n\t\t}\n\t\tDomEvent.off(this._icon, 'keydown', this._onKeyDown, this);\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 map = this._map,\n\t\t// computed once per view for all markers, reset by the map on `move`\n\t\tbounds = map._cullingBounds ??= map.getBounds().pad(0.5),\n\t\tvisible = bounds.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().append(this._icon);\n\t\t\tif (this._shadow) {\n\t\t\t\tthis.getPane(this.options.shadowPane).append(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\t\tthis._positionElements(pos);\n\n\t\tthis._zIndex = Math.round(pos.y) + this.options.zIndexOffset;\n\n\t\tthis._updateRise();\n\t}\n\n\t_positionElements(pos) {\n\t\tconst rotation = this.options.rotation;\n\n\t\tif (this._icon) {\n\t\t\tDomUtil.setPosition(this._icon, pos);\n\t\t\tif (rotation != null) {\n\t\t\t\tthis._icon.style.transform += ` rotate(${rotation}deg)`;\n\t\t\t}\n\t\t}\n\n\t\tif (this._shadow) {\n\t\t\tDomUtil.setPosition(this._shadow, pos);\n\t\t\tthis._shadow.style.display = rotation == null ? '' : 'none';\n\t\t}\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._snapLayerPoint(this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center));\n\n\t\tthis._setPos(pos);\n\t}\n\n\t_updateInteractive() {\n\t\tif (!this._icon) { return; }\n\t\tif (this.options.keyboard) {\n\t\t\tif (this.options.interactive) {\n\t\t\t\tthis._icon.setAttribute('role', 'button');\n\t\t\t} else {\n\t\t\t\tthis._icon.removeAttribute('role');\n\t\t\t}\n\t\t}\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\t// When the icon element is reused, the drag handler still refers to it. Keep that handler, because\n\t\t// replacing it ends a drag in progress and forgets that the marker has just been dragged.\n\t\tif (this.dragging?._draggable?._element === this._icon) {\n\t\t\t// the icon has reset the class names of the element\n\t\t\tthis._icon.classList.toggle('maplair-marker-draggable', this.dragging.enabled());\n\t\t\treturn;\n\t\t}\n\n\t\tlet draggable = this.options.draggable;\n\t\tif (this.dragging) {\n\t\t\tdraggable = this.dragging.enabled();\n\t\t\tthis.dragging.disable();\n\t\t}\n\n\t\t/**\n\t\t * Marker dragging handler, see `Handler`. Only valid when the marker is on the\n\t\t * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).\n\t\t *\n\t\t * Interaction handlers are properties of a marker instance that allow you to\n\t\t * control interaction behavior in runtime, enabling or disabling certain\n\t\t * features such as dragging (see `Handler` methods). Example:\n\t\t *\n\t\t * ```js\n\t\t * marker.dragging.disable();\n\t\t * ```\n\t\t * @group Interaction handlers\n\t\t * @type {MarkerDrag}\n\t\t */\n\t\tthis.dragging = new MarkerDrag(this);\n\n\t\tif (draggable) {\n\t\t\tthis.dragging.enable();\n\t\t}\n\t}\n\n\t/**\n\t * Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.\n\t * @returns {number|null}\n\t */\n\tgetRotation() {\n\t\treturn this.options.rotation;\n\t}\n\n\t/**\n\t * Changes the [rotation](#markeroptions-rotation) of the marker; `null` removes it.\n\t * @param {number|null} rotation\n\t * @returns {this}\n\t */\n\tsetRotation(rotation) {\n\t\tthis.options.rotation = rotation;\n\t\t// mid-zoom, the icon is transitioning to a position that update() can't compute yet; the zoom end applies it\n\t\tif (this._icon && !this._map._animatingZoom) {\n\t\t\tthis._positionElements(DomUtil.getPosition(this._icon));\n\t\t\tthis._popup?._updatePosition();\n\t\t\tthis._tooltip?._updatePosition();\n\t\t}\n\t\treturn this;\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\tfor (const el of [this._icon, this._shadow]) {\n\t\t\tif (el) {\n\t\t\t\tel.style.opacity = `${this.options.opacity}`;\n\t\t\t}\n\t\t}\n\t}\n\n\t_updateRise(e) {\n\t\tif (e?.type.startsWith('pointer')) {\n\t\t\tthis._hovered = e.type === 'pointerover';\n\t\t} else if (e) {\n\t\t\tthis._focused = e.type === 'focusin';\n\t\t}\n\t\tif (this._hovered || this._focused) {\n\t\t\tthis._bringToFront();\n\t\t} else {\n\t\t\tthis._resetZIndex();\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_onKeyDown(e) {\n\t\t// a key pressed on a focusable element inside a DivIcon (e.g. a <button>) already clicks it natively\n\t\tif (this.options.interactive && e.target === this._icon && !e.repeat && (e.key === 'Enter' || e.key === ' ')) {\n\t\t\te.preventDefault(); // stop Space from scrolling the page\n\t\t\t// lets a popup opened by the click take the focus, see Popup.onAdd()\n\t\t\tthis._clickedByKeyboard = true;\n\t\t\tthis._icon.click();\n\t\t\tthis._clickedByKeyboard = false;\n\t\t}\n\t}\n\n\t_panOnFocus() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; }\n\n\t\tconst icon = this._icon,\n\t\tstyle = getComputedStyle(icon),\n\t\tanchor = new Point(-parseFloat(style.marginLeft) || 0, -parseFloat(style.marginTop) || 0),\n\t\tsize = new Point(icon.offsetWidth, icon.offsetHeight);\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._rotateAnchor(this.options.icon.options.popupAnchor);\n\t}\n\n\t_getTooltipAnchor(direction) {\n\t\treturn this._rotateAnchor(this.options.icon._getTooltipAnchor(direction));\n\t}\n\n\t// anchors are offsets from the icon anchor, which is also the rotation origin\n\t_rotateAnchor(anchor) {\n\t\tconst angle = this.options.rotation * Math.PI / 180;\n\t\tif (!angle || !anchor) { return anchor; }\n\n\t\tconst {x, y} = Point.from(anchor),\n\t\tcos = Math.cos(angle),\n\t\tsin = Math.sin(angle);\n\t\treturn new Point(x * cos - y * sin, x * sin + y * cos);\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the marker (as a GeoJSON `Point` Feature).\n\t * @group Other methods\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn pointToGeoJSON(this, precision);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,IAAa,SAAb,MAAa,eAAe,MAAM;CAEjC,OAAO,iBAAiB;EACvB,sBAAsB,IAAI,YAAY;EAGtC,aAAa;EAEb,UAAU;EACV,OAAO;EACP,KAAK,KAAA;EACL,cAAc;EACd,SAAS;EACT,UAAU;EACV,aAAa;EACb,YAAY;EACZ,MAAM;EACN,YAAY;EACZ,QAAQ;EACR,uBAAuB;EACvB,gBAAgB;EAChB,WAAW;EACX,SAAS;EACT,gBAAgB,CAAC,IAAI,EAAE;EACvB,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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EAAE,eAAe;GAEjB,KAAK,qBAAqB;GAC1B,KAAK,MAAM,MAAM;GACjB,KAAK,qBAAqB;EAC3B;CACD;CAEA,cAAc;EACb,MAAM,MAAM,KAAK;EACjB,IAAI,CAAC,KAAO;EAEZ,MAAM,OAAO,KAAK,OAClB,QAAQ,iBAAiB,IAAI,GAC7B,SAAS,IAAI,MAAM,CAAC,WAAW,MAAM,UAAU,KAAK,GAAG,CAAC,WAAW,MAAM,SAAS,KAAK,CAAC,GACxF,OAAO,IAAI,MAAM,KAAK,aAAa,KAAK,YAAY;EAEpD,IAAI,UAAU,KAAK,SAAS;GAC3B,gBAAgB;GAChB,oBAAoB,KAAK,SAAS,MAAM;EACzC,CAAC;CACF;CAEA,kBAAkB;EACjB,OAAO,KAAK,cAAc,KAAK,QAAQ,KAAK,QAAQ,WAAW;CAChE;CAEA,kBAAkB,WAAW;EAC5B,OAAO,KAAK,cAAc,KAAK,QAAQ,KAAK,kBAAkB,SAAS,CAAC;CACzE;CAGA,cAAc,QAAQ;EACrB,MAAM,QAAQ,KAAK,QAAQ,WAAW,KAAK,KAAK;EAChD,IAAI,CAAC,SAAS,CAAC,QAAU,OAAO;EAEhC,MAAM,EAAC,GAAG,MAAK,MAAM,KAAK,MAAM,GAChC,MAAM,KAAK,IAAI,KAAK,GACpB,MAAM,KAAK,IAAI,KAAK;EACpB,OAAO,IAAI,MAAM,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,IAAI,GAAG;CACtD;;;;;;;;;CAUA,UAAU,WAAW;EACpB,OAAO,eAAe,MAAM,SAAS;CACtC;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { setOptions, throttle, wrapNum } from "../../core/Util.js";
|
|
2
2
|
import { Point } from "../../geometry/Point.js";
|
|
3
3
|
import { create, getPosition, setPosition, setTransform, toBack, toFront } from "../../dom/DomUtil.js";
|
|
4
4
|
import { Layer } from "../Layer.js";
|
|
@@ -334,7 +334,7 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
334
334
|
_onOpaqueTile() {}
|
|
335
335
|
_initContainer() {
|
|
336
336
|
if (this._container) return;
|
|
337
|
-
this._container = create("div", `maplair-layer ${this.options.className ?? ""}`);
|
|
337
|
+
this._container = create("div", `maplair-layer maplair-zoom-animated ${this.options.className ?? ""}`);
|
|
338
338
|
this._container.classList.toggle("maplair-pixelated", !!this.options.pixelated);
|
|
339
339
|
this._updateZIndex();
|
|
340
340
|
if (this.options.opacity < 1) this._updateOpacity();
|
|
@@ -401,7 +401,6 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
401
401
|
level.origin = map.project(map.unproject(map.getPixelOrigin()), zoom).round();
|
|
402
402
|
level.zoom = zoom;
|
|
403
403
|
this._setZoomTransform(level, map.getCenter(), map.getZoom());
|
|
404
|
-
falseFn(level.el.offsetWidth);
|
|
405
404
|
this._onCreateLevel(level);
|
|
406
405
|
}
|
|
407
406
|
this._level = level;
|
|
@@ -465,7 +464,10 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
465
464
|
this._setView(this._map.getCenter(), this._map.getZoom(), animating, animating);
|
|
466
465
|
}
|
|
467
466
|
_animateZoom(e) {
|
|
467
|
+
const map = this._map, center = map.getCenter(), zoom = map.getZoom(), scale = map.getZoomScale(e.zoom, zoom);
|
|
468
468
|
this._setView(e.center, e.zoom, true, e.noUpdate);
|
|
469
|
+
this._setZoomTransforms(center, zoom);
|
|
470
|
+
setTransform(this._container, map._getNewPixelOrigin(center, zoom).multiplyBy(scale).subtract(map._getNewPixelOrigin(e.center, e.zoom)), scale);
|
|
469
471
|
}
|
|
470
472
|
_getTileZoom(zoom) {
|
|
471
473
|
const { minZoom, maxZoom = Infinity } = this.options;
|
|
@@ -493,10 +495,12 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
493
495
|
this._setZoomTransforms(center, zoom);
|
|
494
496
|
}
|
|
495
497
|
_setZoomTransforms(center, zoom) {
|
|
498
|
+
if (this._container.style.transform) this._container.style.transform = "";
|
|
496
499
|
for (const level of Object.values(this._levels)) this._setZoomTransform(level, center, zoom);
|
|
497
500
|
}
|
|
498
501
|
_setZoomTransform(level, center, zoom) {
|
|
499
|
-
const scale = this._map.getZoomScale(zoom, level.zoom), translate = level.origin.multiplyBy(scale).subtract(this._map._getNewPixelOrigin(center, zoom))
|
|
502
|
+
const scale = this._map.getZoomScale(zoom, level.zoom), translate = level.origin.multiplyBy(scale).subtract(this._map._getNewPixelOrigin(center, zoom));
|
|
503
|
+
if (scale === 1) this._map._snapLayerPoint(translate);
|
|
500
504
|
setTransform(level.el, translate, scale);
|
|
501
505
|
}
|
|
502
506
|
_resetGrid() {
|
|
@@ -507,7 +511,9 @@ var GridLayer = class GridLayer extends Layer {
|
|
|
507
511
|
this._wrapY = crs.wrapLat && !this.options.noWrap && [Math.floor(map.project([crs.wrapLat[0], 0], tileZoom).y / tileSize.y), Math.ceil(map.project([crs.wrapLat[1], 0], tileZoom).y / tileSize.y)];
|
|
508
512
|
}
|
|
509
513
|
_onMoveEnd() {
|
|
510
|
-
|
|
514
|
+
const map = this._map;
|
|
515
|
+
if (!map || map._animatingZoom) return;
|
|
516
|
+
if (this._container.style.transform) this._setZoomTransforms(map.getCenter(), map.getZoom());
|
|
511
517
|
this._update();
|
|
512
518
|
}
|
|
513
519
|
_onWorldCopyJump({ worlds }) {
|