maplair 4.1.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 (211) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/esm/Maplair.js +5 -4
  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 +1 -2
  6. package/dist/esm/control/ButtonControl.js +1 -2
  7. package/dist/esm/control/ContextMenu.js +1 -2
  8. package/dist/esm/control/Control.js +1 -2
  9. package/dist/esm/control/FullscreenControl.js +1 -2
  10. package/dist/esm/control/LayersControl.js +27 -31
  11. package/dist/esm/control/LayersControl.js.map +1 -1
  12. package/dist/esm/control/LegendControl.js +1 -2
  13. package/dist/esm/control/MiniMapControl.js +1 -2
  14. package/dist/esm/control/RotateControl.js +1 -2
  15. package/dist/esm/control/ScaleControl.js +1 -2
  16. package/dist/esm/control/SearchControl.js +1 -2
  17. package/dist/esm/control/SideBySideControl.js +1 -2
  18. package/dist/esm/control/TextControl.js +1 -2
  19. package/dist/esm/control/TimeControl.js +1 -2
  20. package/dist/esm/control/ZoomControl.js +18 -29
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Class.js +2 -9
  23. package/dist/esm/core/Class.js.map +1 -1
  24. package/dist/esm/core/Events.js +1 -2
  25. package/dist/esm/core/Handler.js +10 -3
  26. package/dist/esm/core/Handler.js.map +1 -1
  27. package/dist/esm/core/I18n.js +1 -2
  28. package/dist/esm/core/Util.js +2 -3
  29. package/dist/esm/core/Util.js.map +1 -1
  30. package/dist/esm/dom/DomEvent.DoubleTap.js +1 -2
  31. package/dist/esm/dom/DomEvent.PointerEvents.js +1 -2
  32. package/dist/esm/dom/DomEvent.js +10 -18
  33. package/dist/esm/dom/DomEvent.js.map +1 -1
  34. package/dist/esm/dom/DomUtil.js +1 -2
  35. package/dist/esm/dom/Draggable.js +4 -3
  36. package/dist/esm/dom/Draggable.js.map +1 -1
  37. package/dist/esm/dom/PosAnimation.js +1 -2
  38. package/dist/esm/geo/LatLng.js +1 -2
  39. package/dist/esm/geo/LatLngBounds.js +9 -15
  40. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  41. package/dist/esm/geo/crs/CRS.js +1 -2
  42. package/dist/esm/geo/crs/EPSG3395.js +4 -5
  43. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  44. package/dist/esm/geo/crs/EPSG3857.js +4 -5
  45. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  46. package/dist/esm/geo/crs/EPSG4326.js +3 -4
  47. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  48. package/dist/esm/geo/crs/EarthCRS.js +1 -2
  49. package/dist/esm/geo/crs/SimpleCRS.js +3 -4
  50. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  51. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +4 -5
  52. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  53. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +3 -4
  54. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  55. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +4 -5
  56. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  57. package/dist/esm/geometry/Bounds.js +10 -14
  58. package/dist/esm/geometry/Bounds.js.map +1 -1
  59. package/dist/esm/geometry/LineUtil.js +2 -3
  60. package/dist/esm/geometry/LineUtil.js.map +1 -1
  61. package/dist/esm/geometry/Point.js +1 -2
  62. package/dist/esm/geometry/PolyUtil.js +17 -25
  63. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  64. package/dist/esm/geometry/Transformation.js +1 -2
  65. package/dist/esm/layer/BlanketOverlay.js +1 -2
  66. package/dist/esm/layer/Classification.js +1 -2
  67. package/dist/esm/layer/DivOverlay.js +2 -3
  68. package/dist/esm/layer/DivOverlay.js.map +1 -1
  69. package/dist/esm/layer/FeatureGroup.js +5 -4
  70. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  71. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  72. package/dist/esm/layer/GeoJSON.js +8 -10
  73. package/dist/esm/layer/GeoJSON.js.map +1 -1
  74. package/dist/esm/layer/GeoJSONUtil.js +1 -2
  75. package/dist/esm/layer/HeatLayer.js +2 -3
  76. package/dist/esm/layer/HeatLayer.js.map +1 -1
  77. package/dist/esm/layer/ImageOverlay.js +2 -3
  78. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  79. package/dist/esm/layer/Layer.js +1 -2
  80. package/dist/esm/layer/LayerGroup.js +2 -3
  81. package/dist/esm/layer/LayerGroup.js.map +1 -1
  82. package/dist/esm/layer/Popup.js +9 -16
  83. package/dist/esm/layer/Popup.js.map +1 -1
  84. package/dist/esm/layer/SVGOverlay.js +1 -2
  85. package/dist/esm/layer/Tooltip.js +16 -17
  86. package/dist/esm/layer/Tooltip.js.map +1 -1
  87. package/dist/esm/layer/VideoOverlay.js +1 -2
  88. package/dist/esm/layer/marker/DefaultIcon.js +29 -7
  89. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  90. package/dist/esm/layer/marker/DivIcon.js +1 -2
  91. package/dist/esm/layer/marker/Icon.js +2 -2
  92. package/dist/esm/layer/marker/Icon.js.map +1 -1
  93. package/dist/esm/layer/marker/Marker.Drag.js +43 -4
  94. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  95. package/dist/esm/layer/marker/Marker.Move.js +4 -6
  96. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  97. package/dist/esm/layer/marker/Marker.js +54 -14
  98. package/dist/esm/layer/marker/Marker.js.map +1 -1
  99. package/dist/esm/layer/marker/MarkerClusterGroup.js +1 -2
  100. package/dist/esm/layer/marker/SvgIcon.js +1 -2
  101. package/dist/esm/layer/tile/GridLayer.js +4 -4
  102. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  103. package/dist/esm/layer/tile/TileLayer.js +8 -8
  104. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  105. package/dist/esm/layer/tile/WMSTileLayer.js +5 -4
  106. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  107. package/dist/esm/layer/vector/Canvas.js +7 -14
  108. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  109. package/dist/esm/layer/vector/Circle.js +4 -3
  110. package/dist/esm/layer/vector/Circle.js.map +1 -1
  111. package/dist/esm/layer/vector/CircleMarker.js +2 -3
  112. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  113. package/dist/esm/layer/vector/Path.DashAnimation.js +1 -2
  114. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  115. package/dist/esm/layer/vector/Path.js +1 -2
  116. package/dist/esm/layer/vector/Polygon.js +2 -3
  117. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  118. package/dist/esm/layer/vector/Polyline.Decorations.js +1 -2
  119. package/dist/esm/layer/vector/Polyline.js +2 -3
  120. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  121. package/dist/esm/layer/vector/Rectangle.js +1 -2
  122. package/dist/esm/layer/vector/Renderer.getRenderer.js +4 -5
  123. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  124. package/dist/esm/layer/vector/Renderer.js +1 -2
  125. package/dist/esm/layer/vector/SVG.js +7 -4
  126. package/dist/esm/layer/vector/SVG.js.map +1 -1
  127. package/dist/esm/map/Hash.js +1 -2
  128. package/dist/esm/map/Map.Rotation.js +31 -16
  129. package/dist/esm/map/Map.Rotation.js.map +1 -1
  130. package/dist/esm/map/Map.js +10 -17
  131. package/dist/esm/map/Map.js.map +1 -1
  132. package/dist/esm/map/MapSync.js +1 -2
  133. package/dist/esm/map/handler/BoxZoomHandler.js +20 -40
  134. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  135. package/dist/esm/map/handler/DisplaceHandler.js +1 -2
  136. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  137. package/dist/esm/map/handler/DragHandler.js +1 -2
  138. package/dist/esm/map/handler/KeyboardHandler.js +23 -43
  139. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  140. package/dist/esm/map/handler/PinchZoomHandler.js +1 -2
  141. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -2
  142. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  143. package/dist/esm/map/handler/TapHoldHandler.js +1 -2
  144. package/dist/esm/package.js +2 -3
  145. package/dist/maplair-global-src.js +487 -613
  146. package/dist/maplair-global-src.js.map +1 -1
  147. package/dist/maplair-global.js +2 -2
  148. package/dist/maplair-global.js.map +1 -1
  149. package/dist/maplair-src.js +483 -609
  150. package/dist/maplair-src.js.map +1 -1
  151. package/dist/maplair.css +1 -1263
  152. package/dist/maplair.js +2 -2
  153. package/dist/maplair.js.map +1 -1
  154. package/package.json +3 -8
  155. package/src/Maplair.all.js +0 -1
  156. package/src/control/LayersControl.js +39 -52
  157. package/src/control/ZoomControl.js +17 -31
  158. package/src/core/Class.js +5 -14
  159. package/src/core/Handler.js +11 -1
  160. package/src/core/Util.js +1 -1
  161. package/src/dom/DomEvent.js +9 -19
  162. package/src/dom/Draggable.js +5 -1
  163. package/src/geo/LatLngBounds.js +8 -15
  164. package/src/geo/crs/EPSG3395.js +3 -3
  165. package/src/geo/crs/EPSG3857.js +3 -3
  166. package/src/geo/crs/EPSG4326.js +2 -2
  167. package/src/geo/crs/SimpleCRS.js +2 -2
  168. package/src/geo/index.js +1 -2
  169. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +1 -1
  170. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +1 -1
  171. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +1 -1
  172. package/src/geo/projection/index.js +5 -5
  173. package/src/geometry/Bounds.js +12 -17
  174. package/src/geometry/LineUtil.js +1 -1
  175. package/src/geometry/PolyUtil.js +23 -31
  176. package/src/layer/DivOverlay.js +1 -1
  177. package/src/layer/FeatureGroup.js +8 -2
  178. package/src/layer/GeoJSON.js +10 -13
  179. package/src/layer/HeatLayer.js +1 -1
  180. package/src/layer/ImageOverlay.js +2 -2
  181. package/src/layer/LayerGroup.js +1 -1
  182. package/src/layer/Popup.js +9 -19
  183. package/src/layer/Tooltip.js +19 -17
  184. package/src/layer/marker/DefaultIcon.js +33 -5
  185. package/src/layer/marker/Icon.js +2 -0
  186. package/src/layer/marker/Marker.Drag.js +53 -5
  187. package/src/layer/marker/Marker.Move.js +3 -4
  188. package/src/layer/marker/Marker.js +64 -13
  189. package/src/layer/tile/GridLayer.js +5 -2
  190. package/src/layer/tile/TileLayer.js +9 -6
  191. package/src/layer/tile/WMSTileLayer.js +5 -2
  192. package/src/layer/vector/Canvas.js +10 -14
  193. package/src/layer/vector/Circle.js +4 -1
  194. package/src/layer/vector/CircleMarker.js +2 -1
  195. package/src/layer/vector/Polygon.js +1 -1
  196. package/src/layer/vector/Polyline.js +1 -1
  197. package/src/layer/vector/Renderer.getRenderer.js +4 -3
  198. package/src/layer/vector/SVG.js +12 -2
  199. package/src/map/Map.Rotation.js +28 -4
  200. package/src/map/Map.js +17 -21
  201. package/src/map/handler/BoxZoomHandler.js +21 -42
  202. package/src/map/handler/KeyboardHandler.js +34 -53
  203. package/src/maplair.css +5 -0
  204. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  205. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  206. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  207. package/dist/esm/geo/projection/index.js +0 -14
  208. package/dist/esm/geo/projection/index.js.map +0 -1
  209. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  210. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  211. package/src/layer/marker/Marker.Rotation.js +0 -103
