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":"MapSync.js","names":[],"sources":["../../../src/map/MapSync.js"],"sourcesContent":["/** @import {MaplairMap} from './Map.js' */\n\n/**\n * Options of `MapSync`.\n * @typedef {object} MapSyncOptions\n * @property {boolean} [bearing=true] Whether to synchronize the bearing of rotated maps\n * (with the map rotation, see `MaplairMap.setBearing()`).\n * @property {boolean} [oneWay=false] Whether only the first map leads and the other\n * maps follow it, without moving the first map when they are moved.\n * @property {'center'|'bounds'} [fit='center'] How the maps follow: `'center'` with the\n * same center and zoom, or `'bounds'` with the same center, zoomed so that the bounds\n * of the leading map fit (like `fitBounds()`), for maps of different sizes.\n */\n\n/**\n * Synchronizes the views (center, zoom and bearing) of several maps, e.g. to\n * compare different layers side by side: whenever one of the maps moves (by the\n * user or by code, including animations), the other maps follow.\n *\n * With the options `oneWay` and `fit: 'bounds'`, smaller maps can follow a main\n * map showing its bounds, e.g. thumbnails next to it.\n *\n * Inspired by the [Leaflet.Sync](https://github.com/jieter/Leaflet.Sync) plugin.\n *\n * @example\n * ```js\n * const sync = new MapSync([map1, map2]);\n * // later\n * sync.remove();\n *\n * // a thumbnail showing the bounds of the main map\n * new MapSync([map, thumbnail], {oneWay: true, fit: 'bounds'});\n * ```\n */\nexport class MapSync {\n\t/**\n\t * Synchronizes the views of the given maps, starting with the view of the first map.\n\t * @param {MaplairMap[]} maps\n\t * @param {MapSyncOptions} [options]\n\t */\n\tconstructor(maps, options) {\n\t\t/** @type {MapSyncOptions} */\n\t\tthis.options = {\n\t\t\tbearing: true,\n\t\t\toneWay: false,\n\t\t\tfit: 'center',\n\t\t\t...options\n\t\t};\n\t\tthis._maps = [...maps];\n\t\tthis._listeners = new Map();\n\t\tthis._animating = new Set();\n\t\t// following maps which ended their zoom animation already\n\t\tthis._ended = new Set();\n\n\t\tfor (const map of this._maps) {\n\t\t\tconst listeners = {\n\t\t\t\tmovestart: () => this._onMoveStart(map),\n\t\t\t\tzoomstart: () => this._onZoomStart(map),\n\t\t\t\tmove: () => this._onMove(map),\n\t\t\t\tzoomanim: e => this._onZoomAnim(map, e),\n\t\t\t\tmoveend: () => this._onMoveEnd(map),\n\t\t\t\trotate: () => this._onRotate(map)\n\t\t\t};\n\t\t\tmap.on(listeners);\n\t\t\tthis._listeners.set(map, listeners);\n\t\t}\n\n\t\tif (this._maps[0]?._loaded) {\n\t\t\tthis._syncAll(this._maps[0]);\n\t\t}\n\t}\n\n\t/**\n\t * Stops synchronizing the maps.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\tfor (const [map, listeners] of this._listeners) {\n\t\t\tmap.off(listeners);\n\t\t}\n\t\tthis._listeners.clear();\n\t\tthis._maps = [];\n\t\treturn this;\n\t}\n\n\t// The other maps, which follow `map`\n\t_followers(map) {\n\t\treturn this._maps.filter(m => m !== map && m._loaded);\n\t}\n\n\t// Whether `map` may lead, see the `oneWay` option\n\t_canLead(map) {\n\t\treturn !this.options.oneWay || map === this._maps[0];\n\t}\n\n\t// The zoom of `other` following `map` at `zoom`, see the `fit` option; snapped to\n\t// the `zoomSnap` of `other` at the `end` of a movement\n\t_zoomFor(other, map, zoom = map.getZoom(), end = true) {\n\t\tconst size = other.getSize(),\n\t\tleaderSize = map.getSize();\n\t\tif (this.options.fit !== 'bounds' || !size.x || !size.y || !leaderSize.x || !leaderSize.y) { return zoom; }\n\t\tlet z = zoom + Math.log2(Math.min(size.x / leaderSize.x, size.y / leaderSize.y));\n\t\tconst snap = other.options.zoomSnap;\n\t\tif (end && snap) {\n\t\t\t// down, so that the bounds fit\n\t\t\tz = Math.floor(z / snap + 1e-6) * snap;\n\t\t}\n\t\treturn Math.max(other.getMinZoom(), Math.min(other.getMaxZoom(), z));\n\t}\n\n\t// A map starting to move leads until it (and all following animations) ended,\n\t// the events of the following maps are ignored meanwhile.\n\t_onMoveStart(map) {\n\t\tif (this._leader || !this._canLead(map)) { return; }\n\t\tthis._leader = map;\n\t\tthis._leaderEnded = false;\n\t\tthis._ended.clear();\n\t\tfor (const other of this._followers(map)) {\n\t\t\tother._stop();\n\t\t\tother._syncStartZoom = other.getZoom();\n\t\t\tother.fire('movestart');\n\t\t}\n\t}\n\n\t_onZoomStart(map) {\n\t\t// `_resetView()` fires zoomstart before movestart\n\t\tthis._onMoveStart(map);\n\t\tif (this._leader !== map) { return; }\n\t\tfor (const other of this._followers(map)) {\n\t\t\tother.fire('zoomstart');\n\t\t}\n\t}\n\n\t_onMove(map) {\n\t\tif (!this._leader) {\n\t\t\t// e.g. invalidateSize(), which fires move without movestart\n\t\t\tif (this._canLead(map)) {\n\t\t\t\tthis._syncAll(map);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this._leader !== map) { return; }\n\t\tfor (const other of this._followers(map)) {\n\t\t\tif (!this._animating.has(other)) {\n\t\t\t\tthis._follow(other, map, true);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Mirrors the CSS zoom animation, the following map ends it itself\n\t_onZoomAnim(map, e) {\n\t\tif (this._leader !== map) { return; }\n\t\tfor (const other of this._followers(map)) {\n\t\t\tif (other._zoomAnimated) {\n\t\t\t\tthis._animating.add(other);\n\t\t\t\tother._animateZoom(e.center, this._zoomFor(other, map, e.zoom), true, e.noUpdate);\n\t\t\t}\n\t\t}\n\t}\n\n\t_onMoveEnd(map) {\n\t\tif (this._leader !== map) {\n\t\t\t// the end of a following zoom animation\n\t\t\tif (this._animating.delete(map)) {\n\t\t\t\tthis._ended.add(map);\n\t\t\t\tif (this._leaderEnded && !this._animating.size) {\n\t\t\t\t\tthis._leader = null;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tfor (const other of this._followers(map)) {\n\t\t\tif (!this._animating.has(other) && !this._ended.has(other)) {\n\t\t\t\tthis._follow(other, map, false);\n\t\t\t\tother._moveEnd(other.getZoom() !== other._syncStartZoom);\n\t\t\t}\n\t\t}\n\t\tthis._leaderEnded = true;\n\t\tif (!this._animating.size) {\n\t\t\tthis._leader = null;\n\t\t}\n\t}\n\n\t_onRotate(map) {\n\t\tif (!this.options.bearing || !this._canLead(map)) { return; }\n\t\tfor (const other of this._followers(map)) {\n\t\t\tif (other._rotate && other.getBearing() !== map.getBearing()) {\n\t\t\t\tother._rotate(map.getBearing());\n\t\t\t}\n\t\t}\n\t}\n\n\t// Moves `other` to the view of `map`, during or at the end of a movement\n\t_follow(other, map, during) {\n\t\tconst center = map.getCenter(),\n\t\tzoom = this._zoomFor(other, map, map.getZoom(), !during);\n\t\tif (zoom === other.getZoom()) {\n\t\t\t// panning, by whole pixels like dragging\n\t\t\tconst offset = other.project(center, zoom).subtract(other.project(other.getCenter(), zoom)).round();\n\t\t\tif (offset.x || offset.y) {\n\t\t\t\tother._rawPanBy(offset);\n\t\t\t\tother.fire('move');\n\t\t\t}\n\t\t} else {\n\t\t\t// zooming frame by frame (pinch, flyTo, continuousZoom) or at the end\n\t\t\tother._move(center, zoom, during ? {pinch: true} : undefined);\n\t\t}\n\t}\n\n\t// Sets the view of all other maps to the one of `map`, without animation\n\t_syncAll(map) {\n\t\tfor (const other of this._maps.filter(m => m !== map)) {\n\t\t\tif (this.options.bearing && other._rotate && other.getBearing() !== map.getBearing()) {\n\t\t\t\tother._rotate(map.getBearing());\n\t\t\t}\n\t\t\tconst zoom = this._zoomFor(other, map);\n\t\t\tif (!other._loaded || other.getZoom() !== zoom ||\n\t\t\t\tother.latLngToContainerPoint(map.getCenter()).distanceTo(other.getSize()._divideBy(2)) >= 1) {\n\t\t\t\tthis._leader = map;\n\t\t\t\tother.setView(map.getCenter(), zoom, {animate: false});\n\t\t\t\tthis._leader = null;\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,UAAb,MAAqB;;;;;;CAMpB,YAAY,MAAM,SAAS;;EAE1B,KAAK,UAAU;GACd,SAAS;GACT,QAAQ;GACR,KAAK;GACL,GAAG;EACJ;EACA,KAAK,QAAQ,CAAC,GAAG,IAAI;EACrB,KAAK,6BAAa,IAAI,IAAI;EAC1B,KAAK,6BAAa,IAAI,IAAI;EAE1B,KAAK,yBAAS,IAAI,IAAI;EAEtB,KAAK,MAAM,OAAO,KAAK,OAAO;GAC7B,MAAM,YAAY;IACjB,iBAAiB,KAAK,aAAa,GAAG;IACtC,iBAAiB,KAAK,aAAa,GAAG;IACtC,YAAY,KAAK,QAAQ,GAAG;IAC5B,WAAU,MAAK,KAAK,YAAY,KAAK,CAAC;IACtC,eAAe,KAAK,WAAW,GAAG;IAClC,cAAc,KAAK,UAAU,GAAG;GACjC;GACA,IAAI,GAAG,SAAS;GAChB,KAAK,WAAW,IAAI,KAAK,SAAS;EACnC;EAEA,IAAI,KAAK,MAAM,EAAE,EAAE,SAClB,KAAK,SAAS,KAAK,MAAM,EAAE;CAE7B;;;;;CAMA,SAAS;EACR,KAAK,MAAM,CAAC,KAAK,cAAc,KAAK,YACnC,IAAI,IAAI,SAAS;EAElB,KAAK,WAAW,MAAM;EACtB,KAAK,QAAQ,CAAC;EACd,OAAO;CACR;CAGA,WAAW,KAAK;EACf,OAAO,KAAK,MAAM,QAAO,MAAK,MAAM,OAAO,EAAE,OAAO;CACrD;CAGA,SAAS,KAAK;EACb,OAAO,CAAC,KAAK,QAAQ,UAAU,QAAQ,KAAK,MAAM;CACnD;CAIA,SAAS,OAAO,KAAK,OAAO,IAAI,QA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O,KAAK,OAAO,GAAG;IACzB,MAAM,UAAU,MAAM;IACtB,MAAM,KAAK,MAAM;GAClB;EACD,OAEC,MAAM,MAAM,QAAQ,MAAM,SAAS,EAAC,OAAO,KAAI,IAAI,KAAA,CAAS;CAE9D;CAGA,SAAS,KAAK;EACb,KAAK,MAAM,SAAS,KAAK,MAAM,QAAO,MAAK,MAAM,GAAG,GAAG;GACtD,IAAI,KAAK,QAAQ,WAAW,MAAM,WAAW,MAAM,WAAW,MAAM,IAAI,WAAW,GAClF,MAAM,QAAQ,IAAI,WAAW,CAAC;GAE/B,MAAM,OAAO,KAAK,SAAS,OAAO,GAAG;GACrC,IAAI,CAAC,MAAM,WAAW,MAAM,QAAQ,MAAM,QACzC,MAAM,uBAAuB,IAAI,UAAU,CAAC,CAAC,CAAC,WAAW,MAAM,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,KAAK,GAAG;IAC7F,KAAK,UAAU;IACf,MAAM,QAAQ,IAAI,UAAU,GAAG,MAAM,EAAC,SAAS,MAAK,CAAC;IACrD,KAAK,UAAU;GAChB;EACD;CACD;AACD"}
1
+ {"version":3,"file":"MapSync.js","names":[],"sources":["../../../src/map/MapSync.js"],"sourcesContent":["/** @import {MaplairMap} from './Map.js' */\n\n/**\n * Options of `MapSync`.\n * @typedef {object} MapSyncOptions\n * @property {boolean} [bearing=true] Whether to synchronize the bearing of rotated maps\n * (with the map rotation, see `MaplairMap.setBearing()`).\n * @property {boolean} [oneWay=false] Whether only the first map leads and the other\n * maps follow it, without moving the first map when they are moved.\n * @property {'center'|'bounds'} [fit='center'] How the maps follow: `'center'` with the\n * same center and zoom, or `'bounds'` with the same center, zoomed so that the bounds\n * of the leading map fit (like `fitBounds()`), for maps of different sizes.\n */\n\n/**\n * Synchronizes the views (center, zoom and bearing) of several maps, e.g. to\n * compare different layers side by side: whenever one of the maps moves (by the\n * user or by code, including animations), the other maps follow.\n *\n * With the options `oneWay` and `fit: 'bounds'`, smaller maps can follow a main\n * map showing its bounds, e.g. thumbnails next to it.\n *\n * Inspired by the [Leaflet.Sync](https://github.com/jieter/Leaflet.Sync) plugin.\n *\n * @example\n * ```js\n * const sync = new MapSync([map1, map2]);\n * // later\n * sync.remove();\n *\n * // a thumbnail showing the bounds of the main map\n * new MapSync([map, thumbnail], {oneWay: true, fit: 'bounds'});\n * ```\n */\nexport class MapSync {\n\t/**\n\t * Synchronizes the views of the given maps, starting with the view of the first map.\n\t * @param {MaplairMap[]} maps\n\t * @param {MapSyncOptions} [options]\n\t */\n\tconstructor(maps, options) {\n\t\t/** @type {MapSyncOptions} */\n\t\tthis.options = {\n\t\t\tbearing: true,\n\t\t\toneWay: false,\n\t\t\tfit: 'center',\n\t\t\t...options\n\t\t};\n\t\tthis._maps = [...maps];\n\t\tthis._listeners = new Map();\n\t\tthis._animating = new Set();\n\t\t// following maps which ended their zoom animation already\n\t\tthis._ended = new Set();\n\n\t\tfor (const map of this._maps) {\n\t\t\tconst listeners = {\n\t\t\t\tmovestart: () => this._onMoveStart(map),\n\t\t\t\tzoomstart: () => this._onZoomStart(map),\n\t\t\t\tmove: () => this._onMove(map),\n\t\t\t\tzoomanim: e => this._onZoomAnim(map, e),\n\t\t\t\tmoveend: () => this._onMoveEnd(map),\n\t\t\t\trotate: () => this._onRotate(map)\n\t\t\t};\n\t\t\tmap.on(listeners);\n\t\t\tthis._listeners.set(map, listeners);\n\t\t}\n\n\t\tif (this._maps[0]?._loaded) {\n\t\t\tthis._syncAll(this._maps[0]);\n\t\t}\n\t}\n\n\t/**\n\t * Stops synchronizing the maps.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\tfor (const [map, listeners] of this._listeners) {\n\t\t\tmap.off(listeners);\n\t\t}\n\t\tthis._listeners.clear();\n\t\tthis._maps = [];\n\t\treturn this;\n\t}\n\n\t// The other maps, which follow `map`\n\t_followers(map) {\n\t\treturn this._maps.filter(m => m !== map && m._loaded);\n\t}\n\n\t// Whether `map` may lead, see the `oneWay` option\n\t_canLead(map) {\n\t\treturn !this.options.oneWay || map === this._maps[0];\n\t}\n\n\t// The zoom of `other` following `map` at `zoom`, see the `fit` option; snapped to\n\t// the `zoomSnap` of `other` at the `end` of a movement\n\t_zoomFor(other, map, zoom = map.getZoom(), end = true) {\n\t\tconst size = other.getSize(),\n\t\tleaderSize = map.getSize();\n\t\tif (this.options.fit !== 'bounds' || !size.x || !size.y || !leaderSize.x || !leaderSize.y) { return zoom; }\n\t\tlet z = zoom + Math.log2(Math.min(size.x / leaderSize.x, size.y / leaderSize.y));\n\t\tconst snap = other.options.zoomSnap;\n\t\tif (end && snap) {\n\t\t\t// down, so that the bounds fit\n\t\t\tz = Math.floor(z / snap + 1e-6) * snap;\n\t\t}\n\t\treturn Math.max(other.getMinZoom(), Math.min(other.getMaxZoom(), z));\n\t}\n\n\t// A map starting to move leads until it (and all following animations) ended,\n\t// the events of the following maps are ignored meanwhile.\n\t_onMoveStart(map) {\n\t\tif (this._leader || !this._canLead(map)) { return; }\n\t\tthis._leader = map;\n\t\tthis._leaderEnded = false;\n\t\tthis._ended.clear();\n\t\tfor (const other of this._followers(map)) {\n\t\t\tother._stop();\n\t\t\tother._syncStartZoom = other.getZoom();\n\t\t\tother.fire('movestart');\n\t\t}\n\t}\n\n\t_onZoomStart(map) {\n\t\t// `_resetView()` fires zoomstart before movestart\n\t\tthis._onMoveStart(map);\n\t\tif (this._leader !== map) { return; }\n\t\tfor (const other of this._followers(map)) {\n\t\t\tother.fire('zoomstart');\n\t\t}\n\t}\n\n\t_onMove(map) {\n\t\tif (!this._leader) {\n\t\t\t// e.g. invalidateSize(), which fires move without movestart\n\t\t\tif (this._canLead(map)) {\n\t\t\t\tthis._syncAll(map);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (this._leader !== map) { return; }\n\t\tfor (const other of this._followers(map)) {\n\t\t\tif (!this._animating.has(other)) {\n\t\t\t\tthis._follow(other, map, true);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Mirrors the CSS zoom animation, the following map ends it itself\n\t_onZoomAnim(map, e) {\n\t\tif (this._leader !== map) { return; }\n\t\tfor (const other of this._followers(map)) {\n\t\t\tif (other._zoomAnimated) {\n\t\t\t\tthis._animating.add(other);\n\t\t\t\tother._animateZoom(e.center, this._zoomFor(other, map, e.zoom), e.noUpdate);\n\t\t\t}\n\t\t}\n\t}\n\n\t_onMoveEnd(map) {\n\t\tif (this._leader !== map) {\n\t\t\t// the end of a following zoom animation\n\t\t\tif (this._animating.delete(map)) {\n\t\t\t\tthis._ended.add(map);\n\t\t\t\tif (this._leaderEnded && !this._animating.size) {\n\t\t\t\t\tthis._leader = null;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tfor (const other of this._followers(map)) {\n\t\t\tif (!this._animating.has(other) && !this._ended.has(other)) {\n\t\t\t\tthis._follow(other, map, false);\n\t\t\t\tother._moveEnd(other.getZoom() !== other._syncStartZoom);\n\t\t\t}\n\t\t}\n\t\tthis._leaderEnded = true;\n\t\tif (!this._animating.size) {\n\t\t\tthis._leader = null;\n\t\t}\n\t}\n\n\t_onRotate(map) {\n\t\tif (!this.options.bearing || !this._canLead(map)) { return; }\n\t\tfor (const other of this._followers(map)) {\n\t\t\tif (other._rotate && other.getBearing() !== map.getBearing()) {\n\t\t\t\tother._rotate(map.getBearing());\n\t\t\t}\n\t\t}\n\t}\n\n\t// Moves `other` to the view of `map`, during or at the end of a movement\n\t_follow(other, map, during) {\n\t\tconst center = map.getCenter(),\n\t\tzoom = this._zoomFor(other, map, map.getZoom(), !during);\n\t\tif (zoom === other.getZoom()) {\n\t\t\t// panning, by whole pixels like dragging\n\t\t\tconst offset = other.project(center, zoom).subtract(other.project(other.getCenter(), zoom)).round();\n\t\t\tif (offset.x || offset.y) {\n\t\t\t\tother._rawPanBy(offset);\n\t\t\t\tother.fire('move');\n\t\t\t}\n\t\t} else {\n\t\t\t// zooming frame by frame (pinch, flyTo, continuousZoom) or at the end\n\t\t\tother._move(center, zoom, during ? {pinch: true} : undefined);\n\t\t}\n\t}\n\n\t// Sets the view of all other maps to the one of `map`, without animation\n\t_syncAll(map) {\n\t\tfor (const other of this._maps.filter(m => m !== map)) {\n\t\t\tif (this.options.bearing && other._rotate && other.getBearing() !== map.getBearing()) {\n\t\t\t\tother._rotate(map.getBearing());\n\t\t\t}\n\t\t\tconst zoom = this._zoomFor(other, map);\n\t\t\tif (!other._loaded || other.getZoom() !== zoom ||\n\t\t\t\tother.latLngToContainerPoint(map.getCenter()).distanceTo(other.getSize()._divideBy(2)) >= 1) {\n\t\t\t\tthis._leader = map;\n\t\t\t\tother.setView(map.getCenter(), zoom, {animate: false});\n\t\t\t\tthis._leader = null;\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,UAAb,MAAqB;;;;;;CAMpB,YAAY,MAAM,SAAS;;EAE1B,KAAK,UAAU;GACd,SAAS;GACT,QAAQ;GACR,KAAK;GACL,GAAG;EACJ;EACA,KAAK,QAAQ,CAAC,GAAG,IAAI;EACrB,KAAK,6BAAa,IAAI,IAAI;EAC1B,KAAK,6BAAa,IAAI,IAAI;EAE1B,KAAK,yBAAS,IAAI,IAAI;EAEtB,KAAK,MAAM,OAAO,KAAK,OAAO;GAC7B,MAAM,YAAY;IACjB,iBAAiB,KAAK,aAAa,GAAG;IACtC,iBAAiB,KAAK,aAAa,GAAG;IACtC,YAAY,KAAK,QAAQ,GAAG;IAC5B,WAAU,MAAK,KAAK,YAAY,KAAK,CAAC;IACtC,eAAe,KAAK,WAAW,GAAG;IAClC,cAAc,KAAK,UAAU,GAAG;GACjC;GACA,IAAI,GAAG,SAAS;GAChB,KAAK,WAAW,IAAI,KAAK,SAAS;EACnC;EAEA,IAAI,KAAK,MAAM,EAAE,EAAE,SAClB,KAAK,SAAS,KAAK,MAAM,EAAE;CAE7B;;;;;CAMA,SAAS;EACR,KAAK,MAAM,CAAC,KAAK,cAAc,KAAK,YACnC,IAAI,IAAI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AM,SAAS,IAAI,UAAU,GAC7B,OAAO,KAAK,SAAS,OAAO,KAAK,IAAI,QAAQ,GAAG,CAAC,MAAM;EACvD,IAAI,SAAS,MAAM,QAAQ,GAAG;GAE7B,MAAM,SAAS,MAAM,QAAQ,QAAQ,IAAI,CAAC,CAAC,SAAS,MAAM,QAAQ,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM;GAClG,IAAI,OAAO,KAAK,OAAO,GAAG;IACzB,MAAM,UAAU,MAAM;IACtB,MAAM,KAAK,MAAM;GAClB;EACD,OAEC,MAAM,MAAM,QAAQ,MAAM,SAAS,EAAC,OAAO,KAAI,IAAI,KAAA,CAAS;CAE9D;CAGA,SAAS,KAAK;EACb,KAAK,MAAM,SAAS,KAAK,MAAM,QAAO,MAAK,MAAM,GAAG,GAAG;GACtD,IAAI,KAAK,QAAQ,WAAW,MAAM,WAAW,MAAM,WAAW,MAAM,IAAI,WAAW,GAClF,MAAM,QAAQ,IAAI,WAAW,CAAC;GAE/B,MAAM,OAAO,KAAK,SAAS,OAAO,GAAG;GACrC,IAAI,CAAC,MAAM,WAAW,MAAM,QAAQ,MAAM,QACzC,MAAM,uBAAuB,IAAI,UAAU,CAAC,CAAC,CAAC,WAAW,MAAM,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,KAAK,GAAG;IAC7F,KAAK,UAAU;IACf,MAAM,QAAQ,IAAI,UAAU,GAAG,MAAM,EAAC,SAAS,MAAK,CAAC;IACrD,KAAK,UAAU;GAChB;EACD;CACD;AACD"}
@@ -55,6 +55,8 @@ var BoxZoomHandler = class BoxZoomHandler extends Handler {
55
55
  removeHooks() {
56
56
  off(this._map._container, "pointerdown", this._onPointerDown, this);
57
57
  this._map._container.classList.remove("maplair-box-zoom");
58
+ this._finish();
59
+ this._resetState();
58
60
  }
59
61
  /**
60
62
  * Returns `true` if a box has been drawn by the current or last interaction.
@@ -1 +1 @@
1
- {"version":3,"file":"BoxZoomHandler.js","names":["DomEvent.stop","DomEvent.on","DomUtil.create","DomEvent.off"],"sources":["../../../../src/map/handler/BoxZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * The event object of `boxzoomend`.\n * @typedef {object} BoxZoomEndEvent\n * @property {LatLngBounds} boxZoomBounds The bounds of the box the map was zoomed to.\n * @extends MaplairEvent\n */\n\n/**\n * Map options of `BoxZoomHandler`.\n * @typedef {object} BoxZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [boxZoom=true] Whether the map can be zoomed to a rectangular\n * area specified by dragging the pointer while pressing the shift key.\n */\n\n/**\n * Handler of `MaplairMap` for box zoom.\n * @typedef {object} BoxZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {BoxZoomHandler} boxZoom Box (shift-drag with pointer) zoom handler.\n */\n\n/**\n * Adds shift-drag zoom interaction to the map (zoom to a selected bounding box),\n * enabled by default, see the map option `boxZoom`.\n *\n * @fires MaplairMap#boxzoomstart {MaplairEvent} Fired when the user starts drawing\n * a box to zoom to.\n * @fires MaplairMap#boxzoomend {BoxZoomEndEvent} Fired when the user has drawn a box\n * and the map is zoomed to it.\n */\nexport class BoxZoomHandler extends Handler {\n\t/**\n\t * @param {MaplairMap} map\n\t */\n\tconstructor(map) {\n\t\tsuper(map);\n\t\tthis.callInitHooks(BoxZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tDomEvent.on(this._map._container, 'pointerdown', this._onPointerDown, this);\n\t\tthis._map._container.classList.add('maplair-box-zoom');\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tDomEvent.off(this._map._container, 'pointerdown', this._onPointerDown, this);\n\t\tthis._map._container.classList.remove('maplair-box-zoom');\n\t}\n\n\t/**\n\t * Returns `true` if a box has been drawn by the current or last interaction.\n\t * @returns {boolean}\n\t */\n\tmoved() {\n\t\treturn this._moved;\n\t}\n\n\t_resetState() {\n\t\tclearTimeout(this._resetStateTimeout);\n\t\tthis._moved = false;\n\t}\n\n\t_toggleListeners(onOff) {\n\t\tonOff(this._map._container, {\n\t\t\tcontextmenu: DomEvent.stop,\n\t\t\tpointermove: this._onPointerMove,\n\t\t\tpointerup: this._onPointerUp\n\t\t}, this);\n\t\tonOff(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_onPointerDown(e) {\n\t\tif (!e.shiftKey || (e.button !== 0)) { return false; }\n\n\t\t// also cancels a deferred reset that hasn't run yet, which would interrupt the interaction and orphan a box\n\t\tthis._resetState();\n\n\t\t// stops both text selection and native image drag in every engine without restyling the page; it also\n\t\t// suppresses compatibility mouse events, which is fine for a press that is already a box zoom gesture\n\t\tDomEvent.preventDefault(e);\n\n\t\tthis._startPoint = this._map.pointerEventToContainerPoint(e);\n\n\t\tthis._toggleListeners(DomEvent.on);\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst map = this._map;\n\n\t\tif (!this._moved) {\n\t\t\tthis._moved = true;\n\n\t\t\tthis._box = DomUtil.create('div', 'maplair-zoom-box', map._container);\n\t\t\tmap._container.classList.add('maplair-crosshair');\n\n\t\t\tmap.fire('boxzoomstart');\n\t\t}\n\n\t\tthis._point = map.pointerEventToContainerPoint(e);\n\n\t\tconst bounds = new Bounds(this._point, this._startPoint),\n\t\tsize = bounds.getSize();\n\n\t\tDomUtil.setPosition(this._box, bounds.min);\n\n\t\tthis._box.style.width = `${size.x}px`;\n\t\tthis._box.style.height = `${size.y}px`;\n\t}\n\n\t_finish() {\n\t\tif (this._moved) {\n\t\t\tthis._box.remove();\n\t\t\tthis._map._container.classList.remove('maplair-crosshair');\n\t\t}\n\n\t\tthis._toggleListeners(DomEvent.off);\n\t}\n\n\t_onPointerUp(e) {\n\t\tif (e.button !== 0) { return; }\n\n\t\tthis._finish();\n\n\t\tif (!this._moved) { return; }\n\t\t// Postpone to next JS tick so internal click event handling\n\t\t// still see it as \"moved\".\n\t\tthis._resetStateTimeout = setTimeout(() => this._resetState(), 0);\n\n\t\tconst bounds = new LatLngBounds(\n\t\t\tthis._map.containerPointToLatLng(this._startPoint),\n\t\t\tthis._map.containerPointToLatLng(this._point));\n\n\t\tthis._map._setUserEvent(e);\n\t\t// a tiny box can collapse to a single LatLng at very high zoom, which fits at an Infinity zoom when no layer\n\t\t// limits it; unlike fitBounds before a tile layer is added, no layer will come along to clamp it (#6709)\n\t\tif (this._map.getBoundsZoom(bounds) !== Infinity) {\n\t\t\tthis._map.fitBounds(bounds);\n\t\t}\n\t\tthis._map.fire('boxzoomend', {boxZoomBounds: bounds});\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.code === 'Escape') {\n\t\t\tthis._finish();\n\t\t\tthis._resetState();\n\t\t}\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\tboxZoom: true\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'boxZoom', BoxZoomHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;;;;CAI3C,YAAY,KAAK;EAChB,MAAM,GAAG;EACT,KAAK,cAAc,cAAc;CAClC;;;;CAKA,WAAW;EACV,GAAY,KAAK,KAAK,YAAY,eAAe,KAAK,gBAAgB,IAAI;EAC1E,KAAK,KAAK,WAAW,UAAU,IAAI,kBAAkB;CACtD;;;;CAKA,cAAc;EACb,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,gBAAgB,IAAI;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pB,KAAK,qBAAqB,iBAAiB,KAAK,YAAY,GAAG,CAAC;EAEhE,MAAM,SAAS,IAAI,aAClB,KAAK,KAAK,uBAAuB,KAAK,WAAW,GACjD,KAAK,KAAK,uBAAuB,KAAK,MAAM,CAAC;EAE9C,KAAK,KAAK,cAAc,CAAC;EAGzB,IAAI,KAAK,KAAK,cAAc,MAAM,MAAM,UACvC,KAAK,KAAK,UAAU,MAAM;EAE3B,KAAK,KAAK,KAAK,cAAc,EAAC,eAAe,OAAM,CAAC;CACrD;CAEA,WAAW,GAAG;EACb,IAAI,EAAE,SAAS,UAAU;GACxB,KAAK,QAAQ;GACb,KAAK,YAAY;EAClB;CACD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,SAAS,KACV,CAAC;EAED,WAAW,YAAY,cAAc,WAAW,cAAc;CAC/D;AACD"}
1
+ {"version":3,"file":"BoxZoomHandler.js","names":["DomEvent.stop","DomEvent.on","DomUtil.create","DomEvent.off"],"sources":["../../../../src/map/handler/BoxZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent} from '../../core/Events.js' */\n\n/**\n * The event object of `boxzoomend`.\n * @typedef {object} BoxZoomEndEvent\n * @property {LatLngBounds} boxZoomBounds The bounds of the box the map was zoomed to.\n * @extends MaplairEvent\n */\n\n/**\n * Map options of `BoxZoomHandler`.\n * @typedef {object} BoxZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [boxZoom=true] Whether the map can be zoomed to a rectangular\n * area specified by dragging the pointer while pressing the shift key.\n */\n\n/**\n * Handler of `MaplairMap` for box zoom.\n * @typedef {object} BoxZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {BoxZoomHandler} boxZoom Box (shift-drag with pointer) zoom handler.\n */\n\n/**\n * Adds shift-drag zoom interaction to the map (zoom to a selected bounding box),\n * enabled by default, see the map option `boxZoom`.\n *\n * @fires MaplairMap#boxzoomstart {MaplairEvent} Fired when the user starts drawing\n * a box to zoom to.\n * @fires MaplairMap#boxzoomend {BoxZoomEndEvent} Fired when the user has drawn a box\n * and the map is zoomed to it.\n */\nexport class BoxZoomHandler extends Handler {\n\t/**\n\t * @param {MaplairMap} map\n\t */\n\tconstructor(map) {\n\t\tsuper(map);\n\t\tthis.callInitHooks(BoxZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tDomEvent.on(this._map._container, 'pointerdown', this._onPointerDown, this);\n\t\tthis._map._container.classList.add('maplair-box-zoom');\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tDomEvent.off(this._map._container, 'pointerdown', this._onPointerDown, this);\n\t\tthis._map._container.classList.remove('maplair-box-zoom');\n\t\t// cancel a box being drawn, as Escape does\n\t\tthis._finish();\n\t\tthis._resetState();\n\t}\n\n\t/**\n\t * Returns `true` if a box has been drawn by the current or last interaction.\n\t * @returns {boolean}\n\t */\n\tmoved() {\n\t\treturn this._moved;\n\t}\n\n\t_resetState() {\n\t\tclearTimeout(this._resetStateTimeout);\n\t\tthis._moved = false;\n\t}\n\n\t_toggleListeners(onOff) {\n\t\tonOff(this._map._container, {\n\t\t\tcontextmenu: DomEvent.stop,\n\t\t\tpointermove: this._onPointerMove,\n\t\t\tpointerup: this._onPointerUp\n\t\t}, this);\n\t\tonOff(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_onPointerDown(e) {\n\t\tif (!e.shiftKey || (e.button !== 0)) { return false; }\n\n\t\t// also cancels a deferred reset that hasn't run yet, which would interrupt the interaction and orphan a box\n\t\tthis._resetState();\n\n\t\t// stops both text selection and native image drag in every engine without restyling the page; it also\n\t\t// suppresses compatibility mouse events, which is fine for a press that is already a box zoom gesture\n\t\tDomEvent.preventDefault(e);\n\n\t\tthis._startPoint = this._map.pointerEventToContainerPoint(e);\n\n\t\tthis._toggleListeners(DomEvent.on);\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst map = this._map;\n\n\t\tif (!this._moved) {\n\t\t\tthis._moved = true;\n\n\t\t\tthis._box = DomUtil.create('div', 'maplair-zoom-box', map._container);\n\t\t\tmap._container.classList.add('maplair-crosshair');\n\n\t\t\tmap.fire('boxzoomstart');\n\t\t}\n\n\t\tthis._point = map.pointerEventToContainerPoint(e);\n\n\t\tconst bounds = new Bounds(this._point, this._startPoint),\n\t\tsize = bounds.getSize();\n\n\t\tDomUtil.setPosition(this._box, bounds.min);\n\n\t\tthis._box.style.width = `${size.x}px`;\n\t\tthis._box.style.height = `${size.y}px`;\n\t}\n\n\t_finish() {\n\t\tif (this._moved) {\n\t\t\tthis._box.remove();\n\t\t\tthis._map._container.classList.remove('maplair-crosshair');\n\t\t}\n\n\t\tthis._toggleListeners(DomEvent.off);\n\t}\n\n\t_onPointerUp(e) {\n\t\tif (e.button !== 0) { return; }\n\n\t\tthis._finish();\n\n\t\tif (!this._moved) { return; }\n\t\t// Postpone to next JS tick so internal click event handling\n\t\t// still see it as \"moved\".\n\t\tthis._resetStateTimeout = setTimeout(() => this._resetState(), 0);\n\n\t\tconst bounds = new LatLngBounds(\n\t\t\tthis._map.containerPointToLatLng(this._startPoint),\n\t\t\tthis._map.containerPointToLatLng(this._point));\n\n\t\tthis._map._setUserEvent(e);\n\t\t// a tiny box can collapse to a single LatLng at very high zoom, which fits at an Infinity zoom when no layer\n\t\t// limits it; unlike fitBounds before a tile layer is added, no layer will come along to clamp it (#6709)\n\t\tif (this._map.getBoundsZoom(bounds) !== Infinity) {\n\t\t\tthis._map.fitBounds(bounds);\n\t\t}\n\t\tthis._map.fire('boxzoomend', {boxZoomBounds: bounds});\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.code === 'Escape') {\n\t\t\tthis._finish();\n\t\t\tthis._resetState();\n\t\t}\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\tboxZoom: true\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'boxZoom', BoxZoomHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;;;;CAI3C,YAAY,KAAK;EAChB,MAAM,GAAG;EACT,KAAK,cAAc,cAAc;CAClC;;;;CAKA,WAAW;EACV,GAAY,KAAK,KAAK,YAAY,eAAe,KAAK,gBAAgB,IAAI;EAC1E,KAAK,KAAK,WAAW,UAAU,IAAI,kBAAkB;CACtD;;;;CAKA,cAAc;EACb,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,gBAAgB,IAAI;EAC3E,KAAK,KAAK,WAAW,UAAU,OAAO,kBAAkB;EAExD,KAAK,QAAQ;EACb,KAAK,YAAY;CAClB;;;;;CAMA,QAAQ;EACP,OAAO,KAAK;CACb;CAEA,cAAc;EACb,aAAa,KAAK,kBAAkB;EACpC,KAAK,SAAS;CACf;CAEA,iBAAiB,OAAO;EACvB,MAAM,KAAK,KAAK,YAAY;GAC3B,aAAaA;GACb,aAAa,KAAK;GAClB,WAAW,KAAK;EACjB,GAAG,IAAI;EACP,MAAM,UAAU,WAAW,KAAK,YAAY,IAAI;CACjD;CAEA,eAAe,GAAG;EACjB,IAAI,CAAC,EAAE,YAAa,EAAE,WAAW,GAAM,OAAO;EAG9C,KAAK,YAAY;EAIjB,eAAwB,CAAC;EAEzB,KAAK,cAAc,KAAK,KAAK,6BAA6B,CAAC;EAE3D,KAAK,iBAAiBC,EAAW;CAClC;CAEA,eAAe,GAAG;EACjB,MAAM,MAAM,KAAK;EA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13 @@ var DragHandler = class DragHandler extends Handler {
101
101
  map._stop();
102
102
  map._setUserEvent(e.originalEvent);
103
103
  if (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) {
104
- const bounds = LatLngBounds.from(this._map.options.maxBounds);
105
- this._offsetLimit = new Bounds(this._map.latLngToContainerPoint(bounds.getNorthWest()).multiplyBy(-1), this._map.latLngToContainerPoint(bounds.getSouthEast()).multiplyBy(-1).add(this._map.getSize()));
104
+ const bounds = LatLngBounds.from(this._map.options.maxBounds), corners = [
105
+ bounds.getNorthWest(),
106
+ bounds.getNorthEast(),
107
+ bounds.getSouthEast(),
108
+ bounds.getSouthWest()
109
+ ], { min, max } = new Bounds(corners.map((c) => this._map.latLngToContainerPoint(c)));
110
+ this._offsetLimit = new Bounds(max.multiplyBy(-1), min.multiplyBy(-1).add(this._map.getSize()));
106
111
  this._viscosity = Math.min(1, Math.max(0, this._map.options.maxBoundsViscosity));
107
112
  } else this._offsetLimit = null;
108
113
  map.fire("movestart").fire("dragstart");
@@ -1 +1 @@
1
- {"version":3,"file":"DragHandler.js","names":[],"sources":["../../../../src/map/handler/DragHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */\n\n/**\n * Map options of `DragHandler`, the interaction options for dragging.\n * @typedef {object} DragHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [dragging=true] Whether the map is draggable with pointer or not.\n * @property {boolean} [inertia=true] If enabled, panning of the map will have an\n * inertia effect where the map builds momentum while dragging and continues moving in\n * the same direction for some time. Feels especially nice on touch devices.\n * @property {number} [inertiaDeceleration=3400] The rate with which the inertial\n * movement slows down, in pixels/second².\n * @property {number} [inertiaMaxSpeed=1400] Max speed of the inertial movement,\n * in pixels/second.\n * @property {number} [easeLinearity=0.2] The linearity of the easing of the inertial\n * movement.\n * @property {boolean} [worldCopyJump=false] With this option enabled, the map tracks\n * when you pan to another \"copy\" of the world and seamlessly jumps to the original one\n * so that all overlays like markers and vector layers are still visible. A map with an\n * infinite CRS, such as `SimpleCRS`, does not jump, as it has no copies of the world.\n * @property {number} [maxBoundsViscosity=0.0] If `maxBounds` is set, this option will\n * control how solid the bounds are when dragging the map around. The default value of\n * `0.0` allows the user to drag outside the bounds at normal speed, higher values will\n * slow down map dragging outside bounds, and `1.0` makes the bounds fully solid,\n * preventing the user from dragging outside the bounds.\n */\n\n/**\n * Handler of `MaplairMap` for dragging.\n * @typedef {object} DragHandlerMapProperties\n * @lends MaplairMap\n * @property {DragHandler} dragging Map dragging handler.\n */\n\n/**\n * Makes the map draggable (with panning inertia), enabled by default, see the map\n * option `dragging`.\n *\n * @fires MaplairMap#dragstart {MaplairEvent} Fired when the user starts dragging the map.\n * @fires MaplairMap#drag {MaplairEvent} Fired repeatedly while the user drags the map.\n * @fires MaplairMap#dragend {DragEndEvent} Fired when the user stops dragging the map.\n */\nexport class DragHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DragHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tif (!this._draggable) {\n\t\t\tconst map = this._map;\n\n\t\t\tthis._draggable = new Draggable(map._mapPane, map._container);\n\n\t\t\tthis._draggable.on({\n\t\t\t\tdown: this._onDown,\n\t\t\t\tdragstart: this._onDragStart,\n\t\t\t\tdrag: this._onDrag,\n\t\t\t\tdragend: this._onDragEnd\n\t\t\t}, this);\n\n\t\t\tthis._draggable.on('predrag', this._onPreDragLimit, this);\n\t\t\tif (map.options.worldCopyJump) {\n\t\t\t\tthis._draggable.on('predrag', this._onPreDragWrap, this);\n\t\t\t}\n\t\t}\n\t\tthis._map._container.classList.add('maplair-grab', 'maplair-touch-drag');\n\t\tthis._draggable.enable();\n\t\tthis._positions = [];\n\t\tthis._times = [];\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._map._container.classList.remove('maplair-grab', 'maplair-touch-drag');\n\t\tthis._draggable.disable();\n\t}\n\n\t/**\n\t * Returns `true` if the map has been moved by the current or last drag.\n\t * @returns {boolean}\n\t */\n\tmoved() {\n\t\treturn this._draggable?._moved;\n\t}\n\n\t/**\n\t * Returns `true` while the map is being dragged.\n\t * @returns {boolean}\n\t */\n\tmoving() {\n\t\treturn this._draggable?._moving;\n\t}\n\n\t_onDown() {\n\t\t// Stop inertia before Draggable captures _startPos (#10376).\n\t\tthis._map._stop();\n\t}\n\n\t_onDragStart(e) {\n\t\tconst map = this._map;\n\n\t\tmap._stop();\n\t\tmap._setUserEvent(e.originalEvent);\n\t\tif (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) {\n\t\t\tconst bounds = LatLngBounds.from(this._map.options.maxBounds);\n\n\t\t\tthis._offsetLimit = new Bounds(\n\t\t\t\tthis._map.latLngToContainerPoint(bounds.getNorthWest()).multiplyBy(-1),\n\t\t\t\tthis._map.latLngToContainerPoint(bounds.getSouthEast()).multiplyBy(-1)\n\t\t\t\t\t.add(this._map.getSize()));\n\n\t\t\tthis._viscosity = Math.min(1.0, Math.max(0.0, this._map.options.maxBoundsViscosity));\n\t\t} else {\n\t\t\tthis._offsetLimit = null;\n\t\t}\n\n\t\tmap\n\t\t\t.fire('movestart')\n\t\t\t.fire('dragstart');\n\n\t\tif (map.options.inertia) {\n\t\t\tthis._positions = [];\n\t\t\tthis._times = [];\n\t\t}\n\t}\n\n\t_onDrag(e) {\n\t\tif (this._map.options.inertia) {\n\t\t\tconst time = this._lastTime = Date.now(),\n\t\t\tpos = this._lastPos = this._draggable._absPos || this._draggable._newPos;\n\n\t\t\tthis._positions.push(pos);\n\t\t\tthis._times.push(time);\n\n\t\t\tthis._prunePositions(time);\n\t\t}\n\n\t\tthis._map\n\t\t\t.fire('move', e)\n\t\t\t.fire('drag', e);\n\t}\n\n\t_prunePositions(time) {\n\t\twhile (this._positions.length > 1 && time - this._times[0] > 50) {\n\t\t\tthis._positions.shift();\n\t\t\tthis._times.shift();\n\t\t}\n\t}\n\n\t_viscousLimit(value, threshold) {\n\t\treturn value - (value - threshold) * this._viscosity;\n\t}\n\n\t_onPreDragLimit() {\n\t\tif (!this._viscosity || !this._offsetLimit) { return; }\n\n\t\tconst offset = this._draggable._newPos.subtract(this._draggable._startPos);\n\n\t\tconst limit = this._offsetLimit;\n\t\tif (offset.x < limit.min.x) { offset.x = this._viscousLimit(offset.x, limit.min.x); }\n\t\tif (offset.y < limit.min.y) { offset.y = this._viscousLimit(offset.y, limit.min.y); }\n\t\tif (offset.x > limit.max.x) { offset.x = this._viscousLimit(offset.x, limit.max.x); }\n\t\tif (offset.y > limit.max.y) { offset.y = this._viscousLimit(offset.y, limit.max.y); }\n\n\t\tthis._draggable._newPos = this._draggable._startPos.add(offset);\n\t}\n\n\t_onPreDragWrap() {\n\t\tconst draggable = this._draggable;\n\t\tdraggable._absPos = draggable._newPos;\n\t\tdraggable._newPos = this._map._wrapWorldCopy(draggable._newPos);\n\t}\n\n\t_onDragEnd(e) {\n\t\tconst map = this._map,\n\t\toptions = map.options,\n\n\t\tnoInertia = !options.inertia || e.noInertia || this._times.length < 2;\n\n\t\tmap.fire('dragend', e);\n\n\t\tif (noInertia) {\n\t\t\tmap.fire('moveend');\n\n\t\t} else {\n\t\t\tthis._prunePositions(Date.now());\n\n\t\t\tconst direction = this._lastPos.subtract(this._positions[0]),\n\t\t\tduration = (this._lastTime - this._times[0]) / 1000,\n\t\t\tease = options.easeLinearity,\n\n\t\t\tspeedVector = direction.multiplyBy(ease / duration),\n\t\t\tspeed = speedVector.distanceTo([0, 0]),\n\n\t\t\tlimitedSpeed = Math.min(options.inertiaMaxSpeed, speed),\n\t\t\tlimitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),\n\n\t\t\tmaxOffset = map.getSize().divideBy(2);\n\n\t\t\tlet decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease),\n\t\t\toffset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();\n\n\t\t\t// with reduced motion, shorten the coast to fit within half the map size; distance grows with the\n\t\t\t// square of duration, so scaling the duration by the square root keeps the deceleration the same\n\t\t\tif (map._prefersReducedMotion() && !maxOffset.contains(offset)) {\n\t\t\t\tconst k = Math.min(maxOffset.x / Math.abs(offset.x), maxOffset.y / Math.abs(offset.y));\n\t\t\t\toffset = offset.multiplyBy(k).round();\n\t\t\t\tdecelerationDuration *= Math.sqrt(k);\n\t\t\t}\n\n\t\t\tif (!offset.x && !offset.y) {\n\t\t\t\tmap.fire('moveend');\n\n\t\t\t} else {\n\t\t\t\toffset = map._limitOffset(offset, map.options.maxBounds);\n\n\t\t\t\trequestAnimationFrame(() => {\n\t\t\t\t\tmap.panBy(offset, {\n\t\t\t\t\t\tduration: decelerationDuration,\n\t\t\t\t\t\teaseLinearity: ease,\n\t\t\t\t\t\tnoMoveStart: true,\n\t\t\t\t\t\tanimate: true\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t}\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\tdragging: true,\n\t\t\tinertia: true,\n\t\t\tinertiaDeceleration: 3400, // px/s^2\n\t\t\tinertiaMaxSpeed: 1400, // px/s\n\t\t\teaseLinearity: 0.2,\n\t\t\t// TODO refactor, move to CRS\n\t\t\tworldCopyJump: false,\n\t\t\tmaxBoundsViscosity: 0.0\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'dragging', DragHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM;IACpC,wBAAwB,KAAK,KAAK,CAAC;GACpC;GAEA,IAAI,CAAC,OAAO,KAAK,CAAC,OAAO,GACxB,IAAI,KAAK,SAAS;QAEZ;IACN,SAAS,IAAI,aAAa,QAAQ,IAAI,QAAQ,SAAS;IAEvD,4BAA4B;KAC3B,IAAI,MAAM,QAAQ;MACjB,UAAU;MACV,eAAe;MACf,aAAa;MACb,SAAS;KACV,CAAC;IACF,CAAC;GACF;EACD;CACD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa;GACvB,UAAU;GACV,SAAS;GACT,qBAAqB;GACrB,iBAAiB;GACjB,eAAe;GAEf,eAAe;GACf,oBAAoB;EACrB,CAAC;EAED,WAAW,YAAY,cAAc,YAAY,WAAW;CAC7D;AACD"}
1
+ {"version":3,"file":"DragHandler.js","names":[],"sources":["../../../../src/map/handler/DragHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {LatLngBounds} from '../../geo/LatLngBounds.js';\nimport {Bounds} from '../../geometry/Bounds.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */\n\n/**\n * Map options of `DragHandler`, the interaction options for dragging.\n * @typedef {object} DragHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [dragging=true] Whether the map is draggable with pointer or not.\n * @property {boolean} [inertia=true] If enabled, panning of the map will have an\n * inertia effect where the map builds momentum while dragging and continues moving in\n * the same direction for some time. Feels especially nice on touch devices.\n * @property {number} [inertiaDeceleration=3400] The rate with which the inertial\n * movement slows down, in pixels/second².\n * @property {number} [inertiaMaxSpeed=1400] Max speed of the inertial movement,\n * in pixels/second.\n * @property {number} [easeLinearity=0.2] The linearity of the easing of the inertial\n * movement.\n * @property {boolean} [worldCopyJump=false] With this option enabled, the map tracks\n * when you pan to another \"copy\" of the world and seamlessly jumps to the original one\n * so that all overlays like markers and vector layers are still visible. A map with an\n * infinite CRS, such as `SimpleCRS`, does not jump, as it has no copies of the world.\n * @property {number} [maxBoundsViscosity=0.0] If `maxBounds` is set, this option will\n * control how solid the bounds are when dragging the map around. The default value of\n * `0.0` allows the user to drag outside the bounds at normal speed, higher values will\n * slow down map dragging outside bounds, and `1.0` makes the bounds fully solid,\n * preventing the user from dragging outside the bounds.\n */\n\n/**\n * Handler of `MaplairMap` for dragging.\n * @typedef {object} DragHandlerMapProperties\n * @lends MaplairMap\n * @property {DragHandler} dragging Map dragging handler.\n */\n\n/**\n * Makes the map draggable (with panning inertia), enabled by default, see the map\n * option `dragging`.\n *\n * @fires MaplairMap#dragstart {MaplairEvent} Fired when the user starts dragging the map.\n * @fires MaplairMap#drag {MaplairEvent} Fired repeatedly while the user drags the map.\n * @fires MaplairMap#dragend {DragEndEvent} Fired when the user stops dragging the map.\n */\nexport class DragHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(DragHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tif (!this._draggable) {\n\t\t\tconst map = this._map;\n\n\t\t\tthis._draggable = new Draggable(map._mapPane, map._container);\n\n\t\t\tthis._draggable.on({\n\t\t\t\tdown: this._onDown,\n\t\t\t\tdragstart: this._onDragStart,\n\t\t\t\tdrag: this._onDrag,\n\t\t\t\tdragend: this._onDragEnd\n\t\t\t}, this);\n\n\t\t\tthis._draggable.on('predrag', this._onPreDragLimit, this);\n\t\t\tif (map.options.worldCopyJump) {\n\t\t\t\tthis._draggable.on('predrag', this._onPreDragWrap, this);\n\t\t\t}\n\t\t}\n\t\tthis._map._container.classList.add('maplair-grab', 'maplair-touch-drag');\n\t\tthis._draggable.enable();\n\t\tthis._positions = [];\n\t\tthis._times = [];\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._map._container.classList.remove('maplair-grab', 'maplair-touch-drag');\n\t\tthis._draggable.disable();\n\t}\n\n\t/**\n\t * Returns `true` if the map has been moved by the current or last drag.\n\t * @returns {boolean}\n\t */\n\tmoved() {\n\t\treturn this._draggable?._moved;\n\t}\n\n\t/**\n\t * Returns `true` while the map is being dragged.\n\t * @returns {boolean}\n\t */\n\tmoving() {\n\t\treturn this._draggable?._moving;\n\t}\n\n\t_onDown() {\n\t\t// Stop inertia before Draggable captures _startPos (#10376).\n\t\tthis._map._stop();\n\t}\n\n\t_onDragStart(e) {\n\t\tconst map = this._map;\n\n\t\tmap._stop();\n\t\tmap._setUserEvent(e.originalEvent);\n\t\tif (this._map.options.maxBounds && this._map.options.maxBoundsViscosity) {\n\t\t\tconst bounds = LatLngBounds.from(this._map.options.maxBounds),\n\t\t\t// any corner can be an extreme when the projection rotates the axes\n\t\t\tcorners = [bounds.getNorthWest(), bounds.getNorthEast(), bounds.getSouthEast(), bounds.getSouthWest()],\n\t\t\t{min, max} = new Bounds(corners.map(c => this._map.latLngToContainerPoint(c)));\n\n\t\t\tthis._offsetLimit = new Bounds(max.multiplyBy(-1), min.multiplyBy(-1).add(this._map.getSize()));\n\n\t\t\tthis._viscosity = Math.min(1.0, Math.max(0.0, this._map.options.maxBoundsViscosity));\n\t\t} else {\n\t\t\tthis._offsetLimit = null;\n\t\t}\n\n\t\tmap\n\t\t\t.fire('movestart')\n\t\t\t.fire('dragstart');\n\n\t\tif (map.options.inertia) {\n\t\t\tthis._positions = [];\n\t\t\tthis._times = [];\n\t\t}\n\t}\n\n\t_onDrag(e) {\n\t\tif (this._map.options.inertia) {\n\t\t\tconst time = this._lastTime = Date.now(),\n\t\t\tpos = this._lastPos = this._draggable._absPos || this._draggable._newPos;\n\n\t\t\tthis._positions.push(pos);\n\t\t\tthis._times.push(time);\n\n\t\t\tthis._prunePositions(time);\n\t\t}\n\n\t\tthis._map\n\t\t\t.fire('move', e)\n\t\t\t.fire('drag', e);\n\t}\n\n\t_prunePositions(time) {\n\t\twhile (this._positions.length > 1 && time - this._times[0] > 50) {\n\t\t\tthis._positions.shift();\n\t\t\tthis._times.shift();\n\t\t}\n\t}\n\n\t_viscousLimit(value, threshold) {\n\t\treturn value - (value - threshold) * this._viscosity;\n\t}\n\n\t_onPreDragLimit() {\n\t\tif (!this._viscosity || !this._offsetLimit) { return; }\n\n\t\tconst offset = this._draggable._newPos.subtract(this._draggable._startPos);\n\n\t\tconst limit = this._offsetLimit;\n\t\tif (offset.x < limit.min.x) { offset.x = this._viscousLimit(offset.x, limit.min.x); }\n\t\tif (offset.y < limit.min.y) { offset.y = this._viscousLimit(offset.y, limit.min.y); }\n\t\tif (offset.x > limit.max.x) { offset.x = this._viscousLimit(offset.x, limit.max.x); }\n\t\tif (offset.y > limit.max.y) { offset.y = this._viscousLimit(offset.y, limit.max.y); }\n\n\t\tthis._draggable._newPos = this._draggable._startPos.add(offset);\n\t}\n\n\t_onPreDragWrap() {\n\t\tconst draggable = this._draggable;\n\t\tdraggable._absPos = draggable._newPos;\n\t\tdraggable._newPos = this._map._wrapWorldCopy(draggable._newPos);\n\t}\n\n\t_onDragEnd(e) {\n\t\tconst map = this._map,\n\t\toptions = map.options,\n\n\t\tnoInertia = !options.inertia || e.noInertia || this._times.length < 2;\n\n\t\tmap.fire('dragend', e);\n\n\t\tif (noInertia) {\n\t\t\tmap.fire('moveend');\n\n\t\t} else {\n\t\t\tthis._prunePositions(Date.now());\n\n\t\t\tconst direction = this._lastPos.subtract(this._positions[0]),\n\t\t\tduration = (this._lastTime - this._times[0]) / 1000,\n\t\t\tease = options.easeLinearity,\n\n\t\t\tspeedVector = direction.multiplyBy(ease / duration),\n\t\t\tspeed = speedVector.distanceTo([0, 0]),\n\n\t\t\tlimitedSpeed = Math.min(options.inertiaMaxSpeed, speed),\n\t\t\tlimitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),\n\n\t\t\tmaxOffset = map.getSize().divideBy(2);\n\n\t\t\tlet decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease),\n\t\t\toffset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();\n\n\t\t\t// with reduced motion, shorten the coast to fit within half the map size; distance grows with the\n\t\t\t// square of duration, so scaling the duration by the square root keeps the deceleration the same\n\t\t\tif (map._prefersReducedMotion() && !maxOffset.contains(offset)) {\n\t\t\t\tconst k = Math.min(maxOffset.x / Math.abs(offset.x), maxOffset.y / Math.abs(offset.y));\n\t\t\t\toffset = offset.multiplyBy(k).round();\n\t\t\t\tdecelerationDuration *= Math.sqrt(k);\n\t\t\t}\n\n\t\t\tif (!offset.x && !offset.y) {\n\t\t\t\tmap.fire('moveend');\n\n\t\t\t} else {\n\t\t\t\toffset = map._limitOffset(offset, map.options.maxBounds);\n\n\t\t\t\trequestAnimationFrame(() => {\n\t\t\t\t\tmap.panBy(offset, {\n\t\t\t\t\t\tduration: decelerationDuration,\n\t\t\t\t\t\teaseLinearity: ease,\n\t\t\t\t\t\tnoMoveStart: true,\n\t\t\t\t\t\tanimate: true\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\t\t}\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\tdragging: true,\n\t\t\tinertia: true,\n\t\t\tinertiaDeceleration: 3400, // px/s^2\n\t\t\tinertiaMaxSpeed: 1400, // px/s\n\t\t\teaseLinearity: 0.2,\n\t\t\t// TODO refactor, move to CRS\n\t\t\tworldCopyJump: false,\n\t\t\tmaxBoundsViscosity: 0.0\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'dragging', DragHandler);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;;;;CAIxC,YAAY,GAAG,MAAM;EACpB,MAA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CAAC,MAAM;IACpC,wBAAwB,KAAK,KAAK,CAAC;GACpC;GAEA,IAAI,CAAC,OAAO,KAAK,CAAC,OAAO,GACxB,IAAI,KAAK,SAAS;QAEZ;IACN,SAAS,IAAI,aAAa,QAAQ,IAAI,QAAQ,SAAS;IAEvD,4BAA4B;KAC3B,IAAI,MAAM,QAAQ;MACjB,UAAU;MACV,eAAe;MACf,aAAa;MACb,SAAS;KACV,CAAC;IACF,CAAC;GACF;EACD;CACD;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa;GACvB,UAAU;GACV,SAAS;GACT,qBAAqB;GACrB,iBAAiB;GACjB,eAAe;GAEf,eAAe;GACf,oBAAoB;EACrB,CAAC;EAED,WAAW,YAAY,cAAc,YAAY,WAAW;CAC7D;AACD"}
@@ -109,7 +109,7 @@ var PinchZoomHandler = class PinchZoomHandler extends Handler {
109
109
  }
110
110
  this._zooming = false;
111
111
  cancelAnimationFrame(this._animRequest);
112
- if (this._map._zoomAnimated) this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);
112
+ if (this._map._zoomAnimated) this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), this._map.options.zoomSnap);
113
113
  else this._map._resetView(this._center, this._map._limitZoom(this._zoom));
114
114
  }
115
115
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"PinchZoomHandler.js","names":["PointerEvents.getPointers","DomUtil.getScale"],"sources":["../../../../src/map/handler/PinchZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport * as PointerEvents from '../../dom/DomEvent.PointerEvents.js';\n/** @import {MaplairMap} from '../Map.js' */\n\n/**\n * Map options of `PinchZoomHandler`, touch interaction options.\n * @typedef {object} PinchZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|'center'} [pinchZoom=true] Whether the map can be zoomed by\n * touch-dragging with two fingers. If passed `'center'`, it will zoom to the center of\n * the view regardless of where the touch events (fingers) were. Enabled for\n * touch-capable web browsers.\n * @property {boolean} [bounceAtZoomLimits=true] Set it to false if you don't want the\n * map to zoom beyond min/max zoom and then bounce back when pinch-zooming.\n * @property {boolean|'center'} [touchZoom] Deprecated, use `pinchZoom` instead.\n */\n\n/**\n * Handler of `MaplairMap` for pinch zoom.\n * @typedef {object} PinchZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {PinchZoomHandler} pinchZoom Pinch zoom handler.\n * @property {PinchZoomHandler} touchZoom Deprecated, the same as `pinchZoom`.\n */\n\n/**\n * Adds pinch zoom to the map on supported mobile browsers, enabled by default, see the\n * map option `pinchZoom`.\n */\nexport class PinchZoomHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(PinchZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tthis._map._container.classList.add('maplair-touch-zoom');\n\t\tDomEvent.on(this._map._container, 'pointerdown', this._onPointerStart, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._map._container.classList.remove('maplair-touch-zoom');\n\t\tDomEvent.off(this._map._container, 'pointerdown', this._onPointerStart, this);\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\t}\n\n\t_onPointerStart(e) {\n\t\tconst map = this._map;\n\n\t\tconst pointers = PointerEvents.getPointers();\n\t\tif (pointers.length !== 2 || map._animatingZoom || this._zooming) { return; }\n\n\t\tconst p1 = map.pointerEventToContainerPoint(pointers[0]);\n\t\tconst p2 = map.pointerEventToContainerPoint(pointers[1]);\n\t\tconst {x, y} = DomUtil.getScale(map._container);\n\n\t\t// the container doesn't move during a pinch, so keep its client offset and CSS scale to avoid reading layout on every move\n\t\tthis._containerScale = new Point(x, y);\n\t\tthis._containerOrigin = new Point(pointers[0].clientX, pointers[0].clientY)._subtract(p1.scaleBy(this._containerScale));\n\n\t\tthis._centerPoint = map.getSize()._divideBy(2);\n\t\tthis._startLatLng = map.containerPointToLatLng(this._centerPoint);\n\t\tif (map.options.pinchZoom !== 'center') {\n\t\t\tthis._pinchStartLatLng = map.containerPointToLatLng(p1.add(p2)._divideBy(2));\n\t\t}\n\n\t\tthis._startDist = p1.distanceTo(p2);\n\t\tthis._startZoom = map.getZoom();\n\n\t\tthis._moved = false;\n\t\tthis._zooming = true;\n\n\t\tmap._stop();\n\n\t\tDomEvent.on(map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\n\t\te.preventDefault();\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst pointers = PointerEvents.getPointers();\n\t\tif (pointers.length !== 2 || !this._zooming) { return; }\n\n\t\tconst map = this._map,\n\t\tp1 = this._toContainerPoint(pointers[0]),\n\t\tp2 = this._toContainerPoint(pointers[1]),\n\t\tscale = p1.distanceTo(p2) / this._startDist;\n\n\t\tthis._zoom = map.getScaleZoom(scale, this._startZoom);\n\n\t\tif (!map.options.bounceAtZoomLimits && (\n\t\t\t(this._zoom < map.getMinZoom() && scale < 1) ||\n\t\t\t(this._zoom > map.getMaxZoom() && scale > 1))) {\n\t\t\tthis._zoom = map._limitZoom(this._zoom);\n\t\t}\n\n\t\tif (map.options.pinchZoom === 'center') {\n\t\t\tthis._center = this._startLatLng;\n\t\t\tif (scale === 1) { return; }\n\t\t} else {\n\t\t\t// Get delta from pinch to center, so centerLatLng is delta applied to initial pinchLatLng\n\t\t\tconst delta = p1._add(p2)._divideBy(2)._subtract(this._centerPoint);\n\t\t\tif (scale === 1 && delta.x === 0 && delta.y === 0) { return; }\n\t\t\tthis._center = map.unproject(map.project(this._pinchStartLatLng, this._zoom).subtract(delta), this._zoom);\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap._moveStart(true, false);\n\t\t\tthis._moved = true;\n\t\t}\n\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\tconst moveFn = map._move.bind(map, this._center, this._zoom, {pinch: true}, undefined);\n\t\tthis._animRequest = requestAnimationFrame(moveFn.bind(this));\n\n\t\te.preventDefault();\n\t}\n\n\t_toContainerPoint(e) {\n\t\treturn new Point(e.clientX, e.clientY)._subtract(this._containerOrigin).unscaleBy(this._containerScale);\n\t}\n\n\t_onPointerEnd() {\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\n\t\tif (!this._moved || !this._zooming) {\n\t\t\tthis._zooming = false;\n\t\t\treturn;\n\t\t}\n\n\t\tthis._zooming = false;\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\t// Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate.\n\t\tif (this._map._zoomAnimated) {\n\t\t\tthis._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);\n\t\t} else {\n\t\t\tthis._map._resetView(this._center, this._map._limitZoom(this._zoom));\n\t\t}\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\tpinchZoom: true,\n\t\t\tbounceAtZoomLimits: true\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'pinchZoom', PinchZoomHandler);\n\n\t\t// Deprecated - Backward compatibility touchZoom\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tthis.touchZoom = this.pinchZoom;\n\n\t\t\tif (this.options.touchZoom !== undefined) {\n\t\t\t\t// To be removed in maplair 3\n\t\t\t\tconsole.warn('Map: touchZoom option is deprecated and will be removed in future versions. Use pinchZoom instead.');\n\t\t\t\tthis.options.pinchZoom = this.options.touchZoom;\n\t\t\t\tdelete this.options.touchZoom;\n\t\t\t}\n\t\t\tif (this.options.pinchZoom) {\n\t\t\t\tthis.pinchZoom.enable();\n\t\t\t} else {\n\t\t\t\tthis.pinchZoom.disable();\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,mBAAb,MAAa,yBAAyB,QAAQ;;;;CAI7C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,gBAAgB;CACpC;;;;CAKA,WAAW;EACV,KAAK,KAAK,WAAW,UAAU,IAAI,oBAAoB;EACvD,GAAY,KAAK,KAAK,YAAY,eAAe,KAAK,iBAAiB,IAAI;CAC5E;;;;CAKA,cAAc;EACb,KAAK,KAAK,WAAW,UAAU,OAAO,oBAAoB;EAC1D,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,iBAAiB,IAAI;EAC5E,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,gBAAgB,IAAI;EAC3E,IAAa,KAAK,KAAK,YAAY,2BAA2B,KAAK,eAAe,IAAI;CACvF;CAEA,gBAAgB,GAAG;EAClB,MAAM,MAAM,KAAK;EAEjB,MAAM,WAAWA,YAA0B;EAC3C,IAAI,SAAS,WAAW,KAAK,IAAI,kBAAkB,KAAK,UAAY;EAEpE,MAAM,KAAK,IAAI,6BAA6B,SAAS,EAAE;EACvD,MAAM,KAAK,IAAI,6BAA6B,SAAS,EAAE;EACvD,MAAM,EAAC,GAAG,MAAKC,SAAiB,IAAI,UAAU;EAG9C,KAAK,kBAAkB,IAAI,MAAM,GAAG,CAAC;EACrC,KAAK,mBAAmB,IAAI,MAAM,SAAS,EAAE,CAAC,SAAS,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,UAAU,GAAG,QAAQ,KAAK,eAAe,CAA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QAAQ,YAAY,KAAK,QAAQ;IACtC,OAAO,KAAK,QAAQ;GACrB;GACA,IAAI,KAAK,QAAQ,WAChB,KAAK,UAAU,OAAO;QAEtB,KAAK,UAAU,QAAQ;EAEzB,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"PinchZoomHandler.js","names":["PointerEvents.getPointers","DomUtil.getScale"],"sources":["../../../../src/map/handler/PinchZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as DomUtil from '../../dom/DomUtil.js';\nimport {Point} from '../../geometry/Point.js';\nimport * as PointerEvents from '../../dom/DomEvent.PointerEvents.js';\n/** @import {MaplairMap} from '../Map.js' */\n\n/**\n * Map options of `PinchZoomHandler`, touch interaction options.\n * @typedef {object} PinchZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|'center'} [pinchZoom=true] Whether the map can be zoomed by\n * touch-dragging with two fingers. If passed `'center'`, it will zoom to the center of\n * the view regardless of where the touch events (fingers) were. Enabled for\n * touch-capable web browsers.\n * @property {boolean} [bounceAtZoomLimits=true] Set it to false if you don't want the\n * map to zoom beyond min/max zoom and then bounce back when pinch-zooming.\n * @property {boolean|'center'} [touchZoom] Deprecated, use `pinchZoom` instead.\n */\n\n/**\n * Handler of `MaplairMap` for pinch zoom.\n * @typedef {object} PinchZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {PinchZoomHandler} pinchZoom Pinch zoom handler.\n * @property {PinchZoomHandler} touchZoom Deprecated, the same as `pinchZoom`.\n */\n\n/**\n * Adds pinch zoom to the map on supported mobile browsers, enabled by default, see the\n * map option `pinchZoom`.\n */\nexport class PinchZoomHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(PinchZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tthis._map._container.classList.add('maplair-touch-zoom');\n\t\tDomEvent.on(this._map._container, 'pointerdown', this._onPointerStart, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tthis._map._container.classList.remove('maplair-touch-zoom');\n\t\tDomEvent.off(this._map._container, 'pointerdown', this._onPointerStart, this);\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\t}\n\n\t_onPointerStart(e) {\n\t\tconst map = this._map;\n\n\t\tconst pointers = PointerEvents.getPointers();\n\t\tif (pointers.length !== 2 || map._animatingZoom || this._zooming) { return; }\n\n\t\tconst p1 = map.pointerEventToContainerPoint(pointers[0]);\n\t\tconst p2 = map.pointerEventToContainerPoint(pointers[1]);\n\t\tconst {x, y} = DomUtil.getScale(map._container);\n\n\t\t// the container doesn't move during a pinch, so keep its client offset and CSS scale to avoid reading layout on every move\n\t\tthis._containerScale = new Point(x, y);\n\t\tthis._containerOrigin = new Point(pointers[0].clientX, pointers[0].clientY)._subtract(p1.scaleBy(this._containerScale));\n\n\t\tthis._centerPoint = map.getSize()._divideBy(2);\n\t\tthis._startLatLng = map.containerPointToLatLng(this._centerPoint);\n\t\tif (map.options.pinchZoom !== 'center') {\n\t\t\tthis._pinchStartLatLng = map.containerPointToLatLng(p1.add(p2)._divideBy(2));\n\t\t}\n\n\t\tthis._startDist = p1.distanceTo(p2);\n\t\tthis._startZoom = map.getZoom();\n\n\t\tthis._moved = false;\n\t\tthis._zooming = true;\n\n\t\tmap._stop();\n\n\t\tDomEvent.on(map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\n\t\te.preventDefault();\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst pointers = PointerEvents.getPointers();\n\t\tif (pointers.length !== 2 || !this._zooming) { return; }\n\n\t\tconst map = this._map,\n\t\tp1 = this._toContainerPoint(pointers[0]),\n\t\tp2 = this._toContainerPoint(pointers[1]),\n\t\tscale = p1.distanceTo(p2) / this._startDist;\n\n\t\tthis._zoom = map.getScaleZoom(scale, this._startZoom);\n\n\t\tif (!map.options.bounceAtZoomLimits && (\n\t\t\t(this._zoom < map.getMinZoom() && scale < 1) ||\n\t\t\t(this._zoom > map.getMaxZoom() && scale > 1))) {\n\t\t\tthis._zoom = map._limitZoom(this._zoom);\n\t\t}\n\n\t\tif (map.options.pinchZoom === 'center') {\n\t\t\tthis._center = this._startLatLng;\n\t\t\tif (scale === 1) { return; }\n\t\t} else {\n\t\t\t// Get delta from pinch to center, so centerLatLng is delta applied to initial pinchLatLng\n\t\t\tconst delta = p1._add(p2)._divideBy(2)._subtract(this._centerPoint);\n\t\t\tif (scale === 1 && delta.x === 0 && delta.y === 0) { return; }\n\t\t\tthis._center = map.unproject(map.project(this._pinchStartLatLng, this._zoom).subtract(delta), this._zoom);\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap._moveStart(true, false);\n\t\t\tthis._moved = true;\n\t\t}\n\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\tconst moveFn = map._move.bind(map, this._center, this._zoom, {pinch: true}, undefined);\n\t\tthis._animRequest = requestAnimationFrame(moveFn.bind(this));\n\n\t\te.preventDefault();\n\t}\n\n\t_toContainerPoint(e) {\n\t\treturn new Point(e.clientX, e.clientY)._subtract(this._containerOrigin).unscaleBy(this._containerScale);\n\t}\n\n\t_onPointerEnd() {\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onPointerEnd, this);\n\n\t\tif (!this._moved || !this._zooming) {\n\t\t\tthis._zooming = false;\n\t\t\treturn;\n\t\t}\n\n\t\tthis._zooming = false;\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\t// Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate.\n\t\tif (this._map._zoomAnimated) {\n\t\t\tthis._map._animateZoom(this._center, this._map._limitZoom(this._zoom), this._map.options.zoomSnap);\n\t\t} else {\n\t\t\tthis._map._resetView(this._center, this._map._limitZoom(this._zoom));\n\t\t}\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\tpinchZoom: true,\n\t\t\tbounceAtZoomLimits: true\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'pinchZoom', PinchZoomHandler);\n\n\t\t// Deprecated - Backward compatibility touchZoom\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tthis.touchZoom = this.pinchZoom;\n\n\t\t\tif (this.options.touchZoom !== undefined) {\n\t\t\t\t// To be removed in maplair 3\n\t\t\t\tconsole.warn('Map: touchZoom option is deprecated and will be removed in future versions. Use pinchZoom instead.');\n\t\t\t\tthis.options.pinchZoom = this.options.touchZoom;\n\t\t\t\tdelete this.options.touchZoom;\n\t\t\t}\n\t\t\tif (this.options.pinchZoom) {\n\t\t\t\tthis.pinchZoom.enable();\n\t\t\t} else {\n\t\t\t\tthis.pinchZoom.disable();\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,mBAAb,MAAa,yBAAyB,QAAQ;;;;CAI7C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,gBAAgB;CACpC;;;;CAKA,WAAW;EACV,KAAK,KAAK,WAAW,UAAU,IAAI,oBAAoB;EACvD,GAAY,KAAK,KAAK,YAAY,eAAe,KAAK,iBAAiB,IAAI;CAC5E;;;;CAKA,cAAc;EACb,KAAK,KAAK,WAAW,UAAU,OAAO,oBAAoB;EAC1D,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,iBAAiB,IAAI;EAC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AU,CAAC,KAAK,UAAU;GACnC,KAAK,WAAW;GAChB;EACD;EAEA,KAAK,WAAW;EAChB,qBAAqB,KAAK,YAAY;EAGtC,IAAI,KAAK,KAAK,eACb,KAAK,KAAK,aAAa,KAAK,SAAS,KAAK,KAAK,WAAW,KAAK,KAAK,GAAG,KAAK,KAAK,QAAQ,QAAQ;OAEjG,KAAK,KAAK,WAAW,KAAK,SAAS,KAAK,KAAK,WAAW,KAAK,KAAK,CAAC;CAErE;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa;GACvB,WAAW;GACX,oBAAoB;EACrB,CAAC;EAED,WAAW,YAAY,cAAc,aAAa,gBAAgB;EAGlE,WAAW,YAAY,WAAY;GAClC,KAAK,YAAY,KAAK;GAEtB,IAAI,KAAK,QAAQ,cAAc,KAAA,GAAW;IAEzC,QAAQ,KAAK,oGAAoG;IACjH,KAAK,QAAQ,YAAY,KAAK,QAAQ;IACtC,OAAO,KAAK,QAAQ;GACrB;GACA,IAAI,KAAK,QAAQ,WAChB,KAAK,UAAU,OAAO;QAEtB,KAAK,UAAU,QAAQ;EAEzB,CAAC;CACF;AACD"}
@@ -129,7 +129,7 @@ var ScrollWheelZoomHandler = class ScrollWheelZoomHandler extends Handler {
129
129
  cancelAnimationFrame(this._pinchFrame);
130
130
  const map = this._map, zoom = map._limitZoom(this._pinch.zoom), center = this._getPinchCenter(zoom);
131
131
  this._pinch = null;
132
- if (map.options.zoomAnimation && Math.abs(zoom - map.getZoom()) > 1e-9) map._animateZoom(center, zoom, true, map.options.zoomSnap);
132
+ if (map.options.zoomAnimation && Math.abs(zoom - map.getZoom()) > 1e-9) map._animateZoom(center, zoom, map.options.zoomSnap);
133
133
  else map._move(center, zoom)._moveEnd(true);
134
134
  }
135
135
  _panBy(e) {
@@ -1 +1 @@
1
- {"version":3,"file":"ScrollWheelZoomHandler.js","names":["PointerEvents.getPointers","DomEvent.getWheelDelta"],"sources":["../../../../src/map/handler/ScrollWheelZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as PointerEvents from '../../dom/DomEvent.PointerEvents.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {MaplairMap} from '../Map.js' */\n\n// The number of pixels of a touchpad pinch (wheel event with `ctrlKey`) for zooming by one zoom level.\nconst pinchPxPerZoomLevel = 100;\n\n// The time (ms) without further wheel events after which a touchpad pinch or pan ends.\nconst gestureEndDelay = 150;\n\n/**\n * Map options of `ScrollWheelZoomHandler`, the mouse wheel options.\n * @typedef {object} ScrollWheelZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|'center'|'trackpad'} [scrollWheelZoom=true] Whether the map can\n * be zoomed by using the mouse wheel and by pinching on a touchpad (or using the mouse\n * wheel with the Ctrl key). If passed `'center'`, it will zoom to the center of the\n * view regardless of where the pointer was. If passed `'trackpad'`, scrolling (e.g.\n * with two fingers on a touchpad) pans the map instead, while pinching still zooms.\n * @property {number} [wheelDebounceTime=40] Limits the rate at which a wheel can fire\n * (in milliseconds). By default, the user can't zoom via wheel more often than once\n * per 40 ms.\n * @property {number} [wheelPxPerZoomLevel=60] How many scroll pixels (as reported by\n * [DomEvent.getWheelDelta](#domevent-getwheeldelta)) mean a change of one full zoom\n * level. Smaller values will make wheel-zooming faster (and vice versa).\n */\n\n/**\n * Handler of `MaplairMap` for scroll wheel zoom.\n * @typedef {object} ScrollWheelZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {ScrollWheelZoomHandler} scrollWheelZoom Scroll wheel zoom handler.\n */\n\n/**\n * Enables mouse scroll wheel zoom on the map, as well as touchpad gestures: pinching\n * zooms, and with `scrollWheelZoom: 'trackpad'` scrolling with two fingers pans.\n * Enabled by default, see the map option `scrollWheelZoom`.\n */\nexport class ScrollWheelZoomHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ScrollWheelZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tDomEvent.on(this._map._container, 'wheel', this._onWheelScroll, this);\n\t\t// Touchpad pinch in Safari (macOS)\n\t\tDomEvent.on(this._map._container, 'gesturestart', this._onGestureStart, this);\n\t\tDomEvent.on(this._map._container, 'gesturechange', this._onGestureChange, this);\n\t\tDomEvent.on(this._map._container, 'gestureend', this._onGestureEnd, this);\n\n\t\tthis._delta = 0;\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tDomEvent.off(this._map._container, 'wheel', this._onWheelScroll, this);\n\t\tDomEvent.off(this._map._container, 'gesturestart', this._onGestureStart, this);\n\t\tDomEvent.off(this._map._container, 'gesturechange', this._onGestureChange, this);\n\t\tDomEvent.off(this._map._container, 'gestureend', this._onGestureEnd, this);\n\t\tclearTimeout(this._timer);\n\t\tthis._endPinch();\n\t\tthis._endPan();\n\t}\n\n\t_onWheelScroll(e) {\n\t\tif (e.ctrlKey) {\n\t\t\t// A touchpad pinch, or the wheel with the Ctrl key pressed\n\t\t\tDomEvent.stop(e);\n\t\t\tconst delta = -e.deltaY * (e.deltaMode === 1 ? 20 : e.deltaMode === 2 ? 60 : 1);\n\t\t\tthis._pinchTo(e, (this._pinch?.zoom ?? this._map.getZoom()) + delta / pinchPxPerZoomLevel);\n\t\t\tclearTimeout(this._pinchTimer);\n\t\t\tthis._pinchTimer = setTimeout(this._endPinch.bind(this), gestureEndDelay);\n\t\t\treturn;\n\t\t}\n\t\tif (this._map.options.scrollWheelZoom === 'trackpad') {\n\t\t\tthis._panBy(e);\n\t\t\treturn;\n\t\t}\n\t\tthis._onWheelZoom(e);\n\t}\n\n\t_onGestureStart(e) {\n\t\t// On touch screens, pinching is handled by `PinchZoomHandler`\n\t\tif (PointerEvents.getPointers().length) { return; }\n\t\tDomEvent.stop(e);\n\t\tthis._gestureStartZoom = this._map.getZoom();\n\t}\n\n\t_onGestureChange(e) {\n\t\tif (this._gestureStartZoom === undefined) { return; }\n\t\tDomEvent.stop(e);\n\t\tthis._pinchTo(e, this._gestureStartZoom + Math.log2(e.scale));\n\t}\n\n\t_onGestureEnd(e) {\n\t\tif (this._gestureStartZoom === undefined) { return; }\n\t\tDomEvent.stop(e);\n\t\tthis._gestureStartZoom = undefined;\n\t\tthis._endPinch();\n\t}\n\n\t// Zooms continuously like `PinchZoomHandler`, around the pointer position of `e`.\n\t// If `eased`, the zoom approaches `zoom` over a few frames (for mouse wheels with steps).\n\t_pinchTo(e, zoom, eased) {\n\t\tconst map = this._map;\n\n\t\tif (!this._pinch) {\n\t\t\tif (map._animatingZoom) { return; }\n\t\t\tmap._stop();\n\t\t\tconst point = map.pointerEventToContainerPoint(e),\n\t\t\toffset = point.subtract(map.getSize()._divideBy(2));\n\t\t\tthis._pinch = {\n\t\t\t\taroundLatLng: map.options.scrollWheelZoom === 'center' ? map.getCenter() : map.containerPointToLatLng(point),\n\t\t\t\toffset: map.options.scrollWheelZoom === 'center' ? new Point(0, 0) : offset\n\t\t\t};\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap._moveStart(true, false);\n\t\t}\n\n\t\tif (!map.options.bounceAtZoomLimits || eased) {\n\t\t\tzoom = Math.max(map.getMinZoom(), Math.min(map.getMaxZoom(), zoom));\n\t\t}\n\t\tthis._pinch.zoom = zoom;\n\t\tthis._pinch.shown ??= map.getZoom();\n\n\t\tconst frame = () => {\n\t\t\tconst pinch = this._pinch,\n\t\t\tdelta = pinch.zoom - pinch.shown;\n\t\t\tpinch.shown = eased && Math.abs(delta) > 0.01 ? pinch.shown + delta * 0.3 : pinch.zoom;\n\t\t\tmap._move(this._getPinchCenter(pinch.shown), pinch.shown, {pinch: true});\n\t\t\tif (pinch.shown !== pinch.zoom) {\n\t\t\t\tthis._pinchFrame = requestAnimationFrame(frame);\n\t\t\t}\n\t\t};\n\t\tcancelAnimationFrame(this._pinchFrame);\n\t\tthis._pinchFrame = requestAnimationFrame(frame);\n\t}\n\n\t_getPinchCenter(zoom) {\n\t\tconst {aroundLatLng, offset} = this._pinch,\n\t\tmap = this._map;\n\t\treturn map.unproject(map.project(aroundLatLng, zoom).subtract(offset), zoom);\n\t}\n\n\t_endPinch() {\n\t\tclearTimeout(this._pinchTimer);\n\t\tif (!this._pinch) { return; }\n\t\tcancelAnimationFrame(this._pinchFrame);\n\n\t\tconst map = this._map,\n\t\tzoom = map._limitZoom(this._pinch.zoom),\n\t\tcenter = this._getPinchCenter(zoom);\n\t\tthis._pinch = null;\n\n\t\tif (map.options.zoomAnimation && Math.abs(zoom - map.getZoom()) > 1e-9) {\n\t\t\tmap._animateZoom(center, zoom, true, map.options.zoomSnap);\n\t\t} else {\n\t\t\t// `_moveStart()` has already been called on the first event\n\t\t\tmap._move(center, zoom)._moveEnd(true);\n\t\t}\n\t}\n\n\t// Pans the map by the wheel deltas, as by scrolling with two fingers on a touchpad.\n\t_panBy(e) {\n\t\tDomEvent.stop(e);\n\t\tconst map = this._map;\n\t\tif (map._animatingZoom) { return; }\n\n\t\tconst factor = e.deltaMode === 1 ? 20 : e.deltaMode === 2 ? 60 : 1;\n\t\tlet offset = new Point(e.deltaX * factor, e.deltaY * factor);\n\t\tif (e.shiftKey && !e.deltaX) {\n\t\t\t// Shift with a mouse wheel scrolls horizontally\n\t\t\toffset = new Point(offset.y, 0);\n\t\t}\n\t\tif (map.options.maxBounds) {\n\t\t\toffset = map._limitOffset(offset, map.options.maxBounds);\n\t\t}\n\n\t\tif (!this._panning) {\n\t\t\tmap._stop();\n\t\t\tthis._panning = true;\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.fire('movestart');\n\t\t}\n\t\tmap._rawPanBy(offset.round());\n\t\tmap.fire('move');\n\n\t\tclearTimeout(this._panTimer);\n\t\tthis._panTimer = setTimeout(this._endPan.bind(this), gestureEndDelay);\n\t}\n\n\t_endPan() {\n\t\tclearTimeout(this._panTimer);\n\t\tif (!this._panning) { return; }\n\t\tthis._panning = false;\n\t\tthis._map.fire('moveend');\n\t}\n\n\t_onWheelZoom(e) {\n\t\tif (this._map.options.continuousZoom) {\n\t\t\t// zoom with each wheel event, see the `continuousZoom` option\n\t\t\tDomEvent.stop(e);\n\t\t\tconst delta = DomEvent.getWheelDelta(e) / this._map.options.wheelPxPerZoomLevel;\n\t\t\tthis._pinchTo(e, (this._pinch?.zoom ?? this._map.getZoom()) + delta, true);\n\t\t\tclearTimeout(this._pinchTimer);\n\t\t\tthis._pinchTimer = setTimeout(this._endPinch.bind(this), gestureEndDelay);\n\t\t\treturn;\n\t\t}\n\t\tconst delta = DomEvent.getWheelDelta(e);\n\n\t\tconst debounce = this._map.options.wheelDebounceTime;\n\n\t\tthis._delta += delta;\n\t\t// resolving the container point reads layout, so defer it to _performZoom\n\t\tthis._lastEvent = e;\n\n\t\tif (!this._startTime) {\n\t\t\tthis._startTime = Date.now();\n\t\t}\n\n\t\tconst left = Math.max(debounce - (Date.now() - this._startTime), 0);\n\n\t\tclearTimeout(this._timer);\n\t\tthis._timer = setTimeout(this._performZoom.bind(this), left);\n\n\t\tDomEvent.stop(e);\n\t}\n\n\t_performZoom() {\n\t\tconst map = this._map,\n\t\tzoom = map.getZoom(),\n\t\tsnap = map.options.zoomSnap ?? 0;\n\n\t\tmap._stop(); // stop panning and fly animations if any\n\n\t\t// map the delta with a sigmoid function to -4..4 range leaning on -1..1\n\t\tconst d2 = this._delta / (map.options.wheelPxPerZoomLevel * 4),\n\t\td3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2,\n\t\td4 = snap ? Math.ceil(d3 / snap) * snap : d3,\n\t\t// with reduced motion, only zooms by up to one level are animated, so a hard scroll is capped to that\n\t\td5 = map._prefersReducedMotion() ? Math.min(d4, 1) : d4,\n\t\tdelta = map._limitZoom(zoom + (this._delta > 0 ? d5 : -d5)) - zoom;\n\n\t\tthis._delta = 0;\n\t\tthis._startTime = null;\n\n\t\tif (!delta || map._zoomInputBlocked()) { return; }\n\n\t\tmap._setUserEvent(this._lastEvent);\n\t\tif (map.options.scrollWheelZoom === 'center') {\n\t\t\tmap.setZoom(zoom + delta);\n\t\t} else {\n\t\t\tmap.setZoomAround(map.pointerEventToContainerPoint(this._lastEvent), zoom + delta);\n\t\t}\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\tscrollWheelZoom: true,\n\t\t\twheelDebounceTime: 40,\n\t\t\twheelPxPerZoomLevel: 60\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'scrollWheelZoom', ScrollWheelZoomHandler);\n\t}\n}\n"],"mappings":";;;;;;AAOA,MAAM,sBAAsB;AAG5B,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BxB,IAAa,yBAAb,MAAa,+BAA+B,QAAQ;;;;CAInD,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,sBAAsB;CAC1C;;;;CAKA,WAAW;EACV,GAAY,KAAK,KAAK,YAAY,SAAS,KAAK,gBAAgB,IAAI;EAEpE,GAAY,KAAK,KAAK,YAAY,gBAAgB,KAAK,iBAAiB,IAAI;EAC5E,GAAY,KAAK,KAAK,YAAY,iBAAiB,KAAK,kBAAkB,IAAI;EAC9E,GAAY,KAAK,KAAK,YAAY,cAAc,KAAK,eAAe,IAAI;EAExE,KAAK,SAAS;CACf;;;;CAKA,cAAc;EACb,IAAa,KAAK,KAAK,YAAY,SAAS,KAAK,gBAAgB,IAAI;EACrE,IAAa,KAAK,KAAK,YAAY,gBAAgB,KAAK,iBAAiB,IAAI;EAC7E,IAAa,KAAK,KAAK,YAAY,iBAAiB,KAAK,kBAAkB,IAAI;EAC/E,IAAa,KAAK,KAAK,YAAY,cAAc,KAAK,eAAe,IAAI;EACzE,aAAa,KAAK,MA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CAAC,KAAK,YACT,KAAK,aAAa,KAAK,IAAI;EAG5B,MAAM,OAAO,KAAK,IAAI,YAAY,KAAK,IAAI,IAAI,KAAK,aAAa,CAAC;EAElE,aAAa,KAAK,MAAM;EACxB,KAAK,SAAS,WAAW,KAAK,aAAa,KAAK,IAAI,GAAG,IAAI;EAE3D,KAAc,CAAC;CAChB;CAEA,eAAe;EACd,MAAM,MAAM,KAAK,MACjB,OAAO,IAAI,QAAQ,GACnB,OAAO,IAAI,QAAQ,YAAY;EAE/B,IAAI,MAAM;EAGV,MAAM,KAAK,KAAK,UAAU,IAAI,QAAQ,sBAAsB,IAC5D,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,IAAI,KAAK,KAC5D,KAAK,OAAO,KAAK,KAAK,KAAK,IAAI,IAAI,OAAO,IAE1C,KAAK,IAAI,sBAAsB,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,IACrD,QAAQ,IAAI,WAAW,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,GAAG,IAAI;EAE9D,KAAK,SAAS;EACd,KAAK,aAAa;EAElB,IAAI,CAAC,SAAS,IAAI,kBAAkB,GAAK;EAEzC,IAAI,cAAc,KAAK,UAAU;EACjC,IAAI,IAAI,QAAQ,oBAAoB,UACnC,IAAI,QAAQ,OAAO,KAAK;OAExB,IAAI,cAAc,IAAI,6BAA6B,KAAK,UAAU,GAAG,OAAO,KAAK;CAEnF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa;GACvB,iBAAiB;GACjB,mBAAmB;GACnB,qBAAqB;EACtB,CAAC;EAED,WAAW,YAAY,cAAc,mBAAmB,sBAAsB;CAC/E;AACD"}
1
+ {"version":3,"file":"ScrollWheelZoomHandler.js","names":["PointerEvents.getPointers","DomEvent.getWheelDelta"],"sources":["../../../../src/map/handler/ScrollWheelZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as PointerEvents from '../../dom/DomEvent.PointerEvents.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {MaplairMap} from '../Map.js' */\n\n// The number of pixels of a touchpad pinch (wheel event with `ctrlKey`) for zooming by one zoom level.\nconst pinchPxPerZoomLevel = 100;\n\n// The time (ms) without further wheel events after which a touchpad pinch or pan ends.\nconst gestureEndDelay = 150;\n\n/**\n * Map options of `ScrollWheelZoomHandler`, the mouse wheel options.\n * @typedef {object} ScrollWheelZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|'center'|'trackpad'} [scrollWheelZoom=true] Whether the map can\n * be zoomed by using the mouse wheel and by pinching on a touchpad (or using the mouse\n * wheel with the Ctrl key). If passed `'center'`, it will zoom to the center of the\n * view regardless of where the pointer was. If passed `'trackpad'`, scrolling (e.g.\n * with two fingers on a touchpad) pans the map instead, while pinching still zooms.\n * @property {number} [wheelDebounceTime=40] Limits the rate at which a wheel can fire\n * (in milliseconds). By default, the user can't zoom via wheel more often than once\n * per 40 ms.\n * @property {number} [wheelPxPerZoomLevel=60] How many scroll pixels (as reported by\n * [DomEvent.getWheelDelta](#domevent-getwheeldelta)) mean a change of one full zoom\n * level. Smaller values will make wheel-zooming faster (and vice versa).\n */\n\n/**\n * Handler of `MaplairMap` for scroll wheel zoom.\n * @typedef {object} ScrollWheelZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {ScrollWheelZoomHandler} scrollWheelZoom Scroll wheel zoom handler.\n */\n\n/**\n * Enables mouse scroll wheel zoom on the map, as well as touchpad gestures: pinching\n * zooms, and with `scrollWheelZoom: 'trackpad'` scrolling with two fingers pans.\n * Enabled by default, see the map option `scrollWheelZoom`.\n */\nexport class ScrollWheelZoomHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ScrollWheelZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tDomEvent.on(this._map._container, 'wheel', this._onWheelScroll, this);\n\t\t// Touchpad pinch in Safari (macOS)\n\t\tDomEvent.on(this._map._container, 'gesturestart', this._onGestureStart, this);\n\t\tDomEvent.on(this._map._container, 'gesturechange', this._onGestureChange, this);\n\t\tDomEvent.on(this._map._container, 'gestureend', this._onGestureEnd, this);\n\n\t\tthis._delta = 0;\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tDomEvent.off(this._map._container, 'wheel', this._onWheelScroll, this);\n\t\tDomEvent.off(this._map._container, 'gesturestart', this._onGestureStart, this);\n\t\tDomEvent.off(this._map._container, 'gesturechange', this._onGestureChange, this);\n\t\tDomEvent.off(this._map._container, 'gestureend', this._onGestureEnd, this);\n\t\tclearTimeout(this._timer);\n\t\tthis._endPinch();\n\t\tthis._endPan();\n\t}\n\n\t_onWheelScroll(e) {\n\t\tif (e.ctrlKey) {\n\t\t\t// A touchpad pinch, or the wheel with the Ctrl key pressed\n\t\t\tDomEvent.stop(e);\n\t\t\tconst delta = -e.deltaY * (e.deltaMode === 1 ? 20 : e.deltaMode === 2 ? 60 : 1);\n\t\t\tthis._pinchTo(e, (this._pinch?.zoom ?? this._map.getZoom()) + delta / pinchPxPerZoomLevel);\n\t\t\tclearTimeout(this._pinchTimer);\n\t\t\tthis._pinchTimer = setTimeout(this._endPinch.bind(this), gestureEndDelay);\n\t\t\treturn;\n\t\t}\n\t\tif (this._map.options.scrollWheelZoom === 'trackpad') {\n\t\t\tthis._panBy(e);\n\t\t\treturn;\n\t\t}\n\t\tthis._onWheelZoom(e);\n\t}\n\n\t_onGestureStart(e) {\n\t\t// On touch screens, pinching is handled by `PinchZoomHandler`\n\t\tif (PointerEvents.getPointers().length) { return; }\n\t\tDomEvent.stop(e);\n\t\tthis._gestureStartZoom = this._map.getZoom();\n\t}\n\n\t_onGestureChange(e) {\n\t\tif (this._gestureStartZoom === undefined) { return; }\n\t\tDomEvent.stop(e);\n\t\tthis._pinchTo(e, this._gestureStartZoom + Math.log2(e.scale));\n\t}\n\n\t_onGestureEnd(e) {\n\t\tif (this._gestureStartZoom === undefined) { return; }\n\t\tDomEvent.stop(e);\n\t\tthis._gestureStartZoom = undefined;\n\t\tthis._endPinch();\n\t}\n\n\t// Zooms continuously like `PinchZoomHandler`, around the pointer position of `e`.\n\t// If `eased`, the zoom approaches `zoom` over a few frames (for mouse wheels with steps).\n\t_pinchTo(e, zoom, eased) {\n\t\tconst map = this._map;\n\n\t\tif (!this._pinch) {\n\t\t\tif (map._animatingZoom) { return; }\n\t\t\tmap._stop();\n\t\t\tconst point = map.pointerEventToContainerPoint(e),\n\t\t\toffset = point.subtract(map.getSize()._divideBy(2));\n\t\t\tthis._pinch = {\n\t\t\t\taroundLatLng: map.options.scrollWheelZoom === 'center' ? map.getCenter() : map.containerPointToLatLng(point),\n\t\t\t\toffset: map.options.scrollWheelZoom === 'center' ? new Point(0, 0) : offset\n\t\t\t};\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap._moveStart(true, false);\n\t\t}\n\n\t\tif (!map.options.bounceAtZoomLimits || eased) {\n\t\t\tzoom = Math.max(map.getMinZoom(), Math.min(map.getMaxZoom(), zoom));\n\t\t}\n\t\tthis._pinch.zoom = zoom;\n\t\tthis._pinch.shown ??= map.getZoom();\n\n\t\tconst frame = () => {\n\t\t\tconst pinch = this._pinch,\n\t\t\tdelta = pinch.zoom - pinch.shown;\n\t\t\tpinch.shown = eased && Math.abs(delta) > 0.01 ? pinch.shown + delta * 0.3 : pinch.zoom;\n\t\t\tmap._move(this._getPinchCenter(pinch.shown), pinch.shown, {pinch: true});\n\t\t\tif (pinch.shown !== pinch.zoom) {\n\t\t\t\tthis._pinchFrame = requestAnimationFrame(frame);\n\t\t\t}\n\t\t};\n\t\tcancelAnimationFrame(this._pinchFrame);\n\t\tthis._pinchFrame = requestAnimationFrame(frame);\n\t}\n\n\t_getPinchCenter(zoom) {\n\t\tconst {aroundLatLng, offset} = this._pinch,\n\t\tmap = this._map;\n\t\treturn map.unproject(map.project(aroundLatLng, zoom).subtract(offset), zoom);\n\t}\n\n\t_endPinch() {\n\t\tclearTimeout(this._pinchTimer);\n\t\tif (!this._pinch) { return; }\n\t\tcancelAnimationFrame(this._pinchFrame);\n\n\t\tconst map = this._map,\n\t\tzoom = map._limitZoom(this._pinch.zoom),\n\t\tcenter = this._getPinchCenter(zoom);\n\t\tthis._pinch = null;\n\n\t\tif (map.options.zoomAnimation && Math.abs(zoom - map.getZoom()) > 1e-9) {\n\t\t\tmap._animateZoom(center, zoom, map.options.zoomSnap);\n\t\t} else {\n\t\t\t// `_moveStart()` has already been called on the first event\n\t\t\tmap._move(center, zoom)._moveEnd(true);\n\t\t}\n\t}\n\n\t// Pans the map by the wheel deltas, as by scrolling with two fingers on a touchpad.\n\t_panBy(e) {\n\t\tDomEvent.stop(e);\n\t\tconst map = this._map;\n\t\tif (map._animatingZoom) { return; }\n\n\t\tconst factor = e.deltaMode === 1 ? 20 : e.deltaMode === 2 ? 60 : 1;\n\t\tlet offset = new Point(e.deltaX * factor, e.deltaY * factor);\n\t\tif (e.shiftKey && !e.deltaX) {\n\t\t\t// Shift with a mouse wheel scrolls horizontally\n\t\t\toffset = new Point(offset.y, 0);\n\t\t}\n\t\tif (map.options.maxBounds) {\n\t\t\toffset = map._limitOffset(offset, map.options.maxBounds);\n\t\t}\n\n\t\tif (!this._panning) {\n\t\t\tmap._stop();\n\t\t\tthis._panning = true;\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.fire('movestart');\n\t\t}\n\t\tmap._rawPanBy(offset.round());\n\t\tmap.fire('move');\n\n\t\tclearTimeout(this._panTimer);\n\t\tthis._panTimer = setTimeout(this._endPan.bind(this), gestureEndDelay);\n\t}\n\n\t_endPan() {\n\t\tclearTimeout(this._panTimer);\n\t\tif (!this._panning) { return; }\n\t\tthis._panning = false;\n\t\tthis._map.fire('moveend');\n\t}\n\n\t_onWheelZoom(e) {\n\t\tif (this._map.options.continuousZoom) {\n\t\t\t// zoom with each wheel event, see the `continuousZoom` option\n\t\t\tDomEvent.stop(e);\n\t\t\tconst delta = DomEvent.getWheelDelta(e) / this._map.options.wheelPxPerZoomLevel;\n\t\t\tthis._pinchTo(e, (this._pinch?.zoom ?? this._map.getZoom()) + delta, true);\n\t\t\tclearTimeout(this._pinchTimer);\n\t\t\tthis._pinchTimer = setTimeout(this._endPinch.bind(this), gestureEndDelay);\n\t\t\treturn;\n\t\t}\n\t\tconst delta = DomEvent.getWheelDelta(e);\n\n\t\tconst debounce = this._map.options.wheelDebounceTime;\n\n\t\tthis._delta += delta;\n\t\t// resolving the container point reads layout, so defer it to _performZoom\n\t\tthis._lastEvent = e;\n\n\t\tif (!this._startTime) {\n\t\t\tthis._startTime = Date.now();\n\t\t}\n\n\t\tconst left = Math.max(debounce - (Date.now() - this._startTime), 0);\n\n\t\tclearTimeout(this._timer);\n\t\tthis._timer = setTimeout(this._performZoom.bind(this), left);\n\n\t\tDomEvent.stop(e);\n\t}\n\n\t_performZoom() {\n\t\tconst map = this._map,\n\t\tzoom = map.getZoom(),\n\t\tsnap = map.options.zoomSnap ?? 0;\n\n\t\tmap._stop(); // stop panning and fly animations if any\n\n\t\t// map the delta with a sigmoid function to -4..4 range leaning on -1..1\n\t\tconst d2 = this._delta / (map.options.wheelPxPerZoomLevel * 4),\n\t\td3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2,\n\t\td4 = snap ? Math.ceil(d3 / snap) * snap : d3,\n\t\t// with reduced motion, only zooms by up to one level are animated, so a hard scroll is capped to that\n\t\td5 = map._prefersReducedMotion() ? Math.min(d4, 1) : d4,\n\t\tdelta = map._limitZoom(zoom + (this._delta > 0 ? d5 : -d5)) - zoom;\n\n\t\tthis._delta = 0;\n\t\tthis._startTime = null;\n\n\t\tif (!delta || map._zoomInputBlocked()) { return; }\n\n\t\tmap._setUserEvent(this._lastEvent);\n\t\tif (map.options.scrollWheelZoom === 'center') {\n\t\t\tmap.setZoom(zoom + delta);\n\t\t} else {\n\t\t\tmap.setZoomAround(map.pointerEventToContainerPoint(this._lastEvent), zoom + delta);\n\t\t}\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\tscrollWheelZoom: true,\n\t\t\twheelDebounceTime: 40,\n\t\t\twheelPxPerZoomLevel: 60\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'scrollWheelZoom', ScrollWheelZoomHandler);\n\t}\n}\n"],"mappings":";;;;;;AAOA,MAAM,sBAAsB;AAG5B,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BxB,IAAa,yBAAb,MAAa,+BAA+B,QAAQ;;;;CAInD,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,sBAAsB;CAC1C;;;;CAKA,WAAW;EACV,GAAY,KAAK,KAAK,YAAY,SAAS,KAAK,gBAAgB,IAAI;EAEpE,GAAY,KAAK,KAAK,YAAY,gBAAgB,KAAK,iBAAiB,IAAI;EAC5E,GAAY,KAAK,KAAK,YAAY,iBAAiB,KAAK,kBAAkB,IAAI;EAC9E,GAAY,KAAK,KAAK,YAAY,cAAc,KAAK,eAAe,IAAI;EAExE,KAAK,SAAS;CACf;;;;CAKA,cAAc;EACb,IAAa,KAAK,KAAK,YAAY,SAAS,KAAK,gBAAgB,IAAI;EACrE,IAAa,KAAK,KAAK,YAAY,gBAAgB,KAAK,iBAAiB,IAAI;EAC7E,IAAa,KAAK,KAAK,YAAY,iBAAiB,KAAK,kBAAkB,IAAI;EAC/E,IAAa,KAAK,KAAK,YAAY,cAAc,KAAK,eAAe,IAAI;EACzE,aAAa,KAAK,MAAM;EACxB,KAAK,UAAU;EACf,KAAK,QAA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AG5B,MAAM,OAAO,KAAK,IAAI,YAAY,KAAK,IAAI,IAAI,KAAK,aAAa,CAAC;EAElE,aAAa,KAAK,MAAM;EACxB,KAAK,SAAS,WAAW,KAAK,aAAa,KAAK,IAAI,GAAG,IAAI;EAE3D,KAAc,CAAC;CAChB;CAEA,eAAe;EACd,MAAM,MAAM,KAAK,MACjB,OAAO,IAAI,QAAQ,GACnB,OAAO,IAAI,QAAQ,YAAY;EAE/B,IAAI,MAAM;EAGV,MAAM,KAAK,KAAK,UAAU,IAAI,QAAQ,sBAAsB,IAC5D,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,IAAI,KAAK,KAC5D,KAAK,OAAO,KAAK,KAAK,KAAK,IAAI,IAAI,OAAO,IAE1C,KAAK,IAAI,sBAAsB,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,IACrD,QAAQ,IAAI,WAAW,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,GAAG,IAAI;EAE9D,KAAK,SAAS;EACd,KAAK,aAAa;EAElB,IAAI,CAAC,SAAS,IAAI,kBAAkB,GAAK;EAEzC,IAAI,cAAc,KAAK,UAAU;EACjC,IAAI,IAAI,QAAQ,oBAAoB,UACnC,IAAI,QAAQ,OAAO,KAAK;OAExB,IAAI,cAAc,IAAI,6BAA6B,KAAK,UAAU,GAAG,OAAO,KAAK;CAEnF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa;GACvB,iBAAiB;GACjB,mBAAmB;GACnB,qBAAqB;EACtB,CAAC;EAED,WAAW,YAAY,cAAc,mBAAmB,sBAAsB;CAC/E;AACD"}
@@ -128,7 +128,7 @@ var TapDragZoomHandler = class TapDragZoomHandler extends Handler {
128
128
  this._moved = false;
129
129
  cancelAnimationFrame(this._animRequest);
130
130
  const map = this._map, zoom = map._limitZoom(this._zoom);
131
- if (map.options.zoomAnimation) map._animateZoom(this._center, zoom, true, map.options.zoomSnap);
131
+ if (map.options.zoomAnimation) map._animateZoom(this._center, zoom, map.options.zoomSnap);
132
132
  else map._move(this._center, zoom)._moveEnd(true);
133
133
  }
134
134
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"TapDragZoomHandler.js","names":["PointerEvents.getPointers"],"sources":["../../../../src/map/handler/TapDragZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as PointerEvents from '../../dom/DomEvent.PointerEvents.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {MaplairMap} from '../Map.js' */\n\n// The max time (ms) between the two taps and the max duration of the first tap.\nconst maxTapInterval = 500;\n\n// The max distance (px) between the first and the second tap.\nconst maxTapDistance = 30;\n\n// The number of pixels to drag vertically for zooming by one zoom level.\nconst pixelsPerZoomLevel = 128;\n\n/**\n * Map options of `TapDragZoomHandler`, touch interaction options.\n * @typedef {object} TapDragZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|'center'} [tapDragZoom=true] Whether the map can be zoomed with\n * one finger by tapping once, then touching again and dragging down (zoom in) or up\n * (zoom out). If passed `'center'`, it will zoom to the center of the view regardless\n * of where the finger was.\n */\n\n/**\n * Handler of `MaplairMap` for tap-drag zoom.\n * @typedef {object} TapDragZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {TapDragZoomHandler} tapDragZoom Tap-drag zoom handler (double tap and\n * drag with one finger).\n */\n\n/**\n * Zooms the map with one finger on touch devices: tap once, then touch again and drag\n * down to zoom in or up to zoom out (as known from MapLibre GL JS and Google Maps).\n * Enabled by default, see the map option `tapDragZoom`.\n */\nexport class TapDragZoomHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(TapDragZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tDomEvent.on(this._map._container, 'pointerdown', this._onDown, this);\n\t\tDomEvent.on(this._map._container, 'pointerup', this._onTapUp, this);\n\t\tDomEvent.on(this._map._container, 'pointercancel', this._reset, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tDomEvent.off(this._map._container, 'pointerdown', this._onDown, this);\n\t\tDomEvent.off(this._map._container, 'pointerup', this._onTapUp, this);\n\t\tDomEvent.off(this._map._container, 'pointercancel', this._reset, this);\n\t\tthis._onUp();\n\t\tthis._reset();\n\t}\n\n\t_onDown(e) {\n\t\tif (e.pointerType === 'mouse' || PointerEvents.getPointers().length !== 1) {\n\t\t\t// A second finger hands over to pinch zoom\n\t\t\tthis._onUp();\n\t\t\tthis._reset();\n\t\t\treturn;\n\t\t}\n\n\t\tconst map = this._map,\n\t\tpos = new Point(e.clientX, e.clientY),\n\t\tnow = Date.now();\n\n\t\tif (!this._tapPos || now - this._tapTime > maxTapInterval ||\n\t\t\tpos.distanceTo(this._tapPos) > maxTapDistance || map._animatingZoom) {\n\t\t\t// Possibly the first tap\n\t\t\tthis._tapPos = null;\n\t\t\tthis._downPos = pos;\n\t\t\tthis._downTime = now;\n\t\t\treturn;\n\t\t}\n\n\t\t// Second tap: zoom on dragging\n\t\tthis._tapPos = this._downPos = null;\n\t\tthis._startPos = pos;\n\t\tthis._startZoom = map.getZoom();\n\t\tthis._moved = false;\n\t\tthis._zooming = true;\n\n\t\tconst containerPoint = map.pointerEventToContainerPoint(e);\n\t\tthis._centerPoint = map.getSize()._divideBy(2);\n\t\tthis._startLatLng = map.containerPointToLatLng(this._centerPoint);\n\t\tif (map.options.tapDragZoom !== 'center') {\n\t\t\tthis._aroundLatLng = map.containerPointToLatLng(containerPoint);\n\t\t\tthis._aroundOffset = containerPoint.subtract(this._centerPoint);\n\t\t}\n\n\t\tthis._cancelDragging();\n\n\t\tDomEvent.on(map._container, 'pointermove', this._onMove, this);\n\t\tDomEvent.on(map._container, 'pointerup pointercancel', this._onUp, this);\n\t}\n\n\t// Keeps track of the first tap of a possible tap-drag gesture.\n\t_onTapUp(e) {\n\t\tif (!this._downPos) { return; }\n\n\t\tconst pos = new Point(e.clientX, e.clientY),\n\t\tnow = Date.now();\n\n\t\tif (now - this._downTime <= maxTapInterval &&\n\t\t\tpos.distanceTo(this._downPos) <= this._map.options.tapTolerance) {\n\t\t\tthis._tapPos = this._downPos;\n\t\t\tthis._tapTime = now;\n\t\t}\n\t\tthis._downPos = null;\n\t}\n\n\t_reset() {\n\t\tthis._tapPos = this._downPos = null;\n\t}\n\n\t// Prevents the map from being panned by the second tap.\n\t_cancelDragging() {\n\t\tconst draggable = this._map.dragging?._draggable;\n\t\tif (draggable && Draggable._dragging === draggable) {\n\t\t\tdraggable.finishDrag(true);\n\t\t}\n\t}\n\n\t_onMove(e) {\n\t\tif (!this._zooming || PointerEvents.getPointers().length !== 1) { return; }\n\n\t\tconst map = this._map,\n\t\tdy = e.clientY - this._startPos.y;\n\n\t\tif (!this._moved && Math.abs(dy) <= map.options.tapTolerance) { return; }\n\n\t\tthis._cancelDragging();\n\n\t\t// Dragging down zooms in, dragging up zooms out\n\t\tthis._zoom = this._startZoom + dy / pixelsPerZoomLevel;\n\n\t\tif (!map.options.bounceAtZoomLimits) {\n\t\t\tthis._zoom = map._limitZoom(this._zoom);\n\t\t}\n\n\t\tif (map.options.tapDragZoom === 'center') {\n\t\t\tthis._center = this._startLatLng;\n\t\t} else {\n\t\t\tthis._center = map.unproject(map.project(this._aroundLatLng, this._zoom).subtract(this._aroundOffset), this._zoom);\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\tmap._stop();\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap._moveStart(true, false);\n\t\t\tthis._moved = true;\n\t\t}\n\n\t\tcancelAnimationFrame(this._animRequest);\n\t\tthis._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, {pinch: true}));\n\n\t\te.preventDefault();\n\t}\n\n\t_onUp() {\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onUp, this);\n\n\t\tif (!this._zooming) { return; }\n\t\tthis._zooming = false;\n\n\t\t// Without moving, the second tap is a double tap (see `doubleClickZoom`)\n\t\tif (!this._moved) { return; }\n\t\tthis._moved = false;\n\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\tconst map = this._map,\n\t\tzoom = map._limitZoom(this._zoom);\n\t\tif (map.options.zoomAnimation) {\n\t\t\tmap._animateZoom(this._center, zoom, true, map.options.zoomSnap);\n\t\t} else {\n\t\t\t// `_moveStart()` has already been called on the first move\n\t\t\tmap._move(this._center, zoom)._moveEnd(true);\n\t\t}\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\ttapDragZoom: true\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'tapDragZoom', TapDragZoomHandler);\n\t}\n}\n"],"mappings":";;;;;;;AAQA,MAAM,iBAAiB;AAGvB,MAAM,iBAAiB;AAGvB,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAyB3B,IAAa,qBAAb,MAAa,2BAA2B,QAAQ;;;;CAI/C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,kBAAkB;CACtC;;;;CAKA,WAAW;EACV,GAAY,KAAK,KAAK,YAAY,eAAe,KAAK,SAAS,IAAI;EACnE,GAAY,KAAK,KAAK,YAAY,aAAa,KAAK,UAAU,IAAI;EAClE,GAAY,KAAK,KAAK,YAAY,iBAAiB,KAAK,QAAQ,IAAI;CACrE;;;;CAKA,cAAc;EACb,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,SAAS,IAAI;EACpE,IAAa,KAAK,KAAK,YAAY,aAAa,KAAK,UAAU,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AC,KAAK,QAAU;EACpB,KAAK,SAAS;EAEd,qBAAqB,KAAK,YAAY;EAEtC,MAAM,MAAM,KAAK,MACjB,OAAO,IAAI,WAAW,KAAK,KAAK;EAChC,IAAI,IAAI,QAAQ,eACf,IAAI,aAAa,KAAK,SAAS,MAAM,MAAM,IAAI,QAAQ,QAAQ;OAG/D,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,SAAS,IAAI;CAE7C;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,aAAa,KACd,CAAC;EAED,WAAW,YAAY,cAAc,eAAe,kBAAkB;CACvE;AACD"}
1
+ {"version":3,"file":"TapDragZoomHandler.js","names":["PointerEvents.getPointers"],"sources":["../../../../src/map/handler/TapDragZoomHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as DomEvent from '../../dom/DomEvent.js';\nimport * as PointerEvents from '../../dom/DomEvent.PointerEvents.js';\nimport {Draggable} from '../../dom/Draggable.js';\nimport {Point} from '../../geometry/Point.js';\n/** @import {MaplairMap} from '../Map.js' */\n\n// The max time (ms) between the two taps and the max duration of the first tap.\nconst maxTapInterval = 500;\n\n// The max distance (px) between the first and the second tap.\nconst maxTapDistance = 30;\n\n// The number of pixels to drag vertically for zooming by one zoom level.\nconst pixelsPerZoomLevel = 128;\n\n/**\n * Map options of `TapDragZoomHandler`, touch interaction options.\n * @typedef {object} TapDragZoomHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|'center'} [tapDragZoom=true] Whether the map can be zoomed with\n * one finger by tapping once, then touching again and dragging down (zoom in) or up\n * (zoom out). If passed `'center'`, it will zoom to the center of the view regardless\n * of where the finger was.\n */\n\n/**\n * Handler of `MaplairMap` for tap-drag zoom.\n * @typedef {object} TapDragZoomHandlerMapProperties\n * @lends MaplairMap\n * @property {TapDragZoomHandler} tapDragZoom Tap-drag zoom handler (double tap and\n * drag with one finger).\n */\n\n/**\n * Zooms the map with one finger on touch devices: tap once, then touch again and drag\n * down to zoom in or up to zoom out (as known from MapLibre GL JS and Google Maps).\n * Enabled by default, see the map option `tapDragZoom`.\n */\nexport class TapDragZoomHandler extends Handler {\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(TapDragZoomHandler);\n\t}\n\n\t/**\n\t * Called when the handler is enabled, adds the event hooks.\n\t */\n\taddHooks() {\n\t\tDomEvent.on(this._map._container, 'pointerdown', this._onDown, this);\n\t\tDomEvent.on(this._map._container, 'pointerup', this._onTapUp, this);\n\t\tDomEvent.on(this._map._container, 'pointercancel', this._reset, this);\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks.\n\t */\n\tremoveHooks() {\n\t\tDomEvent.off(this._map._container, 'pointerdown', this._onDown, this);\n\t\tDomEvent.off(this._map._container, 'pointerup', this._onTapUp, this);\n\t\tDomEvent.off(this._map._container, 'pointercancel', this._reset, this);\n\t\tthis._onUp();\n\t\tthis._reset();\n\t}\n\n\t_onDown(e) {\n\t\tif (e.pointerType === 'mouse' || PointerEvents.getPointers().length !== 1) {\n\t\t\t// A second finger hands over to pinch zoom\n\t\t\tthis._onUp();\n\t\t\tthis._reset();\n\t\t\treturn;\n\t\t}\n\n\t\tconst map = this._map,\n\t\tpos = new Point(e.clientX, e.clientY),\n\t\tnow = Date.now();\n\n\t\tif (!this._tapPos || now - this._tapTime > maxTapInterval ||\n\t\t\tpos.distanceTo(this._tapPos) > maxTapDistance || map._animatingZoom) {\n\t\t\t// Possibly the first tap\n\t\t\tthis._tapPos = null;\n\t\t\tthis._downPos = pos;\n\t\t\tthis._downTime = now;\n\t\t\treturn;\n\t\t}\n\n\t\t// Second tap: zoom on dragging\n\t\tthis._tapPos = this._downPos = null;\n\t\tthis._startPos = pos;\n\t\tthis._startZoom = map.getZoom();\n\t\tthis._moved = false;\n\t\tthis._zooming = true;\n\n\t\tconst containerPoint = map.pointerEventToContainerPoint(e);\n\t\tthis._centerPoint = map.getSize()._divideBy(2);\n\t\tthis._startLatLng = map.containerPointToLatLng(this._centerPoint);\n\t\tif (map.options.tapDragZoom !== 'center') {\n\t\t\tthis._aroundLatLng = map.containerPointToLatLng(containerPoint);\n\t\t\tthis._aroundOffset = containerPoint.subtract(this._centerPoint);\n\t\t}\n\n\t\tthis._cancelDragging();\n\n\t\tDomEvent.on(map._container, 'pointermove', this._onMove, this);\n\t\tDomEvent.on(map._container, 'pointerup pointercancel', this._onUp, this);\n\t}\n\n\t// Keeps track of the first tap of a possible tap-drag gesture.\n\t_onTapUp(e) {\n\t\tif (!this._downPos) { return; }\n\n\t\tconst pos = new Point(e.clientX, e.clientY),\n\t\tnow = Date.now();\n\n\t\tif (now - this._downTime <= maxTapInterval &&\n\t\t\tpos.distanceTo(this._downPos) <= this._map.options.tapTolerance) {\n\t\t\tthis._tapPos = this._downPos;\n\t\t\tthis._tapTime = now;\n\t\t}\n\t\tthis._downPos = null;\n\t}\n\n\t_reset() {\n\t\tthis._tapPos = this._downPos = null;\n\t}\n\n\t// Prevents the map from being panned by the second tap.\n\t_cancelDragging() {\n\t\tconst draggable = this._map.dragging?._draggable;\n\t\tif (draggable && Draggable._dragging === draggable) {\n\t\t\tdraggable.finishDrag(true);\n\t\t}\n\t}\n\n\t_onMove(e) {\n\t\tif (!this._zooming || PointerEvents.getPointers().length !== 1) { return; }\n\n\t\tconst map = this._map,\n\t\tdy = e.clientY - this._startPos.y;\n\n\t\tif (!this._moved && Math.abs(dy) <= map.options.tapTolerance) { return; }\n\n\t\tthis._cancelDragging();\n\n\t\t// Dragging down zooms in, dragging up zooms out\n\t\tthis._zoom = this._startZoom + dy / pixelsPerZoomLevel;\n\n\t\tif (!map.options.bounceAtZoomLimits) {\n\t\t\tthis._zoom = map._limitZoom(this._zoom);\n\t\t}\n\n\t\tif (map.options.tapDragZoom === 'center') {\n\t\t\tthis._center = this._startLatLng;\n\t\t} else {\n\t\t\tthis._center = map.unproject(map.project(this._aroundLatLng, this._zoom).subtract(this._aroundOffset), this._zoom);\n\t\t}\n\n\t\tif (!this._moved) {\n\t\t\tmap._stop();\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap._moveStart(true, false);\n\t\t\tthis._moved = true;\n\t\t}\n\n\t\tcancelAnimationFrame(this._animRequest);\n\t\tthis._animRequest = requestAnimationFrame(() => map._move(this._center, this._zoom, {pinch: true}));\n\n\t\te.preventDefault();\n\t}\n\n\t_onUp() {\n\t\tDomEvent.off(this._map._container, 'pointermove', this._onMove, this);\n\t\tDomEvent.off(this._map._container, 'pointerup pointercancel', this._onUp, this);\n\n\t\tif (!this._zooming) { return; }\n\t\tthis._zooming = false;\n\n\t\t// Without moving, the second tap is a double tap (see `doubleClickZoom`)\n\t\tif (!this._moved) { return; }\n\t\tthis._moved = false;\n\n\t\tcancelAnimationFrame(this._animRequest);\n\n\t\tconst map = this._map,\n\t\tzoom = map._limitZoom(this._zoom);\n\t\tif (map.options.zoomAnimation) {\n\t\t\tmap._animateZoom(this._center, zoom, map.options.zoomSnap);\n\t\t} else {\n\t\t\t// `_moveStart()` has already been called on the first move\n\t\t\tmap._move(this._center, zoom)._moveEnd(true);\n\t\t}\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\ttapDragZoom: true\n\t\t});\n\n\t\tMaplairMap.addInitHook('addHandler', 'tapDragZoom', TapDragZoomHandler);\n\t}\n}\n"],"mappings":";;;;;;;AAQA,MAAM,iBAAiB;AAGvB,MAAM,iBAAiB;AAGvB,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;AAyB3B,IAAa,qBAAb,MAAa,2BAA2B,QAAQ;;;;CAI/C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,kBAAkB;CACtC;;;;CAKA,WAAW;EACV,GAAY,KAAK,KA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