maplair 4.1.0 → 4.3.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.
Files changed (213) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/dist/esm/Maplair.js +5 -4
  3. package/dist/esm/Maplair.js.map +1 -1
  4. package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
  5. package/dist/esm/control/AttributionControl.js +1 -2
  6. package/dist/esm/control/ButtonControl.js +1 -2
  7. package/dist/esm/control/ContextMenu.js +1 -2
  8. package/dist/esm/control/Control.js +1 -2
  9. package/dist/esm/control/FullscreenControl.js +1 -2
  10. package/dist/esm/control/LayersControl.js +27 -31
  11. package/dist/esm/control/LayersControl.js.map +1 -1
  12. package/dist/esm/control/LegendControl.js +1 -2
  13. package/dist/esm/control/MiniMapControl.js +1 -2
  14. package/dist/esm/control/RotateControl.js +1 -2
  15. package/dist/esm/control/ScaleControl.js +1 -2
  16. package/dist/esm/control/SearchControl.js +1 -2
  17. package/dist/esm/control/SideBySideControl.js +1 -2
  18. package/dist/esm/control/TextControl.js +1 -2
  19. package/dist/esm/control/TimeControl.js +1 -2
  20. package/dist/esm/control/ZoomControl.js +18 -29
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Class.js +2 -9
  23. package/dist/esm/core/Class.js.map +1 -1
  24. package/dist/esm/core/Events.js +2 -2
  25. package/dist/esm/core/Events.js.map +1 -1
  26. package/dist/esm/core/Handler.js +10 -3
  27. package/dist/esm/core/Handler.js.map +1 -1
  28. package/dist/esm/core/I18n.js +1 -2
  29. package/dist/esm/core/Util.js +2 -3
  30. package/dist/esm/core/Util.js.map +1 -1
  31. package/dist/esm/dom/DomEvent.DoubleTap.js +1 -2
  32. package/dist/esm/dom/DomEvent.PointerEvents.js +1 -2
  33. package/dist/esm/dom/DomEvent.js +10 -18
  34. package/dist/esm/dom/DomEvent.js.map +1 -1
  35. package/dist/esm/dom/DomUtil.js +1 -2
  36. package/dist/esm/dom/Draggable.js +4 -3
  37. package/dist/esm/dom/Draggable.js.map +1 -1
  38. package/dist/esm/dom/PosAnimation.js +1 -2
  39. package/dist/esm/geo/LatLng.js +1 -2
  40. package/dist/esm/geo/LatLngBounds.js +9 -15
  41. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  42. package/dist/esm/geo/crs/CRS.js +1 -2
  43. package/dist/esm/geo/crs/EPSG3395.js +4 -5
  44. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  45. package/dist/esm/geo/crs/EPSG3857.js +4 -5
  46. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  47. package/dist/esm/geo/crs/EPSG4326.js +3 -4
  48. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  49. package/dist/esm/geo/crs/EarthCRS.js +1 -2
  50. package/dist/esm/geo/crs/SimpleCRS.js +3 -4
  51. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  52. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +4 -5
  53. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  54. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +3 -4
  55. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  56. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +4 -5
  57. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  58. package/dist/esm/geometry/Bounds.js +10 -14
  59. package/dist/esm/geometry/Bounds.js.map +1 -1
  60. package/dist/esm/geometry/LineUtil.js +2 -3
  61. package/dist/esm/geometry/LineUtil.js.map +1 -1
  62. package/dist/esm/geometry/Point.js +1 -2
  63. package/dist/esm/geometry/PolyUtil.js +17 -25
  64. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  65. package/dist/esm/geometry/Transformation.js +1 -2
  66. package/dist/esm/layer/BlanketOverlay.js +1 -2
  67. package/dist/esm/layer/Classification.js +1 -2
  68. package/dist/esm/layer/DivOverlay.js +2 -3
  69. package/dist/esm/layer/DivOverlay.js.map +1 -1
  70. package/dist/esm/layer/FeatureGroup.js +5 -4
  71. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  72. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  73. package/dist/esm/layer/GeoJSON.js +8 -10
  74. package/dist/esm/layer/GeoJSON.js.map +1 -1
  75. package/dist/esm/layer/GeoJSONUtil.js +1 -2
  76. package/dist/esm/layer/HeatLayer.js +2 -3
  77. package/dist/esm/layer/HeatLayer.js.map +1 -1
  78. package/dist/esm/layer/ImageOverlay.js +2 -3
  79. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  80. package/dist/esm/layer/Layer.js +1 -2
  81. package/dist/esm/layer/LayerGroup.js +2 -3
  82. package/dist/esm/layer/LayerGroup.js.map +1 -1
  83. package/dist/esm/layer/Popup.js +9 -16
  84. package/dist/esm/layer/Popup.js.map +1 -1
  85. package/dist/esm/layer/SVGOverlay.js +1 -2
  86. package/dist/esm/layer/Tooltip.js +16 -17
  87. package/dist/esm/layer/Tooltip.js.map +1 -1
  88. package/dist/esm/layer/VideoOverlay.js +1 -2
  89. package/dist/esm/layer/marker/DefaultIcon.js +29 -7
  90. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  91. package/dist/esm/layer/marker/DivIcon.js +1 -2
  92. package/dist/esm/layer/marker/Icon.js +2 -2
  93. package/dist/esm/layer/marker/Icon.js.map +1 -1
  94. package/dist/esm/layer/marker/Marker.Drag.js +43 -4
  95. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  96. package/dist/esm/layer/marker/Marker.Move.js +4 -6
  97. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  98. package/dist/esm/layer/marker/Marker.js +54 -14
  99. package/dist/esm/layer/marker/Marker.js.map +1 -1
  100. package/dist/esm/layer/marker/MarkerClusterGroup.js +1 -2
  101. package/dist/esm/layer/marker/SvgIcon.js +1 -2
  102. package/dist/esm/layer/tile/GridLayer.js +4 -4
  103. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  104. package/dist/esm/layer/tile/TileLayer.js +8 -8
  105. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  106. package/dist/esm/layer/tile/WMSTileLayer.js +5 -4
  107. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  108. package/dist/esm/layer/vector/Canvas.js +7 -14
  109. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  110. package/dist/esm/layer/vector/Circle.js +5 -3
  111. package/dist/esm/layer/vector/Circle.js.map +1 -1
  112. package/dist/esm/layer/vector/CircleMarker.js +2 -3
  113. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  114. package/dist/esm/layer/vector/Path.DashAnimation.js +1 -2
  115. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  116. package/dist/esm/layer/vector/Path.js +1 -2
  117. package/dist/esm/layer/vector/Polygon.js +2 -3
  118. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  119. package/dist/esm/layer/vector/Polyline.Decorations.js +1 -2
  120. package/dist/esm/layer/vector/Polyline.js +2 -3
  121. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  122. package/dist/esm/layer/vector/Rectangle.js +1 -2
  123. package/dist/esm/layer/vector/Renderer.getRenderer.js +4 -5
  124. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  125. package/dist/esm/layer/vector/Renderer.js +1 -2
  126. package/dist/esm/layer/vector/SVG.js +7 -4
  127. package/dist/esm/layer/vector/SVG.js.map +1 -1
  128. package/dist/esm/map/Hash.js +1 -2
  129. package/dist/esm/map/Map.Rotation.js +31 -16
  130. package/dist/esm/map/Map.Rotation.js.map +1 -1
  131. package/dist/esm/map/Map.js +10 -17
  132. package/dist/esm/map/Map.js.map +1 -1
  133. package/dist/esm/map/MapSync.js +1 -2
  134. package/dist/esm/map/handler/BoxZoomHandler.js +20 -40
  135. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  136. package/dist/esm/map/handler/DisplaceHandler.js +1 -2
  137. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  138. package/dist/esm/map/handler/DragHandler.js +1 -2
  139. package/dist/esm/map/handler/KeyboardHandler.js +23 -43
  140. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  141. package/dist/esm/map/handler/PinchZoomHandler.js +1 -2
  142. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -2
  143. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  144. package/dist/esm/map/handler/TapHoldHandler.js +1 -2
  145. package/dist/esm/package.js +2 -3
  146. package/dist/maplair-global-src.js +489 -613
  147. package/dist/maplair-global-src.js.map +1 -1
  148. package/dist/maplair-global.js +2 -2
  149. package/dist/maplair-global.js.map +1 -1
  150. package/dist/maplair-src.js +485 -609
  151. package/dist/maplair-src.js.map +1 -1
  152. package/dist/maplair.css +1 -1263
  153. package/dist/maplair.js +2 -2
  154. package/dist/maplair.js.map +1 -1
  155. package/package.json +4 -8
  156. package/src/Maplair.all.js +0 -1
  157. package/src/control/LayersControl.js +39 -52
  158. package/src/control/ZoomControl.js +17 -31
  159. package/src/core/Class.js +5 -14
  160. package/src/core/Events.js +2 -0
  161. package/src/core/Handler.js +11 -1
  162. package/src/core/Util.js +1 -1
  163. package/src/dom/DomEvent.js +9 -19
  164. package/src/dom/Draggable.js +5 -1
  165. package/src/geo/LatLngBounds.js +8 -15
  166. package/src/geo/crs/EPSG3395.js +3 -3
  167. package/src/geo/crs/EPSG3857.js +3 -3
  168. package/src/geo/crs/EPSG4326.js +2 -2
  169. package/src/geo/crs/SimpleCRS.js +2 -2
  170. package/src/geo/index.js +1 -2
  171. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +1 -1
  172. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +1 -1
  173. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +1 -1
  174. package/src/geo/projection/index.js +5 -5
  175. package/src/geometry/Bounds.js +12 -17
  176. package/src/geometry/LineUtil.js +1 -1
  177. package/src/geometry/PolyUtil.js +23 -31
  178. package/src/layer/DivOverlay.js +1 -1
  179. package/src/layer/FeatureGroup.js +8 -2
  180. package/src/layer/GeoJSON.js +10 -13
  181. package/src/layer/HeatLayer.js +1 -1
  182. package/src/layer/ImageOverlay.js +2 -2
  183. package/src/layer/LayerGroup.js +1 -1
  184. package/src/layer/Popup.js +9 -19
  185. package/src/layer/Tooltip.js +19 -17
  186. package/src/layer/marker/DefaultIcon.js +33 -5
  187. package/src/layer/marker/Icon.js +2 -0
  188. package/src/layer/marker/Marker.Drag.js +53 -5
  189. package/src/layer/marker/Marker.Move.js +3 -4
  190. package/src/layer/marker/Marker.js +64 -13
  191. package/src/layer/tile/GridLayer.js +5 -2
  192. package/src/layer/tile/TileLayer.js +9 -6
  193. package/src/layer/tile/WMSTileLayer.js +5 -2
  194. package/src/layer/vector/Canvas.js +10 -14
  195. package/src/layer/vector/Circle.js +7 -1
  196. package/src/layer/vector/CircleMarker.js +2 -1
  197. package/src/layer/vector/Polygon.js +1 -1
  198. package/src/layer/vector/Polyline.js +1 -1
  199. package/src/layer/vector/Renderer.getRenderer.js +4 -3
  200. package/src/layer/vector/SVG.js +12 -2
  201. package/src/map/Map.Rotation.js +28 -4
  202. package/src/map/Map.js +17 -21
  203. package/src/map/handler/BoxZoomHandler.js +21 -42
  204. package/src/map/handler/KeyboardHandler.js +34 -53
  205. package/src/maplair.css +5 -0
  206. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  207. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  208. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  209. package/dist/esm/geo/projection/index.js +0 -14
  210. package/dist/esm/geo/projection/index.js.map +0 -1
  211. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  212. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  213. package/src/layer/marker/Marker.Rotation.js +0 -103
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maplair",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "homepage": "https://maplair.org/",
5
5
  "description": "JavaScript library for mobile-friendly interactive maps",
