maplair 4.3.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +151 -8
- package/dist/esm/control/AttributionControl.js +30 -13
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +0 -1
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -1
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +16 -11
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +0 -1
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +46 -27
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +0 -1
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -8
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +3 -2
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +14 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +3 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +17 -5
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +4 -7
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +5 -5
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +10 -8
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +24 -35
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +6 -3
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +2 -2
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +16 -19
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +10 -3
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -7
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +3 -2
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +25 -25
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +8 -5
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +12 -7
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +33 -15
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +48 -56
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +2 -2
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +4 -8
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +37 -17
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +11 -12
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +54 -53
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +1 -1
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +29 -21
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +19 -15
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +45 -94
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +8 -9
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +15 -4
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +10 -5
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +10 -11
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +19 -26
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +16 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +3 -3
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +9 -11
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +158 -71
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +2 -5
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +68 -30
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +7 -2
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +8 -20
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +970 -810
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +970 -810
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/en.json +1 -0
- package/package.json +1 -1
- package/src/control/AttributionControl.js +37 -11
- package/src/control/ButtonControl.js +0 -1
- package/src/control/ContextMenu.js +1 -1
- package/src/control/Control.js +13 -16
- package/src/control/FullscreenControl.js +0 -1
- package/src/control/LayersControl.js +61 -37
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +10 -8
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +11 -13
- package/src/core/Events.js +6 -2
- package/src/core/Util.js +17 -4
- package/src/dom/DomEvent.PointerEvents.js +68 -2
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +11 -8
- package/src/geo/LatLng.js +24 -37
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +22 -28
- package/src/geometry/PolyUtil.js +12 -3
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +6 -3
- package/src/layer/DivOverlay.js +30 -32
- package/src/layer/ImageOverlay.js +12 -9
- package/src/layer/Layer.js +19 -7
- package/src/layer/Popup.js +41 -21
- package/src/layer/Tooltip.js +50 -70
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +41 -20
- package/src/layer/marker/Marker.Drag.js +22 -24
- package/src/layer/marker/Marker.js +71 -64
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +41 -30
- package/src/layer/tile/TileLayer.js +31 -21
- package/src/layer/tile/WMSTileLayer.js +4 -2
- package/src/layer/vector/Canvas.js +53 -149
- package/src/layer/vector/Circle.js +13 -13
- package/src/layer/vector/CircleMarker.js +16 -3
- package/src/layer/vector/Path.ZoomStyles.js +5 -3
- package/src/layer/vector/Path.js +11 -5
- package/src/layer/vector/Polygon.js +11 -10
- package/src/layer/vector/Polyline.js +20 -21
- package/src/layer/vector/Renderer.getRenderer.js +2 -1
- package/src/layer/vector/Renderer.js +21 -3
- package/src/layer/vector/SVG.js +3 -3
- package/src/map/Map.Rotation.js +13 -9
- package/src/map/Map.js +195 -83
- package/src/map/MapSync.js +2 -2
- package/src/map/handler/BoxZoomHandler.js +5 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/DragHandler.js +5 -5
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +4 -4
- package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
- package/src/map/handler/TapDragZoomHandler.js +2 -2
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +50 -10
- package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
- package/src/dom/DomEvent.DoubleTap.js +0 -143
|
@@ -81,7 +81,7 @@ var VideoOverlay = class VideoOverlay extends ImageOverlay {
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
if (!Array.isArray(this._url)) this._url = [this._url];
|
|
84
|
-
if (!this.options.keepAspectRatio) vid.style
|
|
84
|
+
if (!this.options.keepAspectRatio) vid.style.objectFit = "fill";
|
|
85
85
|
vid.autoplay = !!this.options.autoplay;
|
|
86
86
|
vid.controls = !!this.options.controls;
|
|
87
87
|
vid.loop = !!this.options.loop;
|
|
@@ -90,7 +90,7 @@ var VideoOverlay = class VideoOverlay extends ImageOverlay {
|
|
|
90
90
|
for (const url of this._url) {
|
|
91
91
|
const source = create("source");
|
|
92
92
|
source.src = url;
|
|
93
|
-
vid.
|
|
93
|
+
vid.append(source);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoOverlay.js","names":["DomUtil.create","Util.splitWords"],"sources":["../../../src/layer/VideoOverlay.js"],"sourcesContent":["import {ImageOverlay} from './ImageOverlay.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as Util from '../core/Util.js';\n\n/** @import {ImageOverlayOptions} from './ImageOverlay.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `VideoOverlay`.\n * @typedef {object} VideoOverlayOptions\n * @property {boolean} [autoplay=true] Whether the video starts playing automatically\n * when loaded. On some browsers autoplay will only work with `muted: true`.\n * @property {boolean} [controls=false] Whether the browser will offer controls to\n * allow the user to control video playback, including volume, seeking, and\n * pause/resume playback.\n * @property {boolean} [loop=true] Whether the video will loop back to the beginning\n * when played.\n * @property {boolean} [keepAspectRatio=true] Whether the video will save aspect ratio\n * after the projection.\n * @property {boolean} [muted=false] Whether the video starts on mute when loaded.\n * @property {boolean} [playsInline=true] Mobile browsers will play the video right\n * where it is instead of open it up in fullscreen mode.\n * @extends ImageOverlayOptions\n */\n\n/**\n * Used to load and display a video player over specific bounds of the map. Extends\n * `ImageOverlay`.\n *\n * A video overlay uses the [`<video>`](https://developer.mozilla.org/docs/Web/HTML/Element/video)\n * HTML element; `getElement()` returns the instance of\n * [`HTMLVideoElement`](https://developer.mozilla.org/docs/Web/API/HTMLVideoElement)\n * used by this overlay.\n *\n * @example\n * ```js\n * const videoUrl = 'https://www.mapbox.com/bites/00188/patricia_nasa.webm',\n * \tvideoBounds = [[ 32, -130], [ 13, -100]];\n * new VideoOverlay(videoUrl, videoBounds ).addTo(map);\n * ```\n *\n * @fires load {MaplairEvent} Fired when the video has finished loading the first frame.\n */\nexport class VideoOverlay extends ImageOverlay {\n\n\tstatic defaultOptions = {\n\t\tautoplay: true,\n\t\tcontrols: false,\n\t\tloop: true,\n\t\tkeepAspectRatio: true,\n\t\tmuted: false,\n\t\tplaysInline: true\n\t};\n\n\t/**\n\t * Instantiates a video overlay object given the URL of the video (or array of\n\t * URLs, or even a video element) and the geographical bounds it is tied to.\n\t * @overload\n\t * @param {string|string[]|HTMLVideoElement} video\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {VideoOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(VideoOverlay);\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url instanceof HTMLVideoElement;\n\t\tconst vid = this._image = wasElementSupplied ? this._url : DomUtil.create('video');\n\n\t\tvid.classList.add('maplair-image-layer', 'maplair-zoom-animated');\n\t\tif (this.options.className) { vid.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\tDomEvent.on(vid, 'pointerdown', (e) => {\n\t\t\tif (vid.controls) {\n\t\t\t\t// Prevent the map from moving when the video or the seekbar is moved\n\t\t\t\tDomEvent.stopPropagation(e);\n\t\t\t}\n\t\t});\n\n\t\tvid.onloadeddata = this.fire.bind(this, 'load');\n\n\t\tif (wasElementSupplied) {\n\t\t\tconst sourceElements = vid.getElementsByTagName('source');\n\t\t\tconst sources = Array.from(sourceElements, e => e.src);\n\t\t\tthis._url = (sourceElements.length > 0) ? sources : [vid.src];\n\t\t\treturn;\n\t\t}\n\n\t\tif (!Array.isArray(this._url)) { this._url = [this._url]; }\n\n\t\tif (!this.options.keepAspectRatio) {\n\t\t\tvid.style
|
|
1
|
+
{"version":3,"file":"VideoOverlay.js","names":["DomUtil.create","Util.splitWords"],"sources":["../../../src/layer/VideoOverlay.js"],"sourcesContent":["import {ImageOverlay} from './ImageOverlay.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as Util from '../core/Util.js';\n\n/** @import {ImageOverlayOptions} from './ImageOverlay.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `VideoOverlay`.\n * @typedef {object} VideoOverlayOptions\n * @property {boolean} [autoplay=true] Whether the video starts playing automatically\n * when loaded. On some browsers autoplay will only work with `muted: true`.\n * @property {boolean} [controls=false] Whether the browser will offer controls to\n * allow the user to control video playback, including volume, seeking, and\n * pause/resume playback.\n * @property {boolean} [loop=true] Whether the video will loop back to the beginning\n * when played.\n * @property {boolean} [keepAspectRatio=true] Whether the video will save aspect ratio\n * after the projection.\n * @property {boolean} [muted=false] Whether the video starts on mute when loaded.\n * @property {boolean} [playsInline=true] Mobile browsers will play the video right\n * where it is instead of open it up in fullscreen mode.\n * @extends ImageOverlayOptions\n */\n\n/**\n * Used to load and display a video player over specific bounds of the map. Extends\n * `ImageOverlay`.\n *\n * A video overlay uses the [`<video>`](https://developer.mozilla.org/docs/Web/HTML/Element/video)\n * HTML element; `getElement()` returns the instance of\n * [`HTMLVideoElement`](https://developer.mozilla.org/docs/Web/API/HTMLVideoElement)\n * used by this overlay.\n *\n * @example\n * ```js\n * const videoUrl = 'https://www.mapbox.com/bites/00188/patricia_nasa.webm',\n * \tvideoBounds = [[ 32, -130], [ 13, -100]];\n * new VideoOverlay(videoUrl, videoBounds ).addTo(map);\n * ```\n *\n * @fires load {MaplairEvent} Fired when the video has finished loading the first frame.\n */\nexport class VideoOverlay extends ImageOverlay {\n\n\tstatic defaultOptions = {\n\t\tautoplay: true,\n\t\tcontrols: false,\n\t\tloop: true,\n\t\tkeepAspectRatio: true,\n\t\tmuted: false,\n\t\tplaysInline: true\n\t};\n\n\t/**\n\t * Instantiates a video overlay object given the URL of the video (or array of\n\t * URLs, or even a video element) and the geographical bounds it is tied to.\n\t * @overload\n\t * @param {string|string[]|HTMLVideoElement} video\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {VideoOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(VideoOverlay);\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url instanceof HTMLVideoElement;\n\t\tconst vid = this._image = wasElementSupplied ? this._url : DomUtil.create('video');\n\n\t\tvid.classList.add('maplair-image-layer', 'maplair-zoom-animated');\n\t\tif (this.options.className) { vid.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\tDomEvent.on(vid, 'pointerdown', (e) => {\n\t\t\tif (vid.controls) {\n\t\t\t\t// Prevent the map from moving when the video or the seekbar is moved\n\t\t\t\tDomEvent.stopPropagation(e);\n\t\t\t}\n\t\t});\n\n\t\tvid.onloadeddata = this.fire.bind(this, 'load');\n\n\t\tif (wasElementSupplied) {\n\t\t\tconst sourceElements = vid.getElementsByTagName('source');\n\t\t\tconst sources = Array.from(sourceElements, e => e.src);\n\t\t\tthis._url = (sourceElements.length > 0) ? sources : [vid.src];\n\t\t\treturn;\n\t\t}\n\n\t\tif (!Array.isArray(this._url)) { this._url = [this._url]; }\n\n\t\tif (!this.options.keepAspectRatio) {\n\t\t\tvid.style.objectFit = 'fill';\n\t\t}\n\t\tvid.autoplay = !!this.options.autoplay;\n\t\tvid.controls = !!this.options.controls;\n\t\tvid.loop = !!this.options.loop;\n\t\tvid.muted = !!this.options.muted;\n\t\tvid.playsInline = !!this.options.playsInline;\n\t\tfor (const url of this._url) {\n\t\t\tconst source = DomUtil.create('source');\n\t\t\tsource.src = url;\n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CAAC,KAAK,QAAQ;EACjC,KAAK,MAAM,OAAO,KAAK,MAAM;GAC5B,MAAM,SAASD,OAAe,QAAQ;GACtC,OAAO,MAAM;GACb,IAAI,OAAO,MAAM;EAClB;CACD;AACD"}
|
|
@@ -54,14 +54,10 @@ var DivIcon = class DivIcon extends Icon {
|
|
|
54
54
|
*/
|
|
55
55
|
createIcon(oldIcon) {
|
|
56
56
|
const div = oldIcon instanceof HTMLDivElement ? oldIcon : document.createElement("div"), options = this.options;
|
|
57
|
-
if (options.html instanceof Element)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (options.bgPos) {
|
|
62
|
-
const bgPos = Point.from(options.bgPos);
|
|
63
|
-
div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
|
|
64
|
-
}
|
|
57
|
+
if (options.html instanceof Element) div.replaceChildren(options.html);
|
|
58
|
+
else div.innerHTML = options.html !== false ? options.html : "";
|
|
59
|
+
const bgPos = options.bgPos && Point.from(options.bgPos);
|
|
60
|
+
div.style.backgroundPosition = bgPos ? `${-bgPos.x}px ${-bgPos.y}px` : "";
|
|
65
61
|
this._setIconStyles(div, "icon");
|
|
66
62
|
return div;
|
|
67
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DivIcon.js","names":[],"sources":["../../../../src/layer/marker/DivIcon.js"],"sourcesContent":["import {Icon} from './Icon.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {IconOptions} from './Icon.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n\n/**\n * Options of `DivIcon`.\n * @typedef {object} DivIconOptions\n * @property {PointExpression|number} [iconSize=[12, 12]] Size of the icon in pixels,\n * also can be set through CSS.\n * @property {string|HTMLElement|false} [html=false] Custom HTML code to put inside the\n * div element, empty by default. Alternatively, an instance of `HTMLElement`.\n * @property {PointExpression|null} [bgPos=null] Optional relative position of the\n * background, in pixels.\n * @property {string} [className='maplair-div-icon']\n * @extends IconOptions\n */\n\n/**\n * Represents a lightweight icon for markers that uses a simple `<div>`\n * element instead of an image. Inherits from `Icon` but ignores the `iconUrl` and\n * shadow options.\n *\n * By default, it has a 'maplair-div-icon' CSS class and is styled as a little white\n * square with a shadow.\n *\n * @example\n * ```js\n * const myIcon = new DivIcon({className: 'my-div-icon'});\n * // you can set .my-div-icon styles in CSS\n *\n * new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);\n * ```\n */\nexport class DivIcon extends Icon {\n\n\tstatic defaultOptions = {\n\t\ticonSize: [12, 12], // also can be set through CSS\n\n\t\t// iconAnchor: (Point),\n\t\t// popupAnchor: (Point),\n\n\t\thtml: false,\n\t\tbgPos: null,\n\t\tclassName: 'maplair-div-icon'\n\t};\n\n\t/**\n\t * Creates a `DivIcon` instance with the given options.\n\t * @param {[options?: DivIconOptions]} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DivIcon);\n\t}\n\n\t/**\n\t * Called internally when the icon has to be shown, returns a `<div>` element\n\t * styled according to the options.\n\t * @param {HTMLElement} [oldIcon] The current element of the icon, to be reused if possible.\n\t * @returns {HTMLElement}\n\t */\n\tcreateIcon(oldIcon) {\n\t\tconst div = oldIcon instanceof HTMLDivElement ? oldIcon : document.createElement('div'),\n\t\toptions = this.options;\n\n\t\tif (options.html instanceof Element) {\n\t\t\tdiv.replaceChildren(
|
|
1
|
+
{"version":3,"file":"DivIcon.js","names":[],"sources":["../../../../src/layer/marker/DivIcon.js"],"sourcesContent":["import {Icon} from './Icon.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {IconOptions} from './Icon.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n\n/**\n * Options of `DivIcon`.\n * @typedef {object} DivIconOptions\n * @property {PointExpression|number} [iconSize=[12, 12]] Size of the icon in pixels,\n * also can be set through CSS.\n * @property {string|HTMLElement|false} [html=false] Custom HTML code to put inside the\n * div element, empty by default. Alternatively, an instance of `HTMLElement`.\n * @property {PointExpression|null} [bgPos=null] Optional relative position of the\n * background, in pixels.\n * @property {string} [className='maplair-div-icon']\n * @extends IconOptions\n */\n\n/**\n * Represents a lightweight icon for markers that uses a simple `<div>`\n * element instead of an image. Inherits from `Icon` but ignores the `iconUrl` and\n * shadow options.\n *\n * By default, it has a 'maplair-div-icon' CSS class and is styled as a little white\n * square with a shadow.\n *\n * @example\n * ```js\n * const myIcon = new DivIcon({className: 'my-div-icon'});\n * // you can set .my-div-icon styles in CSS\n *\n * new Marker([50.505, 30.57], {icon: myIcon}).addTo(map);\n * ```\n */\nexport class DivIcon extends Icon {\n\n\tstatic defaultOptions = {\n\t\ticonSize: [12, 12], // also can be set through CSS\n\n\t\t// iconAnchor: (Point),\n\t\t// popupAnchor: (Point),\n\n\t\thtml: false,\n\t\tbgPos: null,\n\t\tclassName: 'maplair-div-icon'\n\t};\n\n\t/**\n\t * Creates a `DivIcon` instance with the given options.\n\t * @param {[options?: DivIconOptions]} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DivIcon);\n\t}\n\n\t/**\n\t * Called internally when the icon has to be shown, returns a `<div>` element\n\t * styled according to the options.\n\t * @param {HTMLElement} [oldIcon] The current element of the icon, to be reused if possible.\n\t * @returns {HTMLElement}\n\t */\n\tcreateIcon(oldIcon) {\n\t\tconst div = oldIcon instanceof HTMLDivElement ? oldIcon : document.createElement('div'),\n\t\toptions = this.options;\n\n\t\tif (options.html instanceof Element) {\n\t\t\tdiv.replaceChildren(options.html);\n\t\t} else {\n\t\t\tdiv.innerHTML = options.html !== false ? options.html : '';\n\t\t}\n\n\t\tconst bgPos = options.bgPos && Point.from(options.bgPos);\n\t\tdiv.style.backgroundPosition = bgPos ? `${-bgPos.x}px ${-bgPos.y}px` : '';\n\t\tthis._setIconStyles(div, 'icon');\n\n\t\treturn div;\n\t}\n\n\t/**\n\t * Returns `null`, a `DivIcon` has no shadow.\n\t * @returns {null}\n\t */\n\tcreateShadow() {\n\t\treturn null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,UAAb,MAAa,gBAAgB,KAAK;CAEjC,OAAO,iBAAiB;EACvB,UAAU,CAAC,IAAI,EAAE;EAKjB,MAAM;EACN,OAAO;EACP,WAAW;CACZ;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,OAAO;CAC3B;;;;;;;CAQA,WAAW,SAAS;EACnB,MAAM,MAAM,mBAAmB,iBAAiB,UAAU,SAAS,cAAc,KAAK,GACtF,UAAU,KAAK;EAEf,IAAI,QAAQ,gBAAgB,SAC3B,IAAI,gBAAgB,QAAQ,IAAI;OAEhC,IAAI,YAAY,QAAQ,SAAS,QAAQ,QAAQ,OAAO;EAGzD,MAAM,QAAQ,QAAQ,SAAS,MAAM,KAAK,QAAQ,KAAK;EACvD,IAAI,MAAM,qBAAqB,QAAQ,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM;EACvE,KAAK,eAAe,KAAK,MAAM;EAE/B,OAAO;CACR;;;;;CAMA,eAAe;EACd,OAAO;CACR;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setOptions } from "../../core/Util.js";
|
|
1
|
+
import { setOptions, toNumber } from "../../core/Util.js";
|
|
2
2
|
import { Class } from "../../core/Class.js";
|
|
3
3
|
import { Point } from "../../geometry/Point.js";
|
|
4
4
|
// src/layer/marker/Icon.js
|
|
@@ -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
|
|
@@ -99,25 +102,42 @@ var Icon = class Icon extends Class {
|
|
|
99
102
|
const img = this._createImg(src, oldIcon instanceof HTMLImageElement ? oldIcon : null);
|
|
100
103
|
this._setIconStyles(img, name);
|
|
101
104
|
if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
|
|
105
|
+
else img.crossOrigin = null;
|
|
102
106
|
return img;
|
|
103
107
|
}
|
|
108
|
+
_getBox(name) {
|
|
109
|
+
const options = this.options;
|
|
110
|
+
const sizeOption = options[`${name}Size`];
|
|
111
|
+
const [width, height] = (typeof sizeOption === "number" ? [sizeOption, sizeOption] : Array.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);
|
|
112
|
+
const anchorOption = name === "shadow" && options.shadowAnchor || options.iconAnchor;
|
|
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
|
+
}
|
|
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
|
+
}
|
|
104
130
|
_setIconStyles(img, name) {
|
|
105
131
|
const options = this.options;
|
|
106
|
-
|
|
107
|
-
if (typeof sizeOption === "number") sizeOption = [sizeOption, sizeOption];
|
|
108
|
-
const size = Point.validate(sizeOption) && Point.from(sizeOption);
|
|
109
|
-
const anchorPosition = name === "shadow" && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
|
|
110
|
-
const anchor = Point.validate(anchorPosition) && Point.from(anchorPosition);
|
|
132
|
+
const { width, height, anchor } = this._getBox(name);
|
|
111
133
|
img.className = `maplair-marker-${name} ${options.className || ""}`;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
img.style.height = `${size.y}px`;
|
|
120
|
-
}
|
|
134
|
+
const { style } = img;
|
|
135
|
+
style.marginLeft = style.marginTop = style.width = style.height = "";
|
|
136
|
+
if (!isNaN(anchor.x)) style.marginLeft = `${-anchor.x}px`;
|
|
137
|
+
if (!isNaN(anchor.y)) style.marginTop = `${-anchor.y}px`;
|
|
138
|
+
style.transformOrigin = !isNaN(anchor.x) && !isNaN(anchor.y) ? `${anchor.x}px ${anchor.y}px` : "0 0";
|
|
139
|
+
if (!isNaN(width)) style.width = `${width}px`;
|
|
140
|
+
if (!isNaN(height)) style.height = `${height}px`;
|
|
121
141
|
}
|
|
122
142
|
_createImg(src, el) {
|
|
123
143
|
el ??= document.createElement("img");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","names":[],"sources":["../../../../src/layer/marker/Icon.js"],"sourcesContent":["import {Class} from '../../core/Class.js';\nimport {setOptions} from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.js';\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,KAAK,YAAY,UAAU,OAAO;CAC1C;CAEA,YAAY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AAO,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"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Point } from "../../geometry/Point.js";
|
|
2
2
|
import { off, on } from "../../dom/DomEvent.js";
|
|
3
3
|
import { getPosition, setPosition } from "../../dom/DomUtil.js";
|
|
4
|
-
import { Bounds } from "../../geometry/Bounds.js";
|
|
5
4
|
import { Handler } from "../../core/Handler.js";
|
|
6
5
|
import { Draggable } from "../../dom/Draggable.js";
|
|
7
6
|
// src/layer/marker/Marker.Drag.js
|
|
@@ -18,8 +17,8 @@ const arrows = {
|
|
|
18
17
|
* The handler of `Marker` which makes the markers draggable, see the
|
|
19
18
|
* [`dragging`](#marker-dragging) property of markers and its `draggable` option.
|
|
20
19
|
*
|
|
21
|
-
* @fires Marker#dragstart {
|
|
22
|
-
* @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
|
|
23
22
|
* dragging).
|
|
24
23
|
* @fires Marker#drag {MarkerMoveEvent} Fired repeatedly while the user drags the marker.
|
|
25
24
|
* @fires Marker#dragend {DragEndEvent} Fired when the user stops dragging the marker.
|
|
@@ -73,10 +72,10 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
73
72
|
return this._draggable?._moved;
|
|
74
73
|
}
|
|
75
74
|
_adjustPan(e) {
|
|
76
|
-
const marker = this._marker, map = marker._map, speed = this._marker.options.autoPanSpeed, padding = this._marker.options.autoPanPadding, iconPos = getPosition(marker._icon), bounds = map.getPixelBounds(), origin = map.getPixelOrigin();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
const marker = this._marker, map = marker._map, speed = this._marker.options.autoPanSpeed, padding = new Point(this._marker.options.autoPanPadding), iconPos = getPosition(marker._icon), bounds = map.getPixelBounds(), origin = map.getPixelOrigin(), min = bounds.min._subtract(origin)._add(padding), max = bounds.max._subtract(origin)._subtract(padding), dx = Math.max(iconPos.x - max.x, 0) + Math.min(iconPos.x - min.x, 0), dy = Math.max(iconPos.y - max.y, 0) + Math.min(iconPos.y - min.y, 0);
|
|
76
|
+
if (dx || dy) {
|
|
77
|
+
const movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed), map.options.maxBounds)._round();
|
|
78
|
+
if (!movement.x && !movement.y) return;
|
|
80
79
|
map.panBy(movement, { animate: false });
|
|
81
80
|
this._draggable._newPos._add(movement);
|
|
82
81
|
this._draggable._startPos._add(movement);
|
|
@@ -85,10 +84,10 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
85
84
|
this._panRequest = requestAnimationFrame(this._adjustPan.bind(this, e));
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
|
-
_onDragStart() {
|
|
87
|
+
_onDragStart({ originalEvent }) {
|
|
89
88
|
this._oldLatLng = this._marker.getLatLng();
|
|
90
89
|
this._marker.closePopup?.();
|
|
91
|
-
this._marker.fire("movestart").fire("dragstart");
|
|
90
|
+
this._marker.fire("movestart", { originalEvent }).fire("dragstart", { originalEvent });
|
|
92
91
|
}
|
|
93
92
|
_onPreDrag(e) {
|
|
94
93
|
if (this._marker.options.autoPan) {
|
|
@@ -97,7 +96,8 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
_onDrag(e) {
|
|
100
|
-
const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos);
|
|
99
|
+
const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos), { alt } = this._oldLatLng;
|
|
100
|
+
if (alt !== void 0) latlng.alt = alt;
|
|
101
101
|
marker._positionElements(iconPos);
|
|
102
102
|
marker._latlng = latlng;
|
|
103
103
|
e.latlng = latlng;
|
|
@@ -106,7 +106,6 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
106
106
|
}
|
|
107
107
|
_onDragEnd(e) {
|
|
108
108
|
cancelAnimationFrame(this._panRequest);
|
|
109
|
-
delete this._oldLatLng;
|
|
110
109
|
this._marker.fire("moveend").fire("dragend", e);
|
|
111
110
|
}
|
|
112
111
|
/** @param {KeyboardEvent|FocusEvent} e */
|
|
@@ -125,7 +124,7 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
125
124
|
draggable._startPos = getPosition(draggable._element);
|
|
126
125
|
draggable._moved = draggable._moving = true;
|
|
127
126
|
this._keyOffset = new Point(0, 0);
|
|
128
|
-
draggable.fire("dragstart");
|
|
127
|
+
draggable.fire("dragstart", { originalEvent: k });
|
|
129
128
|
}
|
|
130
129
|
const offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);
|
|
131
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 {Bounds} from '../../geometry/Bounds.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 = this._marker.options.autoPanPadding,\n\t\ticonPos = DomUtil.getPosition(marker._icon),\n\t\tbounds = map.getPixelBounds(),\n\t\torigin = map.getPixelOrigin();\n\n\t\tconst panBounds = new Bounds(\n\t\t\tbounds.min._subtract(origin).add(padding),\n\t\t\tbounds.max._subtract(origin).subtract(padding)\n\t\t);\n\n\t\tif (!panBounds.contains(iconPos)) {\n\t\t\t// Compute incremental movement\n\t\t\tconst movement = new Point(\n\t\t\t\t(Math.max(panBounds.max.x, iconPos.x) - panBounds.max.x) / (bounds.max.x - panBounds.max.x) -\n\t\t\t\t(Math.min(panBounds.min.x, iconPos.x) - panBounds.min.x) / (bounds.min.x - panBounds.min.x),\n\n\t\t\t\t(Math.max(panBounds.max.y, iconPos.y) - panBounds.max.y) / (bounds.max.y - panBounds.max.y) -\n\t\t\t\t(Math.min(panBounds.min.y, iconPos.y) - panBounds.min.y) / (bounds.min.y - panBounds.min.y)\n\t\t\t).multiplyBy(speed);\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\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\tdelete this._oldLatLng;\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":";;;;;;;;;;AAWA,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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ErC,OAAO,KAAK;EACZ,KAAK,QACH,KAAK,SAAS,CAAC,CACf,KAAK,WAAW,CAAC;CACpB;;CAKA,OAAO,GAAG;EACT,MAAM,IAAkC,GACxC,MAAM,OAAO,EAAE,MACf,YAAY,KAAK,YACjB,EAAC,SAAS,MAAM,QAAO,KAAK;EAE5B,IAAI,EAAE,SAAS,WACV;OAAA,KAAK,YAAY;IACpB,KAAK,aAAa;IAClB,UAAU,WAAW;GACtB;SAEM,IAAI,OAAO,EAAE,WAAW,UAAU,YAAY,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU;GAC3F,EAAE,eAAe;GAEjB,IAAI,CAAC,KAAK,YAAY;IACrB,IAAI,UAAU,WAAa;IAC3B,UAAU,YAAY;IACtB,UAAU,YAAYA,YAAoB,UAAU,QAAQ;IAC5D,UAAU,SAAS,UAAU,UAAU;IACvC,KAAK,aAAa,IAAI,MAAM,GAAG,CAAC;IAChC,UAAU,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":";;;;;;;;;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,KAA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ACrB,IAAI,UAAU,WAAa;IAC3B,UAAU,YAAY;IACtB,UAAU,YAAYA,YAAoB,UAAU,QAAQ;IAC5D,UAAU,SAAS,UAAU,UAAU;IACvC,KAAK,aAAa,IAAI,MAAM,GAAG,CAAC;IAChC,UAAU,KAAK,aAAa,EAAC,eAAe,EAAC,CAAC;GAC/C;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"}
|
|
@@ -2,6 +2,7 @@ import { setOptions } from "../../core/Util.js";
|
|
|
2
2
|
import { Point } from "../../geometry/Point.js";
|
|
3
3
|
import { off, on } from "../../dom/DomEvent.js";
|
|
4
4
|
import { getPosition, setPosition } from "../../dom/DomUtil.js";
|
|
5
|
+
import { I18n } from "../../core/I18n.js";
|
|
5
6
|
import { Layer } from "../Layer.js";
|
|
6
7
|
import { LatLng } from "../../geo/LatLng.js";
|
|
7
8
|
import { pointToGeoJSON } from "../GeoJSONUtil.js";
|
|
@@ -26,7 +27,8 @@ import { MarkerDrag } from "./Marker.Drag.js";
|
|
|
26
27
|
* @property {string} [title=''] Text for the browser tooltip that appear on marker hover
|
|
27
28
|
* (no tooltip by default).
|
|
28
29
|
* [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
29
|
-
* @property {string} [alt
|
|
30
|
+
* @property {string} [alt] Text for the `alt` attribute of the icon image, the
|
|
31
|
+
* translation of `'Marker'` by default.
|
|
30
32
|
* [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
31
33
|
* @property {number} [zIndexOffset=0] By default, marker images zIndex is set
|
|
32
34
|
* automatically based on its latitude. Use this option if you want to put the marker on
|
|
@@ -38,9 +40,9 @@ import { MarkerDrag } from "./Marker.Drag.js";
|
|
|
38
40
|
* marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
|
|
39
41
|
* under a tilted one. `null` means no rotation.
|
|
40
42
|
* @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
|
|
41
|
-
* others
|
|
42
|
-
* @property {number} [riseOffset=250] The z-index offset used
|
|
43
|
-
*
|
|
43
|
+
* others while the pointer is over it. It always does while it has focus.
|
|
44
|
+
* @property {number} [riseOffset=250] The z-index offset used when the marker gets on
|
|
45
|
+
* top of others on hover or focus.
|
|
44
46
|
* @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.
|
|
45
47
|
* @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will
|
|
46
48
|
* be added.
|
|
@@ -93,7 +95,7 @@ var Marker = class Marker extends Layer {
|
|
|
93
95
|
interactive: true,
|
|
94
96
|
keyboard: true,
|
|
95
97
|
title: "",
|
|
96
|
-
alt:
|
|
98
|
+
alt: void 0,
|
|
97
99
|
zIndexOffset: 0,
|
|
98
100
|
opacity: 1,
|
|
99
101
|
rotation: null,
|
|
@@ -224,7 +226,7 @@ var Marker = class Marker extends Layer {
|
|
|
224
226
|
*/
|
|
225
227
|
update() {
|
|
226
228
|
if (this._icon && this._map && !this._culled) {
|
|
227
|
-
const pos = this._map.latLngToLayerPoint(this._latlng)
|
|
229
|
+
const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
|
|
228
230
|
this._setPos(pos);
|
|
229
231
|
}
|
|
230
232
|
return this;
|
|
@@ -237,7 +239,7 @@ var Marker = class Marker extends Layer {
|
|
|
237
239
|
if (this._icon) this._removeIcon();
|
|
238
240
|
addIcon = true;
|
|
239
241
|
if (options.title) icon.title = options.title;
|
|
240
|
-
if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? "";
|
|
242
|
+
if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? I18n.translate("Marker");
|
|
241
243
|
}
|
|
242
244
|
icon.classList.add(classToAdd);
|
|
243
245
|
if (options.keyboard) {
|
|
@@ -246,10 +248,9 @@ var Marker = class Marker extends Layer {
|
|
|
246
248
|
on(icon, "keydown", this._onKeyDown, this);
|
|
247
249
|
}
|
|
248
250
|
this._icon = icon;
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
});
|
|
251
|
+
if (this._popup?._source === this) this._popup._updateSourceAria(this._popup.isOpen());
|
|
252
|
+
on(icon, "focusin focusout", this._updateRise, this);
|
|
253
|
+
if (options.riseOnHover) on(icon, "pointerover pointerout", this._updateRise, this);
|
|
253
254
|
if (this.options.autoPanOnFocus) on(icon, "focus", this._panOnFocus, this);
|
|
254
255
|
const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
|
|
255
256
|
let addShadow = false;
|
|
@@ -263,15 +264,13 @@ var Marker = class Marker extends Layer {
|
|
|
263
264
|
}
|
|
264
265
|
this._shadow = newShadow;
|
|
265
266
|
if (options.opacity < 1) this._updateOpacity();
|
|
266
|
-
if (addIcon) this.getPane().
|
|
267
|
+
if (addIcon) this.getPane().append(this._icon);
|
|
267
268
|
this._initInteraction();
|
|
268
|
-
if (newShadow && addShadow) this.getPane(options.shadowPane).
|
|
269
|
+
if (newShadow && addShadow) this.getPane(options.shadowPane).append(this._shadow);
|
|
269
270
|
}
|
|
270
271
|
_removeIcon() {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
pointerout: this._resetZIndex
|
|
274
|
-
});
|
|
272
|
+
off(this._icon, "pointerover pointerout focusin focusout", this._updateRise, this);
|
|
273
|
+
this._hovered = this._focused = false;
|
|
275
274
|
if (this.options.autoPanOnFocus) off(this._icon, "focus", this._panOnFocus, this);
|
|
276
275
|
off(this._icon, "keydown", this._onKeyDown, this);
|
|
277
276
|
this._icon.remove();
|
|
@@ -284,8 +283,8 @@ var Marker = class Marker extends Layer {
|
|
|
284
283
|
if (visible === !this._culled) return;
|
|
285
284
|
this._culled = !visible;
|
|
286
285
|
if (visible) {
|
|
287
|
-
this.getPane().
|
|
288
|
-
if (this._shadow) this.getPane(this.options.shadowPane).
|
|
286
|
+
this.getPane().append(this._icon);
|
|
287
|
+
if (this._shadow) this.getPane(this.options.shadowPane).append(this._shadow);
|
|
289
288
|
this.update();
|
|
290
289
|
} else {
|
|
291
290
|
this._icon.remove();
|
|
@@ -298,8 +297,8 @@ var Marker = class Marker extends Layer {
|
|
|
298
297
|
}
|
|
299
298
|
_setPos(pos) {
|
|
300
299
|
this._positionElements(pos);
|
|
301
|
-
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
302
|
-
this.
|
|
300
|
+
this._zIndex = Math.round(pos.y) + this.options.zIndexOffset;
|
|
301
|
+
this._updateRise();
|
|
303
302
|
}
|
|
304
303
|
_positionElements(pos) {
|
|
305
304
|
const rotation = this.options.rotation;
|
|
@@ -318,7 +317,7 @@ var Marker = class Marker extends Layer {
|
|
|
318
317
|
}
|
|
319
318
|
_animateZoom(opt) {
|
|
320
319
|
if (this._culled) return;
|
|
321
|
-
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));
|
|
322
321
|
this._setPos(pos);
|
|
323
322
|
}
|
|
324
323
|
_updateInteractive() {
|
|
@@ -341,33 +340,31 @@ var Marker = class Marker extends Layer {
|
|
|
341
340
|
if (!this.options.interactive) return;
|
|
342
341
|
this._icon.classList.add("maplair-interactive");
|
|
343
342
|
this.addInteractiveTarget(this._icon);
|
|
344
|
-
if (
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
let draggable = this.options.draggable;
|
|
350
|
-
if (this.dragging) {
|
|
351
|
-
draggable = this.dragging.enabled();
|
|
352
|
-
this.dragging.disable();
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Marker dragging handler, see `Handler`. Only valid when the marker is on the
|
|
356
|
-
* map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
|
|
357
|
-
*
|
|
358
|
-
* Interaction handlers are properties of a marker instance that allow you to
|
|
359
|
-
* control interaction behavior in runtime, enabling or disabling certain
|
|
360
|
-
* features such as dragging (see `Handler` methods). Example:
|
|
361
|
-
*
|
|
362
|
-
* ```js
|
|
363
|
-
* marker.dragging.disable();
|
|
364
|
-
* ```
|
|
365
|
-
* @group Interaction handlers
|
|
366
|
-
* @type {MarkerDrag}
|
|
367
|
-
*/
|
|
368
|
-
this.dragging = new MarkerDrag(this);
|
|
369
|
-
if (draggable) this.dragging.enable();
|
|
343
|
+
if (this.dragging?._draggable?._element === this._icon) {
|
|
344
|
+
this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
|
|
345
|
+
return;
|
|
370
346
|
}
|
|
347
|
+
let draggable = this.options.draggable;
|
|
348
|
+
if (this.dragging) {
|
|
349
|
+
draggable = this.dragging.enabled();
|
|
350
|
+
this.dragging.disable();
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Marker dragging handler, see `Handler`. Only valid when the marker is on the
|
|
354
|
+
* map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
|
|
355
|
+
*
|
|
356
|
+
* Interaction handlers are properties of a marker instance that allow you to
|
|
357
|
+
* control interaction behavior in runtime, enabling or disabling certain
|
|
358
|
+
* features such as dragging (see `Handler` methods). Example:
|
|
359
|
+
*
|
|
360
|
+
* ```js
|
|
361
|
+
* marker.dragging.disable();
|
|
362
|
+
* ```
|
|
363
|
+
* @group Interaction handlers
|
|
364
|
+
* @type {MarkerDrag}
|
|
365
|
+
*/
|
|
366
|
+
this.dragging = new MarkerDrag(this);
|
|
367
|
+
if (draggable) this.dragging.enable();
|
|
371
368
|
}
|
|
372
369
|
/**
|
|
373
370
|
* Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
|
|
@@ -401,9 +398,13 @@ var Marker = class Marker extends Layer {
|
|
|
401
398
|
return this;
|
|
402
399
|
}
|
|
403
400
|
_updateOpacity() {
|
|
404
|
-
const opacity = this.options.opacity
|
|
405
|
-
|
|
406
|
-
|
|
401
|
+
for (const el of [this._icon, this._shadow]) if (el) el.style.opacity = `${this.options.opacity}`;
|
|
402
|
+
}
|
|
403
|
+
_updateRise(e) {
|
|
404
|
+
if (e?.type.startsWith("pointer")) this._hovered = e.type === "pointerover";
|
|
405
|
+
else if (e) this._focused = e.type === "focusin";
|
|
406
|
+
if (this._hovered || this._focused) this._bringToFront();
|
|
407
|
+
else this._resetZIndex();
|
|
407
408
|
}
|
|
408
409
|
_bringToFront() {
|
|
409
410
|
this._updateZIndex(this.options.riseOffset);
|
|
@@ -431,8 +432,8 @@ var Marker = class Marker extends Layer {
|
|
|
431
432
|
_getPopupAnchor() {
|
|
432
433
|
return this._rotateAnchor(this.options.icon.options.popupAnchor);
|
|
433
434
|
}
|
|
434
|
-
_getTooltipAnchor() {
|
|
435
|
-
return this._rotateAnchor(this.options.icon.
|
|
435
|
+
_getTooltipAnchor(direction) {
|
|
436
|
+
return this._rotateAnchor(this.options.icon._getTooltipAnchor(direction));
|
|
436
437
|
}
|
|
437
438
|
_rotateAnchor(anchor) {
|
|
438
439
|
const angle = this.options.rotation * Math.PI / 180;
|