maplair 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/esm/Maplair.js +18 -17
  3. package/dist/esm/Maplair.js.map +1 -1
  4. package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
  5. package/dist/esm/control/AttributionControl.js +25 -16
  6. package/dist/esm/control/AttributionControl.js.map +1 -1
  7. package/dist/esm/control/ButtonControl.js +10 -13
  8. package/dist/esm/control/ButtonControl.js.map +1 -1
  9. package/dist/esm/control/ContextMenu.js +2 -5
  10. package/dist/esm/control/ContextMenu.js.map +1 -1
  11. package/dist/esm/control/Control.js +10 -18
  12. package/dist/esm/control/Control.js.map +1 -1
  13. package/dist/esm/control/FullscreenControl.js +6 -9
  14. package/dist/esm/control/FullscreenControl.js.map +1 -1
  15. package/dist/esm/control/LayersControl.js +170 -65
  16. package/dist/esm/control/LayersControl.js.map +1 -1
  17. package/dist/esm/control/LegendControl.js +8 -11
  18. package/dist/esm/control/LegendControl.js.map +1 -1
  19. package/dist/esm/control/MiniMapControl.js +15 -18
  20. package/dist/esm/control/MiniMapControl.js.map +1 -1
  21. package/dist/esm/control/RotateControl.js +2 -5
  22. package/dist/esm/control/RotateControl.js.map +1 -1
  23. package/dist/esm/control/ScaleControl.js +8 -11
  24. package/dist/esm/control/ScaleControl.js.map +1 -1
  25. package/dist/esm/control/SearchControl.js +100 -19
  26. package/dist/esm/control/SearchControl.js.map +1 -1
  27. package/dist/esm/control/SideBySideControl.js +2 -5
  28. package/dist/esm/control/SideBySideControl.js.map +1 -1
  29. package/dist/esm/control/TextControl.js +6 -9
  30. package/dist/esm/control/TextControl.js.map +1 -1
  31. package/dist/esm/control/TimeControl.js +407 -0
  32. package/dist/esm/control/TimeControl.js.map +1 -0
  33. package/dist/esm/control/ZoomControl.js +23 -36
  34. package/dist/esm/control/ZoomControl.js.map +1 -1
  35. package/dist/esm/core/Class.js +28 -44
  36. package/dist/esm/core/Class.js.map +1 -1
  37. package/dist/esm/core/Events.js +22 -10
  38. package/dist/esm/core/Events.js.map +1 -1
  39. package/dist/esm/core/Handler.js +23 -14
  40. package/dist/esm/core/Handler.js.map +1 -1
  41. package/dist/esm/core/I18n.js +1 -2
  42. package/dist/esm/core/Util.js +15 -4
  43. package/dist/esm/core/Util.js.map +1 -1
  44. package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
  45. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  46. package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
  47. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  48. package/dist/esm/dom/DomEvent.js +18 -60
  49. package/dist/esm/dom/DomEvent.js.map +1 -1
  50. package/dist/esm/dom/DomUtil.js +15 -70
  51. package/dist/esm/dom/DomUtil.js.map +1 -1
  52. package/dist/esm/dom/Draggable.js +21 -21
  53. package/dist/esm/dom/Draggable.js.map +1 -1
  54. package/dist/esm/dom/PosAnimation.js +4 -27
  55. package/dist/esm/dom/PosAnimation.js.map +1 -1
  56. package/dist/esm/geo/LatLng.js +16 -7
  57. package/dist/esm/geo/LatLng.js.map +1 -1
  58. package/dist/esm/geo/LatLngBounds.js +9 -15
  59. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  60. package/dist/esm/geo/crs/CRS.js +1 -2
  61. package/dist/esm/geo/crs/EPSG3395.js +5 -6
  62. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  63. package/dist/esm/geo/crs/EPSG3857.js +5 -6
  64. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  65. package/dist/esm/geo/crs/EPSG4326.js +4 -5
  66. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  67. package/dist/esm/geo/crs/EarthCRS.js +3 -4
  68. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  69. package/dist/esm/geo/crs/SimpleCRS.js +4 -5
  70. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  71. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
  72. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  73. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
  74. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  75. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
  76. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  77. package/dist/esm/geometry/Bounds.js +10 -14
  78. package/dist/esm/geometry/Bounds.js.map +1 -1
  79. package/dist/esm/geometry/LineUtil.js +37 -32
  80. package/dist/esm/geometry/LineUtil.js.map +1 -1
  81. package/dist/esm/geometry/Point.js +1 -2
  82. package/dist/esm/geometry/PolyUtil.js +24 -51
  83. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  84. package/dist/esm/geometry/Transformation.js +1 -2
  85. package/dist/esm/layer/BlanketOverlay.js +7 -10
  86. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  87. package/dist/esm/layer/Classification.js +1 -2
  88. package/dist/esm/layer/DivOverlay.js +16 -22
  89. package/dist/esm/layer/DivOverlay.js.map +1 -1
  90. package/dist/esm/layer/FeatureGroup.js +5 -4
  91. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  92. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  93. package/dist/esm/layer/GeoJSON.js +17 -155
  94. package/dist/esm/layer/GeoJSON.js.map +1 -1
  95. package/dist/esm/layer/GeoJSONUtil.js +74 -0
  96. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  97. package/dist/esm/layer/HeatLayer.js +17 -20
  98. package/dist/esm/layer/HeatLayer.js.map +1 -1
  99. package/dist/esm/layer/ImageOverlay.js +22 -29
  100. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  101. package/dist/esm/layer/Layer.js +9 -12
  102. package/dist/esm/layer/Layer.js.map +1 -1
  103. package/dist/esm/layer/LayerGroup.js +53 -3
  104. package/dist/esm/layer/LayerGroup.js.map +1 -1
  105. package/dist/esm/layer/Popup.js +35 -58
  106. package/dist/esm/layer/Popup.js.map +1 -1
  107. package/dist/esm/layer/SVGOverlay.js +3 -7
  108. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  109. package/dist/esm/layer/Tooltip.js +31 -34
  110. package/dist/esm/layer/Tooltip.js.map +1 -1
  111. package/dist/esm/layer/VideoOverlay.js +13 -17
  112. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  113. package/dist/esm/layer/marker/DefaultIcon.js +38 -49
  114. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  115. package/dist/esm/layer/marker/DivIcon.js +8 -11
  116. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  117. package/dist/esm/layer/marker/Icon.js +9 -12
  118. package/dist/esm/layer/marker/Icon.js.map +1 -1
  119. package/dist/esm/layer/marker/Marker.Drag.js +44 -5
  120. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  121. package/dist/esm/layer/marker/Marker.Move.js +5 -8
  122. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  123. package/dist/esm/layer/marker/Marker.js +115 -47
  124. package/dist/esm/layer/marker/Marker.js.map +1 -1
  125. package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
  126. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  127. package/dist/esm/layer/marker/SvgIcon.js +7 -10
  128. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  129. package/dist/esm/layer/tile/GridLayer.js +89 -101
  130. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  131. package/dist/esm/layer/tile/TileLayer.js +36 -44
  132. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  133. package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
  134. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  135. package/dist/esm/layer/vector/Canvas.js +8 -17
  136. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  137. package/dist/esm/layer/vector/Circle.js +6 -5
  138. package/dist/esm/layer/vector/Circle.js.map +1 -1
  139. package/dist/esm/layer/vector/CircleMarker.js +19 -10
  140. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  141. package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
  142. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  143. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  144. package/dist/esm/layer/vector/Path.js +28 -22
  145. package/dist/esm/layer/vector/Path.js.map +1 -1
  146. package/dist/esm/layer/vector/Polygon.js +22 -7
  147. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  148. package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
  149. package/dist/esm/layer/vector/Polyline.js +25 -10
  150. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  151. package/dist/esm/layer/vector/Rectangle.js +1 -2
  152. package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
  153. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  154. package/dist/esm/layer/vector/Renderer.js +1 -2
  155. package/dist/esm/layer/vector/SVG.js +12 -9
  156. package/dist/esm/layer/vector/SVG.js.map +1 -1
  157. package/dist/esm/map/Hash.js +1 -2
  158. package/dist/esm/map/Map.Rotation.js +41 -22
  159. package/dist/esm/map/Map.Rotation.js.map +1 -1
  160. package/dist/esm/map/Map.js +125 -126
  161. package/dist/esm/map/Map.js.map +1 -1
  162. package/dist/esm/map/MapSync.js +1 -2
  163. package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
  164. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  165. package/dist/esm/map/handler/DisplaceHandler.js +7 -10
  166. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  167. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  168. package/dist/esm/map/handler/DragHandler.js +20 -21
  169. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  170. package/dist/esm/map/handler/KeyboardHandler.js +48 -68
  171. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  172. package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
  173. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  174. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
  175. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  176. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  177. package/dist/esm/map/handler/TapHoldHandler.js +13 -7
  178. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  179. package/dist/esm/package.js +2 -3
  180. package/dist/maplair-global-src.js +6495 -5981
  181. package/dist/maplair-global-src.js.map +1 -1
  182. package/dist/maplair-global.js +2 -2
  183. package/dist/maplair-global.js.map +1 -1
  184. package/dist/maplair-src.js +6206 -5673
  185. package/dist/maplair-src.js.map +1 -1
  186. package/dist/maplair.css +1 -1213
  187. package/dist/maplair.js +2 -2
  188. package/dist/maplair.js.map +1 -1
  189. package/i18n/cs.json +6 -0
  190. package/i18n/de.json +6 -0
  191. package/i18n/en.json +6 -0
  192. package/i18n/es.json +6 -0
  193. package/i18n/fr.json +6 -0
  194. package/i18n/hu.json +6 -0
  195. package/i18n/it.json +6 -0
  196. package/i18n/rm.json +6 -0
  197. package/i18n/sk.json +6 -0
  198. package/i18n/sl.json +6 -0
  199. package/package.json +11 -18
  200. package/src/Maplair.all.js +0 -1
  201. package/src/control/AttributionControl.js +25 -18
  202. package/src/control/ButtonControl.js +9 -11
  203. package/src/control/ContextMenu.js +3 -5
  204. package/src/control/Control.js +9 -19
  205. package/src/control/FullscreenControl.js +5 -7
  206. package/src/control/LayersControl.js +196 -86
  207. package/src/control/LegendControl.js +7 -9
  208. package/src/control/MiniMapControl.js +9 -11
  209. package/src/control/RotateControl.js +3 -5
  210. package/src/control/ScaleControl.js +7 -9
  211. package/src/control/SearchControl.js +102 -19
  212. package/src/control/SideBySideControl.js +3 -5
  213. package/src/control/TextControl.js +5 -7
  214. package/src/control/TimeControl.js +471 -0
  215. package/src/control/ZoomControl.js +22 -38
  216. package/src/control/index.js +1 -0
  217. package/src/core/Class.js +37 -45
  218. package/src/core/Events.js +22 -3
  219. package/src/core/Handler.js +25 -13
  220. package/src/core/Util.js +20 -2
  221. package/src/core/index.js +0 -1
  222. package/src/dom/DomEvent.DoubleTap.js +18 -10
  223. package/src/dom/DomEvent.PointerEvents.js +3 -26
  224. package/src/dom/DomEvent.js +17 -85
  225. package/src/dom/DomUtil.js +22 -78
  226. package/src/dom/Draggable.js +32 -23
  227. package/src/dom/PosAnimation.js +3 -25
  228. package/src/dom/index.js +0 -1
  229. package/src/geo/LatLng.js +20 -3
  230. package/src/geo/LatLngBounds.js +8 -15
  231. package/src/geo/crs/EPSG3395.js +4 -4
  232. package/src/geo/crs/EPSG3857.js +4 -4
  233. package/src/geo/crs/EPSG4326.js +3 -3
  234. package/src/geo/crs/EarthCRS.js +2 -8
  235. package/src/geo/crs/SimpleCRS.js +3 -3
  236. package/src/geo/index.js +1 -2
  237. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
  238. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
  239. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
  240. package/src/geo/projection/index.js +5 -5
  241. package/src/geometry/Bounds.js +12 -17
  242. package/src/geometry/LineUtil.js +48 -49
  243. package/src/geometry/PolyUtil.js +39 -76
  244. package/src/layer/BlanketOverlay.js +6 -10
  245. package/src/layer/DivOverlay.js +16 -27
  246. package/src/layer/FeatureGroup.js +8 -2
  247. package/src/layer/GeoJSON.js +17 -218
  248. package/src/layer/GeoJSONUtil.js +85 -0
  249. package/src/layer/HeatLayer.js +10 -12
  250. package/src/layer/ImageOverlay.js +21 -32
  251. package/src/layer/Layer.js +8 -10
  252. package/src/layer/LayerGroup.js +72 -1
  253. package/src/layer/Popup.js +37 -62
  254. package/src/layer/SVGOverlay.js +1 -5
  255. package/src/layer/Tooltip.js +34 -36
  256. package/src/layer/VideoOverlay.js +12 -15
  257. package/src/layer/marker/DefaultIcon.js +40 -58
  258. package/src/layer/marker/DivIcon.js +9 -11
  259. package/src/layer/marker/Icon.js +9 -10
  260. package/src/layer/marker/Marker.Drag.js +54 -6
  261. package/src/layer/marker/Marker.Move.js +4 -6
  262. package/src/layer/marker/Marker.js +145 -52
  263. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  264. package/src/layer/marker/SvgIcon.js +7 -9
  265. package/src/layer/marker/index.js +1 -0
  266. package/src/layer/tile/GridLayer.js +108 -135
  267. package/src/layer/tile/TileLayer.js +44 -49
  268. package/src/layer/tile/WMSTileLayer.js +31 -26
  269. package/src/layer/vector/Canvas.js +13 -19
  270. package/src/layer/vector/Circle.js +9 -3
  271. package/src/layer/vector/CircleMarker.js +19 -7
  272. package/src/layer/vector/Path.DashAnimation.js +1 -2
  273. package/src/layer/vector/Path.js +30 -21
  274. package/src/layer/vector/Polygon.js +29 -6
  275. package/src/layer/vector/Polyline.js +26 -7
  276. package/src/layer/vector/Renderer.getRenderer.js +20 -19
  277. package/src/layer/vector/SVG.js +17 -7
  278. package/src/map/Map.Rotation.js +40 -8
  279. package/src/map/Map.js +158 -153
  280. package/src/map/handler/BoxZoomHandler.js +30 -50
  281. package/src/map/handler/DisplaceHandler.js +6 -8
  282. package/src/map/handler/DragHandler.js +25 -28
  283. package/src/map/handler/KeyboardHandler.js +65 -90
  284. package/src/map/handler/PinchZoomHandler.js +16 -5
  285. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  286. package/src/map/handler/TapHoldHandler.js +15 -4
  287. package/src/map/index.js +1 -1
  288. package/src/maplair.css +153 -98
  289. package/dist/esm/core/Browser.js +0 -100
  290. package/dist/esm/core/Browser.js.map +0 -1
  291. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  292. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  293. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  294. package/dist/esm/geo/projection/index.js +0 -14
  295. package/dist/esm/geo/projection/index.js.map +0 -1
  296. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  297. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  298. package/dist/images/layers.svg +0 -1
  299. package/dist/images/marker-icon.svg +0 -1
  300. package/dist/images/marker-shadow.svg +0 -1
  301. package/src/core/Browser.js +0 -110
  302. package/src/images/layers.svg +0 -1
  303. package/src/images/marker-icon.svg +0 -1
  304. package/src/images/marker-shadow.svg +0 -1
  305. package/src/layer/marker/Marker.Rotation.js +0 -103