6
6
  "author": "Simon Legner",
@@ -21,12 +21,13 @@
21
21
  "@vitest/coverage-v8": "5.0.5",
22
22
  "@vitest/ui": "5.0.5",
23
23
  "eslint-plugin-baseline-js": "^0.7.5",
24
+ "lightningcss": "^1.33.0",
24
25
  "liquidjs": "^10.30.0",
25
26
  "markdown-it": "^15.0.3",
26
27
  "playwright": "^1.64.1",
27
28
  "typescript": "^6.0.3",
28
29
  "ui-event-simulator": "^2.0.0",
29
- "vite-plus": "1.3.0",
30
+ "vite-plus": "1.4.0",
30
31
  "vitest": "5.0.5",
31
32
  "yaml": "^2.9.1"
32
33
  },
@@ -47,10 +48,6 @@
47
48
  "types": "./dist/types/map/Map.Rotation.d.ts",
48
49
  "default": "./dist/esm/map/Map.Rotation.js"
49
50
  },
50
- "./marker-rotation": {
51
- "types": "./dist/types/layer/marker/Marker.Rotation.d.ts",
52
- "default": "./dist/esm/layer/marker/Marker.Rotation.js"
53
- },
54
51
  "./marker-movement": {
55
52
  "types": "./dist/types/layer/marker/Marker.Move.d.ts",
56
53
  "default": "./dist/esm/layer/marker/Marker.Move.js"
@@ -72,6 +69,7 @@
72
69
  "default": "./dist/esm/layer/vector/Path.ZoomStyles.js"
73
70
  },
