maplair 4.0.0 → 4.1.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 (270) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/dist/esm/Maplair.js +14 -14
  3. package/dist/esm/control/AttributionControl.js +24 -14
  4. package/dist/esm/control/AttributionControl.js.map +1 -1
  5. package/dist/esm/control/ButtonControl.js +9 -11
  6. package/dist/esm/control/ButtonControl.js.map +1 -1
  7. package/dist/esm/control/ContextMenu.js +1 -3
  8. package/dist/esm/control/ContextMenu.js.map +1 -1
  9. package/dist/esm/control/Control.js +9 -16
  10. package/dist/esm/control/Control.js.map +1 -1
  11. package/dist/esm/control/FullscreenControl.js +5 -7
  12. package/dist/esm/control/FullscreenControl.js.map +1 -1
  13. package/dist/esm/control/LayersControl.js +144 -35
  14. package/dist/esm/control/LayersControl.js.map +1 -1
  15. package/dist/esm/control/LegendControl.js +7 -9
  16. package/dist/esm/control/LegendControl.js.map +1 -1
  17. package/dist/esm/control/MiniMapControl.js +14 -16
  18. package/dist/esm/control/MiniMapControl.js.map +1 -1
  19. package/dist/esm/control/RotateControl.js +1 -3
  20. package/dist/esm/control/RotateControl.js.map +1 -1
  21. package/dist/esm/control/ScaleControl.js +7 -9
  22. package/dist/esm/control/ScaleControl.js.map +1 -1
  23. package/dist/esm/control/SearchControl.js +99 -17
  24. package/dist/esm/control/SearchControl.js.map +1 -1
  25. package/dist/esm/control/SideBySideControl.js +1 -3
  26. package/dist/esm/control/SideBySideControl.js.map +1 -1
  27. package/dist/esm/control/TextControl.js +5 -7
  28. package/dist/esm/control/TextControl.js.map +1 -1
  29. package/dist/esm/control/TimeControl.js +408 -0
  30. package/dist/esm/control/TimeControl.js.map +1 -0
  31. package/dist/esm/control/ZoomControl.js +5 -7
  32. package/dist/esm/control/ZoomControl.js.map +1 -1
  33. package/dist/esm/core/Class.js +28 -37
  34. package/dist/esm/core/Class.js.map +1 -1
  35. package/dist/esm/core/Events.js +21 -8
  36. package/dist/esm/core/Events.js.map +1 -1
  37. package/dist/esm/core/Handler.js +13 -11
  38. package/dist/esm/core/Handler.js.map +1 -1
  39. package/dist/esm/core/Util.js +13 -1
  40. package/dist/esm/core/Util.js.map +1 -1
  41. package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
  42. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  43. package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
  44. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  45. package/dist/esm/dom/DomEvent.js +8 -42
  46. package/dist/esm/dom/DomEvent.js.map +1 -1
  47. package/dist/esm/dom/DomUtil.js +14 -68
  48. package/dist/esm/dom/DomUtil.js.map +1 -1
  49. package/dist/esm/dom/Draggable.js +17 -18
  50. package/dist/esm/dom/Draggable.js.map +1 -1
  51. package/dist/esm/dom/PosAnimation.js +3 -25
  52. package/dist/esm/dom/PosAnimation.js.map +1 -1
  53. package/dist/esm/geo/LatLng.js +15 -5
  54. package/dist/esm/geo/LatLng.js.map +1 -1
  55. package/dist/esm/geo/crs/EPSG3395.js +1 -1
  56. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  57. package/dist/esm/geo/crs/EPSG3857.js +1 -1
  58. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  59. package/dist/esm/geo/crs/EPSG4326.js +1 -1
  60. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  61. package/dist/esm/geo/crs/EarthCRS.js +2 -2
  62. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  63. package/dist/esm/geo/crs/SimpleCRS.js +1 -1
  64. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  65. package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
  66. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
  67. package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
  68. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
  69. package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
  70. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
  71. package/dist/esm/geometry/LineUtil.js +36 -30
  72. package/dist/esm/geometry/LineUtil.js.map +1 -1
  73. package/dist/esm/geometry/PolyUtil.js +8 -27
  74. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  75. package/dist/esm/layer/BlanketOverlay.js +6 -8
  76. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  77. package/dist/esm/layer/DivOverlay.js +15 -20
  78. package/dist/esm/layer/DivOverlay.js.map +1 -1
  79. package/dist/esm/layer/GeoJSON.js +9 -145
  80. package/dist/esm/layer/GeoJSON.js.map +1 -1
  81. package/dist/esm/layer/GeoJSONUtil.js +75 -0
  82. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  83. package/dist/esm/layer/HeatLayer.js +15 -17
  84. package/dist/esm/layer/HeatLayer.js.map +1 -1
  85. package/dist/esm/layer/ImageOverlay.js +20 -26
  86. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  87. package/dist/esm/layer/Layer.js +8 -10
  88. package/dist/esm/layer/Layer.js.map +1 -1
  89. package/dist/esm/layer/LayerGroup.js +51 -0
  90. package/dist/esm/layer/LayerGroup.js.map +1 -1
  91. package/dist/esm/layer/Popup.js +26 -42
  92. package/dist/esm/layer/Popup.js.map +1 -1
  93. package/dist/esm/layer/SVGOverlay.js +2 -5
  94. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  95. package/dist/esm/layer/Tooltip.js +15 -17
  96. package/dist/esm/layer/Tooltip.js.map +1 -1
  97. package/dist/esm/layer/VideoOverlay.js +12 -15
  98. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  99. package/dist/esm/layer/marker/DefaultIcon.js +15 -48
  100. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  101. package/dist/esm/layer/marker/DivIcon.js +7 -9
  102. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  103. package/dist/esm/layer/marker/Icon.js +7 -10
  104. package/dist/esm/layer/marker/Icon.js.map +1 -1
  105. package/dist/esm/layer/marker/Marker.Drag.js +1 -1
  106. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  107. package/dist/esm/layer/marker/Marker.Move.js +1 -2
  108. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  109. package/dist/esm/layer/marker/Marker.js +61 -33
  110. package/dist/esm/layer/marker/Marker.js.map +1 -1
  111. package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
  112. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  113. package/dist/esm/layer/marker/SvgIcon.js +6 -8
  114. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  115. package/dist/esm/layer/tile/GridLayer.js +85 -97
  116. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  117. package/dist/esm/layer/tile/TileLayer.js +28 -36
  118. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  119. package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
  120. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  121. package/dist/esm/layer/vector/Canvas.js +1 -3
  122. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  123. package/dist/esm/layer/vector/Circle.js +2 -2
  124. package/dist/esm/layer/vector/Circle.js.map +1 -1
  125. package/dist/esm/layer/vector/CircleMarker.js +17 -7
  126. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  127. package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
  128. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  129. package/dist/esm/layer/vector/Path.js +27 -20
  130. package/dist/esm/layer/vector/Path.js.map +1 -1
  131. package/dist/esm/layer/vector/Polygon.js +20 -4
  132. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  133. package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
  134. package/dist/esm/layer/vector/Polyline.js +23 -7
  135. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  136. package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
  137. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  138. package/dist/esm/layer/vector/SVG.js +5 -5
  139. package/dist/esm/layer/vector/SVG.js.map +1 -1
  140. package/dist/esm/map/Map.Rotation.js +10 -6
  141. package/dist/esm/map/Map.Rotation.js.map +1 -1
  142. package/dist/esm/map/Map.js +116 -110
  143. package/dist/esm/map/Map.js.map +1 -1
  144. package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
  145. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  146. package/dist/esm/map/handler/DisplaceHandler.js +6 -8
  147. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  148. package/dist/esm/map/handler/DragHandler.js +19 -19
  149. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  150. package/dist/esm/map/handler/KeyboardHandler.js +35 -35
  151. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  152. package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
  153. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  154. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
  155. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  156. package/dist/esm/map/handler/TapHoldHandler.js +12 -5
  157. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  158. package/dist/esm/package.js +1 -1
  159. package/dist/maplair-global-src.js +8009 -7369
  160. package/dist/maplair-global-src.js.map +1 -1
  161. package/dist/maplair-global.js +2 -2
  162. package/dist/maplair-global.js.map +1 -1
  163. package/dist/maplair-src.js +10040 -9381
  164. package/dist/maplair-src.js.map +1 -1
  165. package/dist/maplair.css +148 -98
  166. package/dist/maplair.js +2 -2
  167. package/dist/maplair.js.map +1 -1
  168. package/i18n/cs.json +6 -0
  169. package/i18n/de.json +6 -0
  170. package/i18n/en.json +6 -0
  171. package/i18n/es.json +6 -0
  172. package/i18n/fr.json +6 -0
  173. package/i18n/hu.json +6 -0
  174. package/i18n/it.json +6 -0
  175. package/i18n/rm.json +6 -0
  176. package/i18n/sk.json +6 -0
  177. package/i18n/sl.json +6 -0
  178. package/package.json +9 -11
  179. package/src/control/AttributionControl.js +25 -18
  180. package/src/control/ButtonControl.js +9 -11
  181. package/src/control/ContextMenu.js +3 -5
  182. package/src/control/Control.js +9 -19
  183. package/src/control/FullscreenControl.js +5 -7
  184. package/src/control/LayersControl.js +159 -36
  185. package/src/control/LegendControl.js +7 -9
  186. package/src/control/MiniMapControl.js +9 -11
  187. package/src/control/RotateControl.js +3 -5
  188. package/src/control/ScaleControl.js +7 -9
  189. package/src/control/SearchControl.js +102 -19
  190. package/src/control/SideBySideControl.js +3 -5
  191. package/src/control/TextControl.js +5 -7
  192. package/src/control/TimeControl.js +471 -0
  193. package/src/control/ZoomControl.js +5 -7
  194. package/src/control/index.js +1 -0
  195. package/src/core/Class.js +35 -34
  196. package/src/core/Events.js +22 -3
  197. package/src/core/Handler.js +14 -12
  198. package/src/core/Util.js +19 -1
  199. package/src/core/index.js +0 -1
  200. package/src/dom/DomEvent.DoubleTap.js +18 -10
  201. package/src/dom/DomEvent.PointerEvents.js +3 -26
  202. package/src/dom/DomEvent.js +8 -66
  203. package/src/dom/DomUtil.js +22 -78
  204. package/src/dom/Draggable.js +27 -22
  205. package/src/dom/PosAnimation.js +3 -25
  206. package/src/dom/index.js +0 -1
  207. package/src/geo/LatLng.js +20 -3
  208. package/src/geo/crs/EPSG3395.js +1 -1
  209. package/src/geo/crs/EPSG3857.js +1 -1
  210. package/src/geo/crs/EPSG4326.js +1 -1
  211. package/src/geo/crs/EarthCRS.js +2 -8
  212. package/src/geo/crs/SimpleCRS.js +1 -1
  213. package/src/geo/projection/Projection.LonLat.js +1 -1
  214. package/src/geo/projection/Projection.Mercator.js +1 -1
  215. package/src/geo/projection/Projection.SphericalMercator.js +1 -1
  216. package/src/geometry/LineUtil.js +47 -48
  217. package/src/geometry/PolyUtil.js +14 -43
  218. package/src/layer/BlanketOverlay.js +6 -10
  219. package/src/layer/DivOverlay.js +15 -26
  220. package/src/layer/GeoJSON.js +7 -205
  221. package/src/layer/GeoJSONUtil.js +85 -0
  222. package/src/layer/HeatLayer.js +9 -11
  223. package/src/layer/ImageOverlay.js +19 -30
  224. package/src/layer/Layer.js +8 -10
  225. package/src/layer/LayerGroup.js +71 -0
  226. package/src/layer/Popup.js +28 -43
  227. package/src/layer/SVGOverlay.js +1 -5
  228. package/src/layer/Tooltip.js +15 -19
  229. package/src/layer/VideoOverlay.js +12 -15
  230. package/src/layer/marker/DefaultIcon.js +15 -61
  231. package/src/layer/marker/DivIcon.js +9 -11
  232. package/src/layer/marker/Icon.js +7 -10
  233. package/src/layer/marker/Marker.Drag.js +1 -1
  234. package/src/layer/marker/Marker.Move.js +1 -2
  235. package/src/layer/marker/Marker.js +81 -39
  236. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  237. package/src/layer/marker/SvgIcon.js +7 -9
  238. package/src/layer/marker/index.js +1 -0
  239. package/src/layer/tile/GridLayer.js +103 -133
  240. package/src/layer/tile/TileLayer.js +35 -43
  241. package/src/layer/tile/WMSTileLayer.js +26 -24
  242. package/src/layer/vector/Canvas.js +3 -5
  243. package/src/layer/vector/Circle.js +5 -2
  244. package/src/layer/vector/CircleMarker.js +17 -6
  245. package/src/layer/vector/Path.DashAnimation.js +1 -2
  246. package/src/layer/vector/Path.js +30 -21
  247. package/src/layer/vector/Polygon.js +28 -5
  248. package/src/layer/vector/Polyline.js +25 -6
  249. package/src/layer/vector/Renderer.getRenderer.js +17 -17
  250. package/src/layer/vector/SVG.js +5 -5
  251. package/src/map/Map.Rotation.js +12 -4
  252. package/src/map/Map.js +142 -133
  253. package/src/map/handler/BoxZoomHandler.js +9 -8
  254. package/src/map/handler/DisplaceHandler.js +6 -8
  255. package/src/map/handler/DragHandler.js +25 -28
  256. package/src/map/handler/KeyboardHandler.js +42 -48
  257. package/src/map/handler/PinchZoomHandler.js +16 -5
  258. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  259. package/src/map/handler/TapHoldHandler.js +15 -4
  260. package/src/map/index.js +1 -1
  261. package/src/maplair.css +148 -98
  262. package/dist/esm/core/Browser.js +0 -100
  263. package/dist/esm/core/Browser.js.map +0 -1
  264. package/dist/images/layers.svg +0 -1
  265. package/dist/images/marker-icon.svg +0 -1
  266. package/dist/images/marker-shadow.svg +0 -1
  267. package/src/core/Browser.js +0 -110
  268. package/src/images/layers.svg +0 -1
  269. package/src/images/marker-icon.svg +0 -1
  270. package/src/images/marker-shadow.svg +0 -1
