maplair 4.3.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/CHANGELOG.md +151 -8
  2. package/dist/esm/control/AttributionControl.js +30 -13
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/ButtonControl.js +0 -1
  5. package/dist/esm/control/ButtonControl.js.map +1 -1
  6. package/dist/esm/control/ContextMenu.js +1 -1
  7. package/dist/esm/control/ContextMenu.js.map +1 -1
  8. package/dist/esm/control/Control.js +16 -11
  9. package/dist/esm/control/Control.js.map +1 -1
  10. package/dist/esm/control/FullscreenControl.js +0 -1
  11. package/dist/esm/control/FullscreenControl.js.map +1 -1
  12. package/dist/esm/control/LayersControl.js +46 -27
  13. package/dist/esm/control/LayersControl.js.map +1 -1
  14. package/dist/esm/control/RotateControl.js +0 -1
  15. package/dist/esm/control/RotateControl.js.map +1 -1
  16. package/dist/esm/control/ScaleControl.js +7 -8
  17. package/dist/esm/control/ScaleControl.js.map +1 -1
  18. package/dist/esm/control/SideBySideControl.js +3 -2
  19. package/dist/esm/control/SideBySideControl.js.map +1 -1
  20. package/dist/esm/control/ZoomControl.js +14 -13
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Events.js +3 -2
  23. package/dist/esm/core/Events.js.map +1 -1
  24. package/dist/esm/core/Util.js +17 -5
  25. package/dist/esm/core/Util.js.map +1 -1
  26. package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
  27. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  28. package/dist/esm/dom/DomEvent.js +4 -7
  29. package/dist/esm/dom/DomEvent.js.map +1 -1
  30. package/dist/esm/dom/DomUtil.js +5 -5
  31. package/dist/esm/dom/DomUtil.js.map +1 -1
  32. package/dist/esm/dom/Draggable.js +10 -8
  33. package/dist/esm/dom/Draggable.js.map +1 -1
  34. package/dist/esm/geo/LatLng.js +24 -35
  35. package/dist/esm/geo/LatLng.js.map +1 -1
  36. package/dist/esm/geo/LatLngBounds.js +6 -3
  37. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  38. package/dist/esm/geometry/Bounds.js +2 -2
  39. package/dist/esm/geometry/Bounds.js.map +1 -1
  40. package/dist/esm/geometry/Point.js +16 -19
  41. package/dist/esm/geometry/Point.js.map +1 -1
  42. package/dist/esm/geometry/PolyUtil.js +10 -3
  43. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  44. package/dist/esm/geometry/Transformation.js +1 -7
  45. package/dist/esm/geometry/Transformation.js.map +1 -1
  46. package/dist/esm/layer/BlanketOverlay.js +3 -2
  47. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  48. package/dist/esm/layer/DivOverlay.js +25 -25
  49. package/dist/esm/layer/DivOverlay.js.map +1 -1
  50. package/dist/esm/layer/ImageOverlay.js +8 -5
  51. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  52. package/dist/esm/layer/Layer.js +12 -7
  53. package/dist/esm/layer/Layer.js.map +1 -1
  54. package/dist/esm/layer/Popup.js +33 -15
  55. package/dist/esm/layer/Popup.js.map +1 -1
  56. package/dist/esm/layer/Tooltip.js +48 -56
  57. package/dist/esm/layer/Tooltip.js.map +1 -1
  58. package/dist/esm/layer/VideoOverlay.js +2 -2
  59. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  60. package/dist/esm/layer/marker/DivIcon.js +4 -8
  61. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  62. package/dist/esm/layer/marker/Icon.js +37 -17
  63. package/dist/esm/layer/marker/Icon.js.map +1 -1
  64. package/dist/esm/layer/marker/Marker.Drag.js +11 -12
  65. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  66. package/dist/esm/layer/marker/Marker.js +54 -53
  67. package/dist/esm/layer/marker/Marker.js.map +1 -1
  68. package/dist/esm/layer/marker/SvgIcon.js +1 -1
  69. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  70. package/dist/esm/layer/tile/GridLayer.js +29 -21
  71. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  72. package/dist/esm/layer/tile/TileLayer.js +19 -15
  73. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  74. package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
  75. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  76. package/dist/esm/layer/vector/Canvas.js +45 -94
  77. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  78. package/dist/esm/layer/vector/Circle.js +8 -9
  79. package/dist/esm/layer/vector/Circle.js.map +1 -1
  80. package/dist/esm/layer/vector/CircleMarker.js +15 -4
  81. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  82. package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
  83. package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
  84. package/dist/esm/layer/vector/Path.js +10 -5
  85. package/dist/esm/layer/vector/Path.js.map +1 -1
  86. package/dist/esm/layer/vector/Polygon.js +10 -11
  87. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  88. package/dist/esm/layer/vector/Polyline.js +19 -26
  89. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  90. package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
  91. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  92. package/dist/esm/layer/vector/Renderer.js +16 -0
  93. package/dist/esm/layer/vector/Renderer.js.map +1 -1
  94. package/dist/esm/layer/vector/SVG.js +3 -3
  95. package/dist/esm/layer/vector/SVG.js.map +1 -1
  96. package/dist/esm/map/Map.Rotation.js +9 -11
  97. package/dist/esm/map/Map.Rotation.js.map +1 -1
  98. package/dist/esm/map/Map.js +158 -71
  99. package/dist/esm/map/Map.js.map +1 -1
  100. package/dist/esm/map/MapSync.js +2 -5
  101. package/dist/esm/map/MapSync.js.map +1 -1
  102. package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
  103. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  104. package/dist/esm/map/handler/DisplaceHandler.js +68 -30
  105. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  106. package/dist/esm/map/handler/DragHandler.js +7 -2
  107. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  108. package/dist/esm/map/handler/KeyboardHandler.js +3 -5
  109. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  110. package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
  111. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  112. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
  113. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  114. package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
  115. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  116. package/dist/esm/map/handler/TapHoldHandler.js +8 -20
  117. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  118. package/dist/esm/package.js +1 -1
  119. package/dist/maplair-global-src.js +970 -810
  120. package/dist/maplair-global-src.js.map +1 -1
  121. package/dist/maplair-global.js +2 -2
  122. package/dist/maplair-global.js.map +1 -1
  123. package/dist/maplair-src.js +970 -810
  124. package/dist/maplair-src.js.map +1 -1
  125. package/dist/maplair.css +1 -1
  126. package/dist/maplair.js +2 -2
  127. package/dist/maplair.js.map +1 -1
  128. package/i18n/en.json +1 -0
  129. package/package.json +1 -1
  130. package/src/control/AttributionControl.js +37 -11
  131. package/src/control/ButtonControl.js +0 -1
  132. package/src/control/ContextMenu.js +1 -1
  133. package/src/control/Control.js +13 -16
  134. package/src/control/FullscreenControl.js +0 -1
  135. package/src/control/LayersControl.js +61 -37
  136. package/src/control/RotateControl.js +0 -1
  137. package/src/control/ScaleControl.js +10 -8
  138. package/src/control/SideBySideControl.js +4 -2
  139. package/src/control/ZoomControl.js +11 -13
  140. package/src/core/Events.js +6 -2
  141. package/src/core/Util.js +17 -4
  142. package/src/dom/DomEvent.PointerEvents.js +68 -2
  143. package/src/dom/DomEvent.js +5 -17
  144. package/src/dom/DomUtil.js +5 -5
  145. package/src/dom/Draggable.js +11 -8
  146. package/src/geo/LatLng.js +24 -37
  147. package/src/geo/LatLngBounds.js +10 -4
  148. package/src/geometry/Bounds.js +3 -3
  149. package/src/geometry/Point.js +22 -28
  150. package/src/geometry/PolyUtil.js +12 -3
  151. package/src/geometry/Transformation.js +1 -8
  152. package/src/layer/BlanketOverlay.js +6 -3
  153. package/src/layer/DivOverlay.js +30 -32
  154. package/src/layer/ImageOverlay.js +12 -9
  155. package/src/layer/Layer.js +19 -7
  156. package/src/layer/Popup.js +41 -21
  157. package/src/layer/Tooltip.js +50 -70
  158. package/src/layer/VideoOverlay.js +2 -2
  159. package/src/layer/marker/DivIcon.js +3 -6
  160. package/src/layer/marker/Icon.js +41 -20
  161. package/src/layer/marker/Marker.Drag.js +22 -24
  162. package/src/layer/marker/Marker.js +71 -64
  163. package/src/layer/marker/SvgIcon.js +1 -1
  164. package/src/layer/tile/GridLayer.js +41 -30
  165. package/src/layer/tile/TileLayer.js +31 -21
  166. package/src/layer/tile/WMSTileLayer.js +4 -2
  167. package/src/layer/vector/Canvas.js +53 -149
  168. package/src/layer/vector/Circle.js +13 -13
  169. package/src/layer/vector/CircleMarker.js +16 -3
  170. package/src/layer/vector/Path.ZoomStyles.js +5 -3
  171. package/src/layer/vector/Path.js +11 -5
  172. package/src/layer/vector/Polygon.js +11 -10
  173. package/src/layer/vector/Polyline.js +20 -21
  174. package/src/layer/vector/Renderer.getRenderer.js +2 -1
  175. package/src/layer/vector/Renderer.js +21 -3
  176. package/src/layer/vector/SVG.js +3 -3
  177. package/src/map/Map.Rotation.js +13 -9
  178. package/src/map/Map.js +195 -83
  179. package/src/map/MapSync.js +2 -2
  180. package/src/map/handler/BoxZoomHandler.js +5 -0
  181. package/src/map/handler/DisplaceHandler.js +53 -7
  182. package/src/map/handler/DragHandler.js +5 -5
  183. package/src/map/handler/KeyboardHandler.js +5 -10
  184. package/src/map/handler/PinchZoomHandler.js +4 -4
  185. package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
  186. package/src/map/handler/TapDragZoomHandler.js +2 -2
  187. package/src/map/handler/TapHoldHandler.js +13 -25
  188. package/src/maplair.css +50 -10
  189. package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
  190. package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
  191. package/src/dom/DomEvent.DoubleTap.js +0 -143