74
71
  "./src/": "./src/",
72
+ "./dist/maplair.css": "./dist/maplair.css",
75
73
  "./styles.css": "./dist/maplair.css",
76
74
  "./i18n/*.json": "./i18n/*.json"
77
75
  },
@@ -81,7 +79,6 @@
81
79
  "./dist/maplair*.js",
82
80
  "./src/map/Map.js",
83
81
  "./src/map/Map.Rotation.js",
84
- "./src/layer/marker/Marker.Rotation.js",
85
82
  "./src/layer/marker/Marker.Move.js",
86
83
  "./src/layer/vector/Path.DashAnimation.js",
87
84
  "./src/layer/vector/Polyline.Decorations.js",
@@ -89,7 +86,6 @@
89
86
  "./src/layer/vector/Path.ZoomStyles.js",
90
87
  "./dist/esm/map/Map.js",
91
88
  "./dist/esm/map/Map.Rotation.js",
92
- "./dist/esm/layer/marker/Marker.Rotation.js",
93
89
  "./dist/esm/layer/marker/Marker.Move.js",
94
90
  "./dist/esm/layer/vector/Path.DashAnimation.js",
95
91
  "./dist/esm/layer/vector/Polyline.Decorations.js",
@@ -2,7 +2,6 @@
2
2
  // ES modules (see `src/Maplair.js`) only contain when imported separately.
