maplair 4.3.0 → 4.4.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 +89 -8
- package/dist/esm/control/AttributionControl.js +10 -10
- 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 +13 -9
- 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 +4 -5
- 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 +13 -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 +16 -4
- package/dist/esm/core/Util.js.map +1 -1
- package/dist/esm/dom/DomEvent.PointerEvents.js +55 -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 +4 -6
- package/dist/esm/dom/Draggable.js.map +1 -1
- package/dist/esm/geo/LatLng.js +23 -34
- 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 +12 -17
- package/dist/esm/geometry/Point.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 +1 -1
- package/dist/esm/layer/BlanketOverlay.js.map +1 -1
- package/dist/esm/layer/DivOverlay.js +23 -23
- package/dist/esm/layer/DivOverlay.js.map +1 -1
- package/dist/esm/layer/ImageOverlay.js +7 -4
- package/dist/esm/layer/ImageOverlay.js.map +1 -1
- package/dist/esm/layer/Layer.js +11 -6
- package/dist/esm/layer/Layer.js.map +1 -1
- package/dist/esm/layer/Popup.js +30 -11
- package/dist/esm/layer/Popup.js.map +1 -1
- package/dist/esm/layer/Tooltip.js +18 -35
- 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 +16 -15
- package/dist/esm/layer/marker/Icon.js.map +1 -1
- package/dist/esm/layer/marker/Marker.Drag.js +6 -7
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
- package/dist/esm/layer/marker/Marker.js +49 -48
- 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 +18 -16
- package/dist/esm/layer/tile/GridLayer.js.map +1 -1
- package/dist/esm/layer/tile/TileLayer.js +9 -9
- package/dist/esm/layer/tile/TileLayer.js.map +1 -1
- package/dist/esm/layer/vector/Canvas.js +44 -93
- package/dist/esm/layer/vector/Canvas.js.map +1 -1
- package/dist/esm/layer/vector/Circle.js +7 -7
- package/dist/esm/layer/vector/Circle.js.map +1 -1
- package/dist/esm/layer/vector/CircleMarker.js +9 -1
- package/dist/esm/layer/vector/CircleMarker.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 +6 -9
- package/dist/esm/map/Map.Rotation.js.map +1 -1
- package/dist/esm/map/Map.js +104 -49
- package/dist/esm/map/Map.js.map +1 -1
- package/dist/esm/map/MapSync.js +1 -4
- package/dist/esm/map/MapSync.js.map +1 -1
- package/dist/esm/map/handler/BoxZoomHandler.js +2 -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/KeyboardHandler.js +3 -5
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
- package/dist/esm/map/handler/PinchZoomHandler.js +3 -6
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -6
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
- package/dist/esm/map/handler/TapDragZoomHandler.js +1 -4
- 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 +698 -687
- 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 +698 -687
- 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 +9 -9
- 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 +14 -10
- package/src/control/RotateControl.js +0 -1
- package/src/control/ScaleControl.js +4 -5
- package/src/control/SideBySideControl.js +4 -2
- package/src/control/ZoomControl.js +10 -13
- package/src/core/Events.js +6 -2
- package/src/core/Util.js +16 -3
- package/src/dom/DomEvent.PointerEvents.js +47 -1
- package/src/dom/DomEvent.js +5 -17
- package/src/dom/DomUtil.js +5 -5
- package/src/dom/Draggable.js +5 -6
- package/src/geo/LatLng.js +22 -36
- package/src/geo/LatLngBounds.js +10 -4
- package/src/geometry/Bounds.js +3 -3
- package/src/geometry/Point.js +18 -26
- package/src/geometry/Transformation.js +1 -8
- package/src/layer/BlanketOverlay.js +1 -1
- package/src/layer/DivOverlay.js +28 -30
- package/src/layer/ImageOverlay.js +9 -7
- package/src/layer/Layer.js +18 -6
- package/src/layer/Popup.js +38 -17
- package/src/layer/Tooltip.js +17 -44
- package/src/layer/VideoOverlay.js +2 -2
- package/src/layer/marker/DivIcon.js +3 -6
- package/src/layer/marker/Icon.js +19 -18
- package/src/layer/marker/Marker.Drag.js +16 -18
- package/src/layer/marker/Marker.js +66 -59
- package/src/layer/marker/SvgIcon.js +1 -1
- package/src/layer/tile/GridLayer.js +21 -23
- package/src/layer/tile/TileLayer.js +17 -14
- package/src/layer/vector/Canvas.js +52 -148
- package/src/layer/vector/Circle.js +11 -9
- package/src/layer/vector/CircleMarker.js +11 -1
- 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 +7 -6
- package/src/map/Map.js +135 -54
- package/src/map/MapSync.js +1 -1
- package/src/map/handler/BoxZoomHandler.js +2 -0
- package/src/map/handler/DisplaceHandler.js +53 -7
- package/src/map/handler/KeyboardHandler.js +5 -10
- package/src/map/handler/PinchZoomHandler.js +3 -3
- package/src/map/handler/ScrollWheelZoomHandler.js +3 -3
- package/src/map/handler/TapDragZoomHandler.js +1 -1
- package/src/map/handler/TapHoldHandler.js +13 -25
- package/src/maplair.css +38 -9
- 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
|
@@ -85,18 +85,21 @@ export class AttributionControl extends Control {
|
|
|
85
85
|
|
|
86
86
|
this._update();
|
|
87
87
|
|
|
88
|
-
map.on({layeradd: this._addLayer, layerremove: this._removeLayer}, this);
|
|
89
|
-
|
|
90
88
|
return this._container;
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
/**
|
|
94
92
|
* @internal
|
|
95
|
-
* @
|
|
93
|
+
* @returns {Record<string, Function>}
|
|
96
94
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
getEvents() {
|
|
96
|
+
return {layeradd: this._addLayer, layerremove: this._removeLayer};
|
|
97
|
+
}
|
|
99
98
|
|
|
99
|
+
/**
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
onRemove() {
|
|
100
103
|
for (const layer of this._layerAttributions.keys()) {
|
|
101
104
|
this._removeLayer({layer});
|
|
102
105
|
}
|
|
@@ -138,10 +141,7 @@ export class AttributionControl extends Control {
|
|
|
138
141
|
if (!text) { return this; }
|
|
139
142
|
|
|
140
143
|
this._orders[text] = order;
|
|
141
|
-
|
|
142
|
-
this._attributions[text] = 0;
|
|
143
|
-
}
|
|
144
|
-
this._attributions[text]++;
|
|
144
|
+
this._attributions[text] = (this._attributions[text] || 0) + 1;
|
|
145
145
|
|
|
146
146
|
this._update();
|
|
147
147
|
|
|
@@ -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',
|
|
@@ -314,6 +317,10 @@ export class LayersControl extends Control {
|
|
|
314
317
|
return this;
|
|
315
318
|
}
|
|
316
319
|
|
|
320
|
+
_getTitle() {
|
|
321
|
+
return this.options.title ?? I18n.translate('Layers');
|
|
322
|
+
}
|
|
323
|
+
|
|
317
324
|
_initLayout() {
|
|
318
325
|
const className = 'maplair-control-layers',
|
|
319
326
|
container = this._container = DomUtil.create('div', className),
|
|
@@ -327,7 +334,7 @@ export class LayersControl extends Control {
|
|
|
327
334
|
DomEvent.disableScrollPropagation(container);
|
|
328
335
|
|
|
329
336
|
const section = this._section = DomUtil.create('fieldset', `${className}-list`);
|
|
330
|
-
section.setAttribute('aria-label',
|
|
337
|
+
section.setAttribute('aria-label', this._getTitle());
|
|
331
338
|
|
|
332
339
|
if (collapsed) {
|
|
333
340
|
this._map.on('click', this.collapse, this);
|
|
@@ -344,8 +351,8 @@ export class LayersControl extends Control {
|
|
|
344
351
|
if (!this.options.inline) {
|
|
345
352
|
const link = this._layersLink = DomUtil.create('button', `${className}-toggle`, container);
|
|
346
353
|
link.type = 'button';
|
|
347
|
-
link.title =
|
|
348
|
-
link.setAttribute('aria-label',
|
|
354
|
+
link.title = this._getTitle();
|
|
355
|
+
link.setAttribute('aria-label', link.title);
|
|
349
356
|
|
|
350
357
|
const {toggleContent} = this.options;
|
|
351
358
|
if (typeof toggleContent === 'string') {
|
|
@@ -376,7 +383,7 @@ export class LayersControl extends Control {
|
|
|
376
383
|
this._separator = DomUtil.create('div', `${className}-separator`, section);
|
|
377
384
|
this._overlaysList = DomUtil.create('div', `${className}-overlays`, section);
|
|
378
385
|
|
|
379
|
-
container.
|
|
386
|
+
container.append(section);
|
|
380
387
|
}
|
|
381
388
|
|
|
382
389
|
_addLayer(layer, name, overlay) {
|
|
@@ -472,13 +479,12 @@ export class LayersControl extends Control {
|
|
|
472
479
|
// https://github.com/Leaflet/Leaflet/issues/2771
|
|
473
480
|
const holder = document.createElement('span');
|
|
474
481
|
|
|
475
|
-
label.
|
|
476
|
-
holder.
|
|
477
|
-
holder.appendChild(name);
|
|
482
|
+
label.append(holder);
|
|
483
|
+
holder.append(input, name);
|
|
478
484
|
|
|
479
485
|
const list = obj.overlay ? this._overlaysList : this._baseLayersList;
|
|
480
486
|
const container = group ? this._getGroupContainer(list, group.group) : list;
|
|
481
|
-
container.
|
|
487
|
+
container.append(label);
|
|
482
488
|
|
|
483
489
|
this._checkDisabledLayers();
|
|
484
490
|
return label;
|
|
@@ -549,8 +555,6 @@ export class LayersControl extends Control {
|
|
|
549
555
|
break;
|
|
550
556
|
}
|
|
551
557
|
}
|
|
552
|
-
|
|
553
|
-
this._refocusOnMap(e);
|
|
554
558
|
}
|
|
555
559
|
|
|
556
560
|
_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,7 +130,7 @@ 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) {
|
|
@@ -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;
|
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
|
/**
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
const activePointers = new Map();
|
|
5
5
|
|
|
6
|
+
let lastPointerType;
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* Enables pointer detection and capture for the document.
|
|
8
10
|
* @group Pointer detection
|
|
@@ -34,6 +36,7 @@ function disablePointerDetection(el) {
|
|
|
34
36
|
function _onSet(e) {
|
|
35
37
|
if (e.isTrusted) { e.target.setPointerCapture(e.pointerId); }
|
|
36
38
|
activePointers.set(e.pointerId, e);
|
|
39
|
+
lastPointerType = e.pointerType;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
function _onUpdate(e) {
|
|
@@ -59,9 +62,52 @@ function getPointers() {
|
|
|
59
62
|
return [...activePointers.values()];
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
const dblclickProps = ['bubbles', 'cancelable', 'composed', 'view', 'screenX', 'screenY', 'clientX', 'clientY',
|
|
66
|
+
'ctrlKey', 'shiftKey', 'altKey', 'metaKey', 'button', 'buttons', 'relatedTarget'];
|
|
67
|
+
|
|
68
|
+
let lastClickTime = 0,
|
|
69
|
+
lastClick,
|
|
70
|
+
lastClickMap,
|
|
71
|
+
clickCount = 0;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Fires a `dblclick` on double tap where the browser doesn't (like iOS Safari),
|
|
75
|
+
* which is where it always reports `detail: 1` on clicks (see Leaflet#7012). The
|
|
76
|
+
* pointer type comes from `pointerdown`, because iOS Safari reports `mouse` on
|
|
77
|
+
* clicks from touch (WebKit bug 282988). Called by the map for clicks in it.
|
|
78
|
+
* @internal
|
|
79
|
+
* @param {MouseEvent} e
|
|
80
|
+
* @param {HTMLElement} mapContainer The container of the map, two taps make a double
|
|
81
|
+
* tap only in the same map.
|
|
82
|
+
* @returns {void}
|
|
83
|
+
*/
|
|
84
|
+
function simulateDblclick(e, mapContainer) {
|
|
85
|
+
// a click in a nested map (e.g. an overview map) counts for the innermost one only
|
|
86
|
+
if (e === lastClick) { return; }
|
|
87
|
+
lastClick = e;
|
|
88
|
+
const target = e.target;
|
|
89
|
+
|
|
90
|
+
// a click on a label is followed by a click on its input, so it would count as a double tap
|
|
91
|
+
if (e.detail !== 1 || lastPointerType === 'mouse' || target.closest('label')) {
|
|
92
|
+
clickCount = 0;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const now = Date.now();
|
|
96
|
+
clickCount = now - lastClickTime <= 200 && mapContainer === lastClickMap ? clickCount + 1 : 1;
|
|
97
|
+
lastClickTime = now;
|
|
98
|
+
lastClickMap = mapContainer;
|
|
99
|
+
|
|
100
|
+
if (clickCount === 2) {
|
|
101
|
+
const init = {detail: 2};
|
|
102
|
+
for (const prop of dblclickProps) { init[prop] = e[prop]; }
|
|
103
|
+
target.dispatchEvent(new MouseEvent('dblclick', init));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
62
107
|
export {
|
|
63
108
|
enablePointerDetection,
|
|
64
109
|
disablePointerDetection,
|
|
65
|
-
getPointers
|
|
110
|
+
getPointers,
|
|
111
|
+
simulateDblclick
|
|
66
112
|
};
|
|
67
113
|
|
package/src/dom/DomEvent.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {Point} from '../geometry/Point.js';
|
|
2
2
|
import * as Util from '../core/Util.js';
|
|
3
|
-
import {addDoubleTapListener, removeDoubleTapListener} from './DomEvent.DoubleTap.js';
|
|
4
3
|
import {getScale} from './DomUtil.js';
|
|
5
4
|
|
|
6
5
|
import * as PointerEvents from './DomEvent.PointerEvents.js';
|
|
@@ -93,15 +92,11 @@ function addOne(obj, type, fn, context) {
|
|
|
93
92
|
|
|
94
93
|
if (obj[eventsKey] && obj[eventsKey][id]) { return; }
|
|
95
94
|
|
|
96
|
-
|
|
95
|
+
const handler = function (e) {
|
|
97
96
|
return fn.call(context || obj, e);
|
|
98
97
|
};
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
handler = addDoubleTapListener(obj, handler);
|
|
102
|
-
} else {
|
|
103
|
-
obj.addEventListener(type, handler, type === 'wheel' ? {passive: false} : false);
|
|
104
|
-
}
|
|
99
|
+
obj.addEventListener(type, handler, type === 'wheel' ? {passive: false} : false);
|
|
105
100
|
|
|
106
101
|
obj[eventsKey] ??= {};
|
|
107
102
|
obj[eventsKey][id] = handler;
|
|
@@ -113,11 +108,7 @@ function removeOne(obj, type, fn, context, id) {
|
|
|
113
108
|
|
|
114
109
|
if (!handler) { return; }
|
|
115
110
|
|
|
116
|
-
|
|
117
|
-
removeDoubleTapListener(obj, handler);
|
|
118
|
-
} else {
|
|
119
|
-
obj.removeEventListener(type, handler, false);
|
|
120
|
-
}
|
|
111
|
+
obj.removeEventListener(type, handler, false);
|
|
121
112
|
|
|
122
113
|
obj[eventsKey][id] = null;
|
|
123
114
|
}
|
|
@@ -230,11 +221,8 @@ export function getWheelPxFactor() {
|
|
|
230
221
|
* @returns {number}
|
|
231
222
|
*/
|
|
232
223
|
export function getWheelDelta(e) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
(e.deltaY && e.deltaMode === 2) ? -e.deltaY * 60 : // Pages
|
|
236
|
-
(e.deltaX || e.deltaZ) ? 0 : // Skip horizontal/depth wheel events
|
|
237
|
-
0;
|
|
224
|
+
// scaled per delta mode: pixels, lines, pages; horizontal and depth scrolling give 0
|
|
225
|
+
return -e.deltaY * (e.deltaMode ? e.deltaMode === 1 ? 20 : 60 : 1 / getWheelPxFactor()) || 0;
|
|
238
226
|
}
|
|
239
227
|
|
|
240
228
|
/**
|
package/src/dom/DomUtil.js
CHANGED
|
@@ -31,7 +31,7 @@ export function create(tagName, className, container) {
|
|
|
31
31
|
const el = document.createElement(tagName);
|
|
32
32
|
el.className = className ?? '';
|
|
33
33
|
|
|
34
|
-
container?.
|
|
34
|
+
container?.append(el);
|
|
35
35
|
return el;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -48,9 +48,9 @@ export function toFront(el) {
|
|
|
48
48
|
// re-inserting a hovered node (e.g. bringToFront in a pointerover handler) makes Chromium 144+ fire a repeated
|
|
49
49
|
// pointerover and lose the next pointerout (#10129), so move the nodes after it instead
|
|
50
50
|
if (el.matches(':hover')) {
|
|
51
|
-
while (el.nextSibling) {
|
|
51
|
+
while (el.nextSibling) { el.before(el.nextSibling); }
|
|
52
52
|
} else {
|
|
53
|
-
parent.
|
|
53
|
+
parent.append(el);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -64,9 +64,9 @@ export function toBack(el) {
|
|
|
64
64
|
if (!parent || parent.firstChild === el) { return; }
|
|
65
65
|
|
|
66
66
|
if (el.matches(':hover')) { // see toFront
|
|
67
|
-
while (el.previousSibling) {
|
|
67
|
+
while (el.previousSibling) { el.after(el.previousSibling); }
|
|
68
68
|
} else {
|
|
69
|
-
parent.
|
|
69
|
+
parent.prepend(el);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
package/src/dom/Draggable.js
CHANGED
|
@@ -99,7 +99,6 @@ export class Draggable extends Evented {
|
|
|
99
99
|
_onDown(e) {
|
|
100
100
|
this._moved = false;
|
|
101
101
|
|
|
102
|
-
if (this._element.classList.contains('maplair-zoom-anim')) { return; }
|
|
103
102
|
|
|
104
103
|
const pointers = PointerEvents.getPointers().length;
|
|
105
104
|
if (pointers > 1) {
|
|
@@ -110,7 +109,9 @@ export class Draggable extends Evented {
|
|
|
110
109
|
return;
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
|
|
112
|
+
// Shift-drag draws a box to zoom to, unless box zoom is disabled
|
|
113
|
+
const boxZoom = e.shiftKey && this._element.closest('.maplair-container')?.classList.contains('maplair-box-zoom');
|
|
114
|
+
if (Draggable._dragging || boxZoom || (e.button !== 0 && e.pointerType !== 'touch')) { return; }
|
|
114
115
|
Draggable._dragging = this; // Prevent dragging multiple objects at once.
|
|
115
116
|
|
|
116
117
|
DomUtil.disableImageDrag();
|
|
@@ -207,10 +208,8 @@ export class Draggable extends Evented {
|
|
|
207
208
|
this._draggingContainer?.classList.remove('maplair-dragging');
|
|
208
209
|
this._draggingContainer = null;
|
|
209
210
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this._lastTarget = null;
|
|
213
|
-
}
|
|
211
|
+
this._lastTarget?.classList.remove('maplair-drag-target');
|
|
212
|
+
this._lastTarget = null;
|
|
214
213
|
|
|
215
214
|
DomEvent.off(this._dragStartTarget, 'pointermove', this._onMove, this);
|
|
216
215
|
DomEvent.off(this._dragStartTarget, 'pointerup pointercancel lostpointercapture', this._onUp, this);
|