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 +1 @@
1
- {"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement`, or a function receiving the source layer and returning one of them.\n * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent\n */\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String` or `HTMLElement` to be used in the\n * overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tinteractive: false,\n\t\t\toffset: [0, 0],\n\t\t\tclassName: '',\n\t\t\tpane: undefined,\n\t\t\toverflow: false,\n\t\t\tcontent: ''\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 0;\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 1;\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 0;\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t * passed the source layer will be passed to the function. The function should\n\t * return a `String` or `HTMLElement` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition\n\t\t};\n\n\t\tif (this._zoomAnimated) {\n\t\t\tevents.zoomanim = this._animateZoom;\n\t\t}\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng),\n\t\tanchor = this._getAnchor();\n\t\tlet offset = Point.from(this.options.offset);\n\n\t\tif (this._zoomAnimated || this.options.overflow) {\n\t\t\tthis._setContainerPosition(pos.add(anchor));\n\t\t} else {\n\t\t\toffset = offset.add(pos).add(anchor);\n\t\t}\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;CAEzB,OAAO;AACR,EACD;;;;;;AAOA,MAAM,yBAAyB,EAC9B,aAAa,cAAc,KAAK,SAAS,SAAS;CACjD,IAAI,UAAU;CACd,IAAI,m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BAAiB,CAAC,KAAK,MAAM,KAAK,kBAAkB,CAAC,IAAI,OAAO;EAG5E,IAAI,KAAK,QAAQ,UAAU;GAE1B,KAAK,WAAW,MAAM,MAAM;GAC5B,KAAK,WAAW,MAAM,SAAS,eAAe,OAAO;EACtD,OACC,KAAK,WAAW,MAAM,SAAS,GAAG,OAAO;EAE1C,KAAK,WAAW,MAAM,OAAO,GAAG,KAAK;CACtC;CAIA,sBAAsB,KAAK;EAC1B,KAAK,gBAAgB;EACrB,IAAI,KAAK,QAAQ,UAAU;GAC1B,MAAM,eAAe,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
1
+ {"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement`, or a function receiving the source layer and returning one of them.\n * @typedef {string|HTMLElement|((layer: Layer) => string|HTMLElement)} DivOverlayContent\n */\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String` or `HTMLElement` to be used in the\n * overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t * passed the source layer will be passed to the function. The function should\n\t * return a `String` or `HTMLElement` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB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C,OAAO,GAC/C,OAAO,KAAK,iBAAiB,CAAC,KAAK,MAAM,KAAK,kBAAkB,CAAC,IAAI,OAAO;EAG5E,IAAI,KAAK,QAAQ,UAAU;GAE1B,KAAK,WAAW,MAAM,MAAM;GAC5B,KAAK,WAAW,MAAM,SAAS,eAAe,OAAO;EACtD,OACC,KAAK,WAAW,MAAM,SAAS,GAAG,OAAO;EAE1C,KAAK,WAAW,MAAM,OAAO,GAAG,KAAK;CACtC;CAIA,sBAAsB,KAAK;EAC1B,KAAK,gBAAgB;EACrB,IAAI,KAAK,QAAQ,UAAU;GAC1B,MAAM,eAAe,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
@@ -1,13 +1,9 @@
1
- import { formatNum } from "../core/Util.js";
2
1
  import { LatLng } from "../geo/LatLng.js";
3
- import { CircleMarker } from "./vector/CircleMarker.js";
4
- import { LayerGroup } from "./LayerGroup.js";
2
+ import { asFeature, getFeature, latLngToCoords, latLngsToCoords } from "./GeoJSONUtil.js";
5
3
  import { FeatureGroup } from "./FeatureGroup.js";
6
- import { isFlat } from "../geometry/LineUtil.js";
7
4
  import { Polyline } from "./vector/Polyline.js";
8
5
  import { Polygon } from "./vector/Polygon.js";
9
6
  import { Marker } from "./marker/Marker.js";
10
- import { Circle } from "./vector/Circle.js";
11
7
  //#region src/layer/GeoJSON.js
12
8
  /** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */
13
9
  /** @import {Layer, InteractiveLayerOptions} from './Layer.js' */
@@ -183,7 +179,10 @@ var GeoJSON = class GeoJSON extends FeatureGroup {
183
179
  type: "Feature",
184
180
  properties: geojson.properties
185
181
  }, options);
186
- if (geoLayer) layers.push(geoLayer);
182
+ if (geoLayer) {
183
+ geoLayer.feature = GeoJSON.asFeature(g);
184
+ layers.push(geoLayer);
185
+ }
187
186
  }
188
187
  return new FeatureGroup(layers);
189
188
  case "FeatureCollection":
@@ -228,12 +227,7 @@ var GeoJSON = class GeoJSON extends FeatureGroup {
228
227
  * @returns {number[]}
229
228
  */
230
229
  static latLngToCoords(latlng, precision) {
231
- latlng = LatLng.from(latlng);
232
- return latlng.alt !== void 0 ? [
233
- formatNum(latlng.lng, precision),
234
- formatNum(latlng.lat, precision),
235
- formatNum(latlng.alt, precision)
236
- ] : [formatNum(latlng.lng, precision), formatNum(latlng.lat, precision)];
230
+ return latLngToCoords(latlng, precision);
237
231
  }
238
232
  /**
239
233
  * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).
@@ -247,9 +241,7 @@ var GeoJSON = class GeoJSON extends FeatureGroup {
247
241
  * @returns {any[]}
248
242
  */
249
243
  static latLngsToCoords(latlngs, levelsDeep, close, precision) {
250
- const coords = latlngs.map((latlng) => levelsDeep ? GeoJSON.latLngsToCoords(latlng, isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) : GeoJSON.latLngToCoords(latlng, precision));
251
- if (!levelsDeep && close && coords.length > 0) coords.push(coords[0].slice());
252
- return coords;
244
+ return latLngsToCoords(latlngs, levelsDeep, close, precision);
253
245
  }
254
246
  /**
255
247
  * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.
@@ -258,10 +250,7 @@ var GeoJSON = class GeoJSON extends FeatureGroup {
258
250
  * @returns {Feature}
259
251
  */
260
252
  static getFeature(layer, newGeometry) {
261
- return layer.feature ? {
262
- ...layer.feature,
263
- geometry: newGeometry
264
- } : GeoJSON.asFeature(newGeometry);
253
+ return getFeature(layer, newGeometry);
265
254
  }
266
255
  /**
267
256
  * Normalize GeoJSON geometries/features into GeoJSON features.
@@ -269,134 +258,9 @@ var GeoJSON = class GeoJSON extends FeatureGroup {
269
258
  * @returns {Feature|FeatureCollection}
270
259
  */
271
260
  static asFeature(geojson) {
272
- if (geojson.type === "Feature" || geojson.type === "FeatureCollection") return geojson;
273
- return {
274
- type: "Feature",
275
- properties: {},
276
- geometry: geojson
277
- };
261
+ return asFeature(geojson);
278
262
  }
279
263
  };