3
3
  export * from './Maplair.js';
4
4
  export {RotateControl} from './map/Map.Rotation.js';
5
- import './layer/marker/Marker.Rotation.js';
6
5
  import './layer/marker/Marker.Move.js';
7
6
  import './layer/vector/Path.DashAnimation.js';
8
7
  import './layer/vector/Polyline.Decorations.js';
@@ -213,6 +213,7 @@ export class LayersControl extends Control {
213
213
  }
214
214
 
215
215
  this._map.off('resize', this._expandIfNotCollapsed, this);
216
+ this._map.off('click', this.collapse, this);
216
217
  }
217
218
 
218
219
  /**
@@ -245,10 +246,7 @@ export class LayersControl extends Control {
245
246
  removeLayer(layer) {
246
247
  layer.off('add remove', this._onLayerChange, this);
247
248
 
248
- const obj = this._getLayer(Util.stamp(layer));
249
- if (obj) {
250
- this._layers.splice(this._layers.indexOf(obj), 1);
251
- }
249
+ this._layers = this._layers.filter(o => o.layer !== layer);
252
250
  return (this._map) ? this._update() : this;
253
251
  }
254
252
 
@@ -270,7 +268,7 @@ export class LayersControl extends Control {
270
268
  * @returns {this}
271
269
  */
