maplair 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/esm/Maplair.js +18 -17
  3. package/dist/esm/Maplair.js.map +1 -1
  4. package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
  5. package/dist/esm/control/AttributionControl.js +25 -16
  6. package/dist/esm/control/AttributionControl.js.map +1 -1
  7. package/dist/esm/control/ButtonControl.js +10 -13
  8. package/dist/esm/control/ButtonControl.js.map +1 -1
  9. package/dist/esm/control/ContextMenu.js +2 -5
  10. package/dist/esm/control/ContextMenu.js.map +1 -1
  11. package/dist/esm/control/Control.js +10 -18
  12. package/dist/esm/control/Control.js.map +1 -1
  13. package/dist/esm/control/FullscreenControl.js +6 -9
  14. package/dist/esm/control/FullscreenControl.js.map +1 -1
  15. package/dist/esm/control/LayersControl.js +170 -65
  16. package/dist/esm/control/LayersControl.js.map +1 -1
  17. package/dist/esm/control/LegendControl.js +8 -11
  18. package/dist/esm/control/LegendControl.js.map +1 -1
  19. package/dist/esm/control/MiniMapControl.js +15 -18
  20. package/dist/esm/control/MiniMapControl.js.map +1 -1
  21. package/dist/esm/control/RotateControl.js +2 -5
  22. package/dist/esm/control/RotateControl.js.map +1 -1
  23. package/dist/esm/control/ScaleControl.js +8 -11
  24. package/dist/esm/control/ScaleControl.js.map +1 -1
  25. package/dist/esm/control/SearchControl.js +100 -19
  26. package/dist/esm/control/SearchControl.js.map +1 -1
  27. package/dist/esm/control/SideBySideControl.js +2 -5
  28. package/dist/esm/control/SideBySideControl.js.map +1 -1
  29. package/dist/esm/control/TextControl.js +6 -9
  30. package/dist/esm/control/TextControl.js.map +1 -1
  31. package/dist/esm/control/TimeControl.js +407 -0
  32. package/dist/esm/control/TimeControl.js.map +1 -0
  33. package/dist/esm/control/ZoomControl.js +23 -36
  34. package/dist/esm/control/ZoomControl.js.map +1 -1
  35. package/dist/esm/core/Class.js +28 -44
  36. package/dist/esm/core/Class.js.map +1 -1
  37. package/dist/esm/core/Events.js +22 -10
  38. package/dist/esm/core/Events.js.map +1 -1
  39. package/dist/esm/core/Handler.js +23 -14
  40. package/dist/esm/core/Handler.js.map +1 -1
  41. package/dist/esm/core/I18n.js +1 -2
  42. package/dist/esm/core/Util.js +15 -4
  43. package/dist/esm/core/Util.js.map +1 -1
  44. package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
  45. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  46. package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
  47. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  48. package/dist/esm/dom/DomEvent.js +18 -60
  49. package/dist/esm/dom/DomEvent.js.map +1 -1
  50. package/dist/esm/dom/DomUtil.js +15 -70
  51. package/dist/esm/dom/DomUtil.js.map +1 -1
  52. package/dist/esm/dom/Draggable.js +21 -21
  53. package/dist/esm/dom/Draggable.js.map +1 -1
  54. package/dist/esm/dom/PosAnimation.js +4 -27
  55. package/dist/esm/dom/PosAnimation.js.map +1 -1
  56. package/dist/esm/geo/LatLng.js +16 -7
  57. package/dist/esm/geo/LatLng.js.map +1 -1
  58. package/dist/esm/geo/LatLngBounds.js +9 -15
  59. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  60. package/dist/esm/geo/crs/CRS.js +1 -2
  61. package/dist/esm/geo/crs/EPSG3395.js +5 -6
  62. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  63. package/dist/esm/geo/crs/EPSG3857.js +5 -6
  64. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  65. package/dist/esm/geo/crs/EPSG4326.js +4 -5
  66. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  67. package/dist/esm/geo/crs/EarthCRS.js +3 -4
  68. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  69. package/dist/esm/geo/crs/SimpleCRS.js +4 -5
  70. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  71. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
  72. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  73. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
  74. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  75. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
  76. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  77. package/dist/esm/geometry/Bounds.js +10 -14
  78. package/dist/esm/geometry/Bounds.js.map +1 -1
  79. package/dist/esm/geometry/LineUtil.js +37 -32
  80. package/dist/esm/geometry/LineUtil.js.map +1 -1
  81. package/dist/esm/geometry/Point.js +1 -2
  82. package/dist/esm/geometry/PolyUtil.js +24 -51
  83. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  84. package/dist/esm/geometry/Transformation.js +1 -2
  85. package/dist/esm/layer/BlanketOverlay.js +7 -10
  86. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  87. package/dist/esm/layer/Classification.js +1 -2
  88. package/dist/esm/layer/DivOverlay.js +16 -22
  89. package/dist/esm/layer/DivOverlay.js.map +1 -1
  90. package/dist/esm/layer/FeatureGroup.js +5 -4
  91. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  92. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  93. package/dist/esm/layer/GeoJSON.js +17 -155
  94. package/dist/esm/layer/GeoJSON.js.map +1 -1
  95. package/dist/esm/layer/GeoJSONUtil.js +74 -0
  96. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  97. package/dist/esm/layer/HeatLayer.js +17 -20
  98. package/dist/esm/layer/HeatLayer.js.map +1 -1
  99. package/dist/esm/layer/ImageOverlay.js +22 -29
  100. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  101. package/dist/esm/layer/Layer.js +9 -12
  102. package/dist/esm/layer/Layer.js.map +1 -1
  103. package/dist/esm/layer/LayerGroup.js +53 -3
  104. package/dist/esm/layer/LayerGroup.js.map +1 -1
  105. package/dist/esm/layer/Popup.js +35 -58
  106. package/dist/esm/layer/Popup.js.map +1 -1
  107. package/dist/esm/layer/SVGOverlay.js +3 -7
  108. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  109. package/dist/esm/layer/Tooltip.js +31 -34
  110. package/dist/esm/layer/Tooltip.js.map +1 -1
  111. package/dist/esm/layer/VideoOverlay.js +13 -17
  112. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  113. package/dist/esm/layer/marker/DefaultIcon.js +38 -49
  114. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  115. package/dist/esm/layer/marker/DivIcon.js +8 -11
  116. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  117. package/dist/esm/layer/marker/Icon.js +9 -12
  118. package/dist/esm/layer/marker/Icon.js.map +1 -1
  119. package/dist/esm/layer/marker/Marker.Drag.js +44 -5
  120. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  121. package/dist/esm/layer/marker/Marker.Move.js +5 -8
  122. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  123. package/dist/esm/layer/marker/Marker.js +115 -47
  124. package/dist/esm/layer/marker/Marker.js.map +1 -1
  125. package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
  126. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  127. package/dist/esm/layer/marker/SvgIcon.js +7 -10
  128. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  129. package/dist/esm/layer/tile/GridLayer.js +89 -101
  130. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  131. package/dist/esm/layer/tile/TileLayer.js +36 -44
  132. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  133. package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
  134. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  135. package/dist/esm/layer/vector/Canvas.js +8 -17
  136. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  137. package/dist/esm/layer/vector/Circle.js +6 -5
  138. package/dist/esm/layer/vector/Circle.js.map +1 -1
  139. package/dist/esm/layer/vector/CircleMarker.js +19 -10
  140. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  141. package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
  142. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  143. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  144. package/dist/esm/layer/vector/Path.js +28 -22
  145. package/dist/esm/layer/vector/Path.js.map +1 -1
  146. package/dist/esm/layer/vector/Polygon.js +22 -7
  147. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  148. package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
  149. package/dist/esm/layer/vector/Polyline.js +25 -10
  150. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  151. package/dist/esm/layer/vector/Rectangle.js +1 -2
  152. package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
  153. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  154. package/dist/esm/layer/vector/Renderer.js +1 -2
  155. package/dist/esm/layer/vector/SVG.js +12 -9
  156. package/dist/esm/layer/vector/SVG.js.map +1 -1
  157. package/dist/esm/map/Hash.js +1 -2
  158. package/dist/esm/map/Map.Rotation.js +41 -22
  159. package/dist/esm/map/Map.Rotation.js.map +1 -1
  160. package/dist/esm/map/Map.js +125 -126
  161. package/dist/esm/map/Map.js.map +1 -1
  162. package/dist/esm/map/MapSync.js +1 -2
  163. package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
  164. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  165. package/dist/esm/map/handler/DisplaceHandler.js +7 -10
  166. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  167. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  168. package/dist/esm/map/handler/DragHandler.js +20 -21
  169. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  170. package/dist/esm/map/handler/KeyboardHandler.js +48 -68
  171. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  172. package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
  173. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  174. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
  175. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  176. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  177. package/dist/esm/map/handler/TapHoldHandler.js +13 -7
  178. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  179. package/dist/esm/package.js +2 -3
  180. package/dist/maplair-global-src.js +6495 -5981
  181. package/dist/maplair-global-src.js.map +1 -1
  182. package/dist/maplair-global.js +2 -2
  183. package/dist/maplair-global.js.map +1 -1
  184. package/dist/maplair-src.js +6206 -5673
  185. package/dist/maplair-src.js.map +1 -1
  186. package/dist/maplair.css +1 -1213
  187. package/dist/maplair.js +2 -2
  188. package/dist/maplair.js.map +1 -1
  189. package/i18n/cs.json +6 -0
  190. package/i18n/de.json +6 -0
  191. package/i18n/en.json +6 -0
  192. package/i18n/es.json +6 -0
  193. package/i18n/fr.json +6 -0
  194. package/i18n/hu.json +6 -0
  195. package/i18n/it.json +6 -0
  196. package/i18n/rm.json +6 -0
  197. package/i18n/sk.json +6 -0
  198. package/i18n/sl.json +6 -0
  199. package/package.json +11 -18
  200. package/src/Maplair.all.js +0 -1
  201. package/src/control/AttributionControl.js +25 -18
  202. package/src/control/ButtonControl.js +9 -11
  203. package/src/control/ContextMenu.js +3 -5
  204. package/src/control/Control.js +9 -19
  205. package/src/control/FullscreenControl.js +5 -7
  206. package/src/control/LayersControl.js +196 -86
  207. package/src/control/LegendControl.js +7 -9
  208. package/src/control/MiniMapControl.js +9 -11
  209. package/src/control/RotateControl.js +3 -5
  210. package/src/control/ScaleControl.js +7 -9
  211. package/src/control/SearchControl.js +102 -19
  212. package/src/control/SideBySideControl.js +3 -5
  213. package/src/control/TextControl.js +5 -7
  214. package/src/control/TimeControl.js +471 -0
  215. package/src/control/ZoomControl.js +22 -38
  216. package/src/control/index.js +1 -0
  217. package/src/core/Class.js +37 -45
  218. package/src/core/Events.js +22 -3
  219. package/src/core/Handler.js +25 -13
  220. package/src/core/Util.js +20 -2
  221. package/src/core/index.js +0 -1
  222. package/src/dom/DomEvent.DoubleTap.js +18 -10
  223. package/src/dom/DomEvent.PointerEvents.js +3 -26
  224. package/src/dom/DomEvent.js +17 -85
  225. package/src/dom/DomUtil.js +22 -78
  226. package/src/dom/Draggable.js +32 -23
  227. package/src/dom/PosAnimation.js +3 -25
  228. package/src/dom/index.js +0 -1
  229. package/src/geo/LatLng.js +20 -3
  230. package/src/geo/LatLngBounds.js +8 -15
  231. package/src/geo/crs/EPSG3395.js +4 -4
  232. package/src/geo/crs/EPSG3857.js +4 -4
  233. package/src/geo/crs/EPSG4326.js +3 -3
  234. package/src/geo/crs/EarthCRS.js +2 -8
  235. package/src/geo/crs/SimpleCRS.js +3 -3
  236. package/src/geo/index.js +1 -2
  237. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
  238. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
  239. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
  240. package/src/geo/projection/index.js +5 -5
  241. package/src/geometry/Bounds.js +12 -17
  242. package/src/geometry/LineUtil.js +48 -49
  243. package/src/geometry/PolyUtil.js +39 -76
  244. package/src/layer/BlanketOverlay.js +6 -10
  245. package/src/layer/DivOverlay.js +16 -27
  246. package/src/layer/FeatureGroup.js +8 -2
  247. package/src/layer/GeoJSON.js +17 -218
  248. package/src/layer/GeoJSONUtil.js +85 -0
  249. package/src/layer/HeatLayer.js +10 -12
  250. package/src/layer/ImageOverlay.js +21 -32
  251. package/src/layer/Layer.js +8 -10
  252. package/src/layer/LayerGroup.js +72 -1
  253. package/src/layer/Popup.js +37 -62
  254. package/src/layer/SVGOverlay.js +1 -5
  255. package/src/layer/Tooltip.js +34 -36
  256. package/src/layer/VideoOverlay.js +12 -15
  257. package/src/layer/marker/DefaultIcon.js +40 -58
  258. package/src/layer/marker/DivIcon.js +9 -11
  259. package/src/layer/marker/Icon.js +9 -10
  260. package/src/layer/marker/Marker.Drag.js +54 -6
  261. package/src/layer/marker/Marker.Move.js +4 -6
  262. package/src/layer/marker/Marker.js +145 -52
  263. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  264. package/src/layer/marker/SvgIcon.js +7 -9
  265. package/src/layer/marker/index.js +1 -0
  266. package/src/layer/tile/GridLayer.js +108 -135
  267. package/src/layer/tile/TileLayer.js +44 -49
  268. package/src/layer/tile/WMSTileLayer.js +31 -26
  269. package/src/layer/vector/Canvas.js +13 -19
  270. package/src/layer/vector/Circle.js +9 -3
  271. package/src/layer/vector/CircleMarker.js +19 -7
  272. package/src/layer/vector/Path.DashAnimation.js +1 -2
  273. package/src/layer/vector/Path.js +30 -21
  274. package/src/layer/vector/Polygon.js +29 -6
  275. package/src/layer/vector/Polyline.js +26 -7
  276. package/src/layer/vector/Renderer.getRenderer.js +20 -19
  277. package/src/layer/vector/SVG.js +17 -7
  278. package/src/map/Map.Rotation.js +40 -8
  279. package/src/map/Map.js +158 -153
  280. package/src/map/handler/BoxZoomHandler.js +30 -50
  281. package/src/map/handler/DisplaceHandler.js +6 -8
  282. package/src/map/handler/DragHandler.js +25 -28
  283. package/src/map/handler/KeyboardHandler.js +65 -90
  284. package/src/map/handler/PinchZoomHandler.js +16 -5
  285. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  286. package/src/map/handler/TapHoldHandler.js +15 -4
  287. package/src/map/index.js +1 -1
  288. package/src/maplair.css +153 -98
  289. package/dist/esm/core/Browser.js +0 -100
  290. package/dist/esm/core/Browser.js.map +0 -1
  291. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  292. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  293. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  294. package/dist/esm/geo/projection/index.js +0 -14
  295. package/dist/esm/geo/projection/index.js.map +0 -1
  296. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  297. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  298. package/dist/images/layers.svg +0 -1
  299. package/dist/images/marker-icon.svg +0 -1
  300. package/dist/images/marker-shadow.svg +0 -1
  301. package/src/core/Browser.js +0 -110
  302. package/src/images/layers.svg +0 -1
  303. package/src/images/marker-icon.svg +0 -1
  304. package/src/images/marker-shadow.svg +0 -1
  305. package/src/layer/marker/Marker.Rotation.js +0 -103
@@ -1,5 +1,5 @@
1
1
  import {EarthCRS} from './EarthCRS.js';
2
- import {LonLat} from '../projection/Projection.LonLat.js';
2
+ import {LonLatProjection} from '../projection/LonLatProjection.js';
3
3
  import {Transformation} from '../../geometry/Transformation.js';
4
4
  /** @import {Projection} from '../projection/index.js' */
5
5
 
@@ -17,7 +17,7 @@ export class EPSG4326 extends EarthCRS {
17
17
  /** @type {string} */
18
18
  static code = 'EPSG:4326';
19
19
  /** @type {Projection} */
20
- static projection = LonLat;
20
+ static projection = LonLatProjection;
21
21
  /** @type {Transformation} */
22
- static transformation = new Transformation(1 / 180, 1, -1 / 180, 0.5);
22
+ static transformation = /* @__PURE__ */ new Transformation(1 / 180, 1, -1 / 180, 0.5);
23
23
  }
@@ -1,4 +1,5 @@
1
1
  import {CRS} from './CRS.js';
2
+ import {haversineDistance} from '../LatLng.js';
2
3
  /** @import {LatLng} from '../LatLng.js' */
3
4
 
4
5
  /**
@@ -30,13 +31,6 @@ export class EarthCRS extends CRS {
30
31
  * @returns {number}
31
32
  */
32
33
  static distance(latlng1, latlng2) {
33
- const rad = Math.PI / 180,
34
- lat1 = latlng1.lat * rad,
35
- lat2 = latlng2.lat * rad,
36
- sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2),
37
- sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2),
38
- a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon,
39
- c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
40
- return this.R * c;
34
+ return haversineDistance(latlng1, latlng2, this.R);
41
35
  }
42
36
  }
@@ -1,5 +1,5 @@
1
1
  import {CRS} from './CRS.js';
2
- import {LonLat} from '../projection/Projection.LonLat.js';
2
+ import {LonLatProjection} from '../projection/LonLatProjection.js';
3
3
  import {Transformation} from '../../geometry/Transformation.js';
4
4
  /** @import {LatLng} from '../LatLng.js' */
5
5
  /** @import {Projection} from '../projection/index.js' */
@@ -12,9 +12,9 @@ import {Transformation} from '../../geometry/Transformation.js';
12
12
  */
13
13
  export class SimpleCRS extends CRS {
14
14
  /** @type {Projection} */
15
- static projection = LonLat;
15
+ static projection = LonLatProjection;
16
16
  /** @type {Transformation} */
17
- static transformation = new Transformation(1, 0, -1, 0);
17
+ static transformation = /* @__PURE__ */ new Transformation(1, 0, -1, 0);
18
18
 
19
19
  /**
20
20
  * Returns `2^zoom`.
package/src/geo/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export {LatLng} from './LatLng.js';
2
2
  export {LatLngBounds} from './LatLngBounds.js';
3
3
 
4
- import * as Projection from './projection/index.js';
5
- export {Projection};
4
+ export * from './projection/index.js';
6
5
 
7
6
  export * from './crs/index.js';
@@ -11,7 +11,7 @@ import {Point} from '../../geometry/Point.js';
11
11
  * `EPSG4326` and `SimpleCRS` CRS.
12
12
  * @type {Projection}
13
13
  */
14
- export const LonLat = {
14
+ export const LonLatProjection = {
15
15
  project(latlng) {
16
16
  latlng = LatLng.from(latlng);
17
17
  return new Point(latlng.lng, latlng.lat);
@@ -22,5 +22,5 @@ export const LonLat = {
22
22
  return new LatLng(point.y, point.x);
23
23
  },
24
24
 
25
- bounds: new Bounds([-180, -90], [180, 90])
25
+ bounds: /* @__PURE__ */ new Bounds([-180, -90], [180, 90])
26
26
  };
@@ -11,11 +11,11 @@ const earthRadius = 6378137;
11
11
  * Earth is an ellipsoid. Used by the EPSG:3395 CRS.
12
12
  * @type {Projection & {R: number, R_MINOR: number}}
13
13
  */
14
- export const Mercator = {
14
+ export const MercatorProjection = {
15
15
  R: earthRadius,
16
16
  R_MINOR: 6356752.314245179,
17
17
 
18
- bounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
18
+ bounds: /* @__PURE__ */ new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
19
19
 
20
20
  project(latlng) {
21
21
  latlng = LatLng.from(latlng);
@@ -12,7 +12,7 @@ const earthRadius = 6378137;
12
12
  * a sphere. Used by the `EPSG:3857` CRS.
13
13
  * @type {Projection & {R: number, MAX_LATITUDE: number}}
14
14
  */
15
- export const SphericalMercator = {
15
+ export const SphericalMercatorProjection = {
16
16
 
17
17
  R: earthRadius,
18
18
  MAX_LATITUDE: 85.0511287798,
@@ -38,7 +38,7 @@ export const SphericalMercator = {
38
38
  point.x * d / this.R);
39
39
  },
40
40
 
41
- bounds: (() => {
41
+ bounds: /* @__PURE__ */ (() => {
42
42
  const d = earthRadius * Math.PI;
43
43
  return new Bounds([-d, -d], [d, d]);
44
44
  })()
@@ -6,8 +6,8 @@
6
6
  * An object with methods for projecting geographical coordinates of the world onto
7
7
  * a flat surface (and back). See [Map projection](https://en.wikipedia.org/wiki/Map_projection).
8
8
  *
9
- * Maplair comes with a set of already defined projections out of the box: `LonLat`,
10
- * `Mercator` and `SphericalMercator` (in the `Projection` namespace).
9
+ * Maplair comes with a set of already defined projections out of the box:
10
+ * `LonLatProjection`, `MercatorProjection` and `SphericalMercatorProjection`.
11
11
  *
12
12
  * Note that the projection instances do not inherit from Maplair's `Class` object,
13
13
  * and can't be instantiated. Also, new classes can't inherit from them,
@@ -23,6 +23,6 @@
23
23
  * arrays.
24
24
  */
25
25
 
26
- export {LonLat} from './Projection.LonLat.js';
27
- export {Mercator} from './Projection.Mercator.js';
28
- export {SphericalMercator} from './Projection.SphericalMercator.js';
26
+ export {LonLatProjection} from './LonLatProjection.js';
27
+ export {MercatorProjection} from './MercatorProjection.js';
28
+ export {SphericalMercatorProjection} from './SphericalMercatorProjection.js';
@@ -84,17 +84,14 @@ export class Bounds {
84
84
  let min2, max2;
85
85
  if (!obj) { return this; }
86
86
 
87
- if (obj instanceof Point || typeof obj[0] === 'number' || 'x' in obj) {
87
+ if (isPointExpression(obj)) {
88
88
  min2 = max2 = Point.from(obj);
89
89
  } else {
90
- obj = Bounds.from(obj);
91
- min2 = obj.min;
92
- max2 = obj.max;
93
-
94
- if (!min2 || !max2) { return this; }
90
+ ({min: min2, max: max2} = Bounds.from(obj));
91
+ if (!min2) { return this; }
95
92
  }
96
93
 
97
- if (!this.min && !this.max) {
94
+ if (!this.min) {
98
95
  this.min = new Point(min2);
99
96
  this.max = new Point(max2);
100
97
  } else {
@@ -165,17 +162,10 @@ export class Bounds {
165
162
  contains(obj) {
166
163
  let min, max;
167
164
 
168
- if (typeof obj[0] === 'number' || obj instanceof Point) {
169
- obj = Point.from(obj);
170
- } else {
171
- obj = Bounds.from(obj);
172
- }
173
-
174
- if (obj instanceof Bounds) {
175
- min = obj.min;
176
- max = obj.max;
165
+ if (isPointExpression(obj)) {
166
+ min = max = Point.from(obj);
177
167
  } else {
178
- min = max = obj;
168
+ ({min, max} = Bounds.from(obj));
179
169
  }
180
170
 
181
171
  return (min.x >= this.min.x) &&
@@ -265,3 +255,8 @@ export class Bounds {
265
255
  this.max.equals(bounds.getBottomRight());
266
256
  }
267
257
  }
258
+
259
+ // Whether `obj` is a point (or an array or object literal of one) rather than bounds
260
+ function isPointExpression(obj) {
261
+ return obj instanceof Point || (Array.isArray(obj) ? typeof obj[0] === 'number' : 'x' in obj);
262
+ }
@@ -1,7 +1,5 @@
1
1
  import {Point} from './Point.js';
2
2
  import {LatLng} from '../geo/LatLng.js';
3
- import {centroid} from './PolyUtil.js';
4
- import {LatLngBounds} from '../geo/LatLngBounds.js';
5
3
  /** @import {LatLngExpression} from '../geo/LatLng.js' */
6
4
  /** @import {Bounds} from './Bounds.js' */
7
5
  /** @import {CRS} from '../geo/crs/CRS.js' */
@@ -139,6 +137,7 @@ let _lastCode;
139
137
  * @returns {[Point, Point]|false}
140
138
  */
141
139
  export function clipSegment(a, b, bounds, useLastCode, round) {
140
+ const a0 = a, b0 = b;
142
141
  let codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),
143
142
  codeB = _getBitCode(b, bounds),
144
143
 
@@ -150,6 +149,12 @@ export function clipSegment(a, b, bounds, useLastCode, round) {
150
149
  while (true) {
151
150
  // if a,b is inside the clip window (trivial accept)
152
151
  if (!(codeA | codeB)) {
152
+ // round only the endpoints that were replaced by a clipped intersection;
153
+ // rounding while iterating can push a point back outside and loop forever
154
+ if (round) {
155
+ if (a !== a0) { a = a.round(); }
156
+ if (b !== b0) { b = b.round(); }
157
+ }
153
158
  return [a, b];
154
159
  }
155
160
 
@@ -160,7 +165,7 @@ export function clipSegment(a, b, bounds, useLastCode, round) {
160
165
 
161
166
  // other cases
162
167
  codeOut = codeA || codeB;
163
- p = _getEdgeIntersection(a, b, codeOut, bounds, round);
168
+ p = _getEdgeIntersection(a, b, codeOut, bounds);
164
169
  newCode = _getBitCode(p, bounds);
165
170
 
166
171
  if (codeOut === codeA) {
@@ -270,59 +275,53 @@ export function isFlat(latlngs) {
270
275
  * @returns {LatLng}
271
276
  */
272
277
  export function polylineCenter(latlngs, crs) {
273
- let i, halfDist, segDist, dist, p1, p2, ratio, center;
274
-
275
- if (!latlngs || latlngs.length === 0) {
276
- throw new Error('latlngs not passed');
277
- }
278
+ const points = _projectRing(latlngs, crs),
279
+ len = points.length;
278
280
 
279
- if (!isFlat(latlngs)) {
280
- console.warn('latlngs are not flat! Only the first ring will be used');
281
- latlngs = latlngs[0];
281
+ let halfDist = 0;
282
+ for (let i = 1; i < len; i++) {
283
+ halfDist += points[i - 1].distanceTo(points[i]);
282
284
  }
283
-
284
- let centroidLatLng = new LatLng([0, 0]);
285
-
286
- const bounds = new LatLngBounds(latlngs);
287
- const areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());
288
- // tests showed that below 1700 rounding errors are happening
289
- if (areaBounds < 1700) {
290
- // getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors
291
- centroidLatLng = centroid(latlngs);
285
+ halfDist /= 2;
286
+
287
+ // if the line has zero length, the loop below never finds a segment and the first point is the center
288
+ let center = points[0];
289
+
290
+ for (let i = 1, dist = 0; i < len; i++) {
291
+ const p1 = points[i - 1],
292
+ p2 = points[i],
293
+ segDist = p1.distanceTo(p2);
294
+ dist += segDist;
295
+
296
+ if (dist > halfDist) {
297
+ const ratio = (dist - halfDist) / segDist;
298
+ center = new Point(
299
+ p2.x - ratio * (p2.x - p1.x),
300
+ p2.y - ratio * (p2.y - p1.y)
301
+ );
302
+ break;
303
+ }
292
304
  }
293
305
 
294
- const len = latlngs.length;
295
- const points = [];
296
- for (i = 0; i < len; i++) {
297
- const latlng = new LatLng(latlngs[i]);
298
- points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
299
- }
306
+ return crs.unproject(center);
307
+ }
300
308
 
301
- for (i = 0, halfDist = 0; i < len - 1; i++) {
302
- halfDist += points[i].distanceTo(points[i + 1]) / 2;
309
+ /**
310
+ * Projects the first ring of the given latlngs.
311
+ * @internal
312
+ * @param {LatLngExpression[]|LatLngExpression[][]} latlngs
313
+ * @param {typeof CRS} crs
314
+ * @returns {Point[]}
315
+ */
316
+ export function _projectRing(latlngs, crs) {
317
+ if (!latlngs || latlngs.length === 0) {
318
+ throw new Error('latlngs not passed');
303
319
  }
304
320
 
305
- // The line is so small in the current view that all points are on the same pixel.
306
- if (halfDist === 0) {
307
- center = points[0];
308
- } else {
309
- for (i = 0, dist = 0; i < len - 1; i++) {
310
- p1 = points[i];
311
- p2 = points[i + 1];
312
- segDist = p1.distanceTo(p2);
313
- dist += segDist;
314
-
315
- if (dist > halfDist) {
316
- ratio = (dist - halfDist) / segDist;
317
- center = [
318
- p2.x - ratio * (p2.x - p1.x),
319
- p2.y - ratio * (p2.y - p1.y)
320
- ];
321
- break;
322
- }
323
- }
321
+ if (!isFlat(latlngs)) {
322
+ console.warn('latlngs are not flat! Only the first ring will be used');
323
+ return _projectRing(latlngs[0], crs);
324
324
  }
325
325
 
326
- const latlngCenter = crs.unproject(new Point(center));
327
- return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
326
+ return latlngs.map(latlng => crs.project(LatLng.from(latlng)));
328
327
  }
@@ -1,7 +1,6 @@
1
1
  import * as LineUtil from './LineUtil.js';
2
2
  import {LatLng} from '../geo/LatLng.js';
3
3
  import {Point} from './Point.js';
4
- import {LatLngBounds} from '../geo/LatLngBounds.js';
5
4
  /** @import {LatLngExpression} from '../geo/LatLng.js' */
6
5
  /** @import {Bounds} from './Bounds.js' */
7
6
  /** @import {CRS} from '../geo/crs/CRS.js' */
@@ -20,41 +19,26 @@ import {LatLngBounds} from '../geo/LatLngBounds.js';
20
19
  * @returns {Point[]}
21
20
  */
22
21
  export function clipPolygon(points, bounds, round) {
23
- let clippedPoints,
24
- i, j, k,
25
- a, b,
26
- len, edge, p;
27
- const edges = [1, 4, 2, 8];
28
-
29
- for (i = 0, len = points.length; i < len; i++) {
30
- points[i]._code = LineUtil._getBitCode(points[i], bounds);
31
- }
32
-
33
- // for each edge (left, bottom, right, top)
34
- for (k = 0; k < 4; k++) {
35
- edge = edges[k];
36
- clippedPoints = [];
37
-
38
- for (i = 0, len = points.length, j = len - 1; i < len; j = i++) {
39
- a = points[i];
40
- b = points[j];
41
-
42
- // if a is inside the clip window
43
- if (!(a._code & edge)) {
44
- // if b is outside the clip window (a->b goes out of screen)
45
- if (b._code & edge) {
46
- p = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);
47
- p._code = LineUtil._getBitCode(p, bounds);
48
- clippedPoints.push(p);
49
- }
22
+ // left, bottom, right, top
23
+ for (const edge of [1, 4, 2, 8]) {
24
+ if (!points.length) { break; }
25
+
26
+ /** @type {Point[]} */
27
+ const clippedPoints = [];
28
+ let b = points[points.length - 1],
29
+ bOut = isOutside(b, edge, bounds);
30
+
31
+ for (const a of points) {
32
+ const aOut = isOutside(a, edge, bounds);
33
+ // a->b crosses the edge
34
+ if (aOut !== bOut) {
35
+ clippedPoints.push(LineUtil._getEdgeIntersection(b, a, edge, bounds, round));
36
+ }
37
+ if (!aOut) {
50
38
  clippedPoints.push(a);
51
-
52
- // else if b is inside the clip window (a->b enters the screen)
53
- } else if (!(b._code & edge)) {
54
- p = LineUtil._getEdgeIntersection(b, a, edge, bounds, round);
55
- p._code = LineUtil._getBitCode(p, bounds);
56
- clippedPoints.push(p);
57
39
  }
40
+ b = a;
41
+ bOut = aOut;
58
42
  }
59
43
  points = clippedPoints;
60
44
  }
@@ -62,6 +46,13 @@ export function clipPolygon(points, bounds, round) {
62
46
  return points;
63
47
  }
64
48
 
49
+ // Whether the point is outside the given edge of the bounds; the edge is a `LineUtil` clipping bit code
50
+ function isOutside(p, edge, bounds) {
51
+ return edge === 1 ? p.x < bounds.min.x :
52
+ edge === 2 ? p.x > bounds.max.x :
53
+ edge === 4 ? p.y < bounds.min.y : p.y > bounds.max.y;
54
+ }
55
+
65
56
  /**
66
57
  * Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed
67
58
  * LatLngs (first ring) from a polygon.
@@ -70,56 +61,28 @@ export function clipPolygon(points, bounds, round) {
70
61
  * @returns {LatLng}
71
62
  */
72
63
  export function polygonCenter(latlngs, crs) {
73
- let i, j, p1, p2, f, area, x, y, center;
64
+ // points relative to the first one, to avoid floating point errors on tiny polygons with large projected coordinates
65
+ const points = LineUtil._projectRing(latlngs, crs),
66
+ origin = new Point(points[0]),
67
+ len = points.length;
74
68
 
75
- if (!latlngs || latlngs.length === 0) {
76
- throw new Error('latlngs not passed');
77
- }
69
+ for (const p of points) { p._subtract(origin); }
78
70
 
79
- if (!LineUtil.isFlat(latlngs)) {
80
- console.warn('latlngs are not flat! Only the first ring will be used');
81
- latlngs = latlngs[0];
82
- }
83
-
84
- let centroidLatLng = new LatLng([0, 0]);
85
-
86
- const bounds = new LatLngBounds(latlngs);
87
- const areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());
88
- // tests showed that below 1700 rounding errors are happening
89
- if (areaBounds < 1700) {
90
- // getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors
91
- centroidLatLng = centroid(latlngs);
92
- }
93
-
94
- const len = latlngs.length;
95
- const points = [];
96
- for (i = 0; i < len; i++) {
97
- const latlng = new LatLng(latlngs[i]);
98
- points.push(crs.project(new LatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
99
- }
100
-
101
- area = x = y = 0;
102
-
103
- // polygon centroid algorithm;
104
- for (i = 0, j = len - 1; i < len; j = i++) {
105
- p1 = points[i];
106
- p2 = points[j];
71
+ let area = 0, x = 0, y = 0;
107
72
 
73
+ // polygon centroid algorithm
74
+ for (let i = 0, j = len - 1; i < len; j = i++) {
75
+ const p1 = points[i],
76
+ p2 = points[j],
108
77
  f = p1.y * p2.x - p2.y * p1.x;
78
+
109
79
  x += (p1.x + p2.x) * f;
110
80
  y += (p1.y + p2.y) * f;
111
- area += f * 3;
112
- }
113
-
114
- if (area === 0) {
115
- // Polygon is so small that all points are on same pixel.
116
- center = points[0];
117
- } else {
118
- center = [x / area, y / area];
81
+ area += f;
119
82
  }
120
83
 
121
- const latlngCenter = crs.unproject(new Point(center));
122
- return new LatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
84
+ // area is 0 when the polygon is so small that all points are on the same pixel
85
+ return crs.unproject(area === 0 ? origin : new Point(x / (3 * area), y / (3 * area))._add(origin));
123
86
  }
124
87
 
125
88
  /**
@@ -45,12 +45,10 @@ import {Bounds} from '../geometry/Bounds.js';
45
45
  */
46
46
  export class BlanketOverlay extends Layer {
47
47
 
48
- static {
49
- this.setDefaultOptions({
50
- padding: 0.1,
51
- continuous: false,
52
- });
53
- }
48
+ static defaultOptions = {
49
+ padding: 0.1,
50
+ continuous: false,
51
+ };
54
52
 
55
53
  /**
56
54
  * @param {BlanketOverlayOptions} [options]
@@ -97,11 +95,9 @@ export class BlanketOverlay extends Layer {
97
95
  zoom: this._onZoom,
98
96
  moveend: this._onMoveEnd,
99
97
  resize: this._resizeContainer,
100
- zoomend: this._onZoomEnd
98
+ zoomend: this._onZoomEnd,
99
+ zoomanim: this._onAnimZoom
101
100
  };
102
- if (this._zoomAnimated) {
103
- events.zoomanim = this._onAnimZoom;
104
- }
105
101
  if (this.options.continuous) {
106
102
  events.move = this._onMoveEnd;
107
103
  }
@@ -81,16 +81,14 @@ const layerDivOverlayMethods = {
81
81
  */
82
82
  export class DivOverlay extends Layer {
83
83
 
84
- static {
85
- this.setDefaultOptions({
86
- interactive: false,
87
- offset: [0, 0],
88
- className: '',
89
- pane: undefined,
90
- overflow: false,
91
- content: ''
92
- });
93
- }
84
+ static defaultOptions = {
85
+ interactive: false,
86
+ offset: [0, 0],
87
+ className: '',
88
+ pane: undefined,
89
+ overflow: false,
90
+ content: ''
91
+ };
94
92
 
95
93
  /**
96
94
  * Instantiates an overlay given an optional `options` object that describes its
@@ -181,14 +179,12 @@ export class DivOverlay extends Layer {
181
179
  * @param {MaplairMap} map
182
180
  */
183
181
  onAdd(map) {
184
- this._zoomAnimated = map._zoomAnimated;
185
-
186
182
  if (!this._container) {
187
183
  this._initLayout();
188
184
  }
189
185
 
190
186
  if (map._fadeAnimated) {
191
- this._container.style.opacity = 0;
187
+ this._container.style.opacity = '0';
192
188
  }
193
189
 
194
190
  clearTimeout(this._removeTimeout);
@@ -205,7 +201,7 @@ export class DivOverlay extends Layer {
205
201
  this.update();
206
202
 
207
203
  if (map._fadeAnimated) {
208
- this._container.style.opacity = 1;
204
+ this._container.style.opacity = '1';
209
205
  }
210
206
 
211
207
  // A popover is shown on top already, re-showing it would skip the fade animation
@@ -230,7 +226,7 @@ export class DivOverlay extends Layer {
230
226
  }
231
227
 
232
228
  if (map._fadeAnimated) {
233
- this._container.style.opacity = 0;
229
+ this._container.style.opacity = '0';
234
230
  this._removeTimeout = setTimeout(() => this._container.remove(), 200);
235
231
  } else {
236
232
  this._container.remove();
@@ -330,12 +326,10 @@ export class DivOverlay extends Layer {
330
326
  getEvents() {
331
327
  const events = {
332
328
  zoom: this._updatePosition,
333
- viewreset: this._updatePosition
329
+ viewreset: this._updatePosition,
330
+ zoomanim: this._animateZoom
334
331
  };
335
332
 
336
- if (this._zoomAnimated) {
337
- events.zoomanim = this._animateZoom;
338
- }
339
333
  if (this.options.overflow) {
340
334
  events.move = this._updatePosition;
341
335
  }
@@ -449,15 +443,10 @@ export class DivOverlay extends Layer {
449
443
  _updatePosition() {
450
444
  if (!this._map) { return; }
451
445
 
452
- const pos = this._map.latLngToLayerPoint(this._latlng),
453
- anchor = this._getAnchor();
454
- let offset = Point.from(this.options.offset);
446
+ const pos = this._map.latLngToLayerPoint(this._latlng)._round(),
447
+ offset = Point.from(this.options.offset);
455
448
 
456
- if (this._zoomAnimated || this.options.overflow) {
457
- this._setContainerPosition(pos.add(anchor));
458
- } else {
459
- offset = offset.add(pos).add(anchor);
460
- }
449
+ this._setContainerPosition(pos.add(this._getAnchor()));
461
450
 
462
451
  const bottom = this._containerBottom = -offset.y,
463
452
  left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
@@ -115,14 +115,20 @@ export class FeatureGroup extends LayerGroup {
115
115
 
116
116
  /**
117
117
  * Returns the `LatLngBounds` of the feature group (created from bounds and
118
- * coordinates of its children).
118
+ * coordinates of its children, including the layers of nested layer groups).
119
119
  * @returns {LatLngBounds}
120
120
  */
121
121
  getBounds() {
122
122
  const bounds = new LatLngBounds();
123
123
 
124
124
  for (const layer of Object.values(this._layers)) {
125
- bounds.extend(layer.getBounds ? layer.getBounds() : layer.getLatLng());
125
+ if (layer.getBounds) {
126
+ bounds.extend(layer.getBounds());
127
+ } else if (layer.getLatLng) {
128
+ bounds.extend(layer.getLatLng());
129
+ } else if (layer instanceof LayerGroup) {
130
+ bounds.extend(FeatureGroup.prototype.getBounds.call(layer));
131
+ }
126
132
  }
127
133
  return bounds;
128
134
  }