@@ -96,7 +96,7 @@ export class VideoOverlay extends ImageOverlay {
96
96
  if (!Array.isArray(this._url)) { this._url = [this._url]; }
97
97
 
98
98
  if (!this.options.keepAspectRatio) {
99
- vid.style['objectFit'] = 'fill';
99
+ vid.style.objectFit = 'fill';
100
100
  }
101
101
  vid.autoplay = !!this.options.autoplay;
102
102
  vid.controls = !!this.options.controls;
@@ -106,7 +106,7 @@ export class VideoOverlay extends ImageOverlay {
106
106
  for (const url of this._url) {
107
107
  const source = DomUtil.create('source');
108
108
  source.src = url;
109
- vid.appendChild(source);
109
+ vid.append(source);
110
110
  }
111
111
  }
112
112
  }
@@ -65,16 +65,13 @@ export class DivIcon extends Icon {
65
65
  options = this.options;
66
66
 
67
67
  if (options.html instanceof Element) {
68
- div.replaceChildren();
69
- div.appendChild(options.html);
68
+ div.replaceChildren(options.html);
70
69
  } else {
71
70
  div.innerHTML = options.html !== false ? options.html : '';
72
71
  }
73
72
 
74
- if (options.bgPos) {
75
- const bgPos = Point.from(options.bgPos);
76
- div.style.backgroundPosition = `${-bgPos.x}px ${-bgPos.y}px`;
77
- }
73
+ const bgPos = options.bgPos && Point.from(options.bgPos);
74
+ div.style.backgroundPosition = bgPos ? `${-bgPos.x}px ${-bgPos.y}px` : '';
78
75
  this._setIconStyles(div, 'icon');
79
76
 
80
77
  return div;
@@ -1,5 +1,5 @@
1
1
  import {Class} from '../../core/Class.js';
2
- import {setOptions} from '../../core/Util.js';
2
+ import {setOptions, toNumber} from '../../core/Util.js';
3
3
  import {Point} from '../../geometry/Point.js';
4
4
 
5
5
  /** @import {PointExpression} from '../../geometry/Point.js' */
@@ -19,8 +19,11 @@ import {Point} from '../../geometry/Point.js';
19
19
  * can be set in CSS with negative margins.
20
20
  * @property {PointExpression} [popupAnchor=[0, 0]] The coordinates of the point from
21
21
  * which popups will "open", relative to the icon anchor.
22
- * @property {PointExpression} [tooltipAnchor=[0, 0]] The coordinates of the point from
23
- * which tooltips will "open", relative to the icon anchor.
22
+ * @property {PointExpression} [tooltipAnchor=[0, 0]] Where tooltips opening to the side
23
+ * attach, relative to the icon anchor: `x` is how far to the right (mirrored for tooltips
24
+ * opening to the left) and `y` how far down. Tooltips opening to the top or bottom attach
25
+ * to the middle of the icon's top or bottom edge, and `center` ones to the middle of the
26
+ * icon at the `y` height.
24
27
  * @property {string} [shadowUrl] The URL to the icon shadow image. If not specified, no
25
28
  * shadow image will be created.
26
29
  * @property {string} [shadowRetinaUrl] The URL to a retina sized version of the shadow
@@ -113,37 +116,55 @@ export class Icon extends Class {
113
116
 
114
117
  if (this.options.crossOrigin || this.options.crossOrigin === '') {
115
118
  img.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;
119
+ } else {
120
+ img.crossOrigin = null;
116
121
  }
117
122
 
118
123
  return img;
119
124
  }
120
125
 
121
- _setIconStyles(img, name) {
126
+ // The size and anchor of the icon or shadow in pixels; a side that isn't a number, like
127
+ // 'auto' in [100, 'auto'], is left to CSS and comes out as NaN.
128
+ _getBox(name) {
122
129
  const options = this.options;
123
- let sizeOption = options[`${name}Size`];
130
+ const sizeOption = options[`${name}Size`];
131
+ const [width, height] = (typeof sizeOption === 'number' ? [sizeOption, sizeOption] :
132
+ Array.isArray(sizeOption) ? sizeOption : [sizeOption?.x, sizeOption?.y]).map(toNumber);
133
+
134
+ const anchorOption = name === 'shadow' && options.shadowAnchor || options.iconAnchor;
135
+ const anchor = Point.validate(anchorOption) ? Point.from(anchorOption) :
136
+ {x: Math.round(width / 2), y: Math.round(height / 2)};
137
+ return {width, height, anchor};
138
+ }
124
139
 
125
- if (typeof sizeOption === 'number') {
126
- sizeOption = [sizeOption, sizeOption];
127
- }
140
+ // Where a tooltip opening in the given direction attaches, relative to the icon anchor.
141
+ _getTooltipAnchor(direction) {
142
+ const {x, y} = Point.from(this.options.tooltipAnchor);
143
+ if (direction === 'left') { return new Point(-x, y); }
144
+ if (direction === 'center') { return new Point(0, y); }
145
+ if (direction !== 'top' && direction !== 'bottom') { return new Point(x, y); }
128
146
 
129
- const size = Point.validate(sizeOption) && Point.from(sizeOption);
147
+ const {height, anchor} = this._getBox('icon');
148
+ return new Point(0, (direction === 'top' ? -anchor.y : height - anchor.y) || 0);
149
+ }
130
150
 
131
- const anchorPosition = name === 'shadow' && options.shadowAnchor || options.iconAnchor || size && size.divideBy(2, true);
132
- const anchor = Point.validate(anchorPosition) && Point.from(anchorPosition);
151
+ _setIconStyles(img, name) {
152
+ const options = this.options;
153
+ const {width, height, anchor} = this._getBox(name);
133
154
 
134
155
  img.className = `maplair-marker-${name} ${options.className || ''}`;
135
156
 
136
- if (anchor) {
137
- img.style.marginLeft = `${-anchor.x}px`;
138
- img.style.marginTop = `${-anchor.y}px`;
139
- }
157
+ // a marker reuses the element of its previous icon, which may have set any of these
158
+ const {style} = img;
159
+ style.marginLeft = style.marginTop = style.width = style.height = '';
160
+
161
+ if (!isNaN(anchor.x)) { style.marginLeft = `${-anchor.x}px`; }
162
+ if (!isNaN(anchor.y)) { style.marginTop = `${-anchor.y}px`; }
140
163
  // the origin of the marker rotation: the anchor, which is the top left corner without one
141
- img.style.transformOrigin = anchor ? `${anchor.x}px ${anchor.y}px` : '0 0';
164
+ style.transformOrigin = !isNaN(anchor.x) && !isNaN(anchor.y) ? `${anchor.x}px ${anchor.y}px` : '0 0';
142
165
 
143
- if (size) {
144
- img.style.width = `${size.x}px`;
145
- img.style.height = `${size.y}px`;
146
- }
166
+ if (!isNaN(width)) { style.width = `${width}px`; }
167
+ if (!isNaN(height)) { style.height = `${height}px`; }
147
168
  }
148
169
 
149
170
  _createImg(src, el) {
@@ -2,7 +2,6 @@ import {Handler} from '../../core/Handler.js';
2
2
  import * as DomEvent from '../../dom/DomEvent.js';
3
3
  import * as DomUtil from '../../dom/DomUtil.js';
4
4
  import {Draggable} from '../../dom/Draggable.js';
5
- import {Bounds} from '../../geometry/Bounds.js';
6
5
  import {Point} from '../../geometry/Point.js';
7
6
 
8
7
  /** @import {Marker, MarkerMoveEvent} from './Marker.js' */
@@ -15,8 +14,8 @@ const arrows = {ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowD
15
14
  * The handler of `Marker` which makes the markers draggable, see the
16
15
  * [`dragging`](#marker-dragging) property of markers and its `draggable` option.
17
16
  *
18
- * @fires Marker#dragstart {MaplairEvent} Fired when the user starts dragging the marker.
19
- * @fires Marker#movestart {MaplairEvent} Fired when the marker starts moving (because of
17
+ * @fires Marker#dragstart {DraggableEvent} Fired when the user starts dragging the marker.
18
+ * @fires Marker#movestart {DraggableEvent} Fired when the marker starts moving (because of
20
19
  * dragging).
21
20
  * @fires Marker#drag {MarkerMoveEvent} Fired repeatedly while the user drags the marker.
22
21
  * @fires Marker#dragend {DragEndEvent} Fired when the user stops dragging the marker.
@@ -87,25 +86,22 @@ export class MarkerDrag extends Handler {
87
86
  const marker = this._marker,
88
87
  map = marker._map,
89
88
  speed = this._marker.options.autoPanSpeed,
90
- padding = this._marker.options.autoPanPadding,
89
+ padding = new Point(this._marker.options.autoPanPadding),
91
90
  iconPos = DomUtil.getPosition(marker._icon),
92
91
  bounds = map.getPixelBounds(),
93
- origin = map.getPixelOrigin();
92
+ origin = map.getPixelOrigin(),
93
+ min = bounds.min._subtract(origin)._add(padding),
94
+ max = bounds.max._subtract(origin)._subtract(padding),
95
+ // how far the icon is past the padded bounds on each axis (0 if within)
96
+ dx = Math.max(iconPos.x - max.x, 0) + Math.min(iconPos.x - min.x, 0),
97
+ dy = Math.max(iconPos.y - max.y, 0) + Math.min(iconPos.y - min.y, 0);
94
98
 
95
- const panBounds = new Bounds(
96
- bounds.min._subtract(origin).add(padding),
97
- bounds.max._subtract(origin).subtract(padding)
98
- );
99
+ if (dx || dy) {
100
+ // pan faster the deeper the icon goes into the padding, but not past maxBounds
101
+ const movement = map._limitOffset(new Point(dx / padding.x * speed, dy / padding.y * speed),
102
+ map.options.maxBounds)._round();
99
103
 
100
- if (!panBounds.contains(iconPos)) {
101
- // Compute incremental movement
102
- const movement = new Point(
103
- (Math.max(panBounds.max.x, iconPos.x) - panBounds.max.x) / (bounds.max.x - panBounds.max.x) -
104
- (Math.min(panBounds.min.x, iconPos.x) - panBounds.min.x) / (bounds.min.x - panBounds.min.x),
105
-
106
- (Math.max(panBounds.max.y, iconPos.y) - panBounds.max.y) / (bounds.max.y - panBounds.max.y) -
107
- (Math.min(panBounds.min.y, iconPos.y) - panBounds.min.y) / (bounds.min.y - panBounds.min.y)
108
- ).multiplyBy(speed);
104
+ if (!movement.x && !movement.y) { return; }
109
105
 
110
106
  map.panBy(movement, {animate: false});
111
107
 
@@ -119,15 +115,15 @@ export class MarkerDrag extends Handler {
119
115
  }
120
116
  }
121
117
 
122
- _onDragStart() {
118
+ _onDragStart({originalEvent}) {
123
119
  this._oldLatLng = this._marker.getLatLng();
124
120
 
125
121
  // When using ES6 imports it could not be set when `Popup` was not imported as well
126
122
  this._marker.closePopup?.();
127
123
 
128
124
  this._marker
129
- .fire('movestart')
130
- .fire('dragstart');
125
+ .fire('movestart', {originalEvent})
126
+ .fire('dragstart', {originalEvent});
131
127
  }
132
128
 
133
129
  _onPreDrag(e) {
@@ -140,7 +136,10 @@ export class MarkerDrag extends Handler {
140
136
  _onDrag(e) {
141
137
  const marker = this._marker,
142
138
  iconPos = DomUtil.getPosition(marker._icon),
143
- latlng = marker._map.layerPointToLatLng(iconPos);
139
+ latlng = marker._map.layerPointToLatLng(iconPos),
140
+ {alt} = this._oldLatLng;
141
+
142
+ if (alt !== undefined) { latlng.alt = alt; }
144
143
 
145
144
  // Draggable only moved the icon and dropped its rotation
146
145
  marker._positionElements(iconPos);
@@ -157,7 +156,6 @@ export class MarkerDrag extends Handler {
157
156
  _onDragEnd(e) {
158
157
  cancelAnimationFrame(this._panRequest);
159
158
 
160
- delete this._oldLatLng;
161
159
  this._marker
162
160
  .fire('moveend')
163
161
  .fire('dragend', e);
@@ -187,7 +185,7 @@ export class MarkerDrag extends Handler {
187
185
  draggable._startPos = DomUtil.getPosition(draggable._element);
188
186
  draggable._moved = draggable._moving = true;
189
187
  this._keyOffset = new Point(0, 0);
190
- draggable.fire('dragstart');
188
+ draggable.fire('dragstart', {originalEvent: k});
191
189
  }
192
190
 
193
191
  // in container pixels, which the map rotation (if any) turns to the frame of the rotated pane
@@ -5,6 +5,7 @@ import {LatLng} from '../../geo/LatLng.js';
5
5
  import {Point} from '../../geometry/Point.js';
6
6
  import * as DomUtil from '../../dom/DomUtil.js';
7
7
  import * as DomEvent from '../../dom/DomEvent.js';
8
+ import {I18n} from '../../core/I18n.js';
8
9
  import {MarkerDrag} from './Marker.Drag.js';
9
10
  import {pointToGeoJSON} from '../GeoJSONUtil.js';
10
11
  /** @import {Feature} from 'geojson' */
@@ -26,7 +27,8 @@ import {pointToGeoJSON} from '../GeoJSONUtil.js';
26
27
  * @property {string} [title=''] Text for the browser tooltip that appear on marker hover
27
28
  * (no tooltip by default).
28
29
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
29
- * @property {string} [alt='Marker'] Text for the `alt` attribute of the icon image.
30
+ * @property {string} [alt] Text for the `alt` attribute of the icon image, the
31
+ * translation of `'Marker'` by default.
30
32
  * [Useful for accessibility](https://maplair.org/examples/accessibility/#markers-must-be-labelled).
31
33
  * @property {number} [zIndexOffset=0] By default, marker images zIndex is set
32
34
  * automatically based on its latitude. Use this option if you want to put the marker on
@@ -38,9 +40,9 @@ import {pointToGeoJSON} from '../GeoJSONUtil.js';
38
40
  * marker, even at 0°, has no shadow, since the shadow of an upright pin looks wrong
39
41
  * under a tilted one. `null` means no rotation.
40
42
  * @property {boolean} [riseOnHover=false] If `true`, the marker will get on top of
41
- * others when you hover the pointer over it.
42
- * @property {number} [riseOffset=250] The z-index offset used for the `riseOnHover`
43
- * feature.
43
+ * others while the pointer is over it. It always does while it has focus.
44
+ * @property {number} [riseOffset=250] The z-index offset used when the marker gets on
45
+ * top of others on hover or focus.
44
46
  * @property {string} [pane='markerPane'] `Map pane` where the markers icon will be added.
45
47
  * @property {string} [shadowPane='shadowPane'] `Map pane` where the markers shadow will
46
48
  * be added.
@@ -99,7 +101,7 @@ export class Marker extends Layer {
99
101
 
100
102
  keyboard: true,
101
103
  title: '',
102
- alt: 'Marker',
104
+ alt: undefined,
103
105
  zIndexOffset: 0,
104
106
  opacity: 1,
105
107
  rotation: null,
@@ -260,7 +262,7 @@ export class Marker extends Layer {
260
262
  update() {
261
263
 
262
264
  if (this._icon && this._map && !this._culled) {
263
- const pos = this._map.latLngToLayerPoint(this._latlng)._round();
265
+ const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
264
266
  this._setPos(pos);
265
267
  }
266
268
 
@@ -286,7 +288,7 @@ export class Marker extends Layer {
286
288
  }
287
289
 
288
290
  if (icon instanceof HTMLImageElement) {
289
- icon.alt = options.alt ?? '';
291
+ icon.alt = options.alt ?? I18n.translate('Marker');
290
292
  }
291
293
  }
292
294
 
@@ -302,11 +304,13 @@ export class Marker extends Layer {
302
304
 
303
305
  this._icon = icon;
304
306
 
307
+ if (this._popup?._source === this) {
308
+ this._popup._updateSourceAria(this._popup.isOpen());
309
+ }
310
+
311
+ DomEvent.on(icon, 'focusin focusout', this._updateRise, this);
305
312
  if (options.riseOnHover) {
306
- this.on({
307
- pointerover: this._bringToFront,
308
- pointerout: this._resetZIndex
309
- });
313
+ DomEvent.on(icon, 'pointerover pointerout', this._updateRise, this);
310
314
  }
311
315
 
312
316
  if (this.options.autoPanOnFocus) {
@@ -334,21 +338,17 @@ export class Marker extends Layer {
334
338
 
335
339
 
336
340
  if (addIcon) {
337
- this.getPane().appendChild(this._icon);
341
+ this.getPane().append(this._icon);
338
342
  }
339
343
  this._initInteraction();
340
344
  if (newShadow && addShadow) {
341
- this.getPane(options.shadowPane).appendChild(this._shadow);
345
+ this.getPane(options.shadowPane).append(this._shadow);
342
346
  }
343
347
  }
344
348
 
345
349
  _removeIcon() {
346
- if (this.options.riseOnHover) {
347
- this.off({
348
- pointerover: this._bringToFront,
349
- pointerout: this._resetZIndex
350
- });
351
- }
350
+ DomEvent.off(this._icon, 'pointerover pointerout focusin focusout', this._updateRise, this);
351
+ this._hovered = this._focused = false;
352
352
 
353
353
  if (this.options.autoPanOnFocus) {
354
354
  DomEvent.off(this._icon, 'focus', this._panOnFocus, this);
@@ -379,9 +379,9 @@ export class Marker extends Layer {
379
379
  this._culled = !visible;
380
380
 
381
381
  if (visible) {
382
- this.getPane().appendChild(this._icon);
382
+ this.getPane().append(this._icon);
383
383
  if (this._shadow) {
384
- this.getPane(this.options.shadowPane).appendChild(this._shadow);
384
+ this.getPane(this.options.shadowPane).append(this._shadow);
385
385
  }
386
386
  this.update();
387
387
  } else {
@@ -398,9 +398,9 @@ export class Marker extends Layer {
398
398
  _setPos(pos) {
399
399
  this._positionElements(pos);
400
400
 
401
- this._zIndex = pos.y + this.options.zIndexOffset;
401
+ this._zIndex = Math.round(pos.y) + this.options.zIndexOffset;
402
402
 
403
- this._resetZIndex();
403
+ this._updateRise();
404
404
  }
405
405
 
406
406
  _positionElements(pos) {
@@ -428,7 +428,7 @@ export class Marker extends Layer {
428
428
 
429
429
  _animateZoom(opt) {
430
430
  if (this._culled) { return; }
431
- const pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center)._round();
431
+ const pos = this._map._snapLayerPoint(this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center));
432
432
 
433
433
  this._setPos(pos);
434
434
  }
@@ -463,40 +463,38 @@ export class Marker extends Layer {
463
463
 
464
464
  this.addInteractiveTarget(this._icon);
465
465
 
466
- if (MarkerDrag) {
467
- // When the icon element is reused, the drag handler still refers to it. Keep that handler, because
468
- // replacing it ends a drag in progress and forgets that the marker has just been dragged.
469
- if (this.dragging?._draggable?._element === this._icon) {
470
- // the icon has reset the class names of the element
471
- this._icon.classList.toggle('maplair-marker-draggable', this.dragging.enabled());
472
- return;
473
- }
466
+ // When the icon element is reused, the drag handler still refers to it. Keep that handler, because
467
+ // replacing it ends a drag in progress and forgets that the marker has just been dragged.
468
+ if (this.dragging?._draggable?._element === this._icon) {
469
+ // the icon has reset the class names of the element
470
+ this._icon.classList.toggle('maplair-marker-draggable', this.dragging.enabled());
471
+ return;
472
+ }
474
473
 
475
- let draggable = this.options.draggable;
476
- if (this.dragging) {
477
- draggable = this.dragging.enabled();
478
- this.dragging.disable();
479
- }
474
+ let draggable = this.options.draggable;
475
+ if (this.dragging) {
476
+ draggable = this.dragging.enabled();
477
+ this.dragging.disable();
478
+ }
480
479
 
481
- /**
482
- * Marker dragging handler, see `Handler`. Only valid when the marker is on the
483
- * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
484
- *
485
- * Interaction handlers are properties of a marker instance that allow you to
486
- * control interaction behavior in runtime, enabling or disabling certain
487
- * features such as dragging (see `Handler` methods). Example:
488
- *
489
- * ```js
490
- * marker.dragging.disable();
491
- * ```
492
- * @group Interaction handlers
493
- * @type {MarkerDrag}
494
- */
495
- this.dragging = new MarkerDrag(this);
496
-
497
- if (draggable) {
498
- this.dragging.enable();
499
- }
480
+ /**
481
+ * Marker dragging handler, see `Handler`. Only valid when the marker is on the
482
+ * map (otherwise set [`marker.options.draggable`](#markeroptions-draggable)).
483
+ *
484
+ * Interaction handlers are properties of a marker instance that allow you to
485
+ * control interaction behavior in runtime, enabling or disabling certain
486
+ * features such as dragging (see `Handler` methods). Example:
487
+ *
488
+ * ```js
489
+ * marker.dragging.disable();
490
+ * ```
491
+ * @group Interaction handlers
492
+ * @type {MarkerDrag}
493
+ */
494
+ this.dragging = new MarkerDrag(this);
495
+
496
+ if (draggable) {
497
+ this.dragging.enable();
500
498
  }
501
499
  }
502
500
 
@@ -539,14 +537,23 @@ export class Marker extends Layer {
539
537
  }
540
538
 
541
539
  _updateOpacity() {
542
- const opacity = this.options.opacity;
543
-
544
- if (this._icon) {
545
- this._icon.style.opacity = `${opacity}`;
540
+ for (const el of [this._icon, this._shadow]) {
541
+ if (el) {
542
+ el.style.opacity = `${this.options.opacity}`;
543
+ }
546
544
  }
545
+ }
547
546
 
548
- if (this._shadow) {
549
- this._shadow.style.opacity = `${opacity}`;
547
+ _updateRise(e) {
548
+ if (e?.type.startsWith('pointer')) {
549
+ this._hovered = e.type === 'pointerover';
550
+ } else if (e) {
551
+ this._focused = e.type === 'focusin';
552
+ }
553
+ if (this._hovered || this._focused) {
554
+ this._bringToFront();
555
+ } else {
556
+ this._resetZIndex();
550
557
  }
551
558
  }
552
559
 
@@ -588,8 +595,8 @@ export class Marker extends Layer {
588
595
  return this._rotateAnchor(this.options.icon.options.popupAnchor);
589
596
  }
590
597
 
591
- _getTooltipAnchor() {
592
- return this._rotateAnchor(this.options.icon.options.tooltipAnchor);
598
+ _getTooltipAnchor(direction) {
599
+ return this._rotateAnchor(this.options.icon._getTooltipAnchor(direction));
593
600
  }
594
601
 
595
602
  // anchors are offsets from the icon anchor, which is also the rotation origin
@@ -18,7 +18,7 @@ function svgElement(name, attributes, parent) {
18
18
  for (const [key, value] of Object.entries(attributes)) {
19
19
  el.setAttribute(key, value);
20
20
  }
21
- parent?.appendChild(el);
21
+ parent?.append(el);
22
22
  return el;
23
23
  }
24
24
 
@@ -65,10 +65,10 @@ import {LatLngBounds} from '../../geo/LatLngBounds.js';
65
65
  */
66
66
 
67
67
  /**
68
- * Generic class for handling a tiled grid of HTML elements. This is the base class for
69
- * all tile layers and replaces `TileLayer.Canvas`. GridLayer can be extended to create
70
- * a tiled grid of HTML elements like `<canvas>`, `<img>` or `<div>`. GridLayer will
71
- * handle creating and animating these DOM elements for you.
68
+ * Generic class for handling a tiled grid of HTML elements, and the base class of all
69
+ * tile layers. To show map tiles from a URL, use `TileLayer` (or `WMSTileLayer`).
70
+ * Extend `GridLayer` to create a tiled grid of your own elements like `<canvas>`,
71
+ * `<img>` or `<div>`; it handles creating and animating them for you.
72
72
  *
73
73
  * Layers extending `GridLayer` shall reimplement the [`createTile()`](#gridlayer-createtile)
74
74
  * method.
@@ -280,7 +280,7 @@ export class GridLayer extends Layer {
280
280
  redraw() {
281
281
  if (this._map) {
282
282
  this._removeAllTiles();
283
- const tileZoom = this._clampZoom(Math.round(this._map.getZoom()));
283
+ const tileZoom = this._getTileZoom(this._map.getZoom());
284
284
  if (tileZoom !== this._tileZoom) {
285
285
  this._tileZoom = tileZoom;
286
286
  this._updateLevels();
@@ -343,7 +343,7 @@ export class GridLayer extends Layer {
343
343
  }
344
344
 
345
345
  _updateZIndex() {
346
- if (this._container && this.options.zIndex !== undefined && this.options.zIndex !== null) {
346
+ if (this._container && this.options.zIndex != null) {
347
347
  this._container.style.zIndex = `${this.options.zIndex}`;
348
348
  }
349
349
  }
@@ -379,7 +379,7 @@ export class GridLayer extends Layer {
379
379
  _initContainer() {
380
380
  if (this._container) { return; }
381
381
 
382
- this._container = DomUtil.create('div', `maplair-layer ${this.options.className ?? ''}`);
382
+ this._container = DomUtil.create('div', `maplair-layer maplair-zoom-animated ${this.options.className ?? ''}`);
383
383
  this._container.classList.toggle('maplair-pixelated', !!this.options.pixelated);
384
384
  this._updateZIndex();
385
385
 
@@ -387,7 +387,7 @@ export class GridLayer extends Layer {
387
387
  this._updateOpacity();
388
388
  }
389
389
 
390
- this.getPane().appendChild(this._container);
390
+ this.getPane().append(this._container);
391
391
  }
392
392
 
393
393
  // Keeps the loaded tiles of the current level visible below the tiles loaded
@@ -476,9 +476,6 @@ export class GridLayer extends Layer {
476
476
 
477
477
  this._setZoomTransform(level, map.getCenter(), map.getZoom());
478
478
 
479
- // force reading offsetWidth so the browser considers the newly added element for transition
480
- Util.falseFn(level.el.offsetWidth);
481
-
482
479
  this._onCreateLevel(level);
483
480
  }
484
481
 
@@ -498,9 +495,7 @@ export class GridLayer extends Layer {
498
495
  return;
499
496
  }
500
497
 
501
- const zoom = this._map.getZoom();
502
- if (zoom > this.options.maxZoom ||
503
- zoom < this.options.minZoom) {
498
+ if (this._getTileZoom(this._map.getZoom()) === undefined) {
504
499
  this._removeAllTiles();
505
500
  return;
506
501
  }
@@ -587,7 +582,23 @@ export class GridLayer extends Layer {
587
582
  }
588
583
 
589
584
  _animateZoom(e) {
585
+ const map = this._map, center = map.getCenter(), zoom = map.getZoom(), scale = map.getZoomScale(e.zoom, zoom);
586
+
590
587
  this._setView(e.center, e.zoom, true, e.noUpdate);
588
+
589
+ // the levels stay put and the container zooms as a whole, since a level created just now would only
590
+ // transition after a forced style recalc, which covers every pending style change on the page
591
+ this._setZoomTransforms(center, zoom);
592
+ DomUtil.setTransform(this._container, map._getNewPixelOrigin(center, zoom).multiplyBy(scale)
593
+ .subtract(map._getNewPixelOrigin(e.center, e.zoom)), scale);
594
+ }
595
+
596
+ // The zoom of the tiles for the map zoom `zoom`, or undefined outside of the
597
+ // `minZoom` and `maxZoom` of the layer, also between levels.
598
+ _getTileZoom(zoom) {
599
+ const {minZoom, maxZoom = Infinity} = this.options;
600
+ if (zoom < minZoom || zoom > maxZoom) { return undefined; }
601
+ return this._clampZoom(Math.round(zoom));
591
602
  }
592
603
 
593
604
  _clampZoom(zoom) {
@@ -605,13 +616,7 @@ export class GridLayer extends Layer {
605
616
  }
606
617
 
607
618
  _setView(center, zoom, noPrune, noUpdate) {
608
- let tileZoom = Math.round(zoom);
609
- if ((this.options.maxZoom !== undefined && tileZoom > this.options.maxZoom) ||
610
- (this.options.minZoom !== undefined && tileZoom < this.options.minZoom)) {
611
- tileZoom = undefined;
612
- } else {
613
- tileZoom = this._clampZoom(tileZoom);
614
- }
619
+ const tileZoom = this._getTileZoom(zoom);
615
620
 
616
621
  const tileZoomChanged = this.options.updateWhenZooming && (tileZoom !== this._tileZoom);
617
622
 
@@ -619,9 +624,7 @@ export class GridLayer extends Layer {
619
624
 
620
625
  this._tileZoom = tileZoom;
621
626
 
622
- if (this._abortLoading) {
623
- this._abortLoading();
624
- }
627
+ this._abortLoading?.();
625
628
 
626
629
  this._updateLevels();
627
630
  this._resetGrid();
@@ -643,6 +646,7 @@ export class GridLayer extends Layer {
643
646
  }
644
647
 
645
648
  _setZoomTransforms(center, zoom) {
649
+ if (this._container.style.transform) { this._container.style.transform = ''; }
646
650
  for (const level of Object.values(this._levels)) {
647
651
  this._setZoomTransform(level, center, zoom);
648
652
  }
@@ -650,8 +654,11 @@ export class GridLayer extends Layer {
650
654
 
651
655
  _setZoomTransform(level, center, zoom) {
652
656
  const scale = this._map.getZoomScale(zoom, level.zoom),
653
- translate = level.origin.multiplyBy(scale)
654
- .subtract(this._map._getNewPixelOrigin(center, zoom)).round();
657
+ translate = level.origin.multiplyBy(scale).subtract(this._map._getNewPixelOrigin(center, zoom));
658
+
659
+ // a scaled level is resampled anyway, and rounding where its origin lands would make its tiles away from the
660
+ // origin jitter against the zoom motion
661
+ if (scale === 1) { this._map._snapLayerPoint(translate); }
655
662
 
656
663
  DomUtil.setTransform(level.el, translate, scale);
657
664
  }
@@ -678,7 +685,11 @@ export class GridLayer extends Layer {
678
685
  }
679
686
 
680
687
  _onMoveEnd() {
681
- if (!this._map || this._map._animatingZoom) { return; }
688
+ const map = this._map;
689
+ if (!map || map._animatingZoom) { return; }
690
+
691
+ // a zoom animation that ends at the same zoom (e.g. a pinch snapping back) fires no zoom event
692
+ if (this._container.style.transform) { this._setZoomTransforms(map.getCenter(), map.getZoom()); }
682
693
 
683
694
  this._update();
684
695
  }
@@ -769,7 +780,7 @@ export class GridLayer extends Layer {
769
780
  // sort tile queue to load tiles in order of their distance to center
770
781
  queue.sort((a, b) => a.distanceTo(tileCenter) - b.distanceTo(tileCenter));
771
782
 
772
- if (queue.length !== 0) {
783
+ if (queue.length) {
773
784
  // if it's the first batch of tiles to load
774
785
  if (!this._loading) {
775
786
  this._loading = true;
@@ -784,7 +795,7 @@ export class GridLayer extends Layer {
784
795
  this._addTile(q, fragment);
785
796
  }
786
797
 
787
- this._level.el.appendChild(fragment);
798
+ this._level.el.append(fragment);
788
799
  }
789
800
  }
790
801
 
@@ -882,7 +893,7 @@ export class GridLayer extends Layer {
882
893
  current: true
883
894
  };
884
895
 
885
- container.appendChild(tile);
896
+ container.append(tile);
886
897
  this.fire('tileloadstart', {
887
898
  tile,
888
899
  coords