272
270
  selectLayer(layer) {
273
- const input = this._layerControlInputs.find(input => input.layerId === Util.stamp(layer));
271
+ const input = this._layerControlInputs.find(input => input._layer === layer);
274
272
  if (input && !input.checked) {
275
273
  input.checked = true;
276
274
  this._onInputClick();
@@ -300,27 +298,17 @@ export class LayersControl extends Control {
300
298
 
301
299
  /**
302
300
  * Collapse the control container if expanded.
303
- * @param {Event} [ev] The event causing the collapse, if any (collapsing is skipped
304
- * for `pointerleave` and `pointerout` of touch).
305
301
  * @returns {this}
306
302
  */
307
- collapse(ev) {
303
+ collapse() {
308
304
  if (this.options.inline) {
309
305
  return this;
310
306
  }
311
- // On touch devices `pointerleave` & `pointerout` is fired while clicking on a checkbox.
312
- // The control was collapsed instead of adding the layer to the map.
313
- // So we allow collapse only if it is not touch.
314
- if (!ev || !((ev.type === 'pointerleave' || ev.type === 'pointerout') && ev.pointerType === 'touch')) {
315
- if (this.options.collapseDelay > 0) {
316
- // Collapse delayed
317
- this._collapseDelayTimeout = setTimeout(() => {
318
- this._container.classList.remove('maplair-control-layers-expanded');
319
- }, this.options.collapseDelay);
320
- return this;
321
- }
322
-
323
- // Collapse immediately
307
+ if (this.options.collapseDelay > 0) {
308
+ this._collapseDelayTimeout = setTimeout(() => {
309
+ this._container.classList.remove('maplair-control-layers-expanded');
310
+ }, this.options.collapseDelay);
311
+ } else {
324
312
  this._container.classList.remove('maplair-control-layers-expanded');
325
313
  }
326
314
  return this;
@@ -346,7 +334,10 @@ export class LayersControl extends Control {
346
334
 
347
335
  DomEvent.on(container, {
348
336
  pointerenter: this._expandSafely,
349
- pointerleave: this.collapse
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
+ }
350
341
  }, this);
351
342
  }
352
343
 
@@ -388,14 +379,6 @@ export class LayersControl extends Control {
388
379
  container.appendChild(section);
389
380
  }
390
381
 
391
- _getLayer(id) {
392
- for (const layer of this._layers) {
393
- if (layer && Util.stamp(layer.layer) === id) {
394
- return layer;
395
- }
396
- }
397
- }
398
-
399
382
  _addLayer(layer, name, overlay) {
400
383
  if (this._map) {
401
384
  layer.on('add remove', this._onLayerChange, this);
@@ -452,7 +435,7 @@ export class LayersControl extends Control {
452
435
  this._update();
453
436
  }
454
437
 
455
- const obj = this._getLayer(Util.stamp(e.target));
438
+ const obj = this._layers.find(o => o.layer === e.target);
456
439
 
457
440
  const type = obj.overlay ?
458
441
  (e.type === 'add' ? 'overlayadd' : 'overlayremove') :
@@ -476,7 +459,7 @@ export class LayersControl extends Control {
476
459
  }
477
460
 
478
461
  this._layerControlInputs.push(input);
479
- input.layerId = Util.stamp(obj.layer);
462
+ input._layer = obj.layer;
480
463
 
481
464
  DomEvent.on(input, 'click', this._onInputClick, this);
482
465
 
@@ -531,38 +514,42 @@ export class LayersControl extends Control {
531
514
  return;
532
515
  }
533
516
 
534
- const inputs = this._layerControlInputs,
535
- addedLayers = [],
536
- removedLayers = [];
537
-
538
- this._handlingClick = true;
539
- this._clickEvent = e;
540
-
541
- for (const input of inputs) {
542
- const layer = this._getLayer(input.layerId).layer;
517
+ // a layer can be listed under several inputs, so it should be on the map if any of them is checked
518
+ const checked = new Map();
519
+ for (const input of this._layerControlInputs) {
520
+ const layer = input._layer;
521
+ checked.set(layer, checked.get(layer) || input.checked);
522
+ }
543
523
 
544
- if (input.checked) {
545
- addedLayers.push(layer);
546
- } else if (!input.checked) {
547
- removedLayers.push(layer);
524
+ // diff against the map upfront, so layers that event handlers add or remove below keep their state
525
+ const addedLayers = [], removedLayers = [];
526
+ for (const [layer, on] of checked) {
527
+ if (on !== this._map.hasLayer(layer)) {
528
+ (on ? addedLayers : removedLayers).push(layer);
548
529
  }
549
530
  }
550
531
 
532
+ this._handlingClick = true;
533
+ this._clickEvent = e;
534
+
551
535
  // Bugfix issue 2318: Should remove all old layers before readding new ones
552
536
  for (const layer of removedLayers) {
553
- if (this._map.hasLayer(layer)) {
554
- this._map.removeLayer(layer);
555
- }
537
+ this._map.removeLayer(layer);
556
538
  }
557
539
  for (const layer of addedLayers) {
558
- if (!this._map.hasLayer(layer)) {
559
- this._map.addLayer(layer);
560
- }
540
+ this._map.addLayer(layer);
561
541
  }
562
542
 
563
543
  this._handlingClick = false;
564
544
  this._clickEvent = undefined;
565
545
 
546
+ for (const [layer, on] of checked) {
547
+ if (on !== this._map.hasLayer(layer)) {
548
+ this._update();
549
+ break;
550
+ }
551
+ }
552
+
566
553
  this._refocusOnMap(e);
567
554
  }
568
555
 
@@ -571,7 +558,7 @@ export class LayersControl extends Control {
571
558
  zoom = this._map.getZoom();
572
559
 
573
560
  for (const input of inputs) {
574
- const layer = this._getLayer(input.layerId).layer;
561
+ const layer = input._layer;
575
562
  input.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) ||
576
563
  (layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom);
577
564
 
@@ -67,9 +67,9 @@ export class ZoomControl extends Control {
67
67
  options = this.options;
68
68
 
69
69
  this._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),
70
- `${zoomName}-in`, container, this._zoomIn);
70
+ `${zoomName}-in`, container, e => this._zoom(e, 1));
71
71
  this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),
72
- `${zoomName}-out`, container, this._zoomOut);
72
+ `${zoomName}-out`, container, e => this._zoom(e, -1));
73
73
 
74
74
  this._updateDisabled();
75
75
  map.on('zoomend zoomlevelschange', this._updateDisabled, this);
@@ -105,17 +105,11 @@ export class ZoomControl extends Control {
105
105
  return this;
106
106
  }
107
107
 
108
- _zoomIn(e) {
109
- if (!this._disabled && this._map._zoom < this._map.getMaxZoom()) {
110
- this._map._setUserEvent(e);
111
- this._map.zoomIn(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));
112
- }
113
- }
114
-
115
- _zoomOut(e) {
116
- if (!this._disabled && this._map._zoom > this._map.getMinZoom()) {
117
- this._map._setUserEvent(e);
118
- 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));
119
113
  }
120
114
  }
121
115
 
@@ -127,29 +121,21 @@ export class ZoomControl extends Control {
127
121
  link.setAttribute('aria-label', title);
128
122
 
129
123
  DomEvent.disableClickPropagation(link);
130
- DomEvent.on(link, 'click', DomEvent.stop);
131
- DomEvent.on(link, 'click', fn, this);
132
- DomEvent.on(link, 'click', this._refocusOnMap, this);
124
+ DomEvent.on(link, 'click', (e) => {
125
+ DomEvent.stop(e);
126
+ fn.call(this, e);
127
+ this._refocusOnMap(e);
128
+ });
133
129
 
134
130
  return link;
135
131
  }
136
132
 
137
133
  _updateDisabled() {
138
- const map = this._map,
139
- className = 'maplair-disabled';
140
-
141
- this._zoomInButton.classList.remove(className);
142
- this._zoomOutButton.classList.remove(className);
143
- this._zoomInButton.setAttribute('aria-disabled', 'false');
144
- this._zoomOutButton.setAttribute('aria-disabled', 'false');
145
-
146
- if (this._disabled || map._zoom === map.getMinZoom()) {
147
- this._zoomOutButton.classList.add(className);
148
- this._zoomOutButton.setAttribute('aria-disabled', 'true');
149
- }
150
- if (this._disabled || map._zoom === map.getMaxZoom()) {
151
- this._zoomInButton.classList.add(className);
152
- 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}`);
153
139
  }
154
140
  }
155
141
 
package/src/core/Class.js CHANGED
@@ -159,26 +159,17 @@ export class Class {
159
159
  * @returns {T}
160
160
  */
161
161
  static include(props) {
162
- for (const k of getAllMethodNames(props)) {
163
- if (k !== 'constructor' && k !== 'options') {
164
- this.prototype[k] = props[k];
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
+ }
165
167
  }
166
168
  }
167
169
  if (props.options) {
168
170
  this.mergeOptions(props.options);
169
171
  }
170
172
  return this;
171
-
172
- function *getAllMethodNames(obj) {
173
- do {
174
- if (obj === Object || obj === Object.prototype) {
175
- break;
176
- }
177
- for (const k of Object.getOwnPropertyNames(obj)) {
178
- yield k;
179
- }
180
- } while ((obj = Object.getPrototypeOf(obj)) !== null);
181
- }
182
173
  }
183
174
 
184
175
  /**
@@ -536,7 +536,9 @@ export class Evented extends Class {
536
536
 
537
537
  _propagateEvent(e) {
538
538
  for (const p of Object.values(this._eventParents ?? {})) {
539
+ // `layer` is the Leaflet 1 name of `propagatedFrom`, left out of the types to steer new code to the new one
539
540
  p.fire(e.type, {
541
+ layer: e.target,
540
542
  propagatedFrom: e.target,
541
543
  ...e
542
544
  }, true);
@@ -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` must implement the two following extension methods:
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
@@ -55,6 +55,16 @@ export class Handler extends Class {
55
55
  return !!this._enabled;
56
56
  }
57
57
 
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
+
58
68
  /**
59
69
  * Adds a new handler of this class to the given map with the given name, which is
60
70
  * then available as the property of the map with this name.
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 always smaller than
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
@@ -23,7 +23,7 @@ export {PointerEvents};
23
23
  * @param {string|Record<string, (ev: any) => void>} types
24
24
  * @param {((ev: any) => void)|object} [fn]
25
25
  * @param {object} [context]
26
- * @returns {typeof import('./DomEvent.js')}
26
+ * @returns {void}
27
27
  */
28
28
  export function on(obj, types, fn, context) {
29
29
 
@@ -36,8 +36,6 @@ export function on(obj, types, fn, context) {
36
36
  addOne(obj, type, fn, context);
37
37
  }
38
38
  }
39
-
40
- return this;
41
39
  }
42
40
 
43
41
  const eventsKey = '_maplair_events';
@@ -53,7 +51,7 @@ const eventsKey = '_maplair_events';
53
51
  * @param {string|Record<string, (ev: any) => void>} [types]
54
52
  * @param {((ev: any) => void)|object} [fn]
55
53
  * @param {object} [context]
56
- * @returns {typeof import('./DomEvent.js')}
54
+ * @returns {void}
57
55
  */
58
56
  export function off(obj, types, fn, context) {
59
57
 
@@ -77,8 +75,6 @@ export function off(obj, types, fn, context) {
77
75
  }
78
76
  }
79
77
  }