280
- /**
281
- * Methods of `Marker` (and `CircleMarker`, `Circle`) for GeoJSON.
282
- * @lends Marker.prototype
283
- */
284
- const PointToGeoJSON = {
285
- /**
286
- * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
287
- * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
288
- * representation of the marker (as a GeoJSON `Point` Feature).
289
- * @group Other methods
290
- * @param {number|false} [precision]
291
- * @returns {Feature}
292
- */
293
- toGeoJSON(precision) {
294
- return GeoJSON.getFeature(this, {
295
- type: "Point",
296
- coordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)
297
- });
298
- } };
299
- /** @typedef {typeof PointToGeoJSON} PointToGeoJSONMethods */
300
- /**
301
- * Methods of `CircleMarker` (and `Circle`) for GeoJSON: `toGeoJSON(precision?)`
302
- * returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the
303
- * circle marker (as a GeoJSON `Point` Feature), with the coordinates values rounded
304
- * with [`formatNum`](#util-formatnum) function with given `precision`.
305
- * @typedef {object} CircleMarkerToGeoJSONMethods
306
- * @extends PointToGeoJSONMethods
307
- * @lends CircleMarker
308
- */
309
- Marker.include(PointToGeoJSON);
310
- Circle.include(PointToGeoJSON);
311
- CircleMarker.include(PointToGeoJSON);
312
- /** @typedef {typeof polylineToGeoJSON} PolylineToGeoJSONMethods */
313
- Polyline.include({
314
- /**
315
- * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
316
- * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
317
- * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`
318
- * Feature).
319
- * @param {number|false} [precision]
320
- * @returns {Feature}
321
- */
322
- toGeoJSON(precision) {
323
- const multi = !isFlat(this._latlngs);
324
- const coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);
325
- return GeoJSON.getFeature(this, {
326
- type: `${multi ? "Multi" : ""}LineString`,
327
- coordinates: coords
328
- });
329
- } });
330
- /** @typedef {typeof polygonToGeoJSON} PolygonToGeoJSONMethods */
331
- Polygon.include({
332
- /**
333
- * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
334
- * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
335
- * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).
336
- * @param {number|false} [precision]
337
- * @returns {Feature}
338
- */
339
- toGeoJSON(precision) {
340
- const holes = !isFlat(this._latlngs), multi = holes && !isFlat(this._latlngs[0]);
341
- let coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);
342
- if (!holes) coords = [coords];
343
- return GeoJSON.getFeature(this, {
344
- type: `${multi ? "Multi" : ""}Polygon`,
345
- coordinates: coords
346
- });
347
- } });
348
- /** @typedef {typeof layerGroupToGeoJSON} LayerGroupToGeoJSONMethods */
349
- LayerGroup.include({
350
- /**
351
- * Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by
352
- * `toGeoJSON()`.
353
- * @internal
354
- * @param {number|false} [precision]
355
- * @returns {Feature}
356
- */
357
- toMultiPoint(precision) {
358
- const coords = [];
359
- this.eachLayer((layer) => {
360
- coords.push(layer.toGeoJSON(precision).geometry.coordinates);
361
- });
362
- return GeoJSON.getFeature(this, {
363
- type: "MultiPoint",
364
- coordinates: coords
365
- });
366
- },
367
- /**
368
- * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
369
- * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
370
- * representation of the layer group (as a GeoJSON `FeatureCollection`,
371
- * `GeometryCollection`, or `MultiPoint`).
372
- * @param {number|false} [precision]
373
- * @returns {Feature|FeatureCollection}
374
- */
375
- toGeoJSON(precision) {
376
- const type = this.feature?.geometry?.type;
377
- if (type === "MultiPoint") return this.toMultiPoint(precision);
378
- const isGeometryCollection = type === "GeometryCollection", jsons = [];
379
- this.eachLayer((layer) => {
380
- if (layer.toGeoJSON) {
381
- const json = layer.toGeoJSON(precision);
382
- if (isGeometryCollection) jsons.push(json.geometry);
383
- else {
384
- const feature = GeoJSON.asFeature(json);
385
- if (feature.type === "FeatureCollection") jsons.push(...feature.features);
386
- else jsons.push(feature);
387
- }
388
- }
389
- });
390
- if (isGeometryCollection) return GeoJSON.getFeature(this, {
391
- geometries: jsons,
392
- type: "GeometryCollection"
393
- });
394
- return {
395
- type: "FeatureCollection",
396
- features: jsons
397
- };
398
- }
399
- });
400
264
  //#endregion
401
265
  export { GeoJSON };
402
266
 
