maplair 4.4.0 → 4.5.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 (121) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/esm/control/AttributionControl.js +20 -3
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/LayersControl.js +35 -20
  5. package/dist/esm/control/LayersControl.js.map +1 -1
  6. package/dist/esm/control/ScaleControl.js +3 -3
  7. package/dist/esm/control/ScaleControl.js.map +1 -1
  8. package/dist/esm/control/ZoomControl.js +1 -0
  9. package/dist/esm/control/ZoomControl.js.map +1 -1
  10. package/dist/esm/core/Util.js +1 -1
  11. package/dist/esm/core/Util.js.map +1 -1
  12. package/dist/esm/dom/DomEvent.PointerEvents.js +19 -2
  13. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  14. package/dist/esm/dom/Draggable.js +6 -2
  15. package/dist/esm/dom/Draggable.js.map +1 -1
  16. package/dist/esm/geo/LatLng.js +1 -1
  17. package/dist/esm/geo/LatLng.js.map +1 -1
  18. package/dist/esm/geo/LatLngBounds.js +1 -1
  19. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  20. package/dist/esm/geometry/Bounds.js +1 -1
  21. package/dist/esm/geometry/Bounds.js.map +1 -1
  22. package/dist/esm/geometry/Point.js +4 -2
  23. package/dist/esm/geometry/Point.js.map +1 -1
  24. package/dist/esm/geometry/PolyUtil.js +10 -3
  25. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  26. package/dist/esm/layer/BlanketOverlay.js +2 -1
  27. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  28. package/dist/esm/layer/DivOverlay.js +3 -3
  29. package/dist/esm/layer/DivOverlay.js.map +1 -1
  30. package/dist/esm/layer/ImageOverlay.js +1 -1
  31. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  32. package/dist/esm/layer/Layer.js +1 -1
  33. package/dist/esm/layer/Layer.js.map +1 -1
  34. package/dist/esm/layer/Popup.js +3 -4
  35. package/dist/esm/layer/Popup.js.map +1 -1
  36. package/dist/esm/layer/Tooltip.js +31 -22
  37. package/dist/esm/layer/Tooltip.js.map +1 -1
  38. package/dist/esm/layer/marker/Icon.js +25 -6
  39. package/dist/esm/layer/marker/Icon.js.map +1 -1
  40. package/dist/esm/layer/marker/Marker.Drag.js +5 -5
  41. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  42. package/dist/esm/layer/marker/Marker.js +5 -5
  43. package/dist/esm/layer/marker/Marker.js.map +1 -1
  44. package/dist/esm/layer/tile/GridLayer.js +11 -5
  45. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  46. package/dist/esm/layer/tile/TileLayer.js +10 -6
  47. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  48. package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
  49. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  50. package/dist/esm/layer/vector/Canvas.js +2 -2
  51. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  52. package/dist/esm/layer/vector/Circle.js +2 -3
  53. package/dist/esm/layer/vector/Circle.js.map +1 -1
  54. package/dist/esm/layer/vector/CircleMarker.js +6 -3
  55. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  56. package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
  57. package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
  58. package/dist/esm/map/Map.Rotation.js +3 -2
  59. package/dist/esm/map/Map.Rotation.js.map +1 -1
  60. package/dist/esm/map/Map.js +58 -26
  61. package/dist/esm/map/Map.js.map +1 -1
  62. package/dist/esm/map/MapSync.js +1 -1
  63. package/dist/esm/map/MapSync.js.map +1 -1
  64. package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
  65. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  66. package/dist/esm/map/handler/DragHandler.js +7 -2
  67. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  68. package/dist/esm/map/handler/PinchZoomHandler.js +1 -1
  69. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  70. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -1
  71. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  72. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -1
  73. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  74. package/dist/esm/package.js +1 -1
  75. package/dist/maplair-global-src.js +289 -140
  76. package/dist/maplair-global-src.js.map +1 -1
  77. package/dist/maplair-global.js +2 -2
  78. package/dist/maplair-global.js.map +1 -1
  79. package/dist/maplair-src.js +289 -140
  80. package/dist/maplair-src.js.map +1 -1
  81. package/dist/maplair.css +1 -1
  82. package/dist/maplair.js +2 -2
  83. package/dist/maplair.js.map +1 -1
  84. package/package.json +1 -1
  85. package/src/control/AttributionControl.js +29 -3
  86. package/src/control/LayersControl.js +47 -27
  87. package/src/control/ScaleControl.js +6 -3
  88. package/src/control/ZoomControl.js +1 -0
  89. package/src/core/Util.js +1 -1
  90. package/src/dom/DomEvent.PointerEvents.js +22 -2
  91. package/src/dom/Draggable.js +6 -2
  92. package/src/geo/LatLng.js +2 -1
  93. package/src/geo/LatLngBounds.js +1 -1
  94. package/src/geometry/Bounds.js +1 -1
  95. package/src/geometry/Point.js +4 -2
  96. package/src/geometry/PolyUtil.js +12 -3
  97. package/src/layer/BlanketOverlay.js +5 -2
  98. package/src/layer/DivOverlay.js +3 -3
  99. package/src/layer/ImageOverlay.js +3 -2
  100. package/src/layer/Layer.js +1 -1
  101. package/src/layer/Popup.js +3 -4
  102. package/src/layer/Tooltip.js +34 -27
  103. package/src/layer/marker/Icon.js +25 -5
  104. package/src/layer/marker/Marker.Drag.js +6 -6
  105. package/src/layer/marker/Marker.js +5 -5
  106. package/src/layer/tile/GridLayer.js +20 -7
  107. package/src/layer/tile/TileLayer.js +14 -7
  108. package/src/layer/tile/WMSTileLayer.js +4 -2
  109. package/src/layer/vector/Canvas.js +2 -2
  110. package/src/layer/vector/Circle.js +3 -5
  111. package/src/layer/vector/CircleMarker.js +5 -2
  112. package/src/layer/vector/Path.ZoomStyles.js +5 -3
  113. package/src/map/Map.Rotation.js +6 -3
  114. package/src/map/Map.js +63 -32
  115. package/src/map/MapSync.js +1 -1
  116. package/src/map/handler/BoxZoomHandler.js +3 -0
  117. package/src/map/handler/DragHandler.js +5 -5
  118. package/src/map/handler/PinchZoomHandler.js +1 -1
  119. package/src/map/handler/ScrollWheelZoomHandler.js +1 -1
  120. package/src/map/handler/TapDragZoomHandler.js +1 -1
  121. package/src/maplair.css +12 -1