@@ -1,6 +1,6 @@
1
1
  import { setOptions } from "../core/Util.js";
2
2
  import { BlanketOverlay } from "./BlanketOverlay.js";
3
- //#region src/layer/HeatLayer.js
3
+ // src/layer/HeatLayer.js
4
4
  /** @import {BlanketOverlayOptions} from './BlanketOverlay.js' */
5
5
  /** @import {LatLngExpression} from '../geo/LatLng.js' */
6
6
  /**
@@ -156,7 +156,7 @@ var HeatLayer = class HeatLayer extends BlanketOverlay {
156
156
  if (!map || !this._bounds) return;
157
157
  const ctx = this._ctx, { width, height } = this._container, offset = this._bounds.min, { radius, blur, max, minOpacity } = this.options, r = radius + blur, maxZoom = this.options.maxZoom ?? map.getMaxZoom(), zoomFactor = 1 / 2 ** Math.max(0, Math.min(maxZoom - map.getZoom(), 12)), cellSize = radius / 2, grid = /* @__PURE__ */ new Map();
158
158
  for (const latlng of this._latlngs) {
159
- const point = map.latLngToLayerPoint(latlng).subtract(offset);
159
+ const point = map.latLngToLayerPoint(latlng)._round()._subtract(offset);
160
160
  if (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) continue;
161
161
  const intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor, key = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`, cell = grid.get(key);
162
162
  if (cell) {
@@ -190,7 +190,6 @@ var HeatLayer = class HeatLayer extends BlanketOverlay {
190
190
  ctx.putImageData(image, 0, 0);
191
191
  }
192
192
  };
193
- //#endregion
194
193
  export { HeatLayer };
195
194
 
196
195
  //# sourceMappingURL=HeatLayer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HeatLayer.js","names":[],"sources":["../../../src/layer/HeatLayer.js"],"sourcesContent":["import {BlanketOverlay} from './BlanketOverlay.js';\nimport * as Util from '../core/Util.js';\n/** @import {BlanketOverlayOptions} from './BlanketOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n\n/**\n * Options of `HeatLayer`.\n * @typedef {object} HeatLayerOptions\n * @property {number} [radius=25] The radius of each point in pixels.\n * @property {number} [blur=15] The amount of blur in pixels.\n * @property {number} [max=1] The intensity with the strongest color.\n * @property {number} [maxZoom] The zoom level where the points reach the full\n * intensity; below it, the intensity is halved per zoom level. By default the\n * maximum zoom of the map.\n * @property {number} [minOpacity=0.05] The minimum opacity of the heat.\n * @property {Record<number, string>} [gradient={0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'}]\n * The colors for the intensities from `0` to `1`, any CSS colors.\n * @property {string} [pane='overlayPane'] The map pane of the layer.\n * @extends BlanketOverlayOptions\n */\n\n/**\n * A heatmap of points, each with an optional intensity, drawn on a canvas: the\n * points are drawn as blurred circles adding up, and colored by a gradient.\n * Nearby points are merged into a grid for speed, so that tens of thousands of\n * points stay fast.\n *\n * Inspired by the [Leaflet.heat](https://github.com/Leaflet/Leaflet.heat) plugin\n * and its [simpleheat](https://github.com/mourner/simpleheat) algorithm.\n *\n * @example\n * ```js\n * new HeatLayer([\n * \t[47.27, 11.40, 0.5], // latitude, longitude, intensity\n * \t[47.28, 11.41],\n * \tnew LatLng(47.26, 11.39)\n * ], {radius: 20}).addTo(map);\n * ```\n */\nexport class HeatLayer extends BlanketOverlay {\n\n\tstatic defaultOptions = {\n\t\tradius: 25,\n\t\tblur: 15,\n\t\tmax: 1,\n\t\tmaxZoom: undefined,\n\t\tminOpacity: 0.05,\n\t\tgradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},\n\t\tpane: 'overlayPane'\n\t};\n\n\t/**\n\t * Creates a heatmap of the given points: `LatLng`s or arrays\n\t * `[lat, lng, intensity]` (the intensity defaults to `1`).\n\t * @param {LatLngExpression[]} [latlngs]\n\t * @param {HeatLayerOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper(options);\n\t\tthis._latlngs = latlngs ?? [];\n\t\tthis.callInitHooks(HeatLayer);\n\t}\n\n\t/**\n\t * Replaces the points of the heatmap.\n\t * @param {LatLngExpression[]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._latlngs = latlngs;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Adds a point to the heatmap.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\taddLatLng(latlng) {\n\t\tthis._latlngs.push(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the points of the heatmap.\n\t * @returns {LatLngExpression[]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Changes the options, e.g. the `radius` or the `gradient`.\n\t * @param {HeatLayerOptions} options\n\t * @returns {this}\n\t */\n\tsetOptions(options) {\n\t\tUtil.setOptions(this, options);\n\t\tthis._circle = this._gradient = null;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Redraws the heatmap.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map && this._bounds) {\n\t\t\tcancelAnimationFrame(this._frame);\n\t\t\tthis._frame = requestAnimationFrame(() => this._draw());\n\t\t}\n\t\treturn this;\n\t}\n\n\t_initContainer() {\n\t\tthis._container = document.createElement('canvas');\n\t\tthis._container.classList.add('maplair-heatmap-layer');\n\t\tthis._ctx = this._container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._frame);\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tthis._container.width = size.x;\n\t\tthis._container.height = size.y;\n\t\treturn size;\n\t}\n\n\t_onSettled() {\n\t\tthis._draw();\n\t}\n\n\t// A blurred circle, drawn for each point\n\t_getCircle() {\n\t\tif (this._circle) { return this._circle; }\n\t\tconst {radius, blur} = this.options,\n\t\tr = radius + blur,\n\t\tcircle = this._circle = document.createElement('canvas'),\n\t\tctx = circle.getContext('2d');\n\t\tcircle.width = circle.height = r * 2;\n\t\t// the shadow of a circle drawn outside of the canvas\n\t\tctx.shadowOffsetX = ctx.shadowOffsetY = r * 2;\n\t\tctx.shadowBlur = blur;\n\t\tctx.shadowColor = 'black';\n\t\tctx.beginPath();\n\t\tctx.arc(-r, -r, radius, 0, Math.PI * 2, true);\n\t\tctx.closePath();\n\t\tctx.fill();\n\t\treturn circle;\n\t}\n\n\t// The colors of the alpha values 0–255 as RGBA values\n\t_getGradient() {\n\t\tif (this._gradient) { return this._gradient; }\n\t\tconst canvas = document.createElement('canvas'),\n\t\tctx = canvas.getContext('2d'),\n\t\tgradient = ctx.createLinearGradient(0, 0, 0, 256);\n\t\tcanvas.width = 1;\n\t\tcanvas.height = 256;\n\t\tfor (const [stop, color] of Object.entries(this.options.gradient)) {\n\t\t\tgradient.addColorStop(Number(stop), color);\n\t\t}\n\t\tctx.fillStyle = gradient;\n\t\tctx.fillRect(0, 0, 1, 256);\n\t\tthis._gradient = ctx.getImageData(0, 0, 1, 256).data;\n\t\treturn this._gradient;\n\t}\n\n\t_draw() {\n\t\tconst map = this._map;\n\t\tif (!map || !this._bounds) { return; }\n\n\t\tconst ctx = this._ctx,\n\t\t{width, height} = this._container,\n\t\toffset = this._bounds.min,\n\t\t{radius, blur, max, minOpacity} = this.options,\n\t\tr = radius + blur,\n\t\tmaxZoom = this.options.maxZoom ?? map.getMaxZoom(),\n\t\t// halve the intensity per zoom level below maxZoom (at most 12)\n\t\tzoomFactor = 1 / 2 ** Math.max(0, Math.min(maxZoom - map.getZoom(), 12)),\n\t\tcellSize = radius / 2,\n\t\tgrid = new Map();\n\n\t\t// merge the points per grid cell, weighted by their intensity\n\t\tfor (const latlng of this._latlngs) {\n\t\t\tconst point = map.latLngToLayerPoint(latlng).subtract(offset);\n\t\t\tif (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }\n\t\t\tconst intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,\n\t\t\tkey = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,\n\t\t\tcell = grid.get(key);\n\t\t\tif (cell) {\n\t\t\t\tconst sum = cell.intensity + intensity;\n\t\t\t\tcell.x = (cell.x * cell.intensity + point.x * intensity) / sum;\n\t\t\t\tcell.y = (cell.y * cell.intensity + point.y * intensity) / sum;\n\t\t\t\tcell.intensity = sum;\n\t\t\t} else {\n\t\t\t\tgrid.set(key, {x: point.x, y: point.y, intensity});\n\t\t\t}\n\t\t}\n\n\t\tctx.clearRect(0, 0, width, height);\n\t\tconst circle = this._getCircle();\n\t\tfor (const {x, y, intensity} of grid.values()) {\n\t\t\tctx.globalAlpha = Math.min(Math.max(intensity / max, minOpacity), 1);\n\t\t\tctx.drawImage(circle, x - r, y - r);\n\t\t}\n\t\tctx.globalAlpha = 1;\n\n\t\t// colorize by the alpha values\n\t\tif (!grid.size) { return; }\n\t\tconst image = ctx.getImageData(0, 0, width, height),\n\t\tpixels = image.data,\n\t\tgradient = this._getGradient();\n\t\tfor (let i = 3; i < pixels.length; i += 4) {\n\t\t\tconst j = pixels[i] * 4;\n\t\t\tif (j) {\n\t\t\t\tpixels[i - 3] = gradient[j];\n\t\t\t\tpixels[i - 2] = gradient[j + 1];\n\t\t\t\tpixels[i - 1] = gradient[j + 2];\n\t\t\t}\n\t\t}\n\t\tctx.putImageData(image, 0, 0);\n\t}\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,YAAb,MAAa,kBAAkB,eAAe;CAE7C,OAAO,iBAAiB;EACvB,QAAQ;EACR,MAAM;EACN,KAAK;EACL,SAAS,KAAA;EACT,YAAY;EACZ,UAAU;GAAC,IAAK;GAAQ,IAAK;GAAQ,IAAK;GAAQ,IAAK;GAAU,GAAG;EAAK;EACzE,MAAM;CACP;;;;;;;CAQA,YAAY,SAAS,SAAS;EAC7B,MAAM,OAAO;EACb,KAAK,WAAW,WAAW,CAAC;EAC5B,KAAK,cAAc,SAAS;CAC7B;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,WAAW;EAChB,OAAO,KAAK,OAAO;CACpB;;;;;;CAOA,UAAU,QAAQ;EACjB,KAAK,SAAS,KAAK,MAAM;EAC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KAAK,YAAY,MAAM,IAAI,aAAa;IAC3D,KAAK,KAAK,KAAK,IAAI,KAAK,YAAY,MAAM,IAAI,aAAa;IAC3D,KAAK,YAAY;GAClB,OACC,KAAK,IAAI,KAAK;IAAC,GAAG,MAAM;IAAG,GAAG,MAAM;IAAG;GAAS,CAAC;EAEnD;EAEA,IAAI,UAAU,GAAG,GAAG,OAAO,MAAM;EACjC,MAAM,SAAS,KAAK,WAAW;EAC/B,KAAK,MAAM,EAAC,GAAG,GAAG,eAAc,KAAK,OAAO,GAAG;GAC9C,IAAI,cAAc,KAAK,IAAI,KAAK,IAAI,YAAY,KAAK,UAAU,GAAG,CAAC;GACnE,IAAI,UAAU,QAAQ,IAAI,GAAG,IAAI,CAAC;EACnC;EACA,IAAI,cAAc;EAGlB,IAAI,CAAC,KAAK,MAAQ;EAClB,MAAM,QAAQ,IAAI,aAAa,GAAG,GAAG,OAAO,MAAM,GAClD,SAAS,MAAM,MACf,WAAW,KAAK,aAAa;EAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;GAC1C,MAAM,IAAI,OAAO,KAAK;GACtB,IAAI,GAAG;IACN,OAAO,IAAI,KAAK,SAAS;IACzB,OAAO,IAAI,KAAK,SAAS,IAAI;IAC7B,OAAO,IAAI,KAAK,SAAS,IAAI;GAC9B;EACD;EACA,IAAI,aAAa,OAAO,GAAG,CAAC;CAC7B;AACD"}
1
+ {"version":3,"file":"HeatLayer.js","names":[],"sources":["../../../src/layer/HeatLayer.js"],"sourcesContent":["import {BlanketOverlay} from './BlanketOverlay.js';\nimport * as Util from '../core/Util.js';\n/** @import {BlanketOverlayOptions} from './BlanketOverlay.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n\n/**\n * Options of `HeatLayer`.\n * @typedef {object} HeatLayerOptions\n * @property {number} [radius=25] The radius of each point in pixels.\n * @property {number} [blur=15] The amount of blur in pixels.\n * @property {number} [max=1] The intensity with the strongest color.\n * @property {number} [maxZoom] The zoom level where the points reach the full\n * intensity; below it, the intensity is halved per zoom level. By default the\n * maximum zoom of the map.\n * @property {number} [minOpacity=0.05] The minimum opacity of the heat.\n * @property {Record<number, string>} [gradient={0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'}]\n * The colors for the intensities from `0` to `1`, any CSS colors.\n * @property {string} [pane='overlayPane'] The map pane of the layer.\n * @extends BlanketOverlayOptions\n */\n\n/**\n * A heatmap of points, each with an optional intensity, drawn on a canvas: the\n * points are drawn as blurred circles adding up, and colored by a gradient.\n * Nearby points are merged into a grid for speed, so that tens of thousands of\n * points stay fast.\n *\n * Inspired by the [Leaflet.heat](https://github.com/Leaflet/Leaflet.heat) plugin\n * and its [simpleheat](https://github.com/mourner/simpleheat) algorithm.\n *\n * @example\n * ```js\n * new HeatLayer([\n * \t[47.27, 11.40, 0.5], // latitude, longitude, intensity\n * \t[47.28, 11.41],\n * \tnew LatLng(47.26, 11.39)\n * ], {radius: 20}).addTo(map);\n * ```\n */\nexport class HeatLayer extends BlanketOverlay {\n\n\tstatic defaultOptions = {\n\t\tradius: 25,\n\t\tblur: 15,\n\t\tmax: 1,\n\t\tmaxZoom: undefined,\n\t\tminOpacity: 0.05,\n\t\tgradient: {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1: 'red'},\n\t\tpane: 'overlayPane'\n\t};\n\n\t/**\n\t * Creates a heatmap of the given points: `LatLng`s or arrays\n\t * `[lat, lng, intensity]` (the intensity defaults to `1`).\n\t * @param {LatLngExpression[]} [latlngs]\n\t * @param {HeatLayerOptions} [options]\n\t */\n\tconstructor(latlngs, options) {\n\t\tsuper(options);\n\t\tthis._latlngs = latlngs ?? [];\n\t\tthis.callInitHooks(HeatLayer);\n\t}\n\n\t/**\n\t * Replaces the points of the heatmap.\n\t * @param {LatLngExpression[]} latlngs\n\t * @returns {this}\n\t */\n\tsetLatLngs(latlngs) {\n\t\tthis._latlngs = latlngs;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Adds a point to the heatmap.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\taddLatLng(latlng) {\n\t\tthis._latlngs.push(latlng);\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Returns the points of the heatmap.\n\t * @returns {LatLngExpression[]}\n\t */\n\tgetLatLngs() {\n\t\treturn this._latlngs;\n\t}\n\n\t/**\n\t * Changes the options, e.g. the `radius` or the `gradient`.\n\t * @param {HeatLayerOptions} options\n\t * @returns {this}\n\t */\n\tsetOptions(options) {\n\t\tUtil.setOptions(this, options);\n\t\tthis._circle = this._gradient = null;\n\t\treturn this.redraw();\n\t}\n\n\t/**\n\t * Redraws the heatmap.\n\t * @returns {this}\n\t */\n\tredraw() {\n\t\tif (this._map && this._bounds) {\n\t\t\tcancelAnimationFrame(this._frame);\n\t\t\tthis._frame = requestAnimationFrame(() => this._draw());\n\t\t}\n\t\treturn this;\n\t}\n\n\t_initContainer() {\n\t\tthis._container = document.createElement('canvas');\n\t\tthis._container.classList.add('maplair-heatmap-layer');\n\t\tthis._ctx = this._container.getContext('2d');\n\t}\n\n\t_destroyContainer() {\n\t\tcancelAnimationFrame(this._frame);\n\t\tsuper._destroyContainer();\n\t}\n\n\t_resizeContainer() {\n\t\tconst size = super._resizeContainer();\n\t\tthis._container.width = size.x;\n\t\tthis._container.height = size.y;\n\t\treturn size;\n\t}\n\n\t_onSettled() {\n\t\tthis._draw();\n\t}\n\n\t// A blurred circle, drawn for each point\n\t_getCircle() {\n\t\tif (this._circle) { return this._circle; }\n\t\tconst {radius, blur} = this.options,\n\t\tr = radius + blur,\n\t\tcircle = this._circle = document.createElement('canvas'),\n\t\tctx = circle.getContext('2d');\n\t\tcircle.width = circle.height = r * 2;\n\t\t// the shadow of a circle drawn outside of the canvas\n\t\tctx.shadowOffsetX = ctx.shadowOffsetY = r * 2;\n\t\tctx.shadowBlur = blur;\n\t\tctx.shadowColor = 'black';\n\t\tctx.beginPath();\n\t\tctx.arc(-r, -r, radius, 0, Math.PI * 2, true);\n\t\tctx.closePath();\n\t\tctx.fill();\n\t\treturn circle;\n\t}\n\n\t// The colors of the alpha values 0–255 as RGBA values\n\t_getGradient() {\n\t\tif (this._gradient) { return this._gradient; }\n\t\tconst canvas = document.createElement('canvas'),\n\t\tctx = canvas.getContext('2d'),\n\t\tgradient = ctx.createLinearGradient(0, 0, 0, 256);\n\t\tcanvas.width = 1;\n\t\tcanvas.height = 256;\n\t\tfor (const [stop, color] of Object.entries(this.options.gradient)) {\n\t\t\tgradient.addColorStop(Number(stop), color);\n\t\t}\n\t\tctx.fillStyle = gradient;\n\t\tctx.fillRect(0, 0, 1, 256);\n\t\tthis._gradient = ctx.getImageData(0, 0, 1, 256).data;\n\t\treturn this._gradient;\n\t}\n\n\t_draw() {\n\t\tconst map = this._map;\n\t\tif (!map || !this._bounds) { return; }\n\n\t\tconst ctx = this._ctx,\n\t\t{width, height} = this._container,\n\t\toffset = this._bounds.min,\n\t\t{radius, blur, max, minOpacity} = this.options,\n\t\tr = radius + blur,\n\t\tmaxZoom = this.options.maxZoom ?? map.getMaxZoom(),\n\t\t// halve the intensity per zoom level below maxZoom (at most 12)\n\t\tzoomFactor = 1 / 2 ** Math.max(0, Math.min(maxZoom - map.getZoom(), 12)),\n\t\tcellSize = radius / 2,\n\t\tgrid = new Map();\n\n\t\t// merge the points per grid cell, weighted by their intensity\n\t\tfor (const latlng of this._latlngs) {\n\t\t\tconst point = map.latLngToLayerPoint(latlng)._round()._subtract(offset);\n\t\t\tif (point.x < -r || point.y < -r || point.x > width + r || point.y > height + r) { continue; }\n\t\t\tconst intensity = (latlng.alt ?? latlng[2] ?? 1) * zoomFactor,\n\t\t\tkey = `${Math.floor(point.x / cellSize)}:${Math.floor(point.y / cellSize)}`,\n\t\t\tcell = grid.get(key);\n\t\t\tif (cell) {\n\t\t\t\tconst sum = cell.intensity + intensity;\n\t\t\t\tcell.x = (cell.x * cell.intensity + point.x * intensity) / sum;\n\t\t\t\tcell.y = (cell.y * cell.intensity + point.y * intensity) / sum;\n\t\t\t\tcell.intensity = sum;\n\t\t\t} else {\n\t\t\t\tgrid.set(key, {x: point.x, y: point.y, intensity});\n\t\t\t}\n\t\t}\n\n\t\tctx.clearRect(0, 0, width, height);\n\t\tconst circle = this._getCircle();\n\t\tfor (const {x, y, intensity} of grid.values()) {\n\t\t\tctx.globalAlpha = Math.min(Math.max(intensity / max, minOpacity), 1);\n\t\t\tctx.drawImage(circle, x - r, y - r);\n\t\t}\n\t\tctx.globalAlpha = 1;\n\n\t\t// colorize by the alpha values\n\t\tif (!grid.size) { return; }\n\t\tconst image = ctx.getImageData(0, 0, width, height),\n\t\tpixels = image.data,\n\t\tgradient = this._getGradient();\n\t\tfor (let i = 3; i < pixels.length; i += 4) {\n\t\t\tconst j = pixels[i] * 4;\n\t\t\tif (j) {\n\t\t\t\tpixels[i - 3] = gradient[j];\n\t\t\t\tpixels[i - 2] = gradient[j + 1];\n\t\t\t\tpixels[i - 1] = gradient[j + 2];\n\t\t\t}\n\t\t}\n\t\tctx.putImageData(image, 0, 0);\n\t}\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,YAAb,MAAa,kBAAkB,eAAe;CAE7C,OAAO,iBAAiB;EACvB,QAAQ;EACR,MAAM;EACN,KAAK;EACL,SAAS,KAAA;EACT,YAAY;EACZ,UAAU;GAAC,IAAK;GAAQ,IAAK;GAAQ,IAAK;GAAQ,IAAK;GAAU,GAAG;EAAK;EACzE,MAAM;CACP;;;;;;;CAQA,YAAY,SAAS,SAAS;EAC7B,MAAM,OAAO;EACb,KAAK,WAAW,WAAW,CAAC;EAC5B,KAAK,cAAc,SAAS;CAC7B;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,WAAW;EAChB,OAAO,KAAK,OAAO;CACpB;;;;;;CAOA,UAAU,QAAQ;EACjB,KAAK,SAAS,KAAK,MAAM;EACzB,OAAO,KAAK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I,KAAK,YAAY,MAAM,IAAI,aAAa;IAC3D,KAAK,KAAK,KAAK,IAAI,KAAK,YAAY,MAAM,IAAI,aAAa;IAC3D,KAAK,YAAY;GAClB,OACC,KAAK,IAAI,KAAK;IAAC,GAAG,MAAM;IAAG,GAAG,MAAM;IAAG;GAAS,CAAC;EAEnD;EAEA,IAAI,UAAU,GAAG,GAAG,OAAO,MAAM;EACjC,MAAM,SAAS,KAAK,WAAW;EAC/B,KAAK,MAAM,EAAC,GAAG,GAAG,eAAc,KAAK,OAAO,GAAG;GAC9C,IAAI,cAAc,KAAK,IAAI,KAAK,IAAI,YAAY,KAAK,UAAU,GAAG,CAAC;GACnE,IAAI,UAAU,QAAQ,IAAI,GAAG,IAAI,CAAC;EACnC;EACA,IAAI,cAAc;EAGlB,IAAI,CAAC,KAAK,MAAQ;EAClB,MAAM,QAAQ,IAAI,aAAa,GAAG,GAAG,OAAO,MAAM,GAClD,SAAS,MAAM,MACf,WAAW,KAAK,aAAa;EAC7B,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;GAC1C,MAAM,IAAI,OAAO,KAAK;GACtB,IAAI,GAAG;IACN,OAAO,IAAI,KAAK,SAAS;IACzB,OAAO,IAAI,KAAK,SAAS,IAAI;IAC7B,OAAO,IAAI,KAAK,SAAS,IAAI;GAC9B;EACD;EACA,IAAI,aAAa,OAAO,GAAG,CAAC;CAC7B;AACD"}
@@ -3,7 +3,7 @@ import { create, setPosition, setTransform, toBack, toFront } from "../dom/DomUt
3
3
  import { Layer } from "./Layer.js";
4
4
  import { Bounds } from "../geometry/Bounds.js";
5
5
  import { LatLngBounds } from "../geo/LatLngBounds.js";
6
- //#region src/layer/ImageOverlay.js
6
+ // src/layer/ImageOverlay.js
7
7
  /** @import {InteractiveLayerOptions} from './Layer.js' */
8
8
  /** @import {LatLng} from '../geo/LatLng.js' */
9
9
  /** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */
@@ -226,7 +226,7 @@ var ImageOverlay = class ImageOverlay extends Layer {
226
226
  setTransform(this._image, offset, scale);
227
227
  }
228
228
  _reset() {
229
- const image = this._image, bounds = new Bounds(this._map.latLngToLayerPoint(this._bounds.getNorthWest()), this._map.latLngToLayerPoint(this._bounds.getSouthEast())), size = bounds.getSize();
229
+ const image = this._image, bounds = new Bounds(this._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(), this._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()), size = bounds.getSize();
230
230
  setPosition(image, bounds.min);
231
231
  image.style.width = `${size.x}px`;
232
232
  image.style.height = `${size.y}px`;
@@ -253,7 +253,6 @@ var ImageOverlay = class ImageOverlay extends Layer {
253
253
  return this._bounds.getCenter();
254
254
  }
255
255
  };
256
- //#endregion
257
256
  export { ImageOverlay };
258
257
 
259
258
  //# sourceMappingURL=ImageOverlay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ImageOverlay.js","names":["DomUtil.create","Util.splitWords"],"sources":["../../../src/layer/ImageOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as Util from '../core/Util.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Bounds} from '../geometry/Bounds.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `ImageOverlay`.\n * @typedef {object} ImageOverlayOptions\n * @property {number} [opacity=1] The opacity of the image overlay.\n * @property {string} [alt=''] Text for the `alt` attribute of the image (useful for\n * accessibility).\n * @property {boolean} [interactive=false] If `true`, the image overlay will emit\n * [pointer events](#interactivelayeroptions) when clicked or hovered.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute\n * will be added to the image. If a String is provided, the image will have its\n * crossOrigin attribute set to the String provided. This is needed if you want to\n * access image pixel data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {string} [errorOverlayUrl=''] URL to the overlay image to show in place\n * of the overlay that failed to load.\n * @property {number} [zIndex=1] The explicit\n * [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index)\n * of the overlay layer.\n * @property {string} [className=''] A custom class name to assign to the image. Empty\n * by default.\n * @property {boolean} [pixelated=false] Whether to scale the image with\n * nearest-neighbour interpolation (`image-rendering: pixelated`) instead of smoothing\n * it, so that its pixels stay crisp when zoomed in. Useful for raster data, pixel art\n * or scientific imagery.\n * @property {string} [decoding='auto'] Tells the browser whether to decode the image\n * in a synchronous fashion, as per the\n * [`decoding` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding).\n * If the image overlay is flickering when being added/removed, set this option to\n * `'sync'`.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Used to load and display a single image over specific bounds of the map. Extends `Layer`.\n *\n * @example\n * ```js\n * const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',\n * \timageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];\n * new ImageOverlay(imageUrl, imageBounds).addTo(map);\n * ```\n *\n * @fires load {MaplairEvent} Fired when the ImageOverlay layer has loaded its image.\n * @fires error {MaplairEvent} Fired when the ImageOverlay layer fails to load its image.\n */\nexport class ImageOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\topacity: 1,\n\t\talt: '',\n\t\tinteractive: false,\n\t\tcrossOrigin: false,\n\t\terrorOverlayUrl: '',\n\t\tzIndex: 1,\n\t\tclassName: '',\n\t\tpixelated: false,\n\t\tdecoding: 'auto'\n\t};\n\n\t/**\n\t * Instantiates an image overlay object given the URL of the image (or an image\n\t * element) and the geographical bounds it is tied to.\n\t * @param {string|HTMLImageElement} url\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {ImageOverlayOptions} [options]\n\t */\n\tconstructor(url, bounds, options) { // (String, LatLngBounds, Object)\n\t\tsuper();\n\t\tthis._url = url;\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(ImageOverlay);\n\t}\n\n\t/**\n\t * Adds the image to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._image) {\n\t\t\tthis._initImage();\n\n\t\t\tif (this.options.opacity < 1) {\n\t\t\t\tthis._updateOpacity();\n\t\t\t}\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._image.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t}\n\t\tthis._image.classList.toggle('maplair-pixelated', !!this.options.pixelated);\n\n\t\tthis.getPane().appendChild(this._image);\n\t\tthis._reset();\n\t}\n\n\t/**\n\t * Removes the image from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._image.remove();\n\t\tif (this.options.interactive) {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._image.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay.\n\t * @param {number} opacity\n\t * @returns {this}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._image) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay from the given style options, e.g. by\n\t * `FeatureGroup.setStyle()`.\n\t * @param {{opacity?: number}} styleOpts\n\t * @returns {this}\n\t */\n\tsetStyle(styleOpts) {\n\t\tif (styleOpts.opacity) {\n\t\t\tthis.setOpacity(styleOpts.opacity);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all overlays.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all overlays.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes the URL of the image.\n\t * @param {string} url\n\t * @returns {this}\n\t */\n\tsetUrl(url) {\n\t\tthis._url = url;\n\n\t\tif (this._image) {\n\t\t\tthis._image.src = url;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Update the bounds that this ImageOverlay covers.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {this}\n\t */\n\tsetBounds(bounds) {\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tif (this._map) {\n\t\t\tthis._reset();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\treturn {\n\t\t\tzoom: this._reset,\n\t\t\tviewreset: this._reset,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\t}\n\n\t/**\n\t * Changes the [zIndex](#imageoverlay-zindex) of the image overlay.\n\t * @param {number} value\n\t * @returns {this}\n\t */\n\tsetZIndex(value) {\n\t\tthis.options.zIndex = value;\n\t\tthis._updateZIndex();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the bounds that this ImageOverlay covers.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Returns the instance of\n\t * [`HTMLImageElement`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement)\n\t * used by this overlay (`HTMLVideoElement` for `VideoOverlay`, `SVGElement` for\n\t * `SVGOverlay`).\n\t * @returns {HTMLElement|SVGElement}\n\t */\n\tgetElement() {\n\t\treturn this._image;\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url instanceof HTMLImageElement;\n\t\tconst img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');\n\n\t\timg.classList.add('maplair-image-layer', 'maplair-zoom-animated');\n\t\tif (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\timg.onload = this.fire.bind(this, 'load');\n\t\timg.onerror = this._overlayOnError.bind(this);\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\timg.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\timg.decoding = this.options.decoding;\n\n\t\tif (this.options.zIndex) {\n\t\t\tthis._updateZIndex();\n\t\t}\n\n\t\tif (wasElementSupplied) {\n\t\t\tthis._url = img.src;\n\t\t\treturn;\n\t\t}\n\n\t\timg.src = this._url;\n\t\timg.alt = this.options.alt;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst scale = this._map.getZoomScale(e.zoom),\n\t\toffset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center);\n\n\t\tDomUtil.setTransform(this._image, offset, scale);\n\t}\n\n\t_reset() {\n\t\tconst image = this._image,\n\t\tbounds = new Bounds(\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getNorthWest()),\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getSouthEast())),\n\t\tsize = bounds.getSize();\n\n\t\tDomUtil.setPosition(image, bounds.min);\n\n\t\timage.style.width = `${size.x}px`;\n\t\timage.style.height = `${size.y}px`;\n\t}\n\n\t_updateOpacity() {\n\t\tthis._image.style.opacity = `${this.options.opacity}`;\n\t}\n\n\t_updateZIndex() {\n\t\tif (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {\n\t\t\tthis._image.style.zIndex = `${this.options.zIndex}`;\n\t\t}\n\t}\n\n\t_overlayOnError() {\n\t\tthis.fire('error');\n\n\t\tconst errorUrl = this.options.errorOverlayUrl;\n\t\tif (errorUrl && this._url !== errorUrl) {\n\t\t\tthis._url = errorUrl;\n\t\t\tthis._image.src = errorUrl;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the center of the ImageOverlay.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn this._bounds.getCenter();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAa,qBAAqB,MAAM;CAEvC,OAAO,iBAAiB;EACvB,SAAS;EACT,KAAK;EACL,aAAa;EACb,aAAa;EACb,iBAAiB;EACjB,QAAQ;EACR,WAAW;EACX,WAAW;EACX,UAAU;CACX;;;;;;;;CASA,YAAY,KAAK,QAAQ,SAAS;EACjC,MAAM;EACN,KAAK,OAAO;EACZ,KAAK,UAAU,IAAI,aAAa,MAAM;EAEtC,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,YAAY;CAChC;;;;;CAMA,QAAQ;EACP,IAAI,CAAC,KAAK,QAAQ;GACjB,KAAK,WAAW;GAEhB,IAAI,KAAK,QAAQ,UAAU,GAC1B,KAAK,eAAe;EAEtB;EAEA,IAAI,KAAK,QAAQ,aAAa;GAC7B,KAAK,OAAO,UAAU,IAAI,qBAAqB;GAC/C,KAAK,qBAAqB,KAAK,MAAM;EACtC;EACA,KAAK,OAAO,UAAU,OAAO,qBAAqB,CAAC,CAAC,KAAK,QAAQ,SAAS;EAE1E,KAAK,QAAQ,CAAC,CAAC,YAAY,KAAK,MAAM;EACtC,KAAK,OAAO;CACb;;;;;CAMA,WAAW;EACV,KAAK,OAAO,OAAO;EACnB,IAAI,KAAK,QAAQ,aAChB,KAAK,wBAAwB,KAAK,MAAM;CAE1C;CAEA,qBAAqB;EACpB,KAAK,OAAO,UAAU,OAAO,uBAAuB,KAAK,QAAQ,WAAW;EAC5E,IAAI,KAAK,QAAQ,aAChB,K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C/B;AACD"}
1
+ {"version":3,"file":"ImageOverlay.js","names":["DomUtil.create","Util.splitWords"],"sources":["../../../src/layer/ImageOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport * as Util from '../core/Util.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Bounds} from '../geometry/Bounds.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `ImageOverlay`.\n * @typedef {object} ImageOverlayOptions\n * @property {number} [opacity=1] The opacity of the image overlay.\n * @property {string} [alt=''] Text for the `alt` attribute of the image (useful for\n * accessibility).\n * @property {boolean} [interactive=false] If `true`, the image overlay will emit\n * [pointer events](#interactivelayeroptions) when clicked or hovered.\n * @property {boolean|string} [crossOrigin=false] Whether the crossOrigin attribute\n * will be added to the image. If a String is provided, the image will have its\n * crossOrigin attribute set to the String provided. This is needed if you want to\n * access image pixel data. Refer to\n * [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes)\n * for valid String values.\n * @property {string} [errorOverlayUrl=''] URL to the overlay image to show in place\n * of the overlay that failed to load.\n * @property {number} [zIndex=1] The explicit\n * [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index)\n * of the overlay layer.\n * @property {string} [className=''] A custom class name to assign to the image. Empty\n * by default.\n * @property {boolean} [pixelated=false] Whether to scale the image with\n * nearest-neighbour interpolation (`image-rendering: pixelated`) instead of smoothing\n * it, so that its pixels stay crisp when zoomed in. Useful for raster data, pixel art\n * or scientific imagery.\n * @property {string} [decoding='auto'] Tells the browser whether to decode the image\n * in a synchronous fashion, as per the\n * [`decoding` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding).\n * If the image overlay is flickering when being added/removed, set this option to\n * `'sync'`.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Used to load and display a single image over specific bounds of the map. Extends `Layer`.\n *\n * @example\n * ```js\n * const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',\n * \timageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];\n * new ImageOverlay(imageUrl, imageBounds).addTo(map);\n * ```\n *\n * @fires load {MaplairEvent} Fired when the ImageOverlay layer has loaded its image.\n * @fires error {MaplairEvent} Fired when the ImageOverlay layer fails to load its image.\n */\nexport class ImageOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\topacity: 1,\n\t\talt: '',\n\t\tinteractive: false,\n\t\tcrossOrigin: false,\n\t\terrorOverlayUrl: '',\n\t\tzIndex: 1,\n\t\tclassName: '',\n\t\tpixelated: false,\n\t\tdecoding: 'auto'\n\t};\n\n\t/**\n\t * Instantiates an image overlay object given the URL of the image (or an image\n\t * element) and the geographical bounds it is tied to.\n\t * @param {string|HTMLImageElement} url\n\t * @param {LatLngBoundsExpression} bounds\n\t * @param {ImageOverlayOptions} [options]\n\t */\n\tconstructor(url, bounds, options) { // (String, LatLngBounds, Object)\n\t\tsuper();\n\t\tthis._url = url;\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(ImageOverlay);\n\t}\n\n\t/**\n\t * Adds the image to the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonAdd() {\n\t\tif (!this._image) {\n\t\t\tthis._initImage();\n\n\t\t\tif (this.options.opacity < 1) {\n\t\t\t\tthis._updateOpacity();\n\t\t\t}\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._image.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t}\n\t\tthis._image.classList.toggle('maplair-pixelated', !!this.options.pixelated);\n\n\t\tthis.getPane().appendChild(this._image);\n\t\tthis._reset();\n\t}\n\n\t/**\n\t * Removes the image from the map.\n\t * @type {(map: MaplairMap) => void}\n\t */\n\tonRemove() {\n\t\tthis._image.remove();\n\t\tif (this.options.interactive) {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._image.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._image);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._image);\n\t\t}\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay.\n\t * @param {number} opacity\n\t * @returns {this}\n\t */\n\tsetOpacity(opacity) {\n\t\tthis.options.opacity = opacity;\n\n\t\tif (this._image) {\n\t\t\tthis._updateOpacity();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Sets the opacity of the overlay from the given style options, e.g. by\n\t * `FeatureGroup.setStyle()`.\n\t * @param {{opacity?: number}} styleOpts\n\t * @returns {this}\n\t */\n\tsetStyle(styleOpts) {\n\t\tif (styleOpts.opacity) {\n\t\t\tthis.setOpacity(styleOpts.opacity);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the top of all overlays.\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings the layer to the bottom of all overlays.\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._image);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Changes the URL of the image.\n\t * @param {string} url\n\t * @returns {this}\n\t */\n\tsetUrl(url) {\n\t\tthis._url = url;\n\n\t\tif (this._image) {\n\t\t\tthis._image.src = url;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Update the bounds that this ImageOverlay covers.\n\t * @param {LatLngBoundsExpression} bounds\n\t * @returns {this}\n\t */\n\tsetBounds(bounds) {\n\t\tthis._bounds = new LatLngBounds(bounds);\n\n\t\tif (this._map) {\n\t\t\tthis._reset();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\treturn {\n\t\t\tzoom: this._reset,\n\t\t\tviewreset: this._reset,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\t}\n\n\t/**\n\t * Changes the [zIndex](#imageoverlay-zindex) of the image overlay.\n\t * @param {number} value\n\t * @returns {this}\n\t */\n\tsetZIndex(value) {\n\t\tthis.options.zIndex = value;\n\t\tthis._updateZIndex();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Get the bounds that this ImageOverlay covers.\n\t * @returns {LatLngBounds}\n\t */\n\tgetBounds() {\n\t\treturn this._bounds;\n\t}\n\n\t/**\n\t * Returns the instance of\n\t * [`HTMLImageElement`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement)\n\t * used by this overlay (`HTMLVideoElement` for `VideoOverlay`, `SVGElement` for\n\t * `SVGOverlay`).\n\t * @returns {HTMLElement|SVGElement}\n\t */\n\tgetElement() {\n\t\treturn this._image;\n\t}\n\n\t_initImage() {\n\t\tconst wasElementSupplied = this._url instanceof HTMLImageElement;\n\t\tconst img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');\n\n\t\timg.classList.add('maplair-image-layer', 'maplair-zoom-animated');\n\t\tif (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }\n\n\t\timg.onload = this.fire.bind(this, 'load');\n\t\timg.onerror = this._overlayOnError.bind(this);\n\n\t\tif (this.options.crossOrigin || this.options.crossOrigin === '') {\n\t\t\timg.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;\n\t\t}\n\n\t\timg.decoding = this.options.decoding;\n\n\t\tif (this.options.zIndex) {\n\t\t\tthis._updateZIndex();\n\t\t}\n\n\t\tif (wasElementSupplied) {\n\t\t\tthis._url = img.src;\n\t\t\treturn;\n\t\t}\n\n\t\timg.src = this._url;\n\t\timg.alt = this.options.alt;\n\t}\n\n\t_animateZoom(e) {\n\t\tconst scale = this._map.getZoomScale(e.zoom),\n\t\toffset = this._map._latLngToNewLayerPoint(this._bounds.getNorthWest(), e.zoom, e.center);\n\n\t\tDomUtil.setTransform(this._image, offset, scale);\n\t}\n\n\t_reset() {\n\t\tconst image = this._image,\n\t\tbounds = new Bounds(\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getNorthWest())._round(),\n\t\t\tthis._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()),\n\t\tsize = bounds.getSize();\n\n\t\tDomUtil.setPosition(image, bounds.min);\n\n\t\timage.style.width = `${size.x}px`;\n\t\timage.style.height = `${size.y}px`;\n\t}\n\n\t_updateOpacity() {\n\t\tthis._image.style.opacity = `${this.options.opacity}`;\n\t}\n\n\t_updateZIndex() {\n\t\tif (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {\n\t\t\tthis._image.style.zIndex = `${this.options.zIndex}`;\n\t\t}\n\t}\n\n\t_overlayOnError() {\n\t\tthis.fire('error');\n\n\t\tconst errorUrl = this.options.errorOverlayUrl;\n\t\tif (errorUrl && this._url !== errorUrl) {\n\t\t\tthis._url = errorUrl;\n\t\t\tthis._image.src = errorUrl;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the center of the ImageOverlay.\n\t * @returns {LatLng}\n\t */\n\tgetCenter() {\n\t\treturn this._bounds.getCenter();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAa,qBAAqB,MAAM;CAEvC,OAAO,iBAAiB;EACvB,SAAS;EACT,KAAK;EACL,aAAa;EACb,aAAa;EACb,iBAAiB;EACjB,QAAQ;EACR,WAAW;EACX,WAAW;EACX,UAAU;CACX;;;;;;;;CASA,YAAY,KAAK,QAAQ,SAAS;EACj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K,QACnB,SAAS,IAAI,OACZ,KAAK,KAAK,mBAAmB,KAAK,QAAQ,aAAa,CAAC,CAAC,CAAC,OAAO,GACjE,KAAK,KAAK,mBAAmB,KAAK,QAAQ,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,GACnE,OAAO,OAAO,QAAQ;EAEtB,YAAoB,OAAO,OAAO,GAAG;EAErC,MAAM,MAAM,QAAS,GAAG,KAAK,EAAE;EAC/B,MAAM,MAAM,SAAS,GAAG,KAAK,EAAE;CAChC;CAEA,iBAAiB;EAChB,KAAK,OAAO,MAAM,UAAU,GAAG,KAAK,QAAQ;CAC7C;CAEA,gBAAgB;EACf,IAAI,KAAK,UAAU,KAAK,QAAQ,WAAW,KAAA,KAAa,KAAK,QAAQ,WAAW,MAC/E,KAAK,OAAO,MAAM,SAAS,GAAG,KAAK,QAAQ;CAE7C;CAEA,kBAAkB;EACjB,KAAK,KAAK,OAAO;EAEjB,MAAM,WAAW,KAAK,QAAQ;EAC9B,IAAI,YAAY,KAAK,SAAS,UAAU;GACvC,KAAK,OAAO;GACZ,KAAK,OAAO,MAAM;EACnB;CACD;;;;;CAMA,YAAY;EACX,OAAO,KAAK,QAAQ,UAAU;CAC/B;AACD"}
@@ -1,6 +1,6 @@
1
1
  import { setOptions, stamp } from "../core/Util.js";
2
2
  import { Evented } from "../core/Events.js";
3
- //#region src/layer/Layer.js
3
+ // src/layer/Layer.js
4
4
  /** @import {MaplairMap} from '../map/Map.js' */
5
5
  /** @import {LayerGroup} from './LayerGroup.js' */
6
6
  /** @import {EventListener, MaplairEvent, MaplairPointerEvent, LayerEvent} from '../core/Events.js' */
@@ -321,7 +321,6 @@ var Layer = class extends Evented {
321
321
  MaplairMap.include(mapLayerMethods);
322
322
  }
323
323
  };
324
- //#endregion
325
324
  export { Layer };
326
325
 
327
326
  //# sourceMappingURL=Layer.js.map
@@ -1,7 +1,7 @@
1
1
  import { setOptions, stamp } from "../core/Util.js";
2
2
  import { Layer } from "./Layer.js";
3
3
  import { asFeature, getFeature } from "./GeoJSONUtil.js";
4
- //#region src/layer/LayerGroup.js
4
+ // src/layer/LayerGroup.js
5
5
  /** @import {Feature, FeatureCollection} from 'geojson' */
6
6
  /** @import {InteractiveLayerOptions} from './Layer.js' */
7
7
  /** @import {MaplairMap} from '../map/Map.js' */
@@ -48,7 +48,7 @@ var LayerGroup = class LayerGroup extends Layer {
48
48
  * @returns {this}
49
49
  */
50
50
  removeLayer(layer) {
51
- const id = layer in this._layers ? layer : this.getLayerId(layer);
51
+ const id = typeof layer === "number" ? layer : this.getLayerId(layer);
52
52
  if (this._map && this._layers[id]) this._map.removeLayer(this._layers[id]);
53
53
  delete this._layers[id];
54
54
  return this;
@@ -180,7 +180,6 @@ var LayerGroup = class LayerGroup extends Layer {
180
180
  };
181
181
  }
182
182
  };
183
- //#endregion
184
183
  export { LayerGroup };
185
184
 
186
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';\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 = 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\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,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,OA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,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
+ {"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,KAAK,QAAQ,MAAM;EAEnB,KAAK,MAAM,SAAS,KAAK;EAEzB,OAAO;CACR;;;;;;CAOA,YAAY,OAAO;EAClB,MAAM,KAAK,OAAO,UAAU,WAAW,QAAQ,KAAK,WAAW,KAAK;EAEpE,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;;;;;;;;CASA,aAAa,WAAW;EACvB,MAAM,SAAS,CAAC;EAEhB,KAAK,WAAW,UAAU;GACzB,OAAO,KAAK,MAAM,UAAU,SAAS,CAAC,CAAC,SAAS,WAAW;EAC5D,CAAC;EAED,OAAO,WAAW,MAAM;GACvB,MAAM;GACN,aAAa;EACd,CAAC;CACF;;;;;;;;;CAUA,UAAU,WAAW;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,12 +1,12 @@
1
1
  import { Point } from "../geometry/Point.js";
2
- import { disableClickPropagation, disableScrollPropagation, on, stop, stopPropagation } from "../dom/DomEvent.js";
2
+ import { disableClickPropagation, disableScrollPropagation, on, stopPropagation } from "../dom/DomEvent.js";
3
3
  import { create } from "../dom/DomUtil.js";
4
4
  import { I18n } from "../core/I18n.js";
5
5
  import { Layer } from "./Layer.js";
6
6
  import { Path } from "./vector/Path.js";
7
7
  import { FeatureGroup } from "./FeatureGroup.js";
8
8
  import { DivOverlay } from "./DivOverlay.js";
9
- //#region src/layer/Popup.js
9
+ // src/layer/Popup.js
10
10
  /** @import {DivOverlayOptions, DivOverlayContent} from './DivOverlay.js' */
11
11
  /** @import {LatLngExpression} from '../geo/LatLng.js' */
12
12
  /** @import {PointExpression} from '../geometry/Point.js' */
@@ -212,7 +212,7 @@ const layerPopupMethods = {
212
212
  },
213
213
  _openPopup(e) {
214
214
  if (!this._popup || !this._map) return;
215
- stop(e);
215
+ stopPropagation(e);
216
216
  const target = e.propagatedFrom ?? e.target;
217
217
  if (this._popup._source === target && !(target instanceof Path)) {
218
218
  if (this._map.hasLayer(this._popup)) this.closePopup();
@@ -364,9 +364,6 @@ var Popup = class Popup extends DivOverlay {
364
364
  const wrapper = this._wrapper = create("div", `${prefix}-content-wrapper`, container);
365
365
  this._contentNode = create("div", `${prefix}-content`, wrapper);
366
366
  disableClickPropagation(container);
367
- on(container, "keydown", (e) => {
368
- if (e.key === "Escape" && this.options.closeOnEscapeKey) this.close();
369
- });
370
367
  disableScrollPropagation(this._contentNode);
371
368
  on(container, "contextmenu", stopPropagation);
372
369
  this._tipContainer = create("div", `${prefix}-tip-container`, container);
@@ -382,14 +379,12 @@ var Popup = class Popup extends DivOverlay {
382
379
  });
383
380
  }
384
381
  if (this.options.trackResize) {
385
- this._resizeObserver = new ResizeObserver(((entries) => {
382
+ this._resizeObserver = new ResizeObserver(() => {
386
383
  if (!this._map) return;
387
- this._containerWidth = entries[0]?.contentRect?.width;
388
- this._containerHeight = entries[0]?.contentRect?.height;
389
384
  this._updateLayout();
390
385
  this._updatePosition();
391
386
  this._adjustPan();
392
- }));
387
+ });
393
388
  this._resizeObserver.observe(this._contentNode);
394
389
  }
395
390
  }
@@ -397,11 +392,10 @@ var Popup = class Popup extends DivOverlay {
397
392
  const container = this._contentNode, style = container.style;
398
393
  style.maxWidth = `${this.options.maxWidth}px`;
399
394
  style.minWidth = `${this.options.minWidth}px`;
400
- const maxHeight = this.options.maxHeight, scrolledClass = "maplair-popup-scrolled";
401
- if (maxHeight && (this._containerHeight ?? container.offsetHeight) > maxHeight) {
402
- style.height = `${maxHeight}px`;
403
- container.classList.add(scrolledClass);
404
- } 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);
405
399
  this._containerWidth = this._container.offsetWidth;
406
400
  this._containerHeight = this._container.offsetHeight;
407
401
  this._containerMarginBottom = parseInt(getComputedStyle(this._container).marginBottom, 10) || 0;
@@ -445,7 +439,6 @@ var Popup = class Popup extends DivOverlay {
445
439
  Layer.include(layerPopupMethods);
446
440
  }
447
441
  };
448
- //#endregion
449
442
  export { Popup };
450
443
 
451
444
  //# sourceMappingURL=Popup.js.map
@@ -1 +1 @@
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.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/** @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\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// 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":";;;;;;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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,OAAO,KAAK,QAAQ,SAAS,OAAO;EACpE,KAAK,GAAG;GACP,O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F,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
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
  /**
@@ -45,7 +45,6 @@ var SVGOverlay = class SVGOverlay extends ImageOverlay {
45
45
  if (this.options.className) el.classList.add(...splitWords(this.options.className));
46
46
  }
47
47
  };
48
- //#endregion
49
48
  export { SVGOverlay };
50
49
 
51
50
  //# sourceMappingURL=SVGOverlay.js.map
@@ -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
@@ -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();
@@ -447,7 +447,7 @@ var Tooltip = class Tooltip extends DivOverlay {
447
447
  };
448
448
  }
449
449
  _updatePosition() {
450
- const pos = this._map.latLngToLayerPoint(this._latlng);
450
+ const pos = this._map.latLngToLayerPoint(this._latlng)._round();
451
451
  this._setPosition(pos);
452
452
  }
453
453
  /**
@@ -476,7 +476,6 @@ var Tooltip = class Tooltip extends DivOverlay {
476
476
  Layer.include(layerTooltipMethods);
477
477
  }
478
478
  };
479
- //#endregion
480
479
  export { Tooltip };
481
480
 
482
481
  //# sourceMappingURL=Tooltip.js.map