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 +1 @@
1
- {"version":3,"file":"EarthCRS.js","names":[],"sources":["../../../../src/geo/crs/EarthCRS.js"],"sourcesContent":["import {CRS} from './CRS.js';\n/** @import {LatLng} from '../LatLng.js' */\n\n/**\n * Serves as the base for CRS that are global such that they cover the earth.\n * Can only be used as the base for other CRS and cannot be used directly,\n * since it does not have a `code`, `projection` or `transformation`. `distance()` returns\n * meters.\n */\nexport class EarthCRS extends CRS {\n\t/**\n\t * The range around which the longitude axis wraps.\n\t * @type {[number, number]}\n\t */\n\tstatic wrapLng = [-180, 180];\n\n\t/**\n\t * Mean Earth Radius in meters, as recommended for use by\n\t * the International Union of Geodesy and Geophysics,\n\t * see https://rosettacode.org/wiki/Haversine_formula\n\t * @type {number}\n\t */\n\tstatic R = 6371000;\n\n\t/**\n\t * Returns the distance in meters between two geographical points using the\n\t * Haversine approximation.\n\t * @param {LatLng} latlng1\n\t * @param {LatLng} latlng2\n\t * @returns {number}\n\t */\n\tstatic distance(latlng1, latlng2) {\n\t\tconst rad = Math.PI / 180,\n\t\tlat1 = latlng1.lat * rad,\n\t\tlat2 = latlng2.lat * rad,\n\t\tsinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2),\n\t\tsinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2),\n\t\ta = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon,\n\t\tc = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\t\treturn this.R * c;\n\t}\n}\n"],"mappings":";;;;;;;;;AASA,IAAa,WAAb,cAA8B,IAAI;;;;;CAKjC,OAAO,UAAU,CAAC,MAAM,GAAG;;;;;;;CAQ3B,OAAO,IAAI;;;;;;;;CASX,OAAO,SAAS,SAAS,SAAS;EACjC,MAAM,MAAM,KAAK,KAAK,KACtB,OAAO,QAAQ,MAAM,KACrB,OAAO,QAAQ,MAAM,KACrB,UAAU,KAAK,KAAK,QAAQ,MAAM,QAAQ,OAAO,MAAM,CAAC,GACxD,UAAU,KAAK,KAAK,QAAQ,MAAM,QAAQ,OAAO,MAAM,CAAC,GACxD,IAAI,UAAU,UAAU,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,UAAU,SACpE,IAAI,IAAI,KAAK,MAAM,KAAK,KAAK,CAAC,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC;EACjD,OAAO,KAAK,IAAI;CACjB;AACD"}
1
+ {"version":3,"file":"EarthCRS.js","names":[],"sources":["../../../../src/geo/crs/EarthCRS.js"],"sourcesContent":["import {CRS} from './CRS.js';\nimport {haversineDistance} from '../LatLng.js';\n/** @import {LatLng} from '../LatLng.js' */\n\n/**\n * Serves as the base for CRS that are global such that they cover the earth.\n * Can only be used as the base for other CRS and cannot be used directly,\n * since it does not have a `code`, `projection` or `transformation`. `distance()` returns\n * meters.\n */\nexport class EarthCRS extends CRS {\n\t/**\n\t * The range around which the longitude axis wraps.\n\t * @type {[number, number]}\n\t */\n\tstatic wrapLng = [-180, 180];\n\n\t/**\n\t * Mean Earth Radius in meters, as recommended for use by\n\t * the International Union of Geodesy and Geophysics,\n\t * see https://rosettacode.org/wiki/Haversine_formula\n\t * @type {number}\n\t */\n\tstatic R = 6371000;\n\n\t/**\n\t * Returns the distance in meters between two geographical points using the\n\t * Haversine approximation.\n\t * @param {LatLng} latlng1\n\t * @param {LatLng} latlng2\n\t * @returns {number}\n\t */\n\tstatic distance(latlng1, latlng2) {\n\t\treturn haversineDistance(latlng1, latlng2, this.R);\n\t}\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,WAAb,cAA8B,IAAI;;;;;CAKjC,OAAO,UAAU,CAAC,MAAM,GAAG;;;;;;;CAQ3B,OAAO,IAAI;;;;;;;;CASX,OAAO,SAAS,SAAS,SAAS;EACjC,OAAO,kBAAkB,SAAS,SAAS,KAAK,CAAC;CAClD;AACD"}
@@ -1,7 +1,7 @@
1
1
  import { CRS } from "./CRS.js";
2
2
  import { Transformation } from "../../geometry/Transformation.js";
3
- import { LonLat } from "../projection/Projection.LonLat.js";
4
- //#region src/geo/crs/SimpleCRS.js
3
+ import { LonLatProjection } from "../projection/LonLatProjection.js";
4
+ // src/geo/crs/SimpleCRS.js
5
5
  /** @import {LatLng} from '../LatLng.js' */
6
6
  /** @import {Projection} from '../projection/index.js' */
7
7
  /**
@@ -12,9 +12,9 @@ import { LonLat } from "../projection/Projection.LonLat.js";
12
12
  */
13
13
  var SimpleCRS = class extends CRS {
14
14
  /** @type {Projection} */
15
- static projection = LonLat;
15
+ static projection = LonLatProjection;
16
16
  /** @type {Transformation} */
17
- static transformation = new Transformation(1, 0, -1, 0);
17
+ static transformation = /* @__PURE__ */ new Transformation(1, 0, -1, 0);
18
18
  /**
19
19
  * Returns `2^zoom`.
20
20
  * @param {number} zoom
@@ -44,7 +44,6 @@ var SimpleCRS = class extends CRS {
44
44
  /** @type {boolean} */
45
45
  static infinite = true;
46
46
  };
47
- //#endregion
48
47
  export { SimpleCRS };
49
48
 
50
49
  //# sourceMappingURL=SimpleCRS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SimpleCRS.js","names":[],"sources":["../../../../src/geo/crs/SimpleCRS.js"],"sourcesContent":["import {CRS} from './CRS.js';\nimport {LonLat} from '../projection/Projection.LonLat.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {LatLng} from '../LatLng.js' */\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * A simple CRS that maps longitude and latitude into `x` and `y` directly.\n * May be used for maps of flat surfaces (e.g. game maps). Note that the `y`\n * axis should still be inverted (going from bottom to top). `distance()` returns\n * simple euclidean distance.\n */\nexport class SimpleCRS extends CRS {\n\t/** @type {Projection} */\n\tstatic projection = LonLat;\n\t/** @type {Transformation} */\n\tstatic transformation = new Transformation(1, 0, -1, 0);\n\n\t/**\n\t * Returns `2^zoom`.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\tstatic scale(zoom) {\n\t\treturn 2 ** zoom;\n\t}\n\n\t/**\n\t * Inverse of `scale()`.\n\t * @param {number} scale\n\t * @returns {number}\n\t */\n\tstatic zoom(scale) {\n\t\treturn Math.log(scale) / Math.LN2;\n\t}\n\n\t/**\n\t * Returns the euclidean distance between two points.\n\t * @param {LatLng} latlng1\n\t * @param {LatLng} latlng2\n\t * @returns {number}\n\t */\n\tstatic distance(latlng1, latlng2) {\n\t\tconst dx = latlng2.lng - latlng1.lng,\n\t\tdy = latlng2.lat - latlng1.lat;\n\n\t\treturn Math.sqrt(dx * dx + dy * dy);\n\t}\n\n\t/** @type {boolean} */\n\tstatic infinite = true;\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,YAAb,cAA+B,IAAI;;CAElC,OAAO,aAAa;;CAEpB,OAAO,iBAAiB,IAAI,eAAe,GAAG,GAAG,IAAI,CAAC;;;;;;CAOtD,OAAO,MAAM,MAAM;EAClB,OAAO,KAAK;CACb;;;;;;CAOA,OAAO,KAAK,OAAO;EAClB,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK;CAC/B;;;;;;;CAQA,OAAO,SAAS,SAAS,SAAS;EACjC,MAAM,KAAK,QAAQ,MAAM,QAAQ,KACjC,KAAK,QAAQ,MAAM,QAAQ;EAE3B,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE;CACnC;;CAGA,OAAO,WAAW;AACnB"}
1
+ {"version":3,"file":"SimpleCRS.js","names":[],"sources":["../../../../src/geo/crs/SimpleCRS.js"],"sourcesContent":["import {CRS} from './CRS.js';\nimport {LonLatProjection} from '../projection/LonLatProjection.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {LatLng} from '../LatLng.js' */\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * A simple CRS that maps longitude and latitude into `x` and `y` directly.\n * May be used for maps of flat surfaces (e.g. game maps). Note that the `y`\n * axis should still be inverted (going from bottom to top). `distance()` returns\n * simple euclidean distance.\n */\nexport class SimpleCRS extends CRS {\n\t/** @type {Projection} */\n\tstatic projection = LonLatProjection;\n\t/** @type {Transformation} */\n\tstatic transformation = /* @__PURE__ */ new Transformation(1, 0, -1, 0);\n\n\t/**\n\t * Returns `2^zoom`.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\tstatic scale(zoom) {\n\t\treturn 2 ** zoom;\n\t}\n\n\t/**\n\t * Inverse of `scale()`.\n\t * @param {number} scale\n\t * @returns {number}\n\t */\n\tstatic zoom(scale) {\n\t\treturn Math.log(scale) / Math.LN2;\n\t}\n\n\t/**\n\t * Returns the euclidean distance between two points.\n\t * @param {LatLng} latlng1\n\t * @param {LatLng} latlng2\n\t * @returns {number}\n\t */\n\tstatic distance(latlng1, latlng2) {\n\t\tconst dx = latlng2.lng - latlng1.lng,\n\t\tdy = latlng2.lat - latlng1.lat;\n\n\t\treturn Math.sqrt(dx * dx + dy * dy);\n\t}\n\n\t/** @type {boolean} */\n\tstatic infinite = true;\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAa,YAAb,cAA+B,IAAI;;CAElC,OAAO,aAAa;;CAEpB,OAAO,iCAAiC,IAAI,eAAe,GAAG,GAAG,IAAI,CAAC;;;;;;CAOtE,OAAO,MAAM,MAAM;EAClB,OAAO,KAAK;CACb;;;;;;CAOA,OAAO,KAAK,OAAO;EAClB,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK;CAC/B;;;;;;;CAQA,OAAO,SAAS,SAAS,SAAS;EACjC,MAAM,KAAK,QAAQ,MAAM,QAAQ,KACjC,KAAK,QAAQ,MAAM,QAAQ;EAE3B,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE;CACnC;;CAGA,OAAO,WAAW;AACnB"}
@@ -1,7 +1,7 @@
1
1
  import { Point } from "../../geometry/Point.js";
2
2
  import { Bounds } from "../../geometry/Bounds.js";
3
3
  import { LatLng } from "../LatLng.js";
4
- //#region src/geo/projection/Projection.LonLat.js
4
+ // src/geo/projection/LonLatProjection.js
5
5
  /** @import {Projection} from './index.js' */
6
6
  /**
7
7
  * Equirectangular, or Plate Carree projection — the most simple projection,
@@ -10,7 +10,7 @@ import { LatLng } from "../LatLng.js";
10
10
  * `EPSG4326` and `SimpleCRS` CRS.
11
11
  * @type {Projection}
12
12
  */
13
- const LonLat = {
13
+ const LonLatProjection = {
14
14
  project(latlng) {
15
15
  latlng = LatLng.from(latlng);
16
16
  return new Point(latlng.lng, latlng.lat);
@@ -19,9 +19,8 @@ const LonLat = {
19
19
  point = Point.from(point);
20
20
  return new LatLng(point.y, point.x);
21
21
  },
22
- bounds: new Bounds([-180, -90], [180, 90])
22
+ bounds: /* @__PURE__ */ new Bounds([-180, -90], [180, 90])
23
23
  };
24
- //#endregion
25
- export { LonLat };
24
+ export { LonLatProjection };
26
25
 
27
- //# sourceMappingURL=Projection.LonLat.js.map
26
+ //# sourceMappingURL=LonLatProjection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LonLatProjection.js","names":[],"sources":["../../../../src/geo/projection/LonLatProjection.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\n/**\n * Equirectangular, or Plate Carree projection — the most simple projection,\n * mostly used by GIS enthusiasts. Directly maps `x` as longitude, and `y` as\n * latitude. Also suitable for flat worlds, e.g. game maps. Used by the\n * `EPSG4326` and `SimpleCRS` CRS.\n * @type {Projection}\n */\nexport const LonLatProjection = {\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\treturn new Point(latlng.lng, latlng.lat);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\treturn new LatLng(point.y, point.x);\n\t},\n\n\tbounds: /* @__PURE__ */ new Bounds([-180, -90], [180, 90])\n};\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,mBAAmB;CAC/B,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,OAAO,IAAI,MAAM,OAAO,KAAK,OAAO,GAAG;CACxC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,CAAC;CACnC;CAEA,wBAAwB,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;AAC1D"}
@@ -6,10 +6,10 @@ import { LatLng } from "../LatLng.js";
6
6
  * Earth is an ellipsoid. Used by the EPSG:3395 CRS.
7
7
  * @type {Projection & {R: number, R_MINOR: number}}
8
8
  */
9
- const Mercator = {
9
+ const MercatorProjection = {
10
10
  R: 6378137,
11
11
  R_MINOR: 6356752.314245179,
12
- bounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
12
+ bounds: /* @__PURE__ */ new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
13
13
  project(latlng) {
14
14
  latlng = LatLng.from(latlng);
15
15
  const d = Math.PI / 180, r = this.R, tmp = this.R_MINOR / r, e = Math.sqrt(1 - tmp * tmp);
@@ -32,7 +32,6 @@ const Mercator = {
32
32
  return new LatLng(phi * d, point.x * d / r);
33
33
  }
34
34
  };
35
- //#endregion
36
- export { Mercator };
35
+ export { MercatorProjection };
37
36
 
38
- //# sourceMappingURL=Projection.Mercator.js.map
37
+ //# sourceMappingURL=MercatorProjection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MercatorProjection.js","names":[],"sources":["../../../../src/geo/projection/MercatorProjection.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that\n * Earth is an ellipsoid. Used by the EPSG:3395 CRS.\n * @type {Projection & {R: number, R_MINOR: number}}\n */\nexport const MercatorProjection = {\n\tR: earthRadius,\n\tR_MINOR: 6356752.314245179,\n\n\tbounds: /* @__PURE__ */ new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp);\n\t\tlet y = latlng.lat * d;\n\t\tconst con = e * Math.sin(y);\n\n\t\tconst ts = Math.tan(Math.PI / 4 - y / 2) / ((1 - con) / (1 + con)) ** (e / 2);\n\t\ty = -r * Math.log(Math.max(ts, 1E-10));\n\n\t\treturn new Point(latlng.lng * d * r, y);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI,\n\t\tr = this.R,\n\t\ttmp = this.R_MINOR / r,\n\t\te = Math.sqrt(1 - tmp * tmp),\n\t\tts = Math.exp(-point.y / r);\n\t\tlet phi = Math.PI / 2 - 2 * Math.atan(ts);\n\n\t\tfor (let i = 0, dphi = 0.1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {\n\t\t\tcon = e * Math.sin(phi);\n\t\t\tcon = ((1 - con) / (1 + con)) ** (e / 2);\n\t\t\tdphi = Math.PI / 2 - 2 * Math.atan(ts * con) - phi;\n\t\t\tphi += dphi;\n\t\t}\n\n\t\treturn new LatLng(phi * d, point.x * d / r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,7 +1,7 @@
1
1
  import { Point } from "../../geometry/Point.js";
2
2
  import { Bounds } from "../../geometry/Bounds.js";
3
3
  import { LatLng } from "../LatLng.js";
4
- //#region src/geo/projection/Projection.SphericalMercator.js
4
+ // src/geo/projection/SphericalMercatorProjection.js
5
5
  /** @import {Projection} from './index.js' */
6
6
  const earthRadius = 6378137;
7
7
  /**
@@ -10,7 +10,7 @@ const earthRadius = 6378137;
10
10
  * a sphere. Used by the `EPSG:3857` CRS.
11
11
  * @type {Projection & {R: number, MAX_LATITUDE: number}}
12
12
  */
13
- const SphericalMercator = {
13
+ const SphericalMercatorProjection = {
14
14
  R: earthRadius,
15
15
  MAX_LATITUDE: 85.0511287798,
16
16
  project(latlng) {
@@ -23,12 +23,11 @@ const SphericalMercator = {
23
23
  const d = 180 / Math.PI;
24
24
  return new LatLng((2 * Math.atan(Math.exp(point.y / this.R)) - Math.PI / 2) * d, point.x * d / this.R);
25
25
  },
26
- bounds: (() => {
26
+ bounds: /* @__PURE__ */ (() => {
27
27
  const d = earthRadius * Math.PI;
28
28
  return new Bounds([-d, -d], [d, d]);
29
29
  })()
30
30
  };
31
- //#endregion
32
- export { SphericalMercator };
31
+ export { SphericalMercatorProjection };
33
32
 
34
- //# sourceMappingURL=Projection.SphericalMercator.js.map
33
+ //# sourceMappingURL=SphericalMercatorProjection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SphericalMercatorProjection.js","names":[],"sources":["../../../../src/geo/projection/SphericalMercatorProjection.js"],"sourcesContent":["import {LatLng} from '../LatLng.js';\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {Point} from '../../geometry/Point.js';\n\n/** @import {Projection} from './index.js' */\n\nconst earthRadius = 6378137;\n\n/**\n * Spherical Mercator projection — the most common projection for online maps,\n * used by almost all free and commercial tile providers. Assumes that Earth is\n * a sphere. Used by the `EPSG:3857` CRS.\n * @type {Projection & {R: number, MAX_LATITUDE: number}}\n */\nexport const SphericalMercatorProjection = {\n\n\tR: earthRadius,\n\tMAX_LATITUDE: 85.0511287798,\n\n\tproject(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst d = Math.PI / 180,\n\t\tmax = this.MAX_LATITUDE,\n\t\tlat = Math.max(Math.min(max, latlng.lat), -max),\n\t\tsin = Math.sin(lat * d);\n\n\t\treturn new Point(\n\t\t\tthis.R * latlng.lng * d,\n\t\t\tthis.R * Math.log((1 + sin) / (1 - sin)) / 2);\n\t},\n\n\tunproject(point) {\n\t\tpoint = Point.from(point);\n\t\tconst d = 180 / Math.PI;\n\n\t\treturn new LatLng(\n\t\t\t(2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d,\n\t\t\tpoint.x * d / this.R);\n\t},\n\n\tbounds: /* @__PURE__ */ (() => {\n\t\tconst d = earthRadius * Math.PI;\n\t\treturn new Bounds([-d, -d], [d, d]);\n\t})()\n};\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;AAQpB,MAAa,8BAA8B;CAE1C,GAAG;CACH,cAAc;CAEd,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,MAAM,KAAK,cACX,MAAM,KAAK,IAAI,KAAK,IAAI,KAAK,OAAO,GAAG,GAAG,CAAC,GAAG,GAC9C,MAAM,KAAK,IAAI,MAAM,CAAC;EAEtB,OAAO,IAAI,MACV,KAAK,IAAI,OAAO,MAAM,GACtB,KAAK,IAAI,KAAK,KAAK,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC;CAC9C;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK;EAErB,OAAO,IAAI,QACT,IAAI,KAAK,KAAK,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,IAAK,KAAK,KAAK,KAAM,GAC9D,MAAM,IAAI,IAAI,KAAK,CAAC;CACtB;CAEA,QAAwB,uBAAO;EAC9B,MAAM,IAAI,cAAc,KAAK;EAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACnC,EAAA,CAAG;AACJ"}
@@ -1,5 +1,5 @@
1
1
  import { Point } from "./Point.js";
2
- //#region src/geometry/Bounds.js
2
+ // src/geometry/Bounds.js
3
3
  /** @import {PointExpression} from './Point.js' */
4
4
  /**
5
5
  * A rectangular area in pixel coordinates: a `Bounds`, or an array of points (usually
@@ -76,14 +76,12 @@ var Bounds = class Bounds {
76
76
  extend(obj) {
77
77
  let min2, max2;
78
78
  if (!obj) return this;
79
- if (obj instanceof Point || typeof obj[0] === "number" || "x" in obj) min2 = max2 = Point.from(obj);
79
+ if (isPointExpression(obj)) min2 = max2 = Point.from(obj);
80
80
  else {
81
- obj = Bounds.from(obj);
82
- min2 = obj.min;
83
- max2 = obj.max;
84
- if (!min2 || !max2) return this;
81
+ ({min: min2, max: max2} = Bounds.from(obj));
82
+ if (!min2) return this;
85
83
  }
86
- if (!this.min && !this.max) {
84
+ if (!this.min) {
87
85
  this.min = new Point(min2);
88
86
  this.max = new Point(max2);
89
87
  } else {
@@ -144,12 +142,8 @@ var Bounds = class Bounds {
144
142
  */
145
143
  contains(obj) {
146
144
  let min, max;
147
- if (typeof obj[0] === "number" || obj instanceof Point) obj = Point.from(obj);
148
- else obj = Bounds.from(obj);
149
- if (obj instanceof Bounds) {
150
- min = obj.min;
151
- max = obj.max;
152
- } else min = max = obj;
145
+ if (isPointExpression(obj)) min = max = Point.from(obj);
146
+ else ({min, max} = Bounds.from(obj));
153
147
  return min.x >= this.min.x && max.x <= this.max.x && min.y >= this.min.y && max.y <= this.max.y;
154
148
  }
155
149
  /**
@@ -203,7 +197,9 @@ var Bounds = class Bounds {
203
197
  return this.min.equals(bounds.getTopLeft()) && this.max.equals(bounds.getBottomRight());
204
198
  }
205
199
  };
206
- //#endregion
200
+ function isPointExpression(obj) {
201
+ return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] === "number" : "x" in obj);
202
+ }
207
203
  export { Bounds };
208
204
 
209
205
  //# sourceMappingURL=Bounds.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Bounds.js","names":[],"sources":["../../../src/geometry/Bounds.js"],"sourcesContent":["import {Point} from './Point.js';\n/** @import {PointExpression} from './Point.js' */\n\n/**\n * A rectangular area in pixel coordinates: a `Bounds`, or an array of points (usually\n * two diagonally opposite corners), e.g. `[[10, 10], [40, 60]]`. Accepted by all\n * Maplair methods which accept `Bounds` objects (unless noted otherwise).\n * @typedef {Bounds|PointExpression[]} BoundsExpression\n */\n\n/**\n * Represents a rectangular area in pixel coordinates.\n *\n * @example\n * ```js\n * const p1 = new Point(10, 10),\n * p2 = new Point(40, 60),\n * bounds = new Bounds(p1, p2);\n * ```\n *\n * All Maplair methods that accept `Bounds` objects also accept them in a simple Array\n * form (unless noted otherwise), so the bounds example above can be passed like this:\n *\n * ```js\n * otherBounds.intersects([[10, 10], [40, 60]]);\n * ```\n *\n * Note that `Bounds` does not inherit from Maplair's `Class` object,\n * which means new classes can't inherit from it, and new methods\n * can't be added to it with the `include` function.\n */\nexport class Bounds {\n\t/**\n\t * Creates a Bounds object from two corners coordinate pairs. Alternatively, creates a\n\t * Bounds object from the given array of points, or a copy of the given Bounds object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds to copy.\n\t * @param {PointExpression} [b] The opposite corner.\n\t */\n\tconstructor(a, b) {\n\t\tif (!a) { return; }\n\n\t\tif (a instanceof Bounds) {\n\t\t\tif (a.isValid()) {\n\t\t\t\t/**\n\t\t\t\t * The top left corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.min = new Point(a.min);\n\t\t\t\t/**\n\t\t\t\t * The bottom right corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.max = new Point(a.max);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst points = b ? [a, b] : a;\n\t\tfor (const point of points) {\n\t\t\tthis.extend(point);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `Bounds` object as it is, or else a new `Bounds` object created\n\t * from the given arguments (the same as of the constructor) — unlike the\n\t * constructor, which always creates a new object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds.\n\t * @param {PointExpression} [b] The opposite corner.\n\t * @returns {Bounds}\n\t */\n\tstatic from(a, b) {\n\t\treturn a instanceof Bounds ? a : new Bounds(a, b);\n\t}\n\n\t/**\n\t * Extends the bounds to contain the given point or bounds.\n\t * @param {PointExpression|BoundsExpression} obj\n\t * @returns {this}\n\t */\n\textend(obj) {\n\t\tlet min2, max2;\n\t\tif (!obj) { return this; }\n\n\t\tif (obj instanceof Point || typeof obj[0] === 'number' || 'x' in obj) {\n\t\t\tmin2 = max2 = Point.from(obj);\n\t\t} else {\n\t\t\tobj = Bounds.from(obj);\n\t\t\tmin2 = obj.min;\n\t\t\tmax2 = obj.max;\n\n\t\t\tif (!min2 || !max2) { return this; }\n\t\t}\n\n\t\tif (!this.min && !this.max) {\n\t\t\tthis.min = new Point(min2);\n\t\t\tthis.max = new Point(max2);\n\t\t} else {\n\t\t\tthis.min.x = Math.min(min2.x, this.min.x);\n\t\t\tthis.max.x = Math.max(max2.x, this.max.x);\n\t\t\tthis.min.y = Math.min(min2.y, this.min.y);\n\t\t\tthis.max.y = Math.max(max2.y, this.max.y);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the center point of the bounds.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\n\tgetCenter(round) {\n\t\treturn new Point(\n\t\t\t(this.min.x + this.max.x) / 2,\n\t\t\t(this.min.y + this.max.y) / 2, round);\n\t}\n\n\t/**\n\t * Returns the bottom-left point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetBottomLeft() {\n\t\treturn new Point(this.min.x, this.max.y);\n\t}\n\n\t/**\n\t * Returns the top-right point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetTopRight() { // -> Point\n\t\treturn new Point(this.max.x, this.min.y);\n\t}\n\n\t/**\n\t * Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).\n\t * @returns {Point}\n\t */\n\tgetTopLeft() {\n\t\treturn this.min; // left, top\n\t}\n\n\t/**\n\t * Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).\n\t * @returns {Point}\n\t */\n\tgetBottomRight() {\n\t\treturn this.max; // right, bottom\n\t}\n\n\t/**\n\t * Returns the size of the given bounds.\n\t * @returns {Point}\n\t */\n\tgetSize() {\n\t\treturn this.max.subtract(this.min);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {BoundsExpression|PointExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) {\n\t\tlet min, max;\n\n\t\tif (typeof obj[0] === 'number' || obj instanceof Point) {\n\t\t\tobj = Point.from(obj);\n\t\t} else {\n\t\t\tobj = Bounds.from(obj);\n\t\t}\n\n\t\tif (obj instanceof Bounds) {\n\t\t\tmin = obj.min;\n\t\t\tmax = obj.max;\n\t\t} else {\n\t\t\tmin = max = obj;\n\t\t}\n\n\t\treturn (min.x >= this.min.x) &&\n\t\t (max.x <= this.max.x) &&\n\t\t (min.y >= this.min.y) &&\n\t\t (max.y <= this.max.y);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle intersects the given bounds. Two bounds\n\t * intersect if they have at least one point in common.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txIntersects = (max2.x >= min.x) && (min2.x <= max.x),\n\t\tyIntersects = (max2.y >= min.y) && (min2.y <= max.y);\n\n\t\treturn xIntersects && yIntersects;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds\n\t * overlap if their intersection is an area.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txOverlaps = (max2.x > min.x) && (min2.x < max.x),\n\t\tyOverlaps = (max2.y > min.y) && (min2.y < max.y);\n\n\t\treturn xOverlaps && yOverlaps;\n\t}\n\n\t/**\n\t * Returns `true` if the bounds are properly initialized.\n\t * @returns {boolean}\n\t */\n\tisValid() {\n\t\treturn !!(this.min && this.max);\n\t}\n\n\n\t/**\n\t * Returns bounds created by extending or retracting the current bounds by a given\n\t * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in\n\t * each direction. Negative values will retract the bounds.\n\t * @param {number} bufferRatio\n\t * @returns {Bounds}\n\t */\n\tpad(bufferRatio) {\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\theightBuffer = Math.abs(min.x - max.x) * bufferRatio,\n\t\twidthBuffer = Math.abs(min.y - max.y) * bufferRatio;\n\n\n\t\treturn new Bounds(\n\t\t\tnew Point(min.x - heightBuffer, min.y - widthBuffer),\n\t\t\tnew Point(max.x + heightBuffer, max.y + widthBuffer));\n\t}\n\n\n\t/**\n\t * Returns `true` if the rectangle is equivalent to the given bounds.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tequals(bounds) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = Bounds.from(bounds);\n\n\t\treturn this.min.equals(bounds.getTopLeft()) &&\n\t\t\tthis.max.equals(bounds.getBottomRight());\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,SAAb,MAAa,OAAO;;;;;;;;CAQnB,YAAY,GAAG,GAAG;EACjB,IAAI,CAAC,GAAK;EAEV,IAAI,aAAa,QAAQ;GACxB,IAA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;;CAUA,IAAI,aAAa;EAChB,MAAM,MAAM,KAAK,KACjB,MAAM,KAAK,KACX,eAAe,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,aACzC,cAAc,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI;EAGxC,OAAO,IAAI,OACV,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,GACnD,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,CAAC;CACtD;;;;;;CAQA,OAAO,QAAQ;EACd,IAAI,CAAC,QAAU,OAAO;EAEtB,SAAS,OAAO,KAAK,MAAM;EAE3B,OAAO,KAAK,IAAI,OAAO,OAAO,WAAW,CAAC,KACzC,KAAK,IAAI,OAAO,OAAO,eAAe,CAAC;CACzC;AACD"}
1
+ {"version":3,"file":"Bounds.js","names":[],"sources":["../../../src/geometry/Bounds.js"],"sourcesContent":["import {Point} from './Point.js';\n/** @import {PointExpression} from './Point.js' */\n\n/**\n * A rectangular area in pixel coordinates: a `Bounds`, or an array of points (usually\n * two diagonally opposite corners), e.g. `[[10, 10], [40, 60]]`. Accepted by all\n * Maplair methods which accept `Bounds` objects (unless noted otherwise).\n * @typedef {Bounds|PointExpression[]} BoundsExpression\n */\n\n/**\n * Represents a rectangular area in pixel coordinates.\n *\n * @example\n * ```js\n * const p1 = new Point(10, 10),\n * p2 = new Point(40, 60),\n * bounds = new Bounds(p1, p2);\n * ```\n *\n * All Maplair methods that accept `Bounds` objects also accept them in a simple Array\n * form (unless noted otherwise), so the bounds example above can be passed like this:\n *\n * ```js\n * otherBounds.intersects([[10, 10], [40, 60]]);\n * ```\n *\n * Note that `Bounds` does not inherit from Maplair's `Class` object,\n * which means new classes can't inherit from it, and new methods\n * can't be added to it with the `include` function.\n */\nexport class Bounds {\n\t/**\n\t * Creates a Bounds object from two corners coordinate pairs. Alternatively, creates a\n\t * Bounds object from the given array of points, or a copy of the given Bounds object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds to copy.\n\t * @param {PointExpression} [b] The opposite corner.\n\t */\n\tconstructor(a, b) {\n\t\tif (!a) { return; }\n\n\t\tif (a instanceof Bounds) {\n\t\t\tif (a.isValid()) {\n\t\t\t\t/**\n\t\t\t\t * The top left corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.min = new Point(a.min);\n\t\t\t\t/**\n\t\t\t\t * The bottom right corner of the rectangle.\n\t\t\t\t * @type {Point}\n\t\t\t\t */\n\t\t\t\tthis.max = new Point(a.max);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst points = b ? [a, b] : a;\n\t\tfor (const point of points) {\n\t\t\tthis.extend(point);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `Bounds` object as it is, or else a new `Bounds` object created\n\t * from the given arguments (the same as of the constructor) — unlike the\n\t * constructor, which always creates a new object.\n\t * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the\n\t * bounds.\n\t * @param {PointExpression} [b] The opposite corner.\n\t * @returns {Bounds}\n\t */\n\tstatic from(a, b) {\n\t\treturn a instanceof Bounds ? a : new Bounds(a, b);\n\t}\n\n\t/**\n\t * Extends the bounds to contain the given point or bounds.\n\t * @param {PointExpression|BoundsExpression} obj\n\t * @returns {this}\n\t */\n\textend(obj) {\n\t\tlet min2, max2;\n\t\tif (!obj) { return this; }\n\n\t\tif (isPointExpression(obj)) {\n\t\t\tmin2 = max2 = Point.from(obj);\n\t\t} else {\n\t\t\t({min: min2, max: max2} = Bounds.from(obj));\n\t\t\tif (!min2) { return this; }\n\t\t}\n\n\t\tif (!this.min) {\n\t\t\tthis.min = new Point(min2);\n\t\t\tthis.max = new Point(max2);\n\t\t} else {\n\t\t\tthis.min.x = Math.min(min2.x, this.min.x);\n\t\t\tthis.max.x = Math.max(max2.x, this.max.x);\n\t\t\tthis.min.y = Math.min(min2.y, this.min.y);\n\t\t\tthis.max.y = Math.max(max2.y, this.max.y);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the center point of the bounds.\n\t * @param {boolean} [round]\n\t * @returns {Point}\n\t */\n\tgetCenter(round) {\n\t\treturn new Point(\n\t\t\t(this.min.x + this.max.x) / 2,\n\t\t\t(this.min.y + this.max.y) / 2, round);\n\t}\n\n\t/**\n\t * Returns the bottom-left point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetBottomLeft() {\n\t\treturn new Point(this.min.x, this.max.y);\n\t}\n\n\t/**\n\t * Returns the top-right point of the bounds.\n\t * @returns {Point}\n\t */\n\tgetTopRight() { // -> Point\n\t\treturn new Point(this.max.x, this.min.y);\n\t}\n\n\t/**\n\t * Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).\n\t * @returns {Point}\n\t */\n\tgetTopLeft() {\n\t\treturn this.min; // left, top\n\t}\n\n\t/**\n\t * Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).\n\t * @returns {Point}\n\t */\n\tgetBottomRight() {\n\t\treturn this.max; // right, bottom\n\t}\n\n\t/**\n\t * Returns the size of the given bounds.\n\t * @returns {Point}\n\t */\n\tgetSize() {\n\t\treturn this.max.subtract(this.min);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {BoundsExpression|PointExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) {\n\t\tlet min, max;\n\n\t\tif (isPointExpression(obj)) {\n\t\t\tmin = max = Point.from(obj);\n\t\t} else {\n\t\t\t({min, max} = Bounds.from(obj));\n\t\t}\n\n\t\treturn (min.x >= this.min.x) &&\n\t\t (max.x <= this.max.x) &&\n\t\t (min.y >= this.min.y) &&\n\t\t (max.y <= this.max.y);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle intersects the given bounds. Two bounds\n\t * intersect if they have at least one point in common.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txIntersects = (max2.x >= min.x) && (min2.x <= max.x),\n\t\tyIntersects = (max2.y >= min.y) && (min2.y <= max.y);\n\n\t\treturn xIntersects && yIntersects;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds\n\t * overlap if their intersection is an area.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) { // (Bounds) -> Boolean\n\t\tbounds = Bounds.from(bounds);\n\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\tmin2 = bounds.min,\n\t\tmax2 = bounds.max,\n\t\txOverlaps = (max2.x > min.x) && (min2.x < max.x),\n\t\tyOverlaps = (max2.y > min.y) && (min2.y < max.y);\n\n\t\treturn xOverlaps && yOverlaps;\n\t}\n\n\t/**\n\t * Returns `true` if the bounds are properly initialized.\n\t * @returns {boolean}\n\t */\n\tisValid() {\n\t\treturn !!(this.min && this.max);\n\t}\n\n\n\t/**\n\t * Returns bounds created by extending or retracting the current bounds by a given\n\t * ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in\n\t * each direction. Negative values will retract the bounds.\n\t * @param {number} bufferRatio\n\t * @returns {Bounds}\n\t */\n\tpad(bufferRatio) {\n\t\tconst min = this.min,\n\t\tmax = this.max,\n\t\theightBuffer = Math.abs(min.x - max.x) * bufferRatio,\n\t\twidthBuffer = Math.abs(min.y - max.y) * bufferRatio;\n\n\n\t\treturn new Bounds(\n\t\t\tnew Point(min.x - heightBuffer, min.y - widthBuffer),\n\t\t\tnew Point(max.x + heightBuffer, max.y + widthBuffer));\n\t}\n\n\n\t/**\n\t * Returns `true` if the rectangle is equivalent to the given bounds.\n\t * @param {BoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tequals(bounds) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = Bounds.from(bounds);\n\n\t\treturn this.min.equals(bounds.getTopLeft()) &&\n\t\t\tthis.max.equals(bounds.getBottomRight());\n\t}\n}\n\n// Whether `obj` is a point (or an array or object literal of one) rather than bounds\nfunction isPointExpression(obj) {\n\treturn obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] === 'number' : 'x' in obj);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAa,SAAb,MAAa,OAAO;;;;;;;;CAQnB,YAAY,GAAG,GAAG;EACjB,IAAI,CAAC,GAAK;EAEV,IAAI,aAAa,QAAQ;GACxB,IAAI,EAAE,QAAQ,GAAG;;;;;IAKhB,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;;;;;IAK1B,KAAK,MAAM,IAAI,MAAM,EAAE,GAAG;GAC3B;GACA;EACD;EAEA,MAAM,SAAS,IAAI,CAAC,GAAG,CAAC,IAAI;EAC5B,KAAK,MAAM,SAAS,QACnB,KAAK,OAAO,KAAK;CAEnB;;;;;;;;;;CAWA,OAAO,KAAK,GAAG,GAAG;EACjB,OAAO,aAAa,SAAS,IAAI,IAAI,OAAO,GAAG,CAAC;CACjD;;;;;;CAOA,OAAO,KAAK;EACX,IAAI,MAAM;EACV,IAAI,CAAC,KAAO,OAAO;EAEnB,IAAI,kBAAkB,GAAG,GACxB,OAAO,OAAO,MAAM,KAAK,GAAG;OACtB;GACN,CAAC,CAAC,KAAK,MAAM,KAAK,QAAQ,OAAO,KAAK,GAAG;GACzC,IAAI,CAAC,MAAQ,OAAO;EACrB;EAEA,IAAI,CAAC,KAAK,KAAK;GACd,KAAK,MAAM,IAAI,MAAM,IAAI;GACzB,KAAK,MAAM,IAAI,MAAM,IAAI;EAC1B,OAAO;GACN,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC;GACxC,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC;GACxC,KAAK,IAAI,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,IAAI,CAAC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ACd,YAAa,KAAK,IAAI,IAAI,KAAO,KAAK,IAAI,IAAI,GAC9C,YAAa,KAAK,IAAI,IAAI,KAAO,KAAK,IAAI,IAAI;EAE9C,OAAO,aAAa;CACrB;;;;;CAMA,UAAU;EACT,OAAO,CAAC,EAAE,KAAK,OAAO,KAAK;CAC5B;;;;;;;;CAUA,IAAI,aAAa;EAChB,MAAM,MAAM,KAAK,KACjB,MAAM,KAAK,KACX,eAAe,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,aACzC,cAAc,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI;EAGxC,OAAO,IAAI,OACV,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,GACnD,IAAI,MAAM,IAAI,IAAI,cAAc,IAAI,IAAI,WAAW,CAAC;CACtD;;;;;;CAQA,OAAO,QAAQ;EACd,IAAI,CAAC,QAAU,OAAO;EAEtB,SAAS,OAAO,KAAK,MAAM;EAE3B,OAAO,KAAK,IAAI,OAAO,OAAO,WAAW,CAAC,KACzC,KAAK,IAAI,OAAO,OAAO,eAAe,CAAC;CACzC;AACD;AAGA,SAAS,kBAAkB,KAAK;CAC/B,OAAO,eAAe,UAAU,MAAM,QAAQ,GAAG,IAAI,OAAO,IAAI,OAAO,WAAW,OAAO;AAC1F"}
@@ -1,12 +1,11 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { Point } from "./Point.js";
3
- import { LatLngBounds } from "../geo/LatLngBounds.js";
4
3
  import { LatLng } from "../geo/LatLng.js";
5
- import { centroid } from "./PolyUtil.js";
6
- //#region src/geometry/LineUtil.js
4
+ // src/geometry/LineUtil.js
7
5
  var LineUtil_exports = /* @__PURE__ */ __exportAll({
8
6
  _getBitCode: () => _getBitCode,
9
7
  _getEdgeIntersection: () => _getEdgeIntersection,
8
+ _projectRing: () => _projectRing,
10
9
  _sqClosestPointOnSegment: () => _sqClosestPointOnSegment,
11
10
  clipSegment: () => clipSegment,
12
11
  closestPointOnSegment: () => closestPointOnSegment,
@@ -107,13 +106,20 @@ let _lastCode;
107
106
  * @returns {[Point, Point]|false}
108
107
  */
109
108
  function clipSegment(a, b, bounds, useLastCode, round) {
109
+ const a0 = a, b0 = b;
110
110
  let codeA = useLastCode ? _lastCode : _getBitCode(a, bounds), codeB = _getBitCode(b, bounds), codeOut, p, newCode;
111
111
  _lastCode = codeB;
112
112
  while (true) {
113
- if (!(codeA | codeB)) return [a, b];
113
+ if (!(codeA | codeB)) {
114
+ if (round) {
115
+ if (a !== a0) a = a.round();
116
+ if (b !== b0) b = b.round();
117
+ }
118
+ return [a, b];
119
+ }
114
120
  if (codeA & codeB) return false;
115
121
  codeOut = codeA || codeB;
116
- p = _getEdgeIntersection(a, b, codeOut, bounds, round);
122
+ p = _getEdgeIntersection(a, b, codeOut, bounds);
117
123
  newCode = _getBitCode(p, bounds);
118
124
  if (codeOut === codeA) {
119
125
  a = p;
@@ -187,38 +193,37 @@ function isFlat(latlngs) {
187
193
  * @returns {LatLng}
188
194
  */
189
195
  function polylineCenter(latlngs, crs) {
190
- let i, halfDist, segDist, dist, p1, p2, ratio, center;
191
- if (!latlngs || latlngs.length === 0) throw new Error("latlngs not passed");
192
- if (!isFlat(latlngs)) {
193
- console.warn("latlngs are not flat! Only the first ring will be used");
194
- latlngs = latlngs[0];
195
- }
196
- let centroidLatLng = new LatLng([0, 0]);
197
- const bounds = new LatLngBounds(latlngs);
198
- if (bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest()) < 1700) centroidLatLng = centroid(latlngs);
199
- const len = latlngs.length;
200
- const points = [];
201
- for (i = 0; i < len; i++) {
202
- const latlng = new LatLng(latlngs[i]);
203
- points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
204
- }
205
- for (i = 0, halfDist = 0; i < len - 1; i++) halfDist += points[i].distanceTo(points[i + 1]) / 2;
206
- if (halfDist === 0) center = points[0];
207
- else for (i = 0, dist = 0; i < len - 1; i++) {
208
- p1 = points[i];
209
- p2 = points[i + 1];
210
- segDist = p1.distanceTo(p2);
196
+ const points = _projectRing(latlngs, crs), len = points.length;
197
+ let halfDist = 0;
198
+ for (let i = 1; i < len; i++) halfDist += points[i - 1].distanceTo(points[i]);
199
+ halfDist /= 2;
200
+ let center = points[0];
201
+ for (let i = 1, dist = 0; i < len; i++) {
202
+ const p1 = points[i - 1], p2 = points[i], segDist = p1.distanceTo(p2);
211
203
  dist += segDist;
212
204
  if (dist > halfDist) {
213
- ratio = (dist - halfDist) / segDist;
214
- center = [p2.x - ratio * (p2.x - p1.x), p2.y - ratio * (p2.y - p1.y)];
205
+ const ratio = (dist - halfDist) / segDist;
206
+ center = new Point(p2.x - ratio * (p2.x - p1.x), p2.y - ratio * (p2.y - p1.y));
215
207
  break;
216
208
  }
217
209
  }
218
- const latlngCenter = crs.unproject(new Point(center));
219
- return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
210
+ return crs.unproject(center);
211
+ }
212
+ /**
213
+ * Projects the first ring of the given latlngs.
214
+ * @internal
215
+ * @param {LatLngExpression[]|LatLngExpression[][]} latlngs
216
+ * @param {typeof CRS} crs
217
+ * @returns {Point[]}
218
+ */
219
+ function _projectRing(latlngs, crs) {
220
+ if (!latlngs || latlngs.length === 0) throw new Error("latlngs not passed");
221
+ if (!isFlat(latlngs)) {
222
+ console.warn("latlngs are not flat! Only the first ring will be used");
223
+ return _projectRing(latlngs[0], crs);
224
+ }
225
+ return latlngs.map((latlng) => crs.project(LatLng.from(latlng)));
220
226
  }
221
- //#endregion
222
- export { LineUtil_exports, _getBitCode, _getEdgeIntersection, _sqClosestPointOnSegment, clipSegment, closestPointOnSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify };
227
+ export { LineUtil_exports, _getBitCode, _getEdgeIntersection, _projectRing, _sqClosestPointOnSegment, clipSegment, closestPointOnSegment, isFlat, pointToSegmentDistance, polylineCenter, simplify };
223
228
 
224
229
  //# sourceMappingURL=LineUtil.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LineUtil.js","names":[],"sources":["../../../src/geometry/LineUtil.js"],"sourcesContent":["import {Point} from './Point.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {centroid} from './PolyUtil.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// LineUtil: various utility functions for polyline points processing, used by Maplair\n// internally to make polylines lightning-fast.\n\n// Simplify polyline with vertex reduction and Douglas-Peucker simplification.\n// Improves rendering performance dramatically by lessening the number of points to draw.\n\n/**\n * Dramatically reduces the number of points in a polyline while retaining\n * its shape and returns a new array of simplified points, using the\n * [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).\n * Used for a huge performance boost when processing/displaying Maplair polylines for\n * each zoom level and also reducing visual noise. tolerance affects the amount of\n * simplification (lesser value means higher quality but slower and with more points).\n * Also released as a separated micro-library\n * [Simplify.js](https://mourner.github.io/simplify-js/).\n * @param {Point[]} points\n * @param {number} tolerance\n * @returns {Point[]}\n */\nexport function simplify(points, tolerance) {\n\tif (!tolerance || !points.length) {\n\t\treturn points.slice();\n\t}\n\n\tconst sqTolerance = tolerance * tolerance;\n\n\t// stage 1: vertex reduction\n\tpoints = _reducePoints(points, sqTolerance);\n\n\t// stage 2: Douglas-Peucker simplification\n\tpoints = _simplifyDP(points, sqTolerance);\n\n\treturn points;\n}\n\n/**\n * Returns the distance between point `p` and segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {number}\n */\nexport function pointToSegmentDistance(p, p1, p2) {\n\treturn Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));\n}\n\n/**\n * Returns the closest point from a point `p` on a segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {Point}\n */\nexport function closestPointOnSegment(p, p1, p2) {\n\treturn _sqClosestPointOnSegment(p, p1, p2);\n}\n\n// Ramer-Douglas-Peucker simplification, see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\nfunction _simplifyDP(points, sqTolerance) {\n\n\tconst len = points.length,\n\tmarkers = new Uint8Array(len);\n\tmarkers[0] = markers[len - 1] = 1;\n\n\t_simplifyDPStep(points, markers, sqTolerance, 0, len - 1);\n\n\tlet i;\n\tconst newPoints = [];\n\n\tfor (i = 0; i < len; i++) {\n\t\tif (markers[i]) {\n\t\t\tnewPoints.push(points[i]);\n\t\t}\n\t}\n\n\treturn newPoints;\n}\n\nfunction _simplifyDPStep(points, markers, sqTolerance, first, last) {\n\n\tlet maxSqDist = 0,\n\tindex, i, sqDist;\n\n\tfor (i = first + 1; i <= last - 1; i++) {\n\t\tsqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);\n\n\t\tif (sqDist > maxSqDist) {\n\t\t\tindex = i;\n\t\t\tmaxSqDist = sqDist;\n\t\t}\n\t}\n\n\tif (maxSqDist > sqTolerance) {\n\t\tmarkers[index] = 1;\n\n\t\t_simplifyDPStep(points, markers, sqTolerance, first, index);\n\t\t_simplifyDPStep(points, markers, sqTolerance, index, last);\n\t}\n}\n\n// reduce points that are too close to each other to a single point\nfunction _reducePoints(points, sqTolerance) {\n\tconst reducedPoints = [points[0]];\n\tlet prev = 0;\n\n\tfor (let i = 1; i < points.length; i++) {\n\t\tif (_sqDist(points[i], points[prev]) > sqTolerance) {\n\t\t\treducedPoints.push(points[i]);\n\t\t\tprev = i;\n\t\t}\n\t}\n\tif (prev < points.length - 1) {\n\t\treducedPoints.push(points[points.length - 1]);\n\t}\n\treturn reducedPoints;\n}\n\nlet _lastCode;\n\n/**\n * Clips the segment a to b by rectangular bounds with the\n * [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)\n * (modifying the segment points directly!). Used by Maplair to only show polyline\n * points that are on the screen or near, increasing performance. Returns `false` if\n * the segment is outside of the bounds.\n * @param {Point} a\n * @param {Point} b\n * @param {Bounds} bounds\n * @param {boolean} [useLastCode]\n * @param {boolean} [round]\n * @returns {[Point, Point]|false}\n */\nexport function clipSegment(a, b, bounds, useLastCode, round) {\n\tlet codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),\n\tcodeB = _getBitCode(b, bounds),\n\n\tcodeOut, p, newCode;\n\n\t// save 2nd code to avoid calculating it on the next segment\n\t_lastCode = codeB;\n\n\twhile (true) {\n\t\t// if a,b is inside the clip window (trivial accept)\n\t\tif (!(codeA | codeB)) {\n\t\t\treturn [a, b];\n\t\t}\n\n\t\t// if a,b is outside the clip window (trivial reject)\n\t\tif (codeA & codeB) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// other cases\n\t\tcodeOut = codeA || codeB;\n\t\tp = _getEdgeIntersection(a, b, codeOut, bounds, round);\n\t\tnewCode = _getBitCode(p, bounds);\n\n\t\tif (codeOut === codeA) {\n\t\t\ta = p;\n\t\t\tcodeA = newCode;\n\t\t} else {\n\t\t\tb = p;\n\t\t\tcodeB = newCode;\n\t\t}\n\t}\n}\n\nexport function _getEdgeIntersection(a, b, code, bounds, round) {\n\tconst dx = b.x - a.x,\n\tdy = b.y - a.y,\n\tmin = bounds.min,\n\tmax = bounds.max;\n\tlet x, y;\n\n\tif (code & 8) { // top\n\t\tx = a.x + dx * (max.y - a.y) / dy;\n\t\ty = max.y;\n\n\t} else if (code & 4) { // bottom\n\t\tx = a.x + dx * (min.y - a.y) / dy;\n\t\ty = min.y;\n\n\t} else if (code & 2) { // right\n\t\tx = max.x;\n\t\ty = a.y + dy * (max.x - a.x) / dx;\n\n\t} else if (code & 1) { // left\n\t\tx = min.x;\n\t\ty = a.y + dy * (min.x - a.x) / dx;\n\t}\n\n\treturn new Point(x, y, round);\n}\n\nexport function _getBitCode(p, bounds) {\n\tlet code = 0;\n\n\tif (p.x < bounds.min.x) { // left\n\t\tcode |= 1;\n\t} else if (p.x > bounds.max.x) { // right\n\t\tcode |= 2;\n\t}\n\n\tif (p.y < bounds.min.y) { // bottom\n\t\tcode |= 4;\n\t} else if (p.y > bounds.max.y) { // top\n\t\tcode |= 8;\n\t}\n\n\treturn code;\n}\n\n// square distance (to avoid unnecessary Math.sqrt calls)\nfunction _sqDist(p1, p2) {\n\tconst dx = p2.x - p1.x,\n\tdy = p2.y - p1.y;\n\treturn dx * dx + dy * dy;\n}\n\n// return closest point on segment or distance to that point\nexport function _sqClosestPointOnSegment(p, p1, p2, sqDist) {\n\tlet x = p1.x,\n\ty = p1.y,\n\tdx = p2.x - x,\n\tdy = p2.y - y,\n\tt;\n\tconst dot = dx * dx + dy * dy;\n\n\tif (dot > 0) {\n\t\tt = ((p.x - x) * dx + (p.y - y) * dy) / dot;\n\n\t\tif (t > 1) {\n\t\t\tx = p2.x;\n\t\t\ty = p2.y;\n\t\t} else if (t > 0) {\n\t\t\tx += dx * t;\n\t\t\ty += dy * t;\n\t\t}\n\t}\n\n\tdx = p.x - x;\n\tdy = p.y - y;\n\n\treturn sqDist ? dx * dx + dy * dy : new Point(x, y);\n}\n\n\n/**\n * Returns true if `latlngs` is a flat array, false is nested.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @returns {boolean}\n */\nexport function isFlat(latlngs) {\n\treturn !Array.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polyline.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polylineCenter(latlngs, crs) {\n\tlet i, halfDist, segDist, dist, p1, p2, ratio, center;\n\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\tlatlngs = latlngs[0];\n\t}\n\n\tlet centroidLatLng = new LatLng([0, 0]);\n\n\tconst bounds = new LatLngBounds(latlngs);\n\tconst areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());\n\t// tests showed that below 1700 rounding errors are happening\n\tif (areaBounds < 1700) {\n\t\t// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors\n\t\tcentroidLatLng = centroid(latlngs);\n\t}\n\n\tconst len = latlngs.length;\n\tconst points = [];\n\tfor (i = 0; i < len; i++) {\n\t\tconst latlng = new LatLng(latlngs[i]);\n\t\tpoints.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));\n\t}\n\n\tfor (i = 0, halfDist = 0; i < len - 1; i++) {\n\t\thalfDist += points[i].distanceTo(points[i + 1]) / 2;\n\t}\n\n\t// The line is so small in the current view that all points are on the same pixel.\n\tif (halfDist === 0) {\n\t\tcenter = points[0];\n\t} else {\n\t\tfor (i = 0, dist = 0; i < len - 1; i++) {\n\t\t\tp1 = points[i];\n\t\t\tp2 = points[i + 1];\n\t\t\tsegDist = p1.distanceTo(p2);\n\t\t\tdist += segDist;\n\n\t\t\tif (dist > halfDist) {\n\t\t\t\tratio = (dist - halfDist) / segDist;\n\t\t\t\tcenter = [\n\t\t\t\t\tp2.x - ratio * (p2.x - p1.x),\n\t\t\t\t\tp2.y - ratio * (p2.y - p1.y)\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst latlngCenter = crs.unproject(new Point(center));\n\treturn new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,SAAS,QAAQ,WAAW;CAC3C,IAAI,CAAC,a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a,MAAM,eAAe,KAAK,aAAa,MAAM,eAAe,GAAG,CAAC;AACjG"}
1
+ {"version":3,"file":"LineUtil.js","names":[],"sources":["../../../src/geometry/LineUtil.js"],"sourcesContent":["import {Point} from './Point.js';\nimport {LatLng} from '../geo/LatLng.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// LineUtil: various utility functions for polyline points processing, used by Maplair\n// internally to make polylines lightning-fast.\n\n// Simplify polyline with vertex reduction and Douglas-Peucker simplification.\n// Improves rendering performance dramatically by lessening the number of points to draw.\n\n/**\n * Dramatically reduces the number of points in a polyline while retaining\n * its shape and returns a new array of simplified points, using the\n * [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).\n * Used for a huge performance boost when processing/displaying Maplair polylines for\n * each zoom level and also reducing visual noise. tolerance affects the amount of\n * simplification (lesser value means higher quality but slower and with more points).\n * Also released as a separated micro-library\n * [Simplify.js](https://mourner.github.io/simplify-js/).\n * @param {Point[]} points\n * @param {number} tolerance\n * @returns {Point[]}\n */\nexport function simplify(points, tolerance) {\n\tif (!tolerance || !points.length) {\n\t\treturn points.slice();\n\t}\n\n\tconst sqTolerance = tolerance * tolerance;\n\n\t// stage 1: vertex reduction\n\tpoints = _reducePoints(points, sqTolerance);\n\n\t// stage 2: Douglas-Peucker simplification\n\tpoints = _simplifyDP(points, sqTolerance);\n\n\treturn points;\n}\n\n/**\n * Returns the distance between point `p` and segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {number}\n */\nexport function pointToSegmentDistance(p, p1, p2) {\n\treturn Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));\n}\n\n/**\n * Returns the closest point from a point `p` on a segment `p1` to `p2`.\n * @param {Point} p\n * @param {Point} p1\n * @param {Point} p2\n * @returns {Point}\n */\nexport function closestPointOnSegment(p, p1, p2) {\n\treturn _sqClosestPointOnSegment(p, p1, p2);\n}\n\n// Ramer-Douglas-Peucker simplification, see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm\nfunction _simplifyDP(points, sqTolerance) {\n\n\tconst len = points.length,\n\tmarkers = new Uint8Array(len);\n\tmarkers[0] = markers[len - 1] = 1;\n\n\t_simplifyDPStep(points, markers, sqTolerance, 0, len - 1);\n\n\tlet i;\n\tconst newPoints = [];\n\n\tfor (i = 0; i < len; i++) {\n\t\tif (markers[i]) {\n\t\t\tnewPoints.push(points[i]);\n\t\t}\n\t}\n\n\treturn newPoints;\n}\n\nfunction _simplifyDPStep(points, markers, sqTolerance, first, last) {\n\n\tlet maxSqDist = 0,\n\tindex, i, sqDist;\n\n\tfor (i = first + 1; i <= last - 1; i++) {\n\t\tsqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);\n\n\t\tif (sqDist > maxSqDist) {\n\t\t\tindex = i;\n\t\t\tmaxSqDist = sqDist;\n\t\t}\n\t}\n\n\tif (maxSqDist > sqTolerance) {\n\t\tmarkers[index] = 1;\n\n\t\t_simplifyDPStep(points, markers, sqTolerance, first, index);\n\t\t_simplifyDPStep(points, markers, sqTolerance, index, last);\n\t}\n}\n\n// reduce points that are too close to each other to a single point\nfunction _reducePoints(points, sqTolerance) {\n\tconst reducedPoints = [points[0]];\n\tlet prev = 0;\n\n\tfor (let i = 1; i < points.length; i++) {\n\t\tif (_sqDist(points[i], points[prev]) > sqTolerance) {\n\t\t\treducedPoints.push(points[i]);\n\t\t\tprev = i;\n\t\t}\n\t}\n\tif (prev < points.length - 1) {\n\t\treducedPoints.push(points[points.length - 1]);\n\t}\n\treturn reducedPoints;\n}\n\nlet _lastCode;\n\n/**\n * Clips the segment a to b by rectangular bounds with the\n * [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)\n * (modifying the segment points directly!). Used by Maplair to only show polyline\n * points that are on the screen or near, increasing performance. Returns `false` if\n * the segment is outside of the bounds.\n * @param {Point} a\n * @param {Point} b\n * @param {Bounds} bounds\n * @param {boolean} [useLastCode]\n * @param {boolean} [round]\n * @returns {[Point, Point]|false}\n */\nexport function clipSegment(a, b, bounds, useLastCode, round) {\n\tconst a0 = a, b0 = b;\n\tlet codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),\n\tcodeB = _getBitCode(b, bounds),\n\n\tcodeOut, p, newCode;\n\n\t// save 2nd code to avoid calculating it on the next segment\n\t_lastCode = codeB;\n\n\twhile (true) {\n\t\t// if a,b is inside the clip window (trivial accept)\n\t\tif (!(codeA | codeB)) {\n\t\t\t// round only the endpoints that were replaced by a clipped intersection;\n\t\t\t// rounding while iterating can push a point back outside and loop forever\n\t\t\tif (round) {\n\t\t\t\tif (a !== a0) { a = a.round(); }\n\t\t\t\tif (b !== b0) { b = b.round(); }\n\t\t\t}\n\t\t\treturn [a, b];\n\t\t}\n\n\t\t// if a,b is outside the clip window (trivial reject)\n\t\tif (codeA & codeB) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// other cases\n\t\tcodeOut = codeA || codeB;\n\t\tp = _getEdgeIntersection(a, b, codeOut, bounds);\n\t\tnewCode = _getBitCode(p, bounds);\n\n\t\tif (codeOut === codeA) {\n\t\t\ta = p;\n\t\t\tcodeA = newCode;\n\t\t} else {\n\t\t\tb = p;\n\t\t\tcodeB = newCode;\n\t\t}\n\t}\n}\n\nexport function _getEdgeIntersection(a, b, code, bounds, round) {\n\tconst dx = b.x - a.x,\n\tdy = b.y - a.y,\n\tmin = bounds.min,\n\tmax = bounds.max;\n\tlet x, y;\n\n\tif (code & 8) { // top\n\t\tx = a.x + dx * (max.y - a.y) / dy;\n\t\ty = max.y;\n\n\t} else if (code & 4) { // bottom\n\t\tx = a.x + dx * (min.y - a.y) / dy;\n\t\ty = min.y;\n\n\t} else if (code & 2) { // right\n\t\tx = max.x;\n\t\ty = a.y + dy * (max.x - a.x) / dx;\n\n\t} else if (code & 1) { // left\n\t\tx = min.x;\n\t\ty = a.y + dy * (min.x - a.x) / dx;\n\t}\n\n\treturn new Point(x, y, round);\n}\n\nexport function _getBitCode(p, bounds) {\n\tlet code = 0;\n\n\tif (p.x < bounds.min.x) { // left\n\t\tcode |= 1;\n\t} else if (p.x > bounds.max.x) { // right\n\t\tcode |= 2;\n\t}\n\n\tif (p.y < bounds.min.y) { // bottom\n\t\tcode |= 4;\n\t} else if (p.y > bounds.max.y) { // top\n\t\tcode |= 8;\n\t}\n\n\treturn code;\n}\n\n// square distance (to avoid unnecessary Math.sqrt calls)\nfunction _sqDist(p1, p2) {\n\tconst dx = p2.x - p1.x,\n\tdy = p2.y - p1.y;\n\treturn dx * dx + dy * dy;\n}\n\n// return closest point on segment or distance to that point\nexport function _sqClosestPointOnSegment(p, p1, p2, sqDist) {\n\tlet x = p1.x,\n\ty = p1.y,\n\tdx = p2.x - x,\n\tdy = p2.y - y,\n\tt;\n\tconst dot = dx * dx + dy * dy;\n\n\tif (dot > 0) {\n\t\tt = ((p.x - x) * dx + (p.y - y) * dy) / dot;\n\n\t\tif (t > 1) {\n\t\t\tx = p2.x;\n\t\t\ty = p2.y;\n\t\t} else if (t > 0) {\n\t\t\tx += dx * t;\n\t\t\ty += dy * t;\n\t\t}\n\t}\n\n\tdx = p.x - x;\n\tdy = p.y - y;\n\n\treturn sqDist ? dx * dx + dy * dy : new Point(x, y);\n}\n\n\n/**\n * Returns true if `latlngs` is a flat array, false is nested.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @returns {boolean}\n */\nexport function isFlat(latlngs) {\n\treturn !Array.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polyline.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polylineCenter(latlngs, crs) {\n\tconst points = _projectRing(latlngs, crs),\n\tlen = points.length;\n\n\tlet halfDist = 0;\n\tfor (let i = 1; i < len; i++) {\n\t\thalfDist += points[i - 1].distanceTo(points[i]);\n\t}\n\thalfDist /= 2;\n\n\t// if the line has zero length, the loop below never finds a segment and the first point is the center\n\tlet center = points[0];\n\n\tfor (let i = 1, dist = 0; i < len; i++) {\n\t\tconst p1 = points[i - 1],\n\t\tp2 = points[i],\n\t\tsegDist = p1.distanceTo(p2);\n\t\tdist += segDist;\n\n\t\tif (dist > halfDist) {\n\t\t\tconst ratio = (dist - halfDist) / segDist;\n\t\t\tcenter = new Point(\n\t\t\t\tp2.x - ratio * (p2.x - p1.x),\n\t\t\t\tp2.y - ratio * (p2.y - p1.y)\n\t\t\t);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn crs.unproject(center);\n}\n\n/**\n * Projects the first ring of the given latlngs.\n * @internal\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {Point[]}\n */\nexport function _projectRing(latlngs, crs) {\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\treturn _projectRing(latlngs[0], crs);\n\t}\n\n\treturn latlngs.map(latlng => crs.project(LatLng.from(latlng)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,SAAS,QAAQ,WAAW;CAC3C,IAAI,CAAC,aAAa,CAAC,OAAO,QACzB,OAAO,OAAO,MAAM;CAGrB,MAAM,cAAc,YAAY;CAGhC,SAAS,cAAc,QAAQ,WAAW;CAG1C,SAAS,YAAY,QAAQ,WAAW;CAExC,OAAO;AACR;;;;;;;;AASA,SAAgB,uBAAuB,GAAG,IAAI,IAAI;CACjD,OAAO,KAAK,KAAK,yBAAyB,GAAG,IAAI,IAAI,IAAI,CAAC;AAC3D;;;;;;;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AAE;CAE/C,YAAY;CAGZ,IAAI,SAAS,OAAO;CAEpB,KAAK,IAAI,IAAI,GAAG,OAAO,GAAG,IAAI,KAAK,KAAK;EACvC,MAAM,KAAK,OAAO,IAAI,IACtB,KAAK,OAAO,IACZ,UAAU,GAAG,WAAW,EAAE;EAC1B,QAAQ;EAER,IAAI,OAAO,UAAU;GACpB,MAAM,SAAS,OAAO,YAAY;GAClC,SAAS,IAAI,MACZ,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,IAC1B,GAAG,IAAI,SAAS,GAAG,IAAI,GAAG,EAC3B;GACA;EACD;CACD;CAEA,OAAO,IAAI,UAAU,MAAM;AAC5B;;;;;;;;AASA,SAAgB,aAAa,SAAS,KAAK;CAC1C,IAAI,CAAC,WAAW,QAAQ,WAAW,GAClC,MAAM,IAAI,MAAM,oBAAoB;CAGrC,IAAI,CAAC,OAAO,OAAO,GAAG;EACrB,QAAQ,KAAK,wDAAwD;EACrE,OAAO,aAAa,QAAQ,IAAI,GAAG;CACpC;CAEA,OAAO,QAAQ,KAAI,WAAU,IAAI,QAAQ,OAAO,KAAK,MAAM,CAAC,CAAC;AAC9D"}
@@ -1,5 +1,5 @@
1
1
  import { formatNum } from "../core/Util.js";
2
- //#region src/geometry/Point.js
2
+ // src/geometry/Point.js
3
3
  /**
4
4
  * A point in pixels: a `Point`, an array of the form `[x, y]`, or a plain object of
5
5
  * the form `{x, y}`. Accepted by all Maplair methods and options which accept `Point`
@@ -252,7 +252,6 @@ var Point = class Point {
252
252
  return `Point(${formatNum(this.x)}, ${formatNum(this.y)})`;
253
253
  }
254
254
  };
255
- //#endregion
256
255
  export { Point };
257
256
 
258
257
  //# sourceMappingURL=Point.js.map
@@ -1,9 +1,8 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
2
  import { Point } from "./Point.js";
3
- import { LatLngBounds } from "../geo/LatLngBounds.js";
4
3
  import { LatLng } from "../geo/LatLng.js";
5
- import { _getBitCode, _getEdgeIntersection, isFlat } from "./LineUtil.js";
6
- //#region src/geometry/PolyUtil.js
4
+ import { _getEdgeIntersection, _projectRing } from "./LineUtil.js";
5
+ // src/geometry/PolyUtil.js
7
6
  var PolyUtil_exports = /* @__PURE__ */ __exportAll({
8
7
  centroid: () => centroid,
9
8
  clipPolygon: () => clipPolygon,
@@ -24,37 +23,30 @@ var PolyUtil_exports = /* @__PURE__ */ __exportAll({
24
23
  * @returns {Point[]}
25
24
  */
26
25
  function clipPolygon(points, bounds, round) {
27
- let clippedPoints, i, j, k, a, b, len, edge, p;
28
- const edges = [
26
+ for (const edge of [
29
27
  1,
30
28
  4,
31
29
  2,
32
30
  8
33
- ];
34
- for (i = 0, len = points.length; i < len; i++) points[i]._code = _getBitCode(points[i], bounds);
35
- for (k = 0; k < 4; k++) {
36
- edge = edges[k];
37
- clippedPoints = [];
38
- for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
39
- a = points[i];
40
- b = points[j];
41
- if (!(a._code & edge)) {
42
- if (b._code & edge) {
43
- p = _getEdgeIntersection(b, a, edge, bounds, round);
44
- p._code = _getBitCode(p, bounds);
45
- clippedPoints.push(p);
46
- }
47
- clippedPoints.push(a);
48
- } else if (!(b._code & edge)) {
49
- p = _getEdgeIntersection(b, a, edge, bounds, round);
50
- p._code = _getBitCode(p, bounds);
51
- clippedPoints.push(p);
52
- }
31
+ ]) {
32
+ if (!points.length) break;
33
+ /** @type {Point[]} */
34
+ const clippedPoints = [];
35
+ let b = points[points.length - 1], bOut = isOutside(b, edge, bounds);
36
+ for (const a of points) {
37
+ const aOut = isOutside(a, edge, bounds);
38
+ if (aOut !== bOut) clippedPoints.push(_getEdgeIntersection(b, a, edge, bounds, round));
39
+ if (!aOut) clippedPoints.push(a);
40
+ b = a;
41
+ bOut = aOut;
53
42
  }
54
43
  points = clippedPoints;
55
44
  }
56
45
  return points;
57
46
  }
47
+ function isOutside(p, edge, bounds) {
48
+ return edge === 1 ? p.x < bounds.min.x : edge === 2 ? p.x > bounds.max.x : edge === 4 ? p.y < bounds.min.y : p.y > bounds.max.y;
49
+ }
58
50
  /**
59
51
  * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed
60
52
  * LatLngs (first ring) from a polygon.
@@ -63,34 +55,16 @@ function clipPolygon(points, bounds, round) {
63
55
  * @returns {LatLng}
64
56
  */
65
57
  function polygonCenter(latlngs, crs) {
66
- let i, j, p1, p2, f, area, x, y, center;
67
- if (!latlngs || latlngs.length === 0) throw new Error("latlngs not passed");
68
- if (!isFlat(latlngs)) {
69
- console.warn("latlngs are not flat! Only the first ring will be used");
70
- latlngs = latlngs[0];
71
- }
72
- let centroidLatLng = new LatLng([0, 0]);
73
- const bounds = new LatLngBounds(latlngs);
74
- if (bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest()) < 1700) centroidLatLng = centroid(latlngs);
75
- const len = latlngs.length;
76
- const points = [];
77
- for (i = 0; i < len; i++) {
78
- const latlng = new LatLng(latlngs[i]);
79
- points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
80
- }
81
- area = x = y = 0;
82
- for (i = 0, j = len - 1; i < len; j = i++) {
83
- p1 = points[i];
84
- p2 = points[j];
85
- f = p1.y * p2.x - p2.y * p1.x;
58
+ const points = _projectRing(latlngs, crs), origin = new Point(points[0]), len = points.length;
59
+ for (const p of points) p._subtract(origin);
60
+ let area = 0, x = 0, y = 0;
61
+ for (let i = 0, j = len - 1; i < len; j = i++) {
62
+ const p1 = points[i], p2 = points[j], f = p1.y * p2.x - p2.y * p1.x;
86
63
  x += (p1.x + p2.x) * f;
87
64
  y += (p1.y + p2.y) * f;
88
- area += f * 3;
65
+ area += f;
89
66
  }
90
- if (area === 0) center = points[0];
91
- else center = [x / area, y / area];
92
- const latlngCenter = crs.unproject(new Point(center));
93
- return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
67
+ return crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));
94
68
  }
95
69
  /**
96
70
  * Returns the 'center of mass' of the passed LatLngs.
@@ -109,7 +83,6 @@ function centroid(coords) {
109
83
  }
110
84
  return new LatLng([latSum / len, lngSum / len]);
111
85
  }
112
- //#endregion
113
86
  export { PolyUtil_exports, centroid, clipPolygon, polygonCenter };
114
87
 
115
88
  //# sourceMappingURL=PolyUtil.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PolyUtil.js","names":["LineUtil._getBitCode","LineUtil._getEdgeIntersection","LineUtil.isFlat"],"sources":["../../../src/geometry/PolyUtil.js"],"sourcesContent":["import * as LineUtil from './LineUtil.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from './Point.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// PolyUtil: various utility functions for polygon geometries.\n\n/**\n * Clips the polygon geometry defined by the given `points` by the given bounds (using\n * the [Sutherland-Hodgman algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)).\n * Used by Maplair to only show polygon points that are on the screen or near, increasing\n * performance. Note that polygon points needs different algorithm for clipping\n * than polyline, so there's a separate method for it.\n * @param {Point[]} points\n * @param {Bounds} bounds\n * @param {boolean} [round]\n * @returns {Point[]}\n */\nexport function clipPolygon(points, bounds, round) {\n\tlet clippedPoints,\n\ti, j, k,\n\ta, b,\n\tlen, edge, p;\n\tconst edges = [1, 4, 2, 8];\n\n\tfor (i = 0, len = points.length; i < len; i++) {\n\t\tpoints[i]._code = LineUtil._getBitCode(points[i], bounds);\n\t}\n\n\t// for each edge (left, bottom, right, top)\n\tfor (k = 0; k < 4; k++) {\n\t\tedge = edges[k];\n\t\tclippedPoints = [];\n\n\t\tfor (i = 0, len = points.length, j = len - 1; i < len; j = i++) {\n\t\t\ta = points[i];\n\t\t\tb = points[j];\n\n\t\t\t// if a is inside the clip window\n\t\t\tif (!(a._code & edge)) {\n\t\t\t\t// if b is outside the clip window (a->b goes out of screen)\n\t\t\t\tif (b._code & edge) {\n\t\t\t\t\tp = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);\n\t\t\t\t\tp._code = LineUtil._getBitCode(p, bounds);\n\t\t\t\t\tclippedPoints.push(p);\n\t\t\t\t}\n\t\t\t\tclippedPoints.push(a);\n\n\t\t\t// else if b is inside the clip window (a->b enters the screen)\n\t\t\t} else if (!(b._code & edge)) {\n\t\t\t\tp = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);\n\t\t\t\tp._code = LineUtil._getBitCode(p, bounds);\n\t\t\t\tclippedPoints.push(p);\n\t\t\t}\n\t\t}\n\t\tpoints = clippedPoints;\n\t}\n\n\treturn points;\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polygon.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polygonCenter(latlngs, crs) {\n\tlet i, j, p1, p2, f, area, x, y, center;\n\n\tif (!latlngs || latlngs.length === 0) {\n\t\tthrow new Error('latlngs not passed');\n\t}\n\n\tif (!LineUtil.isFlat(latlngs)) {\n\t\tconsole.warn('latlngs are not flat! Only the first ring will be used');\n\t\tlatlngs = latlngs[0];\n\t}\n\n\tlet centroidLatLng = new LatLng([0, 0]);\n\n\tconst bounds = new LatLngBounds(latlngs);\n\tconst areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());\n\t// tests showed that below 1700 rounding errors are happening\n\tif (areaBounds < 1700) {\n\t\t// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors\n\t\tcentroidLatLng = centroid(latlngs);\n\t}\n\n\tconst len = latlngs.length;\n\tconst points = [];\n\tfor (i = 0; i < len; i++) {\n\t\tconst latlng = new LatLng(latlngs[i]);\n\t\tpoints.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));\n\t}\n\n\tarea = x = y = 0;\n\n\t// polygon centroid algorithm;\n\tfor (i = 0, j = len - 1; i < len; j = i++) {\n\t\tp1 = points[i];\n\t\tp2 = points[j];\n\n\t\tf = p1.y * p2.x - p2.y * p1.x;\n\t\tx += (p1.x + p2.x) * f;\n\t\ty += (p1.y + p2.y) * f;\n\t\tarea += f * 3;\n\t}\n\n\tif (area === 0) {\n\t\t// Polygon is so small that all points are on same pixel.\n\t\tcenter = points[0];\n\t} else {\n\t\tcenter = [x / area, y / area];\n\t}\n\n\tconst latlngCenter = crs.unproject(new Point(center));\n\treturn new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);\n}\n\n/**\n * Returns the 'center of mass' of the passed LatLngs.\n * @param {LatLngExpression[]} coords\n * @returns {LatLng}\n */\nexport function centroid(coords) {\n\tlet latSum = 0;\n\tlet lngSum = 0;\n\tlet len = 0;\n\tfor (const coord of coords) {\n\t\tconst latlng = LatLng.from(coord);\n\t\tlatSum += latlng.lat;\n\t\tlngSum += latlng.lng;\n\t\tlen++;\n\t}\n\treturn new LatLng([latSum / len, lngSum / len]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,YAAY,QAAQ,QAAQ,OAAO;CAClD,IAAI,eACJ,GAAG,GAAG,GACN,GAAG,GACH,KAAK,MAAM;CACX,MAAM,QAAQ;EAAC;EAAG;EAAG;EAAG;CAAC;CAEzB,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,IAAI,KAAK,KACzC,OAAO,EAAE,CAAC,QAAQA,YAAqB,OAAO,IAAI,MAAM;CAIzD,KAAK,IAAI,GAAG,IAAI,GAAG,KAAK;EACvB,OAAO,MAAM;EACb,gBAAgB,CAAC;EAEjB,KAAK,IAAI,GAAG,MAAM,OAAO,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AM,eAAe,GAAG,CAAC,CAAC,CAAC;CACxG;CAEA,OAAO,IAAI,IAAI;CAGf,KAAK,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,KAAK,IAAI,KAAK;EAC1C,KAAK,OAAO;EACZ,KAAK,OAAO;EAEZ,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;EAC5B,MAAM,GAAG,IAAI,GAAG,KAAK;EACrB,MAAM,GAAG,IAAI,GAAG,KAAK;EACrB,QAAQ,IAAI;CACb;CAEA,IAAI,SAAS,GAEZ,SAAS,OAAO;MAEhB,SAAS,CAAC,IAAI,MAAM,IAAI,IAAI;CAG7B,MAAM,eAAe,IAAI,UAAU,IAAI,MAAM,MAAM,CAAC;CACpD,OAAO,IAAI,OAAO,CAAC,aAAa,MAAM,eAAe,KAAK,aAAa,MAAM,eAAe,GAAG,CAAC;AACjG;;;;;;AAOA,SAAgB,SAAS,QAAQ;CAChC,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,MAAM;CACV,KAAK,MAAM,SAAS,QAAQ;EAC3B,MAAM,SAAS,OAAO,KAAK,KAAK;EAChC,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB;CACD;CACA,OAAO,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,GAAG,CAAC;AAC/C"}
1
+ {"version":3,"file":"PolyUtil.js","names":["LineUtil._getEdgeIntersection","LineUtil._projectRing"],"sources":["../../../src/geometry/PolyUtil.js"],"sourcesContent":["import * as LineUtil from './LineUtil.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from './Point.js';\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {Bounds} from './Bounds.js' */\n/** @import {CRS} from '../geo/crs/CRS.js' */\n\n// PolyUtil: various utility functions for polygon geometries.\n\n/**\n * Clips the polygon geometry defined by the given `points` by the given bounds (using\n * the [Sutherland-Hodgman algorithm](https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm)).\n * Used by Maplair to only show polygon points that are on the screen or near, increasing\n * performance. Note that polygon points needs different algorithm for clipping\n * than polyline, so there's a separate method for it.\n * @param {Point[]} points\n * @param {Bounds} bounds\n * @param {boolean} [round]\n * @returns {Point[]}\n */\nexport function clipPolygon(points, bounds, round) {\n\t// left, bottom, right, top\n\tfor (const edge of [1, 4, 2, 8]) {\n\t\tif (!points.length) { break; }\n\n\t\t/** @type {Point[]} */\n\t\tconst clippedPoints = [];\n\t\tlet b = points[points.length - 1],\n\t\tbOut = isOutside(b, edge, bounds);\n\n\t\tfor (const a of points) {\n\t\t\tconst aOut = isOutside(a, edge, bounds);\n\t\t\t// a->b crosses the edge\n\t\t\tif (aOut !== bOut) {\n\t\t\t\tclippedPoints.push(LineUtil._getEdgeIntersection(b, a, edge, bounds, round));\n\t\t\t}\n\t\t\tif (!aOut) {\n\t\t\t\tclippedPoints.push(a);\n\t\t\t}\n\t\t\tb = a;\n\t\t\tbOut = aOut;\n\t\t}\n\t\tpoints = clippedPoints;\n\t}\n\n\treturn points;\n}\n\n// Whether the point is outside the given edge of the bounds; the edge is a `LineUtil` clipping bit code\nfunction isOutside(p, edge, bounds) {\n\treturn edge === 1 ? p.x < bounds.min.x :\n\t\tedge === 2 ? p.x > bounds.max.x :\n\t\tedge === 4 ? p.y < bounds.min.y : p.y > bounds.max.y;\n}\n\n/**\n * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed\n * LatLngs (first ring) from a polygon.\n * @param {LatLngExpression[]|LatLngExpression[][]} latlngs\n * @param {typeof CRS} crs\n * @returns {LatLng}\n */\nexport function polygonCenter(latlngs, crs) {\n\t// points relative to the first one, to avoid floating point errors on tiny polygons with large projected coordinates\n\tconst points = LineUtil._projectRing(latlngs, crs),\n\torigin = new Point(points[0]),\n\tlen = points.length;\n\n\tfor (const p of points) { p._subtract(origin); }\n\n\tlet area = 0, x = 0, y = 0;\n\n\t// polygon centroid algorithm\n\tfor (let i = 0, j = len - 1; i < len; j = i++) {\n\t\tconst p1 = points[i],\n\t\tp2 = points[j],\n\t\tf = p1.y * p2.x - p2.y * p1.x;\n\n\t\tx += (p1.x + p2.x) * f;\n\t\ty += (p1.y + p2.y) * f;\n\t\tarea += f;\n\t}\n\n\t// area is 0 when the polygon is so small that all points are on the same pixel\n\treturn crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));\n}\n\n/**\n * Returns the 'center of mass' of the passed LatLngs.\n * @param {LatLngExpression[]} coords\n * @returns {LatLng}\n */\nexport function centroid(coords) {\n\tlet latSum = 0;\n\tlet lngSum = 0;\n\tlet len = 0;\n\tfor (const coord of coords) {\n\t\tconst latlng = LatLng.from(coord);\n\t\tlatSum += latlng.lat;\n\t\tlngSum += latlng.lng;\n\t\tlen++;\n\t}\n\treturn new LatLng([latSum / len, lngSum / len]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,YAAY,QAAQ,QAAQ,OAAO;CAElD,KAAK,MAAM,QAAQ;EAAC;EAAG;EAAG;EAAG;CAAC,GAAG;EAChC,IAAI,CAAC,OAAO,QAAU;;EAGtB,MAAM,gBAAgB,CAAC;EACvB,IAAI,IAAI,OAAO,OAAO,SAAS,IAC/B,OAAO,UAAU,GAAG,MAAM,MAAM;EAEhC,KAAK,MAAM,KAAK,QAAQ;GACvB,MAAM,OAAO,UAAU,GAAG,MAAM,MAAM;GAEtC,IAAI,SAAS,MACZ,cAAc,KAAKA,qBAA8B,GAAG,GAAG,MAAM,QAAQ,KAAK,CAAC;GAE5E,IAAI,CAAC,MACJ,cAAc,KAAK,CAAC;GAErB,IAAI;GACJ,OAAO;EACR;EACA,SAAS;CACV;CAEA,OAAO;AACR;AAGA,SAAS,UAAU,GAAG,MAAM,QAAQ;CACnC,OAAO,SAAS,IAAI,EAAE,IAAI,OAAO,IAAI,IACpC,SAAS,IAAI,EAAE,IAAI,OAAO,IAAI,IAC9B,SAAS,IAAI,EAAE,IAAI,OAAO,IAAI,IAAI,EAA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