@@ -1 +1 @@
1
- {"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and\n * returning one of them.\n * @typedef {string|HTMLElement|DocumentFragment|\n * ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent\n */\n\nconst fragmentNodes = new WeakMap();\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String`, `HTMLElement` or `DocumentFragment`\n * to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit\n * from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tif (this._prepareOpen()) {\n\t\t\t\t// open the overlay on the map\n\t\t\t\tthis.openOn(layer._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().append(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t * or pass an `HTMLElement` with safe `textContent` instead. A `DocumentFragment`\n\t * can be passed as well. If a function is passed the source layer will be passed\n\t * to the function. The function should return a `String`, `HTMLElement` or\n\t * `DocumentFragment` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map?.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tlatlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();\n\t\tif (!latlng) { throw new Error('Unable to get source layer LatLng.'); }\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (this._content == null) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else if (content instanceof DocumentFragment) {\n\t\t\t// inserting a fragment empties it, so keep its nodes to insert them again on later updates\n\t\t\tif (content.hasChildNodes()) { fragmentNodes.set(content, [...content.childNodes]); }\n\t\t\tnode.replaceChildren(...fragmentNodes.get(content) ?? []);\n\t\t} else {\n\t\t\tnode.replaceChildren(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng)._round(),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAM,gCAAgB,IAAI,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;AA2BlC,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;CAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;CAEzB,OAAO;AACR,EACD;;;;;;AAOA,MAAM,yBAAyB,EAC9B,aAAa,cAAc,KAAK,SAAS,SAAS;CACjD,IAAI,UAAU;CACd,IAAI,mBAAmB,c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MAAM,SAAS,eAAe,OAAO;EACtD,OACC,KAAK,WAAW,MAAM,SAAS,GAAG,OAAO;EAE1C,KAAK,WAAW,MAAM,OAAO,GAAG,KAAK;CACtC;CAIA,sBAAsB,KAAK;EAC1B,KAAK,gBAAgB;EACrB,IAAI,KAAK,QAAQ,UAAU;GAC1B,MAAM,eAAe,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
1
+ {"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {InteractiveLayerOptions} from './Layer.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {PointExpression} from '../geometry/Point.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {EventListener, MaplairEvent} from '../core/Events.js' */\n\n/**\n * The content of a `DivOverlay` (`Popup`, `Tooltip`): a string rendered as HTML, an\n * `HTMLElement` or `DocumentFragment`, or a function receiving the source layer and\n * returning one of them.\n * @typedef {string|HTMLElement|DocumentFragment|\n * ((layer: Layer) => string|HTMLElement|DocumentFragment)} DivOverlayContent\n */\n\nconst fragmentNodes = new WeakMap();\n\n/**\n * Options of `DivOverlay`.\n * @typedef {object} DivOverlayOptions\n * @property {boolean} [interactive=false] If true, the popup/tooltip will listen to the\n * pointer events.\n * @property {PointExpression} [offset=[0, 0]] The offset of the overlay position.\n * @property {string} [className=''] A custom CSS class name to assign to the overlay.\n * @property {string} [pane] `Map pane` where the overlay will be added.\n * @property {boolean} [overflow=false] Whether the overlay may extend beyond the map\n * container, e.g. a tooltip of a marker near the edge of a small map. The overlay is\n * then shown as [popover](https://developer.mozilla.org/docs/Web/API/Popover_API) in\n * the top layer of the page, above all other content, while remaining in its map pane\n * in the DOM (for styling and events).\n * @property {DivOverlayContent} [content=''] Sets the HTML content of the overlay while\n * initializing. If a function is passed the source layer will be passed to the\n * function. The function should return a `String`, `HTMLElement` or `DocumentFragment`\n * to be used in the overlay. String content is rendered as HTML; sanitize untrusted input or pass an\n * `HTMLElement` with safe `textContent` instead.\n * @extends InteractiveLayerOptions\n */\n\n/**\n * Methods of `MaplairMap` for overlays.\n * @lends MaplairMap.prototype\n */\nconst mapDivOverlayMethods = {\n\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\tlet overlay = content;\n\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t}\n\t\tif (latlng) {\n\t\t\toverlay.setLatLng(latlng);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof mapDivOverlayMethods} MapDivOverlayMethods */\n\n/**\n * Methods of `Layer` for overlays.\n * @lends Layer.prototype\n */\nconst layerDivOverlayMethods = {\n\t_initOverlay(OverlayClass, old, content, options) {\n\t\tlet overlay = content;\n\t\tif (overlay instanceof OverlayClass) {\n\t\t\tUtil.setOptions(overlay, options);\n\t\t\toverlay._source = this;\n\t\t} else {\n\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\toverlay.setContent(content);\n\t\t}\n\t\treturn overlay;\n\t}\n};\n/** @typedef {typeof layerDivOverlayMethods} LayerDivOverlayMethods */\n\n/**\n * Base model for `Popup` and `Tooltip`; use those to show content on the map. Inherit\n * from it for custom overlays like plugins.\n *\n * @fires contentupdate {MaplairEvent} Fired when the content of the overlay is updated.\n */\nexport class DivOverlay extends Layer {\n\n\tstatic defaultOptions = {\n\t\tinteractive: false,\n\t\toffset: [0, 0],\n\t\tclassName: '',\n\t\tpane: undefined,\n\t\toverflow: false,\n\t\tcontent: ''\n\t};\n\n\t/**\n\t * Instantiates an overlay given an optional `options` object that describes its\n\t * appearance and location and an optional `source` object that is used to tag the\n\t * overlay with a reference to the Layer to which it refers.\n\t * @overload\n\t * @param {DivOverlayOptions} [options]\n\t * @param {Layer} [source]\n\t */\n\t/**\n\t * Instantiates an overlay given `latlng` where the overlay will open and an\n\t * optional `options` object that describes its appearance and location.\n\t * @overload\n\t * @param {LatLngExpression} latlng\n\t * @param {DivOverlayOptions} [options]\n\t */\n\t/**\n\t * @param {DivOverlayOptions|LatLngExpression} [options]\n\t * @param {Layer|DivOverlayOptions} [source]\n\t */\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the overlay.\n\t * Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t * and `layer.closePopup()`/`.closeTooltip()`.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Opens or closes the overlay bound to layer depending on its current state.\n\t * Argument may be omitted only for overlay bound to layer.\n\t * Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\t * @param {Layer} [layer]\n\t * @returns {this}\n\t */\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tif (this._prepareOpen()) {\n\t\t\t\t// open the overlay on the map\n\t\t\t\tthis.openOn(layer._map);\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds the overlay to the map.\n\t * @param {MaplairMap} map\n\t */\n\tonAdd(map) {\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().append(this._container);\n\t\tif (this.options.overflow) {\n\t\t\tthis._container.classList.add('maplair-overflow');\n\t\t\tthis._container.popover = 'manual';\n\t\t\tthis._container.showPopover();\n\t\t\t// The map pane does not carry the overlay, it has to follow the page and the map\n\t\t\tthis._onPageChange ??= () => this._updatePosition();\n\t\t\tdocument.addEventListener('scroll', this._onPageChange, {capture: true, passive: true});\n\t\t\twindow.addEventListener('resize', this._onPageChange, {passive: true});\n\t\t}\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '1';\n\t\t}\n\n\t\t// A popover is shown on top already, re-showing it would skip the fade animation\n\t\tif (!this.options.overflow) {\n\t\t\tthis.bringToFront();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Removes the overlay from the map.\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tif (this.options.overflow) {\n\t\t\tdocument.removeEventListener('scroll', this._onPageChange, {capture: true});\n\t\t\twindow.removeEventListener('resize', this._onPageChange);\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = '0';\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t_updateInteractive() {\n\t\tthis._container.classList.toggle('maplair-interactive', this.options.interactive);\n\t\tif (this.options.interactive) {\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t} else {\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t/**\n\t * Returns the geographical point of the overlay.\n\t * @returns {LatLng}\n\t */\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t/**\n\t * Sets the geographical point where the overlay will open.\n\t * @param {LatLngExpression} latlng\n\t * @returns {this}\n\t */\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the overlay.\n\t * @returns {DivOverlayContent}\n\t */\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t/**\n\t * Sets the HTML content of the overlay. A `String` argument is rendered as\n\t * HTML; if it may contain untrusted input, sanitize it or pass an `HTMLElement`\n\t * with safe `textContent` instead. A `DocumentFragment`\n\t * can be passed as well. If a function is passed the source layer will be passed\n\t * to the function. The function should return a `String`, `HTMLElement` or\n\t * `DocumentFragment` to be used in the overlay.\n\t * @param {DivOverlayContent} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTML container of the overlay.\n\t * @returns {HTMLElement}\n\t */\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Updates the overlay content, layout and position. Useful for updating the\n\t * overlay after something inside changed, e.g. image loaded.\n\t * @returns {void}\n\t */\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\t/**\n\t * Returns the map events the overlay listens to.\n\t * @returns {Record<string, EventListener>}\n\t */\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition,\n\t\t\tzoomanim: this._animateZoom\n\t\t};\n\n\t\tif (this.options.overflow) {\n\t\t\tevents.move = this._updatePosition;\n\t\t}\n\t\treturn events;\n\t}\n\n\t/**\n\t * Returns `true` when the overlay is visible on the map.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._map?.hasLayer(this);\n\t}\n\n\t/**\n\t * Brings this overlay in front of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Brings this overlay to the back of other overlays (in the same map pane).\n\t * @returns {this}\n\t */\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t\tthis._restackPopovers();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Popovers are stacked in the order they are shown, not in DOM order. Moving\n\t// a popover in the DOM hides it, so (re-)show the overflowing overlays of\n\t// the pane in DOM order.\n\t_restackPopovers() {\n\t\tif (!this.options.overflow) { return; }\n\t\tfor (const el of this.getPane().children) {\n\t\t\tif (!el.classList.contains('maplair-overflow')) { continue; }\n\t\t\tif (el.matches(':popover-open')) {\n\t\t\t\tel.hidePopover();\n\t\t\t}\n\t\t\tel.showPopover();\n\t\t}\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tlatlng ??= source.getCenter?.() ?? source.getLatLng?.() ?? source.getBounds?.().getCenter();\n\t\tif (!latlng) { throw new Error('Unable to get source layer LatLng.'); }\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (this._content == null) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else if (content instanceof DocumentFragment) {\n\t\t\t// inserting a fragment empties it, so keep its nodes to insert them again on later updates\n\t\t\tif (content.hasChildNodes()) { fragmentNodes.set(content, [...content.childNodes]); }\n\t\t\tnode.replaceChildren(...fragmentNodes.get(content) ?? []);\n\t\t} else {\n\t\t\tnode.replaceChildren(content);\n\t\t}\n\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng)),\n\t\toffset = Point.from(this.options.offset);\n\n\t\tthis._setContainerPosition(pos.add(this._getAnchor()));\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tif (this.options.overflow) {\n\t\t\t// relative to the top of the viewport instead of the pane origin\n\t\t\tthis._container.style.top = 'auto';\n\t\t\tthis._container.style.bottom = `calc(100% + ${bottom}px)`;\n\t\t} else {\n\t\t\tthis._container.style.bottom = `${bottom}px`;\n\t\t}\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t// Positions the container at the given layer point. An overflowing overlay\n\t// lives in the top layer of the page, so it is positioned in viewport coordinates.\n\t_setContainerPosition(pos) {\n\t\tthis._containerPos = pos;\n\t\tif (this.options.overflow) {\n\t\t\tconst mapContainer = this._map._container,\n\t\t\trect = mapContainer.getBoundingClientRect();\n\t\t\tpos = this._map.layerPointToContainerPoint(pos)\n\t\t\t\t._add(new Point(rect.left + mapContainer.clientLeft, rect.top + mapContainer.clientTop));\n\t\t}\n\t\tDomUtil.setPosition(this._container, pos);\n\t}\n\n\t// Returns the layer point the container was positioned at, see `_setContainerPosition`.\n\t_getContainerPosition() {\n\t\treturn this._containerPos ?? new Point(0, 0);\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapDivOverlayMethods);\n\n\t\tLayer.include(layerDivOverlayMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAM,gCAAgB,IAAI,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;AA2BlC,MAAM,uBAAuB,EAC5B,aAAa,cAAc,SAAS,QAAQ,SAAS;CACpD,IAAI,UAAU;CACd,IAAI,EAA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AAI,KAAK,WAAW,CAAC,CAAC;EAErD,MAAM,SAAS,KAAK,mBAAmB,CAAC,OAAO,GAC/C,OAAO,KAAK,iBAAiB,CAAC,KAAK,MAAM,KAAK,kBAAkB,CAAC,IAAI,OAAO;EAG5E,IAAI,KAAK,QAAQ,UAAU;GAE1B,KAAK,WAAW,MAAM,MAAM;GAC5B,KAAK,WAAW,MAAM,SAAS,eAAe,OAAO;EACtD,OACC,KAAK,WAAW,MAAM,SAAS,GAAG,OAAO;EAE1C,KAAK,WAAW,MAAM,OAAO,GAAG,KAAK;CACtC;CAIA,sBAAsB,KAAK;EAC1B,KAAK,gBAAgB;EACrB,IAAI,KAAK,QAAQ,UAAU;GAC1B,MAAM,eAAe,KAAK,KAAK,YAC/B,OAAO,aAAa,sBAAsB;GAC1C,MAAM,KAAK,KAAK,2BAA2B,GAAG,CAAC,CAC7C,KAAK,IAAI,MAAM,KAAK,OAAO,aAAa,YAAY,KAAK,MAAM,aAAa,SAAS,CAAC;EACzF;EACA,YAAoB,KAAK,YAAY,GAAG;CACzC;CAGA,wBAAwB;EACvB,OAAO,KAAK,iBAAiB,IAAI,MAAM,GAAG,CAAC;CAC5C;CAEA,aAAa;EACZ,OAAO,CAAC,GAAG,CAAC;CACb;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,oBAAoB;EAEvC,MAAM,QAAQ,sBAAsB;CACrC;AACD"}
@@ -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())._round(), this._map.latLngToLayerPoint(this._bounds.getSouthEast())._round()), size = bounds.getSize();
229
+ const image = this._image, map = this._map, bounds = new Bounds(map._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getNorthWest())), map._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getSouthEast()))), 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`;
@@ -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\t\t\tthis._updateZIndex();\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().append(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 != null) {\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 (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 != 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\t// like on paths, popups open where the overlay was clicked, so another click moves them\n\t_togglesPopupOnClick() {\n\t\treturn false;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,eAAb,MAAa,qBAAqB,MAAM;CAEvC,OAAO,iBAAiB;EACvB,SAAS;EACT,KAAK;EACL,aAAa;EACb,aAAa;EACb,iBAAiB;EACj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qB,KAAK,QAAQ,QAAQ,KAAK;CAChD;CAEA,SAAS;EACR,MAAM,QAAQ,KAAK,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,UAAU,MACzC,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;CAGA,uBAAuB;EACtB,OAAO;CACR;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\t\t\tthis._updateZIndex();\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().append(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 != null) {\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 (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\tmap = this._map,\n\t\tbounds = new Bounds(\n\t\t\tmap._snapLayerPoint(map.latLngToLayerPoint(this._bounds.getNorthWest())),\n\t\t\tmap._snapLayerPoint(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 != 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\t// like on paths, popups open where the overlay was clicked, so another click moves them\n\t_togglesPopupOnClick() {\n\t\treturn false;\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;GAChB,KAAK,cAAc;GAEnB,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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Q;CAC7C;CAEA,gBAAgB;EACf,IAAI,KAAK,UAAU,KAAK,QAAQ,UAAU,MACzC,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;CAGA,uBAAuB;EACtB,OAAO;CACR;AACD"}
@@ -142,7 +142,7 @@ const mapLayerMethods = {
142
142
  this._layersMaxZoom = maxZoom === -Infinity ? void 0 : maxZoom;
143
143
  this._layersMinZoom = minZoom === Infinity ? void 0 : minZoom;
144
144
  if (oldZoomSpan !== this._getZoomSpan()) this.fire("zoomlevelschange");
145
- if (this.options.maxZoom === void 0 && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) this.setZoom(this._layersMaxZoom);
145
+ if (this.options.maxZoom === void 0 && this._layersMaxZoom !== void 0 && this.getZoom() > this._layersMaxZoom) this.setZoom(this._layersMaxZoom);
146
146
  if (this.options.minZoom === void 0 && this._layersMinZoom && this.getZoom() < this._layersMinZoom) this.setZoom(this._layersMinZoom);
147
147
  }
148
148
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Layer.js","names":["Util.stamp"],"sources":["../../../src/layer/Layer.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as Util from '../core/Util.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LayerGroup} from './LayerGroup.js' */\n/** @import {EventListener, MaplairEvent, MaplairPointerEvent, LayerEvent} from '../core/Events.js' */\n\n/**\n * Options of `Layer`, inherited by all layers.\n * @typedef {object} LayerOptions\n * @property {string} [pane='overlayPane'] By default the layer will be added to the\n * map's [overlay pane](#map-pane) (`overlayPane`). Overriding this option will cause the layer\n * to be placed on another pane by default. Not effective if the `renderer` option is\n * set (the `renderer` option will override the `pane` option).\n * @property {string|null} [attribution=null] String to be shown in the attribution\n * control, e.g. \"© OpenStreetMap contributors\". It describes the layer data and is\n * often a legal obligation towards copyright holders and tile providers.\n * @property {number} [attributionOrder=0] The position of the attribution in the\n * attribution control: attributions are sorted by it, then by the order of adding,\n * e.g. `1` keeps a legend last.\n */\n\n/**\n * Options of interactive layers. Some layers can be made interactive - when the user\n * interacts with such a layer, pointer events like `click` and `pointerover` can be\n * handled. Use the [event handling methods](#evented-method) to handle these events.\n * @typedef {object} InteractiveLayerOptions\n * @property {boolean} [interactive=true] If `false`, the layer will not emit pointer\n * events and will act as a part of the underlying map.\n * @property {boolean} [bubblingPointerEvents=true] When `true`, a pointer event on this\n * layer will trigger the same event on the map (unless\n * [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).\n * @extends LayerOptions\n * @fires Layer#click {MaplairPointerEvent} Fired when the user clicks (or taps) the\n * layer, if it is interactive.\n * @fires Layer#dblclick {MaplairPointerEvent} Fired when the user double-clicks (or\n * double-taps) the layer, if it is interactive.\n * @fires Layer#pointerdown {MaplairPointerEvent} Fired when the user pushes the pointer\n * on the layer, if it is interactive.\n * @fires Layer#pointerup {MaplairPointerEvent} Fired when the user releases the pointer\n * pushed on the layer, if it is interactive.\n * @fires Layer#pointerover {MaplairPointerEvent} Fired when the pointer enters the\n * layer, if it is interactive.\n * @fires Layer#pointerout {MaplairPointerEvent} Fired when the pointer leaves the layer,\n * if it is interactive.\n * @fires Layer#contextmenu {MaplairPointerEvent} Fired when the user right-clicks on\n * the layer, if it is interactive; prevents default browser context menu from showing\n * if there are listeners on this event. Also fired on mobile when the user holds a\n * single touch for a second (also called long press).\n */\n\n/**\n * Methods of `MaplairMap` for layers.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#layeradd {LayerEvent} Fired when a new layer is added to the map.\n * @fires MaplairMap#layerremove {LayerEvent} Fired when some layer is removed from the map.\n * @fires MaplairMap#zoomlevelschange {MaplairEvent} Fired when the number of zoomlevels\n * on the map is changed due to adding or removing a layer.\n */\nconst mapLayerMethods = {\n\t/**\n\t * Adds the given layer to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (!layer._layerAdd) {\n\t\t\tthrow new Error('The provided object is not a Layer.');\n\t\t}\n\n\t\tconst id = Util.stamp(layer);\n\t\tif (this._layers[id]) { return this; }\n\t\tthis._layers[id] = layer;\n\n\t\tlayer._mapToAdd = this;\n\n\t\tif (layer.beforeAdd) {\n\t\t\tlayer.beforeAdd(this);\n\t\t}\n\n\t\tthis.whenReady(layer._layerAdd, layer);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given layer from the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (!this._layers[id]) { return this; }\n\n\t\tif (this._loaded) {\n\t\t\tlayer.onRemove(this);\n\t\t}\n\n\t\tdelete this._layers[id];\n\n\t\tif (this._loaded) {\n\t\t\tthis.fire('layerremove', {layer});\n\t\t\tlayer.fire('remove');\n\t\t}\n\n\t\tlayer._map = layer._mapToAdd = null;\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the given layer is currently added to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {boolean}\n\t */\n\thasLayer(layer) {\n\t\treturn Util.stamp(layer) in this._layers;\n\t},\n\n\t/**\n\t * Iterates over the layers of the map, optionally specifying context of the iterator function.\n\t * ```js\n\t * map.eachLayer(function(layer){\n\t * layer.bindPopup('Hello');\n\t * });\n\t * ```\n\t * @group Methods for layers and controls\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_addLayers(layers) {\n\t\tlayers = layers ? (Array.isArray(layers) ? layers : [layers]) : [];\n\n\t\tfor (const layer of layers) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\t},\n\n\t_addZoomLimit(layer) {\n\t\tif (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) {\n\t\t\tthis._zoomBoundLayers[Util.stamp(layer)] = layer;\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_removeZoomLimit(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (this._zoomBoundLayers[id]) {\n\t\t\tdelete this._zoomBoundLayers[id];\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_updateZoomLevels() {\n\t\tlet minZoom = Infinity,\n\t\tmaxZoom = -Infinity;\n\t\tconst oldZoomSpan = this._getZoomSpan();\n\n\t\tfor (const l of Object.values(this._zoomBoundLayers)) {\n\t\t\tconst options = l.options;\n\t\t\tif (options.minZoom != null && !Number.isNaN(options.minZoom)) {\n\t\t\t\tminZoom = Math.min(minZoom, options.minZoom);\n\t\t\t}\n\t\t\tif (options.maxZoom != null && !Number.isNaN(options.maxZoom)) {\n\t\t\t\tmaxZoom = Math.max(maxZoom, options.maxZoom);\n\t\t\t}\n\t\t}\n\n\t\tthis._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;\n\t\tthis._layersMinZoom = minZoom === Infinity ? undefined : minZoom;\n\n\t\tif (oldZoomSpan !== this._getZoomSpan()) {\n\t\t\tthis.fire('zoomlevelschange');\n\t\t}\n\n\t\tif (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) {\n\t\t\tthis.setZoom(this._layersMaxZoom);\n\t\t}\n\t\tif (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {\n\t\t\tthis.setZoom(this._layersMinZoom);\n\t\t}\n\t}\n};\n/** @typedef {typeof mapLayerMethods} MapLayerMethods */\n\n/**\n * The methods which layers implement, see `Layer`.\n * @typedef {object} LayerExtensionMethods\n * @property {(map: MaplairMap) => void} [onAdd] Should contain code that creates DOM\n * elements for the layer, adds them to `map panes` where they should belong and puts\n * listeners on relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the layer's elements from the DOM and removes listeners previously added in\n * `onAdd`. Called on [`map.removeLayer(layer)`](#map-removelayer).\n * @property {() => Record<string, Function>} [getEvents] Should return an object\n * like `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * @property {() => HTMLElement|string} [getLegend] Should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * @property {(map: MaplairMap) => void} [beforeAdd] Called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map, before\n * events are initialized, without waiting until the map is in a usable state. Use for\n * early initialization only.\n * @lends Layer\n */\n\n/**\n * The base class of all Maplair layers, with the methods they share.\n *\n * Every layer should extend from `Layer` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): this` should contain code that creates DOM elements for\n * the layer, adds them to `map panes` where they should belong and puts listeners on\n * relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * * `onRemove(map: MaplairMap): this` should contain all clean up code that removes the\n * layer's elements from the DOM and removes listeners previously added in `onAdd`.\n * Called on [`map.removeLayer(layer)`](#map-removelayer).\n * * `getEvents(): Object` (optional) should return an object like\n * `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * * `getAttribution(): String` (optional) should return a string containing HTML to be\n * shown on the `Attribution control` whenever the layer is visible.\n * * `getLegend(): HTMLElement|String` (optional) should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * * `beforeAdd(map: MaplairMap): this` (optional) is called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map,\n * before events are initialized, without waiting until the map is in a usable state.\n * Use for early initialization only.\n *\n * @example\n * ```js\n * const layer = new Marker(latlng).addTo(map);\n * layer.addTo(map);\n * layer.remove();\n * ```\n *\n * @fires add {MaplairEvent} Fired after the layer is added to a map.\n * @fires remove {MaplairEvent} Fired after the layer is removed from a map.\n */\nexport class Layer extends Evented {\n\n\tstatic defaultOptions = {\n\t\tpane: 'overlayPane',\n\t\tattribution: null,\n\t\tattributionOrder: 0,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Adds the layer to the given map or layer group.\n\t * @param {MaplairMap|LayerGroup} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tmap.addLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the layer from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\treturn this.removeFrom(this._map || this._mapToAdd);\n\t}\n\n\t/**\n\t * Removes the layer from the given map or `LayerGroup`.\n\t * @param {MaplairMap|LayerGroup} obj\n\t * @returns {this}\n\t */\n\tremoveFrom(obj) {\n\t\tobj?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the `HTMLElement` representing the named pane on the map. If `name` is\n\t * omitted, returns the pane for this layer.\n\t * @param {string} [name]\n\t * @returns {HTMLElement}\n\t */\n\tgetPane(name) {\n\t\treturn this._map.getPane(name ? (this.options[name] || name) : this.options.pane);\n\t}\n\n\t/**\n\t * Changes the [`interactive`](#interactivelayeroptions-interactive) option of the\n\t * layer, e.g. to stop a layer from emitting pointer events while it is being edited.\n\t * @param {boolean} interactive\n\t * @returns {this}\n\t */\n\tsetInteractive(interactive) {\n\t\tinteractive = !!interactive;\n\t\tif (this.options.interactive !== interactive) {\n\t\t\tUtil.setOptions(this, {interactive});\n\t\t\tif (this._map) {\n\t\t\t\tthis._updateInteractive();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Applies a changed `interactive` option to a layer on the map, see `setInteractive()`.\n\t_updateInteractive() {}\n\n\t/**\n\t * Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and\n\t * keyboard events on it (or its descendants) fire on the layer and bubble through its\n\t * parent groups to the map, the way they do for markers and paths. Custom layers call\n\t * it in [`onAdd`](#layer-onadd), once the layer is on a map.\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\taddInteractiveTarget(targetEl) {\n\t\tthis._map._targets[Util.stamp(targetEl)] = this;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in\n\t * [`onRemove`](#layer-onremove).\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\tremoveInteractiveTarget(targetEl) {\n\t\tdelete this._map._targets[Util.stamp(targetEl)];\n\t\treturn this;\n\t}\n\n\t// Whether clicking the layer again closes its popup, rather than moving it to the\n\t// clicked point like on paths, where the popup opens where they were clicked.\n\t_togglesPopupOnClick() {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).\n\t * @returns {string|null}\n\t */\n\tgetAttribution() {\n\t\treturn this.options.attribution;\n\t}\n\n\t/**\n\t * Changes the [attribution option](#layeroptions-attribution), also in the\n\t * attribution control while the layer is on the map.\n\t * @param {string|null} attribution\n\t * @returns {this}\n\t */\n\tsetAttribution(attribution) {\n\t\tconst control = this._map?.attributionControl;\n\t\tcontrol?._removeLayer({layer: this});\n\t\tUtil.setOptions(this, {attribution});\n\t\tcontrol?._addLayer({layer: this});\n\t\treturn this;\n\t}\n\n\t_layerAdd(e) {\n\t\tconst map = e.target;\n\n\t\t// check in case layer gets added and then removed before the map is ready\n\t\tif (!map.hasLayer(this)) { return; }\n\n\t\tthis._map = map;\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (this.getEvents) {\n\t\t\tconst events = this.getEvents();\n\t\t\tmap.on(events, this);\n\t\t\tthis.once('remove', () => map.off(events, this));\n\t\t}\n\n\t\tthis.onAdd(map);\n\n\t\tthis.fire('add');\n\t\tmap.fire('layeradd', {layer: this});\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapLayerMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,kBAAkB;;;;;;;CAOvB,SAAS,OAAO;EACf,IAAI,CAAC,MAAM,WACV,MAAM,IAAI,MAAM,qCAAqC;EAGtD,MAAM,KAAKA,MAAW,KAAK;EAC3B,IAAI,KAAK,QAAQ,KAAO,OAAO;EAC/B,KAAK,QAAQ,MAAM;EAEnB,MAAM,YAAY;EAElB,IAAI,MAAM,WACT,MAAM,UAAU,IAAI;EAGrB,KAAK,UAAU,MAAM,WAAW,KAAK;EAErC,OAAO;CACR;;;;;;;CAQA,YAAY,OAAO;EAClB,MAAM,KAAKA,MAAW,KAAK;EAE3B,IAAI,CAAC,KAAK,QAAQ,KAAO,OAAO;EAEhC,IAAI,KAAK,SACR,MAAM,SAAS,IAAI;EAGpB,OAAO,KAAK,QAAQ;EAEpB,IAAI,KAAK,SAAS;GACjB,KAAK,KAAK,eAAe,EAAC,MAAK,CAAC;GAChC,MAAM,KAAK,QAAQ;EACpB;EAEA,MAAM,OAAO,MAAM,YAAY;EAE/B,OAAO;CACR;;;;;;;CAQA,SAAS,OAAO;EACf,OAAOA,MAAW,KAAK,KAAK,KAAK;CAClC;;;;;;;;;;;;;CAcA,UAAU,QAAQ,SAAS;EAC1B,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,OAAO,KAAK,SAAS,KAAK;EAE3B,OAAO;CACR;CAEA,WAAW,QAAQ;EAClB,SAAS,SAAU,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM,IAA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,KAAK,WAAW;GACnB,MAAM,SAAS,KAAK,UAAU;GAC9B,IAAI,GAAG,QAAQ,IAAI;GACnB,KAAK,KAAK,gBAAgB,IAAI,IAAI,QAAQ,IAAI,CAAC;EAChD;EAEA,KAAK,MAAM,GAAG;EAEd,KAAK,KAAK,KAAK;EACf,IAAI,KAAK,YAAY,EAAC,OAAO,KAAI,CAAC;CACnC;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,eAAe;CACnC;AACD"}
1
+ {"version":3,"file":"Layer.js","names":["Util.stamp"],"sources":["../../../src/layer/Layer.js"],"sourcesContent":["import {Evented} from '../core/Events.js';\nimport * as Util from '../core/Util.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LayerGroup} from './LayerGroup.js' */\n/** @import {EventListener, MaplairEvent, MaplairPointerEvent, LayerEvent} from '../core/Events.js' */\n\n/**\n * Options of `Layer`, inherited by all layers.\n * @typedef {object} LayerOptions\n * @property {string} [pane='overlayPane'] By default the layer will be added to the\n * map's [overlay pane](#map-pane) (`overlayPane`). Overriding this option will cause the layer\n * to be placed on another pane by default. Not effective if the `renderer` option is\n * set (the `renderer` option will override the `pane` option).\n * @property {string|null} [attribution=null] String to be shown in the attribution\n * control, e.g. \"© OpenStreetMap contributors\". It describes the layer data and is\n * often a legal obligation towards copyright holders and tile providers.\n * @property {number} [attributionOrder=0] The position of the attribution in the\n * attribution control: attributions are sorted by it, then by the order of adding,\n * e.g. `1` keeps a legend last.\n */\n\n/**\n * Options of interactive layers. Some layers can be made interactive - when the user\n * interacts with such a layer, pointer events like `click` and `pointerover` can be\n * handled. Use the [event handling methods](#evented-method) to handle these events.\n * @typedef {object} InteractiveLayerOptions\n * @property {boolean} [interactive=true] If `false`, the layer will not emit pointer\n * events and will act as a part of the underlying map.\n * @property {boolean} [bubblingPointerEvents=true] When `true`, a pointer event on this\n * layer will trigger the same event on the map (unless\n * [`DomEvent.stopPropagation`](#domevent-stoppropagation) is used).\n * @extends LayerOptions\n * @fires Layer#click {MaplairPointerEvent} Fired when the user clicks (or taps) the\n * layer, if it is interactive.\n * @fires Layer#dblclick {MaplairPointerEvent} Fired when the user double-clicks (or\n * double-taps) the layer, if it is interactive.\n * @fires Layer#pointerdown {MaplairPointerEvent} Fired when the user pushes the pointer\n * on the layer, if it is interactive.\n * @fires Layer#pointerup {MaplairPointerEvent} Fired when the user releases the pointer\n * pushed on the layer, if it is interactive.\n * @fires Layer#pointerover {MaplairPointerEvent} Fired when the pointer enters the\n * layer, if it is interactive.\n * @fires Layer#pointerout {MaplairPointerEvent} Fired when the pointer leaves the layer,\n * if it is interactive.\n * @fires Layer#contextmenu {MaplairPointerEvent} Fired when the user right-clicks on\n * the layer, if it is interactive; prevents default browser context menu from showing\n * if there are listeners on this event. Also fired on mobile when the user holds a\n * single touch for a second (also called long press).\n */\n\n/**\n * Methods of `MaplairMap` for layers.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#layeradd {LayerEvent} Fired when a new layer is added to the map.\n * @fires MaplairMap#layerremove {LayerEvent} Fired when some layer is removed from the map.\n * @fires MaplairMap#zoomlevelschange {MaplairEvent} Fired when the number of zoomlevels\n * on the map is changed due to adding or removing a layer.\n */\nconst mapLayerMethods = {\n\t/**\n\t * Adds the given layer to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\taddLayer(layer) {\n\t\tif (!layer._layerAdd) {\n\t\t\tthrow new Error('The provided object is not a Layer.');\n\t\t}\n\n\t\tconst id = Util.stamp(layer);\n\t\tif (this._layers[id]) { return this; }\n\t\tthis._layers[id] = layer;\n\n\t\tlayer._mapToAdd = this;\n\n\t\tif (layer.beforeAdd) {\n\t\t\tlayer.beforeAdd(this);\n\t\t}\n\n\t\tthis.whenReady(layer._layerAdd, layer);\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given layer from the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (!this._layers[id]) { return this; }\n\n\t\tif (this._loaded) {\n\t\t\tlayer.onRemove(this);\n\t\t}\n\n\t\tdelete this._layers[id];\n\n\t\tif (this._loaded) {\n\t\t\tthis.fire('layerremove', {layer});\n\t\t\tlayer.fire('remove');\n\t\t}\n\n\t\tlayer._map = layer._mapToAdd = null;\n\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the given layer is currently added to the map.\n\t * @group Methods for layers and controls\n\t * @param {Layer} layer\n\t * @returns {boolean}\n\t */\n\thasLayer(layer) {\n\t\treturn Util.stamp(layer) in this._layers;\n\t},\n\n\t/**\n\t * Iterates over the layers of the map, optionally specifying context of the iterator function.\n\t * ```js\n\t * map.eachLayer(function(layer){\n\t * layer.bindPopup('Hello');\n\t * });\n\t * ```\n\t * @group Methods for layers and controls\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_addLayers(layers) {\n\t\tlayers = layers ? (Array.isArray(layers) ? layers : [layers]) : [];\n\n\t\tfor (const layer of layers) {\n\t\t\tthis.addLayer(layer);\n\t\t}\n\t},\n\n\t_addZoomLimit(layer) {\n\t\tif (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) {\n\t\t\tthis._zoomBoundLayers[Util.stamp(layer)] = layer;\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_removeZoomLimit(layer) {\n\t\tconst id = Util.stamp(layer);\n\n\t\tif (this._zoomBoundLayers[id]) {\n\t\t\tdelete this._zoomBoundLayers[id];\n\t\t\tthis._updateZoomLevels();\n\t\t}\n\t},\n\n\t_updateZoomLevels() {\n\t\tlet minZoom = Infinity,\n\t\tmaxZoom = -Infinity;\n\t\tconst oldZoomSpan = this._getZoomSpan();\n\n\t\tfor (const l of Object.values(this._zoomBoundLayers)) {\n\t\t\tconst options = l.options;\n\t\t\tif (options.minZoom != null && !Number.isNaN(options.minZoom)) {\n\t\t\t\tminZoom = Math.min(minZoom, options.minZoom);\n\t\t\t}\n\t\t\tif (options.maxZoom != null && !Number.isNaN(options.maxZoom)) {\n\t\t\t\tmaxZoom = Math.max(maxZoom, options.maxZoom);\n\t\t\t}\n\t\t}\n\n\t\tthis._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;\n\t\tthis._layersMinZoom = minZoom === Infinity ? undefined : minZoom;\n\n\t\tif (oldZoomSpan !== this._getZoomSpan()) {\n\t\t\tthis.fire('zoomlevelschange');\n\t\t}\n\n\t\tif (this.options.maxZoom === undefined && this._layersMaxZoom !== undefined && this.getZoom() > this._layersMaxZoom) {\n\t\t\tthis.setZoom(this._layersMaxZoom);\n\t\t}\n\t\tif (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {\n\t\t\tthis.setZoom(this._layersMinZoom);\n\t\t}\n\t}\n};\n/** @typedef {typeof mapLayerMethods} MapLayerMethods */\n\n/**\n * The methods which layers implement, see `Layer`.\n * @typedef {object} LayerExtensionMethods\n * @property {(map: MaplairMap) => void} [onAdd] Should contain code that creates DOM\n * elements for the layer, adds them to `map panes` where they should belong and puts\n * listeners on relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the layer's elements from the DOM and removes listeners previously added in\n * `onAdd`. Called on [`map.removeLayer(layer)`](#map-removelayer).\n * @property {() => Record<string, Function>} [getEvents] Should return an object\n * like `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * @property {() => HTMLElement|string} [getLegend] Should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * @property {(map: MaplairMap) => void} [beforeAdd] Called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map, before\n * events are initialized, without waiting until the map is in a usable state. Use for\n * early initialization only.\n * @lends Layer\n */\n\n/**\n * The base class of all Maplair layers, with the methods they share.\n *\n * Every layer should extend from `Layer` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): this` should contain code that creates DOM elements for\n * the layer, adds them to `map panes` where they should belong and puts listeners on\n * relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).\n * * `onRemove(map: MaplairMap): this` should contain all clean up code that removes the\n * layer's elements from the DOM and removes listeners previously added in `onAdd`.\n * Called on [`map.removeLayer(layer)`](#map-removelayer).\n * * `getEvents(): Object` (optional) should return an object like\n * `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your layer.\n * * `getAttribution(): String` (optional) should return a string containing HTML to be\n * shown on the `Attribution control` whenever the layer is visible.\n * * `getLegend(): HTMLElement|String` (optional) should return an element (or a string\n * containing HTML) to be shown on the `LegendControl` whenever the layer is visible.\n * Fire `legendchange` on the layer when the legend changes.\n * * `beforeAdd(map: MaplairMap): this` (optional) is called on\n * [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map,\n * before events are initialized, without waiting until the map is in a usable state.\n * Use for early initialization only.\n *\n * @example\n * ```js\n * const layer = new Marker(latlng).addTo(map);\n * layer.addTo(map);\n * layer.remove();\n * ```\n *\n * @fires add {MaplairEvent} Fired after the layer is added to a map.\n * @fires remove {MaplairEvent} Fired after the layer is removed from a map.\n */\nexport class Layer extends Evented {\n\n\tstatic defaultOptions = {\n\t\tpane: 'overlayPane',\n\t\tattribution: null,\n\t\tattributionOrder: 0,\n\t\tbubblingPointerEvents: true\n\t};\n\n\t/**\n\t * Adds the layer to the given map or layer group.\n\t * @param {MaplairMap|LayerGroup} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tmap.addLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the layer from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\treturn this.removeFrom(this._map || this._mapToAdd);\n\t}\n\n\t/**\n\t * Removes the layer from the given map or `LayerGroup`.\n\t * @param {MaplairMap|LayerGroup} obj\n\t * @returns {this}\n\t */\n\tremoveFrom(obj) {\n\t\tobj?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the `HTMLElement` representing the named pane on the map. If `name` is\n\t * omitted, returns the pane for this layer.\n\t * @param {string} [name]\n\t * @returns {HTMLElement}\n\t */\n\tgetPane(name) {\n\t\treturn this._map.getPane(name ? (this.options[name] || name) : this.options.pane);\n\t}\n\n\t/**\n\t * Changes the [`interactive`](#interactivelayeroptions-interactive) option of the\n\t * layer, e.g. to stop a layer from emitting pointer events while it is being edited.\n\t * @param {boolean} interactive\n\t * @returns {this}\n\t */\n\tsetInteractive(interactive) {\n\t\tinteractive = !!interactive;\n\t\tif (this.options.interactive !== interactive) {\n\t\t\tUtil.setOptions(this, {interactive});\n\t\t\tif (this._map) {\n\t\t\t\tthis._updateInteractive();\n\t\t\t}\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Applies a changed `interactive` option to a layer on the map, see `setInteractive()`.\n\t_updateInteractive() {}\n\n\t/**\n\t * Registers `targetEl`, one of the layer's DOM elements, so that pointer, click and\n\t * keyboard events on it (or its descendants) fire on the layer and bubble through its\n\t * parent groups to the map, the way they do for markers and paths. Custom layers call\n\t * it in [`onAdd`](#layer-onadd), once the layer is on a map.\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\taddInteractiveTarget(targetEl) {\n\t\tthis._map._targets[Util.stamp(targetEl)] = this;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Undoes [`addInteractiveTarget`](#layer-addinteractivetarget), typically in\n\t * [`onRemove`](#layer-onremove).\n\t * @param {HTMLElement} targetEl\n\t * @returns {this}\n\t */\n\tremoveInteractiveTarget(targetEl) {\n\t\tdelete this._map._targets[Util.stamp(targetEl)];\n\t\treturn this;\n\t}\n\n\t// Whether clicking the layer again closes its popup, rather than moving it to the\n\t// clicked point like on paths, where the popup opens where they were clicked.\n\t_togglesPopupOnClick() {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Used by the `attribution control`, returns the [attribution option](#layeroptions-attribution).\n\t * @returns {string|null}\n\t */\n\tgetAttribution() {\n\t\treturn this.options.attribution;\n\t}\n\n\t/**\n\t * Changes the [attribution option](#layeroptions-attribution), also in the\n\t * attribution control while the layer is on the map.\n\t * @param {string|null} attribution\n\t * @returns {this}\n\t */\n\tsetAttribution(attribution) {\n\t\tconst control = this._map?.attributionControl;\n\t\tcontrol?._removeLayer({layer: this});\n\t\tUtil.setOptions(this, {attribution});\n\t\tcontrol?._addLayer({layer: this});\n\t\treturn this;\n\t}\n\n\t_layerAdd(e) {\n\t\tconst map = e.target;\n\n\t\t// check in case layer gets added and then removed before the map is ready\n\t\tif (!map.hasLayer(this)) { return; }\n\n\t\tthis._map = map;\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (this.getEvents) {\n\t\t\tconst events = this.getEvents();\n\t\t\tmap.on(events, this);\n\t\t\tthis.once('remove', () => map.off(events, this));\n\t\t}\n\n\t\tthis.onAdd(map);\n\n\t\tthis.fire('add');\n\t\tmap.fire('layeradd', {layer: this});\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapLayerMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,kBAAkB;;;;;;;CAOvB,SAAS,OAAO;EACf,IAAI,CAAC,MAAM,WACV,MAAM,IAAI,MAAM,qCAAqC;EAGtD,MAAM,KAAKA,MAAW,KAAK;EAC3B,IAAI,KAAK,QAAQ,KAAO,OAAO;EAC/B,KAAK,QAAQ,MAAM;EAEnB,MAAM,Y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7C,WAAgB,MAAM,EAAC,YAAW,CAAC;GACnC,IAAI,KAAK,MACR,KAAK,mBAAmB;EAE1B;EACA,OAAO;CACR;CAGA,qBAAqB,CAAC;;;;;;;;;CAUtB,qBAAqB,UAAU;EAC9B,KAAK,KAAK,SAASA,MAAW,QAAQ,KAAK;EAC3C,OAAO;CACR;;;;;;;CAQA,wBAAwB,UAAU;EACjC,OAAO,KAAK,KAAK,SAASA,MAAW,QAAQ;EAC7C,OAAO;CACR;CAIA,uBAAuB;EACtB,OAAO;CACR;;;;;CAMA,iBAAiB;EAChB,OAAO,KAAK,QAAQ;CACrB;;;;;;;CAQA,eAAe,aAAa;EAC3B,MAAM,UAAU,KAAK,MAAM;EAC3B,SAAS,aAAa,EAAC,OAAO,KAAI,CAAC;EACnC,WAAgB,MAAM,EAAC,YAAW,CAAC;EACnC,SAAS,UAAU,EAAC,OAAO,KAAI,CAAC;EAChC,OAAO;CACR;CAEA,UAAU,GAAG;EACZ,MAAM,MAAM,EAAE;EAGd,IAAI,CAAC,IAAI,SAAS,IAAI,GAAK;EAE3B,KAAK,OAAO;EACZ,KAAK,gBAAgB,IAAI;EAEzB,IAAI,KAAK,WAAW;GACnB,MAAM,SAAS,KAAK,UAAU;GAC9B,IAAI,GAAG,QAAQ,IAAI;GACnB,KAAK,KAAK,gBAAgB,IAAI,IAAI,QAAQ,IAAI,CAAC;EAChD;EAEA,KAAK,MAAM,GAAG;EAEd,KAAK,KAAK,KAAK;EACf,IAAI,KAAK,YAAY,EAAC,OAAO,KAAI,CAAC;CACnC;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,eAAe;CACnC;AACD"}
@@ -116,8 +116,8 @@ const layerPopupMethods = {
116
116
  /**
117
117
  * Binds a popup to the layer with the passed `content` and sets up the
118
118
  * necessary event listeners. A `String` argument is rendered as HTML; if it
119
- * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
120
- * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
119
+ * may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
120
+ * `textContent` instead. If a `Function` is passed
121
121
  * it will receive the layer as the first argument and should return a
122
122
  * `String`, `HTMLElement` or `DocumentFragment`.
123
123
  * @group Popup methods
@@ -259,8 +259,7 @@ const layerPopupMethods = {
259
259
  *
260
260
  * **Security note.** Popup string content is rendered as HTML. If your content
261
261
  * may include untrusted input (e.g. data from users or external APIs), sanitize
262
- * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or
263
- * build a DOM element using `textContent` to render it as plain text:
262
+ * it first, or build a DOM element using `textContent` to render it as plain text:
264
263
  *
265
264
  * ```js
266
265
  * const el = document.createElement('div');
@@ -1 +1 @@
1
- {"version":3,"file":"Popup.js","names":["DomEvent.stopPropagation","DomUtil.create","Util.stamp"],"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 * as Util from '../core/Util.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.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`, `HTMLElement` or `DocumentFragment`.\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._popup._updateSourceAria(this._popup.isOpen());\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\tconst el = this.getElement?.();\n\t\t\tel?.removeAttribute('aria-expanded');\n\t\t\tel?.removeAttribute('aria-controls');\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\t// clicking a marker-like source again toggles its popup closed\n\t\tif (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {\n\t\t\tthis.closePopup();\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?.options.autoClose) {\n\t\t\tmap.removeLayer(map._popup);\n\t\t}\n\t\tmap._popup = this;\n\n\t\tsuper.openOn(map);\n\t\tthis._updateSourceAria(true); // the source may have changed while open, e.g. within a FeatureGroup\n\t\treturn this;\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\t\tthis._updateSourceAria(true);\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._togglesPopupOnClick()) {\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\t// closing removes the focused element, which would send focus back to the start of the page\n\t\tif (this._container.contains(document.activeElement)) {\n\t\t\tconst el = this._source?.getElement?.();\n\t\t\tconst target = this._returnFocus?.isConnected ? this._returnFocus :\n\t\t\t\tel?.tabIndex >= 0 ? el : map._container;\n\t\t\ttarget.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\t\tthis._updateSourceAria(false);\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupclose', {popup: this}, true);\n\t\t\tif (this._source._togglesPopupOnClick()) {\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// Marks a source that acts as a button (e.g. a keyboard-accessible marker) as a\n\t// disclosure for the popup.\n\t_updateSourceAria(open) {\n\t\tthis._ariaSource?.setAttribute('aria-expanded', 'false');\n\t\tthis._ariaSource?.removeAttribute('aria-controls');\n\n\t\tconst el = this._source?.getElement?.();\n\t\tthis._ariaSource = el?.getAttribute('role') === 'button' ? el : null;\n\t\tthis._ariaSource?.setAttribute('aria-expanded', String(open));\n\t\tif (open) { this._ariaSource?.setAttribute('aria-controls', this._container.id); }\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\tcontainer.id = `maplair-popup-${Util.stamp(this)}`;\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.textContent = '\\u00D7';\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(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,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
+ {"version":3,"file":"Popup.js","names":["DomEvent.stopPropagation","DomUtil.create","Util.stamp"],"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 * as Util from '../core/Util.js';\nimport {Point} from '../geometry/Point.js';\nimport {Layer} from './Layer.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 or pass an `HTMLElement` with safe\n\t * `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`, `HTMLElement` or `DocumentFragment`.\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._popup._updateSourceAria(this._popup.isOpen());\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\tconst el = this.getElement?.();\n\t\t\tel?.removeAttribute('aria-expanded');\n\t\t\tel?.removeAttribute('aria-controls');\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\t// clicking a marker-like source again toggles its popup closed\n\t\tif (this._popup._source === target && target._togglesPopupOnClick() && this._map.hasLayer(this._popup)) {\n\t\t\tthis.closePopup();\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 first, or 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?.options.autoClose) {\n\t\t\tmap.removeLayer(map._popup);\n\t\t}\n\t\tmap._popup = this;\n\n\t\tsuper.openOn(map);\n\t\tthis._updateSourceAria(true); // the source may have changed while open, e.g. within a FeatureGroup\n\t\treturn this;\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\t\tthis._updateSourceAria(true);\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._togglesPopupOnClick()) {\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\t// closing removes the focused element, which would send focus back to the start of the page\n\t\tif (this._container.contains(document.activeElement)) {\n\t\t\tconst el = this._source?.getElement?.();\n\t\t\tconst target = this._returnFocus?.isConnected ? this._returnFocus :\n\t\t\t\tel?.tabIndex >= 0 ? el : map._container;\n\t\t\ttarget.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\t\tthis._updateSourceAria(false);\n\n\t\tif (this._source) {\n\t\t\tthis._source.fire('popupclose', {popup: this}, true);\n\t\t\tif (this._source._togglesPopupOnClick()) {\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// Marks a source that acts as a button (e.g. a keyboard-accessible marker) as a\n\t// disclosure for the popup.\n\t_updateSourceAria(open) {\n\t\tthis._ariaSource?.setAttribute('aria-expanded', 'false');\n\t\tthis._ariaSource?.removeAttribute('aria-controls');\n\n\t\tconst el = this._source?.getElement?.();\n\t\tthis._ariaSource = el?.getAttribute('role') === 'button' ? el : null;\n\t\tthis._ariaSource?.setAttribute('aria-expanded', String(open));\n\t\tif (open) { this._ariaSource?.setAttribute('aria-controls', this._container.id); }\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\tcontainer.id = `maplair-popup-${Util.stamp(this)}`;\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.textContent = '\\u00D7';\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,OAAO,kBAAkB,KAAK,OAAO,OAAO,CAAC;EAClD,KAAK,GAAG;GACP,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,MAAM,KAAK;EACZ,CAAC;EAED,OAAO;CACR;;;;;;CAOA,cAAc;EACb,IAAI,KAAK,QAAQ;GAChB,KAAK,IAAI;IACR,OAAO,KAAK;IACZ,QAAQ,KAAK;IACb,M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AAgB,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"}
@@ -31,7 +31,8 @@ function clampTip(tipShift, size) {
31
31
  * Options of `Tooltip`.
32
32
  * @typedef {object} TooltipOptions
33
33
  * @property {string} [pane='tooltipPane'] `Map pane` where the tooltip will be added.
34
- * @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position.
34
+ * @property {PointExpression} [offset=[0, 0]] Optional offset of the tooltip position, in
35
+ * pixels. Mirrored horizontally when an `auto` tooltip opens to the left.
35
36
  * @property {'right'|'left'|'top'|'bottom'|'center'|'auto'} [direction='auto']
36
37
  * Direction where to open the tooltip. Possible values are: `right`, `left`, `top`,
37
38
  * `bottom`, `center`, `auto`. `auto` chooses the direction with enough space when
@@ -102,8 +103,8 @@ const layerTooltipMethods = {
102
103
  /**
103
104
  * Binds a tooltip to the layer with the passed `content` and sets up the
104
105
  * necessary event listeners. A `String` argument is rendered as HTML; if it
105
- * may contain untrusted input, sanitize it (e.g. with DOMPurify) or pass an
106
- * `HTMLElement` with safe `textContent` instead. If a `Function` is passed
106
+ * may contain untrusted input, sanitize it or pass an `HTMLElement` with safe
107
+ * `textContent` instead. If a `Function` is passed
107
108
  * it will receive the layer as the first argument and should return a
108
109
  * `String`, `HTMLElement` or `DocumentFragment`.
109
110
  * @group Tooltip methods
@@ -277,8 +278,7 @@ const layerTooltipMethods = {
277
278
  *
278
279
  * **Security note.** Tooltip string content is rendered as HTML. If your content
279
280
  * may include untrusted input (e.g. data from users or external APIs), sanitize
280
- * it with a library like [DOMPurify](https://github.com/cure53/DOMPurify), or
281
- * build a DOM element using `textContent` to render it as plain text:
281
+ * it first, or build a DOM element using `textContent` to render it as plain text:
282
282
  *
283
283
  * ```js
284
284
  * const el = document.createElement('div');
@@ -335,7 +335,8 @@ var Tooltip = class Tooltip extends DivOverlay {
335
335
  map.fire("tooltipopen", { tooltip: this });
336
336
  if (this._source) {
337
337
  this.addEventParent(this._source);
338
- this._source.getElement?.()?.setAttribute("aria-describedby", this._container.id);
338
+ this._ariaSource = this._source.getElement?.();
339
+ this._ariaSource?.setAttribute("aria-describedby", this._container.id);
339
340
  this._source.fire("tooltipopen", { tooltip: this }, true);
340
341
  }
341
342
  }
@@ -348,6 +349,9 @@ var Tooltip = class Tooltip extends DivOverlay {
348
349
  map.fire("tooltipclose", { tooltip: this });
349
350
  if (this._source) {
350
351
  this.removeEventParent(this._source);
352
+ const el = this._ariaSource;
353
+ if (el?.getAttribute("aria-describedby") === this._container.id) el.removeAttribute("aria-describedby");
354
+ this._ariaSource = null;
351
355
  this._source.fire("tooltipclose", { tooltip: this }, true);
352
356
  }
353
357
  }
@@ -378,14 +382,12 @@ var Tooltip = class Tooltip extends DivOverlay {
378
382
  }
379
383
  _setPosition(pos) {
380
384
  let direction = this.options.direction, shift = new Point(0, 0);
381
- const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset), anchor = this._getAnchor();
385
+ const container = this._container, tooltipWidth = container.offsetWidth, tooltipHeight = container.offsetHeight, offset = new Point(this.options.offset);
382
386
  if (!(direction in directions)) {
383
- ({direction, shift} = this._getAutoPlacement(pos, offset, anchor, tooltipWidth, tooltipHeight));
384
- if (direction === "left") {
385
- offset.x = -offset.x;
386
- anchor.x = -anchor.x;
387
- }
387
+ ({direction, shift} = this._getAutoPlacement(pos, offset, tooltipWidth, tooltipHeight));
388
+ if (direction === "left") offset.x = -offset.x;
388
389
  }
390
+ const anchor = this._getAnchor(direction);
389
391
  const [fx, fy] = directions[direction];
390
392
  pos = pos.subtract(new Point(tooltipWidth * fx, tooltipHeight * fy, true)).add(offset).add(anchor).add(shift);
391
393
  for (const d in directions) container.classList.toggle(`maplair-tooltip-${d}`, d === direction);
@@ -394,12 +396,19 @@ var Tooltip = class Tooltip extends DivOverlay {
394
396
  else container.style.removeProperty("--maplair-tooltip-tip-shift");
395
397
  this._setContainerPosition(pos);
396
398
  }
397
- _getAutoPlacement(pos, offset, anchor, width, height) {
398
- const area = this._getAutoArea(), point = this._map.layerPointToContainerPoint(pos), x = point.x + offset.x + anchor.x, y = point.y + offset.y + anchor.y, space = {
399
- right: area.max.x - x - width - tipSize,
400
- left: point.x - offset.x - anchor.x - area.min.x - width - tipSize,
401
- top: y - area.min.y - height - tipSize,
402
- bottom: area.max.y - y - height - tipSize
399
+ _getAutoPlacement(pos, offset, width, height) {
400
+ const area = this._getAutoArea(), point = this._map.layerPointToContainerPoint(pos), at = {};
401
+ for (const d of [
402
+ "right",
403
+ "left",
404
+ "top",
405
+ "bottom"
406
+ ]) at[d] = point.add(this._getAnchor(d)).add(d === "left" ? [-offset.x, offset.y] : offset);
407
+ const space = {
408
+ right: area.max.x - at.right.x - width - tipSize,
409
+ left: at.left.x - area.min.x - width - tipSize,
410
+ top: at.top.y - area.min.y - height - tipSize,
411
+ bottom: area.max.y - at.bottom.y - height - tipSize
403
412
  };
404
413
  if (!this._autoDirection) {
405
414
  const sides = point.x < (area.min.x + area.max.x) / 2 ? ["right", "left"] : ["left", "right"], fallback = space.right >= space.left ? "right" : "left";
@@ -409,7 +418,7 @@ var Tooltip = class Tooltip extends DivOverlay {
409
418
  "bottom"
410
419
  ].find((d) => space[d] >= 0 && (d === "right" || d === "left" || width <= area.max.x - area.min.x)) ?? fallback;
411
420
  }
412
- const direction = this._autoDirection;
421
+ const direction = this._autoDirection, { x, y } = at[direction];
413
422
  return {
414
423
  direction,
415
424
  shift: direction === "top" || direction === "bottom" ? new Point(shiftInto(x - width / 2, width, area.min.x, area.max.x), 0) : new Point(0, shiftInto(y - height / 2, height, area.min.y, area.max.y))
@@ -430,7 +439,7 @@ var Tooltip = class Tooltip extends DivOverlay {
430
439
  };
431
440
  }
432
441
  _updatePosition() {
433
- const pos = this._map.latLngToLayerPoint(this._latlng)._round();
442
+ const pos = this._map._snapLayerPoint(this._map.latLngToLayerPoint(this._latlng));
434
443
  this._setPosition(pos);
435
444
  }
436
445
  /**
@@ -446,8 +455,8 @@ var Tooltip = class Tooltip extends DivOverlay {
446
455
  const pos = this._map._latLngToNewLayerPoint(this._latlng, e.zoom, e.center);
447
456
  this._setPosition(pos);
448
457
  }
449
- _getAnchor() {
450
- return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]);
458
+ _getAnchor(direction) {
459
+ return new Point(this._source?._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor(direction) : [0, 0]);
451
460
  }
452
461
  /**
453
462
  * Registers this default feature on the map class, called by `MaplairMap` itself.