80
-
81
- return this;
82
78
  }
83
79
 
84
80
  const DIGIT_RE = /\d/;
@@ -95,7 +91,7 @@ function batchRemove(obj, filterFn) {
95
91
  function addOne(obj, type, fn, context) {
96
92
  const id = type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');
97
93
 
98
- if (obj[eventsKey] && obj[eventsKey][id]) { return this; }
94
+ if (obj[eventsKey] && obj[eventsKey][id]) { return; }
99
95
 
100
96
  let handler = function (e) {
101
97
  return fn.call(context || obj, e);
@@ -115,7 +111,7 @@ function removeOne(obj, type, fn, context, id) {
115
111
  id ??= type + Util.stamp(fn) + (context ? `_${Util.stamp(context)}` : '');
116
112
  const handler = obj[eventsKey] && obj[eventsKey][id];
117
113
 
118
- if (!handler) { return this; }
114
+ if (!handler) { return; }
119
115
 
120
116
  if (type === 'dblclick') {
121
117
  removeDoubleTapListener(obj, handler);
@@ -134,7 +130,7 @@ function removeOne(obj, type, fn, context, id) {
134
130
  * ```
135
131
  * Also accepts a Maplair event with an `originalEvent`.
136
132
  * @param {Event|{originalEvent: Event}} e
137
- * @returns {typeof import('./DomEvent.js')}
133
+ * @returns {void}
138
134
  */
139
135
  export function stopPropagation(e) {
140
136
 
@@ -147,18 +143,15 @@ export function stopPropagation(e) {
147
143
  // custom Maplair event
148
144
  console.debug('Unsupported event', e);
149
145
  }
150
-
151
- return this;
152
146
  }
153
147
 
154
148
  /**
155
149
  * Adds `stopPropagation` to the element's `'wheel'` events (plus browser variants).
156
150
  * @param {HTMLElement} el
157
- * @returns {typeof import('./DomEvent.js')}
151
+ * @returns {void}
158
152
  */
159
153
  export function disableScrollPropagation(el) {
160
154
  addOne(el, 'wheel', stopPropagation);
161
- return this;
162
155
  }
163
156
 
164
157
  /**
@@ -167,12 +160,11 @@ export function disableScrollPropagation(el) {
167
160
  * For `'click'` events, prevents the map from handling the click
168
161
  * while still allowing the native DOM click event to propagate normally.
169
162
  * @param {HTMLElement} el
170
- * @returns {typeof import('./DomEvent.js')}
163
+ * @returns {void}
171
164
  */
172
165
  export function disableClickPropagation(el) {
173
166
  on(el, 'pointerdown dblclick contextmenu', stopPropagation);
174
167
  el['_maplair_disable_click'] = true;
175
- return this;
176
168
  }
177
169
 
178
170
  /**
@@ -181,22 +173,20 @@ export function disableClickPropagation(el) {
181
173
  * with page reload when a `<form>` is submitted).
182
174
  * Use it inside listener functions.
183
175
  * @param {Event} e
184
- * @returns {typeof import('./DomEvent.js')}
176
+ * @returns {void}
185
177
  */
186
178
  export function preventDefault(e) {
187
179
  e.preventDefault?.();
188
- return this;
189
180
  }
190
181
 
191
182
  /**
192
183
  * Does `stopPropagation` and `preventDefault` at the same time.
193
184
  * @param {Event} e
194
- * @returns {typeof import('./DomEvent.js')}
185
+ * @returns {void}
195
186
  */
196
187
  export function stop(e) {
197
188
  preventDefault(e);
198
189
  stopPropagation(e);
199
- return this;
200
190
  }
201
191
 
202
192
  /**
@@ -101,7 +101,8 @@ export class Draggable extends Evented {
101
101
 
102
102
  if (this._element.classList.contains('maplair-zoom-anim')) { return; }
103
103
 
104
- if (PointerEvents.getPointers().length !== 1) {
104
+ const pointers = PointerEvents.getPointers().length;
105
+ if (pointers > 1) {
105
106
  // Finish dragging to avoid conflict with touchZoom
106
107
  if (Draggable._dragging === this) {
107
108
  this.finishDrag();
@@ -116,6 +117,9 @@ export class Draggable extends Evented {
116
117
 
117
118
  if (this._moving) { return; }
118
119
 
120
+ // outside a map, nothing tracks pointers or captures them, so capture this one to keep its moves coming
121
+ if (!pointers && e.isTrusted) { e.target.setPointerCapture(e.pointerId); }
122
+
119
123
  this.fire('down');
120
124
 
121
125
  const sizedParent = DomUtil.getSizedParentNode(this._element);
@@ -92,26 +92,19 @@ export class LatLngBounds {
92
92
  let sw2, ne2;
93
93
 
94
94
  if (obj instanceof LatLng) {
95
- sw2 = obj;
96
- ne2 = obj;
97
-
95
+ sw2 = ne2 = obj;
98
96
  } else if (obj instanceof LatLngBounds) {
99
- sw2 = obj._southWest;
100
- ne2 = obj._northEast;
101
-
102
- if (!sw2 || !ne2) { return this; }
103
-
97
+ ({_southWest: sw2, _northEast: ne2} = obj);
98
+ if (!sw2) { return this; }
99
+ } else if (!obj) {
100
+ return this;
101
+ } else if (LatLng.validate(obj)) {
102
+ sw2 = ne2 = LatLng.from(obj);
104
103
  } else {
105
- if (!obj) {
106
- return this;
107
- }
108
- if (LatLng.validate(obj)) {
109
- return this.extend(LatLng.from(obj));
110
- }
111
104
  return this.extend(LatLngBounds.from(obj));
112
105
  }
113
106
 
114
- if (!sw && !ne) {
107
+ if (!sw) {
115
108
  this._southWest = new LatLng(sw2.lat, sw2.lng);
116
109
  this._northEast = new LatLng(ne2.lat, ne2.lng);
117
110
  } else {
@@ -1,5 +1,5 @@
1
1
  import {EarthCRS} from './EarthCRS.js';
2
- import {Mercator} from '../projection/Projection.Mercator.js';
2
+ import {MercatorProjection} from '../projection/MercatorProjection.js';
3
3
  import {Transformation} from '../../geometry/Transformation.js';
4
4
  /** @import {Projection} from '../projection/index.js' */
5
5
 
@@ -10,10 +10,10 @@ export class EPSG3395 extends EarthCRS {
10
10
  /** @type {string} */
11
11
  static code = 'EPSG:3395';
12
12
  /** @type {Projection} */
13
- static projection = Mercator;
13
+ static projection = MercatorProjection;
14
14
  /** @type {Transformation} */
15
15
  static transformation = /* @__PURE__ */ (() => {
16
- const scale = 0.5 / (Math.PI * Mercator.R);
16
+ const scale = 0.5 / (Math.PI * MercatorProjection.R);
17
17
  return new Transformation(scale, 0.5, -scale, 0.5);
18
18
  })();
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import {EarthCRS} from './EarthCRS.js';
2
- import {SphericalMercator} from '../projection/Projection.SphericalMercator.js';
2
+ import {SphericalMercatorProjection} from '../projection/SphericalMercatorProjection.js';
3
3
  import {Transformation} from '../../geometry/Transformation.js';
4
4
  /** @import {Projection} from '../projection/index.js' */
5
5
 
@@ -12,10 +12,10 @@ export class EPSG3857 extends EarthCRS {
12
12
  /** @type {string} */
13
13
  static code = 'EPSG:3857';
14
14
  /** @type {Projection} */
15
- static projection = SphericalMercator;
15
+ static projection = SphericalMercatorProjection;
16
16
  /** @type {Transformation} */
17
17
  static transformation = /* @__PURE__ */ (() => {
18
- const scale = 0.5 / (Math.PI * SphericalMercator.R);
18
+ const scale = 0.5 / (Math.PI * SphericalMercatorProjection.R);
19
19
  return new Transformation(scale, 0.5, -scale, 0.5);
20
20
  })();
21
21
  }
@@ -1,5 +1,5 @@
1
1
  import {EarthCRS} from './EarthCRS.js';
2
- import {LonLat} from '../projection/Projection.LonLat.js';
2
+ import {LonLatProjection} from '../projection/LonLatProjection.js';
3
3
  import {Transformation} from '../../geometry/Transformation.js';
4
4
  /** @import {Projection} from '../projection/index.js' */
5
5
 
@@ -17,7 +17,7 @@ export class EPSG4326 extends EarthCRS {
17
17
  /** @type {string} */
18
18
  static code = 'EPSG:4326';
19
19
  /** @type {Projection} */
20
- static projection = LonLat;
20
+ static projection = LonLatProjection;
21
21
  /** @type {Transformation} */
22
22
  static transformation = /* @__PURE__ */ new Transformation(1 / 180, 1, -1 / 180, 0.5);
23
23
  }
@@ -1,5 +1,5 @@
1
1
  import {CRS} from './CRS.js';
2
- import {LonLat} from '../projection/Projection.LonLat.js';
2
+ import {LonLatProjection} from '../projection/LonLatProjection.js';
3
3
  import {Transformation} from '../../geometry/Transformation.js';
4
4
  /** @import {LatLng} from '../LatLng.js' */
5
5
  /** @import {Projection} from '../projection/index.js' */
@@ -12,7 +12,7 @@ import {Transformation} from '../../geometry/Transformation.js';
12
12
  */
13
13
  export class SimpleCRS extends CRS {
14
14
  /** @type {Projection} */
15
- static projection = LonLat;
15
+ static projection = LonLatProjection;
16
16
  /** @type {Transformation} */
17
17
  static transformation = /* @__PURE__ */ new Transformation(1, 0, -1, 0);
18
18
 
package/src/geo/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export {LatLng} from './LatLng.js';
2
2
  export {LatLngBounds} from './LatLngBounds.js';
3
3
 
4
- import * as Projection from './projection/index.js';
5
- export {Projection};
4
+ export * from './projection/index.js';
6
5
 
7
6
  export * from './crs/index.js';
@@ -11,7 +11,7 @@ import {Point} from '../../geometry/Point.js';
11
11
  * `EPSG4326` and `SimpleCRS` CRS.
12
12
  * @type {Projection}
13
13
  */
14
- export const LonLat = {
14
+ export const LonLatProjection = {
15
15
  project(latlng) {
16
16
  latlng = LatLng.from(latlng);
17
17
  return new Point(latlng.lng, latlng.lat);