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,7 +1,7 @@
1
1
  import { LatLngBounds } from "../../geo/LatLngBounds.js";
2
- import { EarthCRS } from "../../geo/crs/EarthCRS.js";
3
2
  import { CircleMarker } from "./CircleMarker.js";
4
- //#region src/layer/vector/Circle.js
3
+ import { EarthCRS } from "../../geo/crs/EarthCRS.js";
4
+ // src/layer/vector/Circle.js
5
5
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
6
6
  /** @import {CircleMarkerOptions} from './CircleMarker.js' */
7
7
  /**
@@ -35,10 +35,12 @@ var Circle = class Circle extends CircleMarker {
35
35
  this.callInitHooks(Circle);
36
36
  }
37
37
  /**
38
- * Returns the `LatLngBounds` of the path.
38
+ * Returns the `LatLngBounds` of the path. When the circle isn't on a map, they're
39
+ * approximated on a sphere.
39
40
  * @returns {LatLngBounds}
40
41
  */
41
42
  getBounds() {
43
+ if (!this._map) return this._latlng.toBounds(this._radius * 2);
42
44
  const half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];
43
45
  return new LatLngBounds(this._map.layerPointToLatLng(this._point.subtract(half)), this._map.layerPointToLatLng(this._point.add(half)));
44
46
  }
@@ -46,7 +48,7 @@ var Circle = class Circle extends CircleMarker {
46
48
  const lng = this._latlng.lng, lat = this._latlng.lat, map = this._map, crs = map.options.crs;
47
49
  if (crs.distance === EarthCRS.distance) {
48
50
  const d = Math.PI / 180, latR = this._radius / EarthCRS.R / d, top = map.project([lat + latR, lng]), bottom = map.project([lat - latR, lng]), p = top.add(bottom).divideBy(2), lat2 = map.unproject(p).lat;
49
- let lngR = Math.acos((Math.cos(latR * d) - Math.sin(lat * d) * Math.sin(lat2 * d)) / (Math.cos(lat * d) * Math.cos(lat2 * d))) / d;
51
+ let lngR = 2 * Math.asin(Math.sqrt((Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) / (Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;
50
52
  if (isNaN(lngR) || lngR === 0) lngR = latR / Math.cos(Math.PI / 180 * lat);
51
53
  this._point = p.subtract(map.getPixelOrigin());
52
54
  this._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;
@@ -59,7 +61,6 @@ var Circle = class Circle extends CircleMarker {
59
61
  this._updateBounds();
60
62
  }
61
63
  };
62
- //#endregion
63
64
  export { Circle };
64
65
 
65
66
  //# sourceMappingURL=Circle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Circle.js","names":[],"sources":["../../../../src/layer/vector/Circle.js"],"sourcesContent":["import {CircleMarker} from './CircleMarker.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {EarthCRS} from '../../geo/crs/EarthCRS.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {CircleMarkerOptions} from './CircleMarker.js' */\n\n\n/**\n * Options of `Circle`.\n * @typedef {object} CircleOptions\n * @property {number} [radius] Radius of the circle, in meters.\n * @extends CircleMarkerOptions\n */\n\n/**\n * A class for drawing circle overlays on a map with radius specified in meters.\n * Extends `CircleMarker`, its `setRadius()` and `getRadius()` use meters.\n *\n * It's an approximation and starts to diverge from a real circle closer to poles\n * (due to projection distortion).\n *\n * @example\n * ```js\n * new Circle([50.5, 30.5], {radius: 200}).addTo(map);\n * ```\n */\nexport class Circle extends CircleMarker {\n\n\t/**\n\t * Instantiates a circle object given a geographical point, and an options object\n\t * which contains the circle radius.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper(latlng, options);\n\n\t\tif (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }\n\n\t\tthis.callInitHooks(Circle);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\tconst half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];\n\n\t\treturn new LatLngBounds(\n\t\t\tthis._map.layerPointToLatLng(this._point.subtract(half)),\n\t\t\tthis._map.layerPointToLatLng(this._point.add(half)));\n\t}\n\n\t_project() {\n\n\t\tconst lng = this._latlng.lng,\n\t\tlat = this._latlng.lat,\n\t\tmap = this._map,\n\t\tcrs = map.options.crs;\n\n\t\tif (crs.distance === EarthCRS.distance) {\n\t\t\tconst d = Math.PI / 180,\n\t\t\tlatR = (this._radius / EarthCRS.R) / d,\n\t\t\ttop = map.project([lat + latR, lng]),\n\t\t\tbottom = map.project([lat - latR, lng]),\n\t\t\tp = top.add(bottom).divideBy(2),\n\t\t\tlat2 = map.unproject(p).lat;\n\t\t\tlet lngR = Math.acos((Math.cos(latR * d) - Math.sin(lat * d) * Math.sin(lat2 * d)) /\n\t\t\t\t (Math.cos(lat * d) * Math.cos(lat2 * d))) / d;\n\n\t\t\tif (isNaN(lngR) || lngR === 0) {\n\t\t\t\tlngR = latR / Math.cos(Math.PI / 180 * lat); // Fallback for edge case, #2425\n\t\t\t}\n\n\t\t\tthis._point = p.subtract(map.getPixelOrigin());\n\t\t\tthis._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;\n\t\t\tthis._pxRadiusY = p.y - top.y;\n\n\t\t} else {\n\t\t\tconst latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._radius, 0]));\n\n\t\t\tthis._point = map.latLngToLayerPoint(this._latlng);\n\t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,KAAK,MAAM,GAAG;GAG3C,KAAK,SAAS,EAAE,SAAS,IAAI,eAAe,CAAC;GAC7C,KAAK,YAAY,MAAM,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,CAAC,CAAC;GACzE,KAAK,aAAa,EAAE,IAAI,IAAI;EAE7B,OAAO;GACN,MAAM,UAAU,IAAI,UAAU,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;GAEnF,KAAK,SAAS,IAAI,mBAAmB,KAAK,OAAO;GACjD,KAAK,YAAY,KAAK,IAAI,KAAK,OAAO,IAAI,IAAI,mBAAmB,OAAO,CAAC,CAAC,CAAC;EAC5E;EAEA,KAAK,cAAc;CACpB;AACD"}
1
+ {"version":3,"file":"Circle.js","names":[],"sources":["../../../../src/layer/vector/Circle.js"],"sourcesContent":["import {CircleMarker} from './CircleMarker.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {EarthCRS} from '../../geo/crs/EarthCRS.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {CircleMarkerOptions} from './CircleMarker.js' */\n\n\n/**\n * Options of `Circle`.\n * @typedef {object} CircleOptions\n * @property {number} [radius] Radius of the circle, in meters.\n * @extends CircleMarkerOptions\n */\n\n/**\n * A class for drawing circle overlays on a map with radius specified in meters.\n * Extends `CircleMarker`, its `setRadius()` and `getRadius()` use meters.\n *\n * It's an approximation and starts to diverge from a real circle closer to poles\n * (due to projection distortion).\n *\n * @example\n * ```js\n * new Circle([50.5, 30.5], {radius: 200}).addTo(map);\n * ```\n */\nexport class Circle extends CircleMarker {\n\n\t/**\n\t * Instantiates a circle object given a geographical point, and an options object\n\t * which contains the circle radius.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper(latlng, options);\n\n\t\tif (isNaN(this.options.radius)) { throw new Error('Circle radius cannot be NaN'); }\n\n\t\tthis.callInitHooks(Circle);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path. When the circle isn't on a map, they're\n\t * approximated on a sphere.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\tif (!this._map) { return this._latlng.toBounds(this._radius * 2); }\n\n\t\tconst half = [this._pxRadius, this._pxRadiusY ?? this._pxRadius];\n\n\t\treturn new LatLngBounds(\n\t\t\tthis._map.layerPointToLatLng(this._point.subtract(half)),\n\t\t\tthis._map.layerPointToLatLng(this._point.add(half)));\n\t}\n\n\t_project() {\n\n\t\tconst lng = this._latlng.lng,\n\t\tlat = this._latlng.lat,\n\t\tmap = this._map,\n\t\tcrs = map.options.crs;\n\n\t\tif (crs.distance === EarthCRS.distance) {\n\t\t\tconst d = Math.PI / 180,\n\t\t\tlatR = (this._radius / EarthCRS.R) / d,\n\t\t\ttop = map.project([lat + latR, lng]),\n\t\t\tbottom = map.project([lat - latR, lng]),\n\t\t\tp = top.add(bottom).divideBy(2),\n\t\t\tlat2 = map.unproject(p).lat;\n\t\t\t// Longitude span from the haversine form of the spherical law of cosines. The plain acos() form\n\t\t\t// loses precision for radii of about a metre and less, where cos(latR) is too close to 1 (#6120).\n\t\t\tlet lngR = 2 * Math.asin(Math.sqrt(\n\t\t\t\t(Math.sin(latR * d / 2) ** 2 - Math.sin((lat2 - lat) * d / 2) ** 2) /\n\t\t\t\t(Math.cos(lat * d) * Math.cos(lat2 * d)))) / d;\n\n\t\t\tif (isNaN(lngR) || lngR === 0) {\n\t\t\t\tlngR = latR / Math.cos(Math.PI / 180 * lat); // Fallback for edge case, #2425\n\t\t\t}\n\n\t\t\tthis._point = p.subtract(map.getPixelOrigin());\n\t\t\tthis._pxRadius = isNaN(lngR) ? 0 : p.x - map.project([lat2, lng - lngR]).x;\n\t\t\tthis._pxRadiusY = p.y - top.y;\n\n\t\t} else {\n\t\t\tconst latlng2 = crs.unproject(crs.project(this._latlng).subtract([this._rad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KAAK,MAChE,KAAK,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC,EAAE,CAAC,IAAI;GAE9C,IAAI,MAAM,IAAI,KAAK,SAAS,GAC3B,OAAO,OAAO,KAAK,IAAI,KAAK,KAAK,MAAM,GAAG;GAG3C,KAAK,SAAS,EAAE,SAAS,IAAI,eAAe,CAAC;GAC7C,KAAK,YAAY,MAAM,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,QAAQ,CAAC,MAAM,MAAM,IAAI,CAAC,CAAC,CAAC;GACzE,KAAK,aAAa,EAAE,IAAI,IAAI;EAE7B,OAAO;GACN,MAAM,UAAU,IAAI,UAAU,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;GAEnF,KAAK,SAAS,IAAI,mBAAmB,KAAK,OAAO;GACjD,KAAK,YAAY,KAAK,IAAI,KAAK,OAAO,IAAI,IAAI,mBAAmB,OAAO,CAAC,CAAC,CAAC;EAC5E;EAEA,KAAK,cAAc;CACpB;AACD"}
@@ -1,8 +1,10 @@
1
1
  import { setOptions } from "../../core/Util.js";
2
- import { Path } from "./Path.js";
3
2
  import { Bounds } from "../../geometry/Bounds.js";
3
+ import { Path } from "./Path.js";
4
4
  import { LatLng } from "../../geo/LatLng.js";
5
- //#region src/layer/vector/CircleMarker.js
5
+ import { pointToGeoJSON } from "../GeoJSONUtil.js";
6
+ // src/layer/vector/CircleMarker.js
7
+ /** @import {Feature} from 'geojson' */
6
8
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
7
9
  /** @import {MaplairEvent} from '../../core/Events.js' */
8
10
  /** @import {PathOptions} from './Path.js' */
@@ -28,12 +30,10 @@ import { LatLng } from "../../geo/LatLng.js";
28
30
  * event arguments as `oldLatLng`, `latlng`.
29
31
  */
30
32
  var CircleMarker = class CircleMarker extends Path {
31
- static {
32
- this.setDefaultOptions({
33
- fill: true,
34
- radius: 10
35
- });
36
- }
33
+ static defaultOptions = {
34
+ fill: true,
35
+ radius: 10
36
+ };
37
37
  /**
38
38
  * Instantiates a circle marker object given a geographical point, and an optional
39
39
  * options object.
@@ -95,7 +95,7 @@ var CircleMarker = class CircleMarker extends Path {
95
95
  return this;
96
96
  }
97
97
  _project() {
98
- this._point = this._map.latLngToLayerPoint(this._latlng);
98
+ this._point = this._map.latLngToLayerPoint(this._latlng)._round();
99
99
  this._pxRadius = this._radius;
100
100
  this._updateBounds();
101
101
  }
@@ -115,8 +115,17 @@ var CircleMarker = class CircleMarker extends Path {
115
115
  _containsPoint(p) {
116
116
  return p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();
117
117
  }
118
+ /**
119
+ * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
120
+ * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
121
+ * representation of the circle marker (as a GeoJSON `Point` Feature).
122
+ * @param {number|false} [precision]
123
+ * @returns {Feature}
124
+ */
125
+ toGeoJSON(precision) {
126
+ return pointToGeoJSON(this, precision);
127
+ }
118
128
  };
119
- //#endregion
120
129
  export { CircleMarker };
121
130
 
122
131
  //# sourceMappingURL=CircleMarker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CircleMarker.js","names":[],"sources":["../../../../src/layer/vector/CircleMarker.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {PathOptions} from './Path.js' */\n\n\n/**\n * Options of `CircleMarker`.\n * @typedef {object} CircleMarkerOptions\n * @property {boolean} [fill=true] Whether to fill the circle with color.\n * @property {number} [radius=10] Radius of the circle marker, in CSS pixels.\n * @extends PathOptions\n */\n\n/**\n * The event object of `move` of circle markers.\n * @typedef {object} CircleMarkerMoveEvent\n * @property {LatLng} oldLatLng The previous position of the circle marker.\n * @property {LatLng} latlng The new position of the circle marker.\n * @extends MaplairEvent\n */\n\n/**\n * A circle of a fixed size with radius specified in CSS pixels. Extends `Path`.\n *\n * @fires move {CircleMarkerMoveEvent} Fired when the marker is moved via\n * [`setLatLng`](#circlemarker-setlatlng). Old and new coordinates are included in\n * event arguments as `oldLatLng`, `latlng`.\n */\nexport class CircleMarker extends Path {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tfill: true,\n\t\t\tradius: 10\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a circle marker object given a geographical point, and an optional\n\t * options object.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleMarkerOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis._radius = this.options.radius;\n\n\t\tthis.callInitHooks(CircleMarker);\n\t}\n\n\t/**\n\t * Sets the position of a circle marker to a new location.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis.redraw();\n\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t/**\n\t * Returns the current geographical position of the circle marker.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the radius of a circle marker. Units are in CSS pixels.\n\t * @param {number} radius\n\t * @returns {this}\n\t */\n\tsetRadius(radius) {\n\t\tthis.options.radius = this._radius = radius;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the current radius of the circle. Units are in CSS pixels.\n\t * @returns {number}\n\t */\n\tgetRadius() {\n\t\treturn this._radius;\n\t}\n\n\t/**\n\t * Changes the appearance of the circle marker, also its `radius`.\n\t * @param {CircleMarkerOptions} options\n\t * @returns {this}\n\t */\n\tsetStyle(options) {\n\t\tsuper.setStyle(options);\n\t\tif (options?.radius !== undefined) {\n\t\t\tthis.setRadius(options.radius);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_project() {\n\t\tthis._point = this._map.latLngToLayerPoint(this._latlng);\n\t\tthis._pxRadius = this._radius;\n\t\tthis._updateBounds();\n\t}\n\n\t_updateBounds() {\n\t\tconst r = this._pxRadius,\n\t\tr2 = this._pxRadiusY ?? r,\n\t\tw = this._clickTolerance(),\n\t\tp = [r + w, r2 + w];\n\t\tthis._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p));\n\t}\n\n\t_update() {\n\t\tif (this._map) {\n\t\t\tthis._updatePath();\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updateCircle(this);\n\t}\n\n\t_empty() {\n\t\treturn this._pxRadius && !this._renderer._bounds.intersects(this._pxBounds);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\treturn p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,eAAb,MAAa,qBAAqB,KAAK;CAEtC;EACC,KAAK,kBAAkB;GACtB,MAAM;GACN,QAAQ;EACT,CAAC;CACF;;;;;;;CAQA,YAAY,QAAQ,SAAS;EAC5B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,UAAU,IAAI,OAAO,MAAM;EAChC,KAAK,UAAU,KAAK,QAAQ;EAE5B,KAAK,cAAc,YAAY;CAChC;;;;;;CAOA,UAAU,QAAQ;EACjB,MAAM,YAAY,KAAK;EACvB,KAAK,UAAU,IAAI,OAAO,MAAM;EAChC,KAAK,OAAO;EAEZ,OAAO,KAAK,KAAK,QAAQ;GAAC;GAAW,QAAQ,KAAK;EAAO,CAAC;CAC3D;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;;;;;;CAOA,UAAU,QAAQ;EACjB,KAAK,QAAQ,SAAS,KAAK,UAAU;EACrC,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;;;;;;CAOA,SAAS,SAAS;EACjB,MAAM,SAAS,OAAO;EACtB,IAAI,SAAS,WAAW,KAAA,GACvB,KAAK,UAAU,QAAQ,MAAM;EAE9B,OAAO;CACR;CAEA,WAAW;EACV,KAAK,SAAS,KAAK,KAAK,mBAAmB,KAAK,OAAO;EACvD,KAAK,YAAY,KAAK;EACtB,KAAK,cAAc;CACpB;CAEA,gBAAgB;EACf,MAAM,IAAI,KAAK,WACf,KAAK,KAAK,cAAc,GACxB,IAAI,KAAK,gBAAgB,GACzB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;EAClB,KAAK,YAAY,IAAI,OAAO,KAAK,OAAO,SAAS,CAAC,GAAG,KAAK,OAAO,IAAI,CAAC,CAAC;CACxE;CAEA,UAAU;EACT,IAAI,KAAK,MACR,KAAK,YAAY;CAEnB;CAEA,cAAc;EACb,KAAK,UAAU,cAAc,IAAI;CAClC;CAEA,SAAS;EACR,OAAO,KAAK,aAAa,CAAC,KAAK,UAAU,QAAQ,WAAW,KAAK,SAAS;CAC3E;CAGA,eAAe,GAAG;EACjB,OAAO,EAAE,WAAW,KAAK,MAAM,KAAK,KAAK,YAAY,KAAK,gBAAgB;CAC3E;AACD"}
1
+ {"version":3,"file":"CircleMarker.js","names":[],"sources":["../../../../src/layer/vector/CircleMarker.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {pointToGeoJSON} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n/** @import {PathOptions} from './Path.js' */\n\n\n/**\n * Options of `CircleMarker`.\n * @typedef {object} CircleMarkerOptions\n * @property {boolean} [fill=true] Whether to fill the circle with color.\n * @property {number} [radius=10] Radius of the circle marker, in CSS pixels.\n * @extends PathOptions\n */\n\n/**\n * The event object of `move` of circle markers.\n * @typedef {object} CircleMarkerMoveEvent\n * @property {LatLng} oldLatLng The previous position of the circle marker.\n * @property {LatLng} latlng The new position of the circle marker.\n * @extends MaplairEvent\n */\n\n/**\n * A circle of a fixed size with radius specified in CSS pixels. Extends `Path`.\n *\n * @fires move {CircleMarkerMoveEvent} Fired when the marker is moved via\n * [`setLatLng`](#circlemarker-setlatlng). Old and new coordinates are included in\n * event arguments as `oldLatLng`, `latlng`.\n */\nexport class CircleMarker extends Path {\n\n\tstatic defaultOptions = {\n\t\tfill: true,\n\t\tradius: 10\n\t};\n\n\t/**\n\t * Instantiates a circle marker object given a geographical point, and an optional\n\t * options object.\n\t * @param {LatLngExpression} latlng\n\t * @param {CircleMarkerOptions} [options]\n\t */\n\tconstructor(latlng, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis._radius = this.options.radius;\n\n\t\tthis.callInitHooks(CircleMarker);\n\t}\n\n\t/**\n\t * Sets the position of a circle marker to a new location.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tconst oldLatLng = this._latlng;\n\t\tthis._latlng = new LatLng(latlng);\n\t\tthis.redraw();\n\n\t\treturn this.fire('move', {oldLatLng, latlng: this._latlng});\n\t}\n\n\t/**\n\t * Returns the current geographical position of the circle marker.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the radius of a circle marker. Units are in CSS pixels.\n\t * @param {number} radius\n\t * @returns {this}\n\t */\n\tsetRadius(radius) {\n\t\tthis.options.radius = this._radius = radius;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the current radius of the circle. Units are in CSS pixels.\n\t * @returns {number}\n\t */\n\tgetRadius() {\n\t\treturn this._radius;\n\t}\n\n\t/**\n\t * Changes the appearance of the circle marker, also its `radius`.\n\t * @param {CircleMarkerOptions} options\n\t * @returns {this}\n\t */\n\tsetStyle(options) {\n\t\tsuper.setStyle(options);\n\t\tif (options?.radius !== undefined) {\n\t\t\tthis.setRadius(options.radius);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_project() {\n\t\t// snapped to whole pixels: subpixel precision is invisible on markers but slows down rendering many of them\n\t\tthis._point = this._map.latLngToLayerPoint(this._latlng)._round();\n\t\tthis._pxRadius = this._radius;\n\t\tthis._updateBounds();\n\t}\n\n\t_updateBounds() {\n\t\tconst r = this._pxRadius,\n\t\tr2 = this._pxRadiusY ?? r,\n\t\tw = this._clickTolerance(),\n\t\tp = [r + w, r2 + w];\n\t\tthis._pxBounds = new Bounds(this._point.subtract(p), this._point.add(p));\n\t}\n\n\t_update() {\n\t\tif (this._map) {\n\t\t\tthis._updatePath();\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updateCircle(this);\n\t}\n\n\t_empty() {\n\t\treturn this._pxRadius && !this._renderer._bounds.intersects(this._pxBounds);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\treturn p.distanceTo(this._point) <= this._pxRadius + this._clickTolerance();\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the circle marker (as a GeoJSON `Point` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn pointToGeoJSON(this, precision);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,eAAb,MAAa,qBAAqB,KAAK;CAEtC,OAAO,iBAAiB;EACvB,MAAM;EACN,QAAQ;CACT;;;;;;;CAQA,YAAY,QAAQ,SAAS;EAC5B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B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pB,OAAO,eAAe,MAAM,SAAS;CACtC;AACD"}
@@ -1,9 +1,8 @@
1
1
  import { setOptions, stamp } from "../../core/Util.js";
2
- import Browser_default from "../../core/Browser.js";
2
+ import { SVG } from "./SVG.js";
3
3
  import { Path } from "./Path.js";
4
4
  import { Canvas } from "./Canvas.js";
5
- import { SVG } from "./SVG.js";
6
- //#region src/layer/vector/Path.DashAnimation.js
5
+ // src/layer/vector/Path.DashAnimation.js
7
6
  const DASH_SEPARATOR_RE = /[ ,]+/;
8
7
  const { _updateStyle: updateSvgStyle } = SVG.prototype, { _fillStroke: fillStroke, _destroyContainer: destroyCanvasContainer } = Canvas.prototype;
9
8
  /**
@@ -61,7 +60,7 @@ Canvas.include({
61
60
  destroyCanvasContainer.call(this);
62
61
  },
63
62
  _getDashShift(layer) {
64
- const speed = layer.options.dashSpeed, length = speed && !Browser_default.reducedMotion && layer._getDashLength();
63
+ const speed = layer.options.dashSpeed, length = speed && !this._map._prefersReducedMotion() && layer._getDashLength();
65
64
  if (!length) return 0;
66
65
  this._animatedDashes ??= /* @__PURE__ */ new Set();
67
66
  this._animatedDashes.add(layer);
@@ -73,6 +72,5 @@ Canvas.include({
73
72
  return performance.now() / 1e3 * speed % length;
74
73
  }
75
74
  });
76
- //#endregion
77
75
 
78
76
  //# sourceMappingURL=Path.DashAnimation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Path.DashAnimation.js","names":["Browser","Util.stamp"],"sources":["../../../../src/layer/vector/Path.DashAnimation.js"],"sourcesContent":["import {Path} from './Path.js';\nimport {SVG} from './SVG.js';\nimport {Canvas} from './Canvas.js';\nimport * as Util from '../../core/Util.js';\nimport Browser from '../../core/Browser.js';\n\nconst DASH_SEPARATOR_RE = /[ ,]+/;\n\n// The methods extended below\nconst {_updateStyle: updateSvgStyle} = SVG.prototype,\n{_fillStroke: fillStroke, _destroyContainer: destroyCanvasContainer} = Canvas.prototype;\n\n/**\n * Options of `Path` for the animation of dashes. The animation of dashes is an\n * optional feature: import this module to add the `dashSpeed` option to `Path`.\n *\n * ```js\n * import 'maplair/dash-animation';\n *\n * new Polyline(latlngs, {dashArray: '10, 10', dashSpeed: 20}).addTo(map);\n * ```\n *\n * Inspired by the [leaflet-ant-path](https://github.com/rubenspgcavalcante/leaflet-ant-path) plugin.\n * @typedef {object} DashAnimationPathOptions\n * @lends PathOptions\n * @property {number} [dashSpeed=0] Animates the dashes of the `dashArray` along the\n * path (\"marching ants\"), e.g. to show the direction of a flow: the speed in pixels per\n * second, negative for the opposite direction. Not animated with\n * [reduced motion](https://developer.mozilla.org/docs/Web/CSS/@media/prefers-reduced-motion).\n */\n\nPath.include({\n\toptions: {\n\t\tdashSpeed: 0\n\t},\n\n\t// The length of the dash pattern (repeated if it has an odd number of values)\n\t_getDashLength() {\n\t\tconst dashArray = this.options.dashArray,\n\t\tvalues = (Array.isArray(dashArray) ? dashArray : String(dashArray ?? '').split(DASH_SEPARATOR_RE))\n\t\t\t.map(Number).filter(n => !Number.isNaN(n)),\n\t\tlength = values.reduce((sum, value) => sum + value, 0);\n\t\treturn values.length % 2 ? length * 2 : length;\n\t}\n});\n\nSVG.include({\n\t// a CSS animation of the dash offset by the length of the dash pattern\n\t_updateStyle(layer) {\n\t\tupdateSvgStyle.call(this, layer);\n\t\tconst path = layer._path;\n\t\tif (!path) { return; }\n\t\tconst speed = layer.options.dashSpeed,\n\t\tdashLength = layer.options.stroke && speed && layer._getDashLength();\n\t\tpath.classList.toggle('maplair-dash-animated', !!dashLength);\n\t\tif (dashLength) {\n\t\t\tpath.style.setProperty('--maplair-dash-length', `${Math.sign(speed) * dashLength}px`);\n\t\t\tpath.style.setProperty('--maplair-dash-duration', `${dashLength / Math.abs(speed)}s`);\n\t\t}\n\t}\n});\n\nCanvas.include({\n\t// drawing with the dash offset shifted by the time\n\t_fillStroke(ctx, layer) {\n\t\tconst shift = this._getDashShift(layer);\n\t\tif (!shift) {\n\t\t\tfillStroke.call(this, ctx, layer);\n\t\t\treturn;\n\t\t}\n\t\tconst options = layer.options,\n\t\town = Object.hasOwn(options, 'dashOffset'),\n\t\tdashOffset = options.dashOffset;\n\t\tUtil.setOptions(layer, {dashOffset: Number(dashOffset ?? 0) - shift});\n\t\tfillStroke.call(this, ctx, layer);\n\t\tif (own) {\n\t\t\toptions.dashOffset = dashOffset;\n\t\t} else {\n\t\t\tdelete options.dashOffset;\n\t\t}\n\t},\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._dashFrame);\n\t\tthis._dashFrame = null;\n\t\tdestroyCanvasContainer.call(this);\n\t},\n\n\t// The shift of the dashes of an animated path, and keeps redrawing it\n\t_getDashShift(layer) {\n\t\tconst speed = layer.options.dashSpeed,\n\t\tlength = speed && !Browser.reducedMotion && layer._getDashLength();\n\t\tif (!length) { return 0; }\n\n\t\tthis._animatedDashes ??= new Set();\n\t\tthis._animatedDashes.add(layer);\n\t\tthis._dashFrame ??= requestAnimationFrame(() => {\n\t\t\tthis._dashFrame = null;\n\t\t\tfor (const animated of this._animatedDashes) {\n\t\t\t\tif (this._layers[Util.stamp(animated)] && animated.options.dashSpeed) {\n\t\t\t\t\tthis._requestRedraw(animated);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._animatedDashes.clear();\n\t\t});\n\t\treturn (performance.now() / 1000 * speed) % length;\n\t}\n});\n"],"mappings":";;;;;;AAMA,MAAM,oBAAoB;AAG1B,MAAM,EAAC,cAAc,mBAAkB,IAAI,WAC3C,EAAC,aAAa,YAAY,mBAAmB,2BAA0B,OAAO;;;;;;;;;;;;;;;;;;;AAqB9E,KAAK,QAAQ;CACZ,SAAS,EACR,WAAW,EACZ;CAGA,iBAAiB;EAChB,MAAM,YAAY,KAAK,QAAQ,WAC/B,UAAU,MAAM,QAAQ,SAAS,IAAI,YAAY,OAAO,aAAa,EAAE,CAAC,CAAC,MAAM,iBAAiB,EAAA,CAC9F,IAAI,MAAM,CAAC,CAAC,QAAO,MAAK,CAAC,OAAO,MAAM,CAAC,CAAC,GAC1C,SAAS,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,eAAe,4BAA4B;GAC/C,KAAK,aAAa;GAClB,KAAK,MAAM,YAAY,KAAK,iBAC3B,IAAI,KAAK,QAAQC,MAAW,QAAQ,MAAM,SAAS,QAAQ,WAC1D,KAAK,eAAe,QAAQ;GAG9B,KAAK,gBAAgB,MAAM;EAC5B,CAAC;EACD,OAAQ,YAAY,IAAI,IAAI,MAAO,QAAS;CAC7C;AACD,CAAC"}
1
+ {"version":3,"file":"Path.DashAnimation.js","names":["Util.stamp"],"sources":["../../../../src/layer/vector/Path.DashAnimation.js"],"sourcesContent":["import {Path} from './Path.js';\nimport {SVG} from './SVG.js';\nimport {Canvas} from './Canvas.js';\nimport * as Util from '../../core/Util.js';\n\nconst DASH_SEPARATOR_RE = /[ ,]+/;\n\n// The methods extended below\nconst {_updateStyle: updateSvgStyle} = SVG.prototype,\n{_fillStroke: fillStroke, _destroyContainer: destroyCanvasContainer} = Canvas.prototype;\n\n/**\n * Options of `Path` for the animation of dashes. The animation of dashes is an\n * optional feature: import this module to add the `dashSpeed` option to `Path`.\n *\n * ```js\n * import 'maplair/dash-animation';\n *\n * new Polyline(latlngs, {dashArray: '10, 10', dashSpeed: 20}).addTo(map);\n * ```\n *\n * Inspired by the [leaflet-ant-path](https://github.com/rubenspgcavalcante/leaflet-ant-path) plugin.\n * @typedef {object} DashAnimationPathOptions\n * @lends PathOptions\n * @property {number} [dashSpeed=0] Animates the dashes of the `dashArray` along the\n * path (\"marching ants\"), e.g. to show the direction of a flow: the speed in pixels per\n * second, negative for the opposite direction. Not animated with\n * [reduced motion](https://developer.mozilla.org/docs/Web/CSS/@media/prefers-reduced-motion).\n */\n\nPath.include({\n\toptions: {\n\t\tdashSpeed: 0\n\t},\n\n\t// The length of the dash pattern (repeated if it has an odd number of values)\n\t_getDashLength() {\n\t\tconst dashArray = this.options.dashArray,\n\t\tvalues = (Array.isArray(dashArray) ? dashArray : String(dashArray ?? '').split(DASH_SEPARATOR_RE))\n\t\t\t.map(Number).filter(n => !Number.isNaN(n)),\n\t\tlength = values.reduce((sum, value) => sum + value, 0);\n\t\treturn values.length % 2 ? length * 2 : length;\n\t}\n});\n\nSVG.include({\n\t// a CSS animation of the dash offset by the length of the dash pattern\n\t_updateStyle(layer) {\n\t\tupdateSvgStyle.call(this, layer);\n\t\tconst path = layer._path;\n\t\tif (!path) { return; }\n\t\tconst speed = layer.options.dashSpeed,\n\t\tdashLength = layer.options.stroke && speed && layer._getDashLength();\n\t\tpath.classList.toggle('maplair-dash-animated', !!dashLength);\n\t\tif (dashLength) {\n\t\t\tpath.style.setProperty('--maplair-dash-length', `${Math.sign(speed) * dashLength}px`);\n\t\t\tpath.style.setProperty('--maplair-dash-duration', `${dashLength / Math.abs(speed)}s`);\n\t\t}\n\t}\n});\n\nCanvas.include({\n\t// drawing with the dash offset shifted by the time\n\t_fillStroke(ctx, layer) {\n\t\tconst shift = this._getDashShift(layer);\n\t\tif (!shift) {\n\t\t\tfillStroke.call(this, ctx, layer);\n\t\t\treturn;\n\t\t}\n\t\tconst options = layer.options,\n\t\town = Object.hasOwn(options, 'dashOffset'),\n\t\tdashOffset = options.dashOffset;\n\t\tUtil.setOptions(layer, {dashOffset: Number(dashOffset ?? 0) - shift});\n\t\tfillStroke.call(this, ctx, layer);\n\t\tif (own) {\n\t\t\toptions.dashOffset = dashOffset;\n\t\t} else {\n\t\t\tdelete options.dashOffset;\n\t\t}\n\t},\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._dashFrame);\n\t\tthis._dashFrame = null;\n\t\tdestroyCanvasContainer.call(this);\n\t},\n\n\t// The shift of the dashes of an animated path, and keeps redrawing it\n\t_getDashShift(layer) {\n\t\tconst speed = layer.options.dashSpeed,\n\t\tlength = speed && !this._map._prefersReducedMotion() && layer._getDashLength();\n\t\tif (!length) { return 0; }\n\n\t\tthis._animatedDashes ??= new Set();\n\t\tthis._animatedDashes.add(layer);\n\t\tthis._dashFrame ??= requestAnimationFrame(() => {\n\t\t\tthis._dashFrame = null;\n\t\t\tfor (const animated of this._animatedDashes) {\n\t\t\t\tif (this._layers[Util.stamp(animated)] && animated.options.dashSpeed) {\n\t\t\t\t\tthis._requestRedraw(animated);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._animatedDashes.clear();\n\t\t});\n\t\treturn (performance.now() / 1000 * speed) % length;\n\t}\n});\n"],"mappings":";;;;;AAKA,MAAM,oBAAoB;AAG1B,MAAM,EAAC,cAAc,mBAAkB,IAAI,WAC3C,EAAC,aAAa,YAAY,mBAAmB,2BAA0B,OAAO;;;;;;;;;;;;;;;;;;;AAqB9E,KAAK,QAAQ;CACZ,SAAS,EACR,WAAW,EACZ;CAGA,iBAAiB;EAChB,MAAM,YAAY,KAAK,QAAQ,WAC/B,UAAU,MAAM,QAAQ,SAAS,IAAI,YAAY,OAAO,aAAa,EAAE,CAAC,CAAC,MAAM,iBAAiB,EAAA,CAC9F,IAAI,MAAM,CAAC,CAAC,QAAO,MAAK,CAAC,OAAO,MAAM,CAAC,CAAC,GAC1C,SAAS,OAAO,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;EACrD,OAAO,OAAO,SAAS,IAAI,SAAS,IAAI;CACzC;AACD,CAAC;AAED,IAAI,QAAQ,EAEX,aAAa,OAAO;CACnB,eAAe,KAAK,MAAM,KAAK;CAC/B,MAAM,OAAO,MAAM;CACnB,IAAI,CAAC,MAAQ;CACb,MAAM,QAAQ,MAAM,QAAQ,WAC5B,aAAa,MAAM,QAAQ,UAAU,SAAS,MAAM,eAAe;CACnE,KAAK,UAAU,OAAO,yBAAyB,CAAC,CAAC,UAAU;CAC3D,IAAI,YAAY;EACf,KAAK,MAAM,YAAY,yBAAyB,GAAG,KAAK,KAAK,KAAK,IAAI,WAAW,GAAG;EACpF,KAAK,MAAM,YAAY,2BAA2B,GAAG,aAAa,KAAK,IAAI,KAAK,EAAE,EAAE;CACrF;AACD,EACD,CAAC;AAED,OAAO,QAAQ;CAEd,YAAY,KAAK,OAAO;EACvB,MAAM,QAAQ,KAAK,cAAc,KAAK;EACtC,IAAI,CAAC,OAAO;GACX,WAAW,KAAK,MAAM,KAAK,KAAK;GAChC;EACD;EACA,MAAM,UAAU,MAAM,SACtB,MAAM,OAAO,OAAO,SAAS,YAAY,GACzC,aAAa,QAAQ;EACrB,WAAgB,OAAO,EAAC,YAAY,OAAO,cAAc,CAAC,IAAI,MAAK,CAAC;EACpE,WAAW,KAAK,MAAM,KAAK,KAAK;EAChC,IAAI,KACH,QAAQ,aAAa;OAErB,OAAO,QAAQ;CAEjB;CAEA,oBAAoB;EACnB,qBAAqB,KAAK,UAAU;EACpC,KAAK,aAAa;EAClB,uBAAuB,KAAK,IAAI;CACjC;CAGA,cAAc,OAAO;EACpB,MAAM,QAAQ,MAAM,QAAQ,WAC5B,SAAS,SAAS,CAAC,KAAK,KAAK,sBAAsB,KAAK,MAAM,eAAe;EAC7E,IAAI,CAAC,QAAU,OAAO;EAEtB,KAAK,oCAAoB,IAAI,IAAI;EACjC,KAAK,gBAAgB,IAAI,KAAK;EAC9B,KAAK,eAAe,4BAA4B;GAC/C,KAAK,aAAa;GAClB,KAAK,MAAM,YAAY,KAAK,iBAC3B,IAAI,KAAK,QAAQA,MAAW,QAAQ,MAAM,SAAS,QAAQ,WAC1D,KAAK,eAAe,QAAQ;GAG9B,KAAK,gBAAgB,MAAM;EAC5B,CAAC;EACD,OAAQ,YAAY,IAAI,IAAI,MAAO,QAAS;CAC7C;AACD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Path } from "./Path.js";
2
2
  import { CircleMarker } from "./CircleMarker.js";
3
- //#region src/layer/vector/Path.ZoomStyles.js
3
+ // src/layer/vector/Path.ZoomStyles.js
4
4
  /**
5
5
  * A zoom-dependent style value, of the `weight` option of paths and the `radius` of
6
6
  * circle markers: either a function of the zoom or an object of zoom stops
@@ -72,6 +72,5 @@ CircleMarker.include({ setRadius(radius) {
72
72
  Path.addInitHook(function() {
73
73
  this._takeZoomStyles(this.options);
74
74
  });
75
- //#endregion
76
75
 
77
76
  //# sourceMappingURL=Path.ZoomStyles.js.map
@@ -1,6 +1,7 @@
1
1
  import { setOptions } from "../../core/Util.js";
2
2
  import { Layer } from "../Layer.js";
3
- //#region src/layer/vector/Path.js
3
+ import { SVG } from "./SVG.js";
4
+ // src/layer/vector/Path.js
4
5
  /** @import {InteractiveLayerOptions} from '../Layer.js' */
5
6
  /** @import {MaplairMap} from '../../map/Map.js' */
6
7
  /** @import {Renderer} from './Renderer.js' */
@@ -32,9 +33,11 @@ import { Layer } from "../Layer.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
  /**
@@ -42,24 +45,22 @@ import { Layer } from "../Layer.js";
42
45
  * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
43
46
  */
44
47
  var Path = class extends Layer {
45
- static {
46
- this.setDefaultOptions({
47
- stroke: true,
48
- color: "#3388ff",
49
- weight: 3,
50
- opacity: 1,
51
- lineCap: "round",
52
- lineJoin: "round",
53
- dashArray: null,
54
- dashOffset: null,
55
- fill: false,
56
- fillColor: null,
57
- fillOpacity: .2,
58
- fillRule: "evenodd",
59
- interactive: true,
60
- bubblingPointerEvents: true
61
- });
62
- }
48
+ static defaultOptions = {
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: .2,
60
+ fillRule: "evenodd",
61
+ interactive: true,
62
+ bubblingPointerEvents: true
63
+ };
63
64
  /**
64
65
  * Gets the renderer of the path from the map, before it is added.
65
66
  * @param {MaplairMap} map
@@ -94,6 +95,9 @@ var Path = class extends Layer {
94
95
  }
95
96
  /**
96
97
  * Changes the appearance of a Path based on the options in the `PathOptions` object.
98
+ * Note that [`className`](#pathoptions-classname) is an exception: it is applied only
99
+ * when the path element is created, so passing it here updates the option but leaves
100
+ * the element's class unchanged.
97
101
  * @param {PathOptions} style
98
102
  * @returns {this}
99
103
  */
@@ -128,6 +132,9 @@ var Path = class extends Layer {
128
132
  getElement() {
129
133
  return this._path;
130
134
  }
135
+ _createRenderer(options) {
136
+ return new SVG(options);
137
+ }
131
138
  _reset() {
132
139
  this._project();
133
140
  this._update();
@@ -136,7 +143,6 @@ var Path = class extends Layer {
136
143
  return (this.options.stroke ? this.options.weight / 2 : 0) + (this._renderer.options.tolerance || 0);
137
144
  }
138
145
  };
139
- //#endregion
140
146
  export { Path };
141
147
 
142
148
  //# sourceMappingURL=Path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Path.js","names":[],"sources":["../../../../src/layer/vector/Path.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport * as Util from '../../core/Util.js';\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Options of `Path`, shared by all vector layers.\n * @typedef {object} PathOptions\n * @property {boolean} [stroke=true] Whether to draw stroke along the path. Set it to\n * `false` to disable borders on polygons or circles.\n * @property {string} [color='#3388ff'] Stroke color.\n * @property {number} [weight=3] Stroke width in pixels.\n * @property {number} [opacity=1] Stroke opacity.\n * @property {string} [lineCap='round'] A string that defines\n * [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap)\n * of the stroke.\n * @property {string} [lineJoin='round'] A string that defines\n * [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin)\n * of the stroke.\n * @property {string|null} [dashArray=null] A string that defines the stroke\n * [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).\n * @property {string|null} [dashOffset=null] A string that defines the\n * [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).\n * @property {boolean} [fill=false] Whether to fill the path with color. Set it to\n * `false` to disable filling on polygons or circles. The default depends on the\n * class: `true` for polygons and circles.\n * @property {string|null} [fillColor=null] Fill color. Defaults to the value of the\n * [`color`](#pathoptions-color) option.\n * @property {number} [fillOpacity=0.2] Fill opacity.\n * @property {string} [fillRule='evenodd'] A string that defines\n * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)\n * is determined.\n * @property {string} [className] Custom class name set on an element. Only for SVG renderer.\n * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this\n * path. Takes precedence over the map's [default renderer](#maplairmapoptions-renderer).\n * If set, it will override the `pane` option of the path.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * An abstract class that contains options and constants shared between vector\n * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.\n */\nexport class Path extends Layer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tstroke: true,\n\t\t\tcolor: '#3388ff',\n\t\t\tweight: 3,\n\t\t\topacity: 1,\n\t\t\tlineCap: 'round',\n\t\t\tlineJoin: 'round',\n\t\t\tdashArray: null,\n\t\t\tdashOffset: null,\n\t\t\tfill: false,\n\t\t\tfillColor: null,\n\t\t\tfillOpacity: 0.2,\n\t\t\tfillRule: 'evenodd',\n\t\t\t// className: '',\n\t\t\tinteractive: true,\n\t\t\tbubblingPointerEvents: true\n\t\t});\n\t}\n\n\t/**\n\t * Gets the renderer of the path from the map, before it is added.\n\t * @param {MaplairMap} map\n\t */\n\tbeforeAdd(map) {\n\t\t// Renderer is set here because we need to call renderer.getEvents\n\t\t// before this.getEvents.\n\t\tthis._renderer = map.getRenderer(this);\n\t}\n\n\t/**\n\t * Adds the path to its renderer.\n\t */\n\tonAdd() {\n\t\tthis._renderer._initPath(this);\n\t\tthis._reset();\n\t\tthis._renderer._addPath(this);\n\t}\n\n\t/**\n\t * Removes the path from its renderer.\n\t */\n\tonRemove() {\n\t\tthis._renderer._removePath(this);\n\t}\n\n\t/**\n\t * Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map) {\n\t\t\tthis._renderer._updatePath(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_updateInteractive() {\n\t\tthis._renderer._updateInteractive(this);\n\t}\n\n\t/**\n\t * Changes the appearance of a Path based on the options in the `PathOptions` object.\n\t * @param {PathOptions} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\tUtil.setOptions(this, style);\n\t\tif (this._renderer) {\n\t\t\tthis._renderer._updateStyle(this);\n\t\t\tif (this.options.stroke && style && Object.hasOwn(style, 'weight')) {\n\t\t\t\tthis._updateBounds();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all path layers.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tthis._renderer?._bringToFront(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all path layers.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tthis._renderer?._bringToBack(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the SVG `path` element of the layer, if it is rendered by the `SVG` renderer.\n\t * @returns {SVGPathElement|undefined}\n\t */\n\tgetElement() {\n\t\treturn this._path;\n\t}\n\n\t_reset() {\n\t\t// defined in child classes\n\t\tthis._project();\n\t\tthis._update();\n\t}\n\n\t_clickTolerance() {\n\t\t// used when doing hit detection for Canvas layers\n\t\treturn (this.options.stroke ? this.options.weight / 2 : 0) +\n\t\t (this._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"Path.js","names":[],"sources":["../../../../src/layer/vector/Path.js"],"sourcesContent":["import {Layer} from '../Layer.js';\nimport {SVG} from './SVG.js';\nimport * as Util from '../../core/Util.js';\n/** @import {InteractiveLayerOptions} from '../Layer.js' */\n/** @import {MaplairMap} from '../../map/Map.js' */\n/** @import {Renderer} from './Renderer.js' */\n\n/**\n * Options of `Path`, shared by all vector layers.\n * @typedef {object} PathOptions\n * @property {boolean} [stroke=true] Whether to draw stroke along the path. Set it to\n * `false` to disable borders on polygons or circles.\n * @property {string} [color='#3388ff'] Stroke color.\n * @property {number} [weight=3] Stroke width in pixels.\n * @property {number} [opacity=1] Stroke opacity.\n * @property {string} [lineCap='round'] A string that defines\n * [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap)\n * of the stroke.\n * @property {string} [lineJoin='round'] A string that defines\n * [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin)\n * of the stroke.\n * @property {string|null} [dashArray=null] A string that defines the stroke\n * [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray).\n * @property {string|null} [dashOffset=null] A string that defines the\n * [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset).\n * @property {boolean} [fill=false] Whether to fill the path with color. Set it to\n * `false` to disable filling on polygons or circles. The default depends on the\n * class: `true` for polygons and circles.\n * @property {string|null} [fillColor=null] Fill color. Defaults to the value of the\n * [`color`](#pathoptions-color) option.\n * @property {number} [fillOpacity=0.2] Fill opacity.\n * @property {string} [fillRule='evenodd'] A string that defines\n * [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule)\n * is determined.\n * @property {string} [className] Custom class name set on an element. Only for SVG renderer.\n * Applied when the element is created; [`setStyle`](#path-setstyle) does not update it\n * afterwards.\n * @property {Renderer} [renderer] Use this specific instance of `Renderer` for this\n * path. If not set, the path uses the map's [renderer](#maplairmapoptions-renderer),\n * which is `SVG` by default. If set, it overrides the `pane` option.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * An abstract class that contains options and constants shared between vector\n * overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.\n */\nexport class Path extends Layer {\n\n\tstatic defaultOptions = {\n\t\tstroke: true,\n\t\tcolor: '#3388ff',\n\t\tweight: 3,\n\t\topacity: 1,\n\t\tlineCap: 'round',\n\t\tlineJoin: 'round',\n\t\tdashArray: null,\n\t\tdashOffset: null,\n\t\tfill: false,\n\t\tfillColor: null,\n\t\tfillOpacity: 0.2,\n\t\tfillRule: 'evenodd',\n\t\t// className: '',\n\t\tinteractive: true,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Gets the renderer of the path from the map, before it is added.\n\t * @param {MaplairMap} map\n\t */\n\tbeforeAdd(map) {\n\t\t// Renderer is set here because we need to call renderer.getEvents\n\t\t// before this.getEvents.\n\t\tthis._renderer = map.getRenderer(this);\n\t}\n\n\t/**\n\t * Adds the path to its renderer.\n\t */\n\tonAdd() {\n\t\tthis._renderer._initPath(this);\n\t\tthis._reset();\n\t\tthis._renderer._addPath(this);\n\t}\n\n\t/**\n\t * Removes the path from its renderer.\n\t */\n\tonRemove() {\n\t\tthis._renderer._removePath(this);\n\t}\n\n\t/**\n\t * Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map) {\n\t\t\tthis._renderer._updatePath(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t_updateInteractive() {\n\t\tthis._renderer._updateInteractive(this);\n\t}\n\n\t/**\n\t * Changes the appearance of a Path based on the options in the `PathOptions` object.\n\t * Note that [`className`](#pathoptions-classname) is an exception: it is applied only\n\t * when the path element is created, so passing it here updates the option but leaves\n\t * the element's class unchanged.\n\t * @param {PathOptions} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\tUtil.setOptions(this, style);\n\t\tif (this._renderer) {\n\t\t\tthis._renderer._updateStyle(this);\n\t\t\tif (this.options.stroke && style && Object.hasOwn(style, 'weight')) {\n\t\t\t\tthis._updateBounds();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all path layers.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tthis._renderer?._bringToFront(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all path layers.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tthis._renderer?._bringToBack(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the SVG `path` element of the layer, if it is rendered by the `SVG` renderer.\n\t * @returns {SVGPathElement|undefined}\n\t */\n\tgetElement() {\n\t\treturn this._path;\n\t}\n\n\t// the renderer of the path if neither the path nor the map has one\n\t_createRenderer(options) {\n\t\treturn new SVG(options);\n\t}\n\n\t_reset() {\n\t\t// defined in child classes\n\t\tthis._project();\n\t\tthis._update();\n\t}\n\n\t_clickTolerance() {\n\t\t// used when doing hit detection for Canvas layers\n\t\treturn (this.options.stroke ? this.options.weight / 2 : 0) +\n\t\t (this._renderer.options.tolerance || 0);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,OAAb,cAA0B,MAAM;CAE/B,OAAO,iBAAiB;EACvB,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,SAAS;EACT,SAAS;EACT,UAAU;EACV,WAAW;EACX,YAAY;EACZ,MAAM;EACN,WAAW;EACX,aAAa;EACb,UAAU;EAEV,aAAa;EACb,uBAAuB;CACxB;;;;;CAMA,UAAU,KAAK;EAGd,KAAK,YAAY,IAAI,YAAY,IAAI;CACtC;;;;CAKA,QAAQ;EACP,KAAK,UAAU,UAAU,IAAI;EAC7B,KAAK,OAAO;EACZ,KAAK,UAAU,SAAS,IAAI;CAC7B;;;;CAKA,WAAW;EACV,KAAK,UAAU,YAAY,IAAI;CAChC;;;;;CAMA,SAAS;EACR,IAAI,KAAK,MACR,KAAK,UAAU,YAAY,IAAI;EAEhC,OAAO;CACR;CAEA,qBAAqB;EACpB,KAAK,UAAU,mBAAmB,IAAI;CACvC;;;;;;;;;CAUA,SAAS,OAAO;EACf,WAAgB,MAAM,KAAK;EAC3B,IAAI,KAAK,WAAW;GACnB,KAAK,UAAU,aAAa,IAAI;GAChC,IAAI,KAAK,QAAQ,UAAU,SAAS,OAAO,OAAO,OAAO,QAAQ,GAChE,KAAK,cAAc;EAErB;EACA,OAAO;CACR;;;;;CAMA,eAAe;EACd,KAAK,WAAW,cAAc,IAAI;EAClC,OAAO;CACR;;;;;CAMA,cAAc;EACb,KAAK,WAAW,aAAa,IAAI;EACjC,OAAO;CACR;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;CAGA,gBAAgB,SAAS;EACxB,OAAO,IAAI,IAAI,OAAO;CACvB;CAEA,SAAS;EAER,KAAK,SAAS;EACd,KAAK,QAAQ;CACd;CAEA,kBAAkB;EAEjB,QAAQ,KAAK,QAAQ,SAAS,KAAK,QAAQ,SAAS,IAAI,MACrD,KAAK,UAAU,QAAQ,aAAa;CACxC;AACD"}
@@ -1,10 +1,12 @@
1
1
  import { Point } from "../../geometry/Point.js";
2
2
  import { Bounds } from "../../geometry/Bounds.js";
3
3
  import { LatLng } from "../../geo/LatLng.js";
4
- import { clipPolygon, polygonCenter } from "../../geometry/PolyUtil.js";
5
4
  import { isFlat } from "../../geometry/LineUtil.js";
5
+ import { getFeature, latLngsToCoords } from "../GeoJSONUtil.js";
6
6
  import { Polyline } from "./Polyline.js";
7
- //#region src/layer/vector/Polygon.js
7
+ import { clipPolygon, polygonCenter } from "../../geometry/PolyUtil.js";
8
+ // src/layer/vector/Polygon.js
9
+ /** @import {Feature} from 'geojson' */
8
10
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
9
11
  /** @import {PolylineOptions} from './Polyline.js' */
10
12
  /**
@@ -55,9 +57,7 @@ import { Polyline } from "./Polyline.js";
55
57
  * ```
56
58
  */
57
59
  var Polygon = class Polygon extends Polyline {
58
- static {
59
- this.setDefaultOptions({ fill: true });
60
- }
60
+ static defaultOptions = { fill: true };
61
61
  /**
62
62
  * Instantiates a polygon object given an array of geographical points (or arrays
63
63
  * of them for holes and multi-polygons) and optionally an options object.
@@ -110,7 +110,7 @@ var Polygon = class Polygon extends Polyline {
110
110
  return;
111
111
  }
112
112
  for (const ring of this._rings) {
113
- const clipped = clipPolygon(ring, bounds, true);
113
+ const clipped = clipPolygon(ring, bounds);
114
114
  if (clipped.length) this._parts.push(clipped);
115
115
  }
116
116
  }
@@ -130,8 +130,23 @@ var Polygon = class Polygon extends Polyline {
130
130
  }
131
131
  return inside || super._containsPoint(p, true);
132
132
  }
133
+ /**
134
+ * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
135
+ * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
136
+ * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).
137
+ * @param {number|false} [precision]
138
+ * @returns {Feature}
139
+ */
140
+ toGeoJSON(precision) {
141
+ const holes = !isFlat(this._latlngs), multi = holes && !isFlat(this._latlngs[0]);
142
+ let coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);
143
+ if (!holes) coords = [coords];
144
+ return getFeature(this, {
145
+ type: `${multi ? "Multi" : ""}Polygon`,
146
+ coordinates: coords
147
+ });
148
+ }
133
149
  };
134
- //#endregion
135
150
  export { Polygon };
136
151
 
137
152
  //# sourceMappingURL=Polygon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Polygon.js","names":["PolyUtil.polygonCenter","LineUtil.isFlat","PolyUtil.clipPolygon"],"sources":["../../../../src/layer/vector/Polygon.js"],"sourcesContent":["import {Polyline} from './Polyline.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport * as PolyUtil from '../../geometry/PolyUtil.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PolylineOptions} from './Polyline.js' */\n\n/**\n * Options of `Polygon`.\n * @typedef {object} PolygonOptions\n * @property {boolean} [fill=true] Whether to fill the polygon with color.\n * @extends PolylineOptions\n */\n\n/**\n * A class for drawing polygon overlays on a map. Extends `Polyline`.\n *\n * Note that points you pass when creating a polygon shouldn't have an additional last\n * point equal to the first one — it's better to filter out such points.\n *\n * @example\n * ```js\n * // create a red polygon from an array of LatLng points\n * const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];\n *\n * const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polygon\n * map.fitBounds(polygon.getBounds());\n * ```\n *\n * You can also pass an array of arrays of latlngs, with the first array representing\n * the outer shape and the other arrays representing holes in the outer shape:\n *\n * ```js\n * const latlngs = [\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ];\n * ```\n *\n * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.\n *\n * ```js\n * const latlngs = [\n * [ // first polygon\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ],\n * [ // second polygon\n * [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]\n * ]\n * ];\n * ```\n */\nexport class Polygon extends Polyline {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tfill: true\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a polygon object given an array of geographical points (or arrays\n\t * of them for holes and multi-polygons) and optionally an options object.\n\t * @overload\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolygonOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Polygon);\n\t}\n\n\t/**\n\t * Returns `true` if the Polygon has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length || !this._latlngs[0].length;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the Polygon.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn PolyUtil.polygonCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t_convertLatLngs(latlngs) {\n\t\tconst result = super._convertLatLngs(latlngs),\n\t\tlen = result.length;\n\n\t\t// remove last point if it equals first one\n\t\tif (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) {\n\t\t\tresult.pop();\n\t\t}\n\t\treturn result;\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tsuper._setLatLngs(latlngs);\n\t\tif (LineUtil.isFlat(this._latlngs)) {\n\t\t\tthis._latlngs = [this._latlngs];\n\t\t}\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0];\n\t}\n\n\t_clipPoints() {\n\t\t// polygons need a different clipping algorithm so we redefine that\n\n\t\tlet bounds = this._renderer._bounds;\n\t\tconst w = this.options.weight,\n\t\tp = new Point(w, w);\n\n\t\t// increase clip padding by stroke width to avoid stroke on clip edges\n\t\tbounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const ring of this._rings) {\n\t\t\tconst clipped = PolyUtil.clipPolygon(ring, bounds, true);\n\t\t\tif (clipped.length) {\n\t\t\t\tthis._parts.push(clipped);\n\t\t\t}\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this, true);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\tlet inside = false,\n\t\tpart, p1, p2, i, j, k, len, len2;\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// ray casting algorithm for detecting if point is in polygon\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tp1 = part[j];\n\t\t\t\tp2 = part[k];\n\n\t\t\t\tif (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {\n\t\t\t\t\tinside = !inside;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// also check if it's on polygon stroke\n\t\treturn inside || super._containsPoint(p, true);\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,IAAa,UAAb,MAAa,gBAAgB,SAAS;CAErC;EACC,KAAK,kBAAkB,EACtB,MAAM,KACP,CAAC;CACF;;;;;;;;;;;CAYA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,OAAO;CAC3B;;;;;CAMA,UAAU;EACT,OAAO,CAAC,KAAK,SAAS,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;CACnD;;;;;CAMA,YAAY;EAEX,IAAI,CAAC,KAAK,MACT,MAAM,IAAI,MAAM,gDAAgD;EAEjE,OAAOA,cAAuB,KAAK,cAAc,GAAG,KAAK,KAAK,QAAQ,GAAG;CAC1E;CAEA,gBAAgB,SAAS;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OAAO,KAAK,QAAQ,IAAI,OAAO,GAAG,IAAI,MAAM,IAAI,KAAK;IAChE,KAAK,KAAK;IACV,KAAK,KAAK;IAEV,IAAM,GAAG,IAAI,EAAE,MAAQ,GAAG,IAAI,EAAE,KAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,GAC/F,SAAS,CAAC;GAEZ;EACD;EAGA,OAAO,UAAU,MAAM,eAAe,GAAG,IAAI;CAC9C;AAED"}
1
+ {"version":3,"file":"Polygon.js","names":["PolyUtil.polygonCenter","LineUtil.isFlat","PolyUtil.clipPolygon"],"sources":["../../../../src/layer/vector/Polygon.js"],"sourcesContent":["import {Polyline} from './Polyline.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport * as PolyUtil from '../../geometry/PolyUtil.js';\nimport {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PolylineOptions} from './Polyline.js' */\n\n/**\n * Options of `Polygon`.\n * @typedef {object} PolygonOptions\n * @property {boolean} [fill=true] Whether to fill the polygon with color.\n * @extends PolylineOptions\n */\n\n/**\n * A class for drawing polygon overlays on a map. Extends `Polyline`.\n *\n * Note that points you pass when creating a polygon shouldn't have an additional last\n * point equal to the first one — it's better to filter out such points.\n *\n * @example\n * ```js\n * // create a red polygon from an array of LatLng points\n * const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];\n *\n * const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polygon\n * map.fitBounds(polygon.getBounds());\n * ```\n *\n * You can also pass an array of arrays of latlngs, with the first array representing\n * the outer shape and the other arrays representing holes in the outer shape:\n *\n * ```js\n * const latlngs = [\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ];\n * ```\n *\n * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.\n *\n * ```js\n * const latlngs = [\n * [ // first polygon\n * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring\n * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole\n * ],\n * [ // second polygon\n * [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]\n * ]\n * ];\n * ```\n */\nexport class Polygon extends Polyline {\n\n\tstatic defaultOptions = {\n\t\tfill: true\n\t};\n\n\t/**\n\t * Instantiates a polygon object given an array of geographical points (or arrays\n\t * of them for holes and multi-polygons) and optionally an options object.\n\t * @overload\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolygonOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Polygon);\n\t}\n\n\t/**\n\t * Returns `true` if the Polygon has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length || !this._latlngs[0].length;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the Polygon.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn PolyUtil.polygonCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t_convertLatLngs(latlngs) {\n\t\tconst result = super._convertLatLngs(latlngs),\n\t\tlen = result.length;\n\n\t\t// remove last point if it equals first one\n\t\tif (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) {\n\t\t\tresult.pop();\n\t\t}\n\t\treturn result;\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tsuper._setLatLngs(latlngs);\n\t\tif (LineUtil.isFlat(this._latlngs)) {\n\t\t\tthis._latlngs = [this._latlngs];\n\t\t}\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0];\n\t}\n\n\t_clipPoints() {\n\t\t// polygons need a different clipping algorithm so we redefine that\n\n\t\tlet bounds = this._renderer._bounds;\n\t\tconst w = this.options.weight,\n\t\tp = new Point(w, w);\n\n\t\t// increase clip padding by stroke width to avoid stroke on clip edges\n\t\tbounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const ring of this._rings) {\n\t\t\tconst clipped = PolyUtil.clipPolygon(ring, bounds);\n\t\t\tif (clipped.length) {\n\t\t\t\tthis._parts.push(clipped);\n\t\t\t}\n\t\t}\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this, true);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p) {\n\t\tlet inside = false,\n\t\tpart, p1, p2, i, j, k, len, len2;\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// ray casting algorithm for detecting if point is in polygon\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tp1 = part[j];\n\t\t\t\tp2 = part[k];\n\n\t\t\t\tif (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {\n\t\t\t\t\tinside = !inside;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// also check if it's on polygon stroke\n\t\treturn inside || super._containsPoint(p, true);\n\t}\n\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst holes = !LineUtil.isFlat(this._latlngs),\n\t\tmulti = holes && !LineUtil.isFlat(this._latlngs[0]);\n\n\t\tlet coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);\n\n\t\tif (!holes) {\n\t\t\tcoords = [coords];\n\t\t}\n\n\t\treturn getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,UAAb,MAAa,gBAAgB,SAAS;CAErC,OAAO,iBAAiB,EACvB,MAAM,KACP;;;;;;;;;;;CAYA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,OAAO;CAC3B;;;;;CAMA,UAAU;EACT,OAAO,CAAC,KAAK,SAAS,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;CACnD;;;;;CAMA,YAAY;EAEX,IAAI,CAAC,KAAK,MACT,MAAM,IAAI,MAAM,gDAAgD;EAEjE,OAAOA,cAAuB,KAAK,cAAc,GAAG,KAAK,KAAK,QAAQ,GAAG;CAC1E;CAEA,gBAAgB,SAAS;EACxB,MAAM,SAAS,MAAM,gBAAgB,OAAO,GAC5C,MAAM,OAAO;EAGb,IAAI,OAAO,KAAK,OAAO,cAAc,UAAU,OAAO,EAAE,CAAC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E,MAAQ,GAAG,IAAI,EAAE,KAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,GAC/F,SAAS,CAAC;GAEZ;EACD;EAGA,OAAO,UAAU,MAAM,eAAe,GAAG,IAAI;CAC9C;;;;;;;;CAUA,UAAU,WAAW;EACpB,MAAM,QAAQ,CAACD,OAAgB,KAAK,QAAQ,GAC5C,QAAQ,SAAS,CAACA,OAAgB,KAAK,SAAS,EAAE;EAElD,IAAI,SAAS,gBAAgB,KAAK,UAAU,QAAQ,IAAI,QAAQ,IAAI,GAAG,MAAM,SAAS;EAEtF,IAAI,CAAC,OACJ,SAAS,CAAC,MAAM;EAGjB,OAAO,WAAW,MAAM;GACvB,MAAM,GAAG,QAAQ,UAAU,GAAG;GAC9B,aAAa;EACd,CAAC;CACF;AACD"}
@@ -1,10 +1,10 @@
1
1
  import { stamp } from "../../core/Util.js";
2
2
  import { Point } from "../../geometry/Point.js";
3
- import { Path } from "./Path.js";
4
- import { Canvas } from "./Canvas.js";
5
3
  import { SVG } from "./SVG.js";
4
+ import { Path } from "./Path.js";
6
5
  import { Polyline } from "./Polyline.js";
7
- //#region src/layer/vector/Polyline.Decorations.js
6
+ import { Canvas } from "./Canvas.js";
7
+ // src/layer/vector/Polyline.Decorations.js
8
8
  /**
9
9
  * Options of `Path` for arrowheads and text along lines (for `Polyline`s and
10
10
  * `Polygon`s). They are an optional feature: import this module to add the
@@ -239,6 +239,5 @@ Canvas.include({
239
239
  }
240
240
  }
241
241
  });
242
- //#endregion
243
242
 
244
243
  //# sourceMappingURL=Polyline.Decorations.js.map
@@ -1,11 +1,13 @@
1
1
  import { setOptions } from "../../core/Util.js";
2
2
  import { Point } from "../../geometry/Point.js";
3
- import { Path } from "./Path.js";
4
3
  import { Bounds } from "../../geometry/Bounds.js";
4
+ import { Path } from "./Path.js";
5
5
  import { LatLngBounds } from "../../geo/LatLngBounds.js";
6
6
  import { LatLng } from "../../geo/LatLng.js";
7
7
  import { _sqClosestPointOnSegment, clipSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify } from "../../geometry/LineUtil.js";
8
- //#region src/layer/vector/Polyline.js
8
+ import { getFeature, latLngsToCoords } from "../GeoJSONUtil.js";
9
+ // src/layer/vector/Polyline.js
10
+ /** @import {Feature} from 'geojson' */
9
11
  /** @import {LatLngExpression} from '../../geo/LatLng.js' */
10
12
  /** @import {PointExpression} from '../../geometry/Point.js' */
11
13
  /** @import {PathOptions} from './Path.js' */
@@ -51,12 +53,10 @@ import { _sqClosestPointOnSegment, clipSegment, isFlat, pointToSegmentDistance,
51
53
  * ```
52
54
  */
53
55
  var Polyline = class Polyline extends Path {
54
- static {
55
- this.setDefaultOptions({
56
- smoothFactor: .5,
57
- noClip: false
58
- });
59
- }
56
+ static defaultOptions = {
57
+ smoothFactor: .5,
58
+ noClip: false
59
+ };
60
60
  /**
61
61
  * Instantiates a polyline object given an array of geographical points and
62
62
  * optionally an options object. You can create a `Polyline` object with
@@ -197,7 +197,7 @@ var Polyline = class Polyline extends Path {
197
197
  for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
198
198
  points = this._rings[i];
199
199
  for (j = 0, len2 = points.length; j < len2 - 1; j++) {
200
- segment = clipSegment(points[j], points[j + 1], bounds, j, true);
200
+ segment = clipSegment(points[j], points[j + 1], bounds, j);
201
201
  if (!segment) continue;
202
202
  parts[k] ??= [];
203
203
  parts[k].push(segment[0]);
@@ -234,8 +234,23 @@ var Polyline = class Polyline extends Path {
234
234
  }
235
235
  return false;
236
236
  }
237
+ /**
238
+ * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
239
+ * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
240
+ * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`
241
+ * Feature).
242
+ * @param {number|false} [precision]
243
+ * @returns {Feature}
244
+ */
245
+ toGeoJSON(precision) {
246
+ const multi = !isFlat(this._latlngs);
247
+ const coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);
248
+ return getFeature(this, {
249
+ type: `${multi ? "Multi" : ""}LineString`,
250
+ coordinates: coords
251
+ });
252
+ }
237
253
  };
238
- //#endregion
239
254
  export { Polyline };
240
255
 
241
256
  //# sourceMappingURL=Polyline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Polyline.js","names":["LineUtil._sqClosestPointOnSegment","LineUtil.polylineCenter","LineUtil.isFlat","LineUtil.clipSegment","LineUtil.simplify","LineUtil.pointToSegmentDistance"],"sources":["../../../../src/layer/vector/Polyline.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n/** @import {PathOptions} from './Path.js' */\n\n/**\n * Options of `Polyline`.\n * @typedef {object} PolylineOptions\n * @property {number} [smoothFactor=0.5] How much to simplify the polyline on each zoom\n * level (Douglas–Peucker epsilon, in pixels). Higher values mean faster rendering but\n * less accuracy; lower values mean more accuracy but slower rendering.\n * @property {boolean} [noClip=false] Disable polyline clipping.\n * @extends PathOptions\n */\n\n/**\n * A class for drawing polyline overlays on a map. Extends `Path`.\n *\n * @example\n * ```js\n * // create a red polyline from an array of LatLng points\n * const latlngs = [\n * \t[45.51, -122.68],\n * \t[37.77, -122.43],\n * \t[34.04, -118.2]\n * ];\n *\n * const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polyline\n * map.fitBounds(polyline.getBounds());\n * ```\n *\n * You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:\n *\n * ```js\n * // create a red polyline from an array of arrays of LatLng points\n * const latlngs = [\n * \t[[45.51, -122.68],\n * \t [37.77, -122.43],\n * \t [34.04, -118.2]],\n * \t[[40.78, -73.91],\n * \t [41.83, -87.62],\n * \t [32.76, -96.72]]\n * ];\n * ```\n */\nexport class Polyline extends Path {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tsmoothFactor: 0.5,\n\t\t\tnoClip: false\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a polyline object given an array of geographical points and\n\t * optionally an options object. You can create a `Polyline` object with\n\t * multiple separate lines (`MultiPolyline`) by passing an array of arrays\n\t * of geographic points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolylineOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._setLatLngs(latlngs);\n\n\t\tthis.callInitHooks(Polyline);\n\t}\n\n\t/**\n\t * Returns an array of the points in the path, or nested arrays of points in case of\n\t * multi-polyline.\n\t * @returns {LatLng[]|LatLng[][]|LatLng[][][]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Replaces all the points in the polyline with the given array of geographical points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._setLatLngs(latlngs);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns `true` if the Polyline has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length;\n\t}\n\n\t/**\n\t * Returns the point closest to `p` on the Polyline, with its `distance` to `p` in\n\t * pixels, or `null` if the polyline is not visible.\n\t * @param {PointExpression} p\n\t * @returns {(Point & {distance: number})|null}\n\t */\n\tclosestLayerPoint(p) {\n\t\tp = Point.from(p);\n\t\tlet minDistance = Infinity,\n\t\tminPoint = null,\n\t\tp1, p2;\n\t\tconst closest = LineUtil._sqClosestPointOnSegment;\n\n\t\tfor (const points of this._parts) {\n\t\t\tfor (let i = 1, len = points.length; i < len; i++) {\n\t\t\t\tp1 = points[i - 1];\n\t\t\t\tp2 = points[i];\n\n\t\t\t\tconst sqDist = closest(p, p1, p2, true);\n\n\t\t\t\tif (sqDist < minDistance) {\n\t\t\t\t\tminDistance = sqDist;\n\t\t\t\t\tminPoint = closest(p, p1, p2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (minPoint) {\n\t\t\tminPoint.distance = Math.sqrt(minDistance);\n\t\t}\n\t\treturn minPoint;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn LineUtil.polylineCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Adds a given point to the polyline. By default, adds to the first ring of\n\t * the polyline in case of a multi-polyline, but can be overridden by passing\n\t * a specific ring as a LatLng array (that you can earlier access with\n\t * [`getLatLngs`](#polyline-getlatlngs)).\n\t * @param {LatLngExpression} latlng\n\t * @param {LatLng[]} [latlngs]\n\t * @returns {this}\n\t */\n\taddLatLng(latlng, latlngs) {\n\t\tlatlngs ??= this._defaultShape();\n\t\tlatlng = new LatLng(latlng);\n\t\tlatlngs.push(latlng);\n\t\tthis._bounds.extend(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tthis._bounds = new LatLngBounds();\n\t\tthis._latlngs = this._convertLatLngs(latlngs);\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];\n\t}\n\n\t// recursively convert latlngs input into actual LatLng instances; calculate bounds along the way\n\t_convertLatLngs(latlngs) {\n\t\tconst result = [],\n\t\tflat = LineUtil.isFlat(latlngs);\n\n\t\tfor (let i = 0, len = latlngs.length; i < len; i++) {\n\t\t\tif (flat) {\n\t\t\t\tresult[i] = new LatLng(latlngs[i]);\n\t\t\t\tthis._bounds.extend(result[i]);\n\t\t\t} else {\n\t\t\t\tresult[i] = this._convertLatLngs(latlngs[i]);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t_project() {\n\t\tconst pxBounds = new Bounds();\n\t\tthis._rings = [];\n\t\tthis._projectLatlngs(this._latlngs, this._rings, pxBounds);\n\n\t\tif (this._bounds.isValid() && pxBounds.isValid()) {\n\t\t\tthis._rawPxBounds = pxBounds;\n\t\t\tthis._updateBounds();\n\t\t}\n\t}\n\n\t_updateBounds() {\n\t\tconst w = this._clickTolerance(),\n\t\tp = new Point(w, w);\n\n\t\tif (!this._rawPxBounds) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._pxBounds = new Bounds([\n\t\t\tthis._rawPxBounds.min.subtract(p),\n\t\t\tthis._rawPxBounds.max.add(p)\n\t\t]);\n\t}\n\n\t// recursively turns latlngs into a set of rings with projected coordinates\n\t_projectLatlngs(latlngs, result, projectedBounds) {\n\t\tconst flat = latlngs[0] instanceof LatLng;\n\n\t\tif (flat) {\n\t\t\tconst ring = latlngs.map(latlng => this._map.latLngToLayerPoint(latlng));\n\t\t\tring.forEach(r => projectedBounds.extend(r));\n\t\t\tresult.push(ring);\n\t\t} else {\n\t\t\tlatlngs.forEach(latlng => this._projectLatlngs(latlng, result, projectedBounds));\n\t\t}\n\t}\n\n\t// clip polyline by renderer bounds so that we have less to render for performance\n\t_clipPoints() {\n\t\tconst bounds = this._renderer._bounds;\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tconst parts = this._parts;\n\t\tlet i, j, k, len, len2, segment, points;\n\n\t\tfor (i = 0, k = 0, len = this._rings.length; i < len; i++) {\n\t\t\tpoints = this._rings[i];\n\n\t\t\tfor (j = 0, len2 = points.length; j < len2 - 1; j++) {\n\t\t\t\tsegment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j, true);\n\n\t\t\t\tif (!segment) { continue; }\n\n\t\t\t\tparts[k] ??= [];\n\t\t\t\tparts[k].push(segment[0]);\n\n\t\t\t\t// if segment goes out of screen, or it's the last one, it's the end of the line part\n\t\t\t\tif ((segment[1] !== points[j + 1]) || (j === len2 - 2)) {\n\t\t\t\t\tparts[k].push(segment[1]);\n\t\t\t\t\tk++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// simplify each clipped part of the polyline for performance\n\t_simplifyPoints() {\n\t\tconst parts = this._parts,\n\t\ttolerance = this.options.smoothFactor;\n\n\t\tfor (let i = 0, len = parts.length; i < len; i++) {\n\t\t\tparts[i] = LineUtil.simplify(parts[i], tolerance);\n\t\t}\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._clipPoints();\n\t\tthis._simplifyPoints();\n\t\tthis._updatePath();\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p, closed) {\n\t\tlet i, j, k, len, len2, part;\n\t\tconst w = this._clickTolerance();\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// hit detection for polylines\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tif (!closed && (j === 0)) { continue; }\n\n\t\t\t\tif (LineUtil.pointToSegmentDistance(p, part[k], part[j]) <= w) {\n\t\t\t\t\treturn true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AAG,GAAG,GAAG,KAAK,MAAM;EACxB,MAAM,IAAI,KAAK,gBAAgB;EAE/B,IAAI,CAAC,KAAK,aAAa,CAAC,KAAK,UAAU,SAAS,CAAC,GAAK,OAAO;EAG7D,KAAK,IAAI,GAAG,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,KAAK;GACnD,OAAO,KAAK,OAAO;GAEnB,KAAK,IAAI,GAAG,OAAO,KAAK,QAAQ,IAAI,OAAO,GAAG,IAAI,MAAM,IAAI,KAAK;IAChE,IAAI,CAAC,UAAW,MAAM,GAAM;IAE5B,IAAIC,uBAAgC,GAAG,KAAK,IAAI,KAAK,EAAE,KAAK,GAC3D,OAAO;GAET;EACD;EACA,OAAO;CACR;AACD"}
1
+ {"version":3,"file":"Polyline.js","names":["LineUtil._sqClosestPointOnSegment","LineUtil.polylineCenter","LineUtil.isFlat","LineUtil.clipSegment","LineUtil.simplify","LineUtil.pointToSegmentDistance"],"sources":["../../../../src/layer/vector/Polyline.js"],"sourcesContent":["import {Path} from './Path.js';\nimport * as Util from '../../core/Util.js';\nimport * as LineUtil from '../../geometry/LineUtil.js';\nimport {LatLng} from '../../geo/LatLng.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\nimport {latLngsToCoords, getFeature} from '../GeoJSONUtil.js';\n/** @import {Feature} from 'geojson' */\n/** @import {LatLngExpression} from '../../geo/LatLng.js' */\n/** @import {PointExpression} from '../../geometry/Point.js' */\n/** @import {PathOptions} from './Path.js' */\n\n/**\n * Options of `Polyline`.\n * @typedef {object} PolylineOptions\n * @property {number} [smoothFactor=0.5] How much to simplify the polyline on each zoom\n * level (Douglas–Peucker epsilon, in pixels). Higher values mean faster rendering but\n * less accuracy; lower values mean more accuracy but slower rendering.\n * @property {boolean} [noClip=false] Disable polyline clipping.\n * @extends PathOptions\n */\n\n/**\n * A class for drawing polyline overlays on a map. Extends `Path`.\n *\n * @example\n * ```js\n * // create a red polyline from an array of LatLng points\n * const latlngs = [\n * \t[45.51, -122.68],\n * \t[37.77, -122.43],\n * \t[34.04, -118.2]\n * ];\n *\n * const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map);\n *\n * // zoom the map to the polyline\n * map.fitBounds(polyline.getBounds());\n * ```\n *\n * You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:\n *\n * ```js\n * // create a red polyline from an array of arrays of LatLng points\n * const latlngs = [\n * \t[[45.51, -122.68],\n * \t [37.77, -122.43],\n * \t [34.04, -118.2]],\n * \t[[40.78, -73.91],\n * \t [41.83, -87.62],\n * \t [32.76, -96.72]]\n * ];\n * ```\n */\nexport class Polyline extends Path {\n\n\tstatic defaultOptions = {\n\t\tsmoothFactor: 0.5,\n\t\tnoClip: false\n\t};\n\n\t/**\n\t * Instantiates a polyline object given an array of geographical points and\n\t * optionally an options object. You can create a `Polyline` object with\n\t * multiple separate lines (`MultiPolyline`) by passing an array of arrays\n\t * of geographic points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @param {PolylineOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._setLatLngs(latlngs);\n\n\t\tthis.callInitHooks(Polyline);\n\t}\n\n\t/**\n\t * Returns an array of the points in the path, or nested arrays of points in case of\n\t * multi-polyline.\n\t * @returns {LatLng[]|LatLng[][]|LatLng[][][]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Replaces all the points in the polyline with the given array of geographical points.\n\t * @param {LatLngExpression[]|LatLngExpression[][]|LatLngExpression[][][]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._setLatLngs(latlngs);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns `true` if the Polyline has no LatLngs.\n\t * @returns {boolean}\n\t */\n\tisEmpty() {\n\t\treturn !this._latlngs.length;\n\t}\n\n\t/**\n\t * Returns the point closest to `p` on the Polyline, with its `distance` to `p` in\n\t * pixels, or `null` if the polyline is not visible.\n\t * @param {PointExpression} p\n\t * @returns {(Point & {distance: number})|null}\n\t */\n\tclosestLayerPoint(p) {\n\t\tp = Point.from(p);\n\t\tlet minDistance = Infinity,\n\t\tminPoint = null,\n\t\tp1, p2;\n\t\tconst closest = LineUtil._sqClosestPointOnSegment;\n\n\t\tfor (const points of this._parts) {\n\t\t\tfor (let i = 1, len = points.length; i < len; i++) {\n\t\t\t\tp1 = points[i - 1];\n\t\t\t\tp2 = points[i];\n\n\t\t\t\tconst sqDist = closest(p, p1, p2, true);\n\n\t\t\t\tif (sqDist < minDistance) {\n\t\t\t\t\tminDistance = sqDist;\n\t\t\t\t\tminPoint = closest(p, p1, p2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (minPoint) {\n\t\t\tminPoint.distance = Math.sqrt(minDistance);\n\t\t}\n\t\treturn minPoint;\n\t}\n\n\t/**\n\t * Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\t// throws error when not yet added to map as this center calculation requires projected coordinates\n\t\tif (!this._map) {\n\t\t\tthrow new Error('Must add layer to map before using getCenter()');\n\t\t}\n\t\treturn LineUtil.polylineCenter(this._defaultShape(), this._map.options.crs);\n\t}\n\n\t/**\n\t * Returns the `LatLngBounds` of the path.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Adds a given point to the polyline. By default, adds to the first ring of\n\t * the polyline in case of a multi-polyline, but can be overridden by passing\n\t * a specific ring as a LatLng array (that you can earlier access with\n\t * [`getLatLngs`](#polyline-getlatlngs)).\n\t * @param {LatLngExpression} latlng\n\t * @param {LatLng[]} [latlngs]\n\t * @returns {this}\n\t */\n\taddLatLng(latlng, latlngs) {\n\t\tlatlngs ??= this._defaultShape();\n\t\tlatlng = new LatLng(latlng);\n\t\tlatlngs.push(latlng);\n\t\tthis._bounds.extend(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t_setLatLngs(latlngs) {\n\t\tthis._bounds = new LatLngBounds();\n\t\tthis._latlngs = this._convertLatLngs(latlngs);\n\t}\n\n\t_defaultShape() {\n\t\treturn LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];\n\t}\n\n\t// recursively convert latlngs input into actual LatLng instances; calculate bounds along the way\n\t_convertLatLngs(latlngs) {\n\t\tconst result = [],\n\t\tflat = LineUtil.isFlat(latlngs);\n\n\t\tfor (let i = 0, len = latlngs.length; i < len; i++) {\n\t\t\tif (flat) {\n\t\t\t\tresult[i] = new LatLng(latlngs[i]);\n\t\t\t\tthis._bounds.extend(result[i]);\n\t\t\t} else {\n\t\t\t\tresult[i] = this._convertLatLngs(latlngs[i]);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t_project() {\n\t\tconst pxBounds = new Bounds();\n\t\tthis._rings = [];\n\t\tthis._projectLatlngs(this._latlngs, this._rings, pxBounds);\n\n\t\tif (this._bounds.isValid() && pxBounds.isValid()) {\n\t\t\tthis._rawPxBounds = pxBounds;\n\t\t\tthis._updateBounds();\n\t\t}\n\t}\n\n\t_updateBounds() {\n\t\tconst w = this._clickTolerance(),\n\t\tp = new Point(w, w);\n\n\t\tif (!this._rawPxBounds) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._pxBounds = new Bounds([\n\t\t\tthis._rawPxBounds.min.subtract(p),\n\t\t\tthis._rawPxBounds.max.add(p)\n\t\t]);\n\t}\n\n\t// recursively turns latlngs into a set of rings with projected coordinates\n\t_projectLatlngs(latlngs, result, projectedBounds) {\n\t\tconst flat = latlngs[0] instanceof LatLng;\n\n\t\tif (flat) {\n\t\t\tconst ring = latlngs.map(latlng => this._map.latLngToLayerPoint(latlng));\n\t\t\tring.forEach(r => projectedBounds.extend(r));\n\t\t\tresult.push(ring);\n\t\t} else {\n\t\t\tlatlngs.forEach(latlng => this._projectLatlngs(latlng, result, projectedBounds));\n\t\t}\n\t}\n\n\t// clip polyline by renderer bounds so that we have less to render for performance\n\t_clipPoints() {\n\t\tconst bounds = this._renderer._bounds;\n\n\t\tthis._parts = [];\n\t\tif (!this._pxBounds || !this._pxBounds.intersects(bounds)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.options.noClip) {\n\t\t\tthis._parts = this._rings;\n\t\t\treturn;\n\t\t}\n\n\t\tconst parts = this._parts;\n\t\tlet i, j, k, len, len2, segment, points;\n\n\t\tfor (i = 0, k = 0, len = this._rings.length; i < len; i++) {\n\t\t\tpoints = this._rings[i];\n\n\t\t\tfor (j = 0, len2 = points.length; j < len2 - 1; j++) {\n\t\t\t\tsegment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j);\n\n\t\t\t\tif (!segment) { continue; }\n\n\t\t\t\tparts[k] ??= [];\n\t\t\t\tparts[k].push(segment[0]);\n\n\t\t\t\t// if segment goes out of screen, or it's the last one, it's the end of the line part\n\t\t\t\tif ((segment[1] !== points[j + 1]) || (j === len2 - 2)) {\n\t\t\t\t\tparts[k].push(segment[1]);\n\t\t\t\t\tk++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// simplify each clipped part of the polyline for performance\n\t_simplifyPoints() {\n\t\tconst parts = this._parts,\n\t\ttolerance = this.options.smoothFactor;\n\n\t\tfor (let i = 0, len = parts.length; i < len; i++) {\n\t\t\tparts[i] = LineUtil.simplify(parts[i], tolerance);\n\t\t}\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._clipPoints();\n\t\tthis._simplifyPoints();\n\t\tthis._updatePath();\n\t}\n\n\t_updatePath() {\n\t\tthis._renderer._updatePoly(this);\n\t}\n\n\t// Needed by the `Canvas` renderer for interactivity\n\t_containsPoint(p, closed) {\n\t\tlet i, j, k, len, len2, part;\n\t\tconst w = this._clickTolerance();\n\n\t\tif (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }\n\n\t\t// hit detection for polylines\n\t\tfor (i = 0, len = this._parts.length; i < len; i++) {\n\t\t\tpart = this._parts[i];\n\n\t\t\tfor (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {\n\t\t\t\tif (!closed && (j === 0)) { continue; }\n\n\t\t\t\tif (LineUtil.pointToSegmentDistance(p, part[k], part[j]) <= w) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`\n\t * Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst multi = !LineUtil.isFlat(this._latlngs);\n\n\t\tconst coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,WAAb,MAAa,iBAAiB,KAAK;CAElC,OAAO,iBAAiB;EACvB,cAAc;EACd,QAAQ;CACT;;;;;;;;;CAUA,YAAY,SAAS,SAAS;EAC7B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,YAAY,OAAO;EAExB,KAAK,cAAc,QAAQ;CAC5B;;;;;;CAOA,aAAa;EACZ,OAAO,KAAK;CACb;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,YAAY,OAAO;EACxB,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,UAAU;EACT,OAAO,CAAC,KAAK,SAAS;CACvB;;;;;;;CAQA,kBAAkB,GAAG;EACpB,IAAI,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