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,13 +1,9 @@
1
- import {LayerGroup} from './LayerGroup.js';
2
1
  import {FeatureGroup} from './FeatureGroup.js';
3
- import * as Util from '../core/Util.js';
4
2
  import {Marker} from './marker/Marker.js';
5
- import {Circle} from './vector/Circle.js';
6
- import {CircleMarker} from './vector/CircleMarker.js';
7
3
  import {Polyline} from './vector/Polyline.js';
8
4
  import {Polygon} from './vector/Polygon.js';
9
5
  import {LatLng} from '../geo/LatLng.js';
10
- import * as LineUtil from '../geometry/LineUtil.js';
6
+ import {latLngToCoords, latLngsToCoords, getFeature, asFeature} from './GeoJSONUtil.js';
11
7
 
12
8
  /** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */
13
9
  /** @import {Layer, InteractiveLayerOptions} from './Layer.js' */
@@ -113,33 +109,30 @@ export class GeoJSON extends FeatureGroup {
113
109
  * @returns {this}
114
110
  */
115
111
  addData(geojson) {
116
- const features = Array.isArray(geojson) ? geojson : geojson.features;
117
-
118
- if (features) {
119
- for (const feature of features) {
120
- // only add this if geometry or geometries are set and not null
121
- if (feature.geometries || feature.geometry || feature.features || feature.coordinates) {
122
- this.addData(feature);
123
- }
112
+ if (Array.isArray(geojson) || 'features' in geojson) {
113
+ for (const data of Array.isArray(geojson) ? geojson : geojson.features) {
114
+ this.addData(data);
124
115
  }
125
116
  return this;
126
117
  }
127
118
 
128
- const options = this.options;
119
+ const options = this.options,
120
+ feature = GeoJSON.asFeature(geojson);
129
121
 
130
- if (options.filter && !options.filter(geojson)) { return this; }
122
+ // skips features without a geometry
123
+ if (!feature.geometry || (options.filter && !options.filter(feature))) { return this; }
131
124
 
132
- const layer = GeoJSON.geometryToLayer(geojson, options);
125
+ const layer = GeoJSON.geometryToLayer(feature, options);
133
126
  if (!layer) {
134
127
  return this;
135
128
  }
136
- layer.feature = GeoJSON.asFeature(geojson);
129
+ layer.feature = feature;
137
130
 
138
131
  layer.defaultOptions = layer.options;
139
132
  this.resetStyle(layer);
140
133
 
141
134
  if (options.onEachFeature) {
142
- options.onEachFeature(geojson, layer);
135
+ options.onEachFeature(feature, layer);
143
136
  }
144
137
 
145
138
  return this.addLayer(layer);
@@ -232,6 +225,8 @@ export class GeoJSON extends FeatureGroup {
232
225
  }, options);
233
226
 
234
227
  if (geoLayer) {
228
+ // so toGeoJSON exports MultiPoint and GeometryCollection members with their own type
229
+ geoLayer.feature = GeoJSON.asFeature(g);
235
230
  layers.push(geoLayer);
236
231
  }
237
232
  }
@@ -292,10 +287,7 @@ export class GeoJSON extends FeatureGroup {
292
287
  * @returns {number[]}
293
288
  */
294
289
  static latLngToCoords(latlng, precision) {
295
- latlng = LatLng.from(latlng);
296
- return latlng.alt !== undefined ?
297
- [Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :
298
- [Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];
290
+ return latLngToCoords(latlng, precision);
299
291
  }
300
292
 
301
293
  /**
@@ -310,16 +302,7 @@ export class GeoJSON extends FeatureGroup {
310
302
  * @returns {any[]}
311
303
  */
312
304
  static latLngsToCoords(latlngs, levelsDeep, close, precision) {
313
- // Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion
314
- const coords = latlngs.map(latlng => (levelsDeep ?
315
- GeoJSON.latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :
316
- GeoJSON.latLngToCoords(latlng, precision)));
317
-
318
- if (!levelsDeep && close && coords.length > 0) {
319
- coords.push(coords[0].slice());
320
- }
321
-
322
- return coords;
305
+ return latLngsToCoords(latlngs, levelsDeep, close, precision);
323
306
  }
324
307
 
325
308
  /**
@@ -329,9 +312,7 @@ export class GeoJSON extends FeatureGroup {
329
312
  * @returns {Feature}
330
313
  */
331
314
  static getFeature(layer, newGeometry) {
332
- return layer.feature ?
333
- {...layer.feature, geometry: newGeometry} :
334
- GeoJSON.asFeature(newGeometry);
315
+ return getFeature(layer, newGeometry);
335
316
  }
336
317
 
337
318
  /**
@@ -340,189 +321,7 @@ export class GeoJSON extends FeatureGroup {
340
321
  * @returns {Feature|FeatureCollection}
341
322
  */
342
323
  static asFeature(geojson) {
343
- if (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {
344
- return geojson;
345
- }
346
-
347
- return {
348
- type: 'Feature',
349
- properties: {},
350
- geometry: geojson
351
- };
324
+ return asFeature(geojson);
352
325
  }
353
326
 
354
327
  }
355
-
356
- /**
357
- * Methods of `Marker` (and `CircleMarker`, `Circle`) for GeoJSON.
358
- * @lends Marker.prototype
359
- */
360
- const PointToGeoJSON = {
361
- /**
362
- * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
363
- * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
364
- * representation of the marker (as a GeoJSON `Point` Feature).
365
- * @group Other methods
366
- * @param {number|false} [precision]
367
- * @returns {Feature}
368
- */
369
- toGeoJSON(precision) {
370
- return GeoJSON.getFeature(this, {
371
- type: 'Point',
372
- coordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)
373
- });
374
- }
375
- };
376
- /** @typedef {typeof PointToGeoJSON} PointToGeoJSONMethods */
377
-
378
- /**
379
- * Methods of `CircleMarker` (and `Circle`) for GeoJSON: `toGeoJSON(precision?)`
380
- * returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the
381
- * circle marker (as a GeoJSON `Point` Feature), with the coordinates values rounded
382
- * with [`formatNum`](#util-formatnum) function with given `precision`.
383
- * @typedef {object} CircleMarkerToGeoJSONMethods
384
- * @extends PointToGeoJSONMethods
385
- * @lends CircleMarker
386
- */
387
-
388
- Marker.include(PointToGeoJSON);
389
- Circle.include(PointToGeoJSON);
390
- CircleMarker.include(PointToGeoJSON);
391
-
392
- /**
393
- * Methods of `Polyline` for GeoJSON.
394
- * @lends Polyline.prototype
395
- */
396
- const polylineToGeoJSON = {
397
- /**
398
- * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
399
- * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
400
- * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`
401
- * Feature).
402
- * @param {number|false} [precision]
403
- * @returns {Feature}
404
- */
405
- toGeoJSON(precision) {
406
- const multi = !LineUtil.isFlat(this._latlngs);
407
-
408
- const coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);
409
-
410
- return GeoJSON.getFeature(this, {
411
- type: `${multi ? 'Multi' : ''}LineString`,
412
- coordinates: coords
413
- });
414
- }
415
- };
416
- /** @typedef {typeof polylineToGeoJSON} PolylineToGeoJSONMethods */
417
-
418
- Polyline.include(polylineToGeoJSON);
419
-
420
- /**
421
- * Methods of `Polygon` for GeoJSON.
422
- * @lends Polygon.prototype
423
- */
424
- const polygonToGeoJSON = {
425
- /**
426
- * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
427
- * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
428
- * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).
429
- * @param {number|false} [precision]
430
- * @returns {Feature}
431
- */
432
- toGeoJSON(precision) {
433
- const holes = !LineUtil.isFlat(this._latlngs),
434
- multi = holes && !LineUtil.isFlat(this._latlngs[0]);
435
-
436
- let coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);
437
-
438
- if (!holes) {
439
- coords = [coords];
440
- }
441
-
442
- return GeoJSON.getFeature(this, {
443
- type: `${multi ? 'Multi' : ''}Polygon`,
444
- coordinates: coords
445
- });
446
- }
447
- };
448
- /** @typedef {typeof polygonToGeoJSON} PolygonToGeoJSONMethods */
449
-
450
- Polygon.include(polygonToGeoJSON);
451
-
452
- /**
453
- * Methods of `LayerGroup` for GeoJSON.
454
- * @lends LayerGroup.prototype
455
- */
456
- const layerGroupToGeoJSON = {
457
- /**
458
- * Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by
459
- * `toGeoJSON()`.
460
- * @internal
461
- * @param {number|false} [precision]
462
- * @returns {Feature}
463
- */
464
- toMultiPoint(precision) {
465
- const coords = [];
466
-
467
- this.eachLayer((layer) => {
468
- coords.push(layer.toGeoJSON(precision).geometry.coordinates);
469
- });
470
-
471
- return GeoJSON.getFeature(this, {
472
- type: 'MultiPoint',
473
- coordinates: coords
474
- });
475
- },
476
-
477
- /**
478
- * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
479
- * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
480
- * representation of the layer group (as a GeoJSON `FeatureCollection`,
481
- * `GeometryCollection`, or `MultiPoint`).
482
- * @param {number|false} [precision]
483
- * @returns {Feature|FeatureCollection}
484
- */
485
- toGeoJSON(precision) {
486
-
487
- const type = this.feature?.geometry?.type;
488
-
489
- if (type === 'MultiPoint') {
490
- return this.toMultiPoint(precision);
491
- }
492
-
493
- const isGeometryCollection = type === 'GeometryCollection',
494
- jsons = [];
495
-
496
- this.eachLayer((layer) => {
497
- if (layer.toGeoJSON) {
498
- const json = layer.toGeoJSON(precision);
499
- if (isGeometryCollection) {
500
- jsons.push(json.geometry);
501
- } else {
502
- const feature = GeoJSON.asFeature(json);
503
- // Squash nested feature collections
504
- if (feature.type === 'FeatureCollection') {
505
- jsons.push(...feature.features);
506
- } else {
507
- jsons.push(feature);
508
- }
509
- }
510
- }
511
- });
512
-
513
- if (isGeometryCollection) {
514
- return GeoJSON.getFeature(this, {
515
- geometries: jsons,
516
- type: 'GeometryCollection'
517
- });
518
- }
519
-
520
- return {
521
- type: 'FeatureCollection',
522
- features: jsons
523
- };
524
- }
525
- };
526
- /** @typedef {typeof layerGroupToGeoJSON} LayerGroupToGeoJSONMethods */
527
-
528
- LayerGroup.include(layerGroupToGeoJSON);
@@ -0,0 +1,85 @@
1
+ import * as Util from '../core/Util.js';
2
+ import {LatLng} from '../geo/LatLng.js';
3
+ import * as LineUtil from '../geometry/LineUtil.js';
4
+
5
+ /** @import {Feature, FeatureCollection, GeoJsonObject, Geometry} from 'geojson' */
6
+ /** @import {Layer} from './Layer.js' */
7
+ /** @import {LatLngExpression} from '../geo/LatLng.js' */
8
+
9
+ // Shared by `GeoJSON` and the `toGeoJSON` methods of the layers it creates, which can't import `GeoJSON.js` without a cycle.
10
+
11
+ /**
12
+ * See `GeoJSON.latLngToCoords()`.
13
+ * @param {LatLngExpression} latlng
14
+ * @param {number|false} [precision]
15
+ * @returns {number[]}
16
+ */
17
+ export function latLngToCoords(latlng, precision) {
18
+ latlng = LatLng.from(latlng);
19
+ return latlng.alt !== undefined ?
20
+ [Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :
21
+ [Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];
22
+ }
23
+
24
+ /**
25
+ * See `GeoJSON.latLngsToCoords()`.
26
+ * @param {any[]} latlngs
27
+ * @param {number} [levelsDeep]
28
+ * @param {boolean} [close]
29
+ * @param {number|false} [precision]
30
+ * @returns {any[]}
31
+ */
32
+ export function latLngsToCoords(latlngs, levelsDeep, close, precision) {
33
+ // Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion
34
+ const coords = latlngs.map(latlng => (levelsDeep ?
35
+ latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :
36
+ latLngToCoords(latlng, precision)));
37
+
38
+ if (!levelsDeep && close && coords.length > 0) {
39
+ coords.push(coords[0].slice());
40
+ }
41
+
42
+ return coords;
43
+ }
44
+
45
+ /**
46
+ * See `GeoJSON.getFeature()`.
47
+ * @param {Layer} layer
48
+ * @param {Geometry} newGeometry
49
+ * @returns {Feature}
50
+ */
51
+ export function getFeature(layer, newGeometry) {
52
+ return layer.feature ?
53
+ {...layer.feature, geometry: newGeometry} :
54
+ asFeature(newGeometry);
55
+ }
56
+
57
+ /**
58
+ * See `GeoJSON.asFeature()`.
59
+ * @param {GeoJsonObject} geojson
60
+ * @returns {Feature|FeatureCollection}
61
+ */
62
+ export function asFeature(geojson) {
63
+ if (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {
64
+ return geojson;
65
+ }
66
+
67
+ return {
68
+ type: 'Feature',
69
+ properties: {},
70
+ geometry: geojson
71
+ };
72
+ }
73
+
74
+ /**
75
+ * The GeoJSON `Point` Feature of a layer with `getLatLng()`, for its `toGeoJSON()`.
76
+ * @param {Layer & {getLatLng(): LatLng}} layer
77
+ * @param {number|false} [precision]
78
+ * @returns {Feature}
79
+ */
80
+ export function pointToGeoJSON(layer, precision) {
81
+ return getFeature(layer, {
82
+ type: 'Point',
83
+ coordinates: latLngToCoords(layer.getLatLng(), precision)
84
+ });
85
+ }
@@ -39,17 +39,15 @@ import * as Util from '../core/Util.js';
39
39
  */
40
40
  export class HeatLayer extends BlanketOverlay {
41
41
 
42
- static {
43
- this.setDefaultOptions({
44
- radius: 25,
45
- blur: 15,
46
- max: 1,
47
- maxZoom: undefined,
48
- minOpacity: 0.05,
49
- gradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},
50
- pane: 'overlayPane'
51
- });
52
- }
42
+ static defaultOptions = {
43
+ radius: 25,
44
+ blur: 15,
45
+ max: 1,
46
+ maxZoom: undefined,
47
+ minOpacity: 0.05,
48
+ gradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},
49
+ pane: 'overlayPane'
50
+ };
53
51
 
54
52
  /**
55
53
  * Creates a heatmap of the given points: `LatLng`s or arrays
@@ -189,7 +187,7 @@ export class HeatLayer extends BlanketOverlay {
189
187
 
190
188
  // merge the points per grid cell, weighted by their intensity
191
189
  for (const latlng of this._latlngs) {
192
- const point = map.latLngToLayerPoint(latlng).subtract(offset);
190
+ const point = map.latLngToLayerPoint(latlng)._round()._subtract(offset);
193
191
  if (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }
194
192
  const intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,
195
193
  key = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,
@@ -58,19 +58,17 @@ import * as DomUtil from '../dom/DomUtil.js';
58
58
  */
59
59
  export class ImageOverlay extends Layer {
60
60
 
61
- static {
62
- this.setDefaultOptions({
63
- opacity: 1,
64
- alt: '',
65
- interactive: false,
66
- crossOrigin: false,
67
- errorOverlayUrl: '',
68
- zIndex: 1,
69
- className: '',
70
- pixelated: false,
71
- decoding: 'auto'
72
- });
73
- }
61
+ static defaultOptions = {
62
+ opacity: 1,
63
+ alt: '',
64
+ interactive: false,
65
+ crossOrigin: false,
66
+ errorOverlayUrl: '',
67
+ zIndex: 1,
68
+ className: '',
69
+ pixelated: false,
70
+ decoding: 'auto'
71
+ };
74
72
 
75
73
  /**
76
74
  * Instantiates an image overlay object given the URL of the image (or an image
@@ -214,16 +212,11 @@ export class ImageOverlay extends Layer {
214
212
  * @returns {Record<string, EventListener>}
215
213
  */
216
214
  getEvents() {
217
- const events = {
215
+ return {
218
216
  zoom: this._reset,
219
- viewreset: this._reset
217
+ viewreset: this._reset,
218
+ zoomanim: this._animateZoom
220
219
  };
221
-
222
- if (this._zoomAnimated) {
223
- events.zoomanim = this._animateZoom;
224
- }
225
-
226
- return events;
227
220
  }
228
221
 
229
222
  /**
@@ -257,16 +250,12 @@ export class ImageOverlay extends Layer {
257
250
  }
258
251
 
259
252
  _initImage() {
260
- const wasElementSupplied = this._url.tagName === 'IMG';
253
+ const wasElementSupplied = this._url instanceof HTMLImageElement;
261
254
  const img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');
262
255
 
263
- img.classList.add('maplair-image-layer');
264
- if (this._zoomAnimated) { img.classList.add('maplair-zoom-animated'); }
256
+ img.classList.add('maplair-image-layer', 'maplair-zoom-animated');
265
257
  if (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }
266
258
 
267
- img.onselectstart = Util.falseFn;
268
- img.onpointermove = Util.falseFn;
269
-
270
259
  img.onload = this.fire.bind(this, 'load');
271
260
  img.onerror = this._overlayOnError.bind(this);
272
261
 
@@ -291,7 +280,7 @@ export class ImageOverlay extends Layer {
291
280
 
292
281
  _animateZoom(e) {
293
282
  const scale = this._map.getZoomScale(e.zoom),
294
- offset = this._map._latLngBoundsToNewLayerBounds(this._bounds, e.zoom, e.center).min;
283
+ offset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center);
295
284
 
296
285
  DomUtil.setTransform(this._image, offset, scale);
297
286
  }
@@ -299,8 +288,8 @@ export class ImageOverlay extends Layer {
299
288
  _reset() {
300
289
  const image = this._image,
301
290
  bounds = new Bounds(
302
- this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
303
- this._map.latLngToLayerPoint(this._bounds.getSouthEast())),
291
+ this._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(),
292
+ this._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()),
304
293
  size = bounds.getSize();
305
294
 
306
295
  DomUtil.setPosition(image, bounds.min);
@@ -310,12 +299,12 @@ export class ImageOverlay extends Layer {
310
299
  }
311
300
 
312
301
  _updateOpacity() {
313
- this._image.style.opacity = this.options.opacity;
302
+ this._image.style.opacity = `${this.options.opacity}`;
314
303
  }
315
304
 
316
305
  _updateZIndex() {
317
306
  if (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {
318
- this._image.style.zIndex = this.options.zIndex;
307
+ this._image.style.zIndex = `${this.options.zIndex}`;
319
308
  }
320
309
  }
321
310
 
@@ -249,14 +249,12 @@ const mapLayerMethods = {
249
249
  */
250
250
  export class Layer extends Evented {
251
251
 
252
- static {
253
- this.setDefaultOptions({
254
- pane: 'overlayPane',
255
- attribution: null,
256
- attributionOrder: 0,
257
- bubblingPointerEvents: true
258
- });
259
- }
252
+ static defaultOptions = {
253
+ pane: 'overlayPane',
254
+ attribution: null,
255
+ attributionOrder: 0,
256
+ bubblingPointerEvents: true
257
+ };
260
258
 
261
259
  /**
262
260
  * Adds the layer to the given map or layer group.
@@ -354,9 +352,9 @@ export class Layer extends Evented {
354
352
  */
355
353
  setAttribution(attribution) {
356
354
  const control = this._map?.attributionControl;
357
- control?.removeAttribution(this.getAttribution());
355
+ control?._removeLayer({layer: this});
358
356
  Util.setOptions(this, {attribution});
359
- control?.addAttribution(this.getAttribution(), this.options.attributionOrder);
357
+ control?._addLayer({layer: this});
360
358
  return this;
361
359
  }
362
360
 
@@ -1,6 +1,8 @@
1
1
 
2
2
  import {Layer} from './Layer.js';
3
3
  import * as Util from '../core/Util.js';
4
+ import {getFeature, asFeature} from './GeoJSONUtil.js';
5
+ /** @import {Feature, FeatureCollection} from 'geojson' */
4
6
  /** @import {InteractiveLayerOptions} from './Layer.js' */
5
7
  /** @import {MaplairMap} from '../map/Map.js' */
6
8
 
@@ -58,7 +60,7 @@ export class LayerGroup extends Layer {
58
60
  * @returns {this}
59
61
  */
60
62
  removeLayer(layer) {
61
- const id = layer in this._layers ? layer : this.getLayerId(layer);
63
+ const id = typeof layer === 'number' ? layer : this.getLayerId(layer);
62
64
 
63
65
  if (this._map && this._layers[id]) {
64
66
  this._map.removeLayer(this._layers[id]);
@@ -157,4 +159,73 @@ export class LayerGroup extends Layer {
157
159
  getLayerId(layer) {
158
160
  return Util.stamp(layer);
159
161
  }
162
+
163
+ /**
164
+ * Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by
165
+ * `toGeoJSON()`.
166
+ * @internal
167
+ * @param {number|false} [precision]
168
+ * @returns {Feature}
169
+ */
170
+ toMultiPoint(precision) {
171
+ const coords = [];
172
+
173
+ this.eachLayer((layer) => {
174
+ coords.push(layer.toGeoJSON(precision).geometry.coordinates);
175
+ });
176
+
177
+ return getFeature(this, {
178
+ type: 'MultiPoint',
179
+ coordinates: coords
180
+ });
181
+ }
182
+
183
+ /**
184
+ * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
185
+ * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
186
+ * representation of the layer group (as a GeoJSON `FeatureCollection`,
187
+ * `GeometryCollection`, or `MultiPoint`).
188
+ * @param {number|false} [precision]
189
+ * @returns {Feature|FeatureCollection}
190
+ */
191
+ toGeoJSON(precision) {
192
+
193
+ const type = this.feature?.geometry?.type;
194
+
195
+ if (type === 'MultiPoint') {
196
+ return this.toMultiPoint(precision);
197
+ }
198
+
199
+ const isGeometryCollection = type === 'GeometryCollection',
200
+ jsons = [];
201
+
202
+ this.eachLayer((layer) => {
203
+ if (layer.toGeoJSON) {
204
+ const json = layer.toGeoJSON(precision);
205
+ if (isGeometryCollection) {
206
+ jsons.push(json.geometry);
207
+ } else {
208
+ const feature = asFeature(json);
209
+ // Squash nested feature collections
210
+ if (feature.type === 'FeatureCollection') {
211
+ jsons.push(...feature.features);
212
+ } else {
213
+ jsons.push(feature);
214
+ }
215
+ }
216
+ }
217
+ });
218
+
219
+ if (isGeometryCollection) {
220
+ return getFeature(this, {
221
+ geometries: jsons,
222
+ type: 'GeometryCollection'
223
+ });
224
+ }
225
+
226
+ return {
227
+ type: 'FeatureCollection',
228
+ features: jsons
229
+ };
230
+ }
160
231
  }