@@ -1 +1 @@
1
- {"version":3,"file":"GeoJSON.js","names":["Util.formatNum","LineUtil.isFlat"],"sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {LayerGroup} from './LayerGroup.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {Marker} from './marker/Marker.js';\nimport {Circle} from './vector/Circle.js';\nimport {CircleMarker} from './vector/CircleMarker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport * as LineUtil from '../geometry/LineUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Options of `GeoJSON`.\n * @typedef {object} GeoJSONOptions\n * @property {(geoJsonPoint: Feature, latlng: LatLng) => Layer} [pointToLayer] A\n * `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n * The default is to spawn a default `Marker`:\n * ```js\n * function(geoJsonPoint, latlng) {\n * \treturn new Marker(latlng);\n * }\n * ```\n * @property {PathOptions|((geoJsonFeature: Feature) => PathOptions)} [style] A\n * `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n * called internally when data is added.\n * The default value is to not override any defaults:\n * ```js\n * function (geoJsonFeature) {\n * \treturn {}\n * }\n * ```\n * @property {(feature: Feature, layer: Layer) => void} [onEachFeature] A `Function`\n * that will be called once for each created `Feature`, after it has been created and\n * styled. Useful for attaching events and popups to features. It will receive the\n * `feature` as the first argument and its corresponding spawned `layer` from\n * [`asFeature`](#geojson-asFeature) as the second.\n * The default is to do nothing with the newly created layers:\n * ```js\n * function (feature, layer) {}\n * ```\n * @property {(geoJsonFeature: Feature) => boolean} [filter] A `Function` that will be\n * used to decide whether to include a feature or not.\n * The default is to include all features:\n * ```js\n * function (geoJsonFeature) {\n * \treturn true;\n * }\n * ```\n * Note: dynamically changing the `filter` option will have effect only on newly\n * added data. It will _not_ re-evaluate already included features.\n * @property {(coords: number[]) => LatLng} [coordsToLatLng] A `Function` that will be\n * used for converting GeoJSON coordinates to `LatLng`s.\n * The default is the `coordsToLatLng` static method.\n * @property {boolean} [markersInheritOptions=false] Whether default Markers for \"Point\"\n * type Features inherit from group options.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Properties of layers created from GeoJSON.\n * @typedef {object} GeoJSONLayerProperties\n * @lends Layer\n * @property {Feature} [feature] The GeoJSON feature the layer was created from (by\n * `GeoJSON`).\n */\n\n/**\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * There are several static functions which can be called without instantiating\n * `GeoJSON`.\n *\n * @example\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\nexport class GeoJSON extends FeatureGroup {\n\n\t/**\n\t * Creates a GeoJSON layer. Optionally accepts an object in\n\t * [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n\t * (you can alternatively add it later with `addData` method) and an `options` object.\n\t * @param {GeoJSONData|GeoJSONData[]|null} [geojson]\n\t * @param {GeoJSONOptions} [options]\n\t */\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t/**\n\t * Adds a GeoJSON object to the layer.\n\t * @param {GeoJSONData|GeoJSONData[]} geojson\n\t * @returns {this}\n\t */\n\taddData(geojson) {\n\t\tconst features = Array.isArray(geojson) ? geojson : geojson.features;\n\n\t\tif (features) {\n\t\t\tfor (const feature of features) {\n\t\t\t\t// only add this if geometry or geometries are set and not null\n\t\t\t\tif (feature.geometries || feature.geometry || feature.features || feature.coordinates) {\n\t\t\t\t\tthis.addData(feature);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options;\n\n\t\tif (options.filter && !options.filter(geojson)) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(geojson, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = GeoJSON.asFeature(geojson);\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(geojson, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t/**\n\t * Resets the given vector layer's style to the original GeoJSON style, useful for\n\t * resetting style after hover events. If `layer` is omitted, the style of all\n\t * features in the current layer is reset.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes styles of GeoJSON vector layers with the given style function.\n\t * @param {PathOptions|((geoJsonFeature: Feature) => PathOptions)} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t * [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t * functions if provided as options.\n\t * @param {GeoJsonObject} geojson\n\t * @param {GeoJSONOptions} [options]\n\t * @returns {Layer|null}\n\t */\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t/**\n\t * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\t * @param {number[]} coords\n\t * @returns {LatLng}\n\t */\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t/**\n\t * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t * `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an\n\t * array of arrays of points, etc., 0 by default).\n\t * Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\t * @param {any[]} coords\n\t * @param {number} [levelsDeep]\n\t * @param {(coords: number[]) => LatLng} [_coordsToLatLng]\n\t * @returns {any[]}\n\t */\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng).\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {LatLngExpression} latlng\n\t * @param {number|false} [precision]\n\t * @returns {number[]}\n\t */\n\tstatic latLngToCoords(latlng, precision) {\n\t\tlatlng = LatLng.from(latlng);\n\t\treturn latlng.alt !== undefined ?\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).\n\t * `close` determines whether the first point should be appended to the end of the\n\t * array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {any[]} latlngs\n\t * @param {number} [levelsDeep]\n\t * @param {boolean} [close]\n\t * @param {number|false} [precision]\n\t * @returns {any[]}\n\t */\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\t// Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion\n\t\tconst coords = latlngs.map(latlng => (levelsDeep ?\n\t\t\tGeoJSON.latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :\n\t\t\tGeoJSON.latLngToCoords(latlng, precision)));\n\n\t\tif (!levelsDeep && close && coords.length > 0) {\n\t\t\tcoords.push(coords[0].slice());\n\t\t}\n\n\t\treturn coords;\n\t}\n\n\t/**\n\t * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\t * @param {Layer} layer\n\t * @param {Geometry} newGeometry\n\t * @returns {Feature}\n\t */\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn layer.feature ?\n\t\t\t{...layer.feature, geometry: newGeometry} :\n\t\t\tGeoJSON.asFeature(newGeometry);\n\t}\n\n\t/**\n\t * Normalize GeoJSON geometries/features into GeoJSON features.\n\t * @param {GeoJsonObject} geojson\n\t * @returns {Feature|FeatureCollection}\n\t */\n\tstatic asFeature(geojson) {\n\t\tif (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {\n\t\t\treturn geojson;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'Feature',\n\t\t\tproperties: {},\n\t\t\tgeometry: geojson\n\t\t};\n\t}\n\n}\n\n/**\n * Methods of `Marker` (and `CircleMarker`, `Circle`) for GeoJSON.\n * @lends Marker.prototype\n */\nconst PointToGeoJSON = {\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the marker (as a GeoJSON `Point` Feature).\n\t * @group Other methods\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'Point',\n\t\t\tcoordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)\n\t\t});\n\t}\n};\n/** @typedef {typeof PointToGeoJSON} PointToGeoJSONMethods */\n\n/**\n * Methods of `CircleMarker` (and `Circle`) for GeoJSON: `toGeoJSON(precision?)`\n * returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the\n * circle marker (as a GeoJSON `Point` Feature), with the coordinates values rounded\n * with [`formatNum`](#util-formatnum) function with given `precision`.\n * @typedef {object} CircleMarkerToGeoJSONMethods\n * @extends PointToGeoJSONMethods\n * @lends CircleMarker\n */\n\nMarker.include(PointToGeoJSON);\nCircle.include(PointToGeoJSON);\nCircleMarker.include(PointToGeoJSON);\n\n/**\n * Methods of `Polyline` for GeoJSON.\n * @lends Polyline.prototype\n */\nconst polylineToGeoJSON = {\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polyline (as a GeoJSON `LineString` or `MultiLineString`\n\t * Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst multi = !LineUtil.isFlat(this._latlngs);\n\n\t\tconst coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n};\n/** @typedef {typeof polylineToGeoJSON} PolylineToGeoJSONMethods */\n\nPolyline.include(polylineToGeoJSON);\n\n/**\n * Methods of `Polygon` for GeoJSON.\n * @lends Polygon.prototype\n */\nconst polygonToGeoJSON = {\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoGeoJSON(precision) {\n\t\tconst holes = !LineUtil.isFlat(this._latlngs),\n\t\tmulti = holes && !LineUtil.isFlat(this._latlngs[0]);\n\n\t\tlet coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);\n\n\t\tif (!holes) {\n\t\t\tcoords = [coords];\n\t\t}\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n};\n/** @typedef {typeof polygonToGeoJSON} PolygonToGeoJSONMethods */\n\nPolygon.include(polygonToGeoJSON);\n\n/**\n * Methods of `LayerGroup` for GeoJSON.\n * @lends LayerGroup.prototype\n */\nconst layerGroupToGeoJSON = {\n\t/**\n\t * Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by\n\t * `toGeoJSON()`.\n\t * @internal\n\t * @param {number|false} [precision]\n\t * @returns {Feature}\n\t */\n\ttoMultiPoint(precision) {\n\t\tconst coords = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tcoords.push(layer.toGeoJSON(precision).geometry.coordinates);\n\t\t});\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'MultiPoint',\n\t\t\tcoordinates: coords\n\t\t});\n\t},\n\n\t/**\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the\n\t * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)\n\t * representation of the layer group (as a GeoJSON `FeatureCollection`,\n\t * `GeometryCollection`, or `MultiPoint`).\n\t * @param {number|false} [precision]\n\t * @returns {Feature|FeatureCollection}\n\t */\n\ttoGeoJSON(precision) {\n\n\t\tconst type = this.feature?.geometry?.type;\n\n\t\tif (type === 'MultiPoint') {\n\t\t\treturn this.toMultiPoint(precision);\n\t\t}\n\n\t\tconst isGeometryCollection = type === 'GeometryCollection',\n\t\tjsons = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tif (layer.toGeoJSON) {\n\t\t\t\tconst json = layer.toGeoJSON(precision);\n\t\t\t\tif (isGeometryCollection) {\n\t\t\t\t\tjsons.push(json.geometry);\n\t\t\t\t} else {\n\t\t\t\t\tconst feature = GeoJSON.asFeature(json);\n\t\t\t\t\t// Squash nested feature collections\n\t\t\t\t\tif (feature.type === 'FeatureCollection') {\n\t\t\t\t\t\tjsons.push(...feature.features);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tjsons.push(feature);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tif (isGeometryCollection) {\n\t\t\treturn GeoJSON.getFeature(this, {\n\t\t\t\tgeometries: jsons,\n\t\t\t\ttype: 'GeometryCollection'\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'FeatureCollection',\n\t\t\tfeatures: jsons\n\t\t};\n\t}\n};\n/** @typedef {typeof layerGroupToGeoJSON} LayerGroupToGeoJSONMethods */\n\nLayerGroup.include(layerGroupToGeoJSON);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,IAAa,UAAb,MAAa,gBAAgB,aAAa;;;;;;;;CASzC,YAAY,SAAS,SAAS;EAC7B,MAAM,KAAA,GAAW,OAAO;EAExB,IAAI,SACH,KAAK,QAAQ,OAAO;EAGrB,KAAK,cAAc,OAAO;CAC3B;;;;;;CAOA,QAAQ,SAAS;EAChB,MAAM,WAAW,MAAM,QAAQ,OAAO,IAAI,UAAU,QAAQ;EAE5D,IAAI,UAAU;GACb,KAAK,MAAM,WAAW,UAErB,IAAI,QAAQ,cAAc,QAAQ,YAAY,QAAQ,YAAY,QAAQ,aACzE,KAAK,QAAQ,OAAO;GAGtB,OAAO;EACR;EAEA,MAAM,UAAU,KAAK;EAErB,IAAI,QAAQ,UAAU,CAAC,QAAQ,OAAO,OAAO,GAAK,OAAO;EAEzD,MAAM,QAAQ,QAAQ,gBAAgB,SAAS,OAAO;EACtD,IAAI,CAAC,OACJ,OAAO;EAER,MAAM,UAA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sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {FeatureGroup} from './FeatureGroup.js';\nimport {Marker} from './marker/Marker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {latLngToCoords, latLngsToCoords, getFeature, asFeature} from './GeoJSONUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJSON as GeoJSONData, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer, InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PathOptions} from './vector/Path.js' */\n\n/**\n * Options of `GeoJSON`.\n * @typedef {object} GeoJSONOptions\n * @property {(geoJsonPoint: Feature, latlng: LatLng) => Layer} [pointToLayer] A\n * `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n * The default is to spawn a default `Marker`:\n * ```js\n * function(geoJsonPoint, latlng) {\n * \treturn new Marker(latlng);\n * }\n * ```\n * @property {PathOptions|((geoJsonFeature: Feature) => PathOptions)} [style] A\n * `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n * called internally when data is added.\n * The default value is to not override any defaults:\n * ```js\n * function (geoJsonFeature) {\n * \treturn {}\n * }\n * ```\n * @property {(feature: Feature, layer: Layer) => void} [onEachFeature] A `Function`\n * that will be called once for each created `Feature`, after it has been created and\n * styled. Useful for attaching events and popups to features. It will receive the\n * `feature` as the first argument and its corresponding spawned `layer` from\n * [`asFeature`](#geojson-asFeature) as the second.\n * The default is to do nothing with the newly created layers:\n * ```js\n * function (feature, layer) {}\n * ```\n * @property {(geoJsonFeature: Feature) => boolean} [filter] A `Function` that will be\n * used to decide whether to include a feature or not.\n * The default is to include all features:\n * ```js\n * function (geoJsonFeature) {\n * \treturn true;\n * }\n * ```\n * Note: dynamically changing the `filter` option will have effect only on newly\n * added data. It will _not_ re-evaluate already included features.\n * @property {(coords: number[]) => LatLng} [coordsToLatLng] A `Function` that will be\n * used for converting GeoJSON coordinates to `LatLng`s.\n * The default is the `coordsToLatLng` static method.\n * @property {boolean} [markersInheritOptions=false] Whether default Markers for \"Point\"\n * type Features inherit from group options.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Properties of layers created from GeoJSON.\n * @typedef {object} GeoJSONLayerProperties\n * @lends Layer\n * @property {Feature} [feature] The GeoJSON feature the layer was created from (by\n * `GeoJSON`).\n */\n\n/**\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * There are several static functions which can be called without instantiating\n * `GeoJSON`.\n *\n * @example\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\nexport class GeoJSON extends FeatureGroup {\n\n\t/**\n\t * Creates a GeoJSON layer. Optionally accepts an object in\n\t * [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n\t * (you can alternatively add it later with `addData` method) and an `options` object.\n\t * @param {GeoJSONData|GeoJSONData[]|null} [geojson]\n\t * @param {GeoJSONOptions} [options]\n\t */\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t/**\n\t * Adds a GeoJSON object to the layer.\n\t * @param {GeoJSONData|GeoJSONData[]} geojson\n\t * @returns {this}\n\t */\n\taddData(geojson) {\n\t\tconst features = Array.isArray(geojson) ? geojson : geojson.features;\n\n\t\tif (features) {\n\t\t\tfor (const feature of features) {\n\t\t\t\t// only add this if geometry or geometries are set and not null\n\t\t\t\tif (feature.geometries || feature.geometry || feature.features || feature.coordinates) {\n\t\t\t\t\tthis.addData(feature);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options;\n\n\t\tif (options.filter && !options.filter(geojson)) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(geojson, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = GeoJSON.asFeature(geojson);\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(geojson, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t/**\n\t * Resets the given vector layer's style to the original GeoJSON style, useful for\n\t * resetting style after hover events. If `layer` is omitted, the style of all\n\t * features in the current layer is reset.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes styles of GeoJSON vector layers with the given style function.\n\t * @param {PathOptions|((geoJsonFeature: Feature) => PathOptions)} style\n\t * @returns {this}\n\t */\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t * [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t * functions if provided as options.\n\t * @param {GeoJsonObject} geojson\n\t * @param {GeoJSONOptions} [options]\n\t * @returns {Layer|null}\n\t */\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\t// so toGeoJSON exports MultiPoint and GeometryCollection members with their own type\n\t\t\t\t\tgeoLayer.feature = GeoJSON.asFeature(g);\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t/**\n\t * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\t * @param {number[]} coords\n\t * @returns {LatLng}\n\t */\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t/**\n\t * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t * `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an\n\t * array of arrays of points, etc., 0 by default).\n\t * Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\t * @param {any[]} coords\n\t * @param {number} [levelsDeep]\n\t * @param {(coords: number[]) => LatLng} [_coordsToLatLng]\n\t * @returns {any[]}\n\t */\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng).\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {LatLngExpression} latlng\n\t * @param {number|false} [precision]\n\t * @returns {number[]}\n\t */\n\tstatic latLngToCoords(latlng, precision) {\n\t\treturn latLngToCoords(latlng, precision);\n\t}\n\n\t/**\n\t * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs).\n\t * `close` determines whether the first point should be appended to the end of the\n\t * array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t * Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\t * @param {any[]} latlngs\n\t * @param {number} [levelsDeep]\n\t * @param {boolean} [close]\n\t * @param {number|false} [precision]\n\t * @returns {any[]}\n\t */\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\treturn latLngsToCoords(latlngs, levelsDeep, close, precision);\n\t}\n\n\t/**\n\t * Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\t * @param {Layer} layer\n\t * @param {Geometry} newGeometry\n\t * @returns {Feature}\n\t */\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn getFeature(layer, newGeometry);\n\t}\n\n\t/**\n\t * Normalize GeoJSON geometries/features into GeoJSON features.\n\t * @param {GeoJsonObject} geojson\n\t * @returns {Feature|FeatureCollection}\n\t */\n\tstatic asFeature(geojson) {\n\t\treturn asFeature(geojson);\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,IAAa,UAAb,MAAa,gBAAgB,aAAa;;;;;;;;CASzC,YAAY,SAAS,SAAS;EAC7B,MAAM,KAAA,GAAW,OAAO;EAExB,IAAI,SACH,KAAK,QAAQ,OAAO;EAGrB,KAAK,cAAc,OAAO;CAC3B;;;;;;CAOA,QAAQ,SAAS;EAChB,MAAM,WAAW,MAAM,QAAQ,OAAO,IAAI,UAAU,QAAQ;EAE5D,IAAI,UAAU;GACb,KAAK,MAAM,WAAW,UAErB,IAAI,QAAQ,cAAc,QAAQ,YAAY,QAAQ,YAAY,QAAQ,aACzE,KAAK,QAAQ,OAAO;GAGtB,OAAO;EACR;EAEA,MAAM,UAAU,KAAK;EAErB,IAAI,QAAQ,UAAU,CAAC,QAAQ,OAAO,OAAO,GAAK,OAAO;EAEzD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A,OAAO,gBAAgB,SAAS,YAAY,OAAO,WAAW;EAC7D,OAAO,gBAAgB,SAAS,YAAY,OAAO,SAAS;CAC7D;;;;;;;CAQA,OAAO,WAAW,OAAO,aAAa;EACrC,OAAO,WAAW,OAAO,WAAW;CACrC;;;;;;CAOA,OAAO,UAAU,SAAS;EACzB,OAAO,UAAU,OAAO;CACzB;AAED"}
@@ -0,0 +1,75 @@
1
+ import { formatNum } from "../core/Util.js";
2
+ import { LatLng } from "../geo/LatLng.js";
3
+ import { isFlat } from "../geometry/LineUtil.js";
4
+ //#region src/layer/GeoJSONUtil.js
5
+ /** @import {Feature, FeatureCollection, GeoJsonObject, Geometry} from 'geojson' */
6
+ /** @import {Layer} from './Layer.js' */
7
+ /** @import {LatLngExpression} from '../geo/LatLng.js' */
8
+ /**
9
+ * See `GeoJSON.latLngToCoords()`.
10
+ * @param {LatLngExpression} latlng
11
+ * @param {number|false} [precision]
12
+ * @returns {number[]}
13
+ */
14
+ function latLngToCoords(latlng, precision) {
15
+ latlng = LatLng.from(latlng);
16
+ return latlng.alt !== void 0 ? [
17
+ formatNum(latlng.lng, precision),
18
+ formatNum(latlng.lat, precision),
19
+ formatNum(latlng.alt, precision)
20
+ ] : [formatNum(latlng.lng, precision), formatNum(latlng.lat, precision)];
21
+ }
22
+ /**
23
+ * See `GeoJSON.latLngsToCoords()`.
24
+ * @param {any[]} latlngs
25
+ * @param {number} [levelsDeep]
26
+ * @param {boolean} [close]
27
+ * @param {number|false} [precision]
28
+ * @returns {any[]}
29
+ */
30
+ function latLngsToCoords(latlngs, levelsDeep, close, precision) {
31
+ const coords = latlngs.map((latlng) => levelsDeep ? latLngsToCoords(latlng, isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) : latLngToCoords(latlng, precision));
32
+ if (!levelsDeep && close && coords.length > 0) coords.push(coords[0].slice());
33
+ return coords;
34
+ }
35
+ /**
36
+ * See `GeoJSON.getFeature()`.
37
+ * @param {Layer} layer
38
+ * @param {Geometry} newGeometry
39
+ * @returns {Feature}
40
+ */
41
+ function getFeature(layer, newGeometry) {
42
+ return layer.feature ? {
43
+ ...layer.feature,
44
+ geometry: newGeometry
45
+ } : asFeature(newGeometry);
46
+ }
47
+ /**
48
+ * See `GeoJSON.asFeature()`.
49
+ * @param {GeoJsonObject} geojson
50
+ * @returns {Feature|FeatureCollection}
51
+ */
52
+ function asFeature(geojson) {
53
+ if (geojson.type === "Feature" || geojson.type === "FeatureCollection") return geojson;
54
+ return {
55
+ type: "Feature",
56
+ properties: {},
57
+ geometry: geojson
58
+ };
59
+ }
60
+ /**
61
+ * The GeoJSON `Point` Feature of a layer with `getLatLng()`, for its `toGeoJSON()`.
62
+ * @param {Layer & {getLatLng(): LatLng}} layer
63
+ * @param {number|false} [precision]
64
+ * @returns {Feature}
65
+ */
66
+ function pointToGeoJSON(layer, precision) {
67
+ return getFeature(layer, {
68
+ type: "Point",
69
+ coordinates: latLngToCoords(layer.getLatLng(), precision)
70
+ });
71
+ }
72
+ //#endregion
73
+ export { asFeature, getFeature, latLngToCoords, latLngsToCoords, pointToGeoJSON };
74
+
75
+ //# sourceMappingURL=GeoJSONUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeoJSONUtil.js","names":["Util.formatNum","LineUtil.isFlat"],"sources":["../../../src/layer/GeoJSONUtil.js"],"sourcesContent":["import * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport * as LineUtil from '../geometry/LineUtil.js';\n\n/** @import {Feature, FeatureCollection, GeoJsonObject, Geometry} from 'geojson' */\n/** @import {Layer} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n\n// Shared by `GeoJSON` and the `toGeoJSON` methods of the layers it creates, which can't import `GeoJSON.js` without a cycle.\n\n/**\n * See `GeoJSON.latLngToCoords()`.\n * @param {LatLngExpression} latlng\n * @param {number|false} [precision]\n * @returns {number[]}\n */\nexport function latLngToCoords(latlng, precision) {\n\tlatlng = LatLng.from(latlng);\n\treturn latlng.alt !== undefined ?\n\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :\n\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];\n}\n\n/**\n * See `GeoJSON.latLngsToCoords()`.\n * @param {any[]} latlngs\n * @param {number} [levelsDeep]\n * @param {boolean} [close]\n * @param {number|false} [precision]\n * @returns {any[]}\n */\nexport function latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t// Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion\n\tconst coords = latlngs.map(latlng => (levelsDeep ?\n\t\tlatLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :\n\t\tlatLngToCoords(latlng, precision)));\n\n\tif (!levelsDeep && close && coords.length > 0) {\n\t\tcoords.push(coords[0].slice());\n\t}\n\n\treturn coords;\n}\n\n/**\n * See `GeoJSON.getFeature()`.\n * @param {Layer} layer\n * @param {Geometry} newGeometry\n * @returns {Feature}\n */\nexport function getFeature(layer, newGeometry) {\n\treturn layer.feature ?\n\t\t{...layer.feature, geometry: newGeometry} :\n\t\tasFeature(newGeometry);\n}\n\n/**\n * See `GeoJSON.asFeature()`.\n * @param {GeoJsonObject} geojson\n * @returns {Feature|FeatureCollection}\n */\nexport function asFeature(geojson) {\n\tif (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {\n\t\treturn geojson;\n\t}\n\n\treturn {\n\t\ttype: 'Feature',\n\t\tproperties: {},\n\t\tgeometry: geojson\n\t};\n}\n\n/**\n * The GeoJSON `Point` Feature of a layer with `getLatLng()`, for its `toGeoJSON()`.\n * @param {Layer & {getLatLng(): LatLng}} layer\n * @param {number|false} [precision]\n * @returns {Feature}\n */\nexport function pointToGeoJSON(layer, precision) {\n\treturn getFeature(layer, {\n\t\ttype: 'Point',\n\t\tcoordinates: latLngToCoords(layer.getLatLng(), precision)\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,SAAgB,eAAe,QAAQ,WAAW;CACjD,SAAS,OAAO,KAAK,MAAM;CAC3B,OAAO,OAAO,QAAQ,KAAA,IACrB;EAACA,UAAe,OAAO,KAAK,SAAS;EAAGA,UAAe,OAAO,KAAK,SAAS;EAAGA,UAAe,OAAO,KAAK,SAAS;CAAC,IACpH,CAACA,UAAe,OAAO,KAAK,SAAS,GAAGA,UAAe,OAAO,KAAK,SAAS,CAAC;AAC/E;;;;;;;;;AAUA,SAAgB,gBAAgB,SAAS,YAAY,OAAO,WAAW;CAEtE,MAAM,SAAS,QAAQ,KAAI,WAAW,aACrC,gBAAgB,QAAQC,OAAgB,MAAM,IAAI,IAAI,aAAa,GAAG,OAAO,SAAS,IACtF,eAAe,QAAQ,SAAS,CAAE;CAEnC,IAAI,CAAC,cAAc,SAAS,OAAO,SAAS,GAC3C,OAAO,KAAK,OAAO,EAAE,CAAC,MAAM,CAAC;CAG9B,OAAO;AACR;;;;;;;AAQA,SAAgB,WAAW,OAAO,aAAa;CAC9C,OAAO,MAAM,UACZ;EAAC,GAAG,MAAM;EAAS,UAAU;CAAW,IACxC,UAAU,WAAW;AACvB;;;;;;AAOA,SAAgB,UAAU,SAAS;CAClC,IAAI,QAAQ,SAAS,aAAa,QAAQ,SAAS,qBAClD,OAAO;CAGR,OAAO;EACN,MAAM;EACN,YAAY,CAAC;EACb,UAAU;CACX;AACD;;;;;;;AAQA,SAAgB,eAAe,OAAO,WAAW;CAChD,OAAO,WAAW,OAAO;EACxB,MAAM;EACN,aAAa,eAAe,MAAM,UAAU,GAAG,SAAS;CACzD,CAAC;AACF"}
@@ -37,23 +37,21 @@ import { BlanketOverlay } from "./BlanketOverlay.js";
37
37
  * ```
38
38
  */
39
39
  var HeatLayer = class HeatLayer extends BlanketOverlay {
40
- static {
41
- this.setDefaultOptions({
42
- radius: 25,
43
- blur: 15,
44
- max: 1,
45
- maxZoom: void 0,
46
- minOpacity: .05,
47
- gradient: {
48
- .4: "blue",
49
- .6: "cyan",
50
- .7: "lime",
51
- .8: "yellow",
52
- 1: "red"
53
- },
54
- pane: "overlayPane"
55
- });
56
- }
40
+ static defaultOptions = {
41
+ radius: 25,
42
+ blur: 15,
43
+ max: 1,
44
+ maxZoom: void 0,
45
+ minOpacity: .05,
46
+ gradient: {
47
+ .4: "blue",
48
+ .6: "cyan",
49
+ .7: "lime",
50
+ .8: "yellow",
51
+ 1: "red"
52
+ },
53
+ pane: "overlayPane"
54
+ };
57
55
  /**
58
56
  * Creates a heatmap of the given points: `LatLng`s or arrays
59
57
  * `[lat, lng, intensity]` (the intensity defaults to `1`).
@@ -1 +1 @@
1
- {"version":3,"file":"HeatLayer.js","names":[],"sources":["../../../src/layer/HeatLayer.js"],"sourcesContent":["import {BlanketOverlay} from './BlanketOverlay.js';\nimport * as Util from '../core/Util.js';\n/** @import {BlanketOverlayOptions} from './BlanketOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n\n/**\n * Options of `HeatLayer`.\n * @typedef {object} HeatLayerOptions\n * @property {number} [radius=25] The radius of each point in pixels.\n * @property {number} [blur=15] The amount of blur in pixels.\n * @property {number} [max=1] The intensity with the strongest color.\n * @property {number} [maxZoom] The zoom level where the points reach the full\n * intensity; below it, the intensity is halved per zoom level. By default the\n * maximum zoom of the map.\n * @property {number} [minOpacity=0.05] The minimum opacity of the heat.\n * @property {Record<number, string>} [gradient={0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'}]\n * The colors for the intensities from `0` to `1`, any CSS colors.\n * @property {string} [pane='overlayPane'] The map pane of the layer.\n * @extends BlanketOverlayOptions\n */\n\n/**\n * A heatmap of points, each with an optional intensity, drawn on a canvas: the\n * points are drawn as blurred circles adding up, and colored by a gradient.\n * Nearby points are merged into a grid for speed, so that tens of thousands of\n * points stay fast.\n *\n * Inspired by the [Leaflet.heat](https://github.com/Leaflet/Leaflet.heat) plugin\n * and its [simpleheat](https://github.com/mourner/simpleheat) algorithm.\n *\n * @example\n * ```js\n * new HeatLayer([\n * \t[47.27, 11.40, 0.5], // latitude, longitude, intensity\n * \t[47.28, 11.41],\n * \tnew LatLng(47.26, 11.39)\n * ], {radius: 20}).addTo(map);\n * ```\n */\nexport class HeatLayer extends BlanketOverlay {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tradius: 25,\n\t\t\tblur: 15,\n\t\t\tmax: 1,\n\t\t\tmaxZoom: undefined,\n\t\t\tminOpacity: 0.05,\n\t\t\tgradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},\n\t\t\tpane: 'overlayPane'\n\t\t});\n\t}\n\n\t/**\n\t * Creates a heatmap of the given points: `LatLng`s or arrays\n\t * `[lat, lng, intensity]` (the intensity defaults to `1`).\n\t * @param {LatLngExpression[]} [latlngs]\n\t * @param {HeatLayerOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper(options);\n\t\tthis._latlngs = latlngs ?? [];\n\t\tthis.callInitHooks(HeatLayer);\n\t}\n\n\t/**\n\t * Replaces the points of the heatmap.\n\t * @param {LatLngExpression[]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._latlngs = latlngs;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Adds a point to the heatmap.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\taddLatLng(latlng) {\n\t\tthis._latlngs.push(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the points of the heatmap.\n\t * @returns {LatLngExpression[]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Changes the options, e.g. the `radius` or the `gradient`.\n\t * @param {HeatLayerOptions} options\n\t * @returns {this}\n\t */\n\tsetOptions(options) {\n\t\tUtil.setOptions(this, options);\n\t\tthis._circle = this._gradient = null;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Redraws the heatmap.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map && this._bounds) {\n\t\t\tcancelAnimationFrame(this._frame);\n\t\t\tthis._frame = requestAnimationFrame(() => this._draw());\n\t\t}\n\t\treturn this;\n\t}\n\n\t_initContainer() {\n\t\tthis._container = document.createElement('canvas');\n\t\tthis._container.classList.add('maplair-heatmap-layer');\n\t\tthis._ctx = this._container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._frame);\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tthis._container.width = size.x;\n\t\tthis._container.height = size.y;\n\t\treturn size;\n\t}\n\n\t_onSettled() {\n\t\tthis._draw();\n\t}\n\n\t// A blurred circle, drawn for each point\n\t_getCircle() {\n\t\tif (this._circle) { return this._circle; }\n\t\tconst {radius, blur} = this.options,\n\t\tr = radius + blur,\n\t\tcircle = this._circle = document.createElement('canvas'),\n\t\tctx = circle.getContext('2d');\n\t\tcircle.width = circle.height = r * 2;\n\t\t// the shadow of a circle drawn outside of the canvas\n\t\tctx.shadowOffsetX = ctx.shadowOffsetY = r * 2;\n\t\tctx.shadowBlur = blur;\n\t\tctx.shadowColor = 'black';\n\t\tctx.beginPath();\n\t\tctx.arc(-r, -r, radius, 0, Math.PI * 2, true);\n\t\tctx.closePath();\n\t\tctx.fill();\n\t\treturn circle;\n\t}\n\n\t// The colors of the alpha values 0–255 as RGBA values\n\t_getGradient() {\n\t\tif (this._gradient) { return this._gradient; }\n\t\tconst canvas = document.createElement('canvas'),\n\t\tctx = canvas.getContext('2d'),\n\t\tgradient = ctx.createLinearGradient(0, 0, 0, 256);\n\t\tcanvas.width = 1;\n\t\tcanvas.height = 256;\n\t\tfor (const [stop, color] of Object.entries(this.options.gradient)) {\n\t\t\tgradient.addColorStop(Number(stop), color);\n\t\t}\n\t\tctx.fillStyle = gradient;\n\t\tctx.fillRect(0, 0, 1, 256);\n\t\tthis._gradient = ctx.getImageData(0, 0, 1, 256).data;\n\t\treturn this._gradient;\n\t}\n\n\t_draw() {\n\t\tconst map = this._map;\n\t\tif (!map || !this._bounds) { return; }\n\n\t\tconst ctx = this._ctx,\n\t\t{width, height} = this._container,\n\t\toffset = this._bounds.min,\n\t\t{radius, blur, max, minOpacity} = this.options,\n\t\tr = radius + blur,\n\t\tmaxZoom = this.options.maxZoom ?? map.getMaxZoom(),\n\t\t// halve the intensity per zoom level below maxZoom (at most 12)\n\t\tzoomFactor = 1 / 2 ** Math.max(0, Math.min(maxZoom - map.getZoom(), 12)),\n\t\tcellSize = radius / 2,\n\t\tgrid = new Map();\n\n\t\t// merge the points per grid cell, weighted by their intensity\n\t\tfor (const latlng of this._latlngs) {\n\t\t\tconst point = map.latLngToLayerPoint(latlng).subtract(offset);\n\t\t\tif (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }\n\t\t\tconst intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,\n\t\t\tkey = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,\n\t\t\tcell = grid.get(key);\n\t\t\tif (cell) {\n\t\t\t\tconst sum = cell.intensity + intensity;\n\t\t\t\tcell.x = (cell.x * cell.intensity + point.x * intensity) / sum;\n\t\t\t\tcell.y = (cell.y * cell.intensity + point.y * intensity) / sum;\n\t\t\t\tcell.intensity = sum;\n\t\t\t} else {\n\t\t\t\tgrid.set(key, {x: point.x, y: point.y, intensity});\n\t\t\t}\n\t\t}\n\n\t\tctx.clearRect(0, 0, width, height);\n\t\tconst circle = this._getCircle();\n\t\tfor (const {x, y, intensity} of grid.values()) {\n\t\t\tctx.globalAlpha = Math.min(Math.max(intensity / max, minOpacity), 1);\n\t\t\tctx.drawImage(circle, x - r, y - r);\n\t\t}\n\t\tctx.globalAlpha = 1;\n\n\t\t// colorize by the alpha values\n\t\tif (!grid.size) { return; }\n\t\tconst image = ctx.getImageData(0, 0, width, height),\n\t\tpixels = image.data,\n\t\tgradient = this._getGradient();\n\t\tfor (let i = 3; i < pixels.length; i += 4) {\n\t\t\tconst j = pixels[i] * 4;\n\t\t\tif (j) {\n\t\t\t\tpixels[i - 3] = gradient[j];\n\t\t\t\tpixels[i - 2] = gradient[j + 1];\n\t\t\t\tpixels[i - 1] = gradient[j + 2];\n\t\t\t}\n\t\t}\n\t\tctx.putImageData(image, 0, 0);\n\t}\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,YAAb,MAAa,kBAAkB,eAAe;CAE7C;EACC,KAAK,kBAAkB;GACtB,QAAQ;GACR,MAAM;GACN,KAAK;GACL,SAAS,KAAA;GACT,YAAY;GACZ,UAAU;IAAC,IAAK;IAAQ,IAAK;IAAQ,IAAK;IAAQ,IAAK;IAAU,GAAG;GAAK;GACzE,MAAM;EACP,CAAC;CACF;;;;;;;CAQA,YAAY,SAAS,SAAS;EAC7B,MAAM,OAAO;EACb,KAAK,WAAW,WAAW,CAAC;EAC5B,KAAK,cAAc,SAAS;CAC7B;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,WAAW;EAChB,OAAO,KAAK,OAAO;CACpB;;;;;;CAOA,UAAU,QAAQ;EACjB,KAAK,SAAS,KAAK,MAAM;EACzB,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;;;;;;CAOA,WAAW,SAAS;EACnB,WAAgB,MAAM,OAAO;EAC7B,KAAK,UAAU,KAAK,YAAY;EAChC,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,SAAS;EACR,IAAI,KAAK,QAAQ,KAAK,SAAS;GAC9B,qBAAqB,KAAK,MAAM;GAChC,KAAK,SAAS,4BAA4B,KAAK,MAAM,CAAC;EACvD;EACA,OAAO;CACR;CAEA,iBAAiB;EAChB,KAAK,aAAa,SAAS,cAAc,QAAQ;EACjD,KAAK,WAAW,UAAU,IAAI,uBAAuB;EACrD,KAAK,OAAO,KAAK,WAAW,WAAW,IAAI;CAC5C;CAE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IAAI,cAAc;EAGlB,IAAI,CAAC,KAAK,MAAQ;EAClB,MAAM,QAAQ,IAAI,aAAa,GAAG,GAAG,OAAO,MAAM,GAClD,SAAS,MAAM,MACf,WAAW,KAAK,aAAa;EAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;GAC1C,MAAM,IAAI,OAAO,KAAK;GACtB,IAAI,GAAG;IACN,OAAO,IAAI,KAAK,SAAS;IACzB,OAAO,IAAI,KAAK,SAAS,IAAI;IAC7B,OAAO,IAAI,KAAK,SAAS,IAAI;GAC9B;EACD;EACA,IAAI,aAAa,OAAO,GAAG,CAAC;CAC7B;AACD"}
1
+ {"version":3,"file":"HeatLayer.js","names":[],"sources":["../../../src/layer/HeatLayer.js"],"sourcesContent":["import {BlanketOverlay} from './BlanketOverlay.js';\nimport * as Util from '../core/Util.js';\n/** @import {BlanketOverlayOptions} from './BlanketOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n\n/**\n * Options of `HeatLayer`.\n * @typedef {object} HeatLayerOptions\n * @property {number} [radius=25] The radius of each point in pixels.\n * @property {number} [blur=15] The amount of blur in pixels.\n * @property {number} [max=1] The intensity with the strongest color.\n * @property {number} [maxZoom] The zoom level where the points reach the full\n * intensity; below it, the intensity is halved per zoom level. By default the\n * maximum zoom of the map.\n * @property {number} [minOpacity=0.05] The minimum opacity of the heat.\n * @property {Record<number, string>} [gradient={0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'}]\n * The colors for the intensities from `0` to `1`, any CSS colors.\n * @property {string} [pane='overlayPane'] The map pane of the layer.\n * @extends BlanketOverlayOptions\n */\n\n/**\n * A heatmap of points, each with an optional intensity, drawn on a canvas: the\n * points are drawn as blurred circles adding up, and colored by a gradient.\n * Nearby points are merged into a grid for speed, so that tens of thousands of\n * points stay fast.\n *\n * Inspired by the [Leaflet.heat](https://github.com/Leaflet/Leaflet.heat) plugin\n * and its [simpleheat](https://github.com/mourner/simpleheat) algorithm.\n *\n * @example\n * ```js\n * new HeatLayer([\n * \t[47.27, 11.40, 0.5], // latitude, longitude, intensity\n * \t[47.28, 11.41],\n * \tnew LatLng(47.26, 11.39)\n * ], {radius: 20}).addTo(map);\n * ```\n */\nexport class HeatLayer extends BlanketOverlay {\n\n\tstatic defaultOptions = {\n\t\tradius: 25,\n\t\tblur: 15,\n\t\tmax: 1,\n\t\tmaxZoom: undefined,\n\t\tminOpacity: 0.05,\n\t\tgradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},\n\t\tpane: 'overlayPane'\n\t};\n\n\t/**\n\t * Creates a heatmap of the given points: `LatLng`s or arrays\n\t * `[lat, lng, intensity]` (the intensity defaults to `1`).\n\t * @param {LatLngExpression[]} [latlngs]\n\t * @param {HeatLayerOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper(options);\n\t\tthis._latlngs = latlngs ?? [];\n\t\tthis.callInitHooks(HeatLayer);\n\t}\n\n\t/**\n\t * Replaces the points of the heatmap.\n\t * @param {LatLngExpression[]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._latlngs = latlngs;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Adds a point to the heatmap.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\taddLatLng(latlng) {\n\t\tthis._latlngs.push(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the points of the heatmap.\n\t * @returns {LatLngExpression[]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Changes the options, e.g. the `radius` or the `gradient`.\n\t * @param {HeatLayerOptions} options\n\t * @returns {this}\n\t */\n\tsetOptions(options) {\n\t\tUtil.setOptions(this, options);\n\t\tthis._circle = this._gradient = null;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Redraws the heatmap.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map && this._bounds) {\n\t\t\tcancelAnimationFrame(this._frame);\n\t\t\tthis._frame = requestAnimationFrame(() => this._draw());\n\t\t}\n\t\treturn this;\n\t}\n\n\t_initContainer() {\n\t\tthis._container = document.createElement('canvas');\n\t\tthis._container.classList.add('maplair-heatmap-layer');\n\t\tthis._ctx = this._container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._frame);\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tthis._container.width = size.x;\n\t\tthis._container.height = size.y;\n\t\treturn size;\n\t}\n\n\t_onSettled() {\n\t\tthis._draw();\n\t}\n\n\t// A blurred circle, drawn for each point\n\t_getCircle() {\n\t\tif (this._circle) { return this._circle; }\n\t\tconst {radius, blur} = this.options,\n\t\tr = radius + blur,\n\t\tcircle = this._circle = document.createElement('canvas'),\n\t\tctx = circle.getContext('2d');\n\t\tcircle.width = circle.height = r * 2;\n\t\t// the shadow of a circle drawn outside of the canvas\n\t\tctx.shadowOffsetX = ctx.shadowOffsetY = r * 2;\n\t\tctx.shadowBlur = blur;\n\t\tctx.shadowColor = 'black';\n\t\tctx.beginPath();\n\t\tctx.arc(-r, -r, radius, 0, Math.PI * 2, true);\n\t\tctx.closePath();\n\t\tctx.fill();\n\t\treturn circle;\n\t}\n\n\t// The colors of the alpha values 0–255 as RGBA values\n\t_getGradient() {\n\t\tif (this._gradient) { return this._gradient; }\n\t\tconst canvas = document.createElement('canvas'),\n\t\tctx = canvas.getContext('2d'),\n\t\tgradient = ctx.createLinearGradient(0, 0, 0, 256);\n\t\tcanvas.width = 1;\n\t\tcanvas.height = 256;\n\t\tfor (const [stop, color] of Object.entries(this.options.gradient)) {\n\t\t\tgradient.addColorStop(Number(stop), color);\n\t\t}\n\t\tctx.fillStyle = gradient;\n\t\tctx.fillRect(0, 0, 1, 256);\n\t\tthis._gradient = ctx.getImageData(0, 0, 1, 256).data;\n\t\treturn this._gradient;\n\t}\n\n\t_draw() {\n\t\tconst map = this._map;\n\t\tif (!map || !this._bounds) { return; }\n\n\t\tconst ctx = this._ctx,\n\t\t{width, height} = this._container,\n\t\toffset = this._bounds.min,\n\t\t{radius, blur, max, minOpacity} = this.options,\n\t\tr = radius + blur,\n\t\tmaxZoom = this.options.maxZoom ?? map.getMaxZoom(),\n\t\t// halve the intensity per zoom level below maxZoom (at most 12)\n\t\tzoomFactor = 1 / 2 ** Math.max(0, Math.min(maxZoom - map.getZoom(), 12)),\n\t\tcellSize = radius / 2,\n\t\tgrid = new Map();\n\n\t\t// merge the points per grid cell, weighted by their intensity\n\t\tfor (const latlng of this._latlngs) {\n\t\t\tconst point = map.latLngToLayerPoint(latlng).subtract(offset);\n\t\t\tif (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }\n\t\t\tconst intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,\n\t\t\tkey = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,\n\t\t\tcell = grid.get(key);\n\t\t\tif (cell) {\n\t\t\t\tconst sum = cell.intensity + intensity;\n\t\t\t\tcell.x = (cell.x * cell.intensity + point.x * intensity) / sum;\n\t\t\t\tcell.y = (cell.y * cell.intensity + point.y * intensity) / sum;\n\t\t\t\tcell.intensity = sum;\n\t\t\t} else {\n\t\t\t\tgrid.set(key, {x: point.x, y: point.y, intensity});\n\t\t\t}\n\t\t}\n\n\t\tctx.clearRect(0, 0, width, height);\n\t\tconst circle = this._getCircle();\n\t\tfor (const {x, y, intensity} of grid.values()) {\n\t\t\tctx.globalAlpha = Math.min(Math.max(intensity / max, minOpacity), 1);\n\t\t\tctx.drawImage(circle, x - r, y - r);\n\t\t}\n\t\tctx.globalAlpha = 1;\n\n\t\t// colorize by the alpha values\n\t\tif (!grid.size) { return; }\n\t\tconst image = ctx.getImageData(0, 0, width, height),\n\t\tpixels = image.data,\n\t\tgradient = this._getGradient();\n\t\tfor (let i = 3; i < pixels.length; i += 4) {\n\t\t\tconst j = pixels[i] * 4;\n\t\t\tif (j) {\n\t\t\t\tpixels[i - 3] = gradient[j];\n\t\t\t\tpixels[i - 2] = gradient[j + 1];\n\t\t\t\tpixels[i - 1] = gradient[j + 2];\n\t\t\t}\n\t\t}\n\t\tctx.putImageData(image, 0, 0);\n\t}\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,YAAb,MAAa,kBAAkB,eAAe;CAE7C,OAAO,iBAAiB;EACvB,QAAQ;EACR,MAAM;EACN,KAAK;EACL,SAAS,KAAA;EACT,YAAY;EACZ,UAAU;GAAC,IAAK;GAAQ,IAAK;GAAQ,IAAK;GAAQ,IAAK;GAAU,GAAG;EAAK;EACzE,MAAM;CACP;;;;;;;CAQA,YAAY,SAAS,SAAS;EAC7B,MAAM,OAAO;EACb,KAAK,WAAW,WAAW,CAAC;EAC5B,KAAK,cAAc,SAAS;CAC7B;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,WAAW;EAChB,OAAO,KAAK,OAAO;CACpB;;;;;;CAOA,UAAU,QAAQ;EACjB,KAAK,SAAS,KAAK,MAAM;EACzB,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;;;;;;CAOA,WAAW,SAAS;EACnB,WAAgB,MAAM,OAAO;EAC7B,KAAK,UAAU,KAAK,YAAY;EAChC,OAAO,KAAK,OAAO;CACpB;;;;;CAMA,SAAS;EACR,IAAI,KAAK,QAAQ,KAAK,SAAS;GAC9B,qBAAqB,KAAK,MAAM;GAChC,KAAK,SAAS,4BAA4B,KAAK,MAAM,CAAC;EACvD;EACA,OAAO;CACR;CAEA,iBAAiB;EAChB,KAAK,aAAa,SAAS,cAAc,QAAQ;EACjD,KAAK,WAAW,UAAU,IAAI,uBAAuB;EACrD,KAAK,OAAO,KAAK,WAAW,WAAW,IAAI;CAC5C;CAEA,oBAAoB;EACnB,qB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