maplair 4.0.0 → 4.2.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 (305) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/esm/Maplair.js +18 -17
  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 +25 -16
  6. package/dist/esm/control/AttributionControl.js.map +1 -1
  7. package/dist/esm/control/ButtonControl.js +10 -13
  8. package/dist/esm/control/ButtonControl.js.map +1 -1
  9. package/dist/esm/control/ContextMenu.js +2 -5
  10. package/dist/esm/control/ContextMenu.js.map +1 -1
  11. package/dist/esm/control/Control.js +10 -18
  12. package/dist/esm/control/Control.js.map +1 -1
  13. package/dist/esm/control/FullscreenControl.js +6 -9
  14. package/dist/esm/control/FullscreenControl.js.map +1 -1
  15. package/dist/esm/control/LayersControl.js +170 -65
  16. package/dist/esm/control/LayersControl.js.map +1 -1
  17. package/dist/esm/control/LegendControl.js +8 -11
  18. package/dist/esm/control/LegendControl.js.map +1 -1
  19. package/dist/esm/control/MiniMapControl.js +15 -18
  20. package/dist/esm/control/MiniMapControl.js.map +1 -1
  21. package/dist/esm/control/RotateControl.js +2 -5
  22. package/dist/esm/control/RotateControl.js.map +1 -1
  23. package/dist/esm/control/ScaleControl.js +8 -11
  24. package/dist/esm/control/ScaleControl.js.map +1 -1
  25. package/dist/esm/control/SearchControl.js +100 -19
  26. package/dist/esm/control/SearchControl.js.map +1 -1
  27. package/dist/esm/control/SideBySideControl.js +2 -5
  28. package/dist/esm/control/SideBySideControl.js.map +1 -1
  29. package/dist/esm/control/TextControl.js +6 -9
  30. package/dist/esm/control/TextControl.js.map +1 -1
  31. package/dist/esm/control/TimeControl.js +407 -0
  32. package/dist/esm/control/TimeControl.js.map +1 -0
  33. package/dist/esm/control/ZoomControl.js +23 -36
  34. package/dist/esm/control/ZoomControl.js.map +1 -1
  35. package/dist/esm/core/Class.js +28 -44
  36. package/dist/esm/core/Class.js.map +1 -1
  37. package/dist/esm/core/Events.js +22 -10
  38. package/dist/esm/core/Events.js.map +1 -1
  39. package/dist/esm/core/Handler.js +23 -14
  40. package/dist/esm/core/Handler.js.map +1 -1
  41. package/dist/esm/core/I18n.js +1 -2
  42. package/dist/esm/core/Util.js +15 -4
  43. package/dist/esm/core/Util.js.map +1 -1
  44. package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
  45. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  46. package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
  47. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  48. package/dist/esm/dom/DomEvent.js +18 -60
  49. package/dist/esm/dom/DomEvent.js.map +1 -1
  50. package/dist/esm/dom/DomUtil.js +15 -70
  51. package/dist/esm/dom/DomUtil.js.map +1 -1
  52. package/dist/esm/dom/Draggable.js +21 -21
  53. package/dist/esm/dom/Draggable.js.map +1 -1
  54. package/dist/esm/dom/PosAnimation.js +4 -27
  55. package/dist/esm/dom/PosAnimation.js.map +1 -1
  56. package/dist/esm/geo/LatLng.js +16 -7
  57. package/dist/esm/geo/LatLng.js.map +1 -1
  58. package/dist/esm/geo/LatLngBounds.js +9 -15
  59. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  60. package/dist/esm/geo/crs/CRS.js +1 -2
  61. package/dist/esm/geo/crs/EPSG3395.js +5 -6
  62. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  63. package/dist/esm/geo/crs/EPSG3857.js +5 -6
  64. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  65. package/dist/esm/geo/crs/EPSG4326.js +4 -5
  66. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  67. package/dist/esm/geo/crs/EarthCRS.js +3 -4
  68. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  69. package/dist/esm/geo/crs/SimpleCRS.js +4 -5
  70. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  71. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
  72. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  73. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
  74. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  75. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
  76. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  77. package/dist/esm/geometry/Bounds.js +10 -14
  78. package/dist/esm/geometry/Bounds.js.map +1 -1
  79. package/dist/esm/geometry/LineUtil.js +37 -32
  80. package/dist/esm/geometry/LineUtil.js.map +1 -1
  81. package/dist/esm/geometry/Point.js +1 -2
  82. package/dist/esm/geometry/PolyUtil.js +24 -51
  83. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  84. package/dist/esm/geometry/Transformation.js +1 -2
  85. package/dist/esm/layer/BlanketOverlay.js +7 -10
  86. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  87. package/dist/esm/layer/Classification.js +1 -2
  88. package/dist/esm/layer/DivOverlay.js +16 -22
  89. package/dist/esm/layer/DivOverlay.js.map +1 -1
  90. package/dist/esm/layer/FeatureGroup.js +5 -4
  91. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  92. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  93. package/dist/esm/layer/GeoJSON.js +17 -155
  94. package/dist/esm/layer/GeoJSON.js.map +1 -1
  95. package/dist/esm/layer/GeoJSONUtil.js +74 -0
  96. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  97. package/dist/esm/layer/HeatLayer.js +17 -20
  98. package/dist/esm/layer/HeatLayer.js.map +1 -1
  99. package/dist/esm/layer/ImageOverlay.js +22 -29
  100. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  101. package/dist/esm/layer/Layer.js +9 -12
  102. package/dist/esm/layer/Layer.js.map +1 -1
  103. package/dist/esm/layer/LayerGroup.js +53 -3
  104. package/dist/esm/layer/LayerGroup.js.map +1 -1
  105. package/dist/esm/layer/Popup.js +35 -58
  106. package/dist/esm/layer/Popup.js.map +1 -1
  107. package/dist/esm/layer/SVGOverlay.js +3 -7
  108. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  109. package/dist/esm/layer/Tooltip.js +31 -34
  110. package/dist/esm/layer/Tooltip.js.map +1 -1
  111. package/dist/esm/layer/VideoOverlay.js +13 -17
  112. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  113. package/dist/esm/layer/marker/DefaultIcon.js +38 -49
  114. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  115. package/dist/esm/layer/marker/DivIcon.js +8 -11
  116. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  117. package/dist/esm/layer/marker/Icon.js +9 -12
  118. package/dist/esm/layer/marker/Icon.js.map +1 -1
  119. package/dist/esm/layer/marker/Marker.Drag.js +44 -5
  120. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  121. package/dist/esm/layer/marker/Marker.Move.js +5 -8
  122. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  123. package/dist/esm/layer/marker/Marker.js +115 -47
  124. package/dist/esm/layer/marker/Marker.js.map +1 -1
  125. package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
  126. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  127. package/dist/esm/layer/marker/SvgIcon.js +7 -10
  128. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  129. package/dist/esm/layer/tile/GridLayer.js +89 -101
  130. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  131. package/dist/esm/layer/tile/TileLayer.js +36 -44
  132. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  133. package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
  134. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  135. package/dist/esm/layer/vector/Canvas.js +8 -17
  136. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  137. package/dist/esm/layer/vector/Circle.js +6 -5
  138. package/dist/esm/layer/vector/Circle.js.map +1 -1
  139. package/dist/esm/layer/vector/CircleMarker.js +19 -10
  140. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  141. package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
  142. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  143. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  144. package/dist/esm/layer/vector/Path.js +28 -22
  145. package/dist/esm/layer/vector/Path.js.map +1 -1
  146. package/dist/esm/layer/vector/Polygon.js +22 -7
  147. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  148. package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
  149. package/dist/esm/layer/vector/Polyline.js +25 -10
  150. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  151. package/dist/esm/layer/vector/Rectangle.js +1 -2
  152. package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
  153. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  154. package/dist/esm/layer/vector/Renderer.js +1 -2
  155. package/dist/esm/layer/vector/SVG.js +12 -9
  156. package/dist/esm/layer/vector/SVG.js.map +1 -1
  157. package/dist/esm/map/Hash.js +1 -2
  158. package/dist/esm/map/Map.Rotation.js +41 -22
  159. package/dist/esm/map/Map.Rotation.js.map +1 -1
  160. package/dist/esm/map/Map.js +125 -126
  161. package/dist/esm/map/Map.js.map +1 -1
  162. package/dist/esm/map/MapSync.js +1 -2
  163. package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
  164. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  165. package/dist/esm/map/handler/DisplaceHandler.js +7 -10
  166. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  167. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  168. package/dist/esm/map/handler/DragHandler.js +20 -21
  169. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  170. package/dist/esm/map/handler/KeyboardHandler.js +48 -68
  171. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  172. package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
  173. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  174. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
  175. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  176. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  177. package/dist/esm/map/handler/TapHoldHandler.js +13 -7
  178. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  179. package/dist/esm/package.js +2 -3
  180. package/dist/maplair-global-src.js +6495 -5981
  181. package/dist/maplair-global-src.js.map +1 -1
  182. package/dist/maplair-global.js +2 -2
  183. package/dist/maplair-global.js.map +1 -1
  184. package/dist/maplair-src.js +6206 -5673
  185. package/dist/maplair-src.js.map +1 -1
  186. package/dist/maplair.css +1 -1213
  187. package/dist/maplair.js +2 -2
  188. package/dist/maplair.js.map +1 -1
  189. package/i18n/cs.json +6 -0
  190. package/i18n/de.json +6 -0
  191. package/i18n/en.json +6 -0
  192. package/i18n/es.json +6 -0
  193. package/i18n/fr.json +6 -0
  194. package/i18n/hu.json +6 -0
  195. package/i18n/it.json +6 -0
  196. package/i18n/rm.json +6 -0
  197. package/i18n/sk.json +6 -0
  198. package/i18n/sl.json +6 -0
  199. package/package.json +11 -18
  200. package/src/Maplair.all.js +0 -1
  201. package/src/control/AttributionControl.js +25 -18
  202. package/src/control/ButtonControl.js +9 -11
  203. package/src/control/ContextMenu.js +3 -5
  204. package/src/control/Control.js +9 -19
  205. package/src/control/FullscreenControl.js +5 -7
  206. package/src/control/LayersControl.js +196 -86
  207. package/src/control/LegendControl.js +7 -9
  208. package/src/control/MiniMapControl.js +9 -11
  209. package/src/control/RotateControl.js +3 -5
  210. package/src/control/ScaleControl.js +7 -9
  211. package/src/control/SearchControl.js +102 -19
  212. package/src/control/SideBySideControl.js +3 -5
  213. package/src/control/TextControl.js +5 -7
  214. package/src/control/TimeControl.js +471 -0
  215. package/src/control/ZoomControl.js +22 -38
  216. package/src/control/index.js +1 -0
  217. package/src/core/Class.js +37 -45
  218. package/src/core/Events.js +22 -3
  219. package/src/core/Handler.js +25 -13
  220. package/src/core/Util.js +20 -2
  221. package/src/core/index.js +0 -1
  222. package/src/dom/DomEvent.DoubleTap.js +18 -10
  223. package/src/dom/DomEvent.PointerEvents.js +3 -26
  224. package/src/dom/DomEvent.js +17 -85
  225. package/src/dom/DomUtil.js +22 -78
  226. package/src/dom/Draggable.js +32 -23
  227. package/src/dom/PosAnimation.js +3 -25
  228. package/src/dom/index.js +0 -1
  229. package/src/geo/LatLng.js +20 -3
  230. package/src/geo/LatLngBounds.js +8 -15
  231. package/src/geo/crs/EPSG3395.js +4 -4
  232. package/src/geo/crs/EPSG3857.js +4 -4
  233. package/src/geo/crs/EPSG4326.js +3 -3
  234. package/src/geo/crs/EarthCRS.js +2 -8
  235. package/src/geo/crs/SimpleCRS.js +3 -3
  236. package/src/geo/index.js +1 -2
  237. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
  238. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
  239. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
  240. package/src/geo/projection/index.js +5 -5
  241. package/src/geometry/Bounds.js +12 -17
  242. package/src/geometry/LineUtil.js +48 -49
  243. package/src/geometry/PolyUtil.js +39 -76
  244. package/src/layer/BlanketOverlay.js +6 -10
  245. package/src/layer/DivOverlay.js +16 -27
  246. package/src/layer/FeatureGroup.js +8 -2
  247. package/src/layer/GeoJSON.js +17 -218
  248. package/src/layer/GeoJSONUtil.js +85 -0
  249. package/src/layer/HeatLayer.js +10 -12
  250. package/src/layer/ImageOverlay.js +21 -32
  251. package/src/layer/Layer.js +8 -10
  252. package/src/layer/LayerGroup.js +72 -1
  253. package/src/layer/Popup.js +37 -62
  254. package/src/layer/SVGOverlay.js +1 -5
  255. package/src/layer/Tooltip.js +34 -36
  256. package/src/layer/VideoOverlay.js +12 -15
  257. package/src/layer/marker/DefaultIcon.js +40 -58
  258. package/src/layer/marker/DivIcon.js +9 -11
  259. package/src/layer/marker/Icon.js +9 -10
  260. package/src/layer/marker/Marker.Drag.js +54 -6
  261. package/src/layer/marker/Marker.Move.js +4 -6
  262. package/src/layer/marker/Marker.js +145 -52
  263. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  264. package/src/layer/marker/SvgIcon.js +7 -9
  265. package/src/layer/marker/index.js +1 -0
  266. package/src/layer/tile/GridLayer.js +108 -135
  267. package/src/layer/tile/TileLayer.js +44 -49
  268. package/src/layer/tile/WMSTileLayer.js +31 -26
  269. package/src/layer/vector/Canvas.js +13 -19
  270. package/src/layer/vector/Circle.js +9 -3
  271. package/src/layer/vector/CircleMarker.js +19 -7
  272. package/src/layer/vector/Path.DashAnimation.js +1 -2
  273. package/src/layer/vector/Path.js +30 -21
  274. package/src/layer/vector/Polygon.js +29 -6
  275. package/src/layer/vector/Polyline.js +26 -7
  276. package/src/layer/vector/Renderer.getRenderer.js +20 -19
  277. package/src/layer/vector/SVG.js +17 -7
  278. package/src/map/Map.Rotation.js +40 -8
  279. package/src/map/Map.js +158 -153
  280. package/src/map/handler/BoxZoomHandler.js +30 -50
  281. package/src/map/handler/DisplaceHandler.js +6 -8
  282. package/src/map/handler/DragHandler.js +25 -28
  283. package/src/map/handler/KeyboardHandler.js +65 -90
  284. package/src/map/handler/PinchZoomHandler.js +16 -5
  285. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  286. package/src/map/handler/TapHoldHandler.js +15 -4
  287. package/src/map/index.js +1 -1
  288. package/src/maplair.css +153 -98
  289. package/dist/esm/core/Browser.js +0 -100
  290. package/dist/esm/core/Browser.js.map +0 -1
  291. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  292. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  293. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  294. package/dist/esm/geo/projection/index.js +0 -14
  295. package/dist/esm/geo/projection/index.js.map +0 -1
  296. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  297. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  298. package/dist/images/layers.svg +0 -1
  299. package/dist/images/marker-icon.svg +0 -1
  300. package/dist/images/marker-shadow.svg +0 -1
  301. package/src/core/Browser.js +0 -110
  302. package/src/images/layers.svg +0 -1
  303. package/src/images/marker-icon.svg +0 -1
  304. package/src/images/marker-shadow.svg +0 -1
  305. package/src/layer/marker/Marker.Rotation.js +0 -103
@@ -1,12 +1,19 @@
1
- import { falseFn, setOptions, template } from "../../core/Util.js";
2
- import Browser_default from "../../core/Browser.js";
1
+ import { setOptions, template } from "../../core/Util.js";
2
+ import { Point } from "../../geometry/Point.js";
3
3
  import { on } from "../../dom/DomEvent.js";
4
4
  import { I18n } from "../../core/I18n.js";
5
5
  import { GridLayer } from "./GridLayer.js";
6
- //#region src/layer/tile/TileLayer.js
7
- /** @import {Point} from '../../geometry/Point.js' */
6
+ // src/layer/tile/TileLayer.js
8
7
  /** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */
9
8
  /** @import {TileEvent} from '../../core/Events.js' */
9
+ const osmHosts = ["tile.openstreetmap.org", "tile.osm.org"];
10
+ const hostRe = /^(https?:)?\/\/([^/?#:]*)/i;
11
+ const httpRe = /^http:/i;
12
+ function isOSMUrl(url) {
13
+ const host = hostRe.exec(url)?.[2] ?? "";
14
+ return osmHosts.some((osmHost) => host === osmHost || host.endsWith(`.${osmHost}`));
15
+ }
16
+ const upgradeOSMUrl = (url) => isOSMUrl(url) ? url.replace(httpRe, "https:") : url;
10
17
  /**
11
18
  * Options of `TileLayer`.
12
19
  * @typedef {object} TileLayerOptions
@@ -87,21 +94,19 @@ import { GridLayer } from "./GridLayer.js";
87
94
  * @fires tileabort {TileEvent} Fired when a tile was loading but is now not wanted.
88
95
  */
89
96
  var TileLayer = class TileLayer extends GridLayer {
90
- static {
91
- this.setDefaultOptions({
92
- minZoom: 0,
93
- maxZoom: 18,
94
- subdomains: "abc",
95
- errorTileUrl: "",
96
- zoomOffset: 0,
97
- tms: false,
98
- zoomReverse: false,
99
- detectRetina: false,
100
- crossOrigin: false,
101
- referrerPolicy: "strict-origin-when-cross-origin",
102
- fetchOptions: null
103
- });
104
- }
97
+ static defaultOptions = {
98
+ minZoom: 0,
99
+ maxZoom: 18,
100
+ subdomains: "abc",
101
+ errorTileUrl: "",
102
+ zoomOffset: 0,
103
+ tms: false,
104
+ zoomReverse: false,
105
+ detectRetina: false,
106
+ crossOrigin: false,
107
+ referrerPolicy: "strict-origin-when-cross-origin",
108
+ fetchOptions: null
109
+ };
105
110
  /**
106
111
  * Instantiates a tile layer object given a [URL template](#tilelayer) and optionally an
107
112
  * options object.
@@ -111,17 +116,9 @@ var TileLayer = class TileLayer extends GridLayer {
111
116
  */
112
117
  constructor(url, options) {
113
118
  super(options);
114
- this._url = url;
115
119
  options = setOptions(this, options);
116
- const tileUrl = new URL(this._url, location.href);
117
- const urlHostname = tileUrl.hostname;
118
- if (["tile.openstreetmap.org", "tile.osm.org"].some((host) => urlHostname.endsWith(host))) {
119
- if (options.attribution === null) options.attribution = `&copy; <a href="https://www.openstreetmap.org/copyright">${I18n.translate("OpenStreetMap contributors")}</a>`;
120
- if (tileUrl.protocol === "http:") {
121
- tileUrl.protocol = "https:";
122
- this._url = tileUrl.toString();
123
- }
124
- }
120
+ if (isOSMUrl(url) && options.attribution === null) options.attribution = `&copy; <a href="https://www.openstreetmap.org/copyright">${I18n.translate("OpenStreetMap contributors")}</a>`;
121
+ this._url = upgradeOSMUrl(url);
125
122
  const { tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom } = this.options;
126
123
  this._nonRetinaOptions = {
127
124
  tileSize,
@@ -133,14 +130,14 @@ var TileLayer = class TileLayer extends GridLayer {
133
130
  };
134
131
  this._applyRetina();
135
132
  if (typeof this.options.subdomains === "string") this.options.subdomains = this.options.subdomains.split("");
136
- this.on("tileunload", this._onTileRemove);
137
133
  this.callInitHooks(TileLayer);
138
134
  }
139
135
  _applyRetina() {
140
136
  Object.assign(this.options, this._nonRetinaOptions);
141
- this._retina = Browser_default.retina;
137
+ this._retina = window.devicePixelRatio > 1;
142
138
  if (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {
143
- this.options.tileSize = Math.floor(this.options.tileSize / 2);
139
+ const tileSize = this.options.tileSize;
140
+ this.options.tileSize = tileSize instanceof Point ? tileSize.divideBy(2).floor() : Math.floor(tileSize / 2);
144
141
  if (!this.options.zoomReverse) {
145
142
  this.options.zoomOffset++;
146
143
  this.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);
@@ -164,7 +161,7 @@ var TileLayer = class TileLayer extends GridLayer {
164
161
  return events;
165
162
  }
166
163
  _onPixelRatioChange() {
167
- if (Browser_default.retina === this._retina) return;
164
+ if (window.devicePixelRatio > 1 === this._retina) return;
168
165
  const map = this._map;
169
166
  this._applyRetina();
170
167
  if (this.options.detectRetina) {
@@ -184,6 +181,7 @@ var TileLayer = class TileLayer extends GridLayer {
184
181
  * @returns {this}
185
182
  */
186
183
  setUrl(url, noRedraw) {
184
+ url = upgradeOSMUrl(url);
187
185
  if (this._url === url && noRedraw === void 0) noRedraw = true;
188
186
  this._url = url;
189
187
  if (!noRedraw) {
@@ -247,7 +245,7 @@ var TileLayer = class TileLayer extends GridLayer {
247
245
  getTileUrl(coords) {
248
246
  const data = Object.create(this.options);
249
247
  Object.assign(data, {
250
- r: Browser_default.retina ? "@2x" : "",
248
+ r: window.devicePixelRatio > 1 ? "@2x" : "",
251
249
  s: this._getSubdomain(coords),
252
250
  x: coords.x,
253
251
  y: coords.y,
@@ -265,13 +263,10 @@ var TileLayer = class TileLayer extends GridLayer {
265
263
  done(null, tile);
266
264
  }
267
265
  _tileOnError(done, tile, e) {
268
- const errorUrl = this.options.errorTileUrl;
269
- if (errorUrl && tile.getAttribute("src") !== errorUrl) tile.src = errorUrl;
266
+ const errorUrl = this.options.errorTileUrl, src = tile.getAttribute("src");
267
+ if (errorUrl && src !== errorUrl && (src || tile.isConnected)) tile.src = errorUrl;
270
268
  done(e, tile);
271
269
  }
272
- _onTileRemove(e) {
273
- e.tile.onload = null;
274
- }
275
270
  _getZoomForUrl() {
276
271
  let zoom = this._tileZoom;
277
272
  const maxZoom = this.options.maxZoom, zoomReverse = this.options.zoomReverse, zoomOffset = this.options.zoomOffset;
@@ -279,15 +274,13 @@ var TileLayer = class TileLayer extends GridLayer {
279
274
  return zoom + zoomOffset;
280
275
  }
281
276
  _getSubdomain(tilePoint) {
282
- const index = Math.abs(tilePoint.x + tilePoint.y) % this.options.subdomains.length;
283
- return this.options.subdomains[index];
277
+ const { subdomains } = this.options;
278
+ return subdomains?.[Math.abs(tilePoint.x + tilePoint.y) % subdomains.length];
284
279
  }
285
280
  _abortLoading() {
286
281
  let i, tile;
287
282
  for (i of Object.keys(this._tiles)) if (this._tiles[i].coords.z !== this._tileZoom) {
288
283
  tile = this._tiles[i].el;
289
- tile.onload = falseFn;
290
- tile.onerror = falseFn;
291
284
  if (this._abortTileFetch(tile) || !tile.complete) {
292
285
  tile.setAttribute("src", "");
293
286
  const coords = this._tiles[i].coords;
@@ -315,7 +308,6 @@ var TileLayer = class TileLayer extends GridLayer {
315
308
  return Math.round(super._clampZoom(zoom));
316
309
  }
317
310
  };
318
- //#endregion
319
311
  export { TileLayer };
320
312
 
321
313
  //# sourceMappingURL=TileLayer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TileLayer.js","names":["Util.setOptions","Browser","Util.template","Util.falseFn"],"sources":["../../../../src/layer/tile/TileLayer.js"],"sourcesContent":["import {GridLayer} from './GridLayer.js';\nimport Browser from '../../core/Browser.js';\nimport * as Util from '../../core/Util.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {I18n} from '../../core/I18n.js';\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */\n/** @import {TileEvent} from '../../core/Events.js' */\n\n/**\n * Options of `TileLayer`.\n * @typedef {object} TileLayerOptions\n * @property {number} [minZoom=0] The minimum zoom level down to which this layer will be\n * displayed (inclusive).\n * @property {number} [maxZoom=18] The maximum zoom level up to which this layer will be\n * displayed (inclusive).\n * @property {string|string[]} [subdomains='abc'] Subdomains of the tile service. Can be\n * passed in the form of one string (where each letter is a subdomain name) or an array\n * of strings.\n * @property {string} [errorTileUrl=''] URL to the tile image to show in place of the\n * tile that failed to load.\n * @property {number} [zoomOffset=0] The zoom number used in tile URLs will be offset\n * with this value.\n * @property {boolean} [tms=false] If `true`, inverses Y axis numbering for tiles (turn\n * this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).\n * @property {boolean} [zoomReverse=false] If set to true, the zoom number used in tile\n * URLs will be reversed (`maxZoom - zoom` instead of `zoom`).\n * @property {boolean} [detectRetina=false] If `true` and user is on a retina display, it\n * will request four tiles of half the specified size and a bigger zoom level in place\n * of one to utilize the high resolution.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will\n * be added to the tiles. If a String is provided, all tiles will have their crossOrigin\n * attribute set to the String provided. This is needed if you want to access tile pixel\n * data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {ReferrerPolicy} [referrerPolicy='strict-origin-when-cross-origin'] Sets the\n * tiles' `referrerPolicy` attribute set to the String provided. See\n * [`HTMLImageElement.referrerPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy)\n * for possible values.\n *\n * Tile providers might require you to use a specific referrer policy (e.g. to verify\n * API tokens or prevent abuse). Specifically, if you are using tiles from\n * `tile.openstreetmap.org` or `tile.osm.org`, you\n * [should not change this value](https://operations.osmfoundation.org/policies/tiles/).\n * @property {RequestInit|null} [fetchOptions=null] If set, the tiles are loaded with\n * [`fetch()`](https://developer.mozilla.org/docs/Web/API/Window/fetch) using these\n * options (see [`RequestInit`](https://developer.mozilla.org/docs/Web/API/RequestInit)),\n * e.g. `{headers: {Authorization: 'Bearer …'}}` for tile servers requiring custom HTTP\n * headers. Requests of tiles that are no longer needed (e.g. after panning or zooming\n * away) are aborted. Cross-origin tile servers have to allow such requests with\n * [CORS](https://developer.mozilla.org/docs/Web/HTTP/CORS) headers.\n * @extends GridLayerOptions\n */\n\n/**\n * Used to load and display tile layers on the map. Note that most tile servers require\n * attribution, which you can set under `Layer`. Extends `GridLayer`.\n *\n * ### URL template\n *\n * A string of the following form:\n *\n * ```\n * 'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'\n * ```\n *\n * `{s}` means one of the available subdomains (used sequentially to help with browser\n * parallel requests per domain limitation; subdomain values are specified in options;\n * `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` —\n * tile coordinates. `{r}` can be used to add \"@2x\" to the URL to load retina tiles.\n *\n * You can use custom keys in the template, which will be [evaluated](#util-template)\n * from TileLayer options, like this:\n *\n * ```\n * new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});\n * ```\n *\n * Layers extending `TileLayer` might reimplement the [`getTileUrl()`](#tilelayer-gettileurl)\n * method.\n *\n * @example\n * ```js\n * new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: '© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap contributors</a>'}).addTo(map);\n * ```\n *\n * @fires tileabort {TileEvent} Fired when a tile was loading but is now not wanted.\n */\nexport class TileLayer extends GridLayer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tminZoom: 0,\n\t\t\tmaxZoom: 18,\n\t\t\tsubdomains: 'abc',\n\t\t\terrorTileUrl: '',\n\t\t\tzoomOffset: 0,\n\t\t\ttms: false,\n\t\t\tzoomReverse: false,\n\t\t\tdetectRetina: false,\n\t\t\tcrossOrigin: false,\n\t\t\treferrerPolicy: 'strict-origin-when-cross-origin',\n\t\t\tfetchOptions: null\n\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a tile layer object given a [URL template](#tilelayer) and optionally an\n\t * options object.\n\t * @param {string} url The URL template.\n\t * @param {TileLayerOptions & Record<string, unknown>} [options] The options, and the values\n\t * of custom keys of the URL template.\n\t */\n\tconstructor(url, options) {\n\t\tsuper(options);\n\n\t\tthis._url = url;\n\n\t\toptions = Util.setOptions(this, options);\n\n\t\t// Set required OpenStreetMap attribution if it hasn't been specified; upgrade to HTTPS so the referrer policy works.\n\t\tconst tileUrl = new URL(this._url, location.href);\n\t\tconst urlHostname = tileUrl.hostname;\n\t\tconst osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];\n\t\tif (osmHosts.some(host => urlHostname.endsWith(host))) {\n\t\t\tif (options.attribution === null) {\n\t\t\t\toptions.attribution = `&copy; <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`;\n\t\t\t}\n\t\t\tif (tileUrl.protocol === 'http:') {\n\t\t\t\ttileUrl.protocol = 'https:';\n\t\t\t\tthis._url = tileUrl.toString();\n\t\t\t}\n\t\t}\n\n\t\tconst {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom} = this.options;\n\t\tthis._nonRetinaOptions = {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom};\n\t\tthis._applyRetina();\n\n\t\tif (typeof this.options.subdomains === 'string') {\n\t\t\tthis.options.subdomains = this.options.subdomains.split('');\n\t\t}\n\n\t\tthis.on('tileunload', this._onTileRemove);\n\n\t\tthis.callInitHooks(TileLayer);\n\t}\n\n\t// Detects retina displays (if `detectRetina` is set), adjusting tileSize and zoom levels.\n\t_applyRetina() {\n\t\tObject.assign(this.options, this._nonRetinaOptions);\n\t\tthis._retina = Browser.retina;\n\n\t\tif (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {\n\n\t\t\tthis.options.tileSize = Math.floor(this.options.tileSize / 2);\n\n\t\t\tif (!this.options.zoomReverse) {\n\t\t\t\tthis.options.zoomOffset++;\n\t\t\t\tthis.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);\n\t\t\t\t// do not request tiles beyond the native zoom levels\n\t\t\t\tif (this.options.maxNativeZoom !== undefined) {\n\t\t\t\t\tthis.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);\n\t\t\t\t}\n\t\t\t\tif (this.options.minNativeZoom !== undefined) {\n\t\t\t\t\tthis.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.options.zoomOffset--;\n\t\t\t\tthis.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);\n\t\t\t}\n\n\t\t\tthis.options.minZoom = Math.max(0, this.options.minZoom);\n\t\t} else if (!this.options.zoomReverse) {\n\t\t\t// make sure maxZoom is gte minZoom\n\t\t\tthis.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);\n\t\t} else {\n\t\t\t// make sure minZoom is lte maxZoom\n\t\t\tthis.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the layer listens to, see `Layer`.\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.pixelratiochange = this._onPixelRatioChange;\n\t\treturn events;\n\t}\n\n\t// Loads the tiles for the new resolution, see the map's `pixelratiochange` event.\n\t_onPixelRatioChange() {\n\t\tif (Browser.retina === this._retina) { return; }\n\t\tconst map = this._map;\n\t\tthis._applyRetina();\n\t\tif (this.options.detectRetina) {\n\t\t\tmap._removeZoomLimit(this);\n\t\t\tmap._addZoomLimit(this);\n\t\t\tthis._invalidateAll();\n\t\t\tthis._resetView();\n\t\t} else if (this._url.includes('{r}')) {\n\t\t\tthis.redraw();\n\t\t}\n\t}\n\n\t/**\n\t * Updates the layer's URL template and redraws it (unless `noRedraw` is set to `true`).\n\t * If the URL does not change, the layer will not be redrawn unless\n\t * the noRedraw parameter is set to false.\n\t * The current tiles stay visible until the new tiles have loaded, to avoid flickering.\n\t * @param {string} url\n\t * @param {boolean} [noRedraw]\n\t * @returns {this}\n\t */\n\tsetUrl(url, noRedraw) {\n\t\tif (this._url === url && noRedraw === undefined) {\n\t\t\tnoRedraw = true;\n\t\t}\n\n\t\tthis._url = url;\n\n\t\tif (!noRedraw) {\n\t\t\tthis._keepCurrentTiles();\n\t\t\tthis.redraw();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Called only internally, overrides GridLayer's [`createTile()`](#gridlayer-createtile)\n\t * to return an `<img>` HTML element with the appropriate image URL given `coords`. The\n\t * `done` callback is called when the tile has been loaded.\n\t * @param {Point} coords\n\t * @param {TileDoneCallback} [done]\n\t * @returns {HTMLImageElement}\n\t */\n\tcreateTile(coords, done) {\n\t\tconst tile = document.createElement('img');\n\n\t\tDomEvent.on(tile, 'load', this._tileOnLoad.bind(this, done, tile));\n\t\tDomEvent.on(tile, 'error', this._tileOnError.bind(this, done, tile));\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\ttile.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\t// for this new option we follow the documented behavior\n\t\t// more closely by only setting the property when string\n\t\tif (typeof this.options.referrerPolicy === 'string') {\n\t\t\ttile.referrerPolicy = this.options.referrerPolicy;\n\t\t}\n\n\t\t// The alt attribute is set to the empty string,\n\t\t// allowing screen readers to ignore the decorative image tiles.\n\t\t// https://www.w3.org/WAI/tutorials/images/decorative/\n\t\t// https://www.w3.org/TR/html-aria/#el-img-empty-alt\n\t\ttile.alt = '';\n\n\t\tconst url = this.getTileUrl(coords);\n\t\tif (this.options.fetchOptions) {\n\t\t\tthis._fetchTile(tile, url, done);\n\t\t} else {\n\t\t\ttile.src = url;\n\t\t}\n\n\t\treturn tile;\n\t}\n\n\t// Loads the tile image with `fetch()`, see the `fetchOptions` option.\n\t_fetchTile(tile, url, done) {\n\t\tconst controller = new AbortController(),\n\t\toptions = {signal: controller.signal, ...this.options.fetchOptions};\n\t\tif (typeof this.options.referrerPolicy === 'string') {\n\t\t\toptions.referrerPolicy ??= this.options.referrerPolicy;\n\t\t}\n\n\t\tthis._tileFetches ??= new Map();\n\t\tthis._tileFetches.set(tile, controller);\n\n\t\tfetch(url, options)\n\t\t\t.then((response) => {\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`Failed to load the tile ${url}: HTTP ${response.status}`);\n\t\t\t\t}\n\t\t\t\treturn response.blob();\n\t\t\t})\n\t\t\t.then((blob) => {\n\t\t\t\t// revoked in `_tileOnLoad()`\n\t\t\t\ttile.src = URL.createObjectURL(blob);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (!controller.signal.aborted) {\n\t\t\t\t\tthis._tileOnError(done, tile, error);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => this._tileFetches.delete(tile));\n\t}\n\n\t// Aborts the request of a tile loaded with `fetch()`, returns whether there was one.\n\t_abortTileFetch(tile) {\n\t\tconst controller = this._tileFetches?.get(tile);\n\t\tif (!controller) { return false; }\n\t\tcontroller.abort();\n\t\tthis._tileFetches.delete(tile);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called only internally, returns the URL for a tile given its coordinates.\n\t * Classes extending `TileLayer` can override this function to provide custom tile URL\n\t * naming schemes.\n\t * @group Extension methods\n\t * @param {Point} coords\n\t * @returns {string}\n\t */\n\tgetTileUrl(coords) {\n\t\tconst data = Object.create(this.options);\n\t\tObject.assign(data, {\n\t\t\tr: Browser.retina ? '@2x' : '',\n\t\t\ts: this._getSubdomain(coords),\n\t\t\tx: coords.x,\n\t\t\ty: coords.y,\n\t\t\tz: this._getZoomForUrl()\n\t\t});\n\t\tif (this._map && !this._map.options.crs.infinite) {\n\t\t\tconst invertedY = this._globalTileRange.max.y - coords.y;\n\t\t\tif (this.options.tms) {\n\t\t\t\tdata['y'] = invertedY;\n\t\t\t}\n\t\t\tdata['-y'] = invertedY;\n\t\t}\n\n\t\treturn Util.template(this._url, data);\n\t}\n\n\t_tileOnLoad(done, tile) {\n\t\tif (tile.src.startsWith('blob:')) {\n\t\t\t// the image keeps its data, see `_fetchTile()`\n\t\t\tURL.revokeObjectURL(tile.src);\n\t\t}\n\t\tdone(null, tile);\n\t}\n\n\t_tileOnError(done, tile, e) {\n\t\tconst errorUrl = this.options.errorTileUrl;\n\t\tif (errorUrl && tile.getAttribute('src') !== errorUrl) {\n\t\t\ttile.src = errorUrl;\n\t\t}\n\t\tdone(e, tile);\n\t}\n\n\t_onTileRemove(e) {\n\t\te.tile.onload = null;\n\t}\n\n\t_getZoomForUrl() {\n\t\tlet zoom = this._tileZoom;\n\t\tconst maxZoom = this.options.maxZoom,\n\t\tzoomReverse = this.options.zoomReverse,\n\t\tzoomOffset = this.options.zoomOffset;\n\n\t\tif (zoomReverse) {\n\t\t\tzoom = maxZoom - zoom;\n\t\t}\n\n\t\treturn zoom + zoomOffset;\n\t}\n\n\t_getSubdomain(tilePoint) {\n\t\tconst index = Math.abs(tilePoint.x + tilePoint.y) % this.options.subdomains.length;\n\t\treturn this.options.subdomains[index];\n\t}\n\n\t// stops loading all tiles in the background layer\n\t_abortLoading() {\n\t\tlet i, tile;\n\t\tfor (i of Object.keys(this._tiles)) {\n\t\t\tif (this._tiles[i].coords.z !== this._tileZoom) {\n\t\t\t\ttile = this._tiles[i].el;\n\n\t\t\t\ttile.onload = Util.falseFn;\n\t\t\t\ttile.onerror = Util.falseFn;\n\n\t\t\t\tif (this._abortTileFetch(tile) || !tile.complete) {\n\t\t\t\t\ttile.setAttribute('src', '');\n\t\t\t\t\tconst coords = this._tiles[i].coords;\n\t\t\t\t\ttile.remove();\n\t\t\t\t\tdelete this._tiles[i];\n\t\t\t\t\tthis.fire('tileabort', {\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\tcoords\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t_removeTile(key) {\n\t\tconst tile = this._tiles[key];\n\t\tif (!tile) { return; }\n\n\t\t// Cancels any pending http requests associated with the tile\n\t\tthis._abortTileFetch(tile.el);\n\t\ttile.el.setAttribute('src', '');\n\n\t\treturn super._removeTile(key);\n\t}\n\n\t_tileReady(coords, err, tile) {\n\t\tif (!this._map || (tile && tile.getAttribute('src') === '')) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn super._tileReady(coords, err, tile);\n\t}\n\n\t_clampZoom(zoom) {\n\t\treturn Math.round(super._clampZoom(zoom));\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,IAAa,YAAb,MAAa,kBAAkB,UAAU;CAExC;EACC,KAAK,kBAAkB;GACtB,SAAS;GACT,SAAS;GACT,YAAY;GACZ,cAAc;GACd,YAAY;GACZ,KAAK;GACL,aAAa;GACb,cAAc;GACd,aAAa;GACb,gBAAgB;GAChB,cAAc;EAEf,CAAC;CACF;;;;;;;;CASA,YAAY,KAAK,SAAS;EACzB,MAAM,OAAO;EAEb,KAAK,OAAO;EAEZ,UAAUA,WAAgB,MAAM,OAAO;EAGvC,MAAM,UAAU,IAAI,IAAI,KAAK,MAAM,SAAS,IAAI;EAChD,MAAM,cAAc,QAAQ;EAE5B,IAAI,CADc,0BAA0B,cACjC,CAAC,CAAC,MAAK,SAAQ,YAAY,SAAS,IAAI,CAAC,GAAG;GACtD,IAAI,QAAQ,gBAAgB,MAC3B,QAAQ,cAAc,4DAA4D,KAAK,UAAU,4BAA4B,EAAE;GAEhI,IAAI,QAAQ,aAAa,SAAS;IACjC,QAAQ,WAAW;IACnB,KAAK,OAAO,QAAQ,SAAS;GAC9B;EACD;EAEA,MA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CAC7B;CAEA,WAAW,QAAQ,KAAK,MAAM;EAC7B,IAAI,CAAC,KAAK,QAAS,QAAQ,KAAK,aAAa,KAAK,MAAM,IACvD;EAGD,OAAO,MAAM,WAAW,QAAQ,KAAK,IAAI;CAC1C;CAEA,WAAW,MAAM;EAChB,OAAO,KAAK,MAAM,MAAM,WAAW,IAAI,CAAC;CACzC;AACD"}
1
+ {"version":3,"file":"TileLayer.js","names":["Util.setOptions","Util.template"],"sources":["../../../../src/layer/tile/TileLayer.js"],"sourcesContent":["import {GridLayer} from './GridLayer.js';\nimport * as Util from '../../core/Util.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {I18n} from '../../core/I18n.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {GridLayerOptions, TileDoneCallback} from './GridLayer.js' */\n/** @import {TileEvent} from '../../core/Events.js' */\n\nconst osmHosts = ['tile.openstreetmap.org', 'tile.osm.org'];\nconst hostRe = /^(https?:)?\\/\\/([^/?#:]*)/i;\nconst httpRe = /^http:/i;\n\nfunction isOSMUrl(url) {\n\tconst host = hostRe.exec(url)?.[2] ?? '';\n\treturn osmHosts.some(osmHost => host === osmHost || host.endsWith(`.${osmHost}`));\n}\n\n// OSM tiles are upgraded to HTTPS so that the referrer policy works\nconst upgradeOSMUrl = url => (isOSMUrl(url) ? url.replace(httpRe, 'https:') : url);\n\n/**\n * Options of `TileLayer`.\n * @typedef {object} TileLayerOptions\n * @property {number} [minZoom=0] The minimum zoom level down to which this layer will be\n * displayed (inclusive).\n * @property {number} [maxZoom=18] The maximum zoom level up to which this layer will be\n * displayed (inclusive).\n * @property {string|string[]} [subdomains='abc'] Subdomains of the tile service. Can be\n * passed in the form of one string (where each letter is a subdomain name) or an array\n * of strings.\n * @property {string} [errorTileUrl=''] URL to the tile image to show in place of the\n * tile that failed to load.\n * @property {number} [zoomOffset=0] The zoom number used in tile URLs will be offset\n * with this value.\n * @property {boolean} [tms=false] If `true`, inverses Y axis numbering for tiles (turn\n * this on for [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services).\n * @property {boolean} [zoomReverse=false] If set to true, the zoom number used in tile\n * URLs will be reversed (`maxZoom - zoom` instead of `zoom`).\n * @property {boolean} [detectRetina=false] If `true` and user is on a retina display, it\n * will request four tiles of half the specified size and a bigger zoom level in place\n * of one to utilize the high resolution.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute will\n * be added to the tiles. If a String is provided, all tiles will have their crossOrigin\n * attribute set to the String provided. This is needed if you want to access tile pixel\n * data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {ReferrerPolicy} [referrerPolicy='strict-origin-when-cross-origin'] Sets the\n * tiles' `referrerPolicy` attribute set to the String provided. See\n * [`HTMLImageElement.referrerPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy)\n * for possible values.\n *\n * Tile providers might require you to use a specific referrer policy (e.g. to verify\n * API tokens or prevent abuse). Specifically, if you are using tiles from\n * `tile.openstreetmap.org` or `tile.osm.org`, you\n * [should not change this value](https://operations.osmfoundation.org/policies/tiles/).\n * @property {RequestInit|null} [fetchOptions=null] If set, the tiles are loaded with\n * [`fetch()`](https://developer.mozilla.org/docs/Web/API/Window/fetch) using these\n * options (see [`RequestInit`](https://developer.mozilla.org/docs/Web/API/RequestInit)),\n * e.g. `{headers: {Authorization: 'Bearer …'}}` for tile servers requiring custom HTTP\n * headers. Requests of tiles that are no longer needed (e.g. after panning or zooming\n * away) are aborted. Cross-origin tile servers have to allow such requests with\n * [CORS](https://developer.mozilla.org/docs/Web/HTTP/CORS) headers.\n * @extends GridLayerOptions\n */\n\n/**\n * Used to load and display tile layers on the map. Note that most tile servers require\n * attribution, which you can set under `Layer`. Extends `GridLayer`.\n *\n * ### URL template\n *\n * A string of the following form:\n *\n * ```\n * 'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png'\n * ```\n *\n * `{s}` means one of the available subdomains (used sequentially to help with browser\n * parallel requests per domain limitation; subdomain values are specified in options;\n * `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` —\n * tile coordinates. `{r}` can be used to add \"@2x\" to the URL to load retina tiles.\n *\n * You can use custom keys in the template, which will be [evaluated](#util-template)\n * from TileLayer options, like this:\n *\n * ```\n * new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'});\n * ```\n *\n * Layers extending `TileLayer` might reimplement the [`getTileUrl()`](#tilelayer-gettileurl)\n * method.\n *\n * @example\n * ```js\n * new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: '© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap contributors</a>'}).addTo(map);\n * ```\n *\n * @fires tileabort {TileEvent} Fired when a tile was loading but is now not wanted.\n */\nexport class TileLayer extends GridLayer {\n\n\tstatic defaultOptions = {\n\t\tminZoom: 0,\n\t\tmaxZoom: 18,\n\t\tsubdomains: 'abc',\n\t\terrorTileUrl: '',\n\t\tzoomOffset: 0,\n\t\ttms: false,\n\t\tzoomReverse: false,\n\t\tdetectRetina: false,\n\t\tcrossOrigin: false,\n\t\treferrerPolicy: 'strict-origin-when-cross-origin',\n\t\tfetchOptions: null\n\n\t};\n\n\t/**\n\t * Instantiates a tile layer object given a [URL template](#tilelayer) and optionally an\n\t * options object.\n\t * @param {string} url The URL template.\n\t * @param {TileLayerOptions & Record<string, unknown>} [options] The options, and the values\n\t * of custom keys of the URL template.\n\t */\n\tconstructor(url, options) {\n\t\tsuper(options);\n\n\t\toptions = Util.setOptions(this, options);\n\n\t\t// Set required OpenStreetMap attribution if it hasn't been specified\n\t\tif (isOSMUrl(url) && options.attribution === null) {\n\t\t\toptions.attribution = `&copy; <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`;\n\t\t}\n\t\tthis._url = upgradeOSMUrl(url);\n\n\t\tconst {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom} = this.options;\n\t\tthis._nonRetinaOptions = {tileSize, zoomOffset, minZoom, maxZoom, minNativeZoom, maxNativeZoom};\n\t\tthis._applyRetina();\n\n\t\tif (typeof this.options.subdomains === 'string') {\n\t\t\tthis.options.subdomains = this.options.subdomains.split('');\n\t\t}\n\n\t\tthis.callInitHooks(TileLayer);\n\t}\n\n\t// Detects retina displays (if `detectRetina` is set), adjusting tileSize and zoom levels.\n\t_applyRetina() {\n\t\tObject.assign(this.options, this._nonRetinaOptions);\n\t\tthis._retina = window.devicePixelRatio > 1;\n\n\t\tif (this.options.detectRetina && this._retina && this.options.maxZoom > 0) {\n\n\t\t\tconst tileSize = this.options.tileSize;\n\t\t\tthis.options.tileSize = tileSize instanceof Point ? tileSize.divideBy(2).floor() : Math.floor(tileSize / 2);\n\n\t\t\tif (!this.options.zoomReverse) {\n\t\t\t\tthis.options.zoomOffset++;\n\t\t\t\tthis.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom - 1);\n\t\t\t\t// do not request tiles beyond the native zoom levels\n\t\t\t\tif (this.options.maxNativeZoom !== undefined) {\n\t\t\t\t\tthis.options.maxNativeZoom = Math.max(0, this.options.maxNativeZoom - 1);\n\t\t\t\t}\n\t\t\t\tif (this.options.minNativeZoom !== undefined) {\n\t\t\t\t\tthis.options.minNativeZoom = Math.max(0, this.options.minNativeZoom - 1);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.options.zoomOffset--;\n\t\t\t\tthis.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom + 1);\n\t\t\t}\n\n\t\t\tthis.options.minZoom = Math.max(0, this.options.minZoom);\n\t\t} else if (!this.options.zoomReverse) {\n\t\t\t// make sure maxZoom is gte minZoom\n\t\t\tthis.options.maxZoom = Math.max(this.options.minZoom, this.options.maxZoom);\n\t\t} else {\n\t\t\t// make sure minZoom is lte maxZoom\n\t\t\tthis.options.minZoom = Math.min(this.options.maxZoom, this.options.minZoom);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the layer listens to, see `Layer`.\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.pixelratiochange = this._onPixelRatioChange;\n\t\treturn events;\n\t}\n\n\t// Loads the tiles for the new resolution, see the map's `pixelratiochange` event.\n\t_onPixelRatioChange() {\n\t\tif ((window.devicePixelRatio > 1) === this._retina) { return; }\n\t\tconst map = this._map;\n\t\tthis._applyRetina();\n\t\tif (this.options.detectRetina) {\n\t\t\tmap._removeZoomLimit(this);\n\t\t\tmap._addZoomLimit(this);\n\t\t\tthis._invalidateAll();\n\t\t\tthis._resetView();\n\t\t} else if (this._url.includes('{r}')) {\n\t\t\tthis.redraw();\n\t\t}\n\t}\n\n\t/**\n\t * Updates the layer's URL template and redraws it (unless `noRedraw` is set to `true`).\n\t * If the URL does not change, the layer will not be redrawn unless\n\t * the noRedraw parameter is set to false.\n\t * The current tiles stay visible until the new tiles have loaded, to avoid flickering.\n\t * @param {string} url\n\t * @param {boolean} [noRedraw]\n\t * @returns {this}\n\t */\n\tsetUrl(url, noRedraw) {\n\t\turl = upgradeOSMUrl(url);\n\n\t\tif (this._url === url && noRedraw === undefined) {\n\t\t\tnoRedraw = true;\n\t\t}\n\n\t\tthis._url = url;\n\n\t\tif (!noRedraw) {\n\t\t\tthis._keepCurrentTiles();\n\t\t\tthis.redraw();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Called only internally, overrides GridLayer's [`createTile()`](#gridlayer-createtile)\n\t * to return an `<img>` HTML element with the appropriate image URL given `coords`. The\n\t * `done` callback is called when the tile has been loaded.\n\t * @param {Point} coords\n\t * @param {TileDoneCallback} [done]\n\t * @returns {HTMLImageElement}\n\t */\n\tcreateTile(coords, done) {\n\t\tconst tile = document.createElement('img');\n\n\t\tDomEvent.on(tile, 'load', this._tileOnLoad.bind(this, done, tile));\n\t\tDomEvent.on(tile, 'error', this._tileOnError.bind(this, done, tile));\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\ttile.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\t// for this new option we follow the documented behavior\n\t\t// more closely by only setting the property when string\n\t\tif (typeof this.options.referrerPolicy === 'string') {\n\t\t\ttile.referrerPolicy = this.options.referrerPolicy;\n\t\t}\n\n\t\t// The alt attribute is set to the empty string,\n\t\t// allowing screen readers to ignore the decorative image tiles.\n\t\t// https://www.w3.org/WAI/tutorials/images/decorative/\n\t\t// https://www.w3.org/TR/html-aria/#el-img-empty-alt\n\t\ttile.alt = '';\n\n\t\tconst url = this.getTileUrl(coords);\n\t\tif (this.options.fetchOptions) {\n\t\t\tthis._fetchTile(tile, url, done);\n\t\t} else {\n\t\t\ttile.src = url;\n\t\t}\n\n\t\treturn tile;\n\t}\n\n\t// Loads the tile image with `fetch()`, see the `fetchOptions` option.\n\t_fetchTile(tile, url, done) {\n\t\tconst controller = new AbortController(),\n\t\toptions = {signal: controller.signal, ...this.options.fetchOptions};\n\t\tif (typeof this.options.referrerPolicy === 'string') {\n\t\t\toptions.referrerPolicy ??= this.options.referrerPolicy;\n\t\t}\n\n\t\tthis._tileFetches ??= new Map();\n\t\tthis._tileFetches.set(tile, controller);\n\n\t\tfetch(url, options)\n\t\t\t.then((response) => {\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`Failed to load the tile ${url}: HTTP ${response.status}`);\n\t\t\t\t}\n\t\t\t\treturn response.blob();\n\t\t\t})\n\t\t\t.then((blob) => {\n\t\t\t\t// revoked in `_tileOnLoad()`\n\t\t\t\ttile.src = URL.createObjectURL(blob);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tif (!controller.signal.aborted) {\n\t\t\t\t\tthis._tileOnError(done, tile, error);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => this._tileFetches.delete(tile));\n\t}\n\n\t// Aborts the request of a tile loaded with `fetch()`, returns whether there was one.\n\t_abortTileFetch(tile) {\n\t\tconst controller = this._tileFetches?.get(tile);\n\t\tif (!controller) { return false; }\n\t\tcontroller.abort();\n\t\tthis._tileFetches.delete(tile);\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called only internally, returns the URL for a tile given its coordinates.\n\t * Classes extending `TileLayer` can override this function to provide custom tile URL\n\t * naming schemes.\n\t * @group Extension methods\n\t * @param {Point} coords\n\t * @returns {string}\n\t */\n\tgetTileUrl(coords) {\n\t\tconst data = Object.create(this.options);\n\t\tObject.assign(data, {\n\t\t\tr: window.devicePixelRatio > 1 ? '@2x' : '',\n\t\t\ts: this._getSubdomain(coords),\n\t\t\tx: coords.x,\n\t\t\ty: coords.y,\n\t\t\tz: this._getZoomForUrl()\n\t\t});\n\t\tif (this._map && !this._map.options.crs.infinite) {\n\t\t\tconst invertedY = this._globalTileRange.max.y - coords.y;\n\t\t\tif (this.options.tms) {\n\t\t\t\tdata['y'] = invertedY;\n\t\t\t}\n\t\t\tdata['-y'] = invertedY;\n\t\t}\n\n\t\treturn Util.template(this._url, data);\n\t}\n\n\t_tileOnLoad(done, tile) {\n\t\tif (tile.src.startsWith('blob:')) {\n\t\t\t// the image keeps its data, see `_fetchTile()`\n\t\t\tURL.revokeObjectURL(tile.src);\n\t\t}\n\t\tdone(null, tile);\n\t}\n\n\t_tileOnError(done, tile, e) {\n\t\tconst errorUrl = this.options.errorTileUrl,\n\t\tsrc = tile.getAttribute('src');\n\t\t// removed tiles get an empty src to cancel their request, which fires error too\n\t\tif (errorUrl && src !== errorUrl && (src || tile.isConnected)) {\n\t\t\ttile.src = errorUrl;\n\t\t}\n\t\tdone(e, tile);\n\t}\n\n\t_getZoomForUrl() {\n\t\tlet zoom = this._tileZoom;\n\t\tconst maxZoom = this.options.maxZoom,\n\t\tzoomReverse = this.options.zoomReverse,\n\t\tzoomOffset = this.options.zoomOffset;\n\n\t\tif (zoomReverse) {\n\t\t\tzoom = maxZoom - zoom;\n\t\t}\n\n\t\treturn zoom + zoomOffset;\n\t}\n\n\t_getSubdomain(tilePoint) {\n\t\tconst {subdomains} = this.options;\n\t\treturn subdomains?.[Math.abs(tilePoint.x + tilePoint.y) % subdomains.length];\n\t}\n\n\t// stops loading all tiles in the background layer\n\t_abortLoading() {\n\t\tlet i, tile;\n\t\tfor (i of Object.keys(this._tiles)) {\n\t\t\tif (this._tiles[i].coords.z !== this._tileZoom) {\n\t\t\t\ttile = this._tiles[i].el;\n\n\t\t\t\tif (this._abortTileFetch(tile) || !tile.complete) {\n\t\t\t\t\ttile.setAttribute('src', '');\n\t\t\t\t\tconst coords = this._tiles[i].coords;\n\t\t\t\t\ttile.remove();\n\t\t\t\t\tdelete this._tiles[i];\n\t\t\t\t\tthis.fire('tileabort', {\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\tcoords\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t_removeTile(key) {\n\t\tconst tile = this._tiles[key];\n\t\tif (!tile) { return; }\n\n\t\t// Cancels any pending http requests associated with the tile\n\t\tthis._abortTileFetch(tile.el);\n\t\ttile.el.setAttribute('src', '');\n\n\t\treturn super._removeTile(key);\n\t}\n\n\t_tileReady(coords, err, tile) {\n\t\tif (!this._map || (tile && tile.getAttribute('src') === '')) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn super._tileReady(coords, err, tile);\n\t}\n\n\t_clampZoom(zoom) {\n\t\treturn Math.round(super._clampZoom(zoom));\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,WAAW,CAAC,0BAA0B,cAAc;AAC1D,MAAM,SAAS;AACf,MAAM,SAAS;AAEf,SAAS,SAAS,KAAK;CACtB,MAAM,OAAO,OAAO,KAAK,GAAG,CAAC,GAAG,MAAM;CACtC,OAAO,SAAS,MAAK,YAAW,SAAS,WAAW,KAAK,SAAS,IAAI,SAAS,CAAC;AACjF;AAGA,MAAM,iBAAgB,QAAQ,SAAS,GAAG,IAAI,IAAI,QAAQ,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,KAAK,KAAK,OAAO,KAAK,KAAK,MAAM,GAChC,IAAI,KAAK,OAAO,EAAE,CAAC,OAAO,MAAM,KAAK,WAAW;GAC/C,OAAO,KAAK,OAAO,EAAE,CAAC;GAEtB,IAAI,KAAK,gBAAgB,IAAI,KAAK,CAAC,KAAK,UAAU;IACjD,KAAK,aAAa,OAAO,EAAE;IAC3B,MAAM,SAAS,KAAK,OAAO,EAAE,CAAC;IAC9B,KAAK,OAAO;IACZ,OAAO,KAAK,OAAO;IACnB,KAAK,KAAK,aAAa;KACtB;KACA;IACD,CAAC;GACF;EACD;CAEF;CAEA,YAAY,KAAK;EAChB,MAAM,OAAO,KAAK,OAAO;EACzB,IAAI,CAAC,MAAQ;EAGb,KAAK,gBAAgB,KAAK,EAAE;EAC5B,KAAK,GAAG,aAAa,OAAO,EAAE;EAE9B,OAAO,MAAM,YAAY,GAAG;CAC7B;CAEA,WAAW,QAAQ,KAAK,MAAM;EAC7B,IAAI,CAAC,KAAK,QAAS,QAAQ,KAAK,aAAa,KAAK,MAAM,IACvD;EAGD,OAAO,MAAM,WAAW,QAAQ,KAAK,IAAI;CAC1C;CAEA,WAAW,MAAM;EAChB,OAAO,KAAK,MAAM,MAAM,WAAW,IAAI,CAAC;CACzC;AACD"}
@@ -1,8 +1,7 @@
1
- import Browser_default from "../../core/Browser.js";
2
1
  import { Bounds } from "../../geometry/Bounds.js";
3
2
  import { EPSG4326 } from "../../geo/crs/EPSG4326.js";
4
3
  import { TileLayer } from "./TileLayer.js";
5
- //#region src/layer/tile/WMSTileLayer.js
4
+ // src/layer/tile/WMSTileLayer.js
6
5
  /** @import {CRS} from '../../geo/crs/CRS.js' */
7
6
  /** @import {Point} from '../../geometry/Point.js' */
8
7
  /** @import {MaplairMap} from '../../map/Map.js' */
@@ -42,21 +41,23 @@ import { TileLayer } from "./TileLayer.js";
42
41
  * ```
43
42
  */
44
43
  var WMSTileLayer = class WMSTileLayer extends TileLayer {
45
- static {
46
- this.prototype.defaultWmsParams = {
47
- service: "WMS",
48
- request: "GetMap",
49
- layers: "",
50
- styles: "",
51
- format: "image/jpeg",
52
- transparent: false,
53
- version: "1.1.1"
54
- };
55
- this.setDefaultOptions({
56
- crs: null,
57
- uppercase: false
58
- });
59
- }
44
+ /**
45
+ * The default WMS parameters, which the options override, see `WMSTileLayerOptions`.
46
+ * @type {Record<string, any>}
47
+ */
48
+ static defaultWmsParams = {
49
+ service: "WMS",
50
+ request: "GetMap",
51
+ layers: "",
52
+ styles: "",
53
+ format: "image/jpeg",
54
+ transparent: false,
55
+ version: "1.1.1"
56
+ };
57
+ static defaultOptions = {
58
+ crs: null,
59
+ uppercase: false
60
+ };
60
61
  /**
61
62
  * Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS
62
63
  * parameters/options object.
@@ -66,8 +67,8 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
66
67
  */
67
68
  constructor(url, options) {
68
69
  super(url, options);
69
- const wmsParams = { ...this.defaultWmsParams };
70
- for (const [key, value] of Object.entries(options)) if (!(key in WMSTileLayer.prototype.options)) wmsParams[key] = value;
70
+ const wmsParams = { ...WMSTileLayer.defaultWmsParams };
71
+ for (const [key, value] of Object.entries(options)) if (!(key in WMSTileLayer.defaultOptions)) wmsParams[key] = value;
71
72
  /**
72
73
  * The parameters of the WMS requests, see `setParams()`.
73
74
  * @type {Record<string, any>}
@@ -77,7 +78,7 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
77
78
  this.callInitHooks(WMSTileLayer);
78
79
  }
79
80
  _updateWmsSize() {
80
- const realRetina = this.options.detectRetina && Browser_default.retina ? 2 : 1;
81
+ const realRetina = this.options.detectRetina && window.devicePixelRatio > 1 ? 2 : 1;
81
82
  const tileSize = this.getTileSize();
82
83
  this.wmsParams.width = tileSize.x * realRetina;
83
84
  this.wmsParams.height = tileSize.y * realRetina;
@@ -97,8 +98,9 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
97
98
  _updateCrs() {
98
99
  this._crs = this.options.crs ?? this._map.options.crs;
99
100
  this._wmsVersion = parseFloat(this.wmsParams.version);
100
- const projectionKey = this._wmsVersion >= 1.3 ? "crs" : "srs";
101
- this.wmsParams[projectionKey] = this._crs.code;
101
+ delete this.wmsParams.srs;
102
+ delete this.wmsParams.crs;
103
+ this.wmsParams[this._wmsVersion >= 1.3 ? "crs" : "srs"] = this._crs.code;
102
104
  }
103
105
  /**
104
106
  * Returns the map events the layer listens to, see `Layer`.
@@ -128,11 +130,11 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
128
130
  max.x,
129
131
  max.y
130
132
  ]).join(",");
131
- const url = new URL(super.getTileUrl(coords));
133
+ const url = new URL(super.getTileUrl(coords), document.baseURI);
132
134
  for (const [k, v] of Object.entries({
133
135
  ...this.wmsParams,
134
136
  bbox
135
- })) url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v);
137
+ })) url.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);
136
138
  return url.toString();
137
139
  }
138
140
  /**
@@ -159,18 +161,22 @@ var WMSTileLayer = class WMSTileLayer extends TileLayer {
159
161
  }
160
162
  /**
161
163
  * Merges an object with the new parameters and re-requests tiles on the current screen
162
- * (unless `noRedraw` was set to true).
164
+ * (unless `noRedraw` was set to true). The current tiles stay visible until the new
165
+ * tiles have loaded, to avoid flickering.
163
166
  * @param {Record<string, any>} params
164
167
  * @param {boolean} [noRedraw]
165
168
  * @returns {this}
166
169
  */
167
170
  setParams(params, noRedraw) {
168
171
  Object.assign(this.wmsParams, params);
169
- if (!noRedraw) this.redraw();
172
+ if (this._map) this._updateCrs();
173
+ if (!noRedraw) {
174
+ this._keepCurrentTiles();
175
+ this.redraw();
176
+ }
170
177
  return this;
171
178
  }
172
179
  };
173
- //#endregion
174
180
  export { WMSTileLayer };
175
181
 
176
182
  //# sourceMappingURL=WMSTileLayer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WMSTileLayer.js","names":["Browser"],"sources":["../../../../src/layer/tile/WMSTileLayer.js"],"sourcesContent":["import {TileLayer} from './TileLayer.js';\nimport Browser from '../../core/Browser.js';\nimport {EPSG4326} from '../../geo/crs/EPSG4326.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {CRS} from '../../geo/crs/CRS.js' */\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {TileLayerOptions} from './TileLayer.js' */\n\n/**\n * Options of `WMSTileLayer`. If any custom options not documented here are used, they\n * will be sent to the WMS server as extra parameters in each request URL. This can be\n * useful for\n * [non-standard vendor WMS parameters](https://docs.geoserver.org/stable/en/user/services/wms/vendor.html).\n * @typedef {object} WMSTileLayerOptions\n * @property {string} [layers=''] **(required)** Comma-separated list of WMS layers to\n * show.\n * @property {string} [styles=''] Comma-separated list of WMS styles.\n * @property {string} [format='image/jpeg'] WMS image format (use `'image/png'` for\n * layers with transparency).\n * @property {boolean} [transparent=false] If `true`, the WMS service will return images\n * with transparency.\n * @property {string} [version='1.1.1'] Version of the WMS service to use.\n * @property {CRS|null} [crs=null] Coordinate Reference System to use for the WMS\n * requests, defaults to map CRS. Don't change this if you're not sure what it means.\n * @property {boolean} [uppercase=false] If `true`, WMS request parameter keys will be\n * uppercase.\n * @extends TileLayerOptions\n */\n\n/**\n * Used to display [WMS](https://en.wikipedia.org/wiki/Web_Map_Service) services as tile\n * layers on the map. Extends `TileLayer`.\n *\n * @example\n * ```js\n * const nexrad = new WMSTileLayer(\"http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi\", {\n * \tlayers: 'nexrad-n0r-900913',\n * \tformat: 'image/png',\n * \ttransparent: true,\n * \tattribution: \"Weather data © 2012 IEM Nexrad\"\n * });\n * ```\n */\nexport class WMSTileLayer extends TileLayer {\n\n\tstatic {\n\t\t// the WMS parameters among the options, see `WMSTileLayerOptions`\n\t\tthis.prototype.defaultWmsParams = {\n\t\t\tservice: 'WMS',\n\t\t\trequest: 'GetMap',\n\t\t\tlayers: '',\n\t\t\tstyles: '',\n\t\t\tformat: 'image/jpeg',\n\t\t\ttransparent: false,\n\t\t\tversion: '1.1.1'\n\t\t};\n\n\t\tthis.setDefaultOptions({\n\t\t\tcrs: null,\n\t\t\tuppercase: false\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS\n\t * parameters/options object.\n\t * @param {string} url The base URL of the WMS service.\n\t * @param {WMSTileLayerOptions & Record<string, unknown>} options The options and WMS\n\t * parameters.\n\t */\n\tconstructor(url, options) {\n\t\tsuper(url, options);\n\n\t\tconst wmsParams = {...this.defaultWmsParams};\n\n\t\t// Options that are unknown in the prototype chain are considered WMS params.\n\t\tfor (const [key, value] of Object.entries(options)) {\n\t\t\tif (!(key in WMSTileLayer.prototype.options)) {\n\t\t\t\twmsParams[key] = value;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * The parameters of the WMS requests, see `setParams()`.\n\t\t * @type {Record<string, any>}\n\t\t */\n\t\tthis.wmsParams = wmsParams;\n\t\tthis._updateWmsSize();\n\n\t\tthis.callInitHooks(WMSTileLayer);\n\t}\n\n\t// The size of the requested images: the tile size, doubled on retina displays with `detectRetina`.\n\t_updateWmsSize() {\n\t\tconst realRetina = this.options.detectRetina && Browser.retina ? 2 : 1;\n\t\tconst tileSize = this.getTileSize();\n\n\t\tthis.wmsParams.width = tileSize.x * realRetina;\n\t\tthis.wmsParams.height = tileSize.y * realRetina;\n\t}\n\n\t_applyRetina() {\n\t\tsuper._applyRetina();\n\t\tif (this.wmsParams) {\n\t\t\tthis._updateWmsSize();\n\t\t}\n\t}\n\n\t/**\n\t * Uses the CRS of the map (unless the `crs` option is set) and loads the tiles.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._updateCrs();\n\t\tsuper.onAdd(map);\n\t}\n\n\t_updateCrs() {\n\t\tthis._crs = this.options.crs ?? this._map.options.crs;\n\t\tthis._wmsVersion = parseFloat(this.wmsParams.version);\n\n\t\tconst projectionKey = this._wmsVersion >= 1.3 ? 'crs' : 'srs';\n\t\tthis.wmsParams[projectionKey] = this._crs.code;\n\t}\n\n\t/**\n\t * Returns the map events the layer listens to, see `Layer`.\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.crschange = this._updateCrs;\n\t\treturn events;\n\t}\n\n\t/**\n\t * Called only internally, returns the URL of the `GetMap` request for a tile given its\n\t * coordinates.\n\t * @group Extension methods\n\t * @param {Point} coords\n\t * @returns {string}\n\t */\n\tgetTileUrl(coords) {\n\n\t\tconst tileBounds = this._tileCoordsToNwSe(coords),\n\t\tcrs = this._crs,\n\t\tbounds = new Bounds(crs.project(tileBounds[0]), crs.project(tileBounds[1])),\n\t\tmin = bounds.min,\n\t\tmax = bounds.max,\n\t\tbbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ?\n\t\t\t[min.y, min.x, max.y, max.x] :\n\t\t\t[min.x, min.y, max.x, max.y]).join(',');\n\t\tconst url = new URL(super.getTileUrl(coords));\n\t\tfor (const [k, v] of Object.entries({...this.wmsParams, bbox})) {\n\t\t\turl.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, v);\n\t\t}\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Returns the URL of the legend image (a `GetLegendGraphic` request) of the first\n\t * of the `layers` (with its style, if any), with the version, format and `uppercase`\n\t * option of the layer. `params` change or add parameters, e.g. `{layer: 'roads',\n\t * width: 20, height: 20}` or vendor parameters like `legend_options`.\n\t * @param {Record<string, any>} [params]\n\t * @returns {string}\n\t */\n\tgetLegendUrl(params) {\n\t\tconst {version, format, layers, styles} = this.wmsParams,\n\t\turl = new URL(this._url, document.baseURI);\n\t\tfor (const [k, v] of Object.entries({\n\t\t\tservice: 'WMS',\n\t\t\trequest: 'GetLegendGraphic',\n\t\t\tversion,\n\t\t\tformat,\n\t\t\tlayer: layers.split(',')[0],\n\t\t\tstyle: styles?.split(',')[0] || undefined,\n\t\t\t// required by the WMS 1.3 profile of SLD\n\t\t\tsld_version: parseFloat(version) >= 1.3 ? '1.1.0' : undefined,\n\t\t\t...params\n\t\t})) {\n\t\t\tif (v !== undefined) {\n\t\t\t\turl.searchParams.set(this.options.uppercase ? k.toUpperCase() : k, v);\n\t\t\t}\n\t\t}\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Merges an object with the new parameters and re-requests tiles on the current screen\n\t * (unless `noRedraw` was set to true).\n\t * @param {Record<string, any>} params\n\t * @param {boolean} [noRedraw]\n\t * @returns {this}\n\t */\n\tsetParams(params, noRedraw) {\n\n\t\tObject.assign(this.wmsParams, params);\n\n\t\tif (!noRedraw) {\n\t\t\tthis.redraw();\n\t\t}\n\n\t\treturn this;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,eAAb,MAAa,qBAAqB,UAAU;CAE3C;EAEC,KAAK,UAAU,mBAAmB;GACjC,SAAS;GACT,SAAS;GACT,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,aAAa;GACb,SAAS;EACV;EAEA,KAAK,kBAAkB;GACtB,KAAK;GACL,WAAW;EACZ,CAAC;CACF;;;;;;;;CASA,YAAY,KAAK,SAAS;EACzB,MAAM,KAAK,OAAO;EAElB,MAAM,YAAY,EAAC,GAAG,KAAK,iBAAgB;EAG3C,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAChD,IAAI,EAAE,OAAO,aAAa,UAAU,UACnC,UAAU,OAAO;;;;;EAQnB,KAAK,YAAY;EACjB,KAAK,eAAe;EAEpB,KAAK,cAAc,YAAY;CAChC;CAGA,iBAAiB;EAChB,MAAM,aAAa,KAAK,QAAQ,gBAAgBA,gBAAQ,SAAS,IAAI;EACrE,MAAM,WAAW,KAAK,YAAY;EAElC,KAAK,UAAU,QAAQ,SAAS,IAAI;EACpC,KAAK,UAAU,SAAS,SAAS,IAAI;CACtC;CAEA,eAAe;EACd,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ACnC,SAAS;GACT,SAAS;GACT;GACA;GACA,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;GACzB,OAAO,QAAQ,MAAM,GAAG,CAAC,CAAC,MAAM,KAAA;GAEhC,aAAa,WAAW,OAAO,KAAK,MAAM,UAAU,KAAA;GACpD,GAAG;EACJ,CAAC,GACA,IAAI,MAAM,KAAA,GACT,IAAI,aAAa,IAAI,KAAK,QAAQ,YAAY,EAAE,YAAY,IAAI,GAAG,CAAC;EAGtE,OAAO,IAAI,SAAS;CACrB;;;;;;;;CASA,UAAU,QAAQ,UAAU;EAE3B,OAAO,OAAO,KAAK,WAAW,MAAM;EAEpC,IAAI,CAAC,UACJ,KAAK,OAAO;EAGb,OAAO;CACR;AACD"}
1
+ {"version":3,"file":"WMSTileLayer.js","names":[],"sources":["../../../../src/layer/tile/WMSTileLayer.js"],"sourcesContent":["import {TileLayer} from './TileLayer.js';\nimport {EPSG4326} from '../../geo/crs/EPSG4326.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {CRS} from '../../geo/crs/CRS.js' */\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {TileLayerOptions} from './TileLayer.js' */\n\n/**\n * Options of `WMSTileLayer`. If any custom options not documented here are used, they\n * will be sent to the WMS server as extra parameters in each request URL. This can be\n * useful for\n * [non-standard vendor WMS parameters](https://docs.geoserver.org/stable/en/user/services/wms/vendor.html).\n * @typedef {object} WMSTileLayerOptions\n * @property {string} [layers=''] **(required)** Comma-separated list of WMS layers to\n * show.\n * @property {string} [styles=''] Comma-separated list of WMS styles.\n * @property {string} [format='image/jpeg'] WMS image format (use `'image/png'` for\n * layers with transparency).\n * @property {boolean} [transparent=false] If `true`, the WMS service will return images\n * with transparency.\n * @property {string} [version='1.1.1'] Version of the WMS service to use.\n * @property {CRS|null} [crs=null] Coordinate Reference System to use for the WMS\n * requests, defaults to map CRS. Don't change this if you're not sure what it means.\n * @property {boolean} [uppercase=false] If `true`, WMS request parameter keys will be\n * uppercase.\n * @extends TileLayerOptions\n */\n\n/**\n * Used to display [WMS](https://en.wikipedia.org/wiki/Web_Map_Service) services as tile\n * layers on the map. Extends `TileLayer`.\n *\n * @example\n * ```js\n * const nexrad = new WMSTileLayer(\"http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi\", {\n * \tlayers: 'nexrad-n0r-900913',\n * \tformat: 'image/png',\n * \ttransparent: true,\n * \tattribution: \"Weather data © 2012 IEM Nexrad\"\n * });\n * ```\n */\nexport class WMSTileLayer extends TileLayer {\n\n\t/**\n\t * The default WMS parameters, which the options override, see `WMSTileLayerOptions`.\n\t * @type {Record<string, any>}\n\t */\n\tstatic defaultWmsParams = {\n\t\tservice: 'WMS',\n\t\trequest: 'GetMap',\n\t\tlayers: '',\n\t\tstyles: '',\n\t\tformat: 'image/jpeg',\n\t\ttransparent: false,\n\t\tversion: '1.1.1'\n\t};\n\n\tstatic defaultOptions = {\n\t\tcrs: null,\n\t\tuppercase: false\n\t};\n\n\t/**\n\t * Instantiates a WMS tile layer object given a base URL of the WMS service and a WMS\n\t * parameters/options object.\n\t * @param {string} url The base URL of the WMS service.\n\t * @param {WMSTileLayerOptions & Record<string, unknown>} options The options and WMS\n\t * parameters.\n\t */\n\tconstructor(url, options) {\n\t\tsuper(url, options);\n\n\t\tconst wmsParams = {...WMSTileLayer.defaultWmsParams};\n\n\t\t// Options that are unknown in the prototype chain are considered WMS params.\n\t\tfor (const [key, value] of Object.entries(options)) {\n\t\t\tif (!(key in WMSTileLayer.defaultOptions)) {\n\t\t\t\twmsParams[key] = value;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * The parameters of the WMS requests, see `setParams()`.\n\t\t * @type {Record<string, any>}\n\t\t */\n\t\tthis.wmsParams = wmsParams;\n\t\tthis._updateWmsSize();\n\n\t\tthis.callInitHooks(WMSTileLayer);\n\t}\n\n\t// The size of the requested images: the tile size, doubled on retina displays with `detectRetina`.\n\t_updateWmsSize() {\n\t\tconst realRetina = this.options.detectRetina && window.devicePixelRatio > 1 ? 2 : 1;\n\t\tconst tileSize = this.getTileSize();\n\n\t\tthis.wmsParams.width = tileSize.x * realRetina;\n\t\tthis.wmsParams.height = tileSize.y * realRetina;\n\t}\n\n\t_applyRetina() {\n\t\tsuper._applyRetina();\n\t\tif (this.wmsParams) {\n\t\t\tthis._updateWmsSize();\n\t\t}\n\t}\n\n\t/**\n\t * Uses the CRS of the map (unless the `crs` option is set) and loads the tiles.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._updateCrs();\n\t\tsuper.onAdd(map);\n\t}\n\n\t_updateCrs() {\n\t\tthis._crs = this.options.crs ?? this._map.options.crs;\n\t\tthis._wmsVersion = parseFloat(this.wmsParams.version);\n\n\t\tdelete this.wmsParams.srs;\n\t\tdelete this.wmsParams.crs;\n\t\tthis.wmsParams[this._wmsVersion >= 1.3 ? 'crs' : 'srs'] = this._crs.code;\n\t}\n\n\t/**\n\t * Returns the map events the layer listens to, see `Layer`.\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.crschange = this._updateCrs;\n\t\treturn events;\n\t}\n\n\t/**\n\t * Called only internally, returns the URL of the `GetMap` request for a tile given its\n\t * coordinates.\n\t * @group Extension methods\n\t * @param {Point} coords\n\t * @returns {string}\n\t */\n\tgetTileUrl(coords) {\n\n\t\tconst tileBounds = this._tileCoordsToNwSe(coords),\n\t\tcrs = this._crs,\n\t\tbounds = new Bounds(crs.project(tileBounds[0]), crs.project(tileBounds[1])),\n\t\tmin = bounds.min,\n\t\tmax = bounds.max,\n\t\tbbox = (this._wmsVersion >= 1.3 && this._crs === EPSG4326 ?\n\t\t\t[min.y, min.x, max.y, max.x] :\n\t\t\t[min.x, min.y, max.x, max.y]).join(',');\n\t\tconst url = new URL(super.getTileUrl(coords), document.baseURI);\n\t\tfor (const [k, v] of Object.entries({...this.wmsParams, bbox})) {\n\t\t\turl.searchParams.append(this.options.uppercase ? k.toUpperCase() : k, `${v}`);\n\t\t}\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Returns the URL of the legend image (a `GetLegendGraphic` request) of the first\n\t * of the `layers` (with its style, if any), with the version, format and `uppercase`\n\t * option of the layer. `params` change or add parameters, e.g. `{layer: 'roads',\n\t * width: 20, height: 20}` or vendor parameters like `legend_options`.\n\t * @param {Record<string, any>} [params]\n\t * @returns {string}\n\t */\n\tgetLegendUrl(params) {\n\t\tconst {version, format, layers, styles} = this.wmsParams,\n\t\turl = new URL(this._url, document.baseURI);\n\t\tfor (const [k, v] of Object.entries({\n\t\t\tservice: 'WMS',\n\t\t\trequest: 'GetLegendGraphic',\n\t\t\tversion,\n\t\t\tformat,\n\t\t\tlayer: layers.split(',')[0],\n\t\t\tstyle: styles?.split(',')[0] || undefined,\n\t\t\t// required by the WMS 1.3 profile of SLD\n\t\t\tsld_version: parseFloat(version) >= 1.3 ? '1.1.0' : undefined,\n\t\t\t...params\n\t\t})) {\n\t\t\tif (v !== undefined) {\n\t\t\t\turl.searchParams.set(this.options.uppercase ? k.toUpperCase() : k, v);\n\t\t\t}\n\t\t}\n\t\treturn url.toString();\n\t}\n\n\t/**\n\t * Merges an object with the new parameters and re-requests tiles on the current screen\n\t * (unless `noRedraw` was set to true). The current tiles stay visible until the new\n\t * tiles have loaded, to avoid flickering.\n\t * @param {Record<string, any>} params\n\t * @param {boolean} [noRedraw]\n\t * @returns {this}\n\t */\n\tsetParams(params, noRedraw) {\n\n\t\tObject.assign(this.wmsParams, params);\n\n\t\tif (this._map) { this._updateCrs(); }\n\n\t\tif (!noRedraw) {\n\t\t\tthis._keepCurrentTiles();\n\t\t\tthis.redraw();\n\t\t}\n\n\t\treturn this;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,eAAb,MAAa,qBAAqB,UAAU;;;;;CAM3C,OAAO,mBAAmB;EACzB,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
  import { on } from "../../dom/DomEvent.js";
3
3
  import { Bounds } from "../../geometry/Bounds.js";
4
4
  import { Renderer } from "./Renderer.js";
5
- //#region src/layer/vector/Canvas.js
5
+ // src/layer/vector/Canvas.js
6
6
  /** @import {MaplairMap} from '../../map/Map.js' */
7
7
  /** @import {EventListener} from '../../core/Events.js' */
8
8
  /** @import {RendererOptions} from './Renderer.js' */
@@ -37,9 +37,7 @@ const DASH_SEPARATOR_RE = /[, ]+/;
37
37
  * ```
38
38
  */
39
39
  var Canvas = class Canvas extends Renderer {
40
- static {
41
- this.setDefaultOptions({ tolerance: 0 });
42
- }
40
+ static defaultOptions = { tolerance: 0 };
43
41
  /**
44
42
  * Creates a Canvas renderer with the given options.
45
43
  * @overload
@@ -161,10 +159,8 @@ var Canvas = class Canvas extends Renderer {
161
159
  this._requestRedraw(layer);
162
160
  }
163
161
  _updateDashArray(layer) {
164
- if (typeof layer.options.dashArray === "string") {
165
- const parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);
166
- layer.options._dashArray = parts.map((n) => Number(n)).filter((n) => !isNaN(n));
167
- } else layer.options._dashArray = layer.options.dashArray;
162
+ if (typeof layer.options.dashArray === "string") layer._dashArray = layer.options.dashArray.split(DASH_SEPARATOR_RE).map((n) => Number(n)).filter((n) => !isNaN(n));
163
+ else layer._dashArray = layer.options.dashArray;
168
164
  }
169
165
  _requestRedraw(layer) {
170
166
  if (!this._map) return;
@@ -235,14 +231,10 @@ var Canvas = class Canvas extends Renderer {
235
231
  }
236
232
  _updateCircle(layer) {
237
233
  if (!this._drawing || layer._empty()) return;
238
- const p = layer._point, ctx = this._ctx, r = Math.max(Math.round(layer._pxRadius), 1), s = (Math.max(Math.round(layer._pxRadiusY), 1) || r) / r;
239
- if (s !== 1) {
240
- ctx.save();
241
- ctx.scale(1, s);
242
- }
234
+ const { x, y } = layer._point, ctx = this._ctx, r = Math.max(Math.round(layer._pxRadius), 1), ry = Math.max(Math.round(layer._pxRadiusY), 1) || r;
243
235
  ctx.beginPath();
244
- ctx.arc(p.x, p.y / s, r, 0, Math.PI * 2, false);
245
- if (s !== 1) ctx.restore();
236
+ if (ry === r) ctx.arc(x, y, r, 0, Math.PI * 2);
237
+ else ctx.ellipse(x, y, r, ry, 0, 0, Math.PI * 2);
246
238
  this._fillStroke(ctx, layer);
247
239
  }
248
240
  _fillStroke(ctx, layer) {
@@ -254,7 +246,7 @@ var Canvas = class Canvas extends Renderer {
254
246
  }
255
247
  if (options.stroke && options.weight !== 0) {
256
248
  ctx.lineDashOffset = Number(options.dashOffset ?? 0);
257
- ctx.setLineDash(options._dashArray ?? []);
249
+ ctx.setLineDash(layer._dashArray ?? []);
258
250
  ctx.globalAlpha = options.opacity;
259
251
  ctx.lineWidth = options.weight;
260
252
  ctx.strokeStyle = options.color;
@@ -344,7 +336,6 @@ var Canvas = class Canvas extends Renderer {
344
336
  this._requestRedraw(layer);
345
337
  }
346
338
  };
347
- //#endregion
348
339
  export { Canvas };
349
340
 
350
341
  //# sourceMappingURL=Canvas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.js","names":["Util.stamp"],"sources":["../../../../src/layer/vector/Canvas.js"],"sourcesContent":["import {Renderer} from './Renderer.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as Util from '../../core/Util.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {EventListener} from '../../core/Events.js' */\n/** @import {RendererOptions} from './Renderer.js' */\n\nconst DASH_SEPARATOR_RE = /[, ]+/;\n\n/**\n * Options of `Canvas`.\n * @typedef {object} CanvasOptions\n * @property {number} [tolerance=0] How much to extend the click tolerance around a\n * path/object on the map.\n * @extends RendererOptions\n */\n\n/**\n * Allows vector layers to be displayed with [`<canvas>`](https://developer.mozilla.org/docs/Web/API/Canvas_API).\n * Inherits `Renderer`.\n *\n * @example\n * Use Canvas by default for all paths in the map:\n *\n * ```js\n * const map = new MaplairMap('map', {\n * \trenderer: new Canvas()\n * });\n * ```\n *\n * Use a Canvas renderer with extra padding for specific vector geometries:\n *\n * ```js\n * const map = new MaplairMap('map');\n * const myRenderer = new Canvas({ padding: 0.5 });\n * const line = new Polyline( coordinates, { renderer: myRenderer } );\n * const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );\n * ```\n */\nexport class Canvas extends Renderer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\ttolerance: 0\n\t\t});\n\t}\n\n\t/**\n\t * Creates a Canvas renderer with the given options.\n\t * @overload\n\t * @param {CanvasOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Canvas);\n\t}\n\n\t/**\n\t * Returns the map events the renderer listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.viewprereset = this._onViewPreReset;\n\t\tevents.pixelratiochange = this._onPixelRatioChange;\n\t\treturn events;\n\t}\n\n\t// Redraws with the resolution of the new `devicePixelRatio`.\n\t_onPixelRatioChange() {\n\t\tthis._resizeContainer();\n\t\tthis._update();\n\t}\n\n\t_onViewPreReset() {\n\t\t// Set a flag so that a viewprereset+moveend+viewreset only updates&redraws once\n\t\tthis._postponeUpdatePaths = true;\n\t}\n\n\t/**\n\t * Adds the canvas to the map and draws the paths.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\n\t\t// Redraw vectors since canvas is cleared upon removal,\n\t\t// in case of removing the renderer itself from the map.\n\t\tthis._draw();\n\t}\n\n\t/**\n\t * Removes the canvas from the map.\n\t */\n\tonRemove() {\n\t\tsuper.onRemove();\n\n\t\tclearTimeout(this._pointerHoverThrottleTimeout);\n\t}\n\n\t_initContainer() {\n\t\tconst container = this._container = document.createElement('canvas');\n\n\t\tDomEvent.on(container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(container, 'click dblclick pointerdown pointerup contextmenu', this._onClick, this);\n\t\tDomEvent.on(container, 'pointerout', this._handlePointerOut, this);\n\t\tcontainer['_maplair_disable_events'] = true;\n\n\t\tthis._ctx = container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._redrawRequest);\n\t\tthis._redrawRequest = null;\n\t\tdelete this._ctx;\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tconst m = this._ctxScale = window.devicePixelRatio;\n\n\t\t// set canvas size (also clearing it); use double size on retina\n\t\tthis._container.width = m * size.x;\n\t\tthis._container.height = m * size.y;\n\t}\n\n\t_updatePaths() {\n\t\tif (this._postponeUpdatePaths) { return; }\n\n\t\tthis._redrawBounds = null;\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._update();\n\t\t}\n\t\tthis._redraw();\n\t}\n\n\t_update() {\n\t\tif (this._map._animatingZoom && this._bounds) { return; }\n\n\t\tconst b = this._bounds,\n\t\ts = this._ctxScale;\n\n\t\t// translate so we use the same path coordinates after canvas element moves\n\t\tthis._ctx.setTransform(\n\t\t\ts, 0, 0, s,\n\t\t\t-b.min.x * s,\n\t\t\t-b.min.y * s);\n\n\t\t// Tell paths to redraw themselves\n\t\tthis.fire('update');\n\t}\n\n\t_reset() {\n\t\tsuper._reset();\n\n\t\tif (this._postponeUpdatePaths) {\n\t\t\tthis._postponeUpdatePaths = false;\n\t\t\tthis._updatePaths();\n\t\t}\n\t}\n\n\t_initPath(layer) {\n\t\tthis._updateDashArray(layer);\n\t\tthis._layers[Util.stamp(layer)] = layer;\n\n\t\tconst order = layer._order = {\n\t\t\tlayer,\n\t\t\tprev: this._drawLast,\n\t\t\tnext: null\n\t\t};\n\t\tif (this._drawLast) { this._drawLast.next = order; }\n\t\tthis._drawLast = order;\n\t\tthis._drawFirst ??= this._drawLast;\n\t}\n\n\t_addPath(layer) {\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_removePath(layer) {\n\t\tconst order = layer._order;\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else {\n\t\t\tthis._drawLast = prev;\n\t\t}\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else {\n\t\t\tthis._drawFirst = next;\n\t\t}\n\n\t\tdelete layer._order;\n\n\t\tdelete this._layers[Util.stamp(layer)];\n\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updatePath(layer) {\n\t\t// Redraw the union of the layer's old pixel\n\t\t// bounds and the new pixel bounds.\n\t\tthis._extendRedrawBounds(layer);\n\t\tlayer._project();\n\t\tlayer._update();\n\t\t// The redraw will extend the redraw bounds\n\t\t// with the new pixel bounds.\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updateStyle(layer) {\n\t\tthis._updateDashArray(layer);\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updateDashArray(layer) {\n\t\tif (typeof layer.options.dashArray === 'string') {\n\t\t\tconst parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);\n\t\t\t// Ignore dash array containing invalid lengths\n\t\t\tlayer.options._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));\n\t\t} else {\n\t\t\tlayer.options._dashArray = layer.options.dashArray;\n\t\t}\n\t}\n\n\t_requestRedraw(layer) {\n\t\tif (!this._map) { return; }\n\n\t\tthis._extendRedrawBounds(layer);\n\t\tthis._redrawRequest ??= requestAnimationFrame(this._redraw.bind(this));\n\t}\n\n\t_extendRedrawBounds(layer) {\n\t\tif (layer._pxBounds) {\n\t\t\tconst padding = (layer.options.weight ?? 0) + 1;\n\t\t\tthis._redrawBounds ??= new Bounds();\n\t\t\tthis._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));\n\t\t\tthis._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));\n\t\t}\n\t}\n\n\t_redraw() {\n\t\t// also when redrawing directly, see `_updatePaths()`\n\t\tcancelAnimationFrame(this._redrawRequest);\n\t\tthis._redrawRequest = null;\n\n\t\tif (this._redrawBounds) {\n\t\t\tthis._redrawBounds.min._floor();\n\t\t\tthis._redrawBounds.max._ceil();\n\t\t}\n\n\t\tthis._clear(); // clear layers in redraw bounds\n\t\tthis._draw(); // draw layers\n\n\t\tthis._redrawBounds = null;\n\t}\n\n\t_clear() {\n\t\tconst bounds = this._redrawBounds;\n\t\tif (bounds) {\n\t\t\tconst size = bounds.getSize();\n\t\t\tthis._ctx.clearRect(bounds.min.x, bounds.min.y, size.x, size.y);\n\t\t} else {\n\t\t\tthis._ctx.save();\n\t\t\tthis._ctx.setTransform(1, 0, 0, 1, 0, 0);\n\t\t\tthis._ctx.clearRect(0, 0, this._container.width, this._container.height);\n\t\t\tthis._ctx.restore();\n\t\t}\n\t}\n\n\t_draw() {\n\t\tlet layer;\n\t\tconst bounds = this._redrawBounds;\n\t\tthis._ctx.save();\n\t\tif (bounds) {\n\t\t\tconst size = bounds.getSize();\n\t\t\tthis._ctx.beginPath();\n\t\t\tthis._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y);\n\t\t\tthis._ctx.clip();\n\t\t}\n\n\t\tthis._drawing = true;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (!bounds || (layer._pxBounds && layer._pxBounds.intersects(bounds))) {\n\t\t\t\tlayer._updatePath();\n\t\t\t}\n\t\t}\n\n\t\tthis._drawing = false;\n\n\t\tthis._ctx.restore(); // Restore state before clipping.\n\t}\n\n\t_updatePoly(layer, closed) {\n\t\tif (!this._drawing) { return; }\n\n\t\tconst parts = layer._parts,\n\t\tctx = this._ctx;\n\n\t\tif (!parts.length) { return; }\n\n\t\tctx.beginPath();\n\n\t\tparts.forEach((p0) => {\n\t\t\tp0.forEach((p, j) => {\n\t\t\t\tctx[j ? 'lineTo' : 'moveTo'](p.x, p.y);\n\t\t\t});\n\t\t\tif (closed) {\n\t\t\t\tctx.closePath();\n\t\t\t}\n\t\t});\n\n\t\tthis._fillStroke(ctx, layer);\n\n\t\t// TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature\n\t}\n\n\t_updateCircle(layer) {\n\n\t\tif (!this._drawing || layer._empty()) { return; }\n\n\t\tconst p = layer._point,\n\t\tctx = this._ctx,\n\t\tr = Math.max(Math.round(layer._pxRadius), 1),\n\t\ts = (Math.max(Math.round(layer._pxRadiusY), 1) || r) / r;\n\n\t\tif (s !== 1) {\n\t\t\tctx.save();\n\t\t\tctx.scale(1, s);\n\t\t}\n\n\t\tctx.beginPath();\n\t\tctx.arc(p.x, p.y / s, r, 0, Math.PI * 2, false);\n\n\t\tif (s !== 1) {\n\t\t\tctx.restore();\n\t\t}\n\n\t\tthis._fillStroke(ctx, layer);\n\t}\n\n\t_fillStroke(ctx, layer) {\n\t\tconst options = layer.options;\n\n\t\tif (options.fill) {\n\t\t\tctx.globalAlpha = options.fillOpacity;\n\t\t\tctx.fillStyle = options.fillColor ?? options.color;\n\t\t\tctx.fill(options.fillRule || 'evenodd');\n\t\t}\n\n\t\tif (options.stroke && options.weight !== 0) {\n\t\t\tctx.lineDashOffset = Number(options.dashOffset ?? 0);\n\t\t\tctx.setLineDash(options._dashArray ?? []);\n\t\t\tctx.globalAlpha = options.opacity;\n\t\t\tctx.lineWidth = options.weight;\n\t\t\tctx.strokeStyle = options.color;\n\t\t\tctx.lineCap = options.lineCap;\n\t\t\tctx.lineJoin = options.lineJoin;\n\t\t\tctx.stroke();\n\t\t}\n\t}\n\n\t// The hit detection checks the `interactive` option of the layers,\n\t// the hovered layer is left on the next pointer move.\n\t_updateInteractive() {}\n\n\t// Canvas obviously doesn't have pointer events for individual drawn objects,\n\t// so we emulate that by calculating what's under the pointer on pointermove/click manually\n\n\t_onClick(e) {\n\t\tconst point = this._map.pointerEventToLayerPoint(e);\n\t\tlet layer, clickedLayer;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (layer.options.interactive && layer._containsPoint(point)) {\n\t\t\t\tif (!(e.type === 'click' || e.type === 'preclick') || !this._map._draggableMoved(layer)) {\n\t\t\t\t\tclickedLayer = layer;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis._fireEvent(clickedLayer ? [clickedLayer] : false, e);\n\t}\n\n\t_onPointerMove(e) {\n\t\tif (!this._map || this._map.dragging.moving() || this._map._animatingZoom) { return; }\n\n\t\tconst point = this._map.pointerEventToLayerPoint(e);\n\t\tthis._handlePointerHover(e, point);\n\t}\n\n\n\t_handlePointerOut(e) {\n\t\tconst layer = this._hoveredLayer;\n\t\tif (layer) {\n\t\t\t// if we're leaving the layer, fire pointerout\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis._fireEvent([layer], e, 'pointerout');\n\t\t\tthis._hoveredLayer = null;\n\t\t\tthis._pointerHoverThrottled = false;\n\t\t}\n\t}\n\n\t_handlePointerHover(e, point) {\n\t\tif (this._pointerHoverThrottled) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet layer, candidateHoveredLayer;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (layer.options.interactive && layer._containsPoint(point)) {\n\t\t\t\tcandidateHoveredLayer = layer;\n\t\t\t}\n\t\t}\n\n\t\tif (candidateHoveredLayer !== this._hoveredLayer) {\n\t\t\tthis._handlePointerOut(e);\n\n\t\t\tif (candidateHoveredLayer) {\n\t\t\t\tthis._container.classList.add('maplair-interactive'); // change cursor\n\t\t\t\tthis._fireEvent([candidateHoveredLayer], e, 'pointerover');\n\t\t\t\tthis._hoveredLayer = candidateHoveredLayer;\n\t\t\t}\n\t\t}\n\n\t\tthis._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);\n\n\t\tthis._pointerHoverThrottled = true;\n\t\tthis._pointerHoverThrottleTimeout = setTimeout((() => {\n\t\t\tthis._pointerHoverThrottled = false;\n\t\t}), 32);\n\t}\n\n\t_fireEvent(layers, e, type) {\n\t\tthis._map._fireDOMEvent(e, type || e.type, layers);\n\t}\n\n\t_bringToFront(layer) {\n\t\tconst order = layer._order;\n\n\t\tif (!order) { return; }\n\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else {\n\t\t\t// Already last\n\t\t\treturn;\n\t\t}\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else if (next) {\n\t\t\t// Update first entry unless this is the\n\t\t\t// single entry\n\t\t\tthis._drawFirst = next;\n\t\t}\n\n\t\torder.prev = this._drawLast;\n\t\tthis._drawLast.next = order;\n\n\t\torder.next = null;\n\t\tthis._drawLast = order;\n\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_bringToBack(layer) {\n\t\tconst order = layer._order;\n\n\t\tif (!order) { return; }\n\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else {\n\t\t\t// Already first\n\t\t\treturn;\n\t\t}\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else if (prev) {\n\t\t\t// Update last entry unless this is the\n\t\t\t// single entry\n\t\t\tthis._drawLast = prev;\n\t\t}\n\n\t\torder.prev = null;\n\n\t\torder.next = this._drawFirst;\n\t\tthis._drawFirst.prev = order;\n\t\tthis._drawFirst = order;\n\n\t\tthis._requestRedraw(layer);\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgC1B,IAAa,SAAb,MAAa,eAAe,SAAS;CAEpC;EACC,KAAK,kBAAkB,EACtB,WAAW,EACZ,CAAC;CACF;;;;;;;;;CAUA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,MAAM;CAC1B;;;;;CAMA,YAAY;EACX,MAAM,SAAS,MAAM,UAAU;EAC/B,OAAO,eAAe,KAAK;EAC3B,OAAO,mBAAmB,KAAK;EAC/B,OAAO;C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;EAE1B;EAEA,IAAI,0BAA0B,KAAK,eAAe;GACjD,KAAK,kBAAkB,CAAC;GAExB,IAAI,uBAAuB;IAC1B,KAAK,WAAW,UAAU,IAAI,qBAAqB;IACnD,KAAK,WAAW,CAAC,qBAAqB,GAAG,GAAG,aAAa;IACzD,KAAK,gBAAgB;GACtB;EACD;EAEA,KAAK,WAAW,KAAK,gBAAgB,CAAC,KAAK,aAAa,IAAI,OAAO,CAAC;EAEpE,KAAK,yBAAyB;EAC9B,KAAK,+BAA+B,kBAAkB;GACrD,KAAK,yBAAyB;EAC/B,IAAI,EAAE;CACP;CAEA,WAAW,QAAQ,GAAG,MAAM;EAC3B,KAAK,KAAK,cAAc,GAAG,QAAQ,EAAE,MAAM,MAAM;CAClD;CAEA,cAAc,OAAO;EACpB,MAAM,QAAQ,MAAM;EAEpB,IAAI,CAAC,OAAS;EAEd,MAAM,OAAO,MAAM;EACnB,MAAM,OAAO,MAAM;EAEnB,IAAI,MACH,KAAK,OAAO;OAGZ;EAED,IAAI,MACH,KAAK,OAAO;OACN,IAAI,MAGV,KAAK,aAAa;EAGnB,MAAM,OAAO,KAAK;EAClB,KAAK,UAAU,OAAO;EAEtB,MAAM,OAAO;EACb,KAAK,YAAY;EAEjB,KAAK,eAAe,KAAK;CAC1B;CAEA,aAAa,OAAO;EACnB,MAAM,QAAQ,MAAM;EAEpB,IAAI,CAAC,OAAS;EAEd,MAAM,OAAO,MAAM;EACnB,MAAM,OAAO,MAAM;EAEnB,IAAI,MACH,KAAK,OAAO;OAGZ;EAED,IAAI,MACH,KAAK,OAAO;OACN,IAAI,MAGV,KAAK,YAAY;EAGlB,MAAM,OAAO;EAEb,MAAM,OAAO,KAAK;EAClB,KAAK,WAAW,OAAO;EACvB,KAAK,aAAa;EAElB,KAAK,eAAe,KAAK;CAC1B;AACD"}
1
+ {"version":3,"file":"Canvas.js","names":["Util.stamp"],"sources":["../../../../src/layer/vector/Canvas.js"],"sourcesContent":["import {Renderer} from './Renderer.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as Util from '../../core/Util.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {EventListener} from '../../core/Events.js' */\n/** @import {RendererOptions} from './Renderer.js' */\n\nconst DASH_SEPARATOR_RE = /[, ]+/;\n\n/**\n * Options of `Canvas`.\n * @typedef {object} CanvasOptions\n * @property {number} [tolerance=0] How much to extend the click tolerance around a\n * path/object on the map.\n * @extends RendererOptions\n */\n\n/**\n * Allows vector layers to be displayed with [`<canvas>`](https://developer.mozilla.org/docs/Web/API/Canvas_API).\n * Inherits `Renderer`.\n *\n * @example\n * Use Canvas by default for all paths in the map:\n *\n * ```js\n * const map = new MaplairMap('map', {\n * \trenderer: new Canvas()\n * });\n * ```\n *\n * Use a Canvas renderer with extra padding for specific vector geometries:\n *\n * ```js\n * const map = new MaplairMap('map');\n * const myRenderer = new Canvas({ padding: 0.5 });\n * const line = new Polyline( coordinates, { renderer: myRenderer } );\n * const circle = new Circle( center, { renderer: myRenderer, radius: 100 } );\n * ```\n */\nexport class Canvas extends Renderer {\n\n\tstatic defaultOptions = {\n\t\ttolerance: 0\n\t};\n\n\t/**\n\t * Creates a Canvas renderer with the given options.\n\t * @overload\n\t * @param {CanvasOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Canvas);\n\t}\n\n\t/**\n\t * Returns the map events the renderer listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\t\tevents.viewprereset = this._onViewPreReset;\n\t\tevents.pixelratiochange = this._onPixelRatioChange;\n\t\treturn events;\n\t}\n\n\t// Redraws with the resolution of the new `devicePixelRatio`.\n\t_onPixelRatioChange() {\n\t\tthis._resizeContainer();\n\t\tthis._update();\n\t}\n\n\t_onViewPreReset() {\n\t\t// Set a flag so that a viewprereset+moveend+viewreset only updates&redraws once\n\t\tthis._postponeUpdatePaths = true;\n\t}\n\n\t/**\n\t * Adds the canvas to the map and draws the paths.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tsuper.onAdd(map);\n\n\t\t// Redraw vectors since canvas is cleared upon removal,\n\t\t// in case of removing the renderer itself from the map.\n\t\tthis._draw();\n\t}\n\n\t/**\n\t * Removes the canvas from the map.\n\t */\n\tonRemove() {\n\t\tsuper.onRemove();\n\n\t\tclearTimeout(this._pointerHoverThrottleTimeout);\n\t}\n\n\t_initContainer() {\n\t\tconst container = this._container = document.createElement('canvas');\n\n\t\tDomEvent.on(container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(container, 'click dblclick pointerdown pointerup contextmenu', this._onClick, this);\n\t\tDomEvent.on(container, 'pointerout', this._handlePointerOut, this);\n\t\tcontainer['_maplair_disable_events'] = true;\n\n\t\tthis._ctx = container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._redrawRequest);\n\t\tthis._redrawRequest = null;\n\t\tdelete this._ctx;\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tconst m = this._ctxScale = window.devicePixelRatio;\n\n\t\t// set canvas size (also clearing it); use double size on retina\n\t\tthis._container.width = m * size.x;\n\t\tthis._container.height = m * size.y;\n\t}\n\n\t_updatePaths() {\n\t\tif (this._postponeUpdatePaths) { return; }\n\n\t\tthis._redrawBounds = null;\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tlayer._update();\n\t\t}\n\t\tthis._redraw();\n\t}\n\n\t_update() {\n\t\tif (this._map._animatingZoom && this._bounds) { return; }\n\n\t\tconst b = this._bounds,\n\t\ts = this._ctxScale;\n\n\t\t// translate so we use the same path coordinates after canvas element moves\n\t\tthis._ctx.setTransform(\n\t\t\ts, 0, 0, s,\n\t\t\t-b.min.x * s,\n\t\t\t-b.min.y * s);\n\n\t\t// Tell paths to redraw themselves\n\t\tthis.fire('update');\n\t}\n\n\t_reset() {\n\t\tsuper._reset();\n\n\t\tif (this._postponeUpdatePaths) {\n\t\t\tthis._postponeUpdatePaths = false;\n\t\t\tthis._updatePaths();\n\t\t}\n\t}\n\n\t_initPath(layer) {\n\t\tthis._updateDashArray(layer);\n\t\tthis._layers[Util.stamp(layer)] = layer;\n\n\t\tconst order = layer._order = {\n\t\t\tlayer,\n\t\t\tprev: this._drawLast,\n\t\t\tnext: null\n\t\t};\n\t\tif (this._drawLast) { this._drawLast.next = order; }\n\t\tthis._drawLast = order;\n\t\tthis._drawFirst ??= this._drawLast;\n\t}\n\n\t_addPath(layer) {\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_removePath(layer) {\n\t\tconst order = layer._order;\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else {\n\t\t\tthis._drawLast = prev;\n\t\t}\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else {\n\t\t\tthis._drawFirst = next;\n\t\t}\n\n\t\tdelete layer._order;\n\n\t\tdelete this._layers[Util.stamp(layer)];\n\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updatePath(layer) {\n\t\t// Redraw the union of the layer's old pixel\n\t\t// bounds and the new pixel bounds.\n\t\tthis._extendRedrawBounds(layer);\n\t\tlayer._project();\n\t\tlayer._update();\n\t\t// The redraw will extend the redraw bounds\n\t\t// with the new pixel bounds.\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updateStyle(layer) {\n\t\tthis._updateDashArray(layer);\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_updateDashArray(layer) {\n\t\tif (typeof layer.options.dashArray === 'string') {\n\t\t\tconst parts = layer.options.dashArray.split(DASH_SEPARATOR_RE);\n\t\t\t// Ignore dash array containing invalid lengths\n\t\t\tlayer._dashArray = parts.map(n => Number(n)).filter(n => !isNaN(n));\n\t\t} else {\n\t\t\tlayer._dashArray = layer.options.dashArray;\n\t\t}\n\t}\n\n\t_requestRedraw(layer) {\n\t\tif (!this._map) { return; }\n\n\t\tthis._extendRedrawBounds(layer);\n\t\tthis._redrawRequest ??= requestAnimationFrame(this._redraw.bind(this));\n\t}\n\n\t_extendRedrawBounds(layer) {\n\t\tif (layer._pxBounds) {\n\t\t\tconst padding = (layer.options.weight ?? 0) + 1;\n\t\t\tthis._redrawBounds ??= new Bounds();\n\t\t\tthis._redrawBounds.extend(layer._pxBounds.min.subtract([padding, padding]));\n\t\t\tthis._redrawBounds.extend(layer._pxBounds.max.add([padding, padding]));\n\t\t}\n\t}\n\n\t_redraw() {\n\t\t// also when redrawing directly, see `_updatePaths()`\n\t\tcancelAnimationFrame(this._redrawRequest);\n\t\tthis._redrawRequest = null;\n\n\t\tif (this._redrawBounds) {\n\t\t\tthis._redrawBounds.min._floor();\n\t\t\tthis._redrawBounds.max._ceil();\n\t\t}\n\n\t\tthis._clear(); // clear layers in redraw bounds\n\t\tthis._draw(); // draw layers\n\n\t\tthis._redrawBounds = null;\n\t}\n\n\t_clear() {\n\t\tconst bounds = this._redrawBounds;\n\t\tif (bounds) {\n\t\t\tconst size = bounds.getSize();\n\t\t\tthis._ctx.clearRect(bounds.min.x, bounds.min.y, size.x, size.y);\n\t\t} else {\n\t\t\tthis._ctx.save();\n\t\t\tthis._ctx.setTransform(1, 0, 0, 1, 0, 0);\n\t\t\tthis._ctx.clearRect(0, 0, this._container.width, this._container.height);\n\t\t\tthis._ctx.restore();\n\t\t}\n\t}\n\n\t_draw() {\n\t\tlet layer;\n\t\tconst bounds = this._redrawBounds;\n\t\tthis._ctx.save();\n\t\tif (bounds) {\n\t\t\tconst size = bounds.getSize();\n\t\t\tthis._ctx.beginPath();\n\t\t\tthis._ctx.rect(bounds.min.x, bounds.min.y, size.x, size.y);\n\t\t\tthis._ctx.clip();\n\t\t}\n\n\t\tthis._drawing = true;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (!bounds || (layer._pxBounds && layer._pxBounds.intersects(bounds))) {\n\t\t\t\tlayer._updatePath();\n\t\t\t}\n\t\t}\n\n\t\tthis._drawing = false;\n\n\t\tthis._ctx.restore(); // Restore state before clipping.\n\t}\n\n\t_updatePoly(layer, closed) {\n\t\tif (!this._drawing) { return; }\n\n\t\tconst parts = layer._parts,\n\t\tctx = this._ctx;\n\n\t\tif (!parts.length) { return; }\n\n\t\tctx.beginPath();\n\n\t\tparts.forEach((p0) => {\n\t\t\tp0.forEach((p, j) => {\n\t\t\t\tctx[j ? 'lineTo' : 'moveTo'](p.x, p.y);\n\t\t\t});\n\t\t\tif (closed) {\n\t\t\t\tctx.closePath();\n\t\t\t}\n\t\t});\n\n\t\tthis._fillStroke(ctx, layer);\n\n\t\t// TODO optimization: 1 fill/stroke for all features with equal style instead of 1 for each feature\n\t}\n\n\t_updateCircle(layer) {\n\n\t\tif (!this._drawing || layer._empty()) { return; }\n\n\t\tconst {x, y} = layer._point,\n\t\tctx = this._ctx,\n\t\tr = Math.max(Math.round(layer._pxRadius), 1),\n\t\try = Math.max(Math.round(layer._pxRadiusY), 1) || r;\n\n\t\tctx.beginPath();\n\t\t// arc is faster for circles in Chrome and Firefox, ellipse for everything else\n\t\tif (ry === r) {\n\t\t\tctx.arc(x, y, r, 0, Math.PI * 2);\n\t\t} else {\n\t\t\tctx.ellipse(x, y, r, ry, 0, 0, Math.PI * 2);\n\t\t}\n\n\t\tthis._fillStroke(ctx, layer);\n\t}\n\n\t_fillStroke(ctx, layer) {\n\t\tconst options = layer.options;\n\n\t\tif (options.fill) {\n\t\t\tctx.globalAlpha = options.fillOpacity;\n\t\t\tctx.fillStyle = options.fillColor ?? options.color;\n\t\t\tctx.fill(options.fillRule || 'evenodd');\n\t\t}\n\n\t\tif (options.stroke && options.weight !== 0) {\n\t\t\tctx.lineDashOffset = Number(options.dashOffset ?? 0);\n\t\t\tctx.setLineDash(layer._dashArray ?? []);\n\t\t\tctx.globalAlpha = options.opacity;\n\t\t\tctx.lineWidth = options.weight;\n\t\t\tctx.strokeStyle = options.color;\n\t\t\tctx.lineCap = options.lineCap;\n\t\t\tctx.lineJoin = options.lineJoin;\n\t\t\tctx.stroke();\n\t\t}\n\t}\n\n\t// The hit detection checks the `interactive` option of the layers,\n\t// the hovered layer is left on the next pointer move.\n\t_updateInteractive() {}\n\n\t// Canvas obviously doesn't have pointer events for individual drawn objects,\n\t// so we emulate that by calculating what's under the pointer on pointermove/click manually\n\n\t_onClick(e) {\n\t\tconst point = this._map.pointerEventToLayerPoint(e);\n\t\tlet layer, clickedLayer;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (layer.options.interactive && layer._containsPoint(point)) {\n\t\t\t\tif (!(e.type === 'click' || e.type === 'preclick') || !this._map._draggableMoved(layer)) {\n\t\t\t\t\tclickedLayer = layer;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis._fireEvent(clickedLayer ? [clickedLayer] : false, e);\n\t}\n\n\t_onPointerMove(e) {\n\t\tif (!this._map || this._map.dragging.moving() || this._map._animatingZoom) { return; }\n\n\t\tconst point = this._map.pointerEventToLayerPoint(e);\n\t\tthis._handlePointerHover(e, point);\n\t}\n\n\n\t_handlePointerOut(e) {\n\t\tconst layer = this._hoveredLayer;\n\t\tif (layer) {\n\t\t\t// if we're leaving the layer, fire pointerout\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis._fireEvent([layer], e, 'pointerout');\n\t\t\tthis._hoveredLayer = null;\n\t\t\tthis._pointerHoverThrottled = false;\n\t\t}\n\t}\n\n\t_handlePointerHover(e, point) {\n\t\tif (this._pointerHoverThrottled) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet layer, candidateHoveredLayer;\n\n\t\tfor (let order = this._drawFirst; order; order = order.next) {\n\t\t\tlayer = order.layer;\n\t\t\tif (layer.options.interactive && layer._containsPoint(point)) {\n\t\t\t\tcandidateHoveredLayer = layer;\n\t\t\t}\n\t\t}\n\n\t\tif (candidateHoveredLayer !== this._hoveredLayer) {\n\t\t\tthis._handlePointerOut(e);\n\n\t\t\tif (candidateHoveredLayer) {\n\t\t\t\tthis._container.classList.add('maplair-interactive'); // change cursor\n\t\t\t\tthis._fireEvent([candidateHoveredLayer], e, 'pointerover');\n\t\t\t\tthis._hoveredLayer = candidateHoveredLayer;\n\t\t\t}\n\t\t}\n\n\t\tthis._fireEvent(this._hoveredLayer ? [this._hoveredLayer] : false, e);\n\n\t\tthis._pointerHoverThrottled = true;\n\t\tthis._pointerHoverThrottleTimeout = setTimeout((() => {\n\t\t\tthis._pointerHoverThrottled = false;\n\t\t}), 32);\n\t}\n\n\t_fireEvent(layers, e, type) {\n\t\tthis._map._fireDOMEvent(e, type || e.type, layers);\n\t}\n\n\t_bringToFront(layer) {\n\t\tconst order = layer._order;\n\n\t\tif (!order) { return; }\n\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else {\n\t\t\t// Already last\n\t\t\treturn;\n\t\t}\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else if (next) {\n\t\t\t// Update first entry unless this is the\n\t\t\t// single entry\n\t\t\tthis._drawFirst = next;\n\t\t}\n\n\t\torder.prev = this._drawLast;\n\t\tthis._drawLast.next = order;\n\n\t\torder.next = null;\n\t\tthis._drawLast = order;\n\n\t\tthis._requestRedraw(layer);\n\t}\n\n\t_bringToBack(layer) {\n\t\tconst order = layer._order;\n\n\t\tif (!order) { return; }\n\n\t\tconst next = order.next;\n\t\tconst prev = order.prev;\n\n\t\tif (prev) {\n\t\t\tprev.next = next;\n\t\t} else {\n\t\t\t// Already first\n\t\t\treturn;\n\t\t}\n\t\tif (next) {\n\t\t\tnext.prev = prev;\n\t\t} else if (prev) {\n\t\t\t// Update last entry unless this is the\n\t\t\t// single entry\n\t\t\tthis._drawLast = prev;\n\t\t}\n\n\t\torder.prev = null;\n\n\t\torder.next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