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
@@ -33,6 +33,10 @@ import {pointToGeoJSON} from '../GeoJSONUtil.js';
33
33
  * top of all others (or below), specifying a high value like `1000` (or high negative
34
34
  * value, respectively).
35
35
  * @property {number} [opacity=1] The opacity of the marker.
36
+ * @property {number|null} [rotation=null] Rotation of the marker icon in degrees,
37
+ * clockwise, around the icon anchor, e.g. for the heading of a vehicle. A rotated
38
+ * marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
39
+ * under a tilted one. `null` means no rotation.
36
40
  * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
37
41
  * others when you hover the pointer over it.
38
42
  * @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`
@@ -52,7 +56,8 @@ import {pointToGeoJSON} from '../GeoJSONUtil.js';
52
56
  * marker is focused (via e.g. pressing `tab` on the keyboard) to ensure the marker is
53
57
  * visible within the map's bounds.
54
58
  * @property {boolean} [draggable=false] Whether the marker is draggable with pointer or
55
- * not.
59
+ * not. A focused draggable marker can also be moved with the arrow keys, by 10 pixels
60
+ * or 30 with Shift.
56
61
  * @property {boolean} [autoPan=false] Whether to pan the map when dragging this marker
57
62
  * near its edge or not.
58
63
  * @property {PointExpression} [autoPanPadding=[50, 50]] Distance (in pixels to the
@@ -97,6 +102,7 @@ export class Marker extends Layer {
97
102
  alt: 'Marker',
98
103
  zIndexOffset: 0,
99
104
  opacity: 1,
105
+ rotation: null,
100
106
  riseOnHover: false,
101
107
  riseOffset: 250,
102
108
  pane: 'markerPane',
@@ -254,7 +260,7 @@ export class Marker extends Layer {
254
260
  update() {
255
261
 
256
262
  if (this._icon && this._map && !this._culled) {
257
- const pos = this._map.latLngToLayerPoint(this._latlng).round();
263
+ const pos = this._map.latLngToLayerPoint(this._latlng)._round();
258
264
  this._setPos(pos);
259
265
  }
260
266
 
@@ -307,7 +313,7 @@ export class Marker extends Layer {
307
313
  DomEvent.on(icon, 'focus', this._panOnFocus, this);
308
314
  }
309
315
 
310
- const newShadow = options.shadow ? options.icon.createShadow(this._shadow) : null;
316
+ const newShadow = options.shadow ? options.icon.createShadow?.(this._shadow) ?? null : null;
311
317
  let addShadow = false;
312
318
 
313
319
  if (newShadow !== this._shadow) {
@@ -390,18 +396,27 @@ export class Marker extends Layer {
390
396
  }
391
397
 
392
398
  _setPos(pos) {
399
+ this._positionElements(pos);
400
+
401
+ this._zIndex = pos.y + this.options.zIndexOffset;
402
+
403
+ this._resetZIndex();
404
+ }
405
+
406
+ _positionElements(pos) {
407
+ const rotation = this.options.rotation;
393
408
 
394
409
  if (this._icon) {
395
410
  DomUtil.setPosition(this._icon, pos);
411
+ if (rotation != null) {
412
+ this._icon.style.transform += ` rotate(${rotation}deg)`;
413
+ }
396
414
  }
397
415
 
398
416
  if (this._shadow) {
399
417
  DomUtil.setPosition(this._shadow, pos);
418
+ this._shadow.style.display = rotation == null ? '' : 'none';
400
419
  }
401
-
402
- this._zIndex = pos.y + this.options.zIndexOffset;
403
-
404
- this._resetZIndex();
405
420
  }
406
421
 
407
422
  _updateZIndex(offset) {
@@ -413,7 +428,7 @@ export class Marker extends Layer {
413
428
 
414
429
  _animateZoom(opt) {
415
430
  if (this._culled) { return; }
416
- const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).round();
431
+ const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center)._round();
417
432
 
418
433
  this._setPos(pos);
419
434
  }
@@ -485,6 +500,30 @@ export class Marker extends Layer {
485
500
  }
486
501
  }
487
502
 
503
+ /**
504
+ * Returns the current [rotation](#markeroptions-rotation) of the marker in degrees.
505
+ * @returns {number|null}
506
+ */
507
+ getRotation() {
508
+ return this.options.rotation;
509
+ }
510
+
511
+ /**
512
+ * Changes the [rotation](#markeroptions-rotation) of the marker; `null` removes it.
513
+ * @param {number|null} rotation
514
+ * @returns {this}
515
+ */
516
+ setRotation(rotation) {
517
+ this.options.rotation = rotation;
518
+ // mid-zoom, the icon is transitioning to a position that update() can't compute yet; the zoom end applies it
519
+ if (this._icon && !this._map._animatingZoom) {
520
+ this._positionElements(DomUtil.getPosition(this._icon));
521
+ this._popup?._updatePosition();
522
+ this._tooltip?._updatePosition();
523
+ }
524
+ return this;
525
+ }
526
+
488
527
  /**
489
528
  * Changes the opacity of the marker.
490
529
  * @param {number} opacity
@@ -534,9 +573,10 @@ export class Marker extends Layer {
534
573
  const map = this._map;
535
574
  if (!map) { return; }
536
575
 
537
- const iconOpts = this.options.icon.options;
538
- const size = iconOpts.iconSize ? Point.from(iconOpts.iconSize) : new Point(0, 0);
539
- const anchor = iconOpts.iconAnchor ? Point.from(iconOpts.iconAnchor) : new Point(0, 0);
576
+ const icon = this._icon,
577
+ style = getComputedStyle(icon),
578
+ anchor = new Point(-parseFloat(style.marginLeft) || 0, -parseFloat(style.marginTop) || 0),
579
+ size = new Point(icon.offsetWidth, icon.offsetHeight);
540
580
 
541
581
  map.panInside(this._latlng, {
542
582
  paddingTopLeft: anchor,
@@ -545,11 +585,22 @@ export class Marker extends Layer {
545
585
  }
546
586
 
547
587
  _getPopupAnchor() {
548
- return this.options.icon.options.popupAnchor;
588
+ return this._rotateAnchor(this.options.icon.options.popupAnchor);
549
589
  }
550
590
 
551
591
  _getTooltipAnchor() {
552
- return this.options.icon.options.tooltipAnchor;
592
+ return this._rotateAnchor(this.options.icon.options.tooltipAnchor);
593
+ }
594
+
595
+ // anchors are offsets from the icon anchor, which is also the rotation origin
596
+ _rotateAnchor(anchor) {
597
+ const angle = this.options.rotation * Math.PI / 180;
598
+ if (!angle || !anchor) { return anchor; }
599
+
600
+ const {x, y} = Point.from(anchor),
601
+ cos = Math.cos(angle),
602
+ sin = Math.sin(angle);
603
+ return new Point(x * cos - y * sin, x * sin + y * cos);
553
604
  }
554
605
 
555
606
  /**
@@ -270,7 +270,7 @@ export class GridLayer extends Layer {
270
270
  * @returns {boolean}
271
271
  */
272
272
  isLoading() {
273
- return this._loading;
273
+ return !!this._loading;
274
274
  }
275
275
 
276
276
  /**
@@ -927,9 +927,12 @@ export class GridLayer extends Layer {
927
927
  });
928
928
  }
929
929
 
930
- if (this._noTilesToLoad()) {
930
+ // a tileload listener may have removed the layer, emptying the tile list
931
+ if (this._map && this._noTilesToLoad()) {
931
932
  this._loading = false;
932
933
  this.fire('load');
934
+
935
+ if (!this._map) { return; } // removed by a load listener
933
936
  this._map._scheduleIdleCheck();
934
937
 
935
938
  if (!this._map._fadeAnimated) {
@@ -2,7 +2,7 @@ import {GridLayer} from './GridLayer.js';
2
2
  import * as Util from '../../core/Util.js';
3
3
  import * as DomEvent from '../../dom/DomEvent.js';
4
4
  import {I18n} from '../../core/I18n.js';
5
- /** @import {Point} from '../../geometry/Point.js' */
5
+ import {Point} from '../../geometry/Point.js';
6
6
  /** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */
7
7
  /** @import {TileEvent} from '../../core/Events.js' */
8
8
 
@@ -151,7 +151,8 @@ export class TileLayer extends GridLayer {
151
151
 
152
152
  if (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {
153
153
 
154
- this.options.tileSize = Math.floor(this.options.tileSize / 2);
154
+ const tileSize = this.options.tileSize;
155
+ this.options.tileSize = tileSize instanceof Point ? tileSize.divideBy(2).floor() : Math.floor(tileSize / 2);
155
156
 
156
157
  if (!this.options.zoomReverse) {
157
158
  this.options.zoomOffset++;
@@ -344,8 +345,10 @@ export class TileLayer extends GridLayer {
344
345
  }
345
346
 
346
347
  _tileOnError(done, tile, e) {
347
- const errorUrl = this.options.errorTileUrl;
348
- if (errorUrl && tile.getAttribute('src') !== errorUrl) {
348
+ const errorUrl = this.options.errorTileUrl,
349
+ src = tile.getAttribute('src');
350
+ // removed tiles get an empty src to cancel their request, which fires error too
351
+ if (errorUrl && src !== errorUrl && (src || tile.isConnected)) {
349
352
  tile.src = errorUrl;
350
353
  }
351
354
  done(e, tile);
@@ -365,8 +368,8 @@ export class TileLayer extends GridLayer {
365
368
  }
366
369
 
367
370
  _getSubdomain(tilePoint) {
368
- const index = Math.abs(tilePoint.x + tilePoint.y) % this.options.subdomains.length;
369
- return this.options.subdomains[index];
371
+ const {subdomains} = this.options;
372
+ return subdomains?.[Math.abs(tilePoint.x + tilePoint.y) % subdomains.length];
370
373
  }
371
374
 
372
375
  // stops loading all tiles in the background layer
@@ -120,8 +120,9 @@ export class WMSTileLayer extends TileLayer {
120
120
  this._crs = this.options.crs ?? this._map.options.crs;
121
121
  this._wmsVersion = parseFloat(this.wmsParams.version);
122
122
 
123
- const projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs';
124
- this.wmsParams[projectionKey] = this._crs.code;
123
+ delete this.wmsParams.srs;
124
+ delete this.wmsParams.crs;
125
+ this.wmsParams[this._wmsVersion >= 1.3 ? 'crs' : 'srs'] = this._crs.code;
125
126
  }
126
127
 
127
128
  /**
@@ -199,6 +200,8 @@ export class WMSTileLayer extends TileLayer {
199
200
 
200
201
  Object.assign(this.wmsParams, params);
201
202
 
203
+ if (this._map) { this._updateCrs(); }
204
+
202
205
  if (!noRedraw) {
203
206
  this._keepCurrentTiles();
204
207
  this.redraw();
@@ -223,9 +223,9 @@ export class Canvas extends Renderer {
223
223
  if (typeof layer.options.dashArray === 'string') {
224
224
  const parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);
225
225
  // Ignore dash array containing invalid lengths
226
- layer.options._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));
226
+ layer._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));
227
227
  } else {
228
- layer.options._dashArray = layer.options.dashArray;
228
+ layer._dashArray = layer.options.dashArray;
229
229
  }
230
230
  }
231
231
 
@@ -327,21 +327,17 @@ export class Canvas extends Renderer {
327
327
 
328
328
  if (!this._drawing || layer._empty()) { return; }
329
329
 
330
- const p = layer._point,
330
+ const {x, y} = layer._point,
331
331
  ctx = this._ctx,
332
332
  r = Math.max(Math.round(layer._pxRadius), 1),
333
- s = (Math.max(Math.round(layer._pxRadiusY), 1) || r) / r;
334
-
335
- if (s !== 1) {
336
- ctx.save();
337
- ctx.scale(1, s);
338
- }
333
+ ry = Math.max(Math.round(layer._pxRadiusY), 1) || r;
339
334
 
340
335
  ctx.beginPath();
341
- ctx.arc(p.x, p.y / s, r, 0, Math.PI * 2, false);
342
-
343
- if (s !== 1) {
344
- ctx.restore();
336
+ // arc is faster for circles in Chrome and Firefox, ellipse for everything else
337
+ if (ry === r) {
338
+ ctx.arc(x, y, r, 0, Math.PI * 2);
339
+ } else {
340
+ ctx.ellipse(x, y, r, ry, 0, 0, Math.PI * 2);
345
341
  }
346
342
 
347
343
  this._fillStroke(ctx, layer);
@@ -358,7 +354,7 @@ export class Canvas extends Renderer {
358
354
 
359
355
  if (options.stroke && options.weight !== 0) {
360
356
  ctx.lineDashOffset = Number(options.dashOffset ?? 0);
361
- ctx.setLineDash(options._dashArray ?? []);
357
+ ctx.setLineDash(layer._dashArray ?? []);
362
358
  ctx.globalAlpha = options.opacity;
363
359
  ctx.lineWidth = options.weight;
364
360
  ctx.strokeStyle = options.color;
@@ -33,6 +33,9 @@ export class Circle extends CircleMarker {
33
33
  * @param {CircleOptions} [options]
34
34
  */
35
35
  constructor(latlng, options) {
36
+ if (typeof options === 'number') {
37
+ throw new Error('Circle: the radius is an option in Maplair. Use new Circle(latlng, {radius}).');
38
+ }
36
39
  super(latlng, options);
37
40
 
38
41
  if (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }
@@ -41,10 +44,13 @@ export class Circle extends CircleMarker {
41
44
  }
42
45
 
43
46
  /**
44
- * Returns the `LatLngBounds` of the path.
47
+ * Returns the `LatLngBounds` of the path. When the circle isn't on a map, they're
48
+ * approximated on a sphere.
45
49
  * @returns {LatLngBounds}
46
50
  */
47
51
  getBounds() {
52
+ if (!this._map) { return this._latlng.toBounds(this._radius * 2); }
53
+
48
54
  const half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];
49
55
 
50
56
  return new LatLngBounds(
@@ -107,7 +107,8 @@ export class CircleMarker extends Path {
107
107
  }
108
108
 
109
109
  _project() {
110
- this._point = this._map.latLngToLayerPoint(this._latlng);
110
+ // snapped to whole pixels: subpixel precision is invisible on markers but slows down rendering many of them
111
+ this._point = this._map.latLngToLayerPoint(this._latlng)._round();
111
112
  this._pxRadius = this._radius;
112
113
  this._updateBounds();
113
114
  }
@@ -141,7 +141,7 @@ export class Polygon extends Polyline {
141
141
  }
142
142
 
143
143
  for (const ring of this._rings) {
144
- const clipped = PolyUtil.clipPolygon(ring, bounds, true);
144
+ const clipped = PolyUtil.clipPolygon(ring, bounds);
145
145
  if (clipped.length) {
146
146
  this._parts.push(clipped);
147
147
  }
@@ -257,7 +257,7 @@ export class Polyline extends Path {
257
257
  points = this._rings[i];
258
258
 
259
259
  for (j = 0, len2 = points.length; j < len2 - 1; j++) {
260
- segment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j, true);
260
+ segment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j);
261
261
 
262
262
  if (!segment) { continue; }
263
263
 
@@ -13,13 +13,14 @@ const mapRendererMethods = {
13
13
  * are respected, and that the renderers do exist on the map.
14
14
  * @internal
15
15
  * @param {Path} layer
16
- * @returns {Renderer}
16
+ * @returns {Renderer|undefined}
17
17
  */
18
18
  getRenderer(layer) {
19
19
  const renderer = layer.options.renderer ?? this._getPaneRenderer(layer) ?? this.options.renderer ??
20
- (this._renderer ??= layer._createRenderer());
20
+ (this._renderer ??= layer._createRenderer?.());
21
21
 
22
- if (!this.hasLayer(renderer)) {
22
+ // a non-Path layer (e.g. a marker cluster group of a plugin) has no renderer of its own
23
+ if (renderer && !this.hasLayer(renderer)) {
23
24
  this.addLayer(renderer);
24
25
  }
25
26
  return renderer;
@@ -174,7 +174,7 @@ export class SVG extends Renderer {
174
174
 
175
175
  // drawing a circle with two half-arcs
176
176
  const d = layer._empty() ? 'M0 0' :
177
- `M${p.x - r},${p.y
177
+ `M${num(p.x - r)},${num(p.y)
178
178
  }${arc}${r * 2},0 ${
179
179
  arc}${-r * 2},0 `;
180
180
 
@@ -214,7 +214,7 @@ export class SVG extends Renderer {
214
214
  */
215
215
  static pointsToPath(rings, closed) {
216
216
  const str = rings.flatMap(points => [
217
- ...points.map((p, j) => `${(j ? 'L' : 'M') + p.x} ${p.y}`),
217
+ ...points.map((p, j) => `${(j ? 'L' : 'M') + num(p.x)} ${num(p.y)}`),
218
218
  // closes the ring for polygons
219
219
  closed ? 'z' : ''
220
220
  ]).join('');
@@ -224,3 +224,13 @@ export class SVG extends Renderer {
224
224
  }
225
225
 
226
226
  }
227
+
228
+ // Formats a pixel coordinate with 0.1px precision. Built from integer parts because V8 stringifies small integers
229
+ // much faster than fractional numbers, and path strings with many vertices are rebuilt on every redraw.
230
+ function num(v) {
231
+ const n = Math.round(v * 10),
232
+ a = n < 0 ? -n : n,
233
+ i = Math.floor(a / 10),
234
+ d = a - i * 10;
235
+ return (n < 0 ? '-' : '') + (d ? `${i}.${d}` : i);
236
+ }
@@ -12,7 +12,6 @@ import {Popup} from '../layer/Popup.js';
12
12
  import {Tooltip} from '../layer/Tooltip.js';
13
13
  import {Marker} from '../layer/marker/Marker.js';
14
14
  import {MarkerDrag} from '../layer/marker/Marker.Drag.js';
15
- import '../layer/marker/Marker.Rotation.js';
16
15
  import {DragHandler} from './handler/DragHandler.js';
17
16
  import {PinchZoomHandler} from './handler/PinchZoomHandler.js';
18
17
  import {ScrollWheelZoomHandler} from './handler/ScrollWheelZoomHandler.js';
@@ -65,7 +64,7 @@ const rotatedMaps = new WeakMap();
65
64
  const {panBy} = MaplairMap.prototype,
66
65
  {getEvents: getDivOverlayEvents} = DivOverlay.prototype,
67
66
  {_setPosition: setTooltipPosition} = Tooltip.prototype,
68
- {getEvents: getMarkerEvents} = Marker.prototype,
67
+ {getEvents: getMarkerEvents, _positionElements: positionMarkerElements} = Marker.prototype,
69
68
  {_onDown: onDraggableDown, _updatePosition: updateDraggablePosition} = Draggable.prototype,
70
69
  {_onPointerStart: onPinchStart} = PinchZoomHandler.prototype,
71
70
  {_onDown: onTapDragDown} = TapDragZoomHandler.prototype,
@@ -471,7 +470,7 @@ const divOverlayRotationMethods = {
471
470
  if (!this._map) { return; }
472
471
 
473
472
  const map = this._map,
474
- pos = map.latLngToLayerPoint(this._latlng),
473
+ pos = map.latLngToLayerPoint(this._latlng)._round(),
475
474
  // on a rotated map, the anchor is relative to the upright overlay
476
475
  anchor = map._rotateToPane(new Point(this._getAnchor()));
477
476
  let offset = Point.from(this.options.offset);
@@ -625,7 +624,23 @@ const tooltipRotationMethods = {
625
624
  Tooltip.include(tooltipRotationMethods);
626
625
 
627
626
  /**
628
- * Methods of `Marker` for the map rotation: the marker is updated on rotation.
627
+ * Options of `Marker` for the map rotation.
628
+ * @typedef {object} MarkerMapRotationOptions
629
+ * @lends MarkerOptions
630
+ * @property {boolean} [rotateWithView=false] On a rotated map (see
631
+ * `MaplairMap.setBearing()`), whether the icon rotates with the map (e.g. for arrows
632
+ * pointing in a geographic direction) instead of staying upright. The `rotation` of
633
+ * the marker is relative to the screen, or to north with `rotateWithView`.
634
+ */
635
+ Marker.include({
636
+ options: {
637
+ rotateWithView: false
638
+ }
639
+ });
640
+
641
+ /**
642
+ * Methods of `Marker` for the map rotation: the marker is updated on rotation, and
643
+ * its icon and shadow stay upright.
629
644
  * @lends Marker.prototype
630
645
  */
631
646
  const markerRotationMethods = {
@@ -636,6 +651,15 @@ const markerRotationMethods = {
636
651
  */
637
652
  getEvents() {
638
653
  return {...getMarkerEvents.call(this), rotate: this.update};
654
+ },
655
+
656
+ _positionElements(pos) {
657
+ positionMarkerElements.call(this, pos);
658
+ const bearing = this.options.rotateWithView ? 0 : (this._map?.getBearing() ?? 0);
659
+ if (!bearing) { return; }
660
+ for (const el of [this._icon, this._shadow]) {
661
+ if (el) { el.style.transform += ` rotate(${bearing}deg)`; }
662
+ }
639
663
  }
640
664
  };
641
665
  /** @typedef {typeof markerRotationMethods} MarkerMapRotationMethods */
package/src/map/Map.js CHANGED
@@ -451,12 +451,14 @@ export class MaplairMap extends Evented {
451
451
  * @returns {this}
452
452
  */
453
453
  setZoomAround(latlng, zoom, options) {
454
- const scale = this.getZoomScale(zoom),
455
- viewHalf = this.getSize().divideBy(2),
456
- containerPoint = latlng instanceof Point ? latlng : this.latLngToContainerPoint(latlng),
457
-
458
- centerOffset = containerPoint.subtract(viewHalf).multiplyBy(1 - 1 / scale),
459
- newCenter = this.containerPointToLatLng(viewHalf.add(centerOffset));
454
+ // work in unrounded projected coordinates so that zooming back and forth around the same point
455
+ // doesn't accumulate pixel rounding errors (amplified by the zoom scale) and drift the view;
456
+ // a pixel offset goes through layer points, which account for a rotation of the map
457
+ const center = this.project(this.getCenter()),
458
+ offset = latlng instanceof Point ?
459
+ this.containerPointToLayerPoint(latlng).subtract(this.containerPointToLayerPoint(this.getSize().divideBy(2))) :
460
+ this.project(latlng).subtract(center),
461
+ newCenter = this.unproject(center.add(offset.multiplyBy(1 - 1 / this.getZoomScale(zoom))));
460
462
 
461
463
  return this.setView(newCenter, zoom, {zoom: options});
462
464
  }
@@ -635,7 +637,6 @@ export class MaplairMap extends Evented {
635
637
 
636
638
  const r0 = r(0);
637
639
 
638
- function w(s) { return w0 * (Math.cosh(r0) / Math.cosh(r0 + rho * s)); }
639
640
  function u(s) { return w0 * (Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2; }
640
641
 
641
642
  function easeOut(t) { return 1 - (1 - t) ** 1.5; }
@@ -653,7 +654,7 @@ export class MaplairMap extends Evented {
653
654
 
654
655
  this._move(
655
656
  this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1)), startZoom),
656
- this.getScaleZoom(w0 / w(s), startZoom),
657
+ this.getScaleZoom(Math.cosh(r0 + rho * s) / Math.cosh(r0), startZoom),
657
658
  {flyTo: true});
658
659
 
659
660
  } else {
@@ -1137,7 +1138,7 @@ export class MaplairMap extends Evented {
1137
1138
  getCenter() {
1138
1139
  this._checkIfLoaded();
1139
1140
 
1140
- if (this._lastCenter && !this._moved()) {
1141
+ if (this._lastCenter && this._getMapPanePos().equals(this._lastCenterPanePos)) {
1141
1142
  return new LatLng(this._lastCenter);
1142
1143
  }
1143
1144
  return this.layerPointToLatLng(this._getCenterLayerPoint());
@@ -1385,8 +1386,7 @@ export class MaplairMap extends Evented {
1385
1386
  * @returns {Point}
1386
1387
  */
1387
1388
  latLngToLayerPoint(latlng) {
1388
- const projectedPoint = this.project(LatLng.from(latlng))._round();
1389
- return projectedPoint._subtract(this.getPixelOrigin());
1389
+ return this.project(LatLng.from(latlng))._subtract(this.getPixelOrigin());
1390
1390
  }
1391
1391
 
1392
1392
  /**
@@ -1715,6 +1715,7 @@ export class MaplairMap extends Evented {
1715
1715
 
1716
1716
  this._zoom = zoom;
1717
1717
  this._lastCenter = center;
1718
+ this._lastCenterPanePos = this._getMapPanePos();
1718
1719
  this._pixelOrigin = this._getNewPixelOrigin(center);
1719
1720
 
1720
1721
  if (!suppressEvent) {
@@ -1908,11 +1909,11 @@ export class MaplairMap extends Evented {
1908
1909
  };
1909
1910
 
1910
1911
  if (e.type !== 'keydown' && e.type !== 'keyup') {
1911
- const isMarker = target.getLatLng && (!target._pxRadius || target._pxRadius <= 10);
1912
- data.containerPoint = isMarker ?
1913
- this.latLngToContainerPoint(target.getLatLng()) : this.pointerEventToContainerPoint(e);
1912
+ const latlng = (!target._pxRadius || target._pxRadius <= 10) && target.getLatLng?.();
1913
+ data.containerPoint = latlng ?
1914
+ this.latLngToContainerPoint(latlng) : this.pointerEventToContainerPoint(e);
1914
1915
  data.layerPoint = this.containerPointToLayerPoint(data.containerPoint);
1915
- data.latlng = isMarker ? target.getLatLng() : this.layerPointToLatLng(data.layerPoint);
1916
+ data.latlng = latlng || this.layerPointToLatLng(data.layerPoint);
1916
1917
  }
1917
1918
 
1918
1919
  for (const t of targets) {
@@ -1955,11 +1956,6 @@ export class MaplairMap extends Evented {
1955
1956
  return DomUtil.getPosition(this._mapPane);
1956
1957
  }
1957
1958
 
1958
- _moved() {
1959
- const pos = this._getMapPanePos();
1960
- return pos && !pos.equals([0, 0]);
1961
- }
1962
-
1963
1959
  _getTopLeftPoint(center, zoom) {
1964
1960
  const pixelOrigin = center && zoom !== undefined ?
1965
1961
  this._getNewPixelOrigin(center, zoom) :
@@ -1984,7 +1980,7 @@ export class MaplairMap extends Evented {
1984
1980
 
1985
1981
  // offset of the specified place to the current center in pixels
1986
1982
  _getCenterOffset(latlng) {
1987
- return this.latLngToLayerPoint(latlng).subtract(this._getCenterLayerPoint());
1983
+ return this.latLngToLayerPoint(latlng)._round()._subtract(this._getCenterLayerPoint());
1988
1984
  }
1989
1985
 
1990
1986
  // adjust center for view to get inside bounds