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,4 +1,5 @@
|
|
|
1
1
|
import {Handler} from '../../core/Handler.js';
|
|
2
|
+
import * as DomEvent from '../../dom/DomEvent.js';
|
|
2
3
|
import * as DomUtil from '../../dom/DomUtil.js';
|
|
3
4
|
import {Draggable} from '../../dom/Draggable.js';
|
|
4
5
|
import {Bounds} from '../../geometry/Bounds.js';
|
|
@@ -7,6 +8,9 @@ import {Point} from '../../geometry/Point.js';
|
|
|
7
8
|
/** @import {Marker, MarkerMoveEvent} from './Marker.js' */
|
|
8
9
|
/** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */
|
|
9
10
|
|
|
11
|
+
/** @type {Record<string, [number, number]>} */
|
|
12
|
+
const arrows = {ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1]};
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* The handler of `Marker` which makes the markers draggable, see the
|
|
12
16
|
* [`dragging`](#marker-dragging) property of markers and its `draggable` option.
|
|
@@ -38,7 +42,7 @@ export class MarkerDrag extends Handler {
|
|
|
38
42
|
const icon = this._marker._icon;
|
|
39
43
|
|
|
40
44
|
if (!this._draggable) {
|
|
41
|
-
this._draggable = new Draggable(icon
|
|
45
|
+
this._draggable = new Draggable(icon);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
this._draggable.on({
|
|
@@ -48,6 +52,8 @@ export class MarkerDrag extends Handler {
|
|
|
48
52
|
dragend: this._onDragEnd
|
|
49
53
|
}, this).enable();
|
|
50
54
|
|
|
55
|
+
DomEvent.on(icon, 'keydown keyup blur', this._onKey, this);
|
|
56
|
+
|
|
51
57
|
icon.classList.add('maplair-marker-draggable');
|
|
52
58
|
}
|
|
53
59
|
|
|
@@ -55,6 +61,8 @@ export class MarkerDrag extends Handler {
|
|
|
55
61
|
* Makes the icon of the marker undraggable, called by `disable()`.
|
|
56
62
|
*/
|
|
57
63
|
removeHooks() {
|
|
64
|
+
this._keyOffset = null; // disabling the Draggable below ends a keyboard drag in progress, as it does a pointer drag
|
|
65
|
+
|
|
58
66
|
this._draggable.off({
|
|
59
67
|
dragstart: this._onDragStart,
|
|
60
68
|
predrag: this._onPreDrag,
|
|
@@ -62,6 +70,8 @@ export class MarkerDrag extends Handler {
|
|
|
62
70
|
dragend: this._onDragEnd
|
|
63
71
|
}, this).disable();
|
|
64
72
|
|
|
73
|
+
DomEvent.off(this._draggable._element, 'keydown keyup blur', this._onKey, this);
|
|
74
|
+
|
|
65
75
|
this._marker._icon?.classList.remove('maplair-marker-draggable');
|
|
66
76
|
}
|
|
67
77
|
|
|
@@ -129,14 +139,11 @@ export class MarkerDrag extends Handler {
|
|
|
129
139
|
|
|
130
140
|
_onDrag(e) {
|
|
131
141
|
const marker = this._marker,
|
|
132
|
-
shadow = marker._shadow,
|
|
133
142
|
iconPos = DomUtil.getPosition(marker._icon),
|
|
134
143
|
latlng = marker._map.layerPointToLatLng(iconPos);
|
|
135
144
|
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
DomUtil.setPosition(shadow, iconPos);
|
|
139
|
-
}
|
|
145
|
+
// Draggable only moved the icon and dropped its rotation
|
|
146
|
+
marker._positionElements(iconPos);
|
|
140
147
|
|
|
141
148
|
marker._latlng = latlng;
|
|
142
149
|
e.latlng = latlng;
|
|
@@ -155,4 +162,45 @@ export class MarkerDrag extends Handler {
|
|
|
155
162
|
.fire('moveend')
|
|
156
163
|
.fire('dragend', e);
|
|
157
164
|
}
|
|
165
|
+
|
|
166
|
+
// Arrow keys move a focused marker. Holding a key down is one drag, driven through the Draggable like a pointer
|
|
167
|
+
// drag (so the two can't overlap), and ends on keyup or blur.
|
|
168
|
+
/** @param {KeyboardEvent|FocusEvent} e */
|
|
169
|
+
_onKey(e) {
|
|
170
|
+
const k = /** @type {KeyboardEvent} */ (e), // all but blur
|
|
171
|
+
dir = arrows[k.key],
|
|
172
|
+
draggable = this._draggable,
|
|
173
|
+
{options, _map: map} = this._marker;
|
|
174
|
+
|
|
175
|
+
if (e.type !== 'keydown') {
|
|
176
|
+
if (this._keyOffset) {
|
|
177
|
+
this._keyOffset = null;
|
|
178
|
+
draggable.finishDrag();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
} else if (dir && k.target === draggable._element && !(k.altKey || k.ctrlKey || k.metaKey)) {
|
|
182
|
+
e.preventDefault(); // don't scroll the page
|
|
183
|
+
|
|
184
|
+
if (!this._keyOffset) {
|
|
185
|
+
if (Draggable._dragging) { return; }
|
|
186
|
+
Draggable._dragging = draggable;
|
|
187
|
+
draggable._startPos = DomUtil.getPosition(draggable._element);
|
|
188
|
+
draggable._moved = draggable._moving = true;
|
|
189
|
+
this._keyOffset = new Point(0, 0);
|
|
190
|
+
draggable.fire('dragstart');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// in container pixels, which the map rotation (if any) turns to the frame of the rotated pane
|
|
194
|
+
const offset = new Point(...dir).multiplyBy(k.shiftKey ? 30 : 10);
|
|
195
|
+
this._keyOffset = this._keyOffset.add(map._rotateToPane?.(offset) ?? offset);
|
|
196
|
+
// not through _updatePosition, whose predrag would start the pointer autoPan loop
|
|
197
|
+
draggable._newPos = draggable._startPos.add(this._keyOffset);
|
|
198
|
+
DomUtil.setPosition(draggable._element, draggable._newPos);
|
|
199
|
+
draggable.fire('drag', {originalEvent: k});
|
|
200
|
+
|
|
201
|
+
if (options.autoPan) {
|
|
202
|
+
map.panInside(this._marker._latlng, {padding: options.autoPanPadding, animate: false});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
158
206
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {Marker} from './Marker.js';
|
|
2
2
|
import {LatLng} from '../../geo/LatLng.js';
|
|
3
3
|
import {Point} from '../../geometry/Point.js';
|
|
4
|
-
import Browser from '../../core/Browser.js';
|
|
5
4
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
6
5
|
/** @import {MaplairMap} from '../../map/Map.js' */
|
|
7
6
|
/** @import {MaplairEvent} from '../../core/Events.js' */
|
|
@@ -12,9 +11,8 @@ import Browser from '../../core/Browser.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
|
|
|
20
18
|
// The methods extended below
|
|
@@ -73,7 +71,7 @@ const markerMoveMethods = {
|
|
|
73
71
|
|
|
74
72
|
const frame = () => {
|
|
75
73
|
// the distance moved, at a constant speed
|
|
76
|
-
let distance = duration && !
|
|
74
|
+
let distance = duration && !this._map?._prefersReducedMotion() ? Math.min(1, (performance.now() - start) / duration) * total : total,
|
|
77
75
|
i = 0;
|
|
78
76
|
const moved = distance;
|
|
79
77
|
while (i < lengths.length - 1 && distance > lengths[i]) {
|
|
@@ -82,7 +80,7 @@ const markerMoveMethods = {
|
|
|
82
80
|
}
|
|
83
81
|
const from = points[i], to = points[i + 1];
|
|
84
82
|
if (options.rotate && !from.equals(to)) {
|
|
85
|
-
this.options.
|
|
83
|
+
this.options.rotation = this._heading(from, to);
|
|
86
84
|
}
|
|
87
85
|
this.setLatLng(this._interpolate(from, to, lengths[i] ? Math.min(1, distance / lengths[i]) : 1));
|
|
88
86
|
|
|
@@ -6,6 +6,8 @@ import {Point} from '../../geometry/Point.js';
|
|
|
6
6
|
import * as DomUtil from '../../dom/DomUtil.js';
|
|
7
7
|
import * as DomEvent from '../../dom/DomEvent.js';
|
|
8
8
|
import {MarkerDrag} from './Marker.Drag.js';
|
|
9
|
+
import {pointToGeoJSON} from '../GeoJSONUtil.js';
|
|
10
|
+
/** @import {Feature} from 'geojson' */
|
|
9
11
|
/** @import {Icon} from './Icon.js' */
|
|
10
12
|
/** @import {LatLngExpression} from '../../geo/LatLng.js' */
|
|
11
13
|
/** @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
|
|
@@ -84,31 +91,30 @@ import {MarkerDrag} from './Marker.Drag.js';
|
|
|
84
91
|
*/
|
|
85
92
|
export class Marker extends Layer {
|
|
86
93
|
|
|
87
|
-
static {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
94
|
+
static defaultOptions = {
|
|
95
|
+
icon: /* @__PURE__ */ new DefaultIcon(),
|
|
96
|
+
|
|
97
|
+
// Option inherited from "Interactive layer" abstract class
|
|
98
|
+
interactive: true,
|
|
99
|
+
|
|
100
|
+
keyboard: true,
|
|
101
|
+
title: '',
|
|
102
|
+
alt: 'Marker',
|
|
103
|
+
zIndexOffset: 0,
|
|
104
|
+
opacity: 1,
|
|
105
|
+
rotation: null,
|
|
106
|
+
riseOnHover: false,
|
|
107
|
+
riseOffset: 250,
|
|
108
|
+
pane: 'markerPane',
|
|
109
|
+
shadowPane: 'shadowPane',
|
|
110
|
+
shadow: true,
|
|
111
|
+
bubblingPointerEvents: false,
|
|
112
|
+
autoPanOnFocus: true,
|
|
113
|
+
draggable: false,
|
|
114
|
+
autoPan: false,
|
|
115
|
+
autoPanPadding: [50, 50],
|
|
116
|
+
autoPanSpeed: 10
|
|
117
|
+
};
|
|
112
118
|
|
|
113
119
|
/**
|
|
114
120
|
* Instantiates a Marker object given a geographical point and optionally an options
|
|
@@ -148,9 +154,10 @@ export class Marker extends Layer {
|
|
|
148
154
|
* @param {MaplairMap} map
|
|
149
155
|
*/
|
|
150
156
|
onRemove(map) {
|
|
151
|
-
if (this.dragging
|
|
152
|
-
|
|
153
|
-
this.dragging.
|
|
157
|
+
if (this.dragging) {
|
|
158
|
+
// remember whether dragging is on or off (`dragging.disable()`) for when the marker is added again
|
|
159
|
+
this.options.draggable = this.dragging.enabled();
|
|
160
|
+
if (this.options.draggable) { this.dragging.removeHooks(); }
|
|
154
161
|
}
|
|
155
162
|
delete this.dragging;
|
|
156
163
|
|
|
@@ -234,10 +241,6 @@ export class Marker extends Layer {
|
|
|
234
241
|
this.update();
|
|
235
242
|
}
|
|
236
243
|
|
|
237
|
-
if (this._popup) {
|
|
238
|
-
this.bindPopup(this._popup, this._popup.options);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
244
|
return this;
|
|
242
245
|
}
|
|
243
246
|
|
|
@@ -257,7 +260,7 @@ export class Marker extends Layer {
|
|
|
257
260
|
update() {
|
|
258
261
|
|
|
259
262
|
if (this._icon && this._map && !this._culled) {
|
|
260
|
-
const pos = this._map.latLngToLayerPoint(this._latlng).
|
|
263
|
+
const pos = this._map.latLngToLayerPoint(this._latlng)._round();
|
|
261
264
|
this._setPos(pos);
|
|
262
265
|
}
|
|
263
266
|
|
|
@@ -282,7 +285,7 @@ export class Marker extends Layer {
|
|
|
282
285
|
icon.title = options.title;
|
|
283
286
|
}
|
|
284
287
|
|
|
285
|
-
if (icon
|
|
288
|
+
if (icon instanceof HTMLImageElement) {
|
|
286
289
|
icon.alt = options.alt ?? '';
|
|
287
290
|
}
|
|
288
291
|
}
|
|
@@ -290,8 +293,11 @@ export class Marker extends Layer {
|
|
|
290
293
|
icon.classList.add(classToAdd);
|
|
291
294
|
|
|
292
295
|
if (options.keyboard) {
|
|
293
|
-
icon.tabIndex =
|
|
294
|
-
|
|
296
|
+
icon.tabIndex = 0;
|
|
297
|
+
if (options.interactive) {
|
|
298
|
+
icon.setAttribute('role', 'button');
|
|
299
|
+
}
|
|
300
|
+
DomEvent.on(icon, 'keydown', this._onKeyDown, this);
|
|
295
301
|
}
|
|
296
302
|
|
|
297
303
|
this._icon = icon;
|
|
@@ -307,7 +313,7 @@ export class Marker extends Layer {
|
|
|
307
313
|
DomEvent.on(icon, 'focus', this._panOnFocus, this);
|
|
308
314
|
}
|
|
309
315
|
|
|
310
|
-
const newShadow = options.shadow ? options.icon.createShadow(this._shadow) : null;
|
|
316
|
+
const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
|
|
311
317
|
let addShadow = false;
|
|
312
318
|
|
|
313
319
|
if (newShadow !== this._shadow) {
|
|
@@ -347,6 +353,7 @@ export class Marker extends Layer {
|
|
|
347
353
|
if (this.options.autoPanOnFocus) {
|
|
348
354
|
DomEvent.off(this._icon, 'focus', this._panOnFocus, this);
|
|
349
355
|
}
|
|
356
|
+
DomEvent.off(this._icon, 'keydown', this._onKeyDown, this);
|
|
350
357
|
|
|
351
358
|
this._icon.remove();
|
|
352
359
|
this.removeInteractiveTarget(this._icon);
|
|
@@ -361,7 +368,10 @@ export class Marker extends Layer {
|
|
|
361
368
|
_updateCulling() {
|
|
362
369
|
if (!this._icon || !this._map) { return; }
|
|
363
370
|
|
|
364
|
-
const
|
|
371
|
+
const map = this._map,
|
|
372
|
+
// computed once per view for all markers, reset by the map on `move`
|
|
373
|
+
bounds = map._cullingBounds ??= map.getBounds().pad(0.5),
|
|
374
|
+
visible = bounds.contains(this._latlng) ||
|
|
365
375
|
!!this.dragging?._draggable?._moving ||
|
|
366
376
|
this._icon.contains(document.activeElement);
|
|
367
377
|
|
|
@@ -386,18 +396,27 @@ export class Marker extends Layer {
|
|
|
386
396
|
}
|
|
387
397
|
|
|
388
398
|
_setPos(pos) {
|
|
399
|
+
this._positionElements(pos);
|
|
400
|
+
|
|
401
|
+
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
402
|
+
|
|
403
|
+
this._resetZIndex();
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
_positionElements(pos) {
|
|
407
|
+
const rotation = this.options.rotation;
|
|
389
408
|
|
|
390
409
|
if (this._icon) {
|
|
391
410
|
DomUtil.setPosition(this._icon, pos);
|
|
411
|
+
if (rotation != null) {
|
|
412
|
+
this._icon.style.transform += ` rotate(${rotation}deg)`;
|
|
413
|
+
}
|
|
392
414
|
}
|
|
393
415
|
|
|
394
416
|
if (this._shadow) {
|
|
395
417
|
DomUtil.setPosition(this._shadow, pos);
|
|
418
|
+
this._shadow.style.display = rotation == null ? '' : 'none';
|
|
396
419
|
}
|
|
397
|
-
|
|
398
|
-
this._zIndex = pos.y + this.options.zIndexOffset;
|
|
399
|
-
|
|
400
|
-
this._resetZIndex();
|
|
401
420
|
}
|
|
402
421
|
|
|
403
422
|
_updateZIndex(offset) {
|
|
@@ -409,13 +428,20 @@ export class Marker extends Layer {
|
|
|
409
428
|
|
|
410
429
|
_animateZoom(opt) {
|
|
411
430
|
if (this._culled) { return; }
|
|
412
|
-
const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).
|
|
431
|
+
const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center)._round();
|
|
413
432
|
|
|
414
433
|
this._setPos(pos);
|
|
415
434
|
}
|
|
416
435
|
|
|
417
436
|
_updateInteractive() {
|
|
418
437
|
if (!this._icon) { return; }
|
|
438
|
+
if (this.options.keyboard) {
|
|
439
|
+
if (this.options.interactive) {
|
|
440
|
+
this._icon.setAttribute('role', 'button');
|
|
441
|
+
} else {
|
|
442
|
+
this._icon.removeAttribute('role');
|
|
443
|
+
}
|
|
444
|
+
}
|
|
419
445
|
if (this.options.interactive) {
|
|
420
446
|
this._initInteraction();
|
|
421
447
|
if (this._draggableBeforeNonInteractive) {
|
|
@@ -438,6 +464,14 @@ export class Marker extends Layer {
|
|
|
438
464
|
this.addInteractiveTarget(this._icon);
|
|
439
465
|
|
|
440
466
|
if (MarkerDrag) {
|
|
467
|
+
// When the icon element is reused, the drag handler still refers to it. Keep that handler, because
|
|
468
|
+
// replacing it ends a drag in progress and forgets that the marker has just been dragged.
|
|
469
|
+
if (this.dragging?._draggable?._element === this._icon) {
|
|
470
|
+
// the icon has reset the class names of the element
|
|
471
|
+
this._icon.classList.toggle('maplair-marker-draggable', this.dragging.enabled());
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
441
475
|
let draggable = this.options.draggable;
|
|
442
476
|
if (this.dragging) {
|
|
443
477
|
draggable = this.dragging.enabled();
|
|
@@ -466,6 +500,30 @@ export class Marker extends Layer {
|
|
|
466
500
|
}
|
|
467
501
|
}
|
|
468
502
|
|
|
503
|
+
/**
|
|
504
|
+
* Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
|
|
505
|
+
* @returns {number|null}
|
|
506
|
+
*/
|
|
507
|
+
getRotation() {
|
|
508
|
+
return this.options.rotation;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Changes the [rotation](#markeroptions-rotation) of the marker; `null` removes it.
|
|
513
|
+
* @param {number|null} rotation
|
|
514
|
+
* @returns {this}
|
|
515
|
+
*/
|
|
516
|
+
setRotation(rotation) {
|
|
517
|
+
this.options.rotation = rotation;
|
|
518
|
+
// mid-zoom, the icon is transitioning to a position that update() can't compute yet; the zoom end applies it
|
|
519
|
+
if (this._icon && !this._map._animatingZoom) {
|
|
520
|
+
this._positionElements(DomUtil.getPosition(this._icon));
|
|
521
|
+
this._popup?._updatePosition();
|
|
522
|
+
this._tooltip?._updatePosition();
|
|
523
|
+
}
|
|
524
|
+
return this;
|
|
525
|
+
}
|
|
526
|
+
|
|
469
527
|
/**
|
|
470
528
|
* Changes the opacity of the marker.
|
|
471
529
|
* @param {number} opacity
|
|
@@ -484,11 +542,11 @@ export class Marker extends Layer {
|
|
|
484
542
|
const opacity = this.options.opacity;
|
|
485
543
|
|
|
486
544
|
if (this._icon) {
|
|
487
|
-
this._icon.style.opacity = opacity
|
|
545
|
+
this._icon.style.opacity = `${opacity}`;
|
|
488
546
|
}
|
|
489
547
|
|
|
490
548
|
if (this._shadow) {
|
|
491
|
-
this._shadow.style.opacity = opacity
|
|
549
|
+
this._shadow.style.opacity = `${opacity}`;
|
|
492
550
|
}
|
|
493
551
|
}
|
|
494
552
|
|
|
@@ -500,13 +558,25 @@ export class Marker extends Layer {
|
|
|
500
558
|
this._updateZIndex(0);
|
|
501
559
|
}
|
|
502
560
|
|
|
561
|
+
_onKeyDown(e) {
|
|
562
|
+
// a key pressed on a focusable element inside a DivIcon (e.g. a <button>) already clicks it natively
|
|
563
|
+
if (this.options.interactive && e.target === this._icon && !e.repeat && (e.key === 'Enter' || e.key === ' ')) {
|
|
564
|
+
e.preventDefault(); // stop Space from scrolling the page
|
|
565
|
+
// lets a popup opened by the click take the focus, see Popup.onAdd()
|
|
566
|
+
this._clickedByKeyboard = true;
|
|
567
|
+
this._icon.click();
|
|
568
|
+
this._clickedByKeyboard = false;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
503
572
|
_panOnFocus() {
|
|
504
573
|
const map = this._map;
|
|
505
574
|
if (!map) { return; }
|
|
506
575
|
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
576
|
+
const icon = this._icon,
|
|
577
|
+
style = getComputedStyle(icon),
|
|
578
|
+
anchor = new Point(-parseFloat(style.marginLeft) || 0, -parseFloat(style.marginTop) || 0),
|
|
579
|
+
size = new Point(icon.offsetWidth, icon.offsetHeight);
|
|
510
580
|
|
|
511
581
|
map.panInside(this._latlng, {
|
|
512
582
|
paddingTopLeft: anchor,
|
|
@@ -515,10 +585,33 @@ export class Marker extends Layer {
|
|
|
515
585
|
}
|
|
516
586
|
|
|
517
587
|
_getPopupAnchor() {
|
|
518
|
-
return this.options.icon.options.popupAnchor;
|
|
588
|
+
return this._rotateAnchor(this.options.icon.options.popupAnchor);
|
|
519
589
|
}
|
|
520
590
|
|
|
521
591
|
_getTooltipAnchor() {
|
|
522
|
-
return this.options.icon.options.tooltipAnchor;
|
|
592
|
+
return this._rotateAnchor(this.options.icon.options.tooltipAnchor);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// anchors are offsets from the icon anchor, which is also the rotation origin
|
|
596
|
+
_rotateAnchor(anchor) {
|
|
597
|
+
const angle = this.options.rotation * Math.PI / 180;
|
|
598
|
+
if (!angle || !anchor) { return anchor; }
|
|
599
|
+
|
|
600
|
+
const {x, y} = Point.from(anchor),
|
|
601
|
+
cos = Math.cos(angle),
|
|
602
|
+
sin = Math.sin(angle);
|
|
603
|
+
return new Point(x * cos - y * sin, x * sin + y * cos);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
|
|
608
|
+
* given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
|
|
609
|
+
* representation of the marker (as a GeoJSON `Point` Feature).
|
|
610
|
+
* @group Other methods
|
|
611
|
+
* @param {number|false} [precision]
|
|
612
|
+
* @returns {Feature}
|
|
613
|
+
*/
|
|
614
|
+
toGeoJSON(precision) {
|
|
615
|
+
return pointToGeoJSON(this, precision);
|
|
523
616
|
}
|
|
524
617
|
}
|