maplair 4.3.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +151 -8
- package/dist/esm/control/AttributionControl.js +30 -13
- package/dist/esm/control/AttributionControl.js.map +1 -1
- package/dist/esm/control/ButtonControl.js +0 -1
- package/dist/esm/control/ButtonControl.js.map +1 -1
- package/dist/esm/control/ContextMenu.js +1 -1
- package/dist/esm/control/ContextMenu.js.map +1 -1
- package/dist/esm/control/Control.js +16 -11
- package/dist/esm/control/Control.js.map +1 -1
- package/dist/esm/control/FullscreenControl.js +0 -1
- package/dist/esm/control/FullscreenControl.js.map +1 -1
- package/dist/esm/control/LayersControl.js +46 -27
- package/dist/esm/control/LayersControl.js.map +1 -1
- package/dist/esm/control/RotateControl.js +0 -1
- package/dist/esm/control/RotateControl.js.map +1 -1
- package/dist/esm/control/ScaleControl.js +7 -8
- package/dist/esm/control/ScaleControl.js.map +1 -1
- package/dist/esm/control/SideBySideControl.js +3 -2
- package/dist/esm/control/SideBySideControl.js.map +1 -1
- package/dist/esm/control/ZoomControl.js +14 -13
- package/dist/esm/control/ZoomControl.js.map +1 -1
- package/dist/esm/core/Events.js +3 -2
- package/dist/esm/core/Events.js.map +1 -1
- package/dist/esm/core/Util.js +17 -5
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
- package/dist/esm/dom/DomEvent.js +4 -7
- package/dist/esm/dom/DomEvent.js.map +1 -1
- package/dist/esm/dom/DomUtil.js +5 -5
- package/dist/esm/dom/DomUtil.js.map +1 -1
- package/dist/esm/dom/Draggable.js +10 -8
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +24 -35
- package/dist/esm/geo/LatLng.js.map +1 -1
- package/dist/esm/geo/LatLngBounds.js +6 -3
- package/dist/esm/geo/LatLngBounds.js.map +1 -1
- package/dist/esm/geometry/Bounds.js +2 -2
- package/dist/esm/geometry/Bounds.js.map +1 -1
- package/dist/esm/geometry/Point.js +16 -19
- package/dist/esm/geometry/Point.js.map +1 -1
- package/dist/esm/geometry/PolyUtil.js +10 -3
- package/dist/esm/geometry/PolyUtil.js.map +1 -1
- package/dist/esm/geometry/Transformation.js +1 -7
- package/dist/esm/geometry/Transformation.js.map +1 -1
- package/dist/esm/layer/BlanketOverlay.js +3 -2
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +25 -25
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +8 -5
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +12 -7
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +33 -15
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +48 -56
- package/dist/esm/layer/Tooltip.js.map +1 -1
- package/dist/esm/layer/VideoOverlay.js +2 -2
- package/dist/esm/layer/VideoOverlay.js.map +1 -1
- package/dist/esm/layer/marker/DivIcon.js +4 -8
- package/dist/esm/layer/marker/DivIcon.js.map +1 -1
- package/dist/esm/layer/marker/Icon.js +37 -17
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +11 -12
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +54 -53
- package/dist/esm/layer/marker/Marker.js.map +1 -1
- package/dist/esm/layer/marker/SvgIcon.js +1 -1
- package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
- package/dist/esm/layer/tile/GridLayer.js +29 -21
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +19 -15
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +45 -94
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +8 -9
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +15 -4
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
- package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
- package/dist/esm/layer/vector/Path.js +10 -5
- package/dist/esm/layer/vector/Path.js.map +1 -1
- package/dist/esm/layer/vector/Polygon.js +10 -11
- package/dist/esm/layer/vector/Polygon.js.map +1 -1
- package/dist/esm/layer/vector/Polyline.js +19 -26
- package/dist/esm/layer/vector/Polyline.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
- package/dist/esm/layer/vector/Renderer.js +16 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -1
- package/dist/esm/layer/vector/SVG.js +3 -3
- package/dist/esm/layer/vector/SVG.js.map +1 -1
- package/dist/esm/map/Map.Rotation.js +9 -11
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +158 -71
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +2 -5
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/DisplaceHandler.js +68 -30
- package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
- package/dist/esm/map/handler/DragHandler.js +7 -2
- package/dist/esm/map/handler/DragHandler.js.map +1 -1
- package/dist/esm/map/handler/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
- package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapHoldHandler.js +8 -20
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/maplair-global-src.js +970 -810
- package/dist/maplair-global-src.js.map +1 -1
- package/dist/maplair-global.js +2 -2
- package/dist/maplair-global.js.map +1 -1
- package/dist/maplair-src.js +970 -810
- package/dist/maplair-src.js.map +1 -1
- package/dist/maplair.css +1 -1
- package/dist/maplair.js +2 -2
- package/dist/maplair.js.map +1 -1
- package/i18n/en.json +1 -0
- package/package.json +1 -1
- package/src/control/AttributionControl.js +37 -11
- package/src/control/ButtonControl.js +0 -1
- package/src/control/ContextMenu.js +1 -1
- package/src/control/Control.js +13 -16
- package/src/control/FullscreenControl.js +0 -1
- package/src/control/LayersControl.js +61 -37
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +10 -8
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +11 -13
- package/src/core/Events.js +6 -2
- package/src/core/Util.js +17 -4
- package/src/dom/DomEvent.PointerEvents.js +68 -2
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +11 -8
- package/src/geo/LatLng.js +24 -37
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +22 -28
- package/src/geometry/PolyUtil.js +12 -3
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +6 -3
- package/src/layer/DivOverlay.js +30 -32
- package/src/layer/ImageOverlay.js +12 -9
- package/src/layer/Layer.js +19 -7
- package/src/layer/Popup.js +41 -21
- package/src/layer/Tooltip.js +50 -70
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +41 -20
- package/src/layer/marker/Marker.Drag.js +22 -24
- package/src/layer/marker/Marker.js +71 -64
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +41 -30
- package/src/layer/tile/TileLayer.js +31 -21
- package/src/layer/tile/WMSTileLayer.js +4 -2
- package/src/layer/vector/Canvas.js +53 -149
- package/src/layer/vector/Circle.js +13 -13
- package/src/layer/vector/CircleMarker.js +16 -3
- package/src/layer/vector/Path.ZoomStyles.js +5 -3
- package/src/layer/vector/Path.js +11 -5
- package/src/layer/vector/Polygon.js +11 -10
- package/src/layer/vector/Polyline.js +20 -21
- package/src/layer/vector/Renderer.getRenderer.js +2 -1
- package/src/layer/vector/Renderer.js +21 -3
- package/src/layer/vector/SVG.js +3 -3
- package/src/map/Map.Rotation.js +13 -9
- package/src/map/Map.js +195 -83
- package/src/map/MapSync.js +2 -2
- package/src/map/handler/BoxZoomHandler.js +5 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/DragHandler.js +5 -5
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +4 -4
- package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
- package/src/map/handler/TapDragZoomHandler.js +2 -2
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +50 -10
- package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
- package/src/dom/DomEvent.DoubleTap.js +0 -143
package/i18n/en.json
CHANGED
package/package.json
CHANGED
|
@@ -64,6 +64,7 @@ export class AttributionControl extends Control {
|
|
|
64
64
|
this._attributions = {};
|
|
65
65
|
this._orders = {};
|
|
66
66
|
this._layerAttributions = new Map();
|
|
67
|
+
this._shownLayers = new Set();
|
|
67
68
|
|
|
68
69
|
this.callInitHooks(AttributionControl);
|
|
69
70
|
}
|
|
@@ -85,18 +86,21 @@ export class AttributionControl extends Control {
|
|
|
85
86
|
|
|
86
87
|
this._update();
|
|
87
88
|
|
|
88
|
-
map.on({layeradd: this._addLayer, layerremove: this._removeLayer}, this);
|
|
89
|
-
|
|
90
89
|
return this._container;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
/**
|
|
94
93
|
* @internal
|
|
95
|
-
* @
|
|
94
|
+
* @returns {Record<string, Function>}
|
|
96
95
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
getEvents() {
|
|
97
|
+
return {layeradd: this._addLayer, layerremove: this._removeLayer, zoomend: this._onZoomEnd};
|
|
98
|
+
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
onRemove() {
|
|
100
104
|
for (const layer of this._layerAttributions.keys()) {
|
|
101
105
|
this._removeLayer({layer});
|
|
102
106
|
}
|
|
@@ -107,14 +111,39 @@ export class AttributionControl extends Control {
|
|
|
107
111
|
if (!text || this._layerAttributions.has(layer)) { return; }
|
|
108
112
|
|
|
109
113
|
this._layerAttributions.set(layer, text);
|
|
110
|
-
this.
|
|
114
|
+
this._updateLayer(layer);
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
_removeLayer({layer}) {
|
|
114
|
-
|
|
118
|
+
if (this._shownLayers.delete(layer)) {
|
|
119
|
+
this.removeAttribution(this._layerAttributions.get(layer));
|
|
120
|
+
}
|
|
115
121
|
this._layerAttributions.delete(layer);
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
_onZoomEnd() {
|
|
125
|
+
for (const layer of this._layerAttributions.keys()) {
|
|
126
|
+
this._updateLayer(layer);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Layers with `minZoom`/`maxZoom` options (e.g. tile layers) aren't displayed outside that range.
|
|
131
|
+
_updateLayer(layer) {
|
|
132
|
+
const {minZoom = -Infinity, maxZoom = Infinity} = layer.options ?? {},
|
|
133
|
+
zoom = this._map.getZoom(),
|
|
134
|
+
show = zoom >= minZoom && zoom <= maxZoom;
|
|
135
|
+
if (show === this._shownLayers.has(layer)) { return; }
|
|
136
|
+
|
|
137
|
+
const text = this._layerAttributions.get(layer);
|
|
138
|
+
if (show) {
|
|
139
|
+
this._shownLayers.add(layer);
|
|
140
|
+
this.addAttribution(text, layer.options?.attributionOrder);
|
|
141
|
+
} else {
|
|
142
|
+
this._shownLayers.delete(layer);
|
|
143
|
+
this.removeAttribution(text);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
118
147
|
/**
|
|
119
148
|
* The HTML text shown before the attributions. Pass `false` to disable.
|
|
120
149
|
* @param {string|false} prefix
|
|
@@ -138,10 +167,7 @@ export class AttributionControl extends Control {
|
|
|
138
167
|
if (!text) { return this; }
|
|
139
168
|
|
|
140
169
|
this._orders[text] = order;
|
|
141
|
-
|
|
142
|
-
this._attributions[text] = 0;
|
|
143
|
-
}
|
|
144
|
-
this._attributions[text]++;
|
|
170
|
+
this._attributions[text] = (this._attributions[text] || 0) + 1;
|
|
145
171
|
|
|
146
172
|
this._update();
|
|
147
173
|
|
|
@@ -107,7 +107,6 @@ export class ButtonControl extends Control {
|
|
|
107
107
|
DomEvent.disableClickPropagation(button);
|
|
108
108
|
DomEvent.on(button, 'click', DomEvent.stop);
|
|
109
109
|
DomEvent.on(button, 'click', this._onClick, this);
|
|
110
|
-
DomEvent.on(button, 'click', this._refocusOnMap, this);
|
|
111
110
|
|
|
112
111
|
this._update();
|
|
113
112
|
return button;
|
|
@@ -148,7 +148,7 @@ export class ContextMenu extends Class {
|
|
|
148
148
|
_createMenu(parent) {
|
|
149
149
|
const container = this._container ??= DomUtil.create('div', `maplair-contextmenu ${this.options.className}`);
|
|
150
150
|
if (container.parentNode !== parent) {
|
|
151
|
-
parent.
|
|
151
|
+
parent.append(container);
|
|
152
152
|
}
|
|
153
153
|
container.popover = 'auto';
|
|
154
154
|
container.setAttribute('role', 'menu');
|
package/src/control/Control.js
CHANGED
|
@@ -70,6 +70,9 @@ const mapControlMethods = {
|
|
|
70
70
|
* @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that
|
|
71
71
|
* removes the listeners previously added in `onAdd`. Called on
|
|
72
72
|
* [`control.remove()`](#control-remove).
|
|
73
|
+
* @property {() => Record<string, Function>} [getEvents] Should return an object like
|
|
74
|
+
* `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this object
|
|
75
|
+
* will be automatically added and removed from the map with your control.
|
|
73
76
|
* @lends Control
|
|
74
77
|
*/
|
|
75
78
|
|
|
@@ -77,8 +80,9 @@ const mapControlMethods = {
|
|
|
77
80
|
const controlOrders = new WeakMap();
|
|
78
81
|
|
|
79
82
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
83
|
+
* Base class for map controls such as `ZoomControl`, `AttributionControl`,
|
|
84
|
+
* `LayersControl` and `ScaleControl`, which handles positioning them. Extend it to
|
|
85
|
+
* create your own controls.
|
|
82
86
|
*
|
|
83
87
|
* Every control should extend from `Control` and (re-)implement the following methods:
|
|
84
88
|
*
|
|
@@ -88,6 +92,9 @@ const controlOrders = new WeakMap();
|
|
|
88
92
|
* * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes
|
|
89
93
|
* the listeners previously added in [`onAdd`](#control-onadd). Called on
|
|
90
94
|
* [`control.remove()`](#control-remove).
|
|
95
|
+
* * `getEvents(): Object` (optional) should return an object like
|
|
96
|
+
* `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this
|
|
97
|
+
* object will be automatically added and removed from the map with your control.
|
|
91
98
|
*/
|
|
92
99
|
export class Control extends Class {
|
|
93
100
|
|
|
@@ -164,7 +171,8 @@ export class Control extends Class {
|
|
|
164
171
|
(controlOrders.get(el) ?? 0) <= order :
|
|
165
172
|
(controlOrders.get(el) ?? 0) > order) ?? null);
|
|
166
173
|
|
|
167
|
-
this.
|
|
174
|
+
this._mapEvents = {...this.getEvents?.(), unload: this.remove};
|
|
175
|
+
map.on(this._mapEvents, this);
|
|
168
176
|
|
|
169
177
|
return this;
|
|
170
178
|
}
|
|
@@ -179,25 +187,14 @@ export class Control extends Class {
|
|
|
179
187
|
}
|
|
180
188
|
|
|
181
189
|
this._container.remove();
|
|
190
|
+
this._map.off(this._mapEvents, this);
|
|
191
|
+
this.onRemove?.(this._map);
|
|
182
192
|
|
|
183
|
-
if (this.onRemove) {
|
|
184
|
-
this.onRemove(this._map);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
this._map.off('unload', this.remove, this);
|
|
188
193
|
this._map = null;
|
|
189
194
|
|
|
190
195
|
return this;
|
|
191
196
|
}
|
|
192
197
|
|
|
193
|
-
_refocusOnMap(e) {
|
|
194
|
-
// We exclude keyboard-click event to keep the focus on the control for accessibility.
|
|
195
|
-
// The position of keyboard-click events are x=0 and y=0.
|
|
196
|
-
if (this._map && e && !(e.screenX === 0 && e.screenY === 0)) {
|
|
197
|
-
this._map.getContainer().focus({preventScroll: true, focusVisible: false});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
198
|
/**
|
|
202
199
|
* Registers this default feature on the map class, called by `MaplairMap` itself.
|
|
203
200
|
* @internal
|
|
@@ -163,7 +163,6 @@ export class FullscreenControl extends Control {
|
|
|
163
163
|
DomEvent.disableClickPropagation(button);
|
|
164
164
|
DomEvent.on(button, 'click', DomEvent.stop);
|
|
165
165
|
DomEvent.on(button, 'click', this._toggleFullscreen, this);
|
|
166
|
-
DomEvent.on(button, 'click', this._refocusOnMap, this);
|
|
167
166
|
|
|
168
167
|
this._update();
|
|
169
168
|
map.on('fullscreenchange', this._update, this);
|
|
@@ -43,6 +43,8 @@ import {I18n} from '../core/I18n.js';
|
|
|
43
43
|
* `maplair-control-layers-group-name` element, and each entry shows only its label.
|
|
44
44
|
* Events like `baselayerchange` still carry the full `name`. When combined with
|
|
45
45
|
* `sortLayers`, the entries are sorted first and grouped afterwards.
|
|
46
|
+
* @property {string} [title] The title of the toggle button and the accessible label
|
|
47
|
+
* of the layers list, the translation of `'Layers'` by default.
|
|
46
48
|
* @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
|
|
47
49
|
* collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
|
|
48
50
|
* element. String content is rendered as HTML; do not pass untrusted input.
|
|
@@ -129,6 +131,7 @@ export class LayersControl extends Control {
|
|
|
129
131
|
collapsed: true,
|
|
130
132
|
inline: false,
|
|
131
133
|
groupBy: undefined,
|
|
134
|
+
title: undefined,
|
|
132
135
|
toggleContent: undefined,
|
|
133
136
|
collapseDelay: 0,
|
|
134
137
|
position: 'topright',
|
|
@@ -157,6 +160,7 @@ export class LayersControl extends Control {
|
|
|
157
160
|
this._lastZIndex = 0;
|
|
158
161
|
this._handlingClick = false;
|
|
159
162
|
this._preventClick = false;
|
|
163
|
+
this._needsUpdate = false;
|
|
160
164
|
|
|
161
165
|
for (const [name, layer] of Object.entries(baseLayers ?? {})) {
|
|
162
166
|
this._addLayer(layer, name);
|
|
@@ -268,6 +272,8 @@ export class LayersControl extends Control {
|
|
|
268
272
|
* @returns {this}
|
|
269
273
|
*/
|
|
270
274
|
selectLayer(layer) {
|
|
275
|
+
// the list isn't rebuilt while collapsed
|
|
276
|
+
if (this._needsUpdate) { this._update(true); }
|
|
271
277
|
const input = this._layerControlInputs.find(input => input._layer === layer);
|
|
272
278
|
if (input && !input.checked) {
|
|
273
279
|
input.checked = true;
|
|
@@ -284,6 +290,7 @@ export class LayersControl extends Control {
|
|
|
284
290
|
clearTimeout(this._collapseDelayTimeout);
|
|
285
291
|
|
|
286
292
|
this._container.classList.add('maplair-control-layers-expanded');
|
|
293
|
+
if (this._needsUpdate) { this._update(); }
|
|
287
294
|
this._section.style.height = '';
|
|
288
295
|
const acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
|
|
289
296
|
if (acceptableHeight < this._section.clientHeight) {
|
|
@@ -304,6 +311,7 @@ export class LayersControl extends Control {
|
|
|
304
311
|
if (this.options.inline) {
|
|
305
312
|
return this;
|
|
306
313
|
}
|
|
314
|
+
clearTimeout(this._collapseDelayTimeout);
|
|
307
315
|
if (this.options.collapseDelay > 0) {
|
|
308
316
|
this._collapseDelayTimeout = setTimeout(() => {
|
|
309
317
|
this._container.classList.remove('maplair-control-layers-expanded');
|
|
@@ -314,6 +322,10 @@ export class LayersControl extends Control {
|
|
|
314
322
|
return this;
|
|
315
323
|
}
|
|
316
324
|
|
|
325
|
+
_getTitle() {
|
|
326
|
+
return this.options.title ?? I18n.translate('Layers');
|
|
327
|
+
}
|
|
328
|
+
|
|
317
329
|
_initLayout() {
|
|
318
330
|
const className = 'maplair-control-layers',
|
|
319
331
|
container = this._container = DomUtil.create('div', className),
|
|
@@ -327,25 +339,15 @@ export class LayersControl extends Control {
|
|
|
327
339
|
DomEvent.disableScrollPropagation(container);
|
|
328
340
|
|
|
329
341
|
const section = this._section = DomUtil.create('fieldset', `${className}-list`);
|
|
330
|
-
section.setAttribute('aria-label',
|
|
331
|
-
|
|
332
|
-
if (collapsed) {
|
|
333
|
-
this._map.on('click', this.collapse, this);
|
|
334
|
-
|
|
335
|
-
DomEvent.on(container, {
|
|
336
|
-
pointerenter: this._expandSafely,
|
|
337
|
-
// on touch devices, pointerleave fires while clicking a checkbox, which shouldn't collapse the control
|
|
338
|
-
pointerleave(e) {
|
|
339
|
-
if (e.pointerType !== 'touch') { this.collapse(); }
|
|
340
|
-
}
|
|
341
|
-
}, this);
|
|
342
|
-
}
|
|
342
|
+
section.setAttribute('aria-label', this._getTitle());
|
|
343
|
+
section.tabIndex = -1;
|
|
343
344
|
|
|
345
|
+
let link;
|
|
344
346
|
if (!this.options.inline) {
|
|
345
|
-
|
|
347
|
+
link = this._layersLink = DomUtil.create('button', `${className}-toggle`, container);
|
|
346
348
|
link.type = 'button';
|
|
347
|
-
link.title =
|
|
348
|
-
link.setAttribute('aria-label',
|
|
349
|
+
link.title = this._getTitle();
|
|
350
|
+
link.setAttribute('aria-label', link.title);
|
|
349
351
|
|
|
350
352
|
const {toggleContent} = this.options;
|
|
351
353
|
if (typeof toggleContent === 'string') {
|
|
@@ -354,21 +356,36 @@ export class LayersControl extends Control {
|
|
|
354
356
|
link.replaceChildren(toggleContent);
|
|
355
357
|
}
|
|
356
358
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
359
|
+
// also for Enter and Space, and for screen readers that send a click instead of the key event
|
|
360
|
+
DomEvent.on(link, 'click', (e) => {
|
|
361
|
+
e.preventDefault();
|
|
362
|
+
const focused = document.activeElement === link;
|
|
363
|
+
this._expandSafely();
|
|
364
|
+
if (focused) { section.focus(); }
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (collapsed) {
|
|
369
|
+
this._map.on('click', this.collapse, this);
|
|
370
|
+
|
|
371
|
+
DomEvent.on(container, {
|
|
372
|
+
pointerenter: this._expandSafely,
|
|
373
|
+
// on touch devices, pointerleave fires while clicking a checkbox, which shouldn't collapse the control
|
|
374
|
+
pointerleave(e) {
|
|
375
|
+
if (e.pointerType !== 'touch') { this.collapse(); }
|
|
367
376
|
}
|
|
368
377
|
}, this);
|
|
369
|
-
}
|
|
370
378
|
|
|
371
|
-
|
|
379
|
+
// the list only takes focus while expanded; skip `collapseDelay`, as the toggle is hidden until then
|
|
380
|
+
DomEvent.on(section, 'keydown', (e) => {
|
|
381
|
+
if (e.key === 'Escape') {
|
|
382
|
+
clearTimeout(this._collapseDelayTimeout);
|
|
383
|
+
container.classList.remove(`${className}-expanded`);
|
|
384
|
+
link.focus();
|
|
385
|
+
e.preventDefault();
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
} else {
|
|
372
389
|
this.expand();
|
|
373
390
|
}
|
|
374
391
|
|
|
@@ -376,7 +393,7 @@ export class LayersControl extends Control {
|
|
|
376
393
|
this._separator = DomUtil.create('div', `${className}-separator`, section);
|
|
377
394
|
this._overlaysList = DomUtil.create('div', `${className}-overlays`, section);
|
|
378
395
|
|
|
379
|
-
container.
|
|
396
|
+
container.append(section);
|
|
380
397
|
}
|
|
381
398
|
|
|
382
399
|
_addLayer(layer, name, overlay) {
|
|
@@ -402,9 +419,17 @@ export class LayersControl extends Control {
|
|
|
402
419
|
this._expandIfNotCollapsed();
|
|
403
420
|
}
|
|
404
421
|
|
|
405
|
-
_update() {
|
|
422
|
+
_update(force) {
|
|
406
423
|
if (!this._container) { return this; }
|
|
407
424
|
|
|
425
|
+
// Rebuilding on every layer change makes adding n layers O(n²). The list is hidden
|
|
426
|
+
// while collapsed, so leave it until `expand()` shows it.
|
|
427
|
+
if (!force && !this._container.classList.contains('maplair-control-layers-expanded')) {
|
|
428
|
+
this._needsUpdate = true;
|
|
429
|
+
return this;
|
|
430
|
+
}
|
|
431
|
+
this._needsUpdate = false;
|
|
432
|
+
|
|
408
433
|
this._baseLayersList.replaceChildren();
|
|
409
434
|
this._overlaysList.replaceChildren();
|
|
410
435
|
|
|
@@ -427,6 +452,9 @@ export class LayersControl extends Control {
|
|
|
427
452
|
|
|
428
453
|
this._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';
|
|
429
454
|
|
|
455
|
+
// once for the whole list, as it loops over every input
|
|
456
|
+
this._checkDisabledLayers();
|
|
457
|
+
|
|
430
458
|
return this;
|
|
431
459
|
}
|
|
432
460
|
|
|
@@ -472,15 +500,13 @@ export class LayersControl extends Control {
|
|
|
472
500
|
// https://github.com/Leaflet/Leaflet/issues/2771
|
|
473
501
|
const holder = document.createElement('span');
|
|
474
502
|
|
|
475
|
-
label.
|
|
476
|
-
holder.
|
|
477
|
-
holder.appendChild(name);
|
|
503
|
+
label.append(holder);
|
|
504
|
+
holder.append(input, name);
|
|
478
505
|
|
|
479
506
|
const list = obj.overlay ? this._overlaysList : this._baseLayersList;
|
|
480
507
|
const container = group ? this._getGroupContainer(list, group.group) : list;
|
|
481
|
-
container.
|
|
508
|
+
container.append(label);
|
|
482
509
|
|
|
483
|
-
this._checkDisabledLayers();
|
|
484
510
|
return label;
|
|
485
511
|
}
|
|
486
512
|
|
|
@@ -549,8 +575,6 @@ export class LayersControl extends Control {
|
|
|
549
575
|
break;
|
|
550
576
|
}
|
|
551
577
|
}
|
|
552
|
-
|
|
553
|
-
this._refocusOnMap(e);
|
|
554
578
|
}
|
|
555
579
|
|
|
556
580
|
_checkDisabledLayers() {
|
|
@@ -74,7 +74,6 @@ export class RotateControl extends Control {
|
|
|
74
74
|
DomEvent.disableClickPropagation(button);
|
|
75
75
|
DomEvent.on(button, 'click', DomEvent.stop);
|
|
76
76
|
DomEvent.on(button, 'click', this._resetNorth, this);
|
|
77
|
-
DomEvent.on(button, 'click', this._refocusOnMap, this);
|
|
78
77
|
|
|
79
78
|
this._update();
|
|
80
79
|
map.on('rotate', this._update, this);
|
|
@@ -62,7 +62,6 @@ export class ScaleControl extends Control {
|
|
|
62
62
|
|
|
63
63
|
this._addScales(options, `${className}-line`, container);
|
|
64
64
|
|
|
65
|
-
map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
|
|
66
65
|
map.whenReady(this._update, this);
|
|
67
66
|
|
|
68
67
|
return container;
|
|
@@ -70,10 +69,10 @@ export class ScaleControl extends Control {
|
|
|
70
69
|
|
|
71
70
|
/**
|
|
72
71
|
* @internal
|
|
73
|
-
* @
|
|
72
|
+
* @returns {Record<string, Function>}
|
|
74
73
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
getEvents() {
|
|
75
|
+
return {[this.options.updateWhenIdle ? 'moveend' : 'move']: this._update};
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
_addScales(options, className, container) {
|
|
@@ -131,18 +130,21 @@ export class ScaleControl extends Control {
|
|
|
131
130
|
|
|
132
131
|
_updateScale(scale, text, ratio) {
|
|
133
132
|
scale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;
|
|
134
|
-
scale.
|
|
133
|
+
scale.textContent = text;
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
_getRoundNum(num) {
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
// Below 1, count the zeros after the decimal point instead, so that 0.35 gives 0.3 rather than 1
|
|
138
|
+
// (which would draw the scale wider than maxWidth)
|
|
139
|
+
const exponent = num < 1 ? Math.floor(Math.log10(num)) : (`${Math.floor(num)}`).length - 1;
|
|
140
|
+
let d = num / 10 ** exponent;
|
|
140
141
|
|
|
141
142
|
d = d >= 10 ? 10 :
|
|
142
143
|
d >= 5 ? 5 :
|
|
143
144
|
d >= 3 ? 3 :
|
|
144
145
|
d >= 2 ? 2 : 1;
|
|
145
146
|
|
|
146
|
-
|
|
147
|
+
// dividing by a power of ten keeps 0.3 exact, where 3 * 0.1 gives 0.30000000000000004
|
|
148
|
+
return exponent < 0 ? d / 10 ** -exponent : d * 10 ** exponent;
|
|
147
149
|
}
|
|
148
150
|
}
|
|
@@ -72,8 +72,10 @@ export class SideBySideControl extends Control {
|
|
|
72
72
|
this.remove();
|
|
73
73
|
this._map = map;
|
|
74
74
|
this._container = this.onAdd(map);
|
|
75
|
-
map._container.
|
|
76
|
-
|
|
75
|
+
map._container.append(this._container);
|
|
76
|
+
// removed by `remove()` of `Control`
|
|
77
|
+
this._mapEvents = {unload: this.remove};
|
|
78
|
+
map.on(this._mapEvents, this);
|
|
77
79
|
return this;
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -12,10 +12,10 @@ import {I18n} from '../core/I18n.js';
|
|
|
12
12
|
* @property {string} [position='topleft'] The position of the control (one of the map
|
|
13
13
|
* corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
|
|
14
14
|
* `'bottomright'`.
|
|
15
|
-
* @property {string} [zoomInText
|
|
16
|
-
*
|
|
17
|
-
* @property {string} [zoomOutText
|
|
18
|
-
*
|
|
15
|
+
* @property {string} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn
|
|
16
|
+
* in SVG by default.
|
|
17
|
+
* @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign
|
|
18
|
+
* drawn in SVG by default.
|
|
19
19
|
* @extends ControlOptions
|
|
20
20
|
*/
|
|
21
21
|
|
|
@@ -43,8 +43,8 @@ export class ZoomControl extends Control {
|
|
|
43
43
|
|
|
44
44
|
static defaultOptions = {
|
|
45
45
|
position: 'topleft',
|
|
46
|
-
zoomInText: '<
|
|
47
|
-
zoomOutText: '<
|
|
46
|
+
zoomInText: '<svg width="12" height="12" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M0 6h12M6 0v12"/></svg>',
|
|
47
|
+
zoomOutText: '<svg width="12" height="12" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M0 6h12"/></svg>',
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -58,10 +58,9 @@ export class ZoomControl extends Control {
|
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* @internal
|
|
61
|
-
* @param {MaplairMap} map
|
|
62
61
|
* @returns {HTMLElement}
|
|
63
62
|
*/
|
|
64
|
-
onAdd(
|
|
63
|
+
onAdd() {
|
|
65
64
|
const zoomName = 'maplair-control-zoom',
|
|
66
65
|
container = DomUtil.create('div', `${zoomName} maplair-bar`),
|
|
67
66
|
options = this.options;
|
|
@@ -72,17 +71,16 @@ export class ZoomControl extends Control {
|
|
|
72
71
|
`${zoomName}-out`, container, e => this._zoom(e, -1));
|
|
73
72
|
|
|
74
73
|
this._updateDisabled();
|
|
75
|
-
map.on('zoomend zoomlevelschange', this._updateDisabled, this);
|
|
76
74
|
|
|
77
75
|
return container;
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
/**
|
|
81
79
|
* @internal
|
|
82
|
-
* @
|
|
80
|
+
* @returns {Record<string, Function>}
|
|
83
81
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
getEvents() {
|
|
83
|
+
return {zoomend: this._updateDisabled, zoomlevelschange: this._updateDisabled};
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
/**
|
|
@@ -124,7 +122,6 @@ export class ZoomControl extends Control {
|
|
|
124
122
|
DomEvent.on(link, 'click', (e) => {
|
|
125
123
|
DomEvent.stop(e);
|
|
126
124
|
fn.call(this, e);
|
|
127
|
-
this._refocusOnMap(e);
|
|
128
125
|
});
|
|
129
126
|
|
|
130
127
|
return link;
|
|
@@ -132,6 +129,7 @@ export class ZoomControl extends Control {
|
|
|
132
129
|
|
|
133
130
|
_updateDisabled() {
|
|
134
131
|
const map = this._map;
|
|
132
|
+
if (!map) { return; } // `onAdd` applies the state
|
|
135
133
|
for (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {
|
|
136
134
|
const disabled = this._disabled || map._zoom === limit;
|
|
137
135
|
button.classList.toggle('maplair-disabled', disabled);
|
package/src/core/Events.js
CHANGED
|
@@ -310,8 +310,12 @@ export class Evented extends Class {
|
|
|
310
310
|
|
|
311
311
|
this._events ??= {};
|
|
312
312
|
// a Set keeps the listeners in order, and allows removing them in constant time
|
|
313
|
-
this._events[type] ??= new Set();
|
|
314
|
-
this.
|
|
313
|
+
let listeners = this._events[type] ??= new Set();
|
|
314
|
+
if (this._firingCount) {
|
|
315
|
+
// copy the listeners being fired, so that the new one is called from the next fire on
|
|
316
|
+
this._events[type] = listeners = new Set(listeners);
|
|
317
|
+
}
|
|
318
|
+
listeners.add(newListener);
|
|
315
319
|
|
|
316
320
|
if (contexts) {
|
|
317
321
|
contexts.set(context, newListener);
|
package/src/core/Util.js
CHANGED
|
@@ -87,12 +87,23 @@ export function falseFn() { return false; }
|
|
|
87
87
|
* @param {number|false} [precision]
|
|
88
88
|
* @returns {number}
|
|
89
89
|
*/
|
|
90
|
-
export function formatNum(num, precision) {
|
|
90
|
+
export function formatNum(num, precision = 6) {
|
|
91
91
|
if (precision === false) { return num; }
|
|
92
|
-
const pow = 10 **
|
|
92
|
+
const pow = 10 ** precision;
|
|
93
93
|
return Math.round(num * pow) / pow;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Returns `value` if it's a number (including `Infinity`), converts it if it's a
|
|
98
|
+
* numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns
|
|
99
|
+
* `''`, `null` and booleans into `0` or `1`.
|
|
100
|
+
* @param {unknown} value
|
|
101
|
+
* @returns {number}
|
|
102
|
+
*/
|
|
103
|
+
export function toNumber(value) {
|
|
104
|
+
return typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? +value : NaN;
|
|
105
|
+
}
|
|
106
|
+
|
|
96
107
|
const WHITESPACE_RE = /\s+/;
|
|
97
108
|
|
|
98
109
|
/**
|
|
@@ -101,7 +112,9 @@ const WHITESPACE_RE = /\s+/;
|
|
|
101
112
|
* @returns {string[]}
|
|
102
113
|
*/
|
|
103
114
|
export function splitWords(str) {
|
|
104
|
-
|
|
115
|
+
// a single word is the common case, and splitting allocates a lot more than the array
|
|
116
|
+
const trimmed = str.trim();
|
|
117
|
+
return WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
/**
|
|
@@ -141,7 +154,7 @@ function getDefaultOptions(cls) {
|
|
|
141
154
|
return defaults;
|
|
142
155
|
}
|
|
143
156
|
|
|
144
|
-
const templateRe = /\{ *([\w_ -]
|
|
157
|
+
const templateRe = /\{ *([\w_ -]+?) *\}/g;
|
|
145
158
|
|
|
146
159
|
/**
|
|
147
160
|
* Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`
|