@@ -1,6 +1,8 @@
1
1
  import { setOptions, stamp } from "../core/Util.js";
2
2
  import { Layer } from "./Layer.js";
3
- //#region src/layer/LayerGroup.js
3
+ import { asFeature, getFeature } from "./GeoJSONUtil.js";
4
+ // src/layer/LayerGroup.js
5
+ /** @import {Feature, FeatureCollection} from 'geojson' */
4
6
  /** @import {InteractiveLayerOptions} from './Layer.js' */
5
7
  /** @import {MaplairMap} from '../map/Map.js' */
6
8
  /**
@@ -46,7 +48,7 @@ var LayerGroup = class LayerGroup extends Layer {
46
48
  * @returns {this}
47
49
  */
48
50
  removeLayer(layer) {
49
- const id = layer in this._layers ? layer : this.getLayerId(layer);
51
+ const id = typeof layer === "number" ? layer : this.getLayerId(layer);
50
52
  if (this._map && this._layers[id]) this._map.removeLayer(this._layers[id]);
51
53
  delete this._layers[id];
52
54
  return this;
@@ -128,8 +130,56 @@ var LayerGroup = class LayerGroup extends Layer {
128
130
  getLayerId(layer) {
129
131
  return stamp(layer);
130
132
  }
133
+ /**
134
+ * Returns a GeoJSON `MultiPoint` Feature of the points of the group, used by
135
+ * `toGeoJSON()`.
136
+ * @internal
137
+ * @param {number|false} [precision]
138
+ * @returns {Feature}
139
+ */
140
+ toMultiPoint(precision) {
141
+ const coords = [];
142
+ this.eachLayer((layer) => {
143
+ coords.push(layer.toGeoJSON(precision).geometry.coordinates);
144
+ });
145
+ return getFeature(this, {
146
+ type: "MultiPoint",
147
+ coordinates: coords
148
+ });
149
+ }
150
+ /**
151
+ * Coordinates values are rounded with [`formatNum`](#util-formatnum) to the
152
+ * given `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON)
153
+ * representation of the layer group (as a GeoJSON `FeatureCollection`,
154
+ * `GeometryCollection`, or `MultiPoint`).
155
+ * @param {number|false} [precision]
156
+ * @returns {Feature|FeatureCollection}
157
+ */
158
+ toGeoJSON(precision) {
159
+ const type = this.feature?.geometry?.type;
160
+ if (type === "MultiPoint") return this.toMultiPoint(precision);
161
+ const isGeometryCollection = type === "GeometryCollection", jsons = [];
162
+ this.eachLayer((layer) => {
163
+ if (layer.toGeoJSON) {
164
+ const json = layer.toGeoJSON(precision);
165
+ if (isGeometryCollection) jsons.push(json.geometry);
166
+ else {
167
+ const feature = asFeature(json);
168
+ if (feature.type === "FeatureCollection") jsons.push(...feature.features);
169
+ else jsons.push(feature);
170
+ }
171
+ }
172
+ });
173
+ if (isGeometryCollection) return getFeature(this, {
174
+ geometries: jsons,
175
+ type: "GeometryCollection"
176
+ });
177
+ return {
178
+ type: "FeatureCollection",
179
+ features: jsons
180
+ };
181
+ }
131
182
  };
132
- //#endregion
133
183
  export { LayerGroup };
134
184
 
135
185
  //# sourceMappingURL=LayerGroup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LayerGroup.js","names":["Util.stamp"],"sources":["../../../src/layer/LayerGroup.js"],"sourcesContent":["\nimport {Layer} from './Layer.js';\nimport * as Util from '../core/Util.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Used to group several layers and handle them as one. If you add it to the map,\n * any layers added or removed from the group will be added/removed on the map as\n * well. Extends `Layer`.\n *\n * @example\n * ```js\n * new LayerGroup([marker1, marker2])\n * \t.addLayer(polyline)\n * \t.addTo(map);\n * ```\n */\nexport class LayerGroup extends Layer {\n\n\t/**\n\t * Creates a layer group, optionally given an initial set of layers and an\n\t * `options` object.\n\t * @param {Layer[]} [layers]\n\t * @param {InteractiveLayerOptions} [options]\n\t */\n\tconstructor(layers, options) { // for compatibility of code using `LayerGroup.extend`\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis._layers = {};\n\n\t\tfor (const layer of layers ?? []) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\n\t\tthis.callInitHooks(LayerGroup);\n\t}\n\n\t/**\n\t * Adds the given layer to the group.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tconst id = this.getLayerId(layer);\n\n\t\tthis._layers[id] = layer;\n\n\t\tthis._map?.addLayer(layer);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the given layer, or the layer with the given internal ID, from the group.\n\t * @param {Layer|number} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tconst id = layer in this._layers ? layer : this.getLayerId(layer);\n\n\t\tif (this._map && this._layers[id]) {\n\t\t\tthis._map.removeLayer(this._layers[id]);\n\t\t}\n\n\t\tdelete this._layers[id];\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if the given layer, or the layer with the given internal ID, is\n\t * currently added to the group.\n\t * @param {Layer|number} layer\n\t * @returns {boolean}\n\t */\n\thasLayer(layer) {\n\t\tconst layerId = typeof layer === 'number' ? layer : this.getLayerId(layer);\n\t\treturn layerId in this._layers;\n\t}\n\n\t/**\n\t * Removes all the layers from the group.\n\t * @returns {this}\n\t */\n\tclearLayers() {\n\t\treturn this.eachLayer(this.removeLayer, this);\n\t}\n\n\t/**\n\t * Adds the layers of the group to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis.eachLayer(map.addLayer, map);\n\t}\n\n\t/**\n\t * Removes the layers of the group from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tthis.eachLayer(map.removeLayer, map);\n\t}\n\n\t/**\n\t * Iterates over the layers of the group, optionally specifying context of the\n\t * iterator function.\n\t * ```js\n\t * group.eachLayer(layer => layer.bindPopup('Hello'));\n\t * ```\n\t * @param {(layer: Layer) => void} method\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\teachLayer(method, context) {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tmethod.call(context, layer);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the layer with the given internal ID.\n\t * @param {number} id\n\t * @returns {Layer|undefined}\n\t */\n\tgetLayer(id) {\n\t\treturn this._layers[id];\n\t}\n\n\t/**\n\t * Returns an array of all the layers added to the group.\n\t * @returns {Layer[]}\n\t */\n\tgetLayers() {\n\t\tconst layers = [];\n\t\tthis.eachLayer(layers.push, layers);\n\t\treturn layers;\n\t}\n\n\t/**\n\t * Calls `setZIndex` on every layer contained in this group, passing the z-index.\n\t * @param {number} zIndex\n\t * @returns {this}\n\t */\n\tsetZIndex(zIndex) {\n\t\treturn this.eachLayer(l => l.setZIndex?.(zIndex));\n\t}\n\n\t/**\n\t * Returns the internal ID for a layer.\n\t * @param {Layer} layer\n\t * @returns {number}\n\t */\n\tgetLayerId(layer) {\n\t\treturn Util.stamp(layer);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,IAAa,aAAb,MAAa,mBAAmB,MAAM;;;;;;;CAQrC,YAAY,QAAQ,SAAS;EAC5B,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,UAAU,CAAC;EAEhB,KAAK,MAAM,SAAS,UAAU,CAAC,GAC9B,KAAK,SAAS,KAAK;EAGpB,KAAK,cAAc,UAAU;CAC9B;;;;;;CAOA,SAAS,OAAO;EACf,MAAM,KAAK,KAAK,WAAW,KAAK;EAEhC,KAAK,QAAQ,MAAM;EAEnB,KAAK,MAAM,SAAS,KAAK;EAEzB,OAAO;CACR;;;;;;CAOA,YAAY,OAAO;EAClB,MAAM,KAAK,SAAS,KAAK,UAAU,QAAQ,KAAK,WAAW,KAAK;EAEhE,IAAI,KAAK,QAAQ,KAAK,QAAQ,KAC7B,KAAK,KAAK,YAAY,KAAK,QAAQ,GAAG;EAGvC,OAAO,KAAK,QAAQ;EAEpB,OAAO;CACR;;;;;;;CAQA,SAAS,OAAO;EAEf,QADgB,OAAO,UAAU,WAAW,QAAQ,KAAK,WAAW,KAAK,MACvD,KAAK;CACxB;;;;;CAMA,cAAc;EACb,OAAO,KAAK,UAAU,KAAK,aAAa,IAAI;CAC7C;;;;;CAMA,MAAM,KAAK;EACV,KAAK,UAAU,IAAI,UAAU,GAAG;CACjC;;;;;CAMA,SAAS,KAAK;EACb,KAAK,UAAU,IAAI,aAAa,GAAG;CACpC;;;;;;;;;;;CAYA,UAAU,QAAQ,SAAS;EAC1B,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,OAAO,KAAK,SAAS,KAAK;EAE3B,OAAO;CACR;;;;;;CAOA,SAAS,IAAI;EACZ,OAAO,KAAK,QAAQ;CACrB;;;;;CAMA,YAAY;EACX,MAAM,SAAS,CAAC;EAChB,KAAK,UAAU,OAAO,MAAM,MAAM;EAClC,OAAO;CACR;;;;;;CAOA,UAAU,QAAQ;EACjB,OAAO,KAAK,WAAU,MAAK,EAAE,YAAY,MAAM,CAAC;CACjD;;;;;;CAOA,WAAW,OAAO;EACjB,OAAOA,MAAW,KAAK;CACxB;AACD"}
1
+ {"version":3,"file":"LayerGroup.js","names":["Util.stamp"],"sources":["../../../src/layer/LayerGroup.js"],"sourcesContent":["\nimport {Layer} from './Layer.js';\nimport * as Util from '../core/Util.js';\nimport {getFeature, asFeature} from './GeoJSONUtil.js';\n/** @import {Feature, FeatureCollection} from 'geojson' */\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Used to group several layers and handle them as one. If you add it to the map,\n * any layers added or removed from the group will be added/removed on the map as\n * well. Extends `Layer`.\n *\n * @example\n * ```js\n * new LayerGroup([marker1, marker2])\n * \t.addLayer(polyline)\n * \t.addTo(map);\n * ```\n */\nexport class LayerGroup extends Layer {\n\n\t/**\n\t * Creates a layer group, optionally given an initial set of layers and an\n\t * `options` object.\n\t * @param {Layer[]} [layers]\n\t * @param {InteractiveLayerOptions} [options]\n\t */\n\tconstructor(layers, options) { // for compatibility of code using `LayerGroup.extend`\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis._layers = {};\n\n\t\tfor (const layer of layers ?? []) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\n\t\tthis.callInitHooks(LayerGroup);\n\t}\n\n\t/**\n\t * Adds the given layer to the group.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tconst id = this.getLayerId(layer);\n\n\t\tthis._layers[id] = layer;\n\n\t\tthis._map?.addLayer(layer);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the given layer, or the layer with the given internal ID, from the group.\n\t * @param {Layer|number} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tconst id = typeof layer === 'number' ? layer : this.getLayerId(layer);\n\n\t\tif (this._map && this._layers[id]) {\n\t\t\tthis._map.removeLayer(this._layers[id]);\n\t\t}\n\n\t\tdelete this._layers[id];\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if the given layer, or the layer with the given internal ID, is\n\t * currently added to the group.\n\t * @param {Layer|number} layer\n\t * @returns {boolean}\n\t */\n\thasLayer(layer) {\n\t\tconst layerId = typeof layer === 'number' ? layer : this.getLayerId(layer);\n\t\treturn layerId in this._layers;\n\t}\n\n\t/**\n\t * Removes all the layers from the group.\n\t * @returns {this}\n\t */\n\tclearLayers() {\n\t\treturn this.eachLayer(this.removeLayer, this);\n\t}\n\n\t/**\n\t * Adds the layers of the group to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tthis.eachLayer(map.addLayer, map);\n\t}\n\n\t/**\n\t * Removes the layers of the group from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tthis.eachLayer(map.removeLayer, map);\n\t}\n\n\t/**\n\t * Iterates over the layers of the group, optionally specifying context of the\n\t * iterator function.\n\t * ```js\n\t * group.eachLayer(layer => layer.bindPopup('Hello'));\n\t * ```\n\t * @param {(layer: Layer) => void} method\n\t * @param {object} [context]\n\t * @returns {this}\n\t */\n\teachLayer(method, context) {\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tmethod.call(context, layer);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the layer with the given internal ID.\n\t * @param {number} id\n\t * @returns {Layer|undefined}\n\t */\n\tgetLayer(id) {\n\t\treturn this._layers[id];\n\t}\n\n\t/**\n\t * Returns an array of all the layers added to the group.\n\t * @returns {Layer[]}\n\t */\n\tgetLayers() {\n\t\tconst layers = [];\n\t\tthis.eachLayer(layers.push, layers);\n\t\treturn layers;\n\t}\n\n\t/**\n\t * Calls `setZIndex` on every layer contained in this group, passing the z-index.\n\t * @param {number} zIndex\n\t * @returns {this}\n\t */\n\tsetZIndex(zIndex) {\n\t\treturn this.eachLayer(l => l.setZIndex?.(zIndex));\n\t}\n\n\t/**\n\t * Returns the internal ID for a layer.\n\t * @param {Layer} layer\n\t * @returns {number}\n\t */\n\tgetLayerId(layer) {\n\t\treturn Util.stamp(layer);\n\t}\n\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 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 = 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 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"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,IAAa,aAAb,MAAa,mBAAmB,MAAM;;;;;;;CAQrC,YAAY,QAAQ,SAAS;EAC5B,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,UAAU,CAAC;EAEhB,KAAK,MAAM,SAAS,UAAU,CAAC,GAC9B,KAAK,SAAS,KAAK;EAGpB,KAAK,cAAc,UAAU;CAC9B;;;;;;CAOA,SAAS,OAAO;EACf,MAAM,KAAK,KAAK,WAAW,KAAK;EAEhC,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AW;EAEpB,MAAM,OAAO,KAAK,SAAS,UAAU;EAErC,IAAI,SAAS,cACZ,OAAO,KAAK,aAAa,SAAS;EAGnC,MAAM,uBAAuB,SAAS,sBACtC,QAAQ,CAAC;EAET,KAAK,WAAW,UAAU;GACzB,IAAI,MAAM,WAAW;IACpB,MAAM,OAAO,MAAM,UAAU,SAAS;IACtC,IAAI,sBACH,MAAM,KAAK,KAAK,QAAQ;SAClB;KACN,MAAM,UAAU,UAAU,IAAI;KAE9B,IAAI,QAAQ,SAAS,qBACpB,MAAM,KAAK,GAAG,QAAQ,QAAQ;UAE9B,MAAM,KAAK,OAAO;IAEpB;GACD;EACD,CAAC;EAED,IAAI,sBACH,OAAO,WAAW,MAAM;GACvB,YAAY;GACZ,MAAM;EACP,CAAC;EAGF,OAAO;GACN,MAAM;GACN,UAAU;EACX;CACD;AACD"}
@@ -1,13 +1,12 @@
1
1
  import { Point } from "../geometry/Point.js";
2
- import Browser_default from "../core/Browser.js";
3
- import { disableClickPropagation, disableScrollPropagation, on, stop, stopPropagation } from "../dom/DomEvent.js";
2
+ import { disableClickPropagation, disableScrollPropagation, on, stopPropagation } from "../dom/DomEvent.js";
4
3
  import { create } from "../dom/DomUtil.js";
5
4
  import { I18n } from "../core/I18n.js";
6
5
  import { Layer } from "./Layer.js";
7
6
  import { Path } from "./vector/Path.js";
8
7
  import { FeatureGroup } from "./FeatureGroup.js";
9
8
  import { DivOverlay } from "./DivOverlay.js";
10
- //#region src/layer/Popup.js
9
+ // src/layer/Popup.js
11
10
  /** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */
12
11
  /** @import {LatLngExpression} from '../geo/LatLng.js' */
13
12
  /** @import {PointExpression} from '../geometry/Point.js' */
@@ -23,9 +22,8 @@ import { DivOverlay } from "./DivOverlay.js";
23
22
  * @property {number|null} [maxHeight=null] If set, creates a scrollable container of
24
23
  * the given height inside a popup if its content exceeds it. The scrollable container
25
24
  * can be styled using the `maplair-popup-scrolled` CSS class selector.
26
- * @property {boolean} [autoPan] Set it to `false` if you don't want the map to do
27
- * panning animation to fit the opened popup. Defaults to `true`, unless the user
28
- * prefers reduced motion (`Browser.reducedMotion`).
25
+ * @property {boolean} [autoPan=true] Set it to `false` if you don't want the map to do
26
+ * panning animation to fit the opened popup.
29
27
  * @property {PointExpression|null} [autoPanPaddingTopLeft=null] The margin between the
30
28
  * popup and the top left corner of the map view after autopanning was performed.
31
29
  * @property {PointExpression|null} [autoPanPaddingBottomRight=null] The margin between
@@ -129,15 +127,11 @@ const layerPopupMethods = {
129
127
  */
130
128
  bindPopup(content, options) {
131
129
  this._popup = this._initOverlay(Popup, this._popup, content, options);
132
- if (!this._popupHandlersAdded) {
133
- this.on({
134
- click: this._openPopup,
135
- keypress: this._onKeyPress,
136
- remove: this.closePopup,
137
- move: this._movePopup
138
- });
139
- this._popupHandlersAdded = true;
140
- }
130
+ this.on({
131
+ click: this._openPopup,
132
+ remove: this.closePopup,
133
+ move: this._movePopup
134
+ });
141
135
  return this;
142
136
  },
143
137
  /**
@@ -149,11 +143,9 @@ const layerPopupMethods = {
149
143
  if (this._popup) {
150
144
  this.off({
151
145
  click: this._openPopup,
152
- keypress: this._onKeyPress,
153
146
  remove: this.closePopup,
154
147
  move: this._movePopup
155
148
  });
156
- this._popupHandlersAdded = false;
157
149
  this._popup = null;
158
150
  }
159
151
  return this;
@@ -220,7 +212,7 @@ const layerPopupMethods = {
220
212
  },
221
213
  _openPopup(e) {
222
214
  if (!this._popup || !this._map) return;
223
- stop(e);
215
+ stopPropagation(e);
224
216
  const target = e.propagatedFrom ?? e.target;
225
217
  if (this._popup._source === target && !(target instanceof Path)) {
226
218
  if (this._map.hasLayer(this._popup)) this.closePopup();
@@ -232,13 +224,6 @@ const layerPopupMethods = {
232
224
  },
233
225
  _movePopup(e) {
234
226
  this._popup.setLatLng(e.latlng);
235
- },
236
- _onKeyPress(e) {
237
- if (e.originalEvent.code === "Enter") {
238
- this._popup._openedByKeyboard = true;
239
- this._openPopup(e);
240
- this._popup._openedByKeyboard = false;
241
- }
242
227
  }
243
228
  };
244
229
  /** @typedef {typeof layerPopupMethods} LayerPopupMethods */
@@ -281,25 +266,23 @@ const layerPopupMethods = {
281
266
  * ```
282
267
  */
283
268
  var Popup = class Popup extends DivOverlay {
284
- static {
285
- this.setDefaultOptions({
286
- pane: "popupPane",
287
- offset: [0, 7],
288
- maxWidth: 300,
289
- minWidth: 50,
290
- maxHeight: null,
291
- autoPan: !Browser_default.reducedMotion,
292
- autoPanPaddingTopLeft: null,
293
- autoPanPaddingBottomRight: null,
294
- autoPanPadding: [5, 5],
295
- keepInView: false,
296
- closeButton: true,
297
- autoClose: true,
298
- closeOnEscapeKey: true,
299
- className: "",
300
- trackResize: true
301
- });
302
- }
269
+ static defaultOptions = {
270
+ pane: "popupPane",
271
+ offset: [0, 7],
272
+ maxWidth: 300,
273
+ minWidth: 50,
274
+ maxHeight: null,
275
+ autoPan: true,
276
+ autoPanPaddingTopLeft: null,
277
+ autoPanPaddingBottomRight: null,
278
+ autoPanPadding: [5, 5],
279
+ keepInView: false,
280
+ closeButton: true,
281
+ autoClose: true,
282
+ closeOnEscapeKey: true,
283
+ className: "",
284
+ trackResize: true
285
+ };
303
286
  /**
304
287
  * Instantiates a `Popup` object given an optional `options` object that describes
305
288
  * its appearance and location and an optional `source` object that is used to tag
@@ -342,7 +325,7 @@ var Popup = class Popup extends DivOverlay {
342
325
  const active = document.activeElement;
343
326
  this._returnFocus = map._container.contains(active) && !this._container?.contains(active) ? active : null;
344
327
  super.onAdd(map);
345
- if (this._openedByKeyboard) {
328
+ if (this._source?._clickedByKeyboard) {
346
329
  if (!this._closeButton) this._container.tabIndex = -1;
347
330
  (this._closeButton ?? this._container).focus({ preventScroll: true });
348
331
  }
@@ -381,9 +364,6 @@ var Popup = class Popup extends DivOverlay {
381
364
  const wrapper = this._wrapper = create("div", `${prefix}-content-wrapper`, container);
382
365
  this._contentNode = create("div", `${prefix}-content`, wrapper);
383
366
  disableClickPropagation(container);
384
- on(container, "keydown", (e) => {
385
- if (e.key === "Escape" && this.options.closeOnEscapeKey) this.close();
386
- });
387
367
  disableScrollPropagation(this._contentNode);
388
368
  on(container, "contextmenu", stopPropagation);
389
369
  this._tipContainer = create("div", `${prefix}-tip-container`, container);
@@ -399,14 +379,12 @@ var Popup = class Popup extends DivOverlay {
399
379
  });
400
380
  }
401
381
  if (this.options.trackResize) {
402
- this._resizeObserver = new ResizeObserver(((entries) => {
382
+ this._resizeObserver = new ResizeObserver(() => {
403
383
  if (!this._map) return;
404
- this._containerWidth = entries[0]?.contentRect?.width;
405
- this._containerHeight = entries[0]?.contentRect?.height;
406
384
  this._updateLayout();
407
385
  this._updatePosition();
408
386
  this._adjustPan();
409
- }));
387
+ });
410
388
  this._resizeObserver.observe(this._contentNode);
411
389
  }
412
390
  }
@@ -414,11 +392,10 @@ var Popup = class Popup extends DivOverlay {
414
392
  const container = this._contentNode, style = container.style;
415
393
  style.maxWidth = `${this.options.maxWidth}px`;
416
394
  style.minWidth = `${this.options.minWidth}px`;
417
- const maxHeight = this.options.maxHeight, scrolledClass = "maplair-popup-scrolled";
418
- if (maxHeight && (this._containerHeight ?? container.offsetHeight) > maxHeight) {
419
- style.height = `${maxHeight}px`;
420
- container.classList.add(scrolledClass);
421
- } else container.classList.remove(scrolledClass);
395
+ style.height = "";
396
+ const maxHeight = this.options.maxHeight, scrolled = !!maxHeight && container.offsetHeight > maxHeight;
397
+ if (scrolled) style.height = `${maxHeight}px`;
398
+ container.classList.toggle("maplair-popup-scrolled", scrolled);
422
399
  this._containerWidth = this._container.offsetWidth;
423
400
  this._containerHeight = this._container.offsetHeight;
424
401
  this._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;
@@ -430,6 +407,7 @@ var Popup = class Popup extends DivOverlay {
430
407
  _adjustPan() {
431
408
  if (!this.options.autoPan) return;
432
409
  this._map._panAnim?.stop();
410
+ if (!this._map) return;
433
411
  if (this._autopanning) {
434
412
  this._autopanning = false;
435
413
  return;
@@ -461,7 +439,6 @@ var Popup = class Popup extends DivOverlay {
461
439
  Layer.include(layerPopupMethods);
462
440
  }
463
441
  };
464
- //#endregion
465
442
  export { Popup };
466
443
 
467
444
  //# sourceMappingURL=Popup.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Popup.js","names":["Browser","DomEvent.stopPropagation","DomUtil.create"],"sources":["../../../src/layer/Popup.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport Browser from '../core/Browser.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport {Path} from './vector/Path.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport {I18n} from '../core/I18n.js';\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.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, PopupEvent} from '../core/Events.js' */\n\n/**\n * Options of `Popup`.\n * @typedef {object} PopupOptions\n * @property {string} [pane='popupPane'] `Map pane` where the popup will be added.\n * @property {PointExpression} [offset=[0, 7]] The offset of the popup position.\n * @property {number} [maxWidth=300] Max width of the popup, in pixels.\n * @property {number} [minWidth=50] Min width of the popup, in pixels.\n * @property {number|null} [maxHeight=null] If set, creates a scrollable container of\n * the given height inside a popup if its content exceeds it. The scrollable container\n * can be styled using the `maplair-popup-scrolled` CSS class selector.\n * @property {boolean} [autoPan] Set it to `false` if you don't want the map to do\n * panning animation to fit the opened popup. Defaults to `true`, unless the user\n * prefers reduced motion (`Browser.reducedMotion`).\n * @property {PointExpression|null} [autoPanPaddingTopLeft=null] The margin between the\n * popup and the top left corner of the map view after autopanning was performed.\n * @property {PointExpression|null} [autoPanPaddingBottomRight=null] The margin between\n * the popup and the bottom right corner of the map view after autopanning was\n * performed.\n * @property {PointExpression} [autoPanPadding=[5, 5]] Equivalent of setting both top\n * left and bottom right autopan padding to the same value.\n * @property {boolean} [keepInView=false] Set it to `true` if you want to prevent users\n * from panning the popup off of the screen while it is open.\n * @property {boolean} [closeButton=true] Controls the presence of a close button in\n * the popup.\n * @property {boolean} [autoClose=true] Set it to `false` if you want to override the\n * default behavior of the popup closing when another popup is opened.\n * @property {boolean} [closeOnEscapeKey=true] Set it to `false` if you want to\n * override the default behavior of the ESC key for closing of the popup.\n * @property {boolean} [closeOnClick] Set it if you want to override the default\n * behavior of the popup closing when user clicks on the map. Defaults to the map's\n * [`closePopupOnClick`](#map-closepopuponclick) option.\n * @property {string} [className=''] A custom CSS class name to assign to the popup.\n * @property {boolean} [trackResize=true] Whether the popup shall react to changes in\n * the size of its contents (e.g. when an image inside the popup loads) and reposition\n * itself.\n * @extends DivOverlayOptions\n */\n\n/**\n * Map options of `Popup`.\n * @typedef {object} PopupMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [closePopupOnClick=true] Set it to `false` if you don't want\n * popups to close when user clicks the map.\n */\n\n/**\n * Methods of `MaplairMap` for popups.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#popupopen {PopupEvent} Fired when a popup is opened in the map.\n * @fires MaplairMap#popupclose {PopupEvent} Fired when a popup in the map is closed.\n * @fires MaplairMap#autopanstart {MaplairEvent} Fired when the map starts autopanning\n * when opening a popup.\n */\nconst mapPopupMethods = {\n\t/**\n\t * Opens the specified popup while closing the previously opened (to make sure only\n\t * one is opened at one time for usability).\n\t *\n\t * Alternatively, creates a popup with the specified content and options and opens\n\t * it in the given point on a map. String content is rendered as HTML; sanitize\n\t * untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Popup|DivOverlayContent} popup The popup, or the content of a new popup.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\topenPopup(popup, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Popup, popup, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup previously opened with [openPopup](#map-openpopup) (or the\n\t * given one).\n\t * @group Methods for layers and controls\n\t * @param {Popup} [popup]\n\t * @returns {this}\n\t */\n\tclosePopup(popup) {\n\t\tpopup = arguments.length ? popup : this._popup;\n\t\tpopup?.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapPopupMethods} MapPopupMethods */\n\n/**\n * Methods of `Layer` for popups. All layers share a set of methods convenient for\n * binding popups to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindPopup('Hi There!').addTo(map);\n * layer.openPopup();\n * layer.closePopup();\n * ```\n *\n * Popups will also be automatically opened when the layer is clicked on and closed\n * when the layer is removed from the map or another popup is opened.\n *\n * @lends Layer.prototype\n * @fires Layer#popupopen {PopupEvent} Fired when a popup bound to this layer is opened.\n * @fires Layer#popupclose {PopupEvent} Fired when a popup bound to this layer is closed.\n */\nconst layerPopupMethods = {\n\t/**\n\t * Binds a popup to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an\n\t * `HTMLElement` with safe `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String` or `HTMLElement`.\n\t * @group Popup methods\n\t * @param {DivOverlayContent|Popup} content\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\tbindPopup(content, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._popup = this._initOverlay(Popup, this._popup, content, options);\n\t\tif (!this._popupHandlersAdded) {\n\t\t\tthis.on({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tkeypress: this._onKeyPress,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tthis._popupHandlersAdded = true;\n\t\t}\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the popup previously bound with `bindPopup`.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tunbindPopup() {\n\t\tif (this._popup) {\n\t\t\tthis.off({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tkeypress: this._onKeyPress,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tthis._popupHandlersAdded = false;\n\t\t\tthis._popup = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens the bound popup at the specified `latlng` or at the default popup anchor\n\t * if no `latlng` is passed.\n\t * @group Popup methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenPopup(latlng) {\n\t\tif (this._popup) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._popup._source = this;\n\t\t\t}\n\t\t\tif (this._popup._prepareOpen(latlng || this._latlng)) {\n\t\t\t\t// open the popup on the map\n\t\t\t\tthis._popup.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup bound to this layer if it is open.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tclosePopup() {\n\t\tthis._popup?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the popup bound to this layer depending on its current state.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\ttogglePopup() {\n\t\tthis._popup?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the popup bound to this layer is currently open.\n\t * @group Popup methods\n\t * @returns {boolean}\n\t */\n\tisPopupOpen() {\n\t\treturn this._popup?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the popup bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Popup methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetPopupContent(content) {\n\t\tthis._popup?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the popup bound to this layer.\n\t * @group Popup methods\n\t * @returns {Popup|undefined}\n\t */\n\tgetPopup() {\n\t\treturn this._popup;\n\t},\n\n\t_openPopup(e) {\n\t\tif (!this._popup || !this._map) {\n\t\t\treturn;\n\t\t}\n\t\t// prevent map click\n\t\tDomEvent.stop(e);\n\n\t\tconst target = e.propagatedFrom ?? e.target;\n\t\tif (this._popup._source === target && !(target instanceof Path)) {\n\t\t\t// treat it like a marker and figure out\n\t\t\t// if we should toggle it open/closed\n\t\t\tif (this._map.hasLayer(this._popup)) {\n\t\t\t\tthis.closePopup();\n\t\t\t} else {\n\t\t\t\tthis.openPopup(e.latlng);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._popup._source = target;\n\t\tthis.openPopup(e.latlng);\n\t},\n\n\t_movePopup(e) {\n\t\tthis._popup.setLatLng(e.latlng);\n\t},\n\n\t_onKeyPress(e) {\n\t\tif (e.originalEvent.code === 'Enter') {\n\t\t\tthis._popup._openedByKeyboard = true;\n\t\t\tthis._openPopup(e);\n\t\t\tthis._popup._openedByKeyboard = false;\n\t\t}\n\t}\n};\n/** @typedef {typeof layerPopupMethods} LayerPopupMethods */\n\n/**\n * Used to open popups in certain places of the map. Use [Map.openPopup](#map-openpopup) to\n * open popups while making sure that only one popup is open at one time\n * (recommended for usability), or use [Map.addLayer](#map-addlayer) to open as many as you want.\n *\n * @example\n * If you want to just bind a popup to marker click and then open it, it's really easy:\n *\n * ```js\n * marker.bindPopup(popupContent).openPopup();\n * ```\n * Path overlays like polylines also have a `bindPopup` method.\n *\n * A popup can be also standalone:\n *\n * ```js\n * const popup = new Popup()\n * \t.setLatLng(latlng)\n * \t.setContent('<p>Hello world!<br />This is a nice popup.</p>')\n * \t.openOn(map);\n * ```\n * or\n * ```js\n * const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})\n * \t.openOn(map);\n * ```\n *\n * **Security note.** Popup string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or\n * build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindPopup(el);\n * ```\n */\nexport class Popup extends DivOverlay {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tpane: 'popupPane',\n\t\t\toffset: [0, 7],\n\t\t\tmaxWidth: 300,\n\t\t\tminWidth: 50,\n\t\t\tmaxHeight: null,\n\t\t\tautoPan: !Browser.reducedMotion,\n\t\t\tautoPanPaddingTopLeft: null,\n\t\t\tautoPanPaddingBottomRight: null,\n\t\t\tautoPanPadding: [5, 5],\n\t\t\tkeepInView: false,\n\t\t\tcloseButton: true,\n\t\t\tautoClose: true,\n\t\t\tcloseOnEscapeKey: true,\n\t\t\tclassName: '',\n\t\t\ttrackResize: true,\n\t\t});\n\t}\n\n\t/**\n\t * Instantiates a `Popup` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the popup with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {PopupOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Popup` object given `latlng` where the popup 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 {PopupOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Popup);\n\t}\n\n\t/**\n\t * Alternative to `map.openPopup(popup)`.\n\t * Adds the popup to the map and closes the previous one.\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\n\t\tif (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) {\n\t\t\tmap.removeLayer(map._popup);\n\t\t}\n\t\tmap._popup = this;\n\n\t\treturn super.openOn(map);\n\t}\n\n\t/**\n\t * Adds the popup to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\t// The element to return the focus to when closing the popup, e.g. a marker\n\t\tconst active = document.activeElement;\n\t\tthis._returnFocus = map._container.contains(active) && !this._container?.contains(active) ? active : null;\n\n\t\tsuper.onAdd(map);\n\n\t\tif (this._openedByKeyboard) {\n\t\t\t// Move the focus into the popup, so that its content is read and reachable\n\t\t\tif (!this._closeButton) {\n\t\t\t\tthis._container.tabIndex = -1;\n\t\t\t}\n\t\t\t(this._closeButton ?? this._container).focus({preventScroll: true});\n\t\t}\n\n\t\tmap.fire('popupopen', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupopen', {popup: this}, true);\n\t\t\t// For non-path layers, we toggle the popup when clicking\n\t\t\t// again the layer, so prevent the map to reopen it.\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.on('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the popup from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this._container.contains(document.activeElement) && this._returnFocus?.isConnected) {\n\t\t\tthis._returnFocus.focus({preventScroll: true});\n\t\t}\n\t\tthis._returnFocus = null;\n\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('popupclose', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupclose', {popup: this}, true);\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.off('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the popup listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (this.options.closeOnClick ?? this._map.options.closePopupOnClick) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\tif (this.options.keepInView) {\n\t\t\tevents.moveend = this._adjustPan;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-popup',\n\t\tcontainer = this._container = DomUtil.create('div', `${prefix} ${this.options.className || ''} maplair-zoom-animated`);\n\n\t\tconst wrapper = this._wrapper = DomUtil.create('div', `${prefix}-content-wrapper`, container);\n\t\tthis._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\t// The keyboard handler of the map does not get keys while the focus is in the popup\n\t\tDomEvent.on(container, 'keydown', (e) => {\n\t\t\tif (e.key === 'Escape' && this.options.closeOnEscapeKey) {\n\t\t\t\tthis.close();\n\t\t\t}\n\t\t});\n\t\tDomEvent.disableScrollPropagation(this._contentNode);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stopPropagation);\n\n\t\tthis._tipContainer = DomUtil.create('div', `${prefix}-tip-container`, container);\n\t\tthis._tip = DomUtil.create('div', `${prefix}-tip`, this._tipContainer);\n\n\t\tif (this.options.closeButton) {\n\t\t\tconst closeButton = this._closeButton = DomUtil.create('button', `${prefix}-close-button`, container);\n\t\t\tcloseButton.type = 'button';\n\t\t\tcloseButton.setAttribute('aria-label', I18n.translate('Close popup'));\n\n\t\t\tcloseButton.innerHTML = '<span aria-hidden=\"true\">&#215;</span>';\n\n\t\t\tDomEvent.on(closeButton, 'click', (ev) => {\n\t\t\t\tev.preventDefault();\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.trackResize) {\n\t\t\tthis._resizeObserver = new ResizeObserver(((entries) => {\n\t\t\t\tif (!this._map) { return; }\n\t\t\t\tthis._containerWidth = entries[0]?.contentRect?.width;\n\t\t\t\tthis._containerHeight = entries[0]?.contentRect?.height;\n\n\t\t\t\tthis._updateLayout();\n\t\t\t\tthis._updatePosition();\n\t\t\t\tthis._adjustPan();\n\t\t\t}));\n\n\t\t\tthis._resizeObserver.observe(this._contentNode);\n\t\t}\n\t}\n\n\t_updateLayout() {\n\t\tconst container = this._contentNode,\n\t\tstyle = container.style;\n\n\t\tstyle.maxWidth = `${this.options.maxWidth}px`;\n\t\tstyle.minWidth = `${this.options.minWidth}px`;\n\n\t\tconst maxHeight = this.options.maxHeight,\n\t\tscrolledClass = 'maplair-popup-scrolled';\n\n\t\t// only measure the height (forcing a layout) if needed\n\t\tif (maxHeight && (this._containerHeight ?? container.offsetHeight) > maxHeight) {\n\t\t\tstyle.height = `${maxHeight}px`;\n\t\t\tcontainer.classList.add(scrolledClass);\n\t\t} else {\n\t\t\tcontainer.classList.remove(scrolledClass);\n\t\t}\n\n\t\tthis._containerWidth = this._container.offsetWidth;\n\t\tthis._containerHeight = this._container.offsetHeight;\n\t\t// read along with the size, so that _adjustPan doesn't force another style\n\t\t// recalculation and layout after the popup has been positioned\n\t\tthis._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center),\n\t\tanchor = this._getAnchor();\n\t\tthis._setContainerPosition(pos.add(anchor));\n\t}\n\n\t_adjustPan() {\n\t\tif (!this.options.autoPan) { return; }\n\t\tthis._map._panAnim?.stop();\n\n\t\t// We can endlessly recurse if keepInView is set and the view resets.\n\t\t// Let's guard against that by exiting early if we're responding to our own autopan.\n\t\tif (this._autopanning) {\n\t\t\tthis._autopanning = false;\n\t\t\treturn;\n\t\t}\n\n\t\tconst map = this._map,\n\t\tmarginBottom = this._containerMarginBottom ?? (parseInt(getComputedStyle(this._container).marginBottom, 10) || 0),\n\t\tcontainerHeight = this._containerHeight + marginBottom,\n\t\tcontainerWidth = this._containerWidth,\n\t\tlayerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom);\n\n\t\tlayerPos._add(this._getContainerPosition());\n\n\t\tconst containerPos = map.layerPointToContainerPoint(layerPos),\n\t\tpadding = Point.from(this.options.autoPanPadding),\n\t\tpaddingTL = Point.from(this.options.autoPanPaddingTopLeft ?? padding),\n\t\tpaddingBR = Point.from(this.options.autoPanPaddingBottomRight ?? padding),\n\t\tsize = map.getSize();\n\t\tlet dx = 0,\n\t\tdy = 0;\n\n\t\tif (containerPos.x + containerWidth + paddingBR.x > size.x) { // right\n\t\t\tdx = containerPos.x + containerWidth - size.x + paddingBR.x;\n\t\t}\n\t\tif (containerPos.x - dx - paddingTL.x < 0) { // left\n\t\t\tdx = containerPos.x - paddingTL.x;\n\t\t}\n\t\tif (containerPos.y + containerHeight + paddingBR.y > size.y) { // bottom\n\t\t\tdy = containerPos.y + containerHeight - size.y + paddingBR.y;\n\t\t}\n\t\tif (containerPos.y - dy - paddingTL.y < 0) { // top\n\t\t\tdy = containerPos.y - paddingTL.y;\n\t\t}\n\n\t\tif (dx || dy) {\n\t\t\t// Track that we're autopanning, as this function will be re-ran on moveend\n\t\t\tif (this.options.keepInView) {\n\t\t\t\tthis._autopanning = true;\n\t\t\t}\n\n\t\t\tmap\n\t\t\t\t.fire('autopanstart')\n\t\t\t\t.panBy([dx, dy]);\n\t\t}\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the popup on the source layer?\n\t\treturn new Point(this._source?._getPopupAnchor ? this._source._getPopupAnchor() : [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.mergeOptions({\n\t\t\tclosePopupOnClick: true\n\t\t});\n\n\t\tMaplairMap.include(mapPopupMethods);\n\n\t\tLayer.include(layerPopupMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,MAAM,kBAAkB;;;;;;;;;;;;;;CAcvB,UAAU,OAAO,QAAQ,SAAS;EAEjC,KAAK,aAAa,OAAO,OAAO,QAAQ,OAAO,CAAC,CAC9C,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C,IAAI,aAAa,IAAI,kBAAkB,UAAU,IAAI,KAAK,GACzD,KAAK,aAAa,IAAI,kBAAkB,KAAK,IAAI,UAAU;EAE5D,IAAI,aAAa,IAAI,KAAK,UAAU,IAAI,GACvC,KAAK,aAAa,IAAI,UAAU;EAGjC,IAAI,MAAM,IAAI;GAEb,IAAI,KAAK,QAAQ,YAChB,KAAK,eAAe;GAGrB,IACE,KAAK,cAAc,CAAC,CACpB,MAAM,CAAC,IAAI,EAAE,CAAC;EACjB;CACD;CAEA,aAAa;EAEZ,OAAO,IAAI,MAAM,KAAK,SAAS,kBAAkB,KAAK,QAAQ,gBAAgB,IAAI,CAAC,GAAG,CAAC,CAAC;CACzF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,mBAAmB,KACpB,CAAC;EAED,WAAW,QAAQ,eAAe;EAElC,MAAM,QAAQ,iBAAiB;CAChC;AACD"}
1
+ {"version":3,"file":"Popup.js","names":["DomEvent.stopPropagation","DomUtil.create"],"sources":["../../../src/layer/Popup.js"],"sourcesContent":["import {DivOverlay} from './DivOverlay.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.js';\nimport {Path} from './vector/Path.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport {I18n} from '../core/I18n.js';\n\n/** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.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, PopupEvent} from '../core/Events.js' */\n\n/**\n * Options of `Popup`.\n * @typedef {object} PopupOptions\n * @property {string} [pane='popupPane'] `Map pane` where the popup will be added.\n * @property {PointExpression} [offset=[0, 7]] The offset of the popup position.\n * @property {number} [maxWidth=300] Max width of the popup, in pixels.\n * @property {number} [minWidth=50] Min width of the popup, in pixels.\n * @property {number|null} [maxHeight=null] If set, creates a scrollable container of\n * the given height inside a popup if its content exceeds it. The scrollable container\n * can be styled using the `maplair-popup-scrolled` CSS class selector.\n * @property {boolean} [autoPan=true] Set it to `false` if you don't want the map to do\n * panning animation to fit the opened popup.\n * @property {PointExpression|null} [autoPanPaddingTopLeft=null] The margin between the\n * popup and the top left corner of the map view after autopanning was performed.\n * @property {PointExpression|null} [autoPanPaddingBottomRight=null] The margin between\n * the popup and the bottom right corner of the map view after autopanning was\n * performed.\n * @property {PointExpression} [autoPanPadding=[5, 5]] Equivalent of setting both top\n * left and bottom right autopan padding to the same value.\n * @property {boolean} [keepInView=false] Set it to `true` if you want to prevent users\n * from panning the popup off of the screen while it is open.\n * @property {boolean} [closeButton=true] Controls the presence of a close button in\n * the popup.\n * @property {boolean} [autoClose=true] Set it to `false` if you want to override the\n * default behavior of the popup closing when another popup is opened.\n * @property {boolean} [closeOnEscapeKey=true] Set it to `false` if you want to\n * override the default behavior of the ESC key for closing of the popup.\n * @property {boolean} [closeOnClick] Set it if you want to override the default\n * behavior of the popup closing when user clicks on the map. Defaults to the map's\n * [`closePopupOnClick`](#map-closepopuponclick) option.\n * @property {string} [className=''] A custom CSS class name to assign to the popup.\n * @property {boolean} [trackResize=true] Whether the popup shall react to changes in\n * the size of its contents (e.g. when an image inside the popup loads) and reposition\n * itself.\n * @extends DivOverlayOptions\n */\n\n/**\n * Map options of `Popup`.\n * @typedef {object} PopupMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [closePopupOnClick=true] Set it to `false` if you don't want\n * popups to close when user clicks the map.\n */\n\n/**\n * Methods of `MaplairMap` for popups.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#popupopen {PopupEvent} Fired when a popup is opened in the map.\n * @fires MaplairMap#popupclose {PopupEvent} Fired when a popup in the map is closed.\n * @fires MaplairMap#autopanstart {MaplairEvent} Fired when the map starts autopanning\n * when opening a popup.\n */\nconst mapPopupMethods = {\n\t/**\n\t * Opens the specified popup while closing the previously opened (to make sure only\n\t * one is opened at one time for usability).\n\t *\n\t * Alternatively, creates a popup with the specified content and options and opens\n\t * it in the given point on a map. String content is rendered as HTML; sanitize\n\t * untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t * @group Methods for layers and controls\n\t * @param {Popup|DivOverlayContent} popup The popup, or the content of a new popup.\n\t * @param {LatLngExpression} [latlng]\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\topenPopup(popup, latlng, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._initOverlay(Popup, popup, latlng, options)\n\t\t\t.openOn(this);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup previously opened with [openPopup](#map-openpopup) (or the\n\t * given one).\n\t * @group Methods for layers and controls\n\t * @param {Popup} [popup]\n\t * @returns {this}\n\t */\n\tclosePopup(popup) {\n\t\tpopup = arguments.length ? popup : this._popup;\n\t\tpopup?.close();\n\t\treturn this;\n\t}\n};\n/** @typedef {typeof mapPopupMethods} MapPopupMethods */\n\n/**\n * Methods of `Layer` for popups. All layers share a set of methods convenient for\n * binding popups to it.\n *\n * ```js\n * const layer = new Polygon(latlngs).bindPopup('Hi There!').addTo(map);\n * layer.openPopup();\n * layer.closePopup();\n * ```\n *\n * Popups will also be automatically opened when the layer is clicked on and closed\n * when the layer is removed from the map or another popup is opened.\n *\n * @lends Layer.prototype\n * @fires Layer#popupopen {PopupEvent} Fired when a popup bound to this layer is opened.\n * @fires Layer#popupclose {PopupEvent} Fired when a popup bound to this layer is closed.\n */\nconst layerPopupMethods = {\n\t/**\n\t * Binds a popup to the layer with the passed `content` and sets up the\n\t * necessary event listeners. A `String` argument is rendered as HTML; if it\n\t * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an\n\t * `HTMLElement` with safe `textContent` instead. If a `Function` is passed\n\t * it will receive the layer as the first argument and should return a\n\t * `String` or `HTMLElement`.\n\t * @group Popup methods\n\t * @param {DivOverlayContent|Popup} content\n\t * @param {PopupOptions} [options]\n\t * @returns {this}\n\t */\n\tbindPopup(content, options) {\n\t\t// eslint-disable-next-line no-use-before-define -- defined below, used when called\n\t\tthis._popup = this._initOverlay(Popup, this._popup, content, options);\n\t\tthis.on({\n\t\t\tclick: this._openPopup,\n\t\t\tremove: this.closePopup,\n\t\t\tmove: this._movePopup\n\t\t});\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the popup previously bound with `bindPopup`.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tunbindPopup() {\n\t\tif (this._popup) {\n\t\t\tthis.off({\n\t\t\t\tclick: this._openPopup,\n\t\t\t\tremove: this.closePopup,\n\t\t\t\tmove: this._movePopup\n\t\t\t});\n\t\t\tthis._popup = null;\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens the bound popup at the specified `latlng` or at the default popup anchor\n\t * if no `latlng` is passed.\n\t * @group Popup methods\n\t * @param {LatLngExpression} [latlng]\n\t * @returns {this}\n\t */\n\topenPopup(latlng) {\n\t\tif (this._popup) {\n\t\t\tif (!(this instanceof FeatureGroup)) {\n\t\t\t\tthis._popup._source = this;\n\t\t\t}\n\t\t\tif (this._popup._prepareOpen(latlng || this._latlng)) {\n\t\t\t\t// open the popup on the map\n\t\t\t\tthis._popup.openOn(this._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Closes the popup bound to this layer if it is open.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\tclosePopup() {\n\t\tthis._popup?.close();\n\t\treturn this;\n\t},\n\n\t/**\n\t * Opens or closes the popup bound to this layer depending on its current state.\n\t * @group Popup methods\n\t * @returns {this}\n\t */\n\ttogglePopup() {\n\t\tthis._popup?.toggle(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the popup bound to this layer is currently open.\n\t * @group Popup methods\n\t * @returns {boolean}\n\t */\n\tisPopupOpen() {\n\t\treturn this._popup?.isOpen() ?? false;\n\t},\n\n\t/**\n\t * Sets the content of the popup bound to this layer. String content is rendered\n\t * as HTML; sanitize untrusted input or pass an `HTMLElement` with safe\n\t * `textContent` instead.\n\t * @group Popup methods\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetPopupContent(content) {\n\t\tthis._popup?.setContent(content);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns the popup bound to this layer.\n\t * @group Popup methods\n\t * @returns {Popup|undefined}\n\t */\n\tgetPopup() {\n\t\treturn this._popup;\n\t},\n\n\t_openPopup(e) {\n\t\tif (!this._popup || !this._map) {\n\t\t\treturn;\n\t\t}\n\t\t// prevent map click\n\t\tDomEvent.stopPropagation(e);\n\n\t\tconst target = e.propagatedFrom ?? e.target;\n\t\tif (this._popup._source === target && !(target instanceof Path)) {\n\t\t\t// treat it like a marker and figure out\n\t\t\t// if we should toggle it open/closed\n\t\t\tif (this._map.hasLayer(this._popup)) {\n\t\t\t\tthis.closePopup();\n\t\t\t} else {\n\t\t\t\tthis.openPopup(e.latlng);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._popup._source = target;\n\t\tthis.openPopup(e.latlng);\n\t},\n\n\t_movePopup(e) {\n\t\tthis._popup.setLatLng(e.latlng);\n\t}\n};\n/** @typedef {typeof layerPopupMethods} LayerPopupMethods */\n\n/**\n * Used to open popups in certain places of the map. Use [Map.openPopup](#map-openpopup) to\n * open popups while making sure that only one popup is open at one time\n * (recommended for usability), or use [Map.addLayer](#map-addlayer) to open as many as you want.\n *\n * @example\n * If you want to just bind a popup to marker click and then open it, it's really easy:\n *\n * ```js\n * marker.bindPopup(popupContent).openPopup();\n * ```\n * Path overlays like polylines also have a `bindPopup` method.\n *\n * A popup can be also standalone:\n *\n * ```js\n * const popup = new Popup()\n * \t.setLatLng(latlng)\n * \t.setContent('<p>Hello world!<br />This is a nice popup.</p>')\n * \t.openOn(map);\n * ```\n * or\n * ```js\n * const popup = new Popup(latlng, {content: '<p>Hello world!<br />This is a nice popup.</p>'})\n * \t.openOn(map);\n * ```\n *\n * **Security note.** Popup string content is rendered as HTML. If your content\n * may include untrusted input (e.g. data from users or external APIs), sanitize\n * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or\n * build a DOM element using `textContent` to render it as plain text:\n *\n * ```js\n * const el = document.createElement('div');\n * el.textContent = untrustedString;\n * marker.bindPopup(el);\n * ```\n */\nexport class Popup extends DivOverlay {\n\n\tstatic defaultOptions = {\n\t\tpane: 'popupPane',\n\t\toffset: [0, 7],\n\t\tmaxWidth: 300,\n\t\tminWidth: 50,\n\t\tmaxHeight: null,\n\t\tautoPan: true,\n\t\tautoPanPaddingTopLeft: null,\n\t\tautoPanPaddingBottomRight: null,\n\t\tautoPanPadding: [5, 5],\n\t\tkeepInView: false,\n\t\tcloseButton: true,\n\t\tautoClose: true,\n\t\tcloseOnEscapeKey: true,\n\t\tclassName: '',\n\t\ttrackResize: true,\n\t};\n\n\t/**\n\t * Instantiates a `Popup` object given an optional `options` object that describes\n\t * its appearance and location and an optional `source` object that is used to tag\n\t * the popup with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {PopupOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates a `Popup` object given `latlng` where the popup 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 {PopupOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(Popup);\n\t}\n\n\t/**\n\t * Alternative to `map.openPopup(popup)`.\n\t * Adds the popup to the map and closes the previous one.\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\n\t\tif (!map.hasLayer(this) && map._popup && map._popup.options.autoClose) {\n\t\t\tmap.removeLayer(map._popup);\n\t\t}\n\t\tmap._popup = this;\n\n\t\treturn super.openOn(map);\n\t}\n\n\t/**\n\t * Adds the popup to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\t// The element to return the focus to when closing the popup, e.g. a marker\n\t\tconst active = document.activeElement;\n\t\tthis._returnFocus = map._container.contains(active) && !this._container?.contains(active) ? active : null;\n\n\t\tsuper.onAdd(map);\n\n\t\tif (this._source?._clickedByKeyboard) {\n\t\t\t// Move the focus into the popup, so that its content is read and reachable\n\t\t\tif (!this._closeButton) {\n\t\t\t\tthis._container.tabIndex = -1;\n\t\t\t}\n\t\t\t(this._closeButton ?? this._container).focus({preventScroll: true});\n\t\t}\n\n\t\tmap.fire('popupopen', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupopen', {popup: this}, true);\n\t\t\t// For non-path layers, we toggle the popup when clicking\n\t\t\t// again the layer, so prevent the map to reopen it.\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.on('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the popup from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this._container.contains(document.activeElement) && this._returnFocus?.isConnected) {\n\t\t\tthis._returnFocus.focus({preventScroll: true});\n\t\t}\n\t\tthis._returnFocus = null;\n\n\t\tsuper.onRemove(map);\n\n\t\tmap.fire('popupclose', {popup: this});\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupclose', {popup: this}, true);\n\t\t\tif (!(this._source instanceof Path)) {\n\t\t\t\tthis._source.off('preclick', DomEvent.stopPropagation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Returns the map events the popup listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = super.getEvents();\n\n\t\tif (this.options.closeOnClick ?? this._map.options.closePopupOnClick) {\n\t\t\tevents.preclick = this.close;\n\t\t}\n\n\t\tif (this.options.keepInView) {\n\t\t\tevents.moveend = this._adjustPan;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\t_initLayout() {\n\t\tconst prefix = 'maplair-popup',\n\t\tcontainer = this._container = DomUtil.create('div', `${prefix} ${this.options.className || ''} maplair-zoom-animated`);\n\n\t\tconst wrapper = this._wrapper = DomUtil.create('div', `${prefix}-content-wrapper`, container);\n\t\tthis._contentNode = DomUtil.create('div', `${prefix}-content`, wrapper);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(this._contentNode);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stopPropagation);\n\n\t\tthis._tipContainer = DomUtil.create('div', `${prefix}-tip-container`, container);\n\t\tthis._tip = DomUtil.create('div', `${prefix}-tip`, this._tipContainer);\n\n\t\tif (this.options.closeButton) {\n\t\t\tconst closeButton = this._closeButton = DomUtil.create('button', `${prefix}-close-button`, container);\n\t\t\tcloseButton.type = 'button';\n\t\t\tcloseButton.setAttribute('aria-label', I18n.translate('Close popup'));\n\n\t\t\tcloseButton.innerHTML = '<span aria-hidden=\"true\">&#215;</span>';\n\n\t\t\tDomEvent.on(closeButton, 'click', (ev) => {\n\t\t\t\tev.preventDefault();\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tif (this.options.trackResize) {\n\t\t\tthis._resizeObserver = new ResizeObserver(() => {\n\t\t\t\tif (!this._map) { return; }\n\t\t\t\tthis._updateLayout();\n\t\t\t\tthis._updatePosition();\n\t\t\t\tthis._adjustPan();\n\t\t\t});\n\n\t\t\tthis._resizeObserver.observe(this._contentNode);\n\t\t}\n\t}\n\n\t_updateLayout() {\n\t\tconst container = this._contentNode,\n\t\tstyle = container.style;\n\n\t\tstyle.maxWidth = `${this.options.maxWidth}px`;\n\t\tstyle.minWidth = `${this.options.minWidth}px`;\n\n\t\tstyle.height = '';\n\n\t\t// only measure the height of the content (forcing a layout) if needed\n\t\tconst maxHeight = this.options.maxHeight,\n\t\tscrolled = !!maxHeight && container.offsetHeight > maxHeight;\n\t\tif (scrolled) {\n\t\t\tstyle.height = `${maxHeight}px`;\n\t\t}\n\t\tcontainer.classList.toggle('maplair-popup-scrolled', scrolled);\n\n\t\tthis._containerWidth = this._container.offsetWidth;\n\t\tthis._containerHeight = this._container.offsetHeight;\n\t\t// read along with the size, so that _adjustPan doesn't force another style\n\t\t// recalculation and layout after the popup has been positioned\n\t\tthis._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center),\n\t\tanchor = this._getAnchor();\n\t\tthis._setContainerPosition(pos.add(anchor));\n\t}\n\n\t_adjustPan() {\n\t\tif (!this.options.autoPan) { return; }\n\t\tthis._map._panAnim?.stop();\n\n\t\t// Stopping the pan fires `moveend`, whose listeners may have removed this popup.\n\t\tif (!this._map) { return; }\n\n\t\t// We can endlessly recurse if keepInView is set and the view resets.\n\t\t// Let's guard against that by exiting early if we're responding to our own autopan.\n\t\tif (this._autopanning) {\n\t\t\tthis._autopanning = false;\n\t\t\treturn;\n\t\t}\n\n\t\tconst map = this._map,\n\t\tmarginBottom = this._containerMarginBottom ?? (parseInt(getComputedStyle(this._container).marginBottom, 10) || 0),\n\t\tcontainerHeight = this._containerHeight + marginBottom,\n\t\tcontainerWidth = this._containerWidth,\n\t\tlayerPos = new Point(this._containerLeft, -containerHeight - this._containerBottom);\n\n\t\tlayerPos._add(this._getContainerPosition());\n\n\t\tconst containerPos = map.layerPointToContainerPoint(layerPos),\n\t\tpadding = Point.from(this.options.autoPanPadding),\n\t\tpaddingTL = Point.from(this.options.autoPanPaddingTopLeft ?? padding),\n\t\tpaddingBR = Point.from(this.options.autoPanPaddingBottomRight ?? padding),\n\t\tsize = map.getSize();\n\t\tlet dx = 0,\n\t\tdy = 0;\n\n\t\tif (containerPos.x + containerWidth + paddingBR.x > size.x) { // right\n\t\t\tdx = containerPos.x + containerWidth - size.x + paddingBR.x;\n\t\t}\n\t\tif (containerPos.x - dx - paddingTL.x < 0) { // left\n\t\t\tdx = containerPos.x - paddingTL.x;\n\t\t}\n\t\tif (containerPos.y + containerHeight + paddingBR.y > size.y) { // bottom\n\t\t\tdy = containerPos.y + containerHeight - size.y + paddingBR.y;\n\t\t}\n\t\tif (containerPos.y - dy - paddingTL.y < 0) { // top\n\t\t\tdy = containerPos.y - paddingTL.y;\n\t\t}\n\n\t\tif (dx || dy) {\n\t\t\t// Track that we're autopanning, as this function will be re-ran on moveend\n\t\t\tif (this.options.keepInView) {\n\t\t\t\tthis._autopanning = true;\n\t\t\t}\n\n\t\t\tmap\n\t\t\t\t.fire('autopanstart')\n\t\t\t\t.panBy([dx, dy]);\n\t\t}\n\t}\n\n\t_getAnchor() {\n\t\t// Where should we anchor the popup on the source layer?\n\t\treturn new Point(this._source?._getPopupAnchor ? this._source._getPopupAnchor() : [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.mergeOptions({\n\t\t\tclosePopupOnClick: true\n\t\t});\n\n\t\tMaplairMap.include(mapPopupMethods);\n\n\t\tLayer.include(layerPopupMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,kBAAkB;;;;;;;;;;;;;;CAcvB,UAAU,OAAO,QAAQ,SAAS;EAEjC,KAAK,aAAa,OAAO,OAAO,QAAQ,OAAO,CAAC,CAC9C,OAAO,IAAI;EAEb,OAAO;CACR;;;;;;;;CASA,WAAW,OAAO;EACjB,QAAQ,UAAU,SAAS,QAAQ,KAAK;EACxC,OAAO,MAAM;EACb,OAAO;CACR;AACD;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;;;;;;;;;;;;;CAazB,UAAU,SAAS,SAAS;EAE3B,KAAK,SAAS,KAAK,aAAa,OA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MAAM,KAAK,gBAAgB,CAAC,kBAAkB,KAAK,gBAAgB;EAElF,SAAS,KAAK,KAAK,sBAAsB,CAAC;EAE1C,MAAM,eAAe,IAAI,2BAA2B,QAAQ,GAC5D,UAAU,MAAM,KAAK,KAAK,QAAQ,cAAc,GAChD,YAAY,MAAM,KAAK,KAAK,QAAQ,yBAAyB,OAAO,GACpE,YAAY,MAAM,KAAK,KAAK,QAAQ,6BAA6B,OAAO,GACxE,OAAO,IAAI,QAAQ;EACnB,IAAI,KAAK,GACT,KAAK;EAEL,IAAI,aAAa,IAAI,iBAAiB,UAAU,IAAI,KAAK,GACxD,KAAK,aAAa,IAAI,iBAAiB,KAAK,IAAI,UAAU;EAE3D,IAAI,aAAa,IAAI,KAAK,UAAU,IAAI,GACvC,KAAK,aAAa,IAAI,UAAU;EAEjC,IAAI,aAAa,IAAI,kBAAkB,UAAU,IAAI,KAAK,GACzD,KAAK,aAAa,IAAI,kBAAkB,KAAK,IAAI,UAAU;EAE5D,IAAI,aAAa,IAAI,KAAK,UAAU,IAAI,GACvC,KAAK,aAAa,IAAI,UAAU;EAGjC,IAAI,MAAM,IAAI;GAEb,IAAI,KAAK,QAAQ,YAChB,KAAK,eAAe;GAGrB,IACE,KAAK,cAAc,CAAC,CACpB,MAAM,CAAC,IAAI,EAAE,CAAC;EACjB;CACD;CAEA,aAAa;EAEZ,OAAO,IAAI,MAAM,KAAK,SAAS,kBAAkB,KAAK,QAAQ,gBAAgB,IAAI,CAAC,GAAG,CAAC,CAAC;CACzF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,mBAAmB,KACpB,CAAC;EAED,WAAW,QAAQ,eAAe;EAElC,MAAM,QAAQ,iBAAiB;CAChC;AACD"}
@@ -1,6 +1,6 @@
1
- import { falseFn, splitWords } from "../core/Util.js";
1
+ import { splitWords } from "../core/Util.js";
2
2
  import { ImageOverlay } from "./ImageOverlay.js";
3
- //#region src/layer/SVGOverlay.js
3
+ // src/layer/SVGOverlay.js
4
4
  /** @import {ImageOverlayOptions} from './ImageOverlay.js' */
5
5
  /** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */
6
6
  /**
@@ -41,14 +41,10 @@ var SVGOverlay = class SVGOverlay extends ImageOverlay {
41
41
  }
42
42
  _initImage() {
43
43
  const el = this._image = this._url;
44
- el.classList.add("maplair-image-layer");
45
- if (this._zoomAnimated) el.classList.add("maplair-zoom-animated");
44
+ el.classList.add("maplair-image-layer", "maplair-zoom-animated");
46
45
  if (this.options.className) el.classList.add(...splitWords(this.options.className));
47
- el.onselectstart = falseFn;
48
- el.onpointermove = falseFn;
49
46
  }
50
47
  };
51
- //#endregion
52
48
  export { SVGOverlay };
53
49
 
54
50
  //# sourceMappingURL=SVGOverlay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SVGOverlay.js","names":["Util.splitWords","Util.falseFn"],"sources":["../../../src/layer/SVGOverlay.js"],"sourcesContent":["import {ImageOverlay} from './ImageOverlay.js';\nimport * as Util from '../core/Util.js';\n\n/** @import {ImageOverlayOptions} from './ImageOverlay.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n\n/**\n * Used to load, display and provide DOM access to an SVG file over specific bounds of\n * the map. Extends `ImageOverlay`.\n *\n * An SVG overlay uses the [`<svg>`](https://developer.mozilla.org/docs/Web/SVG/Element/svg)\n * element; `getElement()` returns the instance of\n * [`SVGElement`](https://developer.mozilla.org/docs/Web/API/SVGElement) used by this\n * overlay.\n *\n * @example\n * ```js\n * const svgElement = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n * svgElement.setAttribute('xmlns', \"http://www.w3.org/2000/svg\");\n * svgElement.setAttribute('viewBox', \"0 0 200 200\");\n * svgElement.innerHTML = '<rect width=\"200\" height=\"200\"/><rect x=\"75\" y=\"23\" width=\"50\" height=\"50\" style=\"fill:red\"/><rect x=\"75\" y=\"123\" width=\"50\" height=\"50\" style=\"fill:#0013ff\"/>';\n * const svgElementBounds = [ [ 32, -130 ], [ 13, -100 ] ];\n * new SVGOverlay(svgElement, svgElementBounds).addTo(map);\n * ```\n */\nexport class SVGOverlay extends ImageOverlay {\n\t/**\n\t * Instantiates an image overlay object given an SVG element and the geographical\n\t * bounds it is tied to. A viewBox attribute is required on the SVG element to zoom\n\t * in and out properly.\n\t * @overload\n\t * @param {SVGElement} svg\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {ImageOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(SVGOverlay);\n\t}\n\n\t_initImage() {\n\t\tconst el = this._image = this._url;\n\n\t\tel.classList.add('maplair-image-layer');\n\t\tif (this._zoomAnimated) { el.classList.add('maplair-zoom-animated'); }\n\t\tif (this.options.className) { el.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\tel.onselectstart = Util.falseFn;\n\t\tel.onpointermove = Util.falseFn;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,aAAb,MAAa,mBAAmB,aAAa;;;;;;;;;;;;;CAa5C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,UAAU;CAC9B;CAEA,aAAa;EACZ,MAAM,KAAK,KAAK,SAAS,KAAK;EAE9B,GAAG,UAAU,IAAI,qBAAqB;EACtC,IAAI,KAAK,eAAiB,GAAG,UAAU,IAAI,uBAAuB;EAClE,IAAI,KAAK,QAAQ,WAAa,GAAG,UAAU,IAAI,GAAGA,WAAgB,KAAK,QAAQ,SAAS,CAAC;EAEzF,GAAG,gBAAgBC;EACnB,GAAG,gBAAgBA;CACpB;AACD"}
1
+ {"version":3,"file":"SVGOverlay.js","names":["Util.splitWords"],"sources":["../../../src/layer/SVGOverlay.js"],"sourcesContent":["import {ImageOverlay} from './ImageOverlay.js';\nimport * as Util from '../core/Util.js';\n\n/** @import {ImageOverlayOptions} from './ImageOverlay.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n\n/**\n * Used to load, display and provide DOM access to an SVG file over specific bounds of\n * the map. Extends `ImageOverlay`.\n *\n * An SVG overlay uses the [`<svg>`](https://developer.mozilla.org/docs/Web/SVG/Element/svg)\n * element; `getElement()` returns the instance of\n * [`SVGElement`](https://developer.mozilla.org/docs/Web/API/SVGElement) used by this\n * overlay.\n *\n * @example\n * ```js\n * const svgElement = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n * svgElement.setAttribute('xmlns', \"http://www.w3.org/2000/svg\");\n * svgElement.setAttribute('viewBox', \"0 0 200 200\");\n * svgElement.innerHTML = '<rect width=\"200\" height=\"200\"/><rect x=\"75\" y=\"23\" width=\"50\" height=\"50\" style=\"fill:red\"/><rect x=\"75\" y=\"123\" width=\"50\" height=\"50\" style=\"fill:#0013ff\"/>';\n * const svgElementBounds = [ [ 32, -130 ], [ 13, -100 ] ];\n * new SVGOverlay(svgElement, svgElementBounds).addTo(map);\n * ```\n */\nexport class SVGOverlay extends ImageOverlay {\n\t/**\n\t * Instantiates an image overlay object given an SVG element and the geographical\n\t * bounds it is tied to. A viewBox attribute is required on the SVG element to zoom\n\t * in and out properly.\n\t * @overload\n\t * @param {SVGElement} svg\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {ImageOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {...any} args\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(SVGOverlay);\n\t}\n\n\t_initImage() {\n\t\tconst el = this._image = this._url;\n\n\t\tel.classList.add('maplair-image-layer', 'maplair-zoom-animated');\n\t\tif (this.options.className) { el.classList.add(...Util.splitWords(this.options.className)); }\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,aAAb,MAAa,mBAAmB,aAAa;;;;;;;;;;;;;CAa5C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,UAAU;CAC9B;CAEA,aAAa;EACZ,MAAM,KAAK,KAAK,SAAS,KAAK;EAE9B,GAAG,UAAU,IAAI,uBAAuB,uBAAuB;EAC/D,IAAI,KAAK,QAAQ,WAAa,GAAG,UAAU,IAAI,GAAGA,WAAgB,KAAK,QAAQ,SAAS,CAAC;CAC1F;AACD"}
@@ -5,7 +5,7 @@ import { create } from "../dom/DomUtil.js";
5
5
  import { Layer } from "./Layer.js";
6
6
  import { FeatureGroup } from "./FeatureGroup.js";
7
7
  import { DivOverlay } from "./DivOverlay.js";
8
- //#region src/layer/Tooltip.js
8
+ // src/layer/Tooltip.js
9
9
  const directions = [
10
10
  "top",
11
11
  "bottom",
@@ -112,8 +112,9 @@ const layerTooltipMethods = {
112
112
  * @returns {this}
113
113
  */
114
114
  bindTooltip(content, options) {
115
- if (this._tooltip && this.isTooltipOpen()) this.unbindTooltip();
116
- this._tooltip = this._initOverlay(Tooltip, this._tooltip, content, options);
115
+ const old = this.isTooltipOpen() ? null : this._tooltip;
116
+ if (this._tooltip) this.unbindTooltip();
117
+ this._tooltip = this._initOverlay(Tooltip, old, content, options);
117
118
  this._initTooltipInteractions();
118
119
  if (this._tooltip.options.permanent && this._map && this._map.hasLayer(this)) this.openTooltip();
119
120
  return this;
@@ -132,21 +133,20 @@ const layerTooltipMethods = {
132
133
  return this;
133
134
  },
134
135
  _initTooltipInteractions(remove) {
135
- if (!remove && this._tooltipHandlersAdded) return;
136
- const onOff = remove ? "off" : "on", events = {
136
+ const { permanent, sticky } = this._tooltip.options, events = {
137
137
  remove: this.closeTooltip,
138
138
  move: this._moveTooltip
139
139
  };
140
- if (!this._tooltip.options.permanent) {
140
+ if (permanent) events.add = this._openTooltip;
141
+ else {
141
142
  events.pointerover = this._openTooltip;
142
143
  events.pointerout = this.closeTooltip;
143
144
  events.click = this._openTooltip;
144
- if (this._map) this._addFocusListeners(remove);
145
- else events.add = () => this._addFocusListeners(remove);
146
- } else events.add = this._openTooltip;
147
- if (this._tooltip.options.sticky) events.pointermove = this._moveTooltip;
148
- this[onOff](events);
149
- this._tooltipHandlersAdded = !remove;
145
+ events.add = this._toggleFocusListeners;
146
+ if (this._map) this._toggleFocusListeners(!remove);
147
+ }
148
+ if (sticky) events.pointermove = this._moveTooltip;
149
+ this[remove ? "off" : "on"](events);
150
150
  },
151
151
  /**
152
152
  * Opens the bound tooltip at the specified `latlng` or at the default tooltip
@@ -167,13 +167,13 @@ const layerTooltipMethods = {
167
167
  return this;
168
168
  },
169
169
  /**
170
- * Closes the tooltip bound to this layer if it is open. Returns the bound tooltip
171
- * (not the layer), or `undefined` without one.
170
+ * Closes the tooltip bound to this layer if it is open.
172
171
  * @group Tooltip methods
173
- * @returns {Tooltip|undefined}
172
+ * @returns {this}
174
173
  */
175
174
  closeTooltip() {
176
- if (this._tooltip) return this._tooltip.close();
175
+ this._tooltip?.close();
176
+ return this;
177
177
  },
178
178
  /**
179
179
  * Opens or closes the tooltip bound to this layer depending on its current state.
@@ -190,7 +190,7 @@ const layerTooltipMethods = {
190
190
  * @returns {boolean}
191
191
  */
192
192
  isTooltipOpen() {
193
- return this._tooltip.isOpen();
193
+ return this._tooltip?.isOpen() ?? false;
194
194
  },
195
195
  /**
196
196
  * Sets the content of the tooltip bound to this layer. String content is rendered
@@ -212,9 +212,9 @@ const layerTooltipMethods = {
212
212
  getTooltip() {
213
213
  return this._tooltip;
214
214
  },
215
- _addFocusListeners(remove) {
216
- if (this.getElement) this._addFocusListenersOnLayer(this, remove);
217
- else if (this.eachLayer) this.eachLayer((layer) => this._addFocusListenersOnLayer(layer, remove), this);
215
+ _toggleFocusListeners(add) {
216
+ if (this.getElement) this._addFocusListenersOnLayer(this, !add);
217
+ else if (this.eachLayer) this.eachLayer((layer) => this._addFocusListenersOnLayer(layer, !add), this);
218
218
  },
219
219
  _addFocusListenersOnLayer(layer, remove) {
220
220
  const el = typeof layer.getElement === "function" && layer.getElement();
@@ -308,16 +308,14 @@ const layerTooltipMethods = {
308
308
  * should adapt this value if you use a custom icon.
309
309
  */
310
310
  var Tooltip = class Tooltip extends DivOverlay {
311
- static {
312
- this.setDefaultOptions({
313
- pane: "tooltipPane",
314
- offset: [0, 0],
315
- direction: "auto",
316
- permanent: false,
317
- sticky: false,
318
- opacity: .9
319
- });
320
- }
311
+ static defaultOptions = {
312
+ pane: "tooltipPane",
313
+ offset: [0, 0],
314
+ direction: "auto",
315
+ permanent: false,
316
+ sticky: false,
317
+ opacity: .9
318
+ };
321
319
  /**
322
320
  * Instantiates a `Tooltip` object given an optional `options` object that describes
323
321
  * its appearance and location and an optional `source` object that is used to tag
@@ -375,7 +373,7 @@ var Tooltip = class Tooltip extends DivOverlay {
375
373
  return events;
376
374
  }
377
375
  _initLayout() {
378
- const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-${this._zoomAnimated ? "animated" : "hide"}`;
376
+ const className = `maplair-tooltip ${this.options.className || ""} maplair-zoom-animated`;
379
377
  this._contentNode = this._container = create("div", className);
380
378
  this._container.setAttribute("role", "tooltip");
381
379
  this._container.setAttribute("id", `maplair-tooltip-${stamp(this)}`);
@@ -449,7 +447,7 @@ var Tooltip = class Tooltip extends DivOverlay {
449
447
  };
450
448
  }
451
449
  _updatePosition() {
452
- const pos = this._map.latLngToLayerPoint(this._latlng);
450
+ const pos = this._map.latLngToLayerPoint(this._latlng)._round();
453
451
  this._setPosition(pos);
454
452
  }
455
453
  /**
@@ -459,7 +457,7 @@ var Tooltip = class Tooltip extends DivOverlay {
459
457
  */
460
458
  setOpacity(opacity) {
461
459
  this.options.opacity = opacity;
462
- if (this._container) this._container.style.opacity = opacity;
460
+ if (this._container) this._container.style.opacity = `${opacity}`;
463
461
  }
464
462
  _animateZoom(e) {
465
463
  const pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
@@ -478,7 +476,6 @@ var Tooltip = class Tooltip extends DivOverlay {
478
476
  Layer.include(layerTooltipMethods);
479
477
  }
480
478
  };
481
- //#endregion
482
479
  export { Tooltip };
483
480
 
484
481
  //# sourceMappingURL=Tooltip.js.map