@@ -1,5 +1,4 @@
1
1
  import {Layer} from '../Layer.js';
2
- import Browser from '../../core/Browser.js';
3
2
  import * as Util from '../../core/Util.js';
4
3
  import * as DomUtil from '../../dom/DomUtil.js';
5
4
  import {Point} from '../../geometry/Point.js';
@@ -22,16 +21,13 @@ import {LatLngBounds} from '../../geo/LatLngBounds.js';
22
21
  * of tiles while they are loading, e.g. `'#ddd'` or
23
22
  * `'url(loading.svg) center no-repeat #eee'`. Tiles with a placeholder appear without
24
23
  * fading in.
25
- * @property {boolean} [updateWhenIdle] Load new tiles only when panning ends. Defaults
26
- * to `false` (tiles are loaded _during_ panning) unless the browser is configured for
27
- * reduced motion.
24
+ * @property {boolean} [updateWhenIdle=false] Load new tiles only when panning ends.
28
25
  * @property {boolean} [updateWhenZooming=true] By default, a smooth zoom animation
29
26
  * (during a [pinch zoom](#map-pinchzoom) or a [`flyTo()`](#map-flyto)) will update grid
30
27
  * layers every integer zoom level. Setting this option to `false` will update the grid
31
28
  * layer only when the smooth animation ends.
32
- * @property {number} [updateInterval] Tiles will not update more than once every
33
- * `updateInterval` milliseconds when panning. Defaults to `200`, increased to five
34
- * seconds if the browser is configured for reduced motion.
29
+ * @property {number} [updateInterval=200] Tiles will not update more than once every
30
+ * `updateInterval` milliseconds when panning.
35
31
  * @property {number} [zIndex=1] The explicit zIndex of the tile layer.
36
32
  * @property {LatLngBoundsExpression|null} [bounds=null] If set, tiles will only be
37
33
  * loaded inside the set `LatLngBounds`.
@@ -144,27 +140,25 @@ import {LatLngBounds} from '../../geo/LatLngBounds.js';
144
140
  */
145
141
  export class GridLayer extends Layer {
146
142
 
147
- static {
148
- this.setDefaultOptions({
149
- tileSize: 256,
150
- opacity: 1,
151
- placeholder: null,
152
- updateWhenIdle: !Browser.reducedMotion,
153
- updateWhenZooming: true,
154
- updateInterval: Browser.reducedMotion ? 5000 : 200,
155
- zIndex: 1,
156
- bounds: null,
157
- minZoom: 0,
158
- maxZoom: undefined,
159
- maxNativeZoom: undefined,
160
- minNativeZoom: undefined,
161
- noWrap: false,
162
- pane: 'tilePane',
163
- className: '',
164
- pixelated: false,
165
- keepBuffer: 2
166
- });
167
- }
143
+ static defaultOptions = {
144
+ tileSize: 256,
145
+ opacity: 1,
146
+ placeholder: null,
147
+ updateWhenIdle: false,
148
+ updateWhenZooming: true,
149
+ updateInterval: 200,
150
+ zIndex: 1,
151
+ bounds: null,
152
+ minZoom: 0,
153
+ maxZoom: undefined,
154
+ maxNativeZoom: undefined,
155
+ minNativeZoom: undefined,
156
+ noWrap: false,
157
+ pane: 'tilePane',
158
+ className: '',
159
+ pixelated: false,
160
+ keepBuffer: 2
161
+ };
168
162
 
169
163
  /**
170
164
  * Creates a new instance of GridLayer with the supplied options.
@@ -212,6 +206,8 @@ export class GridLayer extends Layer {
212
206
  this._container = null;
213
207
  this._tileZoom = undefined;
214
208
  clearTimeout(this._pruneTimeout);
209
+ cancelAnimationFrame(this._fadePruneFrame);
210
+ this._fadePruneFrame = 0;
215
211
  }
216
212
 
217
213
  /**
@@ -284,7 +280,7 @@ export class GridLayer extends Layer {
284
280
  redraw() {
285
281
  if (this._map) {
286
282
  this._removeAllTiles();
287
- const tileZoom = this._clampZoom(this._map.getZoom());
283
+ const tileZoom = this._clampZoom(Math.round(this._map.getZoom()));
288
284
  if (tileZoom !== this._tileZoom) {
289
285
  this._tileZoom = tileZoom;
290
286
  this._updateLevels();
@@ -303,7 +299,9 @@ export class GridLayer extends Layer {
303
299
  viewprereset: this._invalidateAll,
304
300
  viewreset: this._resetView,
305
301
  zoom: this._resetView,
306
- moveend: this._onMoveEnd
302
+ moveend: this._onMoveEnd,
303
+ worldcopyjump: this._onWorldCopyJump,
304
+ zoomanim: this._animateZoom
307
305
  };
308
306
 
309
307
  if (!this.options.updateWhenIdle) {
@@ -315,10 +313,6 @@ export class GridLayer extends Layer {
315
313
  events.move = this._onMove;
316
314
  }
317
315
 
318
- if (this._zoomAnimated) {
319
- events.zoomanim = this._animateZoom;
320
- }
321
-
322
316
  return events;
323
317
  }
324
318
 
@@ -350,7 +344,7 @@ export class GridLayer extends Layer {
350
344
 
351
345
  _updateZIndex() {
352
346
  if (this._container && this.options.zIndex !== undefined && this.options.zIndex !== null) {
353
- this._container.style.zIndex = this.options.zIndex;
347
+ this._container.style.zIndex = `${this.options.zIndex}`;
354
348
  }
355
349
  }
356
350
 
@@ -377,36 +371,7 @@ export class GridLayer extends Layer {
377
371
  _updateOpacity() {
378
372
  if (!this._map) { return; }
379
373
 
380
- this._container.style.opacity = this.options.opacity;
381
-
382
- const now = Date.now();
383
- let nextFrame = false,
384
- willPrune = false;
385
-
386
- for (const tile of Object.values(this._tiles ?? {})) {
387
- if (!tile.current || !tile.loaded) { continue; }
388
-
389
- const fade = tile.noFade ? 1 : Math.min(1, (now - tile.loaded) / 200);
390
-
391
- tile.el.style.opacity = fade;
392
- if (fade < 1) {
393
- nextFrame = true;
394
- } else {
395
- if (tile.active) {
396
- willPrune = true;
397
- } else {
398
- this._onOpaqueTile(tile);
399
- }
400
- tile.active = true;
401
- }
402
- }
403
-
404
- if (willPrune && !this._noPrune) { this._pruneTiles(); }
405
-
406
- if (nextFrame) {
407
- cancelAnimationFrame(this._fadeFrame);
408
- this._fadeFrame = requestAnimationFrame(this._updateOpacity.bind(this));
409
- }
374
+ this._container.style.opacity = `${this.options.opacity}`;
410
375
  }
411
376
 
412
377
  _onOpaqueTile() {}
@@ -487,7 +452,7 @@ export class GridLayer extends Layer {
487
452
  for (let z of Object.keys(this._levels)) {
488
453
  z = Number(z);
489
454
  if (this._levels[z].el.children.length || z === zoom) {
490
- this._levels[z].el.style.zIndex = maxZoom - Math.abs(zoom - z);
455
+ this._levels[z].el.style.zIndex = `${maxZoom - Math.abs(zoom - z)}`;
491
456
  this._onUpdateLevel(z);
492
457
  } else {
493
458
  this._levels[z].el.remove();
@@ -504,7 +469,7 @@ export class GridLayer extends Layer {
504
469
  level = this._levels[zoom] = {};
505
470
 
506
471
  level.el = DomUtil.create('div', 'maplair-tile-container maplair-zoom-animated', this._container);
507
- level.el.style.zIndex = maxZoom;
472
+ level.el.style.zIndex = `${maxZoom}`;
508
473
 
509
474
  level.origin = map.project(map.unproject(map.getPixelOrigin()), zoom).round();
510
475
  level.zoom = zoom;
@@ -574,7 +539,12 @@ export class GridLayer extends Layer {
574
539
  }
575
540
  }
576
541
 
577
- _invalidateAll() {
542
+ _invalidateAll(e) {
543
+ // a zoom without animation keeps the old levels until new tiles load, like the end of an animated one,
544
+ // unless the view jumps somewhere else
545
+ const map = this._map;
546
+ if (e?.zoom !== undefined && e.zoom !== map.getZoom() && map.getBounds().contains(e.center)) { return; }
547
+
578
548
  for (const z of Object.keys(this._levels)) {
579
549
  this._levels[z].el.remove();
580
550
  this._onRemoveLevel(Number(z));
@@ -586,56 +556,31 @@ export class GridLayer extends Layer {
586
556
  }
587
557
 
588
558
  _retainParent(x, y, z, minZoom) {
589
- const x2 = Math.floor(x / 2),
590
- y2 = Math.floor(y / 2),
591
- z2 = z - 1,
592
- coords2 = new Point(+x2, +y2);
593
- coords2.z = +z2;
594
-
595
- const key = this._tileCoordsToKey(coords2),
596
- tile = this._tiles[key];
597
-
598
- if (tile?.active) {
599
- tile.retain = true;
600
- return true;
601
-
602
- } else if (tile?.loaded) {
603
- tile.retain = true;
604
- }
605
-
606
- if (z2 > minZoom) {
607
- return this._retainParent(x2, y2, z2, minZoom);
559
+ for (z--; z >= minZoom; z--) {
560
+ x = Math.floor(x / 2);
561
+ y = Math.floor(y / 2);
562
+ if (this._retain(x, y, z)) { return true; }
608
563
  }
609
-
610
564
  return false;
611
565
  }
612
566
 
613
567
  _retainChildren(x, y, z, maxZoom) {
614
-
615
568
  for (let i = 2 * x; i < 2 * x + 2; i++) {
616
569
  for (let j = 2 * y; j < 2 * y + 2; j++) {
617
-
618
- const coords = new Point(i, j);
619
- coords.z = z + 1;
620
-
621
- const key = this._tileCoordsToKey(coords),
622
- tile = this._tiles[key];
623
-
624
- if (tile?.active) {
625
- tile.retain = true;
626
- continue;
627
-
628
- } else if (tile?.loaded) {
629
- tile.retain = true;
630
- }
631
-
632
- if (z + 1 < maxZoom) {
570
+ if (!this._retain(i, j, z + 1) && z + 1 < maxZoom) {
633
571
  this._retainChildren(i, j, z + 1, maxZoom);
634
572
  }
635
573
  }
636
574
  }
637
575
  }
638
576
 
577
+ // retains the tile if it's loaded; returns true if it's active, so there's no need to look further
578
+ _retain(x, y, z) {
579
+ const tile = this._tiles[this._tileCoordsToKey({x, y, z})];
580
+ if (tile?.loaded) { tile.retain = true; }
581
+ return tile?.active;
582
+ }
583
+
639
584
  _resetView(e) {
640
585
  const animating = e && (e.pinch || e.flyTo || e.continuous);
641
586
  this._setView(this._map.getCenter(), this._map.getZoom(), animating, animating);
@@ -689,7 +634,7 @@ export class GridLayer extends Layer {
689
634
  this._pruneTiles();
690
635
  }
691
636
 
692
- // Flag to prevent _updateOpacity from pruning tiles during
637
+ // Flag to prevent finished tile fades from pruning tiles during
693
638
  // a zoom anim or a pinch gesture
694
639
  this._noPrune = !!noPrune;
695
640
  }
@@ -724,10 +669,10 @@ export class GridLayer extends Layer {
724
669
 
725
670
  this._wrapX = crs.wrapLng && !this.options.noWrap && [
726
671
  Math.floor(map.project([0, crs.wrapLng[0]], tileZoom).x / tileSize.x),
727
- Math.ceil(map.project([0, crs.wrapLng[1]], tileZoom).x / tileSize.y)
672
+ Math.ceil(map.project([0, crs.wrapLng[1]], tileZoom).x / tileSize.x)
728
673
  ];
729
674
  this._wrapY = crs.wrapLat && !this.options.noWrap && [
730
- Math.floor(map.project([crs.wrapLat[0], 0], tileZoom).y / tileSize.x),
675
+ Math.floor(map.project([crs.wrapLat[0], 0], tileZoom).y / tileSize.y),
731
676
  Math.ceil(map.project([crs.wrapLat[1], 0], tileZoom).y / tileSize.y)
732
677
  ];
733
678
  }
@@ -738,6 +683,28 @@ export class GridLayer extends Layer {
738
683
  this._update();
739
684
  }
740
685
 
686
+ _onWorldCopyJump({worlds}) {
687
+ // noWrap tiles cannot be reused in another world copy.
688
+ if (!this._wrapX) { return; }
689
+
690
+ const tileSize = this.getTileSize(),
691
+ tiles = {};
692
+
693
+ for (const tile of Object.values(this._tiles)) {
694
+ const {coords, el} = tile,
695
+ dx = worlds * this._map.getPixelWorldBounds(coords.z).getSize().x;
696
+
697
+ // tiles can't be shifted by a fraction of a column, so leave those to be reloaded
698
+ if (dx % tileSize.x === 0) {
699
+ coords.x -= dx / tileSize.x;
700
+ DomUtil.setPosition(el, DomUtil.getPosition(el).subtract([dx, 0]), true);
701
+ }
702
+ tiles[this._tileCoordsToKey(coords)] = tile;
703
+ }
704
+
705
+ this._tiles = tiles;
706
+ }
707
+
741
708
  _getTiledPixelBounds(center) {
742
709
  const map = this._map,
743
710
  mapZoom = map._animatingZoom ? Math.max(map._animateToZoom, map.getZoom()) : map.getZoom(),
@@ -838,10 +805,6 @@ export class GridLayer extends Layer {
838
805
  return LatLngBounds.from(this.options.bounds).overlaps(tileBounds);
839
806
  }
840
807
 
841
- _keyToBounds(key) {
842
- return this._tileCoordsToBounds(this._keyToTileCoords(key));
843
- }
844
-
845
808
  _tileCoordsToNwSe(coords) {
846
809
  const map = this._map,
847
810
  tileSize = this.getTileSize(),
@@ -867,14 +830,6 @@ export class GridLayer extends Layer {
867
830
  return `${coords.x}:${coords.y}:${coords.z}`;
868
831
  }
869
832
 
870
- // converts tile cache key to coordinates
871
- _keyToTileCoords(key) {
872
- const k = key.split(':'),
873
- coords = new Point(+k[0], +k[1]);
874
- coords.z = +k[2];
875
- return coords;
876
- }
877
-
878
833
  _removeTile(key) {
879
834
  const tile = this._tiles[key];
880
835
  if (!tile) { return; }
@@ -885,7 +840,7 @@ export class GridLayer extends Layer {
885
840
 
886
841
  this.fire('tileunload', {
887
842
  tile: tile.el,
888
- coords: this._keyToTileCoords(key)
843
+ coords: tile.coords
889
844
  });
890
845
  }
891
846
 
@@ -896,9 +851,6 @@ export class GridLayer extends Layer {
896
851
  tile.style.width = `${tileSize.x}px`;
897
852
  tile.style.height = `${tileSize.y}px`;
898
853
 
899
- tile.onselectstart = Util.falseFn;
900
- tile.onpointermove = Util.falseFn;
901
-
902
854
  if (this.options.placeholder) {
903
855
  tile.style.background = this.options.placeholder;
904
856
  }
@@ -919,7 +871,9 @@ export class GridLayer extends Layer {
919
871
  requestAnimationFrame(this._tileReady.bind(this, coords, null, tile));
920
872
  }
921
873
 
922
- DomUtil.setPosition(tile, tilePos);
874
+ // 2D, so tiles raster into the level's layer: as separate layers they get compositor edge antialiasing,
875
+ // and the overlapping edge ramps show as light seams under plus-lighter blending
876
+ DomUtil.setPosition(tile, tilePos, true);
923
877
 
924
878
  // save tile in cache
925
879
  this._tiles[key] = {
@@ -949,20 +903,20 @@ export class GridLayer extends Layer {
949
903
  tile = this._tiles[key];
950
904
  if (!tile) { return; }
951
905
 
952
- tile.loaded = Date.now();
953
906
  if (this.options.placeholder) {
954
- // fading in would show the map below instead of the placeholder at first
955
- tile.noFade = true;
956
907
  tile.el.style.background = '';
957
908
  }
958
- if (this._map._fadeAnimated && !tile.noFade) {
959
- tile.el.style.opacity = 0;
960
- cancelAnimationFrame(this._fadeFrame);
961
- this._fadeFrame = requestAnimationFrame(this._updateOpacity.bind(this));
962
- } else {
909
+ // fading in with a placeholder would show the map below instead of the placeholder at first
910
+ if (!this._map._fadeAnimated || this.options.placeholder) {
963
911
  tile.active = true;
964
912
  this._pruneTiles();
913
+ } else if (!tile.loaded) { // with errorTileUrl, a tile is ready twice (on error and on fallback load)
914
+ // while fading, the tile is a compositor layer of its own where plus-lighter would light up its
915
+ // antialiased edges, so it's blended normally until the fade ends
916
+ tile.el.classList.add('maplair-tile-fading');
917
+ tile.el.animate({opacity: [0, 1]}, 200).onfinish = this._onTileFaded.bind(this, tile);
965
918
  }
919
+ tile.loaded = true;
966
920
 
967
921
  if (!err) {
968
922
  tile.el.classList.add('maplair-tile-loaded');
@@ -988,6 +942,22 @@ export class GridLayer extends Layer {
988
942
  }
989
943
  }
990
944
 
945
+ _onTileFaded(tile) {
946
+ tile.el.classList.remove('maplair-tile-fading');
947
+ // the tile's key may have changed after a world copy jump, so look it up again
948
+ if (this._tiles[this._tileCoordsToKey(tile.coords)] !== tile) { return; }
949
+
950
+ tile.active = true;
951
+ this._onOpaqueTile(tile);
952
+
953
+ // one prune for all the tiles that finish fading in the same frame
954
+ if (this._noPrune || this._fadePruneFrame) { return; }
955
+ this._fadePruneFrame = requestAnimationFrame(() => {
956
+ this._fadePruneFrame = 0;
957
+ if (!this._noPrune) { this._pruneTiles(); }
958
+ });
959
+ }
960
+
991
961
  _getTilePos(coords) {
992
962
  return coords.scaleBy(this.getTileSize()).subtract(this._level.origin);
993
963
  }
@@ -1,5 +1,4 @@
1
1
  import {GridLayer} from './GridLayer.js';
2
- import Browser from '../../core/Browser.js';
3
2
  import * as Util from '../../core/Util.js';
4
3
  import * as DomEvent from '../../dom/DomEvent.js';
5
4
  import {I18n} from '../../core/I18n.js';
@@ -7,6 +6,18 @@ import {I18n} from '../../core/I18n.js';
7
6
  /** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */
8
7
  /** @import {TileEvent} from '../../core/Events.js' */
9
8
 
9
+ const osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];
10
+ const hostRe = /^(https?:)?\/\/([^/?#:]*)/i;
11
+ const httpRe = /^http:/i;
12
+
13
+ function isOSMUrl(url) {
14
+ const host = hostRe.exec(url)?.[2] ?? '';
15
+ return osmHosts.some(osmHost => host === osmHost || host.endsWith(`.${osmHost}`));
16
+ }
17
+
18
+ // OSM tiles are upgraded to HTTPS so that the referrer policy works
19
+ const upgradeOSMUrl = url => (isOSMUrl(url) ? url.replace(httpRe, 'https:') : url);
20
+
10
21
  /**
11
22
  * Options of `TileLayer`.
12
23
  * @typedef {object} TileLayerOptions
@@ -89,22 +100,20 @@ import {I18n} from '../../core/I18n.js';
89
100
  */
90
101
  export class TileLayer extends GridLayer {
91
102
 
92
- static {
93
- this.setDefaultOptions({
94
- minZoom: 0,
95
- maxZoom: 18,
96
- subdomains: 'abc',
97
- errorTileUrl: '',
98
- zoomOffset: 0,
99
- tms: false,
100
- zoomReverse: false,
101
- detectRetina: false,
102
- crossOrigin: false,
103
- referrerPolicy: 'strict-origin-when-cross-origin',
104
- fetchOptions: null
105
-
106
- });
107
- }
103
+ static defaultOptions = {
104
+ minZoom: 0,
105
+ maxZoom: 18,
106
+ subdomains: 'abc',
107
+ errorTileUrl: '',
108
+ zoomOffset: 0,
109
+ tms: false,
110
+ zoomReverse: false,
111
+ detectRetina: false,
112
+ crossOrigin: false,
113
+ referrerPolicy: 'strict-origin-when-cross-origin',
114
+ fetchOptions: null
115
+
116
+ };
108
117
 
109
118
  /**
110
119
  * Instantiates a tile layer object given a [URL template](#tilelayer) and optionally an
@@ -116,23 +125,13 @@ export class TileLayer extends GridLayer {
116
125
  constructor(url, options) {
117
126
  super(options);
118
127
 
119
- this._url = url;
120
-
121
128
  options = Util.setOptions(this, options);
122
129
 
123
- // Set required OpenStreetMap attribution if it hasn't been specified; upgrade to HTTPS so the referrer policy works.
124
- const tileUrl = new URL(this._url, location.href);
125
- const urlHostname = tileUrl.hostname;
126
- const osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];
127
- if (osmHosts.some(host => urlHostname.endsWith(host))) {
128
- if (options.attribution === null) {
129
- options.attribution = `&copy; <a href="https://www.openstreetmap.org/copyright">${I18n.translate('OpenStreetMap contributors')}</a>`;
130
- }
131
- if (tileUrl.protocol === 'http:') {
132
- tileUrl.protocol = 'https:';
133
- this._url = tileUrl.toString();
134
- }
130
+ // Set required OpenStreetMap attribution if it hasn't been specified
131
+ if (isOSMUrl(url) && options.attribution === null) {
132
+ options.attribution = `&copy; <a href="https://www.openstreetmap.org/copyright">${I18n.translate('OpenStreetMap contributors')}</a>`;
135
133
  }
134
+ this._url = upgradeOSMUrl(url);
136
135
 
137
136
  const {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom} = this.options;
138
137
  this._nonRetinaOptions = {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom};
@@ -142,15 +141,13 @@ export class TileLayer extends GridLayer {
142
141
  this.options.subdomains = this.options.subdomains.split('');
143
142
  }
144
143
 
145
- this.on('tileunload', this._onTileRemove);
146
-
147
144
  this.callInitHooks(TileLayer);
148
145
  }
149
146
 
150
147
  // Detects retina displays (if `detectRetina` is set), adjusting tileSize and zoom levels.
151
148
  _applyRetina() {
152
149
  Object.assign(this.options, this._nonRetinaOptions);
153
- this._retina = Browser.retina;
150
+ this._retina = window.devicePixelRatio > 1;
154
151
 
155
152
  if (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {
156
153
 
@@ -193,7 +190,7 @@ export class TileLayer extends GridLayer {
193
190
 
194
191
  // Loads the tiles for the new resolution, see the map's `pixelratiochange` event.
195
192
  _onPixelRatioChange() {
196
- if (Browser.retina === this._retina) { return; }
193
+ if ((window.devicePixelRatio > 1) === this._retina) { return; }
197
194
  const map = this._map;
198
195
  this._applyRetina();
199
196
  if (this.options.detectRetina) {
@@ -216,6 +213,8 @@ export class TileLayer extends GridLayer {
216
213
  * @returns {this}
217
214
  */
218
215
  setUrl(url, noRedraw) {
216
+ url = upgradeOSMUrl(url);
217
+
219
218
  if (this._url === url && noRedraw === undefined) {
220
219
  noRedraw = true;
221
220
  }
@@ -319,7 +318,7 @@ export class TileLayer extends GridLayer {
319
318
  getTileUrl(coords) {
320
319
  const data = Object.create(this.options);
321
320
  Object.assign(data, {
322
- r: Browser.retina ? '@2x' : '',
321
+ r: window.devicePixelRatio > 1 ? '@2x' : '',
323
322
  s: this._getSubdomain(coords),
324
323
  x: coords.x,
325
324
  y: coords.y,
@@ -352,10 +351,6 @@ export class TileLayer extends GridLayer {
352
351
  done(e, tile);
353
352
  }
354
353
 
355
- _onTileRemove(e) {
356
- e.tile.onload = null;
357
- }
358
-
359
354
  _getZoomForUrl() {
360
355
  let zoom = this._tileZoom;
361
356
  const maxZoom = this.options.maxZoom,
@@ -381,9 +376,6 @@ export class TileLayer extends GridLayer {
381
376
  if (this._tiles[i].coords.z !== this._tileZoom) {
382
377
  tile = this._tiles[i].el;
383
378
 
384
- tile.onload = Util.falseFn;
385
- tile.onerror = Util.falseFn;
386
-
387
379
  if (this._abortTileFetch(tile) || !tile.complete) {
388
380
  tile.setAttribute('src', '');
389
381
  const coords = this._tiles[i].coords;
@@ -1,5 +1,4 @@
1
1
  import {TileLayer} from './TileLayer.js';
2
- import Browser from '../../core/Browser.js';
3
2
  import {EPSG4326} from '../../geo/crs/EPSG4326.js';
4
3
  import {Bounds} from '../../geometry/Bounds.js';
5
4
  /** @import {CRS} from '../../geo/crs/CRS.js' */
@@ -44,23 +43,24 @@ import {Bounds} from '../../geometry/Bounds.js';
44
43
  */
45
44
  export class WMSTileLayer extends TileLayer {
46
45
 
47
- static {
48
- // the WMS parameters among the options, see `WMSTileLayerOptions`
49
- this.prototype.defaultWmsParams = {
50
- service: 'WMS',
51
- request: 'GetMap',
52
- layers: '',
53
- styles: '',
54
- format: 'image/jpeg',
55
- transparent: false,
56
- version: '1.1.1'
57
- };
58
-
59
- this.setDefaultOptions({
60
- crs: null,
61
- uppercase: false
62
- });
63
- }
46
+ /**
47
+ * The default WMS parameters, which the options override, see `WMSTileLayerOptions`.
48
+ * @type {Record<string, any>}
49
+ */
50
+ static defaultWmsParams = {
51
+ service: 'WMS',
52
+ request: 'GetMap',
53
+ layers: '',
54
+ styles: '',
55
+ format: 'image/jpeg',
56
+ transparent: false,
57
+ version: '1.1.1'
58
+ };
59
+
60
+ static defaultOptions = {
61
+ crs: null,
62
+ uppercase: false
63
+ };
64
64
 
65
65
  /**
66
66
  * Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS
@@ -72,11 +72,11 @@ export class WMSTileLayer extends TileLayer {
72
72
  constructor(url, options) {
73
73
  super(url, options);
74
74
 
75
- const wmsParams = {...this.defaultWmsParams};
75
+ const wmsParams = {...WMSTileLayer.defaultWmsParams};
76
76
 
77
77
  // Options that are unknown in the prototype chain are considered WMS params.
78
78
  for (const [key, value] of Object.entries(options)) {
79
- if (!(key in WMSTileLayer.prototype.options)) {
79
+ if (!(key in WMSTileLayer.defaultOptions)) {
80
80
  wmsParams[key] = value;
81
81
  }
82
82
  }
@@ -93,7 +93,7 @@ export class WMSTileLayer extends TileLayer {
93
93
 
94
94
  // The size of the requested images: the tile size, doubled on retina displays with `detectRetina`.
95
95
  _updateWmsSize() {
96
- const realRetina = this.options.detectRetina && Browser.retina ? 2 : 1;
96
+ const realRetina = this.options.detectRetina && window.devicePixelRatio > 1 ? 2 : 1;
97
97
  const tileSize = this.getTileSize();
98
98
 
99
99
  this.wmsParams.width = tileSize.x * realRetina;
@@ -151,9 +151,9 @@ export class WMSTileLayer extends TileLayer {
151
151
  bbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ?
152
152
  [min.y, min.x, max.y, max.x] :
153
153
  [min.x, min.y, max.x, max.y]).join(',');
154
- const url = new URL(super.getTileUrl(coords));
154
+ const url = new URL(super.getTileUrl(coords), document.baseURI);
155
155
  for (const [k, v] of Object.entries({...this.wmsParams, bbox})) {
156
- url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v);
156
+ url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);
157
157
  }
158
158
  return url.toString();
159
159
  }
@@ -189,7 +189,8 @@ export class WMSTileLayer extends TileLayer {
189
189
 
190
190
  /**
191
191
  * Merges an object with the new parameters and re-requests tiles on the current screen
192
- * (unless `noRedraw` was set to true).
192
+ * (unless `noRedraw` was set to true). The current tiles stay visible until the new
193
+ * tiles have loaded, to avoid flickering.
193
194
  * @param {Record<string, any>} params
194
195
  * @param {boolean} [noRedraw]
195
196
  * @returns {this}
@@ -199,6 +200,7 @@ export class WMSTileLayer extends TileLayer {
199
200
  Object.assign(this.wmsParams, params);
200
201
 
201
202
  if (!noRedraw) {
203
+ this._keepCurrentTiles();
202
204
  this.redraw();
203
205
  }
204
206
 
@@ -40,11 +40,9 @@ const DASH_SEPARATOR_RE = /[, ]+/;
40
40
  */
41
41
  export class Canvas extends Renderer {
42
42
 
43
- static {
44
- this.setDefaultOptions({
45
- tolerance: 0
46
- });
47
- }
43
+ static defaultOptions = {
44
+ tolerance: 0
45
+ };
48
46
 
49
47
  /**
50
48
  * Creates a Canvas renderer with the given options.