maplair 4.0.0 → 4.2.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 +178 -0
- package/dist/esm/Maplair.js +18 -17
- package/dist/esm/Maplair.js.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
- package/dist/esm/control/AttributionControl.js +25 -16
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +10 -13
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +2 -5
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +10 -18
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +6 -9
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +170 -65
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/LegendControl.js +8 -11
- package/dist/esm/control/LegendControl.js.map +1 -1
- package/dist/esm/control/MiniMapControl.js +15 -18
- package/dist/esm/control/MiniMapControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +2 -5
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +8 -11
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SearchControl.js +100 -19
- package/dist/esm/control/SearchControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +2 -5
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/TextControl.js +6 -9
- package/dist/esm/control/TextControl.js.map +1 -1
- package/dist/esm/control/TimeControl.js +407 -0
- package/dist/esm/control/TimeControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +23 -36
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Class.js +28 -44
- package/dist/esm/core/Class.js.map +1 -1
- package/dist/esm/core/Events.js +22 -10
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Handler.js +23 -14
- package/dist/esm/core/Handler.js.map +1 -1
- package/dist/esm/core/I18n.js +1 -2
- package/dist/esm/core/Util.js +15 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +18 -60
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +15 -70
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +21 -21
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/dom/PosAnimation.js +4 -27
- package/dist/esm/dom/PosAnimation.js.map +1 -1
- package/dist/esm/geo/LatLng.js +16 -7
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +9 -15
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geo/crs/CRS.js +1 -2
- package/dist/esm/geo/crs/EPSG3395.js +5 -6
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
- package/dist/esm/geo/crs/EPSG3857.js +5 -6
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
- package/dist/esm/geo/crs/EPSG4326.js +4 -5
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
- package/dist/esm/geo/crs/EarthCRS.js +3 -4
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
- package/dist/esm/geo/crs/SimpleCRS.js +4 -5
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
- package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
- package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
- package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
- package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
- package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +10 -14
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/LineUtil.js +37 -32
- package/dist/esm/geometry/LineUtil.js.map +1 -1
- package/dist/esm/geometry/Point.js +1 -2
- package/dist/esm/geometry/PolyUtil.js +24 -51
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -2
- package/dist/esm/layer/BlanketOverlay.js +7 -10
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/Classification.js +1 -2
- package/dist/esm/layer/DivOverlay.js +16 -22
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/FeatureGroup.js +5 -4
- package/dist/esm/layer/FeatureGroup.js.map +1 -1
- package/dist/esm/layer/GeoJSON.Load.js +1 -2
- package/dist/esm/layer/GeoJSON.js +17 -155
- package/dist/esm/layer/GeoJSON.js.map +1 -1
- package/dist/esm/layer/GeoJSONUtil.js +74 -0
- package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
- package/dist/esm/layer/HeatLayer.js +17 -20
- package/dist/esm/layer/HeatLayer.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +22 -29
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +9 -12
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/LayerGroup.js +53 -3
- package/dist/esm/layer/LayerGroup.js.map +1 -1
- package/dist/esm/layer/Popup.js +35 -58
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/SVGOverlay.js +3 -7
- package/dist/esm/layer/SVGOverlay.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +31 -34
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +13 -17
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DefaultIcon.js +38 -49
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +8 -11
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +9 -12
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +44 -5
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Move.js +5 -8
- package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +115 -47
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
- package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
- package/dist/esm/layer/marker/SvgIcon.js +7 -10
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +89 -101
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +36 -44
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +8 -17
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +6 -5
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +19 -10
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
- package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
- package/dist/esm/layer/vector/Path.js +28 -22
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +22 -7
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
- package/dist/esm/layer/vector/Polyline.js +25 -10
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Rectangle.js +1 -2
- package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +1 -2
- package/dist/esm/layer/vector/SVG.js +12 -9
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Hash.js +1 -2
- package/dist/esm/map/Map.Rotation.js +41 -22
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +125 -126
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -2
- package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +7 -10
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
- package/dist/esm/map/handler/DragHandler.js +20 -21
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +48 -68
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
- package/dist/esm/map/handler/TapHoldHandler.js +13 -7
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +2 -3
- package/dist/maplair-global-src.js +6495 -5981
- 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 +6206 -5673
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1213
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/cs.json +6 -0
- package/i18n/de.json +6 -0
- package/i18n/en.json +6 -0
- package/i18n/es.json +6 -0
- package/i18n/fr.json +6 -0
- package/i18n/hu.json +6 -0
- package/i18n/it.json +6 -0
- package/i18n/rm.json +6 -0
- package/i18n/sk.json +6 -0
- package/i18n/sl.json +6 -0
- package/package.json +11 -18
- package/src/Maplair.all.js +0 -1
- package/src/control/AttributionControl.js +25 -18
- package/src/control/ButtonControl.js +9 -11
- package/src/control/ContextMenu.js +3 -5
- package/src/control/Control.js +9 -19
- package/src/control/FullscreenControl.js +5 -7
- package/src/control/LayersControl.js +196 -86
- package/src/control/LegendControl.js +7 -9
- package/src/control/MiniMapControl.js +9 -11
- package/src/control/RotateControl.js +3 -5
- package/src/control/ScaleControl.js +7 -9
- package/src/control/SearchControl.js +102 -19
- package/src/control/SideBySideControl.js +3 -5
- package/src/control/TextControl.js +5 -7
- package/src/control/TimeControl.js +471 -0
- package/src/control/ZoomControl.js +22 -38
- package/src/control/index.js +1 -0
- package/src/core/Class.js +37 -45
- package/src/core/Events.js +22 -3
- package/src/core/Handler.js +25 -13
- package/src/core/Util.js +20 -2
- package/src/core/index.js +0 -1
- package/src/dom/DomEvent.DoubleTap.js +18 -10
- package/src/dom/DomEvent.PointerEvents.js +3 -26
- package/src/dom/DomEvent.js +17 -85
- package/src/dom/DomUtil.js +22 -78
- package/src/dom/Draggable.js +32 -23
- package/src/dom/PosAnimation.js +3 -25
- package/src/dom/index.js +0 -1
- package/src/geo/LatLng.js +20 -3
- package/src/geo/LatLngBounds.js +8 -15
- package/src/geo/crs/EPSG3395.js +4 -4
- package/src/geo/crs/EPSG3857.js +4 -4
- package/src/geo/crs/EPSG4326.js +3 -3
- package/src/geo/crs/EarthCRS.js +2 -8
- package/src/geo/crs/SimpleCRS.js +3 -3
- package/src/geo/index.js +1 -2
- package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
- package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
- package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
- package/src/geo/projection/index.js +5 -5
- package/src/geometry/Bounds.js +12 -17
- package/src/geometry/LineUtil.js +48 -49
- package/src/geometry/PolyUtil.js +39 -76
- package/src/layer/BlanketOverlay.js +6 -10
- package/src/layer/DivOverlay.js +16 -27
- package/src/layer/FeatureGroup.js +8 -2
- package/src/layer/GeoJSON.js +17 -218
- package/src/layer/GeoJSONUtil.js +85 -0
- package/src/layer/HeatLayer.js +10 -12
- package/src/layer/ImageOverlay.js +21 -32
- package/src/layer/Layer.js +8 -10
- package/src/layer/LayerGroup.js +72 -1
- package/src/layer/Popup.js +37 -62
- package/src/layer/SVGOverlay.js +1 -5
- package/src/layer/Tooltip.js +34 -36
- package/src/layer/VideoOverlay.js +12 -15
- package/src/layer/marker/DefaultIcon.js +40 -58
- package/src/layer/marker/DivIcon.js +9 -11
- package/src/layer/marker/Icon.js +9 -10
- package/src/layer/marker/Marker.Drag.js +54 -6
- package/src/layer/marker/Marker.Move.js +4 -6
- package/src/layer/marker/Marker.js +145 -52
- package/src/layer/marker/MarkerClusterGroup.js +370 -0
- package/src/layer/marker/SvgIcon.js +7 -9
- package/src/layer/marker/index.js +1 -0
- package/src/layer/tile/GridLayer.js +108 -135
- package/src/layer/tile/TileLayer.js +44 -49
- package/src/layer/tile/WMSTileLayer.js +31 -26
- package/src/layer/vector/Canvas.js +13 -19
- package/src/layer/vector/Circle.js +9 -3
- package/src/layer/vector/CircleMarker.js +19 -7
- package/src/layer/vector/Path.DashAnimation.js +1 -2
- package/src/layer/vector/Path.js +30 -21
- package/src/layer/vector/Polygon.js +29 -6
- package/src/layer/vector/Polyline.js +26 -7
- package/src/layer/vector/Renderer.getRenderer.js +20 -19
- package/src/layer/vector/SVG.js +17 -7
- package/src/map/Map.Rotation.js +40 -8
- package/src/map/Map.js +158 -153
- package/src/map/handler/BoxZoomHandler.js +30 -50
- package/src/map/handler/DisplaceHandler.js +6 -8
- package/src/map/handler/DragHandler.js +25 -28
- package/src/map/handler/KeyboardHandler.js +65 -90
- package/src/map/handler/PinchZoomHandler.js +16 -5
- package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
- package/src/map/handler/TapHoldHandler.js +15 -4
- package/src/map/index.js +1 -1
- package/src/maplair.css +153 -98
- package/dist/esm/core/Browser.js +0 -100
- package/dist/esm/core/Browser.js.map +0 -1
- package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
- package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
- package/dist/esm/geo/projection/index.js +0 -14
- package/dist/esm/geo/projection/index.js.map +0 -1
- package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
- package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
- package/dist/images/layers.svg +0 -1
- package/dist/images/marker-icon.svg +0 -1
- package/dist/images/marker-shadow.svg +0 -1
- package/src/core/Browser.js +0 -110
- package/src/images/layers.svg +0 -1
- package/src/images/marker-icon.svg +0 -1
- package/src/images/marker-shadow.svg +0 -1
- package/src/layer/marker/Marker.Rotation.js +0 -103
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { Point } from "../../geometry/Point.js";
|
|
2
|
+
import { off, on } from "../../dom/DomEvent.js";
|
|
2
3
|
import { getPosition, setPosition } from "../../dom/DomUtil.js";
|
|
3
4
|
import { Bounds } from "../../geometry/Bounds.js";
|
|
4
5
|
import { Handler } from "../../core/Handler.js";
|
|
5
6
|
import { Draggable } from "../../dom/Draggable.js";
|
|
6
|
-
|
|
7
|
+
// src/layer/marker/Marker.Drag.js
|
|
7
8
|
/** @import {Marker, MarkerMoveEvent} from './Marker.js' */
|
|
8
9
|
/** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */
|
|
10
|
+
/** @type {Record<string, [number, number]>} */
|
|
11
|
+
const arrows = {
|
|
12
|
+
ArrowLeft: [-1, 0],
|
|
13
|
+
ArrowRight: [1, 0],
|
|
14
|
+
ArrowUp: [0, -1],
|
|
15
|
+
ArrowDown: [0, 1]
|
|
16
|
+
};
|
|
9
17
|
/**
|
|
10
18
|
* The handler of `Marker` which makes the markers draggable, see the
|
|
11
19
|
* [`dragging`](#marker-dragging) property of markers and its `draggable` option.
|
|
@@ -33,25 +41,28 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
33
41
|
*/
|
|
34
42
|
addHooks() {
|
|
35
43
|
const icon = this._marker._icon;
|
|
36
|
-
if (!this._draggable) this._draggable = new Draggable(icon
|
|
44
|
+
if (!this._draggable) this._draggable = new Draggable(icon);
|
|
37
45
|
this._draggable.on({
|
|
38
46
|
dragstart: this._onDragStart,
|
|
39
47
|
predrag: this._onPreDrag,
|
|
40
48
|
drag: this._onDrag,
|
|
41
49
|
dragend: this._onDragEnd
|
|
42
50
|
}, this).enable();
|
|
51
|
+
on(icon, "keydown keyup blur", this._onKey, this);
|
|
43
52
|
icon.classList.add("maplair-marker-draggable");
|
|
44
53
|
}
|
|
45
54
|
/**
|
|
46
55
|
* Makes the icon of the marker undraggable, called by `disable()`.
|
|
47
56
|
*/
|
|
48
57
|
removeHooks() {
|
|
58
|
+
this._keyOffset = null;
|
|
49
59
|
this._draggable.off({
|
|
50
60
|
dragstart: this._onDragStart,
|
|
51
61
|
predrag: this._onPreDrag,
|
|
52
62
|
drag: this._onDrag,
|
|
53
63
|
dragend: this._onDragEnd
|
|
54
64
|
}, this).disable();
|
|
65
|
+
off(this._draggable._element, "keydown keyup blur", this._onKey, this);
|
|
55
66
|
this._marker._icon?.classList.remove("maplair-marker-draggable");
|
|
56
67
|
}
|
|
57
68
|
/**
|
|
@@ -86,8 +97,8 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
86
97
|
}
|
|
87
98
|
}
|
|
88
99
|
_onDrag(e) {
|
|
89
|
-
const marker = this._marker,
|
|
90
|
-
|
|
100
|
+
const marker = this._marker, iconPos = getPosition(marker._icon), latlng = marker._map.layerPointToLatLng(iconPos);
|
|
101
|
+
marker._positionElements(iconPos);
|
|
91
102
|
marker._latlng = latlng;
|
|
92
103
|
e.latlng = latlng;
|
|
93
104
|
e.oldLatLng = this._oldLatLng;
|
|
@@ -98,8 +109,36 @@ var MarkerDrag = class MarkerDrag extends Handler {
|
|
|
98
109
|
delete this._oldLatLng;
|
|
99
110
|
this._marker.fire("moveend").fire("dragend", e);
|
|
100
111
|
}
|
|
112
|
+
/** @param {KeyboardEvent|FocusEvent} e */
|
|
113
|
+
_onKey(e) {
|
|
114
|
+
const k = e, dir = arrows[k.key], draggable = this._draggable, { options, _map: map } = this._marker;
|
|
115
|
+
if (e.type !== "keydown") {
|
|
116
|
+
if (this._keyOffset) {
|
|
117
|
+
this._keyOffset = null;
|
|
118
|
+
draggable.finishDrag();
|
|
119
|
+
}
|
|
120
|
+
} else if (dir && k.target === draggable._element && !(k.altKey || k.ctrlKey || k.metaKey)) {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
if (!this._keyOffset) {
|
|
123
|
+
if (Draggable._dragging) return;
|
|
124
|
+
Draggable._dragging = draggable;
|
|
125
|
+
draggable._startPos = getPosition(draggable._element);
|
|
126
|
+
draggable._moved = draggable._moving = true;
|
|
127
|
+
this._keyOffset = new Point(0, 0);
|
|
128
|
+
draggable.fire("dragstart");
|
|
129
|
+
}
|
|
130
|
+
const offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);
|
|
131
|
+
this._keyOffset = this._keyOffset.add(map._rotateToPane?.(offset) ?? offset);
|
|
132
|
+
draggable._newPos = draggable._startPos.add(this._keyOffset);
|
|
133
|
+
setPosition(draggable._element, draggable._newPos);
|
|
134
|
+
draggable.fire("drag", { originalEvent: k });
|
|
135
|
+
if (options.autoPan) map.panInside(this._marker._latlng, {
|
|
136
|
+
padding: options.autoPanPadding,
|
|
137
|
+
animate: false
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
101
141
|
};
|
|
102
|
-
//#endregion
|
|
103
142
|
export { MarkerDrag };
|
|
104
143
|
|
|
105
144
|
//# sourceMappingURL=Marker.Drag.js.map
|
|
@@ -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 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/**\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, icon, true);\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\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._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\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\tshadow = marker._shadow,\n\t\ticonPos = DomUtil.getPosition(marker._icon),\n\t\tlatlng = marker._map.layerPointToLatLng(iconPos);\n\n\t\t// update shadow position\n\t\tif (shadow) {\n\t\t\tDomUtil.setPosition(shadow, iconPos);\n\t\t}\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,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,YAC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CAAC,IAAI,UAAU,IAAI,MAAM,OAAO,IAAI,IAAI,UAAU,IAAI,EAC1F,CAAC,CAAC,WAAW,KAAK;GAElB,IAAI,MAAM,UAAU,EAAC,SAAS,MAAK,CAAC;GAEpC,KAAK,WAAW,QAAQ,KAAK,QAAQ;GACrC,KAAK,WAAW,UAAU,KAAK,QAAQ;GAEvC,YAAoB,OAAO,OAAO,KAAK,WAAW,OAAO;GACzD,KAAK,QAAQ,CAAC;GAEd,KAAK,cAAc,sBAAsB,KAAK,WAAW,KAAK,MAAM,CAAC,CAAC;EACvE;CACD;CAEA,eAAe;EACd,KAAK,aAAa,KAAK,QAAQ,UAAU;EAGzC,KAAK,QAAQ,aAAa;EAE1B,KAAK,QACH,KAAK,WAAW,CAAC,CACjB,KAAK,WAAW;CACnB;CAEA,WAAW,GAAG;EACb,IAAI,KAAK,QAAQ,QAAQ,SAAS;GACjC,qBAAqB,KAAK,WAAW;GACrC,KAAK,cAAc,sBAAsB,KAAK,WAAW,KAAK,MAAM,CAAC,CAAC;EACvE;CACD;CAEA,QAAQ,GAAG;EACV,MAAM,SAAS,KAAK,SACpB,SAAS,OAAO,SAChB,UAAUA,YAAoB,OAAO,KAAK,GAC1C,SAAS,OAAO,KAAK,mBAAmB,OAAO;EAG/C,IAAI,QACH,YAAoB,QAAQ,OAAO;EAGpC,OAAO,UAAU;EACjB,EAAE,SAAS;EACX,EAAE,YAAY,KAAK;EAEnB,OACE,KAAK,QAAQ,CAAC,CAAC,CACf,KAAK,QAAQ,CAAC;CACjB;CAEA,WAAW,GAAG;EACb,qBAAqB,KAAK,WAAW;EAErC,OAAO,KAAK;EACZ,KAAK,QACH,KAAK,SAAS,CAAC,CACf,KAAK,WAAW,CAAC;CACpB;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 {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,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,G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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,8 +1,7 @@
|
|
|
1
1
|
import { Point } from "../../geometry/Point.js";
|
|
2
|
-
import Browser_default from "../../core/Browser.js";
|
|
3
2
|
import { LatLng } from "../../geo/LatLng.js";
|
|
4
3
|
import { Marker } from "./Marker.js";
|
|
5
|
-
|
|
4
|
+
// src/layer/marker/Marker.Move.js
|
|
6
5
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
7
6
|
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
8
7
|
/** @import {MaplairEvent} from '../../core/Events.js' */
|
|
@@ -12,9 +11,8 @@ import { Marker } from "./Marker.js";
|
|
|
12
11
|
* @property {number} [duration=1000] The duration of the movement in milliseconds.
|
|
13
12
|
* @property {number} [speed] The speed in meters (or units of the CRS) per second
|
|
14
13
|
* instead of the `duration`.
|
|
15
|
-
* @property {boolean} [rotate=false] Whether to set the `
|
|
16
|
-
* the heading of the movement (for icons pointing up
|
|
17
|
-
* `rotationAngle`).
|
|
14
|
+
* @property {boolean} [rotate=false] Whether to set the `rotation` of the marker to
|
|
15
|
+
* the heading of the movement (for icons pointing up).
|
|
18
16
|
*/
|
|
19
17
|
const { onRemove } = Marker.prototype;
|
|
20
18
|
/** @typedef {typeof markerMoveMethods} MarkerMoveMethods */
|
|
@@ -46,14 +44,14 @@ Marker.include({
|
|
|
46
44
|
this.stopMoving();
|
|
47
45
|
const points = [this._latlng, ...latlngs.map((latlng) => LatLng.from(latlng))], lengths = points.slice(1).map((point, i) => this._map?.distance(points[i], point) ?? points[i].distanceTo(point)), total = lengths.reduce((sum, length) => sum + length, 0), duration = options.speed ? total / options.speed * 1e3 : options.duration ?? 1e3, start = performance.now();
|
|
48
46
|
const frame = () => {
|
|
49
|
-
let distance = duration && !
|
|
47
|
+
let distance = duration && !this._map?._prefersReducedMotion() ? Math.min(1, (performance.now() - start) / duration) * total : total, i = 0;
|
|
50
48
|
const moved = distance;
|
|
51
49
|
while (i < lengths.length - 1 && distance > lengths[i]) {
|
|
52
50
|
distance -= lengths[i];
|
|
53
51
|
i++;
|
|
54
52
|
}
|
|
55
53
|
const from = points[i], to = points[i + 1];
|
|
56
|
-
if (options.rotate && !from.equals(to)) this.options.
|
|
54
|
+
if (options.rotate && !from.equals(to)) this.options.rotation = this._heading(from, to);
|
|
57
55
|
this.setLatLng(this._interpolate(from, to, lengths[i] ? Math.min(1, distance / lengths[i]) : 1));
|
|
58
56
|
if (moved < total) this._moveFrame = requestAnimationFrame(frame);
|
|
59
57
|
else {
|
|
@@ -102,6 +100,5 @@ Marker.include({
|
|
|
102
100
|
return onRemove.call(this, map);
|
|
103
101
|
}
|
|
104
102
|
});
|
|
105
|
-
//#endregion
|
|
106
103
|
|
|
107
104
|
//# sourceMappingURL=Marker.Move.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Marker.Move.js","names":[
|
|
1
|
+
{"version":3,"file":"Marker.Move.js","names":[],"sources":["../../../../src/layer/marker/Marker.Move.js"],"sourcesContent":["import {Marker} from './Marker.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * Options of the movement of markers, see `moveAlong()`.\n * @typedef {object} MarkerMovementOptions\n * @property {number} [duration=1000] The duration of the movement in milliseconds.\n * @property {number} [speed] The speed in meters (or units of the CRS) per second\n * instead of the `duration`.\n * @property {boolean} [rotate=false] Whether to set the `rotation` of the marker to\n * the heading of the movement (for icons pointing up).\n */\n\n// The methods extended below\nconst {onRemove} = Marker.prototype;\n\n/**\n * Methods of `Marker` for the animated movement of markers, an optional feature: import\n * this module to add `moveTo()`, `moveAlong()`, `stopMoving()` and `isMoving()` to\n * `Marker`.\n *\n * ```js\n * import 'maplair/marker-movement';\n *\n * marker.moveAlong([[47.27, 11.40], [47.28, 11.42]], {duration: 5000});\n * ```\n *\n * Inspired by the [Leaflet.MovingMarker](https://github.com/ewoken/Leaflet.MovingMarker)\n * and [Leaflet.AnimatedMarker](https://github.com/openplans/Leaflet.AnimatedMarker) plugins.\n * @lends Marker.prototype\n * @fires Marker#moveend {MaplairEvent} Fired when the marker stops moving (after dragging\n * or `moveAlong()`).\n */\nconst markerMoveMethods = {\n\t/**\n\t * Moves the marker smoothly to `latlng`, see `moveAlong()`.\n\t * @group Marker movement\n\t * @param {LatLngExpression} latlng\n\t * @param {MarkerMovementOptions} [options]\n\t * @returns {this}\n\t */\n\tmoveTo(latlng, options) {\n\t\treturn this.moveAlong([latlng], options);\n\t},\n\n\t/**\n\t * Moves the marker smoothly along the given points, frame by frame at a constant\n\t * speed, e.g. to follow a vehicle or to replay a track. Fires `move` with each\n\t * frame and `moveend` at the end. A new movement or `stopMoving()` stops it; with\n\t * [reduced motion](https://developer.mozilla.org/docs/Web/CSS/@media/prefers-reduced-motion),\n\t * the marker jumps to the end.\n\t * Inspired by the [Leaflet.MovingMarker](https://github.com/ewoken/Leaflet.MovingMarker)\n\t * and [Leaflet.AnimatedMarker](https://github.com/openplans/Leaflet.AnimatedMarker) plugins.\n\t * @group Marker movement\n\t * @param {LatLngExpression[]} latlngs\n\t * @param {MarkerMovementOptions} [options]\n\t * @returns {this}\n\t */\n\tmoveAlong(latlngs, options = {}) {\n\t\tthis.stopMoving();\n\n\t\tconst points = [this._latlng, ...latlngs.map(latlng => LatLng.from(latlng))],\n\t\tlengths = points.slice(1).map((point, i) => this._map?.distance(points[i], point) ?? points[i].distanceTo(point)),\n\t\ttotal = lengths.reduce((sum, length) => sum + length, 0),\n\t\tduration = options.speed ? total / options.speed * 1000 : (options.duration ?? 1000),\n\t\tstart = performance.now();\n\n\t\tconst frame = () => {\n\t\t\t// the distance moved, at a constant speed\n\t\t\tlet distance = duration && !this._map?._prefersReducedMotion() ? Math.min(1, (performance.now() - start) / duration) * total : total,\n\t\t\ti = 0;\n\t\t\tconst moved = distance;\n\t\t\twhile (i < lengths.length - 1 && distance > lengths[i]) {\n\t\t\t\tdistance -= lengths[i];\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tconst from = points[i], to = points[i + 1];\n\t\t\tif (options.rotate && !from.equals(to)) {\n\t\t\t\tthis.options.rotation = this._heading(from, to);\n\t\t\t}\n\t\t\tthis.setLatLng(this._interpolate(from, to, lengths[i] ? Math.min(1, distance / lengths[i]) : 1));\n\n\t\t\tif (moved < total) {\n\t\t\t\tthis._moveFrame = requestAnimationFrame(frame);\n\t\t\t} else {\n\t\t\t\tthis._moveFrame = null;\n\t\t\t\tthis.fire('moveend');\n\t\t\t}\n\t\t};\n\t\tthis._moveFrame = requestAnimationFrame(frame);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Stops the movement of `moveTo()` or `moveAlong()`.\n\t * @group Marker movement\n\t * @returns {this}\n\t */\n\tstopMoving() {\n\t\tcancelAnimationFrame(this._moveFrame);\n\t\tthis._moveFrame = null;\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` while the marker moves with `moveTo()` or `moveAlong()`.\n\t * @group Marker movement\n\t * @returns {boolean}\n\t */\n\tisMoving() {\n\t\treturn !!this._moveFrame;\n\t},\n\n\t// A straight line in the projection of the map (if any)\n\t_interpolate(from, to, t) {\n\t\tconst crs = this._map?.options.crs;\n\t\tif (!crs) {\n\t\t\treturn new LatLng(from.lat + (to.lat - from.lat) * t, from.lng + (to.lng - from.lng) * t);\n\t\t}\n\t\tconst a = crs.projection.project(from),\n\t\tb = crs.projection.project(to);\n\t\treturn crs.projection.unproject(a.add(b.subtract(a).multiplyBy(t)));\n\t},\n\n\t// The heading from `from` to `to` in degrees clockwise from north, relative to\n\t// the screen unless the icon rotates with the view\n\t_heading(from, to) {\n\t\tconst crs = this._map?.options.crs,\n\t\ta = crs ? crs.latLngToPoint(from, 0) : new Point(from.lng, -from.lat),\n\t\tb = crs ? crs.latLngToPoint(to, 0) : new Point(to.lng, -to.lat),\n\t\theading = Math.atan2(b.x - a.x, a.y - b.y) * 180 / Math.PI;\n\t\treturn heading - (this.options.rotateWithView ? 0 : (this._map?.getBearing?.() ?? 0));\n\t},\n\n\t/**\n\t * Stops the movement when the marker is removed from the map.\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tthis.stopMoving();\n\t\treturn onRemove.call(this, map);\n\t}\n};\n/** @typedef {typeof markerMoveMethods} MarkerMoveMethods */\n\nMarker.include(markerMoveMethods);\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,MAAM,EAAC,aAAY,OAAO;;AAoI1B,OAAO,QAAQ;;;;;;;;CAzGd,OAAO,QAAQ,SAAS;EACvB,OAAO,KAAK,UAAU,CAAC,MAAM,GAAG,OAAO;CACxC;;;;;;;;;;;;;;CAeA,UAAU,SAAS,UAAU,CAAC,GAAG;EAChC,KAAK,WAAW;EAEhB,MAAM,SAAS,C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AQ;EAC/B,IAAI,CAAC,KACJ,OAAO,IAAI,OAAO,KAAK,OAAO,GAAG,MAAM,KAAK,OAAO,GAAG,KAAK,OAAO,GAAG,MAAM,KAAK,OAAO,CAAC;EAEzF,MAAM,IAAI,IAAI,WAAW,QAAQ,IAAI,GACrC,IAAI,IAAI,WAAW,QAAQ,EAAE;EAC7B,OAAO,IAAI,WAAW,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;CACnE;CAIA,SAAS,MAAM,IAAI;EAClB,MAAM,MAAM,KAAK,MAAM,QAAQ,KAC/B,IAAI,MAAM,IAAI,cAAc,MAAM,CAAC,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,KAAK,GAAG,GACpE,IAAI,MAAM,IAAI,cAAc,IAAI,CAAC,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,GAAG;EAE9D,OADU,KAAK,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,IAAI,MAAM,KAAK,MACtC,KAAK,QAAQ,iBAAiB,IAAK,KAAK,MAAM,aAAa,KAAK;CACnF;;;;;;CAOA,SAAS,KAAK;EACb,KAAK,WAAW;EAChB,OAAO,SAAS,KAAK,MAAM,GAAG;CAC/B;AAI8B,CAAC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { setOptions } from "../../core/Util.js";
|
|
2
2
|
import { Point } from "../../geometry/Point.js";
|
|
3
3
|
import { off, on } from "../../dom/DomEvent.js";
|
|
4
|
-
import { setPosition } from "../../dom/DomUtil.js";
|
|
4
|
+
import { getPosition, setPosition } from "../../dom/DomUtil.js";
|
|
5
5
|
import { Layer } from "../Layer.js";
|
|
6
6
|
import { LatLng } from "../../geo/LatLng.js";
|
|
7
|
+
import { pointToGeoJSON } from "../GeoJSONUtil.js";
|
|
7
8
|
import { DefaultIcon } from "./DefaultIcon.js";
|
|
8
9
|
import { MarkerDrag } from "./Marker.Drag.js";
|
|
9
|
-
|
|
10
|
+
// src/layer/marker/Marker.js
|
|
11
|
+
/** @import {Feature} from 'geojson' */
|
|
10
12
|
/** @import {Icon} from './Icon.js' */
|
|
11
13
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
12
14
|
/** @import {PointExpression} from '../../geometry/Point.js' */
|
|
@@ -20,7 +22,7 @@ import { MarkerDrag } from "./Marker.Drag.js";
|
|
|
20
22
|
* marker. See [Icon documentation](#Icon) for details on how to customize the marker
|
|
21
23
|
* icon. If not specified, a common instance of `DefaultIcon` is used.
|
|
22
24
|
* @property {boolean} [keyboard=true] Whether the marker can be tabbed to with a keyboard
|
|
23
|
-
* and clicked by pressing
|
|
25
|
+
* and, if interactive, clicked by pressing Enter or Space.
|
|
24
26
|
* @property {string} [title=''] Text for the browser tooltip that appear on marker hover
|
|
25
27
|
* (no tooltip by default).
|
|
26
28
|
* [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
|
|
@@ -31,6 +33,10 @@ import { MarkerDrag } from "./Marker.Drag.js";
|
|
|
31
33
|
* top of all others (or below), specifying a high value like `1000` (or high negative
|
|
32
34
|
* value, respectively).
|
|
33
35
|
* @property {number} [opacity=1] The opacity of the marker.
|
|
36
|
+
* @property {number|null} [rotation=null] Rotation of the marker icon in degrees,
|
|
37
|
+
* clockwise, around the icon anchor, e.g. for the heading of a vehicle. A rotated
|
|
38
|
+
* marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
|
|
39
|
+
* under a tilted one. `null` means no rotation.
|
|
34
40
|
* @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
|
|
35
41
|
* others when you hover the pointer over it.
|
|
36
42
|
* @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`
|
|
@@ -50,7 +56,8 @@ import { MarkerDrag } from "./Marker.Drag.js";
|
|
|
50
56
|
* marker is focused (via e.g. pressing `tab` on the keyboard) to ensure the marker is
|
|
51
57
|
* visible within the map's bounds.
|
|
52
58
|
* @property {boolean} [draggable=false] Whether the marker is draggable with pointer or
|
|
53
|
-
* not.
|
|
59
|
+
* not. A focused draggable marker can also be moved with the arrow keys, by 10 pixels
|
|
60
|
+
* or 30 with Shift.
|
|
54
61
|
* @property {boolean} [autoPan=false] Whether to pan the map when dragging this marker
|
|
55
62
|
* near its edge or not.
|
|
56
63
|
* @property {PointExpression} [autoPanPadding=[50, 50]] Distance (in pixels to the
|
|
@@ -81,28 +88,27 @@ import { MarkerDrag } from "./Marker.Drag.js";
|
|
|
81
88
|
* coordinates are included in event arguments as `oldLatLng`, `latlng`.
|
|
82
89
|
*/
|
|
83
90
|
var Marker = class Marker extends Layer {
|
|
84
|
-
static {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
91
|
+
static defaultOptions = {
|
|
92
|
+
icon: /* @__PURE__ */ new DefaultIcon(),
|
|
93
|
+
interactive: true,
|
|
94
|
+
keyboard: true,
|
|
95
|
+
title: "",
|
|
96
|
+
alt: "Marker",
|
|
97
|
+
zIndexOffset: 0,
|
|
98
|
+
opacity: 1,
|
|
99
|
+
rotation: null,
|
|
100
|
+
riseOnHover: false,
|
|
101
|
+
riseOffset: 250,
|
|
102
|
+
pane: "markerPane",
|
|
103
|
+
shadowPane: "shadowPane",
|
|
104
|
+
shadow: true,
|
|
105
|
+
bubblingPointerEvents: false,
|
|
106
|
+
autoPanOnFocus: true,
|
|
107
|
+
draggable: false,
|
|
108
|
+
autoPan: false,
|
|
109
|
+
autoPanPadding: [50, 50],
|
|
110
|
+
autoPanSpeed: 10
|
|
111
|
+
};
|
|
106
112
|
/**
|
|
107
113
|
* Instantiates a Marker object given a geographical point and optionally an options
|
|
108
114
|
* object.
|
|
@@ -131,9 +137,9 @@ var Marker = class Marker extends Layer {
|
|
|
131
137
|
* @param {MaplairMap} map
|
|
132
138
|
*/
|
|
133
139
|
onRemove(map) {
|
|
134
|
-
if (this.dragging
|
|
135
|
-
this.options.draggable =
|
|
136
|
-
this.dragging.removeHooks();
|
|
140
|
+
if (this.dragging) {
|
|
141
|
+
this.options.draggable = this.dragging.enabled();
|
|
142
|
+
if (this.options.draggable) this.dragging.removeHooks();
|
|
137
143
|
}
|
|
138
144
|
delete this.dragging;
|
|
139
145
|
if (this._zoomAnimated) map.off("zoomanim", this._animateZoom, this);
|
|
@@ -202,7 +208,6 @@ var Marker = class Marker extends Layer {
|
|
|
202
208
|
this._initIcon();
|
|
203
209
|
this.update();
|
|
204
210
|
}
|
|
205
|
-
if (this._popup) this.bindPopup(this._popup, this._popup.options);
|
|
206
211
|
return this;
|
|
207
212
|
}
|
|
208
213
|
/**
|
|
@@ -219,7 +224,7 @@ var Marker = class Marker extends Layer {
|
|
|
219
224
|
*/
|
|
220
225
|
update() {
|
|
221
226
|
if (this._icon && this._map && !this._culled) {
|
|
222
|
-
const pos = this._map.latLngToLayerPoint(this._latlng).
|
|
227
|
+
const pos = this._map.latLngToLayerPoint(this._latlng)._round();
|
|
223
228
|
this._setPos(pos);
|
|
224
229
|
}
|
|
225
230
|
return this;
|
|
@@ -232,12 +237,13 @@ var Marker = class Marker extends Layer {
|
|
|
232
237
|
if (this._icon) this._removeIcon();
|
|
233
238
|
addIcon = true;
|
|
234
239
|
if (options.title) icon.title = options.title;
|
|
235
|
-
if (icon
|
|
240
|
+
if (icon instanceof HTMLImageElement) icon.alt = options.alt ?? "";
|
|
236
241
|
}
|
|
237
242
|
icon.classList.add(classToAdd);
|
|
238
243
|
if (options.keyboard) {
|
|
239
|
-
icon.tabIndex =
|
|
240
|
-
icon.setAttribute("role", "button");
|
|
244
|
+
icon.tabIndex = 0;
|
|
245
|
+
if (options.interactive) icon.setAttribute("role", "button");
|
|
246
|
+
on(icon, "keydown", this._onKeyDown, this);
|
|
241
247
|
}
|
|
242
248
|
this._icon = icon;
|
|
243
249
|
if (options.riseOnHover) this.on({
|
|
@@ -245,7 +251,7 @@ var Marker = class Marker extends Layer {
|
|
|
245
251
|
pointerout: this._resetZIndex
|
|
246
252
|
});
|
|
247
253
|
if (this.options.autoPanOnFocus) on(icon, "focus", this._panOnFocus, this);
|
|
248
|
-
const newShadow = options.shadow ? options.icon.createShadow(this._shadow) : null;
|
|
254
|
+
const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
|
|
249
255
|
let addShadow = false;
|
|
250
256
|
if (newShadow !== this._shadow) {
|
|
251
257
|
this._removeShadow();
|
|
@@ -267,13 +273,14 @@ var Marker = class Marker extends Layer {
|
|
|
267
273
|
pointerout: this._resetZIndex
|
|
268
274
|
});
|
|
269
275
|
if (this.options.autoPanOnFocus) off(this._icon, "focus", this._panOnFocus, this);
|
|
276
|
+
off(this._icon, "keydown", this._onKeyDown, this);
|
|
270
277
|
this._icon.remove();
|
|
271
278
|
this.removeInteractiveTarget(this._icon);
|
|
272
279
|
this._icon = null;
|
|
273
280
|
}
|
|
274
281
|
_updateCulling() {
|
|
275
282
|
if (!this._icon || !this._map) return;
|
|
276
|
-
const
|
|
283
|
+
const map = this._map, visible = (map._cullingBounds ??= map.getBounds().pad(.5)).contains(this._latlng) || !!this.dragging?._draggable?._moving || this._icon.contains(document.activeElement);
|
|
277
284
|
if (visible === !this._culled) return;
|
|
278
285
|
this._culled = !visible;
|
|
279
286
|
if (visible) {
|
|
@@ -290,22 +297,36 @@ var Marker = class Marker extends Layer {
|
|
|
290
297
|
this._shadow = null;
|
|
291
298
|
}
|
|
292
299
|
_setPos(pos) {
|
|
293
|
-
|
|
294
|
-
if (this._shadow) setPosition(this._shadow, pos);
|
|
300
|
+
this._positionElements(pos);
|
|
295
301
|
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
296
302
|
this._resetZIndex();
|
|
297
303
|
}
|
|
304
|
+
_positionElements(pos) {
|
|
305
|
+
const rotation = this.options.rotation;
|
|
306
|
+
if (this._icon) {
|
|
307
|
+
setPosition(this._icon, pos);
|
|
308
|
+
if (rotation != null) this._icon.style.transform += ` rotate(${rotation}deg)`;
|
|
309
|
+
}
|
|
310
|
+
if (this._shadow) {
|
|
311
|
+
setPosition(this._shadow, pos);
|
|
312
|
+
this._shadow.style.display = rotation == null ? "" : "none";
|
|
313
|
+
}
|
|
314
|
+
}
|
|
298
315
|
_updateZIndex(offset) {
|
|
299
316
|
const zIndex = String(this._zIndex + offset);
|
|
300
317
|
if (this._icon && this._icon.style.zIndex !== zIndex) this._icon.style.zIndex = zIndex;
|
|
301
318
|
}
|
|
302
319
|
_animateZoom(opt) {
|
|
303
320
|
if (this._culled) return;
|
|
304
|
-
const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).
|
|
321
|
+
const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center)._round();
|
|
305
322
|
this._setPos(pos);
|
|
306
323
|
}
|
|
307
324
|
_updateInteractive() {
|
|
308
325
|
if (!this._icon) return;
|
|
326
|
+
if (this.options.keyboard) {
|
|
327
|
+
if (this.options.interactive) this._icon.setAttribute("role", "button");
|
|
328
|
+
else this._icon.removeAttribute("role");
|
|
329
|
+
}
|
|
309
330
|
if (this.options.interactive) {
|
|
310
331
|
this._initInteraction();
|
|
311
332
|
if (this._draggableBeforeNonInteractive) this.dragging?.enable();
|
|
@@ -321,6 +342,10 @@ var Marker = class Marker extends Layer {
|
|
|
321
342
|
this._icon.classList.add("maplair-interactive");
|
|
322
343
|
this.addInteractiveTarget(this._icon);
|
|
323
344
|
if (MarkerDrag) {
|
|
345
|
+
if (this.dragging?._draggable?._element === this._icon) {
|
|
346
|
+
this._icon.classList.toggle("maplair-marker-draggable", this.dragging.enabled());
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
324
349
|
let draggable = this.options.draggable;
|
|
325
350
|
if (this.dragging) {
|
|
326
351
|
draggable = this.dragging.enabled();
|
|
@@ -345,6 +370,27 @@ var Marker = class Marker extends Layer {
|
|
|
345
370
|
}
|
|
346
371
|
}
|
|
347
372
|
/**
|
|
373
|
+
* Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
|
|
374
|
+
* @returns {number|null}
|
|
375
|
+
*/
|
|
376
|
+
getRotation() {
|
|
377
|
+
return this.options.rotation;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Changes the [rotation](#markeroptions-rotation) of the marker; `null` removes it.
|
|
381
|
+
* @param {number|null} rotation
|
|
382
|
+
* @returns {this}
|
|
383
|
+
*/
|
|
384
|
+
setRotation(rotation) {
|
|
385
|
+
this.options.rotation = rotation;
|
|
386
|
+
if (this._icon && !this._map._animatingZoom) {
|
|
387
|
+
this._positionElements(getPosition(this._icon));
|
|
388
|
+
this._popup?._updatePosition();
|
|
389
|
+
this._tooltip?._updatePosition();
|
|
390
|
+
}
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
348
394
|
* Changes the opacity of the marker.
|
|
349
395
|
* @param {number} opacity
|
|
350
396
|
* @returns {this}
|
|
@@ -356,8 +402,8 @@ var Marker = class Marker extends Layer {
|
|
|
356
402
|
}
|
|
357
403
|
_updateOpacity() {
|
|
358
404
|
const opacity = this.options.opacity;
|
|
359
|
-
if (this._icon) this._icon.style.opacity = opacity
|
|
360
|
-
if (this._shadow) this._shadow.style.opacity = opacity
|
|
405
|
+
if (this._icon) this._icon.style.opacity = `${opacity}`;
|
|
406
|
+
if (this._shadow) this._shadow.style.opacity = `${opacity}`;
|
|
361
407
|
}
|
|
362
408
|
_bringToFront() {
|
|
363
409
|
this._updateZIndex(this.options.riseOffset);
|
|
@@ -365,25 +411,47 @@ var Marker = class Marker extends Layer {
|
|
|
365
411
|
_resetZIndex() {
|
|
366
412
|
this._updateZIndex(0);
|
|
367
413
|
}
|
|
414
|
+
_onKeyDown(e) {
|
|
415
|
+
if (this.options.interactive && e.target === this._icon && !e.repeat && (e.key === "Enter" || e.key === " ")) {
|
|
416
|
+
e.preventDefault();
|
|
417
|
+
this._clickedByKeyboard = true;
|
|
418
|
+
this._icon.click();
|
|
419
|
+
this._clickedByKeyboard = false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
368
422
|
_panOnFocus() {
|
|
369
423
|
const map = this._map;
|
|
370
424
|
if (!map) return;
|
|
371
|
-
const
|
|
372
|
-
const size = iconOpts.iconSize ? Point.from(iconOpts.iconSize) : new Point(0, 0);
|
|
373
|
-
const anchor = iconOpts.iconAnchor ? Point.from(iconOpts.iconAnchor) : new Point(0, 0);
|
|
425
|
+
const icon = this._icon, style = getComputedStyle(icon), anchor = new Point(-parseFloat(style.marginLeft) || 0, -parseFloat(style.marginTop) || 0), size = new Point(icon.offsetWidth, icon.offsetHeight);
|
|
374
426
|
map.panInside(this._latlng, {
|
|
375
427
|
paddingTopLeft: anchor,
|
|
376
428
|
paddingBottomRight: size.subtract(anchor)
|
|
377
429
|
});
|
|
378
430
|
}
|
|
379
431
|
_getPopupAnchor() {
|
|
380
|
-
return this.options.icon.options.popupAnchor;
|
|
432
|
+
return this._rotateAnchor(this.options.icon.options.popupAnchor);
|
|
381
433
|
}
|
|
382
434
|
_getTooltipAnchor() {
|
|
383
|
-
return this.options.icon.options.tooltipAnchor;
|
|
435
|
+
return this._rotateAnchor(this.options.icon.options.tooltipAnchor);
|
|
436
|
+
}
|
|
437
|
+
_rotateAnchor(anchor) {
|
|
438
|
+
const angle = this.options.rotation * Math.PI / 180;
|
|
439
|
+
if (!angle || !anchor) return anchor;
|
|
440
|
+
const { x, y } = Point.from(anchor), cos = Math.cos(angle), sin = Math.sin(angle);
|
|
441
|
+
return new Point(x * cos - y * sin, x * sin + y * cos);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
445
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
446
|
+
* representation of the marker (as a GeoJSON `Point` Feature).
|
|
447
|
+
* @group Other methods
|
|
448
|
+
* @param {number|false} [precision]
|
|
449
|
+
* @returns {Feature}
|
|
450
|
+
*/
|
|
451
|
+
toGeoJSON(precision) {
|
|
452
|
+
return pointToGeoJSON(this, precision);
|
|
384
453
|
}
|
|
385
454
|
};
|
|
386
|
-
//#endregion
|
|
387
455
|
export { Marker };
|
|
388
456
|
|
|
389
457
|
//# sourceMappingURL=Marker.js.map
|