maplair 4.0.0-alpha.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/CHANGELOG.md +140 -38
  2. package/LICENSE +1 -1
  3. package/README.md +10 -9
  4. package/dist/esm/Maplair.js +14 -14
  5. package/dist/esm/control/AttributionControl.js +24 -14
  6. package/dist/esm/control/AttributionControl.js.map +1 -1
  7. package/dist/esm/control/ButtonControl.js +9 -11
  8. package/dist/esm/control/ButtonControl.js.map +1 -1
  9. package/dist/esm/control/ContextMenu.js +1 -3
  10. package/dist/esm/control/ContextMenu.js.map +1 -1
  11. package/dist/esm/control/Control.js +9 -16
  12. package/dist/esm/control/Control.js.map +1 -1
  13. package/dist/esm/control/FullscreenControl.js +5 -7
  14. package/dist/esm/control/FullscreenControl.js.map +1 -1
  15. package/dist/esm/control/LayersControl.js +144 -35
  16. package/dist/esm/control/LayersControl.js.map +1 -1
  17. package/dist/esm/control/LegendControl.js +7 -9
  18. package/dist/esm/control/LegendControl.js.map +1 -1
  19. package/dist/esm/control/MiniMapControl.js +14 -16
  20. package/dist/esm/control/MiniMapControl.js.map +1 -1
  21. package/dist/esm/control/RotateControl.js +1 -3
  22. package/dist/esm/control/RotateControl.js.map +1 -1
  23. package/dist/esm/control/ScaleControl.js +7 -9
  24. package/dist/esm/control/ScaleControl.js.map +1 -1
  25. package/dist/esm/control/SearchControl.js +100 -18
  26. package/dist/esm/control/SearchControl.js.map +1 -1
  27. package/dist/esm/control/SideBySideControl.js +1 -3
  28. package/dist/esm/control/SideBySideControl.js.map +1 -1
  29. package/dist/esm/control/TextControl.js +5 -7
  30. package/dist/esm/control/TextControl.js.map +1 -1
  31. package/dist/esm/control/TimeControl.js +408 -0
  32. package/dist/esm/control/TimeControl.js.map +1 -0
  33. package/dist/esm/control/ZoomControl.js +5 -7
  34. package/dist/esm/control/ZoomControl.js.map +1 -1
  35. package/dist/esm/core/Class.js +28 -37
  36. package/dist/esm/core/Class.js.map +1 -1
  37. package/dist/esm/core/Events.js +21 -8
  38. package/dist/esm/core/Events.js.map +1 -1
  39. package/dist/esm/core/Handler.js +13 -11
  40. package/dist/esm/core/Handler.js.map +1 -1
  41. package/dist/esm/core/Util.js +13 -1
  42. package/dist/esm/core/Util.js.map +1 -1
  43. package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
  44. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  45. package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
  46. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  47. package/dist/esm/dom/DomEvent.js +8 -42
  48. package/dist/esm/dom/DomEvent.js.map +1 -1
  49. package/dist/esm/dom/DomUtil.js +14 -68
  50. package/dist/esm/dom/DomUtil.js.map +1 -1
  51. package/dist/esm/dom/Draggable.js +17 -18
  52. package/dist/esm/dom/Draggable.js.map +1 -1
  53. package/dist/esm/dom/PosAnimation.js +3 -25
  54. package/dist/esm/dom/PosAnimation.js.map +1 -1
  55. package/dist/esm/geo/LatLng.js +34 -6
  56. package/dist/esm/geo/LatLng.js.map +1 -1
  57. package/dist/esm/geo/LatLngBounds.js +19 -7
  58. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  59. package/dist/esm/geo/crs/CRS.js +4 -3
  60. package/dist/esm/geo/crs/CRS.js.map +1 -1
  61. package/dist/esm/geo/crs/EPSG3395.js +1 -1
  62. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  63. package/dist/esm/geo/crs/EPSG3857.js +1 -1
  64. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  65. package/dist/esm/geo/crs/EPSG4326.js +1 -1
  66. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  67. package/dist/esm/geo/crs/EarthCRS.js +2 -2
  68. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  69. package/dist/esm/geo/crs/SimpleCRS.js +1 -1
  70. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  71. package/dist/esm/geo/projection/Projection.LonLat.js +3 -3
  72. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
  73. package/dist/esm/geo/projection/Projection.Mercator.js +3 -3
  74. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
  75. package/dist/esm/geo/projection/Projection.SphericalMercator.js +3 -3
  76. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
  77. package/dist/esm/geometry/Bounds.js +19 -7
  78. package/dist/esm/geometry/Bounds.js.map +1 -1
  79. package/dist/esm/geometry/LineUtil.js +36 -30
  80. package/dist/esm/geometry/LineUtil.js.map +1 -1
  81. package/dist/esm/geometry/Point.js +23 -5
  82. package/dist/esm/geometry/Point.js.map +1 -1
  83. package/dist/esm/geometry/PolyUtil.js +9 -28
  84. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  85. package/dist/esm/layer/BlanketOverlay.js +6 -8
  86. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  87. package/dist/esm/layer/DivOverlay.js +15 -20
  88. package/dist/esm/layer/DivOverlay.js.map +1 -1
  89. package/dist/esm/layer/GeoJSON.js +9 -145
  90. package/dist/esm/layer/GeoJSON.js.map +1 -1
  91. package/dist/esm/layer/GeoJSONUtil.js +75 -0
  92. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  93. package/dist/esm/layer/HeatLayer.js +15 -17
  94. package/dist/esm/layer/HeatLayer.js.map +1 -1
  95. package/dist/esm/layer/ImageOverlay.js +20 -26
  96. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  97. package/dist/esm/layer/Layer.js +8 -10
  98. package/dist/esm/layer/Layer.js.map +1 -1
  99. package/dist/esm/layer/LayerGroup.js +51 -0
  100. package/dist/esm/layer/LayerGroup.js.map +1 -1
  101. package/dist/esm/layer/Popup.js +27 -43
  102. package/dist/esm/layer/Popup.js.map +1 -1
  103. package/dist/esm/layer/SVGOverlay.js +2 -5
  104. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  105. package/dist/esm/layer/Tooltip.js +15 -17
  106. package/dist/esm/layer/Tooltip.js.map +1 -1
  107. package/dist/esm/layer/VideoOverlay.js +12 -15
  108. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  109. package/dist/esm/layer/marker/DefaultIcon.js +15 -48
  110. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  111. package/dist/esm/layer/marker/DivIcon.js +8 -10
  112. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  113. package/dist/esm/layer/marker/Icon.js +9 -12
  114. package/dist/esm/layer/marker/Icon.js.map +1 -1
  115. package/dist/esm/layer/marker/Marker.Drag.js +1 -1
  116. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  117. package/dist/esm/layer/marker/Marker.Move.js +2 -3
  118. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  119. package/dist/esm/layer/marker/Marker.js +63 -35
  120. package/dist/esm/layer/marker/Marker.js.map +1 -1
  121. package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
  122. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  123. package/dist/esm/layer/marker/SvgIcon.js +6 -8
  124. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  125. package/dist/esm/layer/tile/GridLayer.js +86 -98
  126. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  127. package/dist/esm/layer/tile/TileLayer.js +28 -36
  128. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  129. package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
  130. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  131. package/dist/esm/layer/vector/Canvas.js +1 -3
  132. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  133. package/dist/esm/layer/vector/Circle.js +2 -2
  134. package/dist/esm/layer/vector/Circle.js.map +1 -1
  135. package/dist/esm/layer/vector/CircleMarker.js +17 -7
  136. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  137. package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
  138. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  139. package/dist/esm/layer/vector/Path.js +27 -20
  140. package/dist/esm/layer/vector/Path.js.map +1 -1
  141. package/dist/esm/layer/vector/Polygon.js +20 -4
  142. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  143. package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
  144. package/dist/esm/layer/vector/Polyline.js +24 -8
  145. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  146. package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
  147. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  148. package/dist/esm/layer/vector/SVG.js +5 -5
  149. package/dist/esm/layer/vector/SVG.js.map +1 -1
  150. package/dist/esm/map/Map.Rotation.js +15 -11
  151. package/dist/esm/map/Map.Rotation.js.map +1 -1
  152. package/dist/esm/map/Map.js +135 -129
  153. package/dist/esm/map/Map.js.map +1 -1
  154. package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
  155. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  156. package/dist/esm/map/handler/DisplaceHandler.js +6 -8
  157. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  158. package/dist/esm/map/handler/DragHandler.js +20 -20
  159. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  160. package/dist/esm/map/handler/KeyboardHandler.js +37 -37
  161. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  162. package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
  163. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  164. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
  165. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  166. package/dist/esm/map/handler/TapHoldHandler.js +12 -5
  167. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  168. package/dist/esm/package.js +1 -1
  169. package/dist/maplair-global-src.js +6326 -5625
  170. package/dist/maplair-global-src.js.map +1 -1
  171. package/dist/maplair-global.js +3 -3
  172. package/dist/maplair-global.js.map +1 -1
  173. package/dist/maplair-src.js +9010 -8290
  174. package/dist/maplair-src.js.map +1 -1
  175. package/dist/maplair.css +148 -98
  176. package/dist/maplair.js +3 -3
  177. package/dist/maplair.js.map +1 -1
  178. package/i18n/cs.json +6 -0
  179. package/i18n/de.json +6 -0
  180. package/i18n/en.json +6 -0
  181. package/i18n/es.json +6 -0
  182. package/i18n/fr.json +6 -0
  183. package/i18n/hu.json +6 -0
  184. package/i18n/it.json +6 -0
  185. package/i18n/rm.json +6 -0
  186. package/i18n/sk.json +6 -0
  187. package/i18n/sl.json +6 -0
  188. package/package.json +12 -14
  189. package/src/control/AttributionControl.js +25 -18
  190. package/src/control/ButtonControl.js +9 -11
  191. package/src/control/ContextMenu.js +3 -5
  192. package/src/control/Control.js +9 -19
  193. package/src/control/FullscreenControl.js +5 -7
  194. package/src/control/LayersControl.js +159 -36
  195. package/src/control/LegendControl.js +7 -9
  196. package/src/control/MiniMapControl.js +9 -11
  197. package/src/control/RotateControl.js +3 -5
  198. package/src/control/ScaleControl.js +7 -9
  199. package/src/control/SearchControl.js +104 -21
  200. package/src/control/SideBySideControl.js +3 -5
  201. package/src/control/TextControl.js +5 -7
  202. package/src/control/TimeControl.js +471 -0
  203. package/src/control/ZoomControl.js +5 -7
  204. package/src/control/index.js +1 -0
  205. package/src/core/Class.js +35 -34
  206. package/src/core/Events.js +22 -3
  207. package/src/core/Handler.js +14 -12
  208. package/src/core/Util.js +19 -1
  209. package/src/core/index.js +0 -1
  210. package/src/dom/DomEvent.DoubleTap.js +18 -10
  211. package/src/dom/DomEvent.PointerEvents.js +3 -26
  212. package/src/dom/DomEvent.js +8 -66
  213. package/src/dom/DomUtil.js +22 -78
  214. package/src/dom/Draggable.js +27 -22
  215. package/src/dom/PosAnimation.js +3 -25
  216. package/src/dom/index.js +0 -1
  217. package/src/geo/LatLng.js +40 -4
  218. package/src/geo/LatLngBounds.js +20 -7
  219. package/src/geo/crs/CRS.js +4 -3
  220. package/src/geo/crs/EPSG3395.js +1 -1
  221. package/src/geo/crs/EPSG3857.js +1 -1
  222. package/src/geo/crs/EPSG4326.js +1 -1
  223. package/src/geo/crs/EarthCRS.js +2 -8
  224. package/src/geo/crs/SimpleCRS.js +1 -1
  225. package/src/geo/projection/Projection.LonLat.js +3 -3
  226. package/src/geo/projection/Projection.Mercator.js +3 -3
  227. package/src/geo/projection/Projection.SphericalMercator.js +3 -3
  228. package/src/geometry/Bounds.js +20 -7
  229. package/src/geometry/LineUtil.js +47 -48
  230. package/src/geometry/Point.js +24 -5
  231. package/src/geometry/PolyUtil.js +15 -44
  232. package/src/layer/BlanketOverlay.js +6 -10
  233. package/src/layer/DivOverlay.js +15 -26
  234. package/src/layer/GeoJSON.js +7 -205
  235. package/src/layer/GeoJSONUtil.js +85 -0
  236. package/src/layer/HeatLayer.js +9 -11
  237. package/src/layer/ImageOverlay.js +19 -30
  238. package/src/layer/Layer.js +8 -10
  239. package/src/layer/LayerGroup.js +71 -0
  240. package/src/layer/Popup.js +31 -46
  241. package/src/layer/SVGOverlay.js +1 -5
  242. package/src/layer/Tooltip.js +15 -19
  243. package/src/layer/VideoOverlay.js +12 -15
  244. package/src/layer/marker/DefaultIcon.js +15 -61
  245. package/src/layer/marker/DivIcon.js +10 -12
  246. package/src/layer/marker/Icon.js +9 -12
  247. package/src/layer/marker/Marker.Drag.js +1 -1
  248. package/src/layer/marker/Marker.Move.js +2 -3
  249. package/src/layer/marker/Marker.js +83 -41
  250. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  251. package/src/layer/marker/SvgIcon.js +7 -9
  252. package/src/layer/marker/index.js +1 -0
  253. package/src/layer/tile/GridLayer.js +104 -134
  254. package/src/layer/tile/TileLayer.js +35 -43
  255. package/src/layer/tile/WMSTileLayer.js +26 -24
  256. package/src/layer/vector/Canvas.js +3 -5
  257. package/src/layer/vector/Circle.js +5 -2
  258. package/src/layer/vector/CircleMarker.js +17 -6
  259. package/src/layer/vector/Path.DashAnimation.js +1 -2
  260. package/src/layer/vector/Path.js +30 -21
  261. package/src/layer/vector/Polygon.js +28 -5
  262. package/src/layer/vector/Polyline.js +26 -7
  263. package/src/layer/vector/Renderer.getRenderer.js +17 -17
  264. package/src/layer/vector/SVG.js +5 -5
  265. package/src/map/Map.Rotation.js +19 -11
  266. package/src/map/Map.js +163 -154
  267. package/src/map/handler/BoxZoomHandler.js +9 -8
  268. package/src/map/handler/DisplaceHandler.js +6 -8
  269. package/src/map/handler/DragHandler.js +26 -29
  270. package/src/map/handler/KeyboardHandler.js +44 -50
  271. package/src/map/handler/PinchZoomHandler.js +16 -5
  272. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  273. package/src/map/handler/TapHoldHandler.js +15 -4
  274. package/src/map/index.js +1 -1
  275. package/src/maplair.css +148 -98
  276. package/dist/esm/core/Browser.js +0 -100
  277. package/dist/esm/core/Browser.js.map +0 -1
  278. package/dist/images/layers.svg +0 -1
  279. package/dist/images/marker-icon.svg +0 -1
  280. package/dist/images/marker-shadow.svg +0 -1
  281. package/src/core/Browser.js +0 -110
  282. package/src/images/layers.svg +0 -1
  283. package/src/images/marker-icon.svg +0 -1
  284. package/src/images/marker-shadow.svg +0 -1
@@ -66,8 +66,11 @@ export class Circle extends CircleMarker {
66
66
  bottom = map.project([lat - latR, lng]),
67
67
  p = top.add(bottom).divideBy(2),
68
68
  lat2 = map.unproject(p).lat;
69
- let lngR = Math.acos((Math.cos(latR * d) - Math.sin(lat * d) * Math.sin(lat2 * d)) /
70
- (Math.cos(lat * d) * Math.cos(lat2 * d))) / d;
69
+ // Longitude span from the haversine form of the spherical law of cosines. The plain acos() form
70
+ // loses precision for radii of about a metre and less, where cos(latR) is too close to 1 (#6120).
71
+ let lngR = 2 * Math.asin(Math.sqrt(
72
+ (Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) /
73
+ (Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;
71
74
 
72
75
  if (isNaN(lngR) || lngR === 0) {
73
76
  lngR = latR / Math.cos(Math.PI / 180 * lat); // Fallback for edge case, #2425
@@ -2,6 +2,8 @@ import {Path} from './Path.js';
2
2
  import * as Util from '../../core/Util.js';
3
3
  import {LatLng} from '../../geo/LatLng.js';
4
4
  import {Bounds} from '../../geometry/Bounds.js';
5
+ import {pointToGeoJSON} from '../GeoJSONUtil.js';
6
+ /** @import {Feature} from 'geojson' */
5
7
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
6
8
  /** @import {MaplairEvent} from '../../core/Events.js' */
7
9
  /** @import {PathOptions} from './Path.js' */
@@ -32,12 +34,10 @@ import {Bounds} from '../../geometry/Bounds.js';
32
34
  */
33
35
  export class CircleMarker extends Path {
34
36
 
35
- static {
36
- this.setDefaultOptions({
37
- fill: true,
38
- radius: 10
39
- });
40
- }
37
+ static defaultOptions = {
38
+ fill: true,
39
+ radius: 10
40
+ };
41
41
 
42
42
  /**
43
43
  * Instantiates a circle marker object given a geographical point, and an optional
@@ -138,4 +138,15 @@ export class CircleMarker extends Path {
138
138
  _containsPoint(p) {
139
139
  return p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();
140
140
  }
141
+
142
+ /**
143
+ * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
144
+ * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
145
+ * representation of the circle marker (as a GeoJSON `Point` Feature).
146
+ * @param {number|false} [precision]
147
+ * @returns {Feature}
148
+ */
149
+ toGeoJSON(precision) {
150
+ return pointToGeoJSON(this, precision);
151
+ }
141
152
  }
@@ -2,7 +2,6 @@ import {Path} from './Path.js';
2
2
  import {SVG} from './SVG.js';
3
3
  import {Canvas} from './Canvas.js';
4
4
  import * as Util from '../../core/Util.js';
5
- import Browser from '../../core/Browser.js';
6
5
 
7
6
  const DASH_SEPARATOR_RE = /[ ,]+/;
8
7
 
@@ -89,7 +88,7 @@ Canvas.include({
89
88
  // The shift of the dashes of an animated path, and keeps redrawing it
90
89
  _getDashShift(layer) {
91
90
  const speed = layer.options.dashSpeed,
92
- length = speed && !Browser.reducedMotion && layer._getDashLength();
91
+ length = speed && !this._map._prefersReducedMotion() && layer._getDashLength();
93
92
  if (!length) { return 0; }
94
93
 
95
94
  this._animatedDashes ??= new Set();
@@ -1,4 +1,5 @@
1
1
  import {Layer} from '../Layer.js';
2
+ import {SVG} from './SVG.js';
2
3
  import * as Util from '../../core/Util.js';
3
4
  /** @import {InteractiveLayerOptions} from '../Layer.js' */
4
5
  /** @import {MaplairMap} from '../../map/Map.js' */
@@ -32,9 +33,11 @@ import * as Util from '../../core/Util.js';
32
33
  * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)
33
34
  * is determined.
34
35
  * @property {string} [className] Custom class name set on an element. Only for SVG renderer.
36
+ * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it
37
+ * afterwards.
35
38
  * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this
36
- * path. Takes precedence over the map's [default renderer](#maplairmapoptions-renderer).
37
- * If set, it will override the `pane` option of the path.
39
+ * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),
40
+ * which is `SVG` by default. If set, it overrides the `pane` option.
38
41
  * @extends InteractiveLayerOptions
39
42
  */
40
43
 
@@ -44,25 +47,23 @@ import * as Util from '../../core/Util.js';
44
47
  */
45
48
  export class Path extends Layer {
46
49
 
47
- static {
48
- this.setDefaultOptions({
49
- stroke: true,
50
- color: '#3388ff',
51
- weight: 3,
52
- opacity: 1,
53
- lineCap: 'round',
54
- lineJoin: 'round',
55
- dashArray: null,
56
- dashOffset: null,
57
- fill: false,
58
- fillColor: null,
59
- fillOpacity: 0.2,
60
- fillRule: 'evenodd',
61
- // className: '',
62
- interactive: true,
63
- bubblingPointerEvents: true
64
- });
65
- }
50
+ static defaultOptions = {
51
+ stroke: true,
52
+ color: '#3388ff',
53
+ weight: 3,
54
+ opacity: 1,
55
+ lineCap: 'round',
56
+ lineJoin: 'round',
57
+ dashArray: null,
58
+ dashOffset: null,
59
+ fill: false,
60
+ fillColor: null,
61
+ fillOpacity: 0.2,
62
+ fillRule: 'evenodd',
63
+ // className: '',
64
+ interactive: true,
65
+ bubblingPointerEvents: true
66
+ };
66
67
 
67
68
  /**
68
69
  * Gets the renderer of the path from the map, before it is added.
@@ -107,6 +108,9 @@ export class Path extends Layer {
107
108
 
108
109
  /**
109
110
  * Changes the appearance of a Path based on the options in the `PathOptions` object.
111
+ * Note that [`className`](#pathoptions-classname) is an exception: it is applied only
112
+ * when the path element is created, so passing it here updates the option but leaves
113
+ * the element's class unchanged.
110
114
  * @param {PathOptions} style
111
115
  * @returns {this}
112
116
  */
@@ -147,6 +151,11 @@ export class Path extends Layer {
147
151
  return this._path;
148
152
  }
149
153
 
154
+ // the renderer of the path if neither the path nor the map has one
155
+ _createRenderer(options) {
156
+ return new SVG(options);
157
+ }
158
+
150
159
  _reset() {
151
160
  // defined in child classes
152
161
  this._project();
@@ -4,6 +4,8 @@ import * as LineUtil from '../../geometry/LineUtil.js';
4
4
  import {Point} from '../../geometry/Point.js';
5
5
  import {Bounds} from '../../geometry/Bounds.js';
6
6
  import * as PolyUtil from '../../geometry/PolyUtil.js';
7
+ import {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';
8
+ /** @import {Feature} from 'geojson' */
7
9
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
8
10
  /** @import {PolylineOptions} from './Polyline.js' */
9
11
 
@@ -57,11 +59,9 @@ import * as PolyUtil from '../../geometry/PolyUtil.js';
57
59
  */
58
60
  export class Polygon extends Polyline {
59
61
 
60
- static {
61
- this.setDefaultOptions({
62
- fill: true
63
- });
64
- }
62
+ static defaultOptions = {
63
+ fill: true
64
+ };
65
65
 
66
66
  /**
67
67
  * Instantiates a polygon object given an array of geographical points (or arrays
@@ -177,4 +177,27 @@ export class Polygon extends Polyline {
177
177
  return inside || super._containsPoint(p, true);
178
178
  }
179
179
 
180
+
181
+ /**
182
+ * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
183
+ * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
184
+ * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).
185
+ * @param {number|false} [precision]
186
+ * @returns {Feature}
187
+ */
188
+ toGeoJSON(precision) {
189
+ const holes = !LineUtil.isFlat(this._latlngs),
190
+ multi = holes && !LineUtil.isFlat(this._latlngs[0]);
191
+
192
+ let coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);
193
+
194
+ if (!holes) {
195
+ coords = [coords];
196
+ }
197
+
198
+ return getFeature(this, {
199
+ type: `${multi ? 'Multi' : ''}Polygon`,
200
+ coordinates: coords
201
+ });
202
+ }
180
203
  }
@@ -5,6 +5,8 @@ import {LatLng} from '../../geo/LatLng.js';
5
5
  import {LatLngBounds} from '../../geo/LatLngBounds.js';
6
6
  import {Bounds} from '../../geometry/Bounds.js';
7
7
  import {Point} from '../../geometry/Point.js';
8
+ import {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';
9
+ /** @import {Feature} from 'geojson' */
8
10
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
9
11
  /** @import {PointExpression} from '../../geometry/Point.js' */
10
12
  /** @import {PathOptions} from './Path.js' */
@@ -53,12 +55,10 @@ import {Point} from '../../geometry/Point.js';
53
55
  */
54
56
  export class Polyline extends Path {
55
57
 
56
- static {
57
- this.setDefaultOptions({
58
- smoothFactor: 0.5,
59
- noClip: false
60
- });
61
- }
58
+ static defaultOptions = {
59
+ smoothFactor: 0.5,
60
+ noClip: false
61
+ };
62
62
 
63
63
  /**
64
64
  * Instantiates a polyline object given an array of geographical points and
@@ -110,7 +110,7 @@ export class Polyline extends Path {
110
110
  * @returns {(Point & {distance: number})|null}
111
111
  */
112
112
  closestLayerPoint(p) {
113
- p = new Point(p);
113
+ p = Point.from(p);
114
114
  let minDistance = Infinity,
115
115
  minPoint = null,
116
116
  p1, p2;
@@ -316,4 +316,23 @@ export class Polyline extends Path {
316
316
  }
317
317
  return false;
318
318
  }
319
+
320
+ /**
321
+ * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
322
+ * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
323
+ * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`
324
+ * Feature).
325
+ * @param {number|false} [precision]
326
+ * @returns {Feature}
327
+ */
328
+ toGeoJSON(precision) {
329
+ const multi = !LineUtil.isFlat(this._latlngs);
330
+
331
+ const coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);
332
+
333
+ return getFeature(this, {
334
+ type: `${multi ? 'Multi' : ''}LineString`,
335
+ coordinates: coords
336
+ });
337
+ }
319
338
  }
@@ -1,5 +1,3 @@
1
- import {Canvas} from './Canvas.js';
2
- import {SVG} from './SVG.js';
3
1
  /** @import {MaplairMap} from '../../map/Map.js' */
4
2
  /** @import {Path} from './Path.js' */
5
3
  /** @import {Renderer} from './Renderer.js' */
@@ -18,11 +16,8 @@ const mapRendererMethods = {
18
16
  * @returns {Renderer}
19
17
  */
20
18
  getRenderer(layer) {
21
- let renderer = layer.options.renderer ?? this._getPaneRenderer(layer.options.pane) ?? this.options.renderer ?? this._renderer;
22
-
23
- if (!renderer) {
24
- renderer = this._renderer = this._createRenderer();
25
- }
19
+ const renderer = layer.options.renderer ?? this._getPaneRenderer(layer) ?? this.options.renderer ??
20
+ (this._renderer ??= layer._createRenderer());
26
21
 
27
22
  if (!this.hasLayer(renderer)) {
28
23
  this.addLayer(renderer);
@@ -30,21 +25,22 @@ const mapRendererMethods = {
30
25
  return renderer;
31
26
  },
32
27
 
33
- _getPaneRenderer(name) {
28
+ _getPaneRenderer(layer) {
29
+ const name = layer.options.pane;
34
30
  if (name === 'overlayPane' || name === undefined) {
35
31
  return;
36
32
  }
37
33
 
38
34
  let renderer = this._paneRenderers[name];
39
- if (renderer === undefined) {
40
- renderer = this._createRenderer({pane: name});
35
+ if (!renderer) {
36
+ // custom panes get a renderer of the same kind as the map's default one, so Canvas maps stay Canvas
37
+ const Renderer = this.options.renderer?.constructor;
38
+ renderer = Renderer ?
39
+ new Renderer({...this.options.renderer.options, pane: name}) :
40
+ layer._createRenderer({pane: name});
41
41
  this._paneRenderers[name] = renderer;
42
42
  }
43
43
  return renderer;
44
- },
45
-
46
- _createRenderer(options) {
47
- return (this.options.preferCanvas && new Canvas(options)) || new SVG(options);
48
44
  }
49
45
  };
50
46
  /** @typedef {typeof mapRendererMethods} MapRendererMethods */
@@ -53,10 +49,9 @@ const mapRendererMethods = {
53
49
  * Map options of the vector renderers.
54
50
  * @typedef {object} RendererMapOptions
55
51
  * @lends MaplairMapOptions
56
- * @property {boolean} [preferCanvas=false] Whether `Path`s should be rendered on a
57
- * `Canvas` renderer. By default, all `Path`s are rendered in a `SVG` renderer.
58
52
  * @property {Renderer} [renderer] The default method for drawing vector layers on the
59
- * map. `SVG` or `Canvas` by default depending on the `preferCanvas` option.
53
+ * map. A new `SVG` renderer by default; pass `new Canvas()` to draw them on a canvas
54
+ * instead.
60
55
  */
61
56
 
62
57
  /**
@@ -67,4 +62,9 @@ const mapRendererMethods = {
67
62
  */
68
63
  export function register(MaplairMap) {
69
64
  MaplairMap.include(mapRendererMethods);
65
+ MaplairMap.addInitHook(function () {
66
+ if (this.options.preferCanvas !== undefined) {
67
+ console.error('MaplairMap: preferCanvas option has been removed. Use renderer: new Canvas() instead.');
68
+ }
69
+ });
70
70
  }
@@ -63,8 +63,8 @@ export class SVG extends Renderer {
63
63
  // set size of svg-container if changed
64
64
  if (!this._svgSize || !this._svgSize.equals(size)) {
65
65
  this._svgSize = size;
66
- this._container.setAttribute('width', size.x);
67
- this._container.setAttribute('height', size.y);
66
+ this._container.setAttribute('width', `${size.x}`);
67
+ this._container.setAttribute('height', `${size.y}`);
68
68
  }
69
69
 
70
70
  // Reset the <SVG>'s viewBox as per _update, but skip redrawing paths.
@@ -133,8 +133,8 @@ export class SVG extends Renderer {
133
133
 
134
134
  if (options.stroke) {
135
135
  path.setAttribute('stroke', options.color);
136
- path.setAttribute('stroke-opacity', options.opacity);
137
- path.setAttribute('stroke-width', options.weight);
136
+ path.setAttribute('stroke-opacity', `${options.opacity}`);
137
+ path.setAttribute('stroke-width', `${options.weight}`);
138
138
  path.setAttribute('stroke-linecap', options.lineCap);
139
139
  path.setAttribute('stroke-linejoin', options.lineJoin);
140
140
 
@@ -155,7 +155,7 @@ export class SVG extends Renderer {
155
155
 
156
156
  if (options.fill) {
157
157
  path.setAttribute('fill', options.fillColor || options.color);
158
- path.setAttribute('fill-opacity', options.fillOpacity);
158
+ path.setAttribute('fill-opacity', `${options.fillOpacity}`);
159
159
  path.setAttribute('fill-rule', options.fillRule || 'evenodd');
160
160
  } else {
161
161
  path.setAttribute('fill', 'none');
@@ -1,5 +1,4 @@
1
1
  import {MaplairMap} from './Map.js';
2
- import Browser from '../core/Browser.js';
3
2
  import * as DomUtil from '../dom/DomUtil.js';
4
3
  import * as DomEvent from '../dom/DomEvent.js';
5
4
  import * as PointerEvents from '../dom/DomEvent.PointerEvents.js';
@@ -143,7 +142,7 @@ const mapRotationMethods = {
143
142
  if (bearing === from) { return this; }
144
143
 
145
144
  this._stop();
146
- if (!options?.animate || !this._loaded || Browser.reducedMotion) {
145
+ if (!options?.animate || !this._loaded || this._prefersReducedMotion()) {
147
146
  this._rotate(bearing);
148
147
  return this._loaded ? this.fire('movestart').fire('move').fire('moveend') : this;
149
148
  }
@@ -236,7 +235,7 @@ const mapRotationMethods = {
236
235
  * @returns {Point}
237
236
  */
238
237
  containerPointToLayerPoint(point) { // (Point)
239
- point = new Point(point);
238
+ point = Point.from(point);
240
239
  if (this._bearing) {
241
240
  // the map pane is rotated around the center of the container
242
241
  const center = this.getSize()._divideBy(2);
@@ -253,7 +252,7 @@ const mapRotationMethods = {
253
252
  * @returns {Point}
254
253
  */
255
254
  layerPointToContainerPoint(point) { // (Point)
256
- point = new Point(point).add(this._getMapPanePos());
255
+ point = Point.from(point).add(this._getMapPanePos());
257
256
  if (this._bearing) {
258
257
  const center = this.getSize()._divideBy(2);
259
258
  point = this._rotateToContainer(point.subtract(center))._add(center);
@@ -289,7 +288,7 @@ const mapRotationMethods = {
289
288
  * @returns {this}
290
289
  */
291
290
  panBy(offset, options) {
292
- return panBy.call(this, this._rotateToPane(new Point(offset)), options);
291
+ return panBy.call(this, this._rotateToPane(Point.from(offset)), options);
293
292
  },
294
293
 
295
294
  _tryAnimatedPan(center, options) {
@@ -475,7 +474,7 @@ const divOverlayRotationMethods = {
475
474
  pos = map.latLngToLayerPoint(this._latlng),
476
475
  // on a rotated map, the anchor is relative to the upright overlay
477
476
  anchor = map._rotateToPane(new Point(this._getAnchor()));
478
- let offset = new Point(this.options.offset);
477
+ let offset = Point.from(this.options.offset);
479
478
 
480
479
  const transformed = this._zoomAnimated || this.options.overflow || map._bearing;
481
480
  if (!transformed) {
@@ -553,9 +552,9 @@ const popupRotationMethods = {
553
552
  topLeft = new Point(this._containerLeft, -containerHeight - this._containerBottom);
554
553
 
555
554
  const containerPos = map.layerPointToContainerPoint(this._getContainerPosition())._add(topLeft),
556
- padding = new Point(this.options.autoPanPadding),
557
- paddingTL = new Point(this.options.autoPanPaddingTopLeft ?? padding),
558
- paddingBR = new Point(this.options.autoPanPaddingBottomRight ?? padding),
555
+ padding = Point.from(this.options.autoPanPadding),
556
+ paddingTL = Point.from(this.options.autoPanPaddingTopLeft ?? padding),
557
+ paddingBR = Point.from(this.options.autoPanPaddingBottomRight ?? padding),
559
558
  size = map.getSize();
560
559
  let dx = 0,
561
560
  dy = 0;
@@ -746,8 +745,17 @@ const dragHandlerRotationMethods = {
746
745
  limitedSpeed = Math.min(options.inertiaMaxSpeed, speed),
747
746
  limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),
748
747
 
749
- decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease);
750
- let offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
748
+ maxOffset = map.getSize().divideBy(2);
749
+
750
+ let decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease),
751
+ offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
752
+
753
+ // with reduced motion, shorten the coast to fit within half the map size, see DragHandler
754
+ if (map._prefersReducedMotion() && !maxOffset.contains(offset)) {
755
+ const k = Math.min(maxOffset.x / Math.abs(offset.x), maxOffset.y / Math.abs(offset.y));
756
+ offset = offset.multiplyBy(k).round();
757
+ decelerationDuration *= Math.sqrt(k);
758
+ }
751
759
 
752
760
  if (!offset.x && !offset.y) {
753
761
  map.fire('moveend');