maplair 4.0.0 → 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 (270) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/dist/esm/Maplair.js +14 -14
  3. package/dist/esm/control/AttributionControl.js +24 -14
  4. package/dist/esm/control/AttributionControl.js.map +1 -1
  5. package/dist/esm/control/ButtonControl.js +9 -11
  6. package/dist/esm/control/ButtonControl.js.map +1 -1
  7. package/dist/esm/control/ContextMenu.js +1 -3
  8. package/dist/esm/control/ContextMenu.js.map +1 -1
  9. package/dist/esm/control/Control.js +9 -16
  10. package/dist/esm/control/Control.js.map +1 -1
  11. package/dist/esm/control/FullscreenControl.js +5 -7
  12. package/dist/esm/control/FullscreenControl.js.map +1 -1
  13. package/dist/esm/control/LayersControl.js +144 -35
  14. package/dist/esm/control/LayersControl.js.map +1 -1
  15. package/dist/esm/control/LegendControl.js +7 -9
  16. package/dist/esm/control/LegendControl.js.map +1 -1
  17. package/dist/esm/control/MiniMapControl.js +14 -16
  18. package/dist/esm/control/MiniMapControl.js.map +1 -1
  19. package/dist/esm/control/RotateControl.js +1 -3
  20. package/dist/esm/control/RotateControl.js.map +1 -1
  21. package/dist/esm/control/ScaleControl.js +7 -9
  22. package/dist/esm/control/ScaleControl.js.map +1 -1
  23. package/dist/esm/control/SearchControl.js +99 -17
  24. package/dist/esm/control/SearchControl.js.map +1 -1
  25. package/dist/esm/control/SideBySideControl.js +1 -3
  26. package/dist/esm/control/SideBySideControl.js.map +1 -1
  27. package/dist/esm/control/TextControl.js +5 -7
  28. package/dist/esm/control/TextControl.js.map +1 -1
  29. package/dist/esm/control/TimeControl.js +408 -0
  30. package/dist/esm/control/TimeControl.js.map +1 -0
  31. package/dist/esm/control/ZoomControl.js +5 -7
  32. package/dist/esm/control/ZoomControl.js.map +1 -1
  33. package/dist/esm/core/Class.js +28 -37
  34. package/dist/esm/core/Class.js.map +1 -1
  35. package/dist/esm/core/Events.js +21 -8
  36. package/dist/esm/core/Events.js.map +1 -1
  37. package/dist/esm/core/Handler.js +13 -11
  38. package/dist/esm/core/Handler.js.map +1 -1
  39. package/dist/esm/core/Util.js +13 -1
  40. package/dist/esm/core/Util.js.map +1 -1
  41. package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
  42. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  43. package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
  44. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  45. package/dist/esm/dom/DomEvent.js +8 -42
  46. package/dist/esm/dom/DomEvent.js.map +1 -1
  47. package/dist/esm/dom/DomUtil.js +14 -68
  48. package/dist/esm/dom/DomUtil.js.map +1 -1
  49. package/dist/esm/dom/Draggable.js +17 -18
  50. package/dist/esm/dom/Draggable.js.map +1 -1
  51. package/dist/esm/dom/PosAnimation.js +3 -25
  52. package/dist/esm/dom/PosAnimation.js.map +1 -1
  53. package/dist/esm/geo/LatLng.js +15 -5
  54. package/dist/esm/geo/LatLng.js.map +1 -1
  55. package/dist/esm/geo/crs/EPSG3395.js +1 -1
  56. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  57. package/dist/esm/geo/crs/EPSG3857.js +1 -1
  58. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  59. package/dist/esm/geo/crs/EPSG4326.js +1 -1
  60. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  61. package/dist/esm/geo/crs/EarthCRS.js +2 -2
  62. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  63. package/dist/esm/geo/crs/SimpleCRS.js +1 -1
  64. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  65. package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
  66. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
  67. package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
  68. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
  69. package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
  70. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
  71. package/dist/esm/geometry/LineUtil.js +36 -30
  72. package/dist/esm/geometry/LineUtil.js.map +1 -1
  73. package/dist/esm/geometry/PolyUtil.js +8 -27
  74. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  75. package/dist/esm/layer/BlanketOverlay.js +6 -8
  76. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  77. package/dist/esm/layer/DivOverlay.js +15 -20
  78. package/dist/esm/layer/DivOverlay.js.map +1 -1
  79. package/dist/esm/layer/GeoJSON.js +9 -145
  80. package/dist/esm/layer/GeoJSON.js.map +1 -1
  81. package/dist/esm/layer/GeoJSONUtil.js +75 -0
  82. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  83. package/dist/esm/layer/HeatLayer.js +15 -17
  84. package/dist/esm/layer/HeatLayer.js.map +1 -1
  85. package/dist/esm/layer/ImageOverlay.js +20 -26
  86. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  87. package/dist/esm/layer/Layer.js +8 -10
  88. package/dist/esm/layer/Layer.js.map +1 -1
  89. package/dist/esm/layer/LayerGroup.js +51 -0
  90. package/dist/esm/layer/LayerGroup.js.map +1 -1
  91. package/dist/esm/layer/Popup.js +26 -42
  92. package/dist/esm/layer/Popup.js.map +1 -1
  93. package/dist/esm/layer/SVGOverlay.js +2 -5
  94. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  95. package/dist/esm/layer/Tooltip.js +15 -17
  96. package/dist/esm/layer/Tooltip.js.map +1 -1
  97. package/dist/esm/layer/VideoOverlay.js +12 -15
  98. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  99. package/dist/esm/layer/marker/DefaultIcon.js +15 -48
  100. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  101. package/dist/esm/layer/marker/DivIcon.js +7 -9
  102. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  103. package/dist/esm/layer/marker/Icon.js +7 -10
  104. package/dist/esm/layer/marker/Icon.js.map +1 -1
  105. package/dist/esm/layer/marker/Marker.Drag.js +1 -1
  106. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  107. package/dist/esm/layer/marker/Marker.Move.js +1 -2
  108. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  109. package/dist/esm/layer/marker/Marker.js +61 -33
  110. package/dist/esm/layer/marker/Marker.js.map +1 -1
  111. package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
  112. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  113. package/dist/esm/layer/marker/SvgIcon.js +6 -8
  114. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  115. package/dist/esm/layer/tile/GridLayer.js +85 -97
  116. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  117. package/dist/esm/layer/tile/TileLayer.js +28 -36
  118. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  119. package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
  120. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  121. package/dist/esm/layer/vector/Canvas.js +1 -3
  122. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  123. package/dist/esm/layer/vector/Circle.js +2 -2
  124. package/dist/esm/layer/vector/Circle.js.map +1 -1
  125. package/dist/esm/layer/vector/CircleMarker.js +17 -7
  126. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  127. package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
  128. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  129. package/dist/esm/layer/vector/Path.js +27 -20
  130. package/dist/esm/layer/vector/Path.js.map +1 -1
  131. package/dist/esm/layer/vector/Polygon.js +20 -4
  132. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  133. package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
  134. package/dist/esm/layer/vector/Polyline.js +23 -7
  135. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  136. package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
  137. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  138. package/dist/esm/layer/vector/SVG.js +5 -5
  139. package/dist/esm/layer/vector/SVG.js.map +1 -1
  140. package/dist/esm/map/Map.Rotation.js +10 -6
  141. package/dist/esm/map/Map.Rotation.js.map +1 -1
  142. package/dist/esm/map/Map.js +116 -110
  143. package/dist/esm/map/Map.js.map +1 -1
  144. package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
  145. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  146. package/dist/esm/map/handler/DisplaceHandler.js +6 -8
  147. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  148. package/dist/esm/map/handler/DragHandler.js +19 -19
  149. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  150. package/dist/esm/map/handler/KeyboardHandler.js +35 -35
  151. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  152. package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
  153. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  154. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
  155. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  156. package/dist/esm/map/handler/TapHoldHandler.js +12 -5
  157. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  158. package/dist/esm/package.js +1 -1
  159. package/dist/maplair-global-src.js +8009 -7369
  160. package/dist/maplair-global-src.js.map +1 -1
  161. package/dist/maplair-global.js +2 -2
  162. package/dist/maplair-global.js.map +1 -1
  163. package/dist/maplair-src.js +10040 -9381
  164. package/dist/maplair-src.js.map +1 -1
  165. package/dist/maplair.css +148 -98
  166. package/dist/maplair.js +2 -2
  167. package/dist/maplair.js.map +1 -1
  168. package/i18n/cs.json +6 -0
  169. package/i18n/de.json +6 -0
  170. package/i18n/en.json +6 -0
  171. package/i18n/es.json +6 -0
  172. package/i18n/fr.json +6 -0
  173. package/i18n/hu.json +6 -0
  174. package/i18n/it.json +6 -0
  175. package/i18n/rm.json +6 -0
  176. package/i18n/sk.json +6 -0
  177. package/i18n/sl.json +6 -0
  178. package/package.json +9 -11
  179. package/src/control/AttributionControl.js +25 -18
  180. package/src/control/ButtonControl.js +9 -11
  181. package/src/control/ContextMenu.js +3 -5
  182. package/src/control/Control.js +9 -19
  183. package/src/control/FullscreenControl.js +5 -7
  184. package/src/control/LayersControl.js +159 -36
  185. package/src/control/LegendControl.js +7 -9
  186. package/src/control/MiniMapControl.js +9 -11
  187. package/src/control/RotateControl.js +3 -5
  188. package/src/control/ScaleControl.js +7 -9
  189. package/src/control/SearchControl.js +102 -19
  190. package/src/control/SideBySideControl.js +3 -5
  191. package/src/control/TextControl.js +5 -7
  192. package/src/control/TimeControl.js +471 -0
  193. package/src/control/ZoomControl.js +5 -7
  194. package/src/control/index.js +1 -0
  195. package/src/core/Class.js +35 -34
  196. package/src/core/Events.js +22 -3
  197. package/src/core/Handler.js +14 -12
  198. package/src/core/Util.js +19 -1
  199. package/src/core/index.js +0 -1
  200. package/src/dom/DomEvent.DoubleTap.js +18 -10
  201. package/src/dom/DomEvent.PointerEvents.js +3 -26
  202. package/src/dom/DomEvent.js +8 -66
  203. package/src/dom/DomUtil.js +22 -78
  204. package/src/dom/Draggable.js +27 -22
  205. package/src/dom/PosAnimation.js +3 -25
  206. package/src/dom/index.js +0 -1
  207. package/src/geo/LatLng.js +20 -3
  208. package/src/geo/crs/EPSG3395.js +1 -1
  209. package/src/geo/crs/EPSG3857.js +1 -1
  210. package/src/geo/crs/EPSG4326.js +1 -1
  211. package/src/geo/crs/EarthCRS.js +2 -8
  212. package/src/geo/crs/SimpleCRS.js +1 -1
  213. package/src/geo/projection/Projection.LonLat.js +1 -1
  214. package/src/geo/projection/Projection.Mercator.js +1 -1
  215. package/src/geo/projection/Projection.SphericalMercator.js +1 -1
  216. package/src/geometry/LineUtil.js +47 -48
  217. package/src/geometry/PolyUtil.js +14 -43
  218. package/src/layer/BlanketOverlay.js +6 -10
  219. package/src/layer/DivOverlay.js +15 -26
  220. package/src/layer/GeoJSON.js +7 -205
  221. package/src/layer/GeoJSONUtil.js +85 -0
  222. package/src/layer/HeatLayer.js +9 -11
  223. package/src/layer/ImageOverlay.js +19 -30
  224. package/src/layer/Layer.js +8 -10
  225. package/src/layer/LayerGroup.js +71 -0
  226. package/src/layer/Popup.js +28 -43
  227. package/src/layer/SVGOverlay.js +1 -5
  228. package/src/layer/Tooltip.js +15 -19
  229. package/src/layer/VideoOverlay.js +12 -15
  230. package/src/layer/marker/DefaultIcon.js +15 -61
  231. package/src/layer/marker/DivIcon.js +9 -11
  232. package/src/layer/marker/Icon.js +7 -10
  233. package/src/layer/marker/Marker.Drag.js +1 -1
  234. package/src/layer/marker/Marker.Move.js +1 -2
  235. package/src/layer/marker/Marker.js +81 -39
  236. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  237. package/src/layer/marker/SvgIcon.js +7 -9
  238. package/src/layer/marker/index.js +1 -0
  239. package/src/layer/tile/GridLayer.js +103 -133
  240. package/src/layer/tile/TileLayer.js +35 -43
  241. package/src/layer/tile/WMSTileLayer.js +26 -24
  242. package/src/layer/vector/Canvas.js +3 -5
  243. package/src/layer/vector/Circle.js +5 -2
  244. package/src/layer/vector/CircleMarker.js +17 -6
  245. package/src/layer/vector/Path.DashAnimation.js +1 -2
  246. package/src/layer/vector/Path.js +30 -21
  247. package/src/layer/vector/Polygon.js +28 -5
  248. package/src/layer/vector/Polyline.js +25 -6
  249. package/src/layer/vector/Renderer.getRenderer.js +17 -17
  250. package/src/layer/vector/SVG.js +5 -5
  251. package/src/map/Map.Rotation.js +12 -4
  252. package/src/map/Map.js +142 -133
  253. package/src/map/handler/BoxZoomHandler.js +9 -8
  254. package/src/map/handler/DisplaceHandler.js +6 -8
  255. package/src/map/handler/DragHandler.js +25 -28
  256. package/src/map/handler/KeyboardHandler.js +42 -48
  257. package/src/map/handler/PinchZoomHandler.js +16 -5
  258. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  259. package/src/map/handler/TapHoldHandler.js +15 -4
  260. package/src/map/index.js +1 -1
  261. package/src/maplair.css +148 -98
  262. package/dist/esm/core/Browser.js +0 -100
  263. package/dist/esm/core/Browser.js.map +0 -1
  264. package/dist/images/layers.svg +0 -1
  265. package/dist/images/marker-icon.svg +0 -1
  266. package/dist/images/marker-shadow.svg +0 -1
  267. package/src/core/Browser.js +0 -110
  268. package/src/images/layers.svg +0 -1
  269. package/src/images/marker-icon.svg +0 -1
  270. package/src/images/marker-shadow.svg +0 -1
@@ -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' */
@@ -232,6 +228,8 @@ export class GeoJSON extends FeatureGroup {
232
228
  }, options);
233
229
 
234
230
  if (geoLayer) {
231
+ // so toGeoJSON exports MultiPoint and GeometryCollection members with their own type
232
+ geoLayer.feature = GeoJSON.asFeature(g);
235
233
  layers.push(geoLayer);
236
234
  }
237
235
  }
@@ -292,10 +290,7 @@ export class GeoJSON extends FeatureGroup {
292
290
  * @returns {number[]}
293
291
  */
294
292
  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)];
293
+ return latLngToCoords(latlng, precision);
299
294
  }
300
295
 
301
296
  /**
@@ -310,16 +305,7 @@ export class GeoJSON extends FeatureGroup {
310
305
  * @returns {any[]}
311
306
  */
312
307
  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;
308
+ return latLngsToCoords(latlngs, levelsDeep, close, precision);
323
309
  }
324
310
 
325
311
  /**
@@ -329,9 +315,7 @@ export class GeoJSON extends FeatureGroup {
329
315
  * @returns {Feature}
330
316
  */
331
317
  static getFeature(layer, newGeometry) {
332
- return layer.feature ?
333
- {...layer.feature, geometry: newGeometry} :
334
- GeoJSON.asFeature(newGeometry);
318
+ return getFeature(layer, newGeometry);
335
319
  }
336
320
 
337
321
  /**
@@ -340,189 +324,7 @@ export class GeoJSON extends FeatureGroup {
340
324
  * @returns {Feature|FeatureCollection}
341
325
  */
342
326
  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
- };
327
+ return asFeature(geojson);
352
328
  }
353
329
 
354
330
  }
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
@@ -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
  }
@@ -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
 
@@ -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
  }