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
|
@@ -41,13 +41,11 @@ import {I18n} from '../core/I18n.js';
|
|
|
41
41
|
*/
|
|
42
42
|
export class ZoomControl extends Control {
|
|
43
43
|
|
|
44
|
-
static {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
}
|
|
44
|
+
static defaultOptions = {
|
|
45
|
+
position: 'topleft',
|
|
46
|
+
zoomInText: '<span aria-hidden="true">+</span>',
|
|
47
|
+
zoomOutText: '<span aria-hidden="true">−</span>',
|
|
48
|
+
};
|
|
51
49
|
|
|
52
50
|
/**
|
|
53
51
|
* Creates a zoom control.
|
|
@@ -69,9 +67,9 @@ export class ZoomControl extends Control {
|
|
|
69
67
|
options = this.options;
|
|
70
68
|
|
|
71
69
|
this._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),
|
|
72
|
-
`${zoomName}-in`, container, this.
|
|
70
|
+
`${zoomName}-in`, container, e => this._zoom(e, 1));
|
|
73
71
|
this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),
|
|
74
|
-
`${zoomName}-out`, container, this.
|
|
72
|
+
`${zoomName}-out`, container, e => this._zoom(e, -1));
|
|
75
73
|
|
|
76
74
|
this._updateDisabled();
|
|
77
75
|
map.on('zoomend zoomlevelschange', this._updateDisabled, this);
|
|
@@ -107,17 +105,11 @@ export class ZoomControl extends Control {
|
|
|
107
105
|
return this;
|
|
108
106
|
}
|
|
109
107
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
_zoomOut(e) {
|
|
118
|
-
if (!this._disabled && this._map._zoom > this._map.getMinZoom()) {
|
|
119
|
-
this._map._setUserEvent(e);
|
|
120
|
-
this._map.zoomOut(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));
|
|
108
|
+
_zoom(e, dir) {
|
|
109
|
+
const map = this._map;
|
|
110
|
+
if (!this._disabled && (dir > 0 ? map._zoom < map.getMaxZoom() : map._zoom > map.getMinZoom())) {
|
|
111
|
+
map._setUserEvent(e);
|
|
112
|
+
map.zoomIn(dir * map.options.zoomDelta * (e.shiftKey ? 3 : 1));
|
|
121
113
|
}
|
|
122
114
|
}
|
|
123
115
|
|
|
@@ -129,29 +121,21 @@ export class ZoomControl extends Control {
|
|
|
129
121
|
link.setAttribute('aria-label', title);
|
|
130
122
|
|
|
131
123
|
DomEvent.disableClickPropagation(link);
|
|
132
|
-
DomEvent.on(link, 'click',
|
|
133
|
-
|
|
134
|
-
|
|
124
|
+
DomEvent.on(link, 'click', (e) => {
|
|
125
|
+
DomEvent.stop(e);
|
|
126
|
+
fn.call(this, e);
|
|
127
|
+
this._refocusOnMap(e);
|
|
128
|
+
});
|
|
135
129
|
|
|
136
130
|
return link;
|
|
137
131
|
}
|
|
138
132
|
|
|
139
133
|
_updateDisabled() {
|
|
140
|
-
const map = this._map
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this._zoomInButton.setAttribute('aria-disabled', 'false');
|
|
146
|
-
this._zoomOutButton.setAttribute('aria-disabled', 'false');
|
|
147
|
-
|
|
148
|
-
if (this._disabled || map._zoom === map.getMinZoom()) {
|
|
149
|
-
this._zoomOutButton.classList.add(className);
|
|
150
|
-
this._zoomOutButton.setAttribute('aria-disabled', 'true');
|
|
151
|
-
}
|
|
152
|
-
if (this._disabled || map._zoom === map.getMaxZoom()) {
|
|
153
|
-
this._zoomInButton.classList.add(className);
|
|
154
|
-
this._zoomInButton.setAttribute('aria-disabled', 'true');
|
|
134
|
+
const map = this._map;
|
|
135
|
+
for (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {
|
|
136
|
+
const disabled = this._disabled || map._zoom === limit;
|
|
137
|
+
button.classList.toggle('maplair-disabled', disabled);
|
|
138
|
+
button.setAttribute('aria-disabled', `${disabled}`);
|
|
155
139
|
}
|
|
156
140
|
}
|
|
157
141
|
|
package/src/control/index.js
CHANGED
|
@@ -10,4 +10,5 @@ export {ScaleControl} from './ScaleControl.js';
|
|
|
10
10
|
export {SearchControl} from './SearchControl.js';
|
|
11
11
|
export {SideBySideControl} from './SideBySideControl.js';
|
|
12
12
|
export {TextControl} from './TextControl.js';
|
|
13
|
+
export {TimeControl} from './TimeControl.js';
|
|
13
14
|
export {ZoomControl} from './ZoomControl.js';
|
package/src/core/Class.js
CHANGED
|
@@ -12,28 +12,24 @@ import * as Util from './Util.js';
|
|
|
12
12
|
*
|
|
13
13
|
* <h3 id="class-options">Options</h3>
|
|
14
14
|
*
|
|
15
|
-
* `options` is a special property
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* `options` is a special property whose defaults, the static `defaultOptions` of the
|
|
16
|
+
* class, are merged with those of the parent class instead of overriding them
|
|
17
|
+
* completely, which makes managing configuration of objects and default values
|
|
18
|
+
* convenient:
|
|
19
19
|
*
|
|
20
20
|
* ```js
|
|
21
21
|
* class MyClass extends Class {
|
|
22
|
-
* static {
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* });
|
|
27
|
-
* }
|
|
22
|
+
* static defaultOptions = {
|
|
23
|
+
* myOption1: 'foo',
|
|
24
|
+
* myOption2: 'bar'
|
|
25
|
+
* };
|
|
28
26
|
* }
|
|
29
27
|
*
|
|
30
28
|
* class MyChildClass extends MyClass {
|
|
31
|
-
* static {
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* });
|
|
36
|
-
* }
|
|
29
|
+
* static defaultOptions = {
|
|
30
|
+
* myOption1: 'baz',
|
|
31
|
+
* myOption3: 5
|
|
32
|
+
* };
|
|
37
33
|
* }
|
|
38
34
|
*
|
|
39
35
|
* const a = new MyChildClass();
|
|
@@ -48,12 +44,10 @@ import * as Util from './Util.js';
|
|
|
48
44
|
*
|
|
49
45
|
* ```js
|
|
50
46
|
* class MyClass extends Class {
|
|
51
|
-
* static {
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* });
|
|
56
|
-
* }
|
|
47
|
+
* static defaultOptions = {
|
|
48
|
+
* foo: 'bar',
|
|
49
|
+
* bla: 5
|
|
50
|
+
* };
|
|
57
51
|
*
|
|
58
52
|
* constructor(options) {
|
|
59
53
|
* super();
|
|
@@ -165,51 +159,44 @@ export class Class {
|
|
|
165
159
|
* @returns {T}
|
|
166
160
|
*/
|
|
167
161
|
static include(props) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
162
|
+
for (let obj = props; obj && obj !== Object.prototype; obj = Object.getPrototypeOf(obj)) {
|
|
163
|
+
for (const k of Object.getOwnPropertyNames(obj)) {
|
|
164
|
+
if (k !== 'constructor' && k !== 'options') {
|
|
165
|
+
this.prototype[k] = props[k];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
171
168
|
}
|
|
172
169
|
if (props.options) {
|
|
173
|
-
this.prototype.options = parentOptions;
|
|
174
170
|
this.mergeOptions(props.options);
|
|
175
171
|
}
|
|
176
172
|
return this;
|
|
177
|
-
|
|
178
|
-
function *getAllMethodNames(obj) {
|
|
179
|
-
do {
|
|
180
|
-
if (obj === Object || obj === Object.prototype) {
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
for (const k of Object.getOwnPropertyNames(obj)) {
|
|
184
|
-
yield k;
|
|
185
|
-
}
|
|
186
|
-
} while ((obj = Object.getPrototypeOf(obj)) !== undefined);
|
|
187
|
-
}
|
|
188
173
|
}
|
|
189
174
|
|
|
190
175
|
/**
|
|
191
|
-
*
|
|
176
|
+
* [Merges `options`](#class-options) into the `defaultOptions` of the class.
|
|
192
177
|
* @template {typeof Class} T
|
|
193
178
|
* @this {T}
|
|
194
179
|
* @param {object} options
|
|
195
180
|
* @returns {T}
|
|
196
181
|
*/
|
|
197
|
-
static
|
|
198
|
-
|
|
182
|
+
static mergeOptions(options) {
|
|
183
|
+
if (!Object.hasOwn(this, 'defaultOptions')) {
|
|
184
|
+
this.defaultOptions = Object.create(this.defaultOptions ?? Object.prototype);
|
|
185
|
+
}
|
|
186
|
+
Object.assign(this.defaultOptions, options);
|
|
199
187
|
return this;
|
|
200
188
|
}
|
|
201
189
|
|
|
202
190
|
/**
|
|
203
|
-
*
|
|
191
|
+
* Deprecated alias of `mergeOptions()`, kept for code written for Maplair 4.0.
|
|
192
|
+
* @deprecated Use `static defaultOptions = {…}` or `mergeOptions()`.
|
|
204
193
|
* @template {typeof Class} T
|
|
205
194
|
* @this {T}
|
|
206
195
|
* @param {object} options
|
|
207
196
|
* @returns {T}
|
|
208
197
|
*/
|
|
209
|
-
static
|
|
210
|
-
this.
|
|
211
|
-
Object.assign(this.prototype.options, options);
|
|
212
|
-
return this;
|
|
198
|
+
static setDefaultOptions(options) {
|
|
199
|
+
return this.mergeOptions(options);
|
|
213
200
|
}
|
|
214
201
|
|
|
215
202
|
/**
|
|
@@ -235,6 +222,11 @@ export class Class {
|
|
|
235
222
|
}
|
|
236
223
|
|
|
237
224
|
constructor() {
|
|
225
|
+
if (this.initialize) {
|
|
226
|
+
throw new Error(`${this.constructor.name}: initialize() is not called in Maplair. ` +
|
|
227
|
+
'Rename it to constructor() and call super() at its start.');
|
|
228
|
+
}
|
|
229
|
+
|
|
238
230
|
Util.setOptions(this);
|
|
239
231
|
}
|
|
240
232
|
|
package/src/core/Events.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {Class} from './Class.js';
|
|
2
2
|
import * as Util from './Util.js';
|
|
3
|
+
|
|
4
|
+
const warnedEvents = new Set();
|
|
3
5
|
/** @import {LatLng} from '../geo/LatLng.js' */
|
|
4
6
|
/** @import {LatLngBounds} from '../geo/LatLngBounds.js' */
|
|
5
7
|
/** @import {Point} from '../geometry/Point.js' */
|
|
@@ -95,6 +97,8 @@ import * as Util from './Util.js';
|
|
|
95
97
|
* @typedef {object} LayersControlEvent
|
|
96
98
|
* @property {Layer} layer The layer that was added or removed.
|
|
97
99
|
* @property {string} name The name of the layer that was added or removed.
|
|
100
|
+
* @property {Event} [originalEvent] The DOM event of the click on the entry in the
|
|
101
|
+
* layers control, `undefined` if the layer was added or removed by code.
|
|
98
102
|
* @extends MaplairEvent
|
|
99
103
|
*/
|
|
100
104
|
|
|
@@ -129,6 +133,13 @@ import * as Util from './Util.js';
|
|
|
129
133
|
* @extends MaplairEvent
|
|
130
134
|
*/
|
|
131
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The event object of `worldcopyjump`.
|
|
138
|
+
* @typedef {object} WorldCopyJumpEvent
|
|
139
|
+
* @property {number} worlds The signed number of world widths by which the map pane moved.
|
|
140
|
+
* @extends MaplairEvent
|
|
141
|
+
*/
|
|
142
|
+
|
|
132
143
|
/**
|
|
133
144
|
* The event object of adding GeoJSON features.
|
|
134
145
|
* @typedef {object} GeoJSONEvent
|
|
@@ -259,13 +270,21 @@ export class Evented extends Class {
|
|
|
259
270
|
return this;
|
|
260
271
|
}
|
|
261
272
|
|
|
262
|
-
static __REMOVED_EVENTS =
|
|
273
|
+
static __REMOVED_EVENTS = {
|
|
274
|
+
mousedown: 'pointerdown',
|
|
275
|
+
mouseup: 'pointerup',
|
|
276
|
+
mouseover: 'pointerover',
|
|
277
|
+
mouseout: 'pointerout',
|
|
278
|
+
mousemove: 'pointermove',
|
|
279
|
+
keypress: 'keydown'
|
|
280
|
+
};
|
|
263
281
|
|
|
264
282
|
// attach listener (without syntactic sugar now)
|
|
265
283
|
_on(type, fn, context, _once) {
|
|
266
284
|
// To be removed in maplair 3
|
|
267
|
-
if (Evented.__REMOVED_EVENTS.
|
|
268
|
-
|
|
285
|
+
if (Object.hasOwn(Evented.__REMOVED_EVENTS, type) && !warnedEvents.has(type)) {
|
|
286
|
+
warnedEvents.add(type);
|
|
287
|
+
console.error(`The event ${type} has been removed in Maplair. Use ${Evented.__REMOVED_EVENTS[type]} instead.`);
|
|
269
288
|
}
|
|
270
289
|
|
|
271
290
|
if (typeof fn !== 'function') {
|
package/src/core/Handler.js
CHANGED
|
@@ -6,7 +6,7 @@ import {Class} from './Class.js';
|
|
|
6
6
|
* are used internally to inject interaction features like dragging to classes like
|
|
7
7
|
* `MaplairMap` and `Marker`.
|
|
8
8
|
*
|
|
9
|
-
* Classes inheriting from `Handler`
|
|
9
|
+
* Classes inheriting from `Handler` implement the two following extension methods:
|
|
10
10
|
*
|
|
11
11
|
* * `addHooks()` is called when the handler is enabled, should add event hooks.
|
|
12
12
|
* * `removeHooks()` is called when the handler is disabled, should remove the event
|
|
@@ -54,16 +54,28 @@ export class Handler extends Class {
|
|
|
54
54
|
enabled() {
|
|
55
55
|
return !!this._enabled;
|
|
56
56
|
}
|
|
57
|
-
}
|
|
58
57
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Called when the handler is enabled, should add event hooks.
|
|
60
|
+
*/
|
|
61
|
+
addHooks() {}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Called when the handler is disabled, should remove the event hooks added previously.
|
|
65
|
+
*/
|
|
66
|
+
removeHooks() {}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Adds a new handler of this class to the given map with the given name, which is
|
|
70
|
+
* then available as the property of the map with this name.
|
|
71
|
+
* @template {typeof Handler} T
|
|
72
|
+
* @this {T}
|
|
73
|
+
* @param {MaplairMap} map
|
|
74
|
+
* @param {string} name
|
|
75
|
+
* @returns {T}
|
|
76
|
+
*/
|
|
77
|
+
static addTo(map, name) {
|
|
78
|
+
map.addHandler(name, this);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/core/Util.js
CHANGED
|
@@ -59,7 +59,7 @@ export function throttle(fn, time, context) {
|
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Returns the number `x` modulo `range` in such a way so it lies within
|
|
62
|
-
* `range[0]` and `range[1]`. The returned value will be
|
|
62
|
+
* `range[0]` and `range[1]`. The returned value will always be smaller than
|
|
63
63
|
* `range[1]` unless `includeMax` is set to `true`.
|
|
64
64
|
* @param {number} x
|
|
65
65
|
* @param {[number, number]} range
|
|
@@ -113,7 +113,8 @@ export function splitWords(str) {
|
|
|
113
113
|
*/
|
|
114
114
|
export function setOptions(obj, options) {
|
|
115
115
|
if (!Object.hasOwn(obj, 'options')) {
|
|
116
|
-
|
|
116
|
+
const defaults = getDefaultOptions(obj.constructor) ?? obj.options;
|
|
117
|
+
obj.options = defaults ? Object.create(defaults) : {};
|
|
117
118
|
}
|
|
118
119
|
for (const i in options) {
|
|
119
120
|
if (Object.hasOwn(options, i)) {
|
|
@@ -123,6 +124,23 @@ export function setOptions(obj, options) {
|
|
|
123
124
|
return obj.options;
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
const chainedDefaults = new WeakMap(); // class -> the defaultOptions object it was chained with
|
|
128
|
+
|
|
129
|
+
// Links the `defaultOptions` of each class in the chain to its parent's, so defaults are inherited and stay live.
|
|
130
|
+
// Done on first use because a static field can't do it in its initializer and stay tree-shakeable.
|
|
131
|
+
function getDefaultOptions(cls) {
|
|
132
|
+
const defaults = cls?.defaultOptions;
|
|
133
|
+
if (defaults && chainedDefaults.get(cls) !== defaults) {
|
|
134
|
+
for (let c = cls; c.defaultOptions; c = Object.getPrototypeOf(c)) {
|
|
135
|
+
if (Object.hasOwn(c, 'defaultOptions')) {
|
|
136
|
+
Object.setPrototypeOf(c.defaultOptions, Object.getPrototypeOf(c).defaultOptions ?? Object.prototype);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
chainedDefaults.set(cls, defaults);
|
|
140
|
+
}
|
|
141
|
+
return defaults;
|
|
142
|
+
}
|
|
143
|
+
|
|
126
144
|
const templateRe = /\{ *([\w_ -]+) *\}/g;
|
|
127
145
|
|
|
128
146
|
/**
|
package/src/core/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as DomEvent from './DomEvent.js';
|
|
2
|
-
|
|
3
1
|
/*
|
|
4
2
|
* Extends the event handling code with double tap support for mobile browsers.
|
|
5
3
|
*
|
|
@@ -8,7 +6,7 @@ import * as DomEvent from './DomEvent.js';
|
|
|
8
6
|
*/
|
|
9
7
|
|
|
10
8
|
function makeDblclick(ev) {
|
|
11
|
-
|
|
9
|
+
const init = {
|
|
12
10
|
// EventInit
|
|
13
11
|
bubbles: ev.bubbles,
|
|
14
12
|
cancelable: ev.cancelable,
|
|
@@ -37,7 +35,7 @@ function makeDblclick(ev) {
|
|
|
37
35
|
// The `click` event received should be a PointerEvent - but some
|
|
38
36
|
// Firefox versions still use MouseEvent.
|
|
39
37
|
if (ev instanceof PointerEvent) {
|
|
40
|
-
|
|
38
|
+
newEvent = new PointerEvent('dblclick', {
|
|
41
39
|
...init,
|
|
42
40
|
pointerId: ev.pointerId,
|
|
43
41
|
width: ev.width,
|
|
@@ -49,8 +47,7 @@ function makeDblclick(ev) {
|
|
|
49
47
|
twist: ev.twist,
|
|
50
48
|
pointerType: ev.pointerType,
|
|
51
49
|
isPrimary: ev.isPrimary,
|
|
52
|
-
};
|
|
53
|
-
newEvent = new PointerEvent('dblclick', init);
|
|
50
|
+
});
|
|
54
51
|
} else {
|
|
55
52
|
newEvent = new MouseEvent('dblclick', init);
|
|
56
53
|
}
|
|
@@ -75,14 +72,22 @@ export function addDoubleTapListener(obj, handler) {
|
|
|
75
72
|
// It seems that in all such cases `detail` property of `click` event is always `1`.
|
|
76
73
|
// So here we rely on that fact to avoid excessive 'dblclick' simulation when not needed.
|
|
77
74
|
let last = 0,
|
|
78
|
-
detail
|
|
75
|
+
detail,
|
|
76
|
+
pointerType;
|
|
77
|
+
|
|
78
|
+
// iOS Safari reports `pointerType: 'mouse'` on clicks from touch (WebKit bug 282988), so we take it from the
|
|
79
|
+
// pointerdown instead; capturing so that it's seen even if a child (e.g. a control) stops its propagation.
|
|
80
|
+
function onPointerDown(ev) {
|
|
81
|
+
pointerType = ev.pointerType;
|
|
82
|
+
}
|
|
83
|
+
|
|
79
84
|
function simDblclick(ev) {
|
|
80
85
|
if (ev.detail !== 1) {
|
|
81
86
|
detail = ev.detail; // keep in sync to avoid false dblclick in some cases
|
|
82
87
|
return;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
if (
|
|
90
|
+
if (pointerType === 'mouse' ||
|
|
86
91
|
(ev.sourceCapabilities && !ev.sourceCapabilities.firesTouchEvents)) {
|
|
87
92
|
|
|
88
93
|
return;
|
|
@@ -93,8 +98,8 @@ export function addDoubleTapListener(obj, handler) {
|
|
|
93
98
|
// This ignores clicks on elements which are a label with a 'for'
|
|
94
99
|
// attribute (or children of such a label), but not children of
|
|
95
100
|
// a <input>.
|
|
96
|
-
const path =
|
|
97
|
-
if (path.some(el => el instanceof HTMLLabelElement && el.
|
|
101
|
+
const path = ev.composedPath();
|
|
102
|
+
if (path.some(el => el instanceof HTMLLabelElement && el.htmlFor) &&
|
|
98
103
|
!path.some(el => (
|
|
99
104
|
el instanceof HTMLInputElement ||
|
|
100
105
|
el instanceof HTMLSelectElement
|
|
@@ -115,10 +120,12 @@ export function addDoubleTapListener(obj, handler) {
|
|
|
115
120
|
last = now;
|
|
116
121
|
}
|
|
117
122
|
|
|
123
|
+
obj.addEventListener('pointerdown', onPointerDown, true);
|
|
118
124
|
obj.addEventListener('click', simDblclick);
|
|
119
125
|
|
|
120
126
|
return {
|
|
121
127
|
dblclick: handler,
|
|
128
|
+
onPointerDown,
|
|
122
129
|
simDblclick
|
|
123
130
|
};
|
|
124
131
|
}
|
|
@@ -131,5 +138,6 @@ export function addDoubleTapListener(obj, handler) {
|
|
|
131
138
|
*/
|
|
132
139
|
export function removeDoubleTapListener(obj, handlers) {
|
|
133
140
|
obj.removeEventListener('dblclick', handlers.dblclick);
|
|
141
|
+
obj.removeEventListener('pointerdown', handlers.onPointerDown, true);
|
|
134
142
|
obj.removeEventListener('click', handlers.simDblclick);
|
|
135
143
|
}
|
|
@@ -30,12 +30,9 @@ function disablePointerDetection(el) {
|
|
|
30
30
|
el.removeEventListener('pointercancel', _onDelete, {capture: true});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
//
|
|
34
|
-
// synthetic events. The prosthetic-hand library does handle pointer capture,
|
|
35
|
-
// but others don't.
|
|
36
|
-
// If this becomers an issue, replace with `e.isTrusted && e.target.setPointerCapture()`
|
|
33
|
+
// capturing throws for synthetic pointers the browser doesn't know about, so only capture real ones
|
|
37
34
|
function _onSet(e) {
|
|
38
|
-
e.target.setPointerCapture(e.pointerId);
|
|
35
|
+
if (e.isTrusted) { e.target.setPointerCapture(e.pointerId); }
|
|
39
36
|
activePointers.set(e.pointerId, e);
|
|
40
37
|
}
|
|
41
38
|
|
|
@@ -45,7 +42,6 @@ function _onUpdate(e) {
|
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
// NOTE: idem as _onSet.
|
|
49
45
|
function _onDelete(e) {
|
|
50
46
|
// released already if the document has nested maps (e.g. an overview map)
|
|
51
47
|
if (e.target.hasPointerCapture(e.pointerId)) {
|
|
@@ -63,28 +59,9 @@ function getPointers() {
|
|
|
63
59
|
return [...activePointers.values()];
|
|
64
60
|
}
|
|
65
61
|
|
|
66
|
-
/**
|
|
67
|
-
* Clears the detected pointers on the document.
|
|
68
|
-
* Note: This function should be not necessary to call, as the pointers are
|
|
69
|
-
* automatically cleared with `pointerup`, `pointercancel` and `pointerout` events.
|
|
70
|
-
* @group Pointer detection
|
|
71
|
-
* @returns {void}
|
|
72
|
-
*/
|
|
73
|
-
function cleanupPointers() {
|
|
74
|
-
for (const e of activePointers.values()) {
|
|
75
|
-
try {
|
|
76
|
-
e.target.releasePointerCapture(e.pointerId);
|
|
77
|
-
} catch {
|
|
78
|
-
// target may already be detached; capture was on a dead node
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
activePointers.clear();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
62
|
export {
|
|
85
63
|
enablePointerDetection,
|
|
86
64
|
disablePointerDetection,
|
|
87
|
-
getPointers
|
|
88
|
-
cleanupPointers
|
|
65
|
+
getPointers
|
|
89
66
|
};
|
|
90
67
|
|