maplair 4.0.0-alpha.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/CHANGELOG.md +140 -38
  2. package/LICENSE +1 -1
  3. package/README.md +10 -9
  4. package/dist/esm/Maplair.js +14 -14
  5. package/dist/esm/control/AttributionControl.js +24 -14
  6. package/dist/esm/control/AttributionControl.js.map +1 -1
  7. package/dist/esm/control/ButtonControl.js +9 -11
  8. package/dist/esm/control/ButtonControl.js.map +1 -1
  9. package/dist/esm/control/ContextMenu.js +1 -3
  10. package/dist/esm/control/ContextMenu.js.map +1 -1
  11. package/dist/esm/control/Control.js +9 -16
  12. package/dist/esm/control/Control.js.map +1 -1
  13. package/dist/esm/control/FullscreenControl.js +5 -7
  14. package/dist/esm/control/FullscreenControl.js.map +1 -1
  15. package/dist/esm/control/LayersControl.js +144 -35
  16. package/dist/esm/control/LayersControl.js.map +1 -1
  17. package/dist/esm/control/LegendControl.js +7 -9
  18. package/dist/esm/control/LegendControl.js.map +1 -1
  19. package/dist/esm/control/MiniMapControl.js +14 -16
  20. package/dist/esm/control/MiniMapControl.js.map +1 -1
  21. package/dist/esm/control/RotateControl.js +1 -3
  22. package/dist/esm/control/RotateControl.js.map +1 -1
  23. package/dist/esm/control/ScaleControl.js +7 -9
  24. package/dist/esm/control/ScaleControl.js.map +1 -1
  25. package/dist/esm/control/SearchControl.js +100 -18
  26. package/dist/esm/control/SearchControl.js.map +1 -1
  27. package/dist/esm/control/SideBySideControl.js +1 -3
  28. package/dist/esm/control/SideBySideControl.js.map +1 -1
  29. package/dist/esm/control/TextControl.js +5 -7
  30. package/dist/esm/control/TextControl.js.map +1 -1
  31. package/dist/esm/control/TimeControl.js +408 -0
  32. package/dist/esm/control/TimeControl.js.map +1 -0
  33. package/dist/esm/control/ZoomControl.js +5 -7
  34. package/dist/esm/control/ZoomControl.js.map +1 -1
  35. package/dist/esm/core/Class.js +28 -37
  36. package/dist/esm/core/Class.js.map +1 -1
  37. package/dist/esm/core/Events.js +21 -8
  38. package/dist/esm/core/Events.js.map +1 -1
  39. package/dist/esm/core/Handler.js +13 -11
  40. package/dist/esm/core/Handler.js.map +1 -1
  41. package/dist/esm/core/Util.js +13 -1
  42. package/dist/esm/core/Util.js.map +1 -1
  43. package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
  44. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  45. package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
  46. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  47. package/dist/esm/dom/DomEvent.js +8 -42
  48. package/dist/esm/dom/DomEvent.js.map +1 -1
  49. package/dist/esm/dom/DomUtil.js +14 -68
  50. package/dist/esm/dom/DomUtil.js.map +1 -1
  51. package/dist/esm/dom/Draggable.js +17 -18
  52. package/dist/esm/dom/Draggable.js.map +1 -1
  53. package/dist/esm/dom/PosAnimation.js +3 -25
  54. package/dist/esm/dom/PosAnimation.js.map +1 -1
  55. package/dist/esm/geo/LatLng.js +34 -6
  56. package/dist/esm/geo/LatLng.js.map +1 -1
  57. package/dist/esm/geo/LatLngBounds.js +19 -7
  58. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  59. package/dist/esm/geo/crs/CRS.js +4 -3
  60. package/dist/esm/geo/crs/CRS.js.map +1 -1
  61. package/dist/esm/geo/crs/EPSG3395.js +1 -1
  62. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  63. package/dist/esm/geo/crs/EPSG3857.js +1 -1
  64. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  65. package/dist/esm/geo/crs/EPSG4326.js +1 -1
  66. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  67. package/dist/esm/geo/crs/EarthCRS.js +2 -2
  68. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  69. package/dist/esm/geo/crs/SimpleCRS.js +1 -1
  70. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  71. package/dist/esm/geo/projection/Projection.LonLat.js +3 -3
  72. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
  73. package/dist/esm/geo/projection/Projection.Mercator.js +3 -3
  74. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
  75. package/dist/esm/geo/projection/Projection.SphericalMercator.js +3 -3
  76. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
  77. package/dist/esm/geometry/Bounds.js +19 -7
  78. package/dist/esm/geometry/Bounds.js.map +1 -1
  79. package/dist/esm/geometry/LineUtil.js +36 -30
  80. package/dist/esm/geometry/LineUtil.js.map +1 -1
  81. package/dist/esm/geometry/Point.js +23 -5
  82. package/dist/esm/geometry/Point.js.map +1 -1
  83. package/dist/esm/geometry/PolyUtil.js +9 -28
  84. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  85. package/dist/esm/layer/BlanketOverlay.js +6 -8
  86. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  87. package/dist/esm/layer/DivOverlay.js +15 -20
  88. package/dist/esm/layer/DivOverlay.js.map +1 -1
  89. package/dist/esm/layer/GeoJSON.js +9 -145
  90. package/dist/esm/layer/GeoJSON.js.map +1 -1
  91. package/dist/esm/layer/GeoJSONUtil.js +75 -0
  92. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  93. package/dist/esm/layer/HeatLayer.js +15 -17
  94. package/dist/esm/layer/HeatLayer.js.map +1 -1
  95. package/dist/esm/layer/ImageOverlay.js +20 -26
  96. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  97. package/dist/esm/layer/Layer.js +8 -10
  98. package/dist/esm/layer/Layer.js.map +1 -1
  99. package/dist/esm/layer/LayerGroup.js +51 -0
  100. package/dist/esm/layer/LayerGroup.js.map +1 -1
  101. package/dist/esm/layer/Popup.js +27 -43
  102. package/dist/esm/layer/Popup.js.map +1 -1
  103. package/dist/esm/layer/SVGOverlay.js +2 -5
  104. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  105. package/dist/esm/layer/Tooltip.js +15 -17
  106. package/dist/esm/layer/Tooltip.js.map +1 -1
  107. package/dist/esm/layer/VideoOverlay.js +12 -15
  108. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  109. package/dist/esm/layer/marker/DefaultIcon.js +15 -48
  110. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  111. package/dist/esm/layer/marker/DivIcon.js +8 -10
  112. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  113. package/dist/esm/layer/marker/Icon.js +9 -12
  114. package/dist/esm/layer/marker/Icon.js.map +1 -1
  115. package/dist/esm/layer/marker/Marker.Drag.js +1 -1
  116. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  117. package/dist/esm/layer/marker/Marker.Move.js +2 -3
  118. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  119. package/dist/esm/layer/marker/Marker.js +63 -35
  120. package/dist/esm/layer/marker/Marker.js.map +1 -1
  121. package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
  122. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  123. package/dist/esm/layer/marker/SvgIcon.js +6 -8
  124. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  125. package/dist/esm/layer/tile/GridLayer.js +86 -98
  126. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  127. package/dist/esm/layer/tile/TileLayer.js +28 -36
  128. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  129. package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
  130. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  131. package/dist/esm/layer/vector/Canvas.js +1 -3
  132. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  133. package/dist/esm/layer/vector/Circle.js +2 -2
  134. package/dist/esm/layer/vector/Circle.js.map +1 -1
  135. package/dist/esm/layer/vector/CircleMarker.js +17 -7
  136. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  137. package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
  138. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  139. package/dist/esm/layer/vector/Path.js +27 -20
  140. package/dist/esm/layer/vector/Path.js.map +1 -1
  141. package/dist/esm/layer/vector/Polygon.js +20 -4
  142. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  143. package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
  144. package/dist/esm/layer/vector/Polyline.js +24 -8
  145. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  146. package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
  147. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  148. package/dist/esm/layer/vector/SVG.js +5 -5
  149. package/dist/esm/layer/vector/SVG.js.map +1 -1
  150. package/dist/esm/map/Map.Rotation.js +15 -11
  151. package/dist/esm/map/Map.Rotation.js.map +1 -1
  152. package/dist/esm/map/Map.js +135 -129
  153. package/dist/esm/map/Map.js.map +1 -1
  154. package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
  155. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  156. package/dist/esm/map/handler/DisplaceHandler.js +6 -8
  157. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  158. package/dist/esm/map/handler/DragHandler.js +20 -20
  159. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  160. package/dist/esm/map/handler/KeyboardHandler.js +37 -37
  161. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  162. package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
  163. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  164. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
  165. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  166. package/dist/esm/map/handler/TapHoldHandler.js +12 -5
  167. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  168. package/dist/esm/package.js +1 -1
  169. package/dist/maplair-global-src.js +6326 -5625
  170. package/dist/maplair-global-src.js.map +1 -1
  171. package/dist/maplair-global.js +3 -3
  172. package/dist/maplair-global.js.map +1 -1
  173. package/dist/maplair-src.js +9010 -8290
  174. package/dist/maplair-src.js.map +1 -1
  175. package/dist/maplair.css +148 -98
  176. package/dist/maplair.js +3 -3
  177. package/dist/maplair.js.map +1 -1
  178. package/i18n/cs.json +6 -0
  179. package/i18n/de.json +6 -0
  180. package/i18n/en.json +6 -0
  181. package/i18n/es.json +6 -0
  182. package/i18n/fr.json +6 -0
  183. package/i18n/hu.json +6 -0
  184. package/i18n/it.json +6 -0
  185. package/i18n/rm.json +6 -0
  186. package/i18n/sk.json +6 -0
  187. package/i18n/sl.json +6 -0
  188. package/package.json +12 -14
  189. package/src/control/AttributionControl.js +25 -18
  190. package/src/control/ButtonControl.js +9 -11
  191. package/src/control/ContextMenu.js +3 -5
  192. package/src/control/Control.js +9 -19
  193. package/src/control/FullscreenControl.js +5 -7
  194. package/src/control/LayersControl.js +159 -36
  195. package/src/control/LegendControl.js +7 -9
  196. package/src/control/MiniMapControl.js +9 -11
  197. package/src/control/RotateControl.js +3 -5
  198. package/src/control/ScaleControl.js +7 -9
  199. package/src/control/SearchControl.js +104 -21
  200. package/src/control/SideBySideControl.js +3 -5
  201. package/src/control/TextControl.js +5 -7
  202. package/src/control/TimeControl.js +471 -0
  203. package/src/control/ZoomControl.js +5 -7
  204. package/src/control/index.js +1 -0
  205. package/src/core/Class.js +35 -34
  206. package/src/core/Events.js +22 -3
  207. package/src/core/Handler.js +14 -12
  208. package/src/core/Util.js +19 -1
  209. package/src/core/index.js +0 -1
  210. package/src/dom/DomEvent.DoubleTap.js +18 -10
  211. package/src/dom/DomEvent.PointerEvents.js +3 -26
  212. package/src/dom/DomEvent.js +8 -66
  213. package/src/dom/DomUtil.js +22 -78
  214. package/src/dom/Draggable.js +27 -22
  215. package/src/dom/PosAnimation.js +3 -25
  216. package/src/dom/index.js +0 -1
  217. package/src/geo/LatLng.js +40 -4
  218. package/src/geo/LatLngBounds.js +20 -7
  219. package/src/geo/crs/CRS.js +4 -3
  220. package/src/geo/crs/EPSG3395.js +1 -1
  221. package/src/geo/crs/EPSG3857.js +1 -1
  222. package/src/geo/crs/EPSG4326.js +1 -1
  223. package/src/geo/crs/EarthCRS.js +2 -8
  224. package/src/geo/crs/SimpleCRS.js +1 -1
  225. package/src/geo/projection/Projection.LonLat.js +3 -3
  226. package/src/geo/projection/Projection.Mercator.js +3 -3
  227. package/src/geo/projection/Projection.SphericalMercator.js +3 -3
  228. package/src/geometry/Bounds.js +20 -7
  229. package/src/geometry/LineUtil.js +47 -48
  230. package/src/geometry/Point.js +24 -5
  231. package/src/geometry/PolyUtil.js +15 -44
  232. package/src/layer/BlanketOverlay.js +6 -10
  233. package/src/layer/DivOverlay.js +15 -26
  234. package/src/layer/GeoJSON.js +7 -205
  235. package/src/layer/GeoJSONUtil.js +85 -0
  236. package/src/layer/HeatLayer.js +9 -11
  237. package/src/layer/ImageOverlay.js +19 -30
  238. package/src/layer/Layer.js +8 -10
  239. package/src/layer/LayerGroup.js +71 -0
  240. package/src/layer/Popup.js +31 -46
  241. package/src/layer/SVGOverlay.js +1 -5
  242. package/src/layer/Tooltip.js +15 -19
  243. package/src/layer/VideoOverlay.js +12 -15
  244. package/src/layer/marker/DefaultIcon.js +15 -61
  245. package/src/layer/marker/DivIcon.js +10 -12
  246. package/src/layer/marker/Icon.js +9 -12
  247. package/src/layer/marker/Marker.Drag.js +1 -1
  248. package/src/layer/marker/Marker.Move.js +2 -3
  249. package/src/layer/marker/Marker.js +83 -41
  250. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  251. package/src/layer/marker/SvgIcon.js +7 -9
  252. package/src/layer/marker/index.js +1 -0
  253. package/src/layer/tile/GridLayer.js +104 -134
  254. package/src/layer/tile/TileLayer.js +35 -43
  255. package/src/layer/tile/WMSTileLayer.js +26 -24
  256. package/src/layer/vector/Canvas.js +3 -5
  257. package/src/layer/vector/Circle.js +5 -2
  258. package/src/layer/vector/CircleMarker.js +17 -6
  259. package/src/layer/vector/Path.DashAnimation.js +1 -2
  260. package/src/layer/vector/Path.js +30 -21
  261. package/src/layer/vector/Polygon.js +28 -5
  262. package/src/layer/vector/Polyline.js +26 -7
  263. package/src/layer/vector/Renderer.getRenderer.js +17 -17
  264. package/src/layer/vector/SVG.js +5 -5
  265. package/src/map/Map.Rotation.js +19 -11
  266. package/src/map/Map.js +163 -154
  267. package/src/map/handler/BoxZoomHandler.js +9 -8
  268. package/src/map/handler/DisplaceHandler.js +6 -8
  269. package/src/map/handler/DragHandler.js +26 -29
  270. package/src/map/handler/KeyboardHandler.js +44 -50
  271. package/src/map/handler/PinchZoomHandler.js +16 -5
  272. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  273. package/src/map/handler/TapHoldHandler.js +15 -4
  274. package/src/map/index.js +1 -1
  275. package/src/maplair.css +148 -98
  276. package/dist/esm/core/Browser.js +0 -100
  277. package/dist/esm/core/Browser.js.map +0 -1
  278. package/dist/images/layers.svg +0 -1
  279. package/dist/images/marker-icon.svg +0 -1
  280. package/dist/images/marker-shadow.svg +0 -1
  281. package/src/core/Browser.js +0 -110
  282. package/src/images/layers.svg +0 -1
  283. package/src/images/marker-icon.svg +0 -1
  284. package/src/images/marker-shadow.svg +0 -1
@@ -60,6 +60,18 @@ var LatLngBounds = class LatLngBounds {
60
60
  for (const latlng of latlngs) this.extend(latlng);
61
61
  }
62
62
  /**
63
+ * Returns the given `LatLngBounds` object as it is, or else a new `LatLngBounds`
64
+ * object created from the given arguments (the same as of the constructor) — unlike
65
+ * the constructor, which always creates a new object.
66
+ * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the
67
+ * points or the bounds.
68
+ * @param {LatLngExpression} [corner2] The opposite corner.
69
+ * @returns {LatLngBounds}
70
+ */
71
+ static from(corner1, corner2) {
72
+ return corner1 instanceof LatLngBounds ? corner1 : new LatLngBounds(corner1, corner2);
73
+ }
74
+ /**
63
75
  * Extend the bounds to contain the given point or bounds.
64
76
  * @param {LatLngExpression|LatLngBoundsExpression} obj
65
77
  * @returns {this}
@@ -76,8 +88,8 @@ var LatLngBounds = class LatLngBounds {
76
88
  if (!sw2 || !ne2) return this;
77
89
  } else {
78
90
  if (!obj) return this;
79
- if (LatLng.validate(obj)) return this.extend(new LatLng(obj));
80
- return this.extend(new LatLngBounds(obj));
91
+ if (LatLng.validate(obj)) return this.extend(LatLng.from(obj));
92
+ return this.extend(LatLngBounds.from(obj));
81
93
  }
82
94
  if (!sw && !ne) {
83
95
  this._southWest = new LatLng(sw2.lat, sw2.lng);
@@ -170,8 +182,8 @@ var LatLngBounds = class LatLngBounds {
170
182
  * @returns {boolean}
171
183
  */
172
184
  contains(obj) {
173
- if (LatLng.validate(obj)) obj = new LatLng(obj);
174
- else obj = new LatLngBounds(obj);
185
+ if (LatLng.validate(obj)) obj = LatLng.from(obj);
186
+ else obj = LatLngBounds.from(obj);
175
187
  const sw = this._southWest, ne = this._northEast;
176
188
  let sw2, ne2;
177
189
  if (obj instanceof LatLngBounds) {
@@ -187,7 +199,7 @@ var LatLngBounds = class LatLngBounds {
187
199
  * @returns {boolean}
188
200
  */
189
201
  intersects(bounds) {
190
- bounds = new LatLngBounds(bounds);
202
+ bounds = LatLngBounds.from(bounds);
191
203
  const sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), ne2 = bounds.getNorthEast(), latIntersects = ne2.lat >= sw.lat && sw2.lat <= ne.lat, lngIntersects = ne2.lng >= sw.lng && sw2.lng <= ne.lng;
192
204
  return latIntersects && lngIntersects;
193
205
  }
@@ -198,7 +210,7 @@ var LatLngBounds = class LatLngBounds {
198
210
  * @returns {boolean}
199
211
  */
200
212
  overlaps(bounds) {
201
- bounds = new LatLngBounds(bounds);
213
+ bounds = LatLngBounds.from(bounds);
202
214
  const sw = this._southWest, ne = this._northEast, sw2 = bounds.getSouthWest(), ne2 = bounds.getNorthEast(), latOverlaps = ne2.lat > sw.lat && sw2.lat < ne.lat, lngOverlaps = ne2.lng > sw.lng && sw2.lng < ne.lng;
203
215
  return latOverlaps && lngOverlaps;
204
216
  }
@@ -226,7 +238,7 @@ var LatLngBounds = class LatLngBounds {
226
238
  */
227
239
  equals(bounds, maxMargin) {
228
240
  if (!bounds) return false;
229
- bounds = new LatLngBounds(bounds);
241
+ bounds = LatLngBounds.from(bounds);
230
242
  return this._southWest.equals(bounds.getSouthWest(), maxMargin) && this._northEast.equals(bounds.getNorthEast(), maxMargin);
231
243
  }
232
244
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"LatLngBounds.js","names":[],"sources":["../../../src/geo/LatLngBounds.js"],"sourcesContent":["import {LatLng} from './LatLng.js';\n/** @import {LatLngExpression} from './LatLng.js' */\n\n/**\n * A geographical area: a `LatLngBounds`, or an array of geographical points (usually\n * two diagonally opposite corners), e.g. `[[40.712, -74.227], [40.774, -74.125]]`.\n * Accepted by all Maplair methods which accept `LatLngBounds` objects (unless noted\n * otherwise).\n * @typedef {LatLngBounds|LatLngExpression[]} LatLngBoundsExpression\n */\n\n// TODO International date line?\n\n/**\n * Represents a rectangular geographical area on a map.\n *\n * @example\n * ```js\n * const corner1 = new LatLng(40.712, -74.227),\n * corner2 = new LatLng(40.774, -74.125),\n * bounds = new LatLngBounds(corner1, corner2);\n * ```\n *\n * All Maplair methods that accept LatLngBounds objects also accept them in a simple\n * Array form (unless noted otherwise), so the bounds example above can be passed like\n * this:\n *\n * ```js\n * map.fitBounds([\n * \t[40.712, -74.227],\n * \t[40.774, -74.125]\n * ]);\n * ```\n *\n * Caution: if the area crosses the antimeridian (often confused with the International\n * Date Line), you must specify corners _outside_ the [-180, 180] degrees longitude range.\n *\n * Note that `LatLngBounds` 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 LatLngBounds {\n\t/**\n\t * Creates a `LatLngBounds` object by defining two diagonally opposite corners of the\n\t * rectangle. Alternatively, creates a `LatLngBounds` object defined by the\n\t * geographical points it contains (very useful for zooming the map to fit a\n\t * particular set of locations with [`fitBounds`](#map-fitbounds)), or a copy of the\n\t * given `LatLngBounds` object.\n\t * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the\n\t * points or the bounds to copy.\n\t * @param {LatLngExpression} [corner2] The opposite corner.\n\t */\n\tconstructor(corner1, corner2) { // (LatLng, LatLng) or (LatLng[])\n\t\tif (!corner1) { return; }\n\n\t\tif (corner1 instanceof LatLngBounds) {\n\t\t\tif (corner1.isValid()) {\n\t\t\t\tthis._southWest = new LatLng(corner1._southWest);\n\t\t\t\tthis._northEast = new LatLng(corner1._northEast);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst latlngs = corner2 ? [corner1, corner2] : corner1;\n\n\t\tfor (const latlng of latlngs) {\n\t\t\tthis.extend(latlng);\n\t\t}\n\t}\n\n\t/**\n\t * Extend the bounds to contain the given point or bounds.\n\t * @param {LatLngExpression|LatLngBoundsExpression} obj\n\t * @returns {this}\n\t */\n\textend(obj) {\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast;\n\t\tlet sw2, ne2;\n\n\t\tif (obj instanceof LatLng) {\n\t\t\tsw2 = obj;\n\t\t\tne2 = obj;\n\n\t\t} else if (obj instanceof LatLngBounds) {\n\t\t\tsw2 = obj._southWest;\n\t\t\tne2 = obj._northEast;\n\n\t\t\tif (!sw2 || !ne2) { return this; }\n\n\t\t} else {\n\t\t\tif (!obj) {\n\t\t\t\treturn this;\n\t\t\t}\n\t\t\tif (LatLng.validate(obj)) {\n\t\t\t\treturn this.extend(new LatLng(obj));\n\t\t\t}\n\t\t\treturn this.extend(new LatLngBounds(obj));\n\t\t}\n\n\t\tif (!sw && !ne) {\n\t\t\tthis._southWest = new LatLng(sw2.lat, sw2.lng);\n\t\t\tthis._northEast = new LatLng(ne2.lat, ne2.lng);\n\t\t} else {\n\t\t\tsw.lat = Math.min(sw2.lat, sw.lat);\n\t\t\tsw.lng = Math.min(sw2.lng, sw.lng);\n\t\t\tne.lat = Math.max(ne2.lat, ne.lat);\n\t\t\tne.lng = Math.max(ne2.lng, ne.lng);\n\t\t}\n\n\t\treturn this;\n\t}\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 {LatLngBounds}\n\t */\n\tpad(bufferRatio) {\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\theightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio,\n\t\twidthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio;\n\n\t\treturn new LatLngBounds(\n\t\t\tnew LatLng(sw.lat - heightBuffer, sw.lng - widthBuffer),\n\t\t\tnew LatLng(ne.lat + heightBuffer, ne.lng + widthBuffer));\n\t}\n\n\t/**\n\t * Returns the center point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn new LatLng(\n\t\t\t(this._southWest.lat + this._northEast.lat) / 2,\n\t\t\t(this._southWest.lng + this._northEast.lng) / 2);\n\t}\n\n\t/**\n\t * Returns the south-west point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetSouthWest() {\n\t\treturn this._southWest;\n\t}\n\n\t/**\n\t * Returns the north-east point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetNorthEast() {\n\t\treturn this._northEast;\n\t}\n\n\t/**\n\t * Returns the north-west point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetNorthWest() {\n\t\treturn new LatLng(this.getNorth(), this.getWest());\n\t}\n\n\t/**\n\t * Returns the south-east point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetSouthEast() {\n\t\treturn new LatLng(this.getSouth(), this.getEast());\n\t}\n\n\t/**\n\t * Returns the west longitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetWest() {\n\t\treturn this._southWest.lng;\n\t}\n\n\t/**\n\t * Returns the south latitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetSouth() {\n\t\treturn this._southWest.lat;\n\t}\n\n\t/**\n\t * Returns the east longitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetEast() {\n\t\treturn this._northEast.lng;\n\t}\n\n\t/**\n\t * Returns the north latitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetNorth() {\n\t\treturn this._northEast.lat;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {LatLngBoundsExpression|LatLngExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) { // (LatLngBounds) or (LatLng) -> Boolean\n\t\tif (LatLng.validate(obj)) {\n\t\t\tobj = new LatLng(obj);\n\t\t} else {\n\t\t\tobj = new LatLngBounds(obj);\n\t\t}\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast;\n\t\tlet sw2, ne2;\n\n\t\tif (obj instanceof LatLngBounds) {\n\t\t\tsw2 = obj.getSouthWest();\n\t\t\tne2 = obj.getNorthEast();\n\t\t} else {\n\t\t\tsw2 = ne2 = obj;\n\t\t}\n\n\t\treturn (sw2.lat >= sw.lat) && (ne2.lat <= ne.lat) &&\n\t\t (sw2.lng >= sw.lng) && (ne2.lng <= ne.lng);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle intersects the given bounds. Two bounds intersect\n\t * if they have at least one point in common.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) {\n\t\tbounds = new LatLngBounds(bounds);\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\tsw2 = bounds.getSouthWest(),\n\t\tne2 = bounds.getNorthEast(),\n\n\t\tlatIntersects = (ne2.lat >= sw.lat) && (sw2.lat <= ne.lat),\n\t\tlngIntersects = (ne2.lng >= sw.lng) && (sw2.lng <= ne.lng);\n\n\t\treturn latIntersects && lngIntersects;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds overlap if\n\t * their intersection is an area.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) {\n\t\tbounds = new LatLngBounds(bounds);\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\tsw2 = bounds.getSouthWest(),\n\t\tne2 = bounds.getNorthEast(),\n\n\t\tlatOverlaps = (ne2.lat > sw.lat) && (sw2.lat < ne.lat),\n\t\tlngOverlaps = (ne2.lng > sw.lng) && (sw2.lng < ne.lng);\n\n\t\treturn latOverlaps && lngOverlaps;\n\t}\n\n\t/**\n\t * Returns a string with bounding box coordinates in a\n\t * 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for\n\t * sending requests to web services that return geo data.\n\t * @returns {string}\n\t */\n\ttoBBoxString() {\n\t\treturn [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',');\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle is equivalent (within a small margin of error) to\n\t * the given bounds. The margin of error can be overridden by setting `maxMargin` to\n\t * a small number.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {number} [maxMargin]\n\t * @returns {boolean}\n\t */\n\tequals(bounds, maxMargin) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = new LatLngBounds(bounds);\n\n\t\treturn this._southWest.equals(bounds.getSouthWest(), maxMargin) &&\n\t\t this._northEast.equals(bounds.getNorthEast(), maxMargin);\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._southWest && this._northEast);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,eAAb,MAAa,aAAa;;;;;;;;;;;CAWzB,YAAY,SAAS,SAAS;EAC7B,IAAI,CAAC,SAAW;EAEhB,IAAI,mBAAmB,cAAc;GACpC,IAAI,QAAQ,QAAQ,GAAG;IACtB,KAAK,aAAa,IAAI,OAAO,QAAQ,UAAU;IAC/C,KAAK,aAAa,IAAI,OAAO,QAAQ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iB;CACzB;;;;;;;CAQA,SAAS,QAAQ;EAChB,SAAS,IAAI,aAAa,MAAM;EAEhC,MAAM,KAAK,KAAK,YAChB,KAAK,KAAK,YACV,MAAM,OAAO,aAAa,GAC1B,MAAM,OAAO,aAAa,GAE1B,cAAe,IAAI,MAAM,GAAG,OAAS,IAAI,MAAM,GAAG,KAClD,cAAe,IAAI,MAAM,GAAG,OAAS,IAAI,MAAM,GAAG;EAElD,OAAO,eAAe;CACvB;;;;;;;CAQA,eAAe;EACd,OAAO;GAAC,KAAK,QAAQ;GAAG,KAAK,SAAS;GAAG,KAAK,QAAQ;GAAG,KAAK,SAAS;EAAC,CAAC,CAAC,KAAK,GAAG;CACnF;;;;;;;;;CAUA,OAAO,QAAQ,WAAW;EACzB,IAAI,CAAC,QAAU,OAAO;EAEtB,SAAS,IAAI,aAAa,MAAM;EAEhC,OAAO,KAAK,WAAW,OAAO,OAAO,aAAa,GAAG,SAAS,KACvD,KAAK,WAAW,OAAO,OAAO,aAAa,GAAG,SAAS;CAC/D;;;;;CAMA,UAAU;EACT,OAAO,CAAC,EAAE,KAAK,cAAc,KAAK;CACnC;AACD"}
1
+ {"version":3,"file":"LatLngBounds.js","names":[],"sources":["../../../src/geo/LatLngBounds.js"],"sourcesContent":["import {LatLng} from './LatLng.js';\n/** @import {LatLngExpression} from './LatLng.js' */\n\n/**\n * A geographical area: a `LatLngBounds`, or an array of geographical points (usually\n * two diagonally opposite corners), e.g. `[[40.712, -74.227], [40.774, -74.125]]`.\n * Accepted by all Maplair methods which accept `LatLngBounds` objects (unless noted\n * otherwise).\n * @typedef {LatLngBounds|LatLngExpression[]} LatLngBoundsExpression\n */\n\n// TODO International date line?\n\n/**\n * Represents a rectangular geographical area on a map.\n *\n * @example\n * ```js\n * const corner1 = new LatLng(40.712, -74.227),\n * corner2 = new LatLng(40.774, -74.125),\n * bounds = new LatLngBounds(corner1, corner2);\n * ```\n *\n * All Maplair methods that accept LatLngBounds objects also accept them in a simple\n * Array form (unless noted otherwise), so the bounds example above can be passed like\n * this:\n *\n * ```js\n * map.fitBounds([\n * \t[40.712, -74.227],\n * \t[40.774, -74.125]\n * ]);\n * ```\n *\n * Caution: if the area crosses the antimeridian (often confused with the International\n * Date Line), you must specify corners _outside_ the [-180, 180] degrees longitude range.\n *\n * Note that `LatLngBounds` 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 LatLngBounds {\n\t/**\n\t * Creates a `LatLngBounds` object by defining two diagonally opposite corners of the\n\t * rectangle. Alternatively, creates a `LatLngBounds` object defined by the\n\t * geographical points it contains (very useful for zooming the map to fit a\n\t * particular set of locations with [`fitBounds`](#map-fitbounds)), or a copy of the\n\t * given `LatLngBounds` object.\n\t * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the\n\t * points or the bounds to copy.\n\t * @param {LatLngExpression} [corner2] The opposite corner.\n\t */\n\tconstructor(corner1, corner2) { // (LatLng, LatLng) or (LatLng[])\n\t\tif (!corner1) { return; }\n\n\t\tif (corner1 instanceof LatLngBounds) {\n\t\t\tif (corner1.isValid()) {\n\t\t\t\tthis._southWest = new LatLng(corner1._southWest);\n\t\t\t\tthis._northEast = new LatLng(corner1._northEast);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst latlngs = corner2 ? [corner1, corner2] : corner1;\n\n\t\tfor (const latlng of latlngs) {\n\t\t\tthis.extend(latlng);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the given `LatLngBounds` object as it is, or else a new `LatLngBounds`\n\t * object created from the given arguments (the same as of the constructor) — unlike\n\t * the constructor, which always creates a new object.\n\t * @param {LatLngExpression|LatLngBoundsExpression} [corner1] The first corner, the\n\t * points or the bounds.\n\t * @param {LatLngExpression} [corner2] The opposite corner.\n\t * @returns {LatLngBounds}\n\t */\n\tstatic from(corner1, corner2) {\n\t\treturn corner1 instanceof LatLngBounds ? corner1 : new LatLngBounds(corner1, corner2);\n\t}\n\n\t/**\n\t * Extend the bounds to contain the given point or bounds.\n\t * @param {LatLngExpression|LatLngBoundsExpression} obj\n\t * @returns {this}\n\t */\n\textend(obj) {\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast;\n\t\tlet sw2, ne2;\n\n\t\tif (obj instanceof LatLng) {\n\t\t\tsw2 = obj;\n\t\t\tne2 = obj;\n\n\t\t} else if (obj instanceof LatLngBounds) {\n\t\t\tsw2 = obj._southWest;\n\t\t\tne2 = obj._northEast;\n\n\t\t\tif (!sw2 || !ne2) { return this; }\n\n\t\t} else {\n\t\t\tif (!obj) {\n\t\t\t\treturn this;\n\t\t\t}\n\t\t\tif (LatLng.validate(obj)) {\n\t\t\t\treturn this.extend(LatLng.from(obj));\n\t\t\t}\n\t\t\treturn this.extend(LatLngBounds.from(obj));\n\t\t}\n\n\t\tif (!sw && !ne) {\n\t\t\tthis._southWest = new LatLng(sw2.lat, sw2.lng);\n\t\t\tthis._northEast = new LatLng(ne2.lat, ne2.lng);\n\t\t} else {\n\t\t\tsw.lat = Math.min(sw2.lat, sw.lat);\n\t\t\tsw.lng = Math.min(sw2.lng, sw.lng);\n\t\t\tne.lat = Math.max(ne2.lat, ne.lat);\n\t\t\tne.lng = Math.max(ne2.lng, ne.lng);\n\t\t}\n\n\t\treturn this;\n\t}\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 {LatLngBounds}\n\t */\n\tpad(bufferRatio) {\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\theightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio,\n\t\twidthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio;\n\n\t\treturn new LatLngBounds(\n\t\t\tnew LatLng(sw.lat - heightBuffer, sw.lng - widthBuffer),\n\t\t\tnew LatLng(ne.lat + heightBuffer, ne.lng + widthBuffer));\n\t}\n\n\t/**\n\t * Returns the center point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn new LatLng(\n\t\t\t(this._southWest.lat + this._northEast.lat) / 2,\n\t\t\t(this._southWest.lng + this._northEast.lng) / 2);\n\t}\n\n\t/**\n\t * Returns the south-west point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetSouthWest() {\n\t\treturn this._southWest;\n\t}\n\n\t/**\n\t * Returns the north-east point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetNorthEast() {\n\t\treturn this._northEast;\n\t}\n\n\t/**\n\t * Returns the north-west point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetNorthWest() {\n\t\treturn new LatLng(this.getNorth(), this.getWest());\n\t}\n\n\t/**\n\t * Returns the south-east point of the bounds.\n\t * @returns {LatLng}\n\t */\n\tgetSouthEast() {\n\t\treturn new LatLng(this.getSouth(), this.getEast());\n\t}\n\n\t/**\n\t * Returns the west longitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetWest() {\n\t\treturn this._southWest.lng;\n\t}\n\n\t/**\n\t * Returns the south latitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetSouth() {\n\t\treturn this._southWest.lat;\n\t}\n\n\t/**\n\t * Returns the east longitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetEast() {\n\t\treturn this._northEast.lng;\n\t}\n\n\t/**\n\t * Returns the north latitude of the bounds.\n\t * @returns {number}\n\t */\n\tgetNorth() {\n\t\treturn this._northEast.lat;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle contains the given bounds or point.\n\t * @param {LatLngBoundsExpression|LatLngExpression} obj\n\t * @returns {boolean}\n\t */\n\tcontains(obj) { // (LatLngBounds) or (LatLng) -> Boolean\n\t\tif (LatLng.validate(obj)) {\n\t\t\tobj = LatLng.from(obj);\n\t\t} else {\n\t\t\tobj = LatLngBounds.from(obj);\n\t\t}\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast;\n\t\tlet sw2, ne2;\n\n\t\tif (obj instanceof LatLngBounds) {\n\t\t\tsw2 = obj.getSouthWest();\n\t\t\tne2 = obj.getNorthEast();\n\t\t} else {\n\t\t\tsw2 = ne2 = obj;\n\t\t}\n\n\t\treturn (sw2.lat >= sw.lat) && (ne2.lat <= ne.lat) &&\n\t\t (sw2.lng >= sw.lng) && (ne2.lng <= ne.lng);\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle intersects the given bounds. Two bounds intersect\n\t * if they have at least one point in common.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\tintersects(bounds) {\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\tsw2 = bounds.getSouthWest(),\n\t\tne2 = bounds.getNorthEast(),\n\n\t\tlatIntersects = (ne2.lat >= sw.lat) && (sw2.lat <= ne.lat),\n\t\tlngIntersects = (ne2.lng >= sw.lng) && (sw2.lng <= ne.lng);\n\n\t\treturn latIntersects && lngIntersects;\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle overlaps the given bounds. Two bounds overlap if\n\t * their intersection is an area.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {boolean}\n\t */\n\toverlaps(bounds) {\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\tconst sw = this._southWest,\n\t\tne = this._northEast,\n\t\tsw2 = bounds.getSouthWest(),\n\t\tne2 = bounds.getNorthEast(),\n\n\t\tlatOverlaps = (ne2.lat > sw.lat) && (sw2.lat < ne.lat),\n\t\tlngOverlaps = (ne2.lng > sw.lng) && (sw2.lng < ne.lng);\n\n\t\treturn latOverlaps && lngOverlaps;\n\t}\n\n\t/**\n\t * Returns a string with bounding box coordinates in a\n\t * 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for\n\t * sending requests to web services that return geo data.\n\t * @returns {string}\n\t */\n\ttoBBoxString() {\n\t\treturn [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',');\n\t}\n\n\t/**\n\t * Returns `true` if the rectangle is equivalent (within a small margin of error) to\n\t * the given bounds. The margin of error can be overridden by setting `maxMargin` to\n\t * a small number.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {number} [maxMargin]\n\t * @returns {boolean}\n\t */\n\tequals(bounds, maxMargin) {\n\t\tif (!bounds) { return false; }\n\n\t\tbounds = LatLngBounds.from(bounds);\n\n\t\treturn this._southWest.equals(bounds.getSouthWest(), maxMargin) &&\n\t\t this._northEast.equals(bounds.getNorthEast(), maxMargin);\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._southWest && this._northEast);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,eAAb,MAAa,aAAa;;;;;;;;;;;CAWzB,YAAY,SAAS,SAAS;EAC7B,IAAI,CAAC,SAAW;EAEhB,IAAI,mBAAmB,cAAc;GACpC,IAAI,QAAQ,QAAQ,GAAG;IACtB,KAAK,aAAa,IAAI,OAAO,QAAQ,UAAU;IAC/C,KAAK,aAAa,IAAI,OAAO,QAAQ,UAAU;GAChD;GACA;EACD;EAEA,MAAM,UAAU,UAAU,CAAC,SAAS,OAAO,IAAI;EAE/C,KAAK,MAAM,UAAU,SACpB,KAAK,OAAO,MAAM;CAEpB;;;;;;;;;;CAWA,OAAO,KAAK,SAAS,SAAS;EAC7B,OAAO,mBAAmB,eAAe,UAAU,IAAI,aAAa,SAAS,OAAO;CACrF;;;;;;CAOA,OAAO,KAAK;EACX,MAAM,KAAK,KAAK,YAChB,KAAK,KAAK;EACV,IAAI,KAAK;EAET,IAAI,eAAe,QAAQ;GAC1B,MAAM;GACN,MAAM;EAEP,OAAO,IAAI,eAAe,cAAc;GACvC,MAAM,IAAI;GACV,MAAM,IAAI;GAEV,IAAI,CAAC,OAAO,CAAC,KAAO,OAAO;EAE5B,OAAO;GACN,IAAI,CAAC,KACJ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AC,CAAC,CAAC,KAAK,GAAG;CACnF;;;;;;;;;CAUA,OAAO,QAAQ,WAAW;EACzB,IAAI,CAAC,QAAU,OAAO;EAEtB,SAAS,aAAa,KAAK,MAAM;EAEjC,OAAO,KAAK,WAAW,OAAO,OAAO,aAAa,GAAG,SAAS,KACvD,KAAK,WAAW,OAAO,OAAO,aAAa,GAAG,SAAS;CAC/D;;;;;CAMA,UAAU;EACT,OAAO,CAAC,EAAE,KAAK,cAAc,KAAK;CACnC;AACD"}
@@ -16,8 +16,9 @@ import { LatLng } from "../LatLng.js";
16
16
  * [spatial reference system](https://en.wikipedia.org/wiki/Spatial_reference_system).
17
17
  *
18
18
  * Maplair defines the most usual CRSs by default. If you want to use a
19
- * CRS not defined by default, take a look at the
20
- * [Proj4Maplair](https://github.com/kartena/Proj4Leaflet) plugin.
19
+ * CRS not defined by default, extend `CRS` with a projection of your own, e.g.
20
+ * based on [Proj4js](https://github.com/proj4js/proj4js) (the Leaflet plugin
21
+ * [Proj4Leaflet](https://github.com/kartena/Proj4Leaflet) doesn't work with Maplair).
21
22
  *
22
23
  * The CRSs are classes with static properties and methods only; they are not
23
24
  * instantiated, the class itself is passed as the CRS, e.g. to the `crs` option of the
@@ -127,7 +128,7 @@ var CRS = class {
127
128
  * @returns {LatLng}
128
129
  */
129
130
  static wrapLatLng(latlng) {
130
- latlng = new LatLng(latlng);
131
+ latlng = LatLng.from(latlng);
131
132
  const lng = this.wrapLng ? wrapNum(latlng.lng, this.wrapLng, true) : latlng.lng, lat = this.wrapLat ? wrapNum(latlng.lat, this.wrapLat, true) : latlng.lat, alt = latlng.alt;
132
133
  return new LatLng(lat, lng, alt);
133
134
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CRS.js","names":["Util.wrapNum"],"sources":["../../../../src/geo/crs/CRS.js"],"sourcesContent":["\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {LatLng} from '../LatLng.js';\nimport {LatLngBounds} from '../LatLngBounds.js';\nimport * as Util from '../../core/Util.js';\n/** @import {LatLngExpression} from '../LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../LatLngBounds.js' */\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {Transformation} from '../../geometry/Transformation.js' */\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * Object that defines coordinate reference systems for projecting\n * geographical points into pixel (screen) coordinates and back (and to\n * coordinates in other units for [WMS](https://en.wikipedia.org/wiki/Web_Map_Service)\n * services). See\n * [spatial reference system](https://en.wikipedia.org/wiki/Spatial_reference_system).\n *\n * Maplair defines the most usual CRSs by default. If you want to use a\n * CRS not defined by default, take a look at the\n * [Proj4Maplair](https://github.com/kartena/Proj4Leaflet) plugin.\n *\n * The CRSs are classes with static properties and methods only; they are not\n * instantiated, the class itself is passed as the CRS, e.g. to the `crs` option of the\n * map. Maplair's CRSs extend `CRS` (`EarthCRS` for the global ones).\n *\n * Besides the properties and methods below, a CRS may define:\n *\n * * `code: string`: Standard code name of the CRS passed into WMS services (e.g.\n * `'EPSG:3857'`).\n * * `wrapLng: [number, number]`: An array of two numbers defining whether the longitude\n * (horizontal) coordinate axis wraps around a given range and how. Defaults to\n * `[-180, 180]` in most geographical CRSs. If `undefined`, the longitude axis does\n * not wrap around.\n * * `wrapLat: [number, number]`: Like `wrapLng`, but for the latitude (vertical) axis.\n * * `distance(latlng1: LatLng, latlng2: LatLng): number`: Returns the distance between\n * two geographical coordinates.\n */\nexport class CRS {\n\t/**\n\t * The projection of the CRS.\n\t * @type {Projection|undefined}\n\t */\n\tstatic projection = undefined;\n\t/**\n\t * The transformation of projected coordinates into pixel coordinates at zoom 0.\n\t * @type {Transformation|undefined}\n\t */\n\tstatic transformation = undefined;\n\n\t/**\n\t * Projects geographical coordinates into pixel coordinates for a given zoom.\n\t * @param {LatLngExpression} latlng\n\t * @param {number} zoom\n\t * @returns {Point}\n\t */\n\tstatic latLngToPoint(latlng, zoom) {\n\t\tconst projectedPoint = this.projection.project(latlng),\n\t\tscale = this.scale(zoom);\n\n\t\treturn this.transformation._transform(projectedPoint, scale);\n\t}\n\n\t/**\n\t * The inverse of `latLngToPoint`. Projects pixel coordinates on a given\n\t * zoom into geographical coordinates.\n\t * @param {Point} point\n\t * @param {number} zoom\n\t * @returns {LatLng}\n\t */\n\tstatic pointToLatLng(point, zoom) {\n\t\tconst scale = this.scale(zoom),\n\t\tuntransformedPoint = this.transformation.untransform(point, scale);\n\n\t\treturn this.projection.unproject(untransformedPoint);\n\t}\n\n\t/**\n\t * Projects geographical coordinates into coordinates in units accepted for\n\t * this CRS (e.g. meters for EPSG:3857, for passing it to WMS services).\n\t * @param {LatLngExpression} latlng\n\t * @returns {Point}\n\t */\n\tstatic project(latlng) {\n\t\treturn this.projection.project(latlng);\n\t}\n\n\t/**\n\t * Given a projected coordinate returns the corresponding LatLng.\n\t * The inverse of `project`.\n\t * @param {Point} point\n\t * @returns {LatLng}\n\t */\n\tstatic unproject(point) {\n\t\treturn this.projection.unproject(point);\n\t}\n\n\t/**\n\t * Returns the scale used when transforming projected coordinates into\n\t * pixel coordinates for a particular zoom. For example, it returns\n\t * `256 * 2^zoom` for Mercator-based CRS.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\tstatic scale(zoom) {\n\t\treturn 256 * 2 ** zoom;\n\t}\n\n\t/**\n\t * Inverse of `scale()`, returns the zoom level corresponding to a scale\n\t * factor of `scale`.\n\t * @param {number} scale\n\t * @returns {number}\n\t */\n\tstatic zoom(scale) {\n\t\treturn Math.log(scale / 256) / Math.LN2;\n\t}\n\n\t/**\n\t * Returns the projection's bounds scaled and transformed for the provided `zoom`\n\t * (`null` if the CRS is `infinite`).\n\t * @param {number} zoom\n\t * @returns {Bounds|null}\n\t */\n\tstatic getProjectedBounds(zoom) {\n\t\tif (this.infinite) { return null; }\n\n\t\tconst b = this.projection.bounds,\n\t\ts = this.scale(zoom),\n\t\tmin = this.transformation.transform(b.min, s),\n\t\tmax = this.transformation.transform(b.max, s);\n\n\t\treturn new Bounds(min, max);\n\t}\n\n\t/**\n\t * If true, the coordinate space will be unbounded (infinite in both axes).\n\t * @type {boolean}\n\t */\n\tstatic infinite = false;\n\n\t/**\n\t * Returns a `LatLng` where lat and lng has been wrapped according to the\n\t * CRS's `wrapLat` and `wrapLng` properties, if they are outside the CRS's bounds.\n\t * @param {LatLngExpression} latlng\n\t * @returns {LatLng}\n\t */\n\tstatic wrapLatLng(latlng) {\n\t\tlatlng = new LatLng(latlng);\n\t\tconst lng = this.wrapLng ? Util.wrapNum(latlng.lng, this.wrapLng, true) : latlng.lng,\n\t\tlat = this.wrapLat ? Util.wrapNum(latlng.lat, this.wrapLat, true) : latlng.lat,\n\t\talt = latlng.alt;\n\n\t\treturn new LatLng(lat, lng, alt);\n\t}\n\n\t/**\n\t * Returns a `LatLngBounds` with the same size as the given one, ensuring\n\t * that its center is within the CRS's bounds.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {LatLngBounds}\n\t */\n\tstatic wrapLatLngBounds(bounds) {\n\t\tbounds = new LatLngBounds(bounds);\n\t\tconst center = bounds.getCenter(),\n\t\tnewCenter = this.wrapLatLng(center),\n\t\tlatShift = center.lat - newCenter.lat,\n\t\tlngShift = center.lng - newCenter.lng;\n\n\t\tif (latShift === 0 && lngShift === 0) {\n\t\t\treturn bounds;\n\t\t}\n\n\t\tconst sw = bounds.getSouthWest(),\n\t\tne = bounds.getNorthEast(),\n\t\tnewSw = new LatLng(sw.lat - latShift, sw.lng - lngShift),\n\t\tnewNe = new LatLng(ne.lat - latShift, ne.lng - lngShift);\n\n\t\treturn new LatLngBounds(newSw, newNe);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAa,MAAb,MAAiB;;;;;CAKhB,OAAO,aAAa,KAAA;;;;;CAKpB,OAAO,iBAAiB,KAAA;;;;;;;CAQxB,OAAO,cAAc,QAAQ,MAAM;EAClC,MAAM,iBAAiB,KAAK,WAAW,QAAQ,MAAM,GACrD,QAAQ,KAA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AM,GAClC,WAAW,OAAO,MAAM,UAAU,KAClC,WAAW,OAAO,MAAM,UAAU;EAElC,IAAI,aAAa,KAAK,aAAa,GAClC,OAAO;EAGR,MAAM,KAAK,OAAO,aAAa,GAC/B,KAAK,OAAO,aAAa,GACzB,QAAQ,IAAI,OAAO,GAAG,MAAM,UAAU,GAAG,MAAM,QAAQ,GACvD,QAAQ,IAAI,OAAO,GAAG,MAAM,UAAU,GAAG,MAAM,QAAQ;EAEvD,OAAO,IAAI,aAAa,OAAO,KAAK;CACrC;AACD"}
1
+ {"version":3,"file":"CRS.js","names":["Util.wrapNum"],"sources":["../../../../src/geo/crs/CRS.js"],"sourcesContent":["\nimport {Bounds} from '../../geometry/Bounds.js';\nimport {LatLng} from '../LatLng.js';\nimport {LatLngBounds} from '../LatLngBounds.js';\nimport * as Util from '../../core/Util.js';\n/** @import {LatLngExpression} from '../LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../LatLngBounds.js' */\n/** @import {Point} from '../../geometry/Point.js' */\n/** @import {Transformation} from '../../geometry/Transformation.js' */\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * Object that defines coordinate reference systems for projecting\n * geographical points into pixel (screen) coordinates and back (and to\n * coordinates in other units for [WMS](https://en.wikipedia.org/wiki/Web_Map_Service)\n * services). See\n * [spatial reference system](https://en.wikipedia.org/wiki/Spatial_reference_system).\n *\n * Maplair defines the most usual CRSs by default. If you want to use a\n * CRS not defined by default, extend `CRS` with a projection of your own, e.g.\n * based on [Proj4js](https://github.com/proj4js/proj4js) (the Leaflet plugin\n * [Proj4Leaflet](https://github.com/kartena/Proj4Leaflet) doesn't work with Maplair).\n *\n * The CRSs are classes with static properties and methods only; they are not\n * instantiated, the class itself is passed as the CRS, e.g. to the `crs` option of the\n * map. Maplair's CRSs extend `CRS` (`EarthCRS` for the global ones).\n *\n * Besides the properties and methods below, a CRS may define:\n *\n * * `code: string`: Standard code name of the CRS passed into WMS services (e.g.\n * `'EPSG:3857'`).\n * * `wrapLng: [number, number]`: An array of two numbers defining whether the longitude\n * (horizontal) coordinate axis wraps around a given range and how. Defaults to\n * `[-180, 180]` in most geographical CRSs. If `undefined`, the longitude axis does\n * not wrap around.\n * * `wrapLat: [number, number]`: Like `wrapLng`, but for the latitude (vertical) axis.\n * * `distance(latlng1: LatLng, latlng2: LatLng): number`: Returns the distance between\n * two geographical coordinates.\n */\nexport class CRS {\n\t/**\n\t * The projection of the CRS.\n\t * @type {Projection|undefined}\n\t */\n\tstatic projection = undefined;\n\t/**\n\t * The transformation of projected coordinates into pixel coordinates at zoom 0.\n\t * @type {Transformation|undefined}\n\t */\n\tstatic transformation = undefined;\n\n\t/**\n\t * Projects geographical coordinates into pixel coordinates for a given zoom.\n\t * @param {LatLngExpression} latlng\n\t * @param {number} zoom\n\t * @returns {Point}\n\t */\n\tstatic latLngToPoint(latlng, zoom) {\n\t\tconst projectedPoint = this.projection.project(latlng),\n\t\tscale = this.scale(zoom);\n\n\t\treturn this.transformation._transform(projectedPoint, scale);\n\t}\n\n\t/**\n\t * The inverse of `latLngToPoint`. Projects pixel coordinates on a given\n\t * zoom into geographical coordinates.\n\t * @param {Point} point\n\t * @param {number} zoom\n\t * @returns {LatLng}\n\t */\n\tstatic pointToLatLng(point, zoom) {\n\t\tconst scale = this.scale(zoom),\n\t\tuntransformedPoint = this.transformation.untransform(point, scale);\n\n\t\treturn this.projection.unproject(untransformedPoint);\n\t}\n\n\t/**\n\t * Projects geographical coordinates into coordinates in units accepted for\n\t * this CRS (e.g. meters for EPSG:3857, for passing it to WMS services).\n\t * @param {LatLngExpression} latlng\n\t * @returns {Point}\n\t */\n\tstatic project(latlng) {\n\t\treturn this.projection.project(latlng);\n\t}\n\n\t/**\n\t * Given a projected coordinate returns the corresponding LatLng.\n\t * The inverse of `project`.\n\t * @param {Point} point\n\t * @returns {LatLng}\n\t */\n\tstatic unproject(point) {\n\t\treturn this.projection.unproject(point);\n\t}\n\n\t/**\n\t * Returns the scale used when transforming projected coordinates into\n\t * pixel coordinates for a particular zoom. For example, it returns\n\t * `256 * 2^zoom` for Mercator-based CRS.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\tstatic scale(zoom) {\n\t\treturn 256 * 2 ** zoom;\n\t}\n\n\t/**\n\t * Inverse of `scale()`, returns the zoom level corresponding to a scale\n\t * factor of `scale`.\n\t * @param {number} scale\n\t * @returns {number}\n\t */\n\tstatic zoom(scale) {\n\t\treturn Math.log(scale / 256) / Math.LN2;\n\t}\n\n\t/**\n\t * Returns the projection's bounds scaled and transformed for the provided `zoom`\n\t * (`null` if the CRS is `infinite`).\n\t * @param {number} zoom\n\t * @returns {Bounds|null}\n\t */\n\tstatic getProjectedBounds(zoom) {\n\t\tif (this.infinite) { return null; }\n\n\t\tconst b = this.projection.bounds,\n\t\ts = this.scale(zoom),\n\t\tmin = this.transformation.transform(b.min, s),\n\t\tmax = this.transformation.transform(b.max, s);\n\n\t\treturn new Bounds(min, max);\n\t}\n\n\t/**\n\t * If true, the coordinate space will be unbounded (infinite in both axes).\n\t * @type {boolean}\n\t */\n\tstatic infinite = false;\n\n\t/**\n\t * Returns a `LatLng` where lat and lng has been wrapped according to the\n\t * CRS's `wrapLat` and `wrapLng` properties, if they are outside the CRS's bounds.\n\t * @param {LatLngExpression} latlng\n\t * @returns {LatLng}\n\t */\n\tstatic wrapLatLng(latlng) {\n\t\tlatlng = LatLng.from(latlng);\n\t\tconst lng = this.wrapLng ? Util.wrapNum(latlng.lng, this.wrapLng, true) : latlng.lng,\n\t\tlat = this.wrapLat ? Util.wrapNum(latlng.lat, this.wrapLat, true) : latlng.lat,\n\t\talt = latlng.alt;\n\n\t\treturn new LatLng(lat, lng, alt);\n\t}\n\n\t/**\n\t * Returns a `LatLngBounds` with the same size as the given one, ensuring\n\t * that its center is within the CRS's bounds.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {LatLngBounds}\n\t */\n\tstatic wrapLatLngBounds(bounds) {\n\t\tbounds = new LatLngBounds(bounds);\n\t\tconst center = bounds.getCenter(),\n\t\tnewCenter = this.wrapLatLng(center),\n\t\tlatShift = center.lat - newCenter.lat,\n\t\tlngShift = center.lng - newCenter.lng;\n\n\t\tif (latShift === 0 && lngShift === 0) {\n\t\t\treturn bounds;\n\t\t}\n\n\t\tconst sw = bounds.getSouthWest(),\n\t\tne = bounds.getNorthEast(),\n\t\tnewSw = new LatLng(sw.lat - latShift, sw.lng - lngShift),\n\t\tnewNe = new LatLng(ne.lat - latShift, ne.lng - lngShift);\n\n\t\treturn new LatLngBounds(newSw, newNe);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,MAAb,MAAiB;;;;;CAKhB,OAAO,aAAa,KAAA;;;;;CAKpB,OAAO,iBAAiB,KAAA;;;;;;;CAQxB,OAAO,cAAc,QAAQ,MAAM;EAClC,MAAM,iBAAiB,KAAK,WAAW,QAAQ,MAAM,GACrD,QAAQ,KAAK,MAAM,IAAI;EAEvB,OAAO,KAAK,eAAe,WAAW,gBAAgB,KAAK;CAC5D;;;;;;;;CASA,OAAO,cAAc,OAAO,MAAM;EACjC,MAAM,QAAQ,KAAK,MAAM,IAAI,GAC7B,qBAAqB,KAAK,eAAe,YAAY,OAAO,KAAK;EAEjE,OAAO,KAAK,WAAW,UAAU,kBAAkB;CACpD;;;;;;;CAQA,OAAO,QAAQ,QAAQ;EACtB,OAAO,KAAK,WAAW,QAAQ,MAAM;CACtC;;;;;;;CAQA,OAAO,UAAU,OAAO;EACvB,OAAO,KAAK,WAAW,UAAU,KAAK;CACvC;;;;;;;;CASA,OAAO,MAAM,MAAM;EAClB,OAAO,MAAM,KAAK;CACnB;;;;;;;CAQA,OAAO,KAAK,OAAO;EAClB,OAAO,KAAK,IAAI,QAAQ,GAAG,IAAI,KAAK;CACrC;;;;;;;CAQA,OAAO,mBAAmB,MAAM;EAC/B,IAAI,KAAK,UAAY,OAAO;EAE5B,MAAM,IAAI,KAAK,WAAW,QAC1B,IAAI,KAAK,MAAM,IAAI,GACnB,MAAM,KAAK,eAAe,UAAU,EAAE,KAAK,CAAC,GAC5C,MAAM,KAAK,eAAe,UAAU,EAAE,KAAK,CAAC;EAE5C,OAAO,IAAI,OAAO,KAAK,GAAG;CAC3B;;;;;CAMA,OAAO,WAAW;;;;;;;CAQlB,OAAO,WAAW,QAAQ;EACzB,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,MAAM,KAAK,UAAUA,QAAa,OAAO,KAAK,KAAK,SAAS,IAAI,IAAI,OAAO,KACjF,MAAM,KAAK,UAAUA,QAAa,OAAO,KAAK,KAAK,SAAS,IAAI,IAAI,OAAO,KAC3E,MAAM,OAAO;EAEb,OAAO,IAAI,OAAO,KAAK,KAAK,GAAG;CAChC;;;;;;;CAQA,OAAO,iBAAiB,QAAQ;EAC/B,SAAS,IAAI,aAAa,MAAM;EAChC,MAAM,SAAS,OAAO,UAAU,GAChC,YAAY,KAAK,WAAW,MAAM,GAClC,WAAW,OAAO,MAAM,UAAU,KAClC,WAAW,OAAO,MAAM,UAAU;EAElC,IAAI,aAAa,KAAK,aAAa,GAClC,OAAO;EAGR,MAAM,KAAK,OAAO,aAAa,GAC/B,KAAK,OAAO,aAAa,GACzB,QAAQ,IAAI,OAAO,GAAG,MAAM,UAAU,GAAG,MAAM,QAAQ,GACvD,QAAQ,IAAI,OAAO,GAAG,MAAM,UAAU,GAAG,MAAM,QAAQ;EAEvD,OAAO,IAAI,aAAa,OAAO,KAAK;CACrC;AACD"}
@@ -12,7 +12,7 @@ var EPSG3395 = class extends EarthCRS {
12
12
  /** @type {Projection} */
13
13
  static projection = Mercator;
14
14
  /** @type {Transformation} */
15
- static transformation = (() => {
15
+ static transformation = /* @__PURE__ */ (() => {
16
16
  const scale = .5 / (Math.PI * Mercator.R);
17
17
  return new Transformation(scale, .5, -scale, .5);
18
18
  })();
@@ -1 +1 @@
1
- {"version":3,"file":"EPSG3395.js","names":[],"sources":["../../../../src/geo/crs/EPSG3395.js"],"sourcesContent":["import {EarthCRS} from './EarthCRS.js';\nimport {Mercator} from '../projection/Projection.Mercator.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * Rarely used by some commercial tile providers. Uses Elliptical Mercator projection.\n */\nexport class EPSG3395 extends EarthCRS {\n\t/** @type {string} */\n\tstatic code = 'EPSG:3395';\n\t/** @type {Projection} */\n\tstatic projection = Mercator;\n\t/** @type {Transformation} */\n\tstatic transformation = (() => {\n\t\tconst scale = 0.5 / (Math.PI * Mercator.R);\n\t\treturn new Transformation(scale, 0.5, -scale, 0.5);\n\t})();\n}\n"],"mappings":";;;;;;;;AAQA,IAAa,WAAb,cAA8B,SAAS;;CAEtC,OAAO,OAAO;;CAEd,OAAO,aAAa;;CAEpB,OAAO,wBAAwB;EAC9B,MAAM,QAAQ,MAAO,KAAK,KAAK,SAAS;EACxC,OAAO,IAAI,eAAe,OAAO,IAAK,CAAC,OAAO,EAAG;CAClD,EAAA,CAAG;AACJ"}
1
+ {"version":3,"file":"EPSG3395.js","names":[],"sources":["../../../../src/geo/crs/EPSG3395.js"],"sourcesContent":["import {EarthCRS} from './EarthCRS.js';\nimport {Mercator} from '../projection/Projection.Mercator.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * Rarely used by some commercial tile providers. Uses Elliptical Mercator projection.\n */\nexport class EPSG3395 extends EarthCRS {\n\t/** @type {string} */\n\tstatic code = 'EPSG:3395';\n\t/** @type {Projection} */\n\tstatic projection = Mercator;\n\t/** @type {Transformation} */\n\tstatic transformation = /* @__PURE__ */ (() => {\n\t\tconst scale = 0.5 / (Math.PI * Mercator.R);\n\t\treturn new Transformation(scale, 0.5, -scale, 0.5);\n\t})();\n}\n"],"mappings":";;;;;;;;AAQA,IAAa,WAAb,cAA8B,SAAS;;CAEtC,OAAO,OAAO;;CAEd,OAAO,aAAa;;CAEpB,OAAO,iBAAiC,uBAAO;EAC9C,MAAM,QAAQ,MAAO,KAAK,KAAK,SAAS;EACxC,OAAO,IAAI,eAAe,OAAO,IAAK,CAAC,OAAO,EAAG;CAClD,EAAA,CAAG;AACJ"}
@@ -14,7 +14,7 @@ var EPSG3857 = class extends EarthCRS {
14
14
  /** @type {Projection} */
15
15
  static projection = SphericalMercator;
16
16
  /** @type {Transformation} */
17
- static transformation = (() => {
17
+ static transformation = /* @__PURE__ */ (() => {
18
18
  const scale = .5 / (Math.PI * SphericalMercator.R);
19
19
  return new Transformation(scale, .5, -scale, .5);
20
20
  })();
@@ -1 +1 @@
1
- {"version":3,"file":"EPSG3857.js","names":[],"sources":["../../../../src/geo/crs/EPSG3857.js"],"sourcesContent":["import {EarthCRS} from './EarthCRS.js';\nimport {SphericalMercator} from '../projection/Projection.SphericalMercator.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * The most common CRS for online maps, used by almost all free and commercial\n * tile providers. Uses Spherical Mercator projection. Set in by default in\n * Map's `crs` option.\n */\nexport class EPSG3857 extends EarthCRS {\n\t/** @type {string} */\n\tstatic code = 'EPSG:3857';\n\t/** @type {Projection} */\n\tstatic projection = SphericalMercator;\n\t/** @type {Transformation} */\n\tstatic transformation = (() => {\n\t\tconst scale = 0.5 / (Math.PI * SphericalMercator.R);\n\t\treturn new Transformation(scale, 0.5, -scale, 0.5);\n\t})();\n}\n\n/**\n * The same as `EPSG3857`, with its former unofficial code `EPSG:900913`.\n */\nexport class EPSG900913 extends EPSG3857 {\n\t/** @type {string} */\n\tstatic code = 'EPSG:900913';\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,WAAb,cAA8B,SAAS;;CAEtC,OAAO,OAAO;;CAEd,OAAO,aAAa;;CAEpB,OAAO,wBAAwB;EAC9B,MAAM,QAAQ,MAAO,KAAK,KAAK,kBAAkB;EACjD,OAAO,IAAI,eAAe,OAAO,IAAK,CAAC,OAAO,EAAG;CAClD,EAAA,CAAG;AACJ;;;;AAKA,IAAa,aAAb,cAAgC,SAAS;;CAExC,OAAO,OAAO;AACf"}
1
+ {"version":3,"file":"EPSG3857.js","names":[],"sources":["../../../../src/geo/crs/EPSG3857.js"],"sourcesContent":["import {EarthCRS} from './EarthCRS.js';\nimport {SphericalMercator} from '../projection/Projection.SphericalMercator.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * The most common CRS for online maps, used by almost all free and commercial\n * tile providers. Uses Spherical Mercator projection. Set in by default in\n * Map's `crs` option.\n */\nexport class EPSG3857 extends EarthCRS {\n\t/** @type {string} */\n\tstatic code = 'EPSG:3857';\n\t/** @type {Projection} */\n\tstatic projection = SphericalMercator;\n\t/** @type {Transformation} */\n\tstatic transformation = /* @__PURE__ */ (() => {\n\t\tconst scale = 0.5 / (Math.PI * SphericalMercator.R);\n\t\treturn new Transformation(scale, 0.5, -scale, 0.5);\n\t})();\n}\n\n/**\n * The same as `EPSG3857`, with its former unofficial code `EPSG:900913`.\n */\nexport class EPSG900913 extends EPSG3857 {\n\t/** @type {string} */\n\tstatic code = 'EPSG:900913';\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,WAAb,cAA8B,SAAS;;CAEtC,OAAO,OAAO;;CAEd,OAAO,aAAa;;CAEpB,OAAO,iBAAiC,uBAAO;EAC9C,MAAM,QAAQ,MAAO,KAAK,KAAK,kBAAkB;EACjD,OAAO,IAAI,eAAe,OAAO,IAAK,CAAC,OAAO,EAAG;CAClD,EAAA,CAAG;AACJ;;;;AAKA,IAAa,aAAb,cAAgC,SAAS;;CAExC,OAAO,OAAO;AACf"}
@@ -19,7 +19,7 @@ var EPSG4326 = class extends EarthCRS {
19
19
  /** @type {Projection} */
20
20
  static projection = LonLat;
21
21
  /** @type {Transformation} */
22
- static transformation = new Transformation(1 / 180, 1, -1 / 180, .5);
22
+ static transformation = /* @__PURE__ */ new Transformation(1 / 180, 1, -1 / 180, .5);
23
23
  };
24
24
  //#endregion
25
25
  export { EPSG4326 };
@@ -1 +1 @@
1
- {"version":3,"file":"EPSG4326.js","names":[],"sources":["../../../../src/geo/crs/EPSG4326.js"],"sourcesContent":["import {EarthCRS} from './EarthCRS.js';\nimport {LonLat} from '../projection/Projection.LonLat.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.\n *\n * Maplair complies with the\n * [TMS coordinate scheme for EPSG:4326](https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#global-geodetic).\n * If you are using a `TileLayer` with this CRS, ensure that there are two 256x256\n * pixel tiles covering the whole earth at zoom level zero, and that the tile\n * coordinate origin is (-180,+90), or (-180,-90) for `TileLayer`s with\n * [the `tms` option](#tilelayer-tms) set.\n */\nexport class EPSG4326 extends EarthCRS {\n\t/** @type {string} */\n\tstatic code = 'EPSG:4326';\n\t/** @type {Projection} */\n\tstatic projection = LonLat;\n\t/** @type {Transformation} */\n\tstatic transformation = new Transformation(1 / 180, 1, -1 / 180, 0.5);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,WAAb,cAA8B,SAAS;;CAEtC,OAAO,OAAO;;CAEd,OAAO,aAAa;;CAEpB,OAAO,iBAAiB,IAAI,eAAe,IAAI,KAAK,GAAG,KAAK,KAAK,EAAG;AACrE"}
1
+ {"version":3,"file":"EPSG4326.js","names":[],"sources":["../../../../src/geo/crs/EPSG4326.js"],"sourcesContent":["import {EarthCRS} from './EarthCRS.js';\nimport {LonLat} from '../projection/Projection.LonLat.js';\nimport {Transformation} from '../../geometry/Transformation.js';\n/** @import {Projection} from '../projection/index.js' */\n\n/**\n * A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.\n *\n * Maplair complies with the\n * [TMS coordinate scheme for EPSG:4326](https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#global-geodetic).\n * If you are using a `TileLayer` with this CRS, ensure that there are two 256x256\n * pixel tiles covering the whole earth at zoom level zero, and that the tile\n * coordinate origin is (-180,+90), or (-180,-90) for `TileLayer`s with\n * [the `tms` option](#tilelayer-tms) set.\n */\nexport class EPSG4326 extends EarthCRS {\n\t/** @type {string} */\n\tstatic code = 'EPSG:4326';\n\t/** @type {Projection} */\n\tstatic projection = LonLat;\n\t/** @type {Transformation} */\n\tstatic transformation = /* @__PURE__ */ new Transformation(1 / 180, 1, -1 / 180, 0.5);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,WAAb,cAA8B,SAAS;;CAEtC,OAAO,OAAO;;CAEd,OAAO,aAAa;;CAEpB,OAAO,iCAAiC,IAAI,eAAe,IAAI,KAAK,GAAG,KAAK,KAAK,EAAG;AACrF"}
@@ -1,3 +1,4 @@
1
+ import { haversineDistance } from "../LatLng.js";
1
2
  import { CRS } from "./CRS.js";
2
3
  //#region src/geo/crs/EarthCRS.js
3
4
  /** @import {LatLng} from '../LatLng.js' */
@@ -28,8 +29,7 @@ var EarthCRS = class extends CRS {
28
29
  * @returns {number}
29
30
  */
30
31
  static distance(latlng1, latlng2) {
31
- const rad = Math.PI / 180, lat1 = latlng1.lat * rad, lat2 = latlng2.lat * rad, sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2), sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2), a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon, c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
32
- return this.R * c;
32
+ return haversineDistance(latlng1, latlng2, this.R);
33
33
  }
34
34
  };
35
35
  //#endregion
@@ -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"}
@@ -14,7 +14,7 @@ var SimpleCRS = class extends CRS {
14
14
  /** @type {Projection} */
15
15
  static projection = LonLat;
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
@@ -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 {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 = /* @__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"}
@@ -12,14 +12,14 @@ import { LatLng } from "../LatLng.js";
12
12
  */
13
13
  const LonLat = {
14
14
  project(latlng) {
15
- latlng = new LatLng(latlng);
15
+ latlng = LatLng.from(latlng);
16
16
  return new Point(latlng.lng, latlng.lat);
17
17
  },
18
18
  unproject(point) {
19
- point = new Point(point);
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
24
  //#endregion
25
25
  export { LonLat };
@@ -1 +1 @@
1
- {"version":3,"file":"Projection.LonLat.js","names":[],"sources":["../../../../src/geo/projection/Projection.LonLat.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 LonLat = {\n\tproject(latlng) {\n\t\tlatlng = new LatLng(latlng);\n\t\treturn new Point(latlng.lng, latlng.lat);\n\t},\n\n\tunproject(point) {\n\t\tpoint = new Point(point);\n\t\treturn new LatLng(point.y, point.x);\n\t},\n\n\tbounds: new Bounds([-180, -90], [180, 90])\n};\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,SAAS;CACrB,QAAQ,QAAQ;EACf,SAAS,IAAI,OAAO,MAAM;EAC1B,OAAO,IAAI,MAAM,OAAO,KAAK,OAAO,GAAG;CACxC;CAEA,UAAU,OAAO;EAChB,QAAQ,IAAI,MAAM,KAAK;EACvB,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,CAAC;CACnC;CAEA,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;AAC1C"}
1
+ {"version":3,"file":"Projection.LonLat.js","names":[],"sources":["../../../../src/geo/projection/Projection.LonLat.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 LonLat = {\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,SAAS;CACrB,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"}
@@ -9,9 +9,9 @@ import { LatLng } from "../LatLng.js";
9
9
  const Mercator = {
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
- latlng = new LatLng(latlng);
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);
16
16
  let y = latlng.lat * d;
17
17
  const con = e * Math.sin(y);
@@ -20,7 +20,7 @@ const Mercator = {
20
20
  return new Point(latlng.lng * d * r, y);
21
21
  },
22
22
  unproject(point) {
23
- point = new Point(point);
23
+ point = Point.from(point);
24
24
  const d = 180 / Math.PI, r = this.R, tmp = this.R_MINOR / r, e = Math.sqrt(1 - tmp * tmp), ts = Math.exp(-point.y / r);
25
25
  let phi = Math.PI / 2 - 2 * Math.atan(ts);
26
26
  for (let i = 0, dphi = .1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {
@@ -1 +1 @@
1
- {"version":3,"file":"Projection.Mercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.Mercator.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 Mercator = {\n\tR: earthRadius,\n\tR_MINOR: 6356752.314245179,\n\n\tbounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),\n\n\tproject(latlng) {\n\t\tlatlng = new LatLng(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 = new Point(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);\n\t}\n};\n"],"mappings":";;;;;;;;AAaA,MAAa,WAAW;CACvB,GAAG;CACH,SAAS;CAET,QAAQ,IAAI,OAAO,CAAC,iBAAiB,eAAe,GAAG,CAAC,gBAAgB,cAAc,CAAC;CAEvF,QAAQ,QAAQ;EACf,SAAS,IAAI,OAAO,MAAM;EAC1B,MAAM,IAAI,KAAK,KAAK,KACpB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG;EAC3B,IAAI,IAAI,OAAO,MAAM;EACrB,MAAM,MAAM,IAAI,KAAK,IAAI,CAAC;EAE1B,MAAM,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,UAAU,IAAI;EAC3E,IAAI,CAAC,IAAI,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC;EAErC,OAAO,IAAI,MAAM,OAAO,MAAM,IAAI,GAAG,CAAC;CACvC;CAEA,UAAU,OAAO;EAChB,QAAQ,IAAI,MAAM,KAAK;EACvB,MAAM,IAAI,MAAM,KAAK,IACrB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG,GAC3B,KAAK,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;EAC1B,IAAI,MAAM,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;EAExC,KAAK,IAAI,IAAI,GAAG,OAAO,IAAK,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,MAAM,KAAK;GACtE,MAAM,IAAI,KAAK,IAAI,GAAG;GACtB,QAAQ,IAAI,QAAQ,IAAI,UAAU,IAAI;GACtC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,GAAG,IAAI;GAC/C,OAAO;EACR;EAEA,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;CAC3C;AACD"}
1
+ {"version":3,"file":"Projection.Mercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.Mercator.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 Mercator = {\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);\n\t}\n};\n"],"mappings":";;;;;;;;AAaA,MAAa,WAAW;CACvB,GAAG;CACH,SAAS;CAET,wBAAwB,IAAI,OAAO,CAAC,iBAAiB,eAAe,GAAG,CAAC,gBAAgB,cAAc,CAAC;CAEvG,QAAQ,QAAQ;EACf,SAAS,OAAO,KAAK,MAAM;EAC3B,MAAM,IAAI,KAAK,KAAK,KACpB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG;EAC3B,IAAI,IAAI,OAAO,MAAM;EACrB,MAAM,MAAM,IAAI,KAAK,IAAI,CAAC;EAE1B,MAAM,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,UAAU,IAAI;EAC3E,IAAI,CAAC,IAAI,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC;EAErC,OAAO,IAAI,MAAM,OAAO,MAAM,IAAI,GAAG,CAAC;CACvC;CAEA,UAAU,OAAO;EAChB,QAAQ,MAAM,KAAK,KAAK;EACxB,MAAM,IAAI,MAAM,KAAK,IACrB,IAAI,KAAK,GACT,MAAM,KAAK,UAAU,GACrB,IAAI,KAAK,KAAK,IAAI,MAAM,GAAG,GAC3B,KAAK,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;EAC1B,IAAI,MAAM,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;EAExC,KAAK,IAAI,IAAI,GAAG,OAAO,IAAK,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,IAAI,MAAM,KAAK;GACtE,MAAM,IAAI,KAAK,IAAI,GAAG;GACtB,QAAQ,IAAI,QAAQ,IAAI,UAAU,IAAI;GACtC,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,GAAG,IAAI;GAC/C,OAAO;EACR;EAEA,OAAO,IAAI,OAAO,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC;CAC3C;AACD"}
@@ -14,16 +14,16 @@ const SphericalMercator = {
14
14
  R: earthRadius,
15
15
  MAX_LATITUDE: 85.0511287798,
16
16
  project(latlng) {
17
- latlng = new LatLng(latlng);
17
+ latlng = LatLng.from(latlng);
18
18
  const d = Math.PI / 180, max = this.MAX_LATITUDE, lat = Math.max(Math.min(max, latlng.lat), -max), sin = Math.sin(lat * d);
19
19
  return new Point(this.R * latlng.lng * d, this.R * Math.log((1 + sin) / (1 - sin)) / 2);
20
20
  },
21
21
  unproject(point) {
22
- point = new Point(point);
22
+ point = Point.from(point);
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
  })()
@@ -1 +1 @@
1
- {"version":3,"file":"Projection.SphericalMercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.SphericalMercator.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 SphericalMercator = {\n\n\tR: earthRadius,\n\tMAX_LATITUDE: 85.0511287798,\n\n\tproject(latlng) {\n\t\tlatlng = new LatLng(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 = new Point(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: (() => {\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,oBAAoB;CAEhC,GAAG;CACH,cAAc;CAEd,QAAQ,QAAQ;EACf,SAAS,IAAI,OAAO,MAAM;EAC1B,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,IAAI,MAAM,KAAK;EACvB,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,eAAe;EACd,MAAM,IAAI,cAAc,KAAK;EAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACnC,EAAA,CAAG;AACJ"}
1
+ {"version":3,"file":"Projection.SphericalMercator.js","names":[],"sources":["../../../../src/geo/projection/Projection.SphericalMercator.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 SphericalMercator = {\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,oBAAoB;CAEhC,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"}
@@ -57,6 +57,18 @@ var Bounds = class Bounds {
57
57
  for (const point of points) this.extend(point);
58
58
  }
59
59
  /**
60
+ * Returns the given `Bounds` object as it is, or else a new `Bounds` object created
61
+ * from the given arguments (the same as of the constructor) — unlike the
62
+ * constructor, which always creates a new object.
63
+ * @param {PointExpression|BoundsExpression} [a] The first corner, the points or the
64
+ * bounds.
65
+ * @param {PointExpression} [b] The opposite corner.
66
+ * @returns {Bounds}
67
+ */
68
+ static from(a, b) {
69
+ return a instanceof Bounds ? a : new Bounds(a, b);
70
+ }
71
+ /**
60
72
  * Extends the bounds to contain the given point or bounds.
61
73
  * @param {PointExpression|BoundsExpression} obj
62
74
  * @returns {this}
@@ -64,9 +76,9 @@ var Bounds = class Bounds {
64
76
  extend(obj) {
65
77
  let min2, max2;
66
78
  if (!obj) return this;
67
- if (obj instanceof Point || typeof obj[0] === "number" || "x" in obj) min2 = max2 = new Point(obj);
79
+ if (obj instanceof Point || typeof obj[0] === "number" || "x" in obj) min2 = max2 = Point.from(obj);
68
80
  else {
69
- obj = new Bounds(obj);
81
+ obj = Bounds.from(obj);
70
82
  min2 = obj.min;
71
83
  max2 = obj.max;
72
84
  if (!min2 || !max2) return this;
@@ -132,8 +144,8 @@ var Bounds = class Bounds {
132
144
  */
133
145
  contains(obj) {
134
146
  let min, max;
135
- if (typeof obj[0] === "number" || obj instanceof Point) obj = new Point(obj);
136
- else obj = new Bounds(obj);
147
+ if (typeof obj[0] === "number" || obj instanceof Point) obj = Point.from(obj);
148
+ else obj = Bounds.from(obj);
137
149
  if (obj instanceof Bounds) {
138
150
  min = obj.min;
139
151
  max = obj.max;
@@ -147,7 +159,7 @@ var Bounds = class Bounds {
147
159
  * @returns {boolean}
148
160
  */
149
161
  intersects(bounds) {
150
- bounds = new Bounds(bounds);
162
+ bounds = Bounds.from(bounds);
151
163
  const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xIntersects = max2.x >= min.x && min2.x <= max.x, yIntersects = max2.y >= min.y && min2.y <= max.y;
152
164
  return xIntersects && yIntersects;
153
165
  }
@@ -158,7 +170,7 @@ var Bounds = class Bounds {
158
170
  * @returns {boolean}
159
171
  */
160
172
  overlaps(bounds) {
161
- bounds = new Bounds(bounds);
173
+ bounds = Bounds.from(bounds);
162
174
  const min = this.min, max = this.max, min2 = bounds.min, max2 = bounds.max, xOverlaps = max2.x > min.x && min2.x < max.x, yOverlaps = max2.y > min.y && min2.y < max.y;
163
175
  return xOverlaps && yOverlaps;
164
176
  }
@@ -187,7 +199,7 @@ var Bounds = class Bounds {
187
199
  */
188
200
  equals(bounds) {
189
201
  if (!bounds) return false;
190
- bounds = new Bounds(bounds);
202
+ bounds = Bounds.from(bounds);
191
203
  return this.min.equals(bounds.getTopLeft()) && this.max.equals(bounds.getBottomRight());
192
204
  }
193
205
  };
@@ -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 * 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 = new Point(obj);\n\t\t} else {\n\t\t\tobj = new Bounds(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 = new Point(obj);\n\t\t} else {\n\t\t\tobj = new Bounds(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 = new Bounds(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 = new Bounds(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 = new Bounds(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,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,I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AAI,IAAI,WAAW,CAAC;CACtD;;;;;;CAQA,OAAO,QAAQ;EACd,IAAI,CAAC,QAAU,OAAO;EAEtB,SAAS,IAAI,OAAO,MAAM;EAE1B,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 (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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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