maplair 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/esm/Maplair.js +18 -17
  3. package/dist/esm/Maplair.js.map +1 -1
  4. package/dist/esm/_virtual/_rolldown/runtime.js +1 -2
  5. package/dist/esm/control/AttributionControl.js +25 -16
  6. package/dist/esm/control/AttributionControl.js.map +1 -1
  7. package/dist/esm/control/ButtonControl.js +10 -13
  8. package/dist/esm/control/ButtonControl.js.map +1 -1
  9. package/dist/esm/control/ContextMenu.js +2 -5
  10. package/dist/esm/control/ContextMenu.js.map +1 -1
  11. package/dist/esm/control/Control.js +10 -18
  12. package/dist/esm/control/Control.js.map +1 -1
  13. package/dist/esm/control/FullscreenControl.js +6 -9
  14. package/dist/esm/control/FullscreenControl.js.map +1 -1
  15. package/dist/esm/control/LayersControl.js +170 -65
  16. package/dist/esm/control/LayersControl.js.map +1 -1
  17. package/dist/esm/control/LegendControl.js +8 -11
  18. package/dist/esm/control/LegendControl.js.map +1 -1
  19. package/dist/esm/control/MiniMapControl.js +15 -18
  20. package/dist/esm/control/MiniMapControl.js.map +1 -1
  21. package/dist/esm/control/RotateControl.js +2 -5
  22. package/dist/esm/control/RotateControl.js.map +1 -1
  23. package/dist/esm/control/ScaleControl.js +8 -11
  24. package/dist/esm/control/ScaleControl.js.map +1 -1
  25. package/dist/esm/control/SearchControl.js +100 -19
  26. package/dist/esm/control/SearchControl.js.map +1 -1
  27. package/dist/esm/control/SideBySideControl.js +2 -5
  28. package/dist/esm/control/SideBySideControl.js.map +1 -1
  29. package/dist/esm/control/TextControl.js +6 -9
  30. package/dist/esm/control/TextControl.js.map +1 -1
  31. package/dist/esm/control/TimeControl.js +407 -0
  32. package/dist/esm/control/TimeControl.js.map +1 -0
  33. package/dist/esm/control/ZoomControl.js +23 -36
  34. package/dist/esm/control/ZoomControl.js.map +1 -1
  35. package/dist/esm/core/Class.js +28 -44
  36. package/dist/esm/core/Class.js.map +1 -1
  37. package/dist/esm/core/Events.js +22 -10
  38. package/dist/esm/core/Events.js.map +1 -1
  39. package/dist/esm/core/Handler.js +23 -14
  40. package/dist/esm/core/Handler.js.map +1 -1
  41. package/dist/esm/core/I18n.js +1 -2
  42. package/dist/esm/core/Util.js +15 -4
  43. package/dist/esm/core/Util.js.map +1 -1
  44. package/dist/esm/dom/DomEvent.DoubleTap.js +26 -24
  45. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  46. package/dist/esm/dom/DomEvent.PointerEvents.js +3 -18
  47. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  48. package/dist/esm/dom/DomEvent.js +18 -60
  49. package/dist/esm/dom/DomEvent.js.map +1 -1
  50. package/dist/esm/dom/DomUtil.js +15 -70
  51. package/dist/esm/dom/DomUtil.js.map +1 -1
  52. package/dist/esm/dom/Draggable.js +21 -21
  53. package/dist/esm/dom/Draggable.js.map +1 -1
  54. package/dist/esm/dom/PosAnimation.js +4 -27
  55. package/dist/esm/dom/PosAnimation.js.map +1 -1
  56. package/dist/esm/geo/LatLng.js +16 -7
  57. package/dist/esm/geo/LatLng.js.map +1 -1
  58. package/dist/esm/geo/LatLngBounds.js +9 -15
  59. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  60. package/dist/esm/geo/crs/CRS.js +1 -2
  61. package/dist/esm/geo/crs/EPSG3395.js +5 -6
  62. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  63. package/dist/esm/geo/crs/EPSG3857.js +5 -6
  64. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  65. package/dist/esm/geo/crs/EPSG4326.js +4 -5
  66. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  67. package/dist/esm/geo/crs/EarthCRS.js +3 -4
  68. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  69. package/dist/esm/geo/crs/SimpleCRS.js +4 -5
  70. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  71. package/dist/esm/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +5 -6
  72. package/dist/esm/geo/projection/LonLatProjection.js.map +1 -0
  73. package/dist/esm/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +4 -5
  74. package/dist/esm/geo/projection/MercatorProjection.js.map +1 -0
  75. package/dist/esm/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +5 -6
  76. package/dist/esm/geo/projection/SphericalMercatorProjection.js.map +1 -0
  77. package/dist/esm/geometry/Bounds.js +10 -14
  78. package/dist/esm/geometry/Bounds.js.map +1 -1
  79. package/dist/esm/geometry/LineUtil.js +37 -32
  80. package/dist/esm/geometry/LineUtil.js.map +1 -1
  81. package/dist/esm/geometry/Point.js +1 -2
  82. package/dist/esm/geometry/PolyUtil.js +24 -51
  83. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  84. package/dist/esm/geometry/Transformation.js +1 -2
  85. package/dist/esm/layer/BlanketOverlay.js +7 -10
  86. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  87. package/dist/esm/layer/Classification.js +1 -2
  88. package/dist/esm/layer/DivOverlay.js +16 -22
  89. package/dist/esm/layer/DivOverlay.js.map +1 -1
  90. package/dist/esm/layer/FeatureGroup.js +5 -4
  91. package/dist/esm/layer/FeatureGroup.js.map +1 -1
  92. package/dist/esm/layer/GeoJSON.Load.js +1 -2
  93. package/dist/esm/layer/GeoJSON.js +17 -155
  94. package/dist/esm/layer/GeoJSON.js.map +1 -1
  95. package/dist/esm/layer/GeoJSONUtil.js +74 -0
  96. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  97. package/dist/esm/layer/HeatLayer.js +17 -20
  98. package/dist/esm/layer/HeatLayer.js.map +1 -1
  99. package/dist/esm/layer/ImageOverlay.js +22 -29
  100. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  101. package/dist/esm/layer/Layer.js +9 -12
  102. package/dist/esm/layer/Layer.js.map +1 -1
  103. package/dist/esm/layer/LayerGroup.js +53 -3
  104. package/dist/esm/layer/LayerGroup.js.map +1 -1
  105. package/dist/esm/layer/Popup.js +35 -58
  106. package/dist/esm/layer/Popup.js.map +1 -1
  107. package/dist/esm/layer/SVGOverlay.js +3 -7
  108. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  109. package/dist/esm/layer/Tooltip.js +31 -34
  110. package/dist/esm/layer/Tooltip.js.map +1 -1
  111. package/dist/esm/layer/VideoOverlay.js +13 -17
  112. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  113. package/dist/esm/layer/marker/DefaultIcon.js +38 -49
  114. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  115. package/dist/esm/layer/marker/DivIcon.js +8 -11
  116. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  117. package/dist/esm/layer/marker/Icon.js +9 -12
  118. package/dist/esm/layer/marker/Icon.js.map +1 -1
  119. package/dist/esm/layer/marker/Marker.Drag.js +44 -5
  120. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  121. package/dist/esm/layer/marker/Marker.Move.js +5 -8
  122. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  123. package/dist/esm/layer/marker/Marker.js +115 -47
  124. package/dist/esm/layer/marker/Marker.js.map +1 -1
  125. package/dist/esm/layer/marker/MarkerClusterGroup.js +301 -0
  126. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  127. package/dist/esm/layer/marker/SvgIcon.js +7 -10
  128. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  129. package/dist/esm/layer/tile/GridLayer.js +89 -101
  130. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  131. package/dist/esm/layer/tile/TileLayer.js +36 -44
  132. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  133. package/dist/esm/layer/tile/WMSTileLayer.js +33 -27
  134. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  135. package/dist/esm/layer/vector/Canvas.js +8 -17
  136. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  137. package/dist/esm/layer/vector/Circle.js +6 -5
  138. package/dist/esm/layer/vector/Circle.js.map +1 -1
  139. package/dist/esm/layer/vector/CircleMarker.js +19 -10
  140. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  141. package/dist/esm/layer/vector/Path.DashAnimation.js +3 -5
  142. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  143. package/dist/esm/layer/vector/Path.ZoomStyles.js +1 -2
  144. package/dist/esm/layer/vector/Path.js +28 -22
  145. package/dist/esm/layer/vector/Path.js.map +1 -1
  146. package/dist/esm/layer/vector/Polygon.js +22 -7
  147. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  148. package/dist/esm/layer/vector/Polyline.Decorations.js +3 -4
  149. package/dist/esm/layer/vector/Polyline.js +25 -10
  150. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  151. package/dist/esm/layer/vector/Rectangle.js +1 -2
  152. package/dist/esm/layer/vector/Renderer.getRenderer.js +17 -17
  153. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  154. package/dist/esm/layer/vector/Renderer.js +1 -2
  155. package/dist/esm/layer/vector/SVG.js +12 -9
  156. package/dist/esm/layer/vector/SVG.js.map +1 -1
  157. package/dist/esm/map/Hash.js +1 -2
  158. package/dist/esm/map/Map.Rotation.js +41 -22
  159. package/dist/esm/map/Map.Rotation.js.map +1 -1
  160. package/dist/esm/map/Map.js +125 -126
  161. package/dist/esm/map/Map.js.map +1 -1
  162. package/dist/esm/map/MapSync.js +1 -2
  163. package/dist/esm/map/handler/BoxZoomHandler.js +25 -47
  164. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  165. package/dist/esm/map/handler/DisplaceHandler.js +7 -10
  166. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  167. package/dist/esm/map/handler/DoubleClickZoomHandler.js +1 -2
  168. package/dist/esm/map/handler/DragHandler.js +20 -21
  169. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  170. package/dist/esm/map/handler/KeyboardHandler.js +48 -68
  171. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  172. package/dist/esm/map/handler/PinchZoomHandler.js +13 -5
  173. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  174. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -6
  175. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  176. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -2
  177. package/dist/esm/map/handler/TapHoldHandler.js +13 -7
  178. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  179. package/dist/esm/package.js +2 -3
  180. package/dist/maplair-global-src.js +6495 -5981
  181. package/dist/maplair-global-src.js.map +1 -1
  182. package/dist/maplair-global.js +2 -2
  183. package/dist/maplair-global.js.map +1 -1
  184. package/dist/maplair-src.js +6206 -5673
  185. package/dist/maplair-src.js.map +1 -1
  186. package/dist/maplair.css +1 -1213
  187. package/dist/maplair.js +2 -2
  188. package/dist/maplair.js.map +1 -1
  189. package/i18n/cs.json +6 -0
  190. package/i18n/de.json +6 -0
  191. package/i18n/en.json +6 -0
  192. package/i18n/es.json +6 -0
  193. package/i18n/fr.json +6 -0
  194. package/i18n/hu.json +6 -0
  195. package/i18n/it.json +6 -0
  196. package/i18n/rm.json +6 -0
  197. package/i18n/sk.json +6 -0
  198. package/i18n/sl.json +6 -0
  199. package/package.json +11 -18
  200. package/src/Maplair.all.js +0 -1
  201. package/src/control/AttributionControl.js +25 -18
  202. package/src/control/ButtonControl.js +9 -11
  203. package/src/control/ContextMenu.js +3 -5
  204. package/src/control/Control.js +9 -19
  205. package/src/control/FullscreenControl.js +5 -7
  206. package/src/control/LayersControl.js +196 -86
  207. package/src/control/LegendControl.js +7 -9
  208. package/src/control/MiniMapControl.js +9 -11
  209. package/src/control/RotateControl.js +3 -5
  210. package/src/control/ScaleControl.js +7 -9
  211. package/src/control/SearchControl.js +102 -19
  212. package/src/control/SideBySideControl.js +3 -5
  213. package/src/control/TextControl.js +5 -7
  214. package/src/control/TimeControl.js +471 -0
  215. package/src/control/ZoomControl.js +22 -38
  216. package/src/control/index.js +1 -0
  217. package/src/core/Class.js +37 -45
  218. package/src/core/Events.js +22 -3
  219. package/src/core/Handler.js +25 -13
  220. package/src/core/Util.js +20 -2
  221. package/src/core/index.js +0 -1
  222. package/src/dom/DomEvent.DoubleTap.js +18 -10
  223. package/src/dom/DomEvent.PointerEvents.js +3 -26
  224. package/src/dom/DomEvent.js +17 -85
  225. package/src/dom/DomUtil.js +22 -78
  226. package/src/dom/Draggable.js +32 -23
  227. package/src/dom/PosAnimation.js +3 -25
  228. package/src/dom/index.js +0 -1
  229. package/src/geo/LatLng.js +20 -3
  230. package/src/geo/LatLngBounds.js +8 -15
  231. package/src/geo/crs/EPSG3395.js +4 -4
  232. package/src/geo/crs/EPSG3857.js +4 -4
  233. package/src/geo/crs/EPSG4326.js +3 -3
  234. package/src/geo/crs/EarthCRS.js +2 -8
  235. package/src/geo/crs/SimpleCRS.js +3 -3
  236. package/src/geo/index.js +1 -2
  237. package/src/geo/projection/{Projection.LonLat.js → LonLatProjection.js} +2 -2
  238. package/src/geo/projection/{Projection.Mercator.js → MercatorProjection.js} +2 -2
  239. package/src/geo/projection/{Projection.SphericalMercator.js → SphericalMercatorProjection.js} +2 -2
  240. package/src/geo/projection/index.js +5 -5
  241. package/src/geometry/Bounds.js +12 -17
  242. package/src/geometry/LineUtil.js +48 -49
  243. package/src/geometry/PolyUtil.js +39 -76
  244. package/src/layer/BlanketOverlay.js +6 -10
  245. package/src/layer/DivOverlay.js +16 -27
  246. package/src/layer/FeatureGroup.js +8 -2
  247. package/src/layer/GeoJSON.js +17 -218
  248. package/src/layer/GeoJSONUtil.js +85 -0
  249. package/src/layer/HeatLayer.js +10 -12
  250. package/src/layer/ImageOverlay.js +21 -32
  251. package/src/layer/Layer.js +8 -10
  252. package/src/layer/LayerGroup.js +72 -1
  253. package/src/layer/Popup.js +37 -62
  254. package/src/layer/SVGOverlay.js +1 -5
  255. package/src/layer/Tooltip.js +34 -36
  256. package/src/layer/VideoOverlay.js +12 -15
  257. package/src/layer/marker/DefaultIcon.js +40 -58
  258. package/src/layer/marker/DivIcon.js +9 -11
  259. package/src/layer/marker/Icon.js +9 -10
  260. package/src/layer/marker/Marker.Drag.js +54 -6
  261. package/src/layer/marker/Marker.Move.js +4 -6
  262. package/src/layer/marker/Marker.js +145 -52
  263. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  264. package/src/layer/marker/SvgIcon.js +7 -9
  265. package/src/layer/marker/index.js +1 -0
  266. package/src/layer/tile/GridLayer.js +108 -135
  267. package/src/layer/tile/TileLayer.js +44 -49
  268. package/src/layer/tile/WMSTileLayer.js +31 -26
  269. package/src/layer/vector/Canvas.js +13 -19
  270. package/src/layer/vector/Circle.js +9 -3
  271. package/src/layer/vector/CircleMarker.js +19 -7
  272. package/src/layer/vector/Path.DashAnimation.js +1 -2
  273. package/src/layer/vector/Path.js +30 -21
  274. package/src/layer/vector/Polygon.js +29 -6
  275. package/src/layer/vector/Polyline.js +26 -7
  276. package/src/layer/vector/Renderer.getRenderer.js +20 -19
  277. package/src/layer/vector/SVG.js +17 -7
  278. package/src/map/Map.Rotation.js +40 -8
  279. package/src/map/Map.js +158 -153
  280. package/src/map/handler/BoxZoomHandler.js +30 -50
  281. package/src/map/handler/DisplaceHandler.js +6 -8
  282. package/src/map/handler/DragHandler.js +25 -28
  283. package/src/map/handler/KeyboardHandler.js +65 -90
  284. package/src/map/handler/PinchZoomHandler.js +16 -5
  285. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  286. package/src/map/handler/TapHoldHandler.js +15 -4
  287. package/src/map/index.js +1 -1
  288. package/src/maplair.css +153 -98
  289. package/dist/esm/core/Browser.js +0 -100
  290. package/dist/esm/core/Browser.js.map +0 -1
  291. package/dist/esm/geo/projection/Projection.LonLat.js.map +0 -1
  292. package/dist/esm/geo/projection/Projection.Mercator.js.map +0 -1
  293. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +0 -1
  294. package/dist/esm/geo/projection/index.js +0 -14
  295. package/dist/esm/geo/projection/index.js.map +0 -1
  296. package/dist/esm/layer/marker/Marker.Rotation.js +0 -70
  297. package/dist/esm/layer/marker/Marker.Rotation.js.map +0 -1
  298. package/dist/images/layers.svg +0 -1
  299. package/dist/images/marker-icon.svg +0 -1
  300. package/dist/images/marker-shadow.svg +0 -1
  301. package/src/core/Browser.js +0 -110
  302. package/src/images/layers.svg +0 -1
  303. package/src/images/marker-icon.svg +0 -1
  304. package/src/images/marker-shadow.svg +0 -1
  305. package/src/layer/marker/Marker.Rotation.js +0 -103
@@ -1,9 +1,9 @@
1
- import { off, on, stop } from "../../dom/DomEvent.js";
2
- import { create, disableImageDrag, disableTextSelection, enableImageDrag, enableTextSelection, setPosition } from "../../dom/DomUtil.js";
1
+ import { off, on, preventDefault, stop } from "../../dom/DomEvent.js";
2
+ import { create, setPosition } from "../../dom/DomUtil.js";
3
3
  import { Bounds } from "../../geometry/Bounds.js";
4
4
  import { LatLngBounds } from "../../geo/LatLngBounds.js";
5
5
  import { Handler } from "../../core/Handler.js";
6
- //#region src/map/handler/BoxZoomHandler.js
6
+ // src/map/handler/BoxZoomHandler.js
7
7
  /** @import {MaplairMap} from '../Map.js' */
8
8
  /** @import {MaplairEvent} from '../../core/Events.js' */
9
9
  /**
@@ -40,23 +40,19 @@ var BoxZoomHandler = class BoxZoomHandler extends Handler {
40
40
  */
41
41
  constructor(map) {
42
42
  super(map);
43
- this._container = map._container;
44
- this._pane = map._panes.overlayPane;
45
- this._resetStateTimeout = 0;
46
- map.on("unload", this._destroy, this);
47
43
  this.callInitHooks(BoxZoomHandler);
48
44
  }
49
45
  /**
50
46
  * Called when the handler is enabled, adds the event hooks.
51
47
  */
52
48
  addHooks() {
53
- on(this._container, "pointerdown", this._onPointerDown, this);
49
+ on(this._map._container, "pointerdown", this._onPointerDown, this);
54
50
  }
55
51
  /**
56
52
  * Called when the handler is disabled, removes the event hooks.
57
53
  */
58
54
  removeHooks() {
59
- off(this._container, "pointerdown", this._onPointerDown, this);
55
+ off(this._map._container, "pointerdown", this._onPointerDown, this);
60
56
  }
61
57
  /**
62
58
  * Returns `true` if a box has been drawn by the current or last interaction.
@@ -65,43 +61,34 @@ var BoxZoomHandler = class BoxZoomHandler extends Handler {
65
61
  moved() {
66
62
  return this._moved;
67
63
  }
68
- _destroy() {
69
- this._pane.remove();
70
- delete this._pane;
71
- }
72
64
  _resetState() {
73
- this._resetStateTimeout = 0;
65
+ clearTimeout(this._resetStateTimeout);
74
66
  this._moved = false;
75
67
  }
76
- _clearDeferredResetState() {
77
- if (this._resetStateTimeout !== 0) {
78
- clearTimeout(this._resetStateTimeout);
79
- this._resetStateTimeout = 0;
80
- }
68
+ _toggleListeners(onOff) {
69
+ onOff(this._map._container, {
70
+ contextmenu: stop,
71
+ pointermove: this._onPointerMove,
72
+ pointerup: this._onPointerUp
73
+ }, this);
74
+ onOff(document, "keydown", this._onKeyDown, this);
81
75
  }
82
76
  _onPointerDown(e) {
83
77
  if (!e.shiftKey || e.button !== 0) return false;
84
- this._clearDeferredResetState();
85
78
  this._resetState();
86
- disableTextSelection();
87
- disableImageDrag();
79
+ preventDefault(e);
88
80
  this._startPoint = this._map.pointerEventToContainerPoint(e);
89
- on(this._container, {
90
- contextmenu: stop,
91
- pointermove: this._onPointerMove,
92
- pointerup: this._onPointerUp,
93
- keydown: this._onKeyDown
94
- }, this);
95
- on(document, "keydown", this._onKeyDown, this);
81
+ this._toggleListeners(on);
96
82
  }
97
83
  _onPointerMove(e) {
84
+ const map = this._map;
98
85
  if (!this._moved) {
99
86
  this._moved = true;
100
- this._box = create("div", "maplair-zoom-box", this._container);
101
- this._container.classList.add("maplair-crosshair");
102
- this._map.fire("boxzoomstart");
87
+ this._box = create("div", "maplair-zoom-box", map._container);
88
+ map._container.classList.add("maplair-crosshair");
89
+ map.fire("boxzoomstart");
103
90
  }
104
- this._point = this._map.pointerEventToContainerPoint(e);
91
+ this._point = map.pointerEventToContainerPoint(e);
105
92
  const bounds = new Bounds(this._point, this._startPoint), size = bounds.getSize();
106
93
  setPosition(this._box, bounds.min);
107
94
  this._box.style.width = `${size.x}px`;
@@ -110,31 +97,23 @@ var BoxZoomHandler = class BoxZoomHandler extends Handler {
110
97
  _finish() {
111
98
  if (this._moved) {
112
99
  this._box.remove();
113
- this._container.classList.remove("maplair-crosshair");
100
+ this._map._container.classList.remove("maplair-crosshair");
114
101
  }
115
- enableTextSelection();
116
- enableImageDrag();
117
- off(this._container, {
118
- contextmenu: stop,
119
- pointermove: this._onPointerMove,
120
- pointerup: this._onPointerUp
121
- }, this);
122
- off(document, "keydown", this._onKeyDown, this);
102
+ this._toggleListeners(off);
123
103
  }
124
104
  _onPointerUp(e) {
125
105
  if (e.button !== 0) return;
126
106
  this._finish();
127
107
  if (!this._moved) return;
128
- this._clearDeferredResetState();
129
- this._resetStateTimeout = setTimeout(this._resetState.bind(this), 0);
108
+ this._resetStateTimeout = setTimeout(() => this._resetState(), 0);
130
109
  const bounds = new LatLngBounds(this._map.containerPointToLatLng(this._startPoint), this._map.containerPointToLatLng(this._point));
131
110
  this._map._setUserEvent(e);
132
- this._map.fitBounds(bounds).fire("boxzoomend", { boxZoomBounds: bounds });
111
+ if (this._map.getBoundsZoom(bounds) !== Infinity) this._map.fitBounds(bounds);
112
+ this._map.fire("boxzoomend", { boxZoomBounds: bounds });
133
113
  }
134
114
  _onKeyDown(e) {
135
115
  if (e.code === "Escape") {
136
116
  this._finish();
137
- this._clearDeferredResetState();
138
117
  this._resetState();
139
118
  }
140
119
  }
@@ -148,7 +127,6 @@ var BoxZoomHandler = class BoxZoomHandler extends Handler {
148
127
  MaplairMap.addInitHook("addHandler", "boxZoom", BoxZoomHandler);
149
128
  }
150
129
  };
151
- //#endregion
152
130
  export { BoxZoomHandler };
153
131
 
154
132
  //# sourceMappingURL=BoxZoomHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BoxZoomHandler.js","names":["DomEvent.stop","DomUtil.create"],"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._container = map._container;\n\t\tthis._pane = map._panes.overlayPane;\n\t\tthis._resetStateTimeout = 0;\n\t\tmap.on('unload', this._destroy, this);\n\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._container, 'pointerdown', this._onPointerDown, 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._container, 'pointerdown', this._onPointerDown, this);\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_destroy() {\n\t\tthis._pane.remove();\n\t\tdelete this._pane;\n\t}\n\n\t_resetState() {\n\t\tthis._resetStateTimeout = 0;\n\t\tthis._moved = false;\n\t}\n\n\t_clearDeferredResetState() {\n\t\tif (this._resetStateTimeout !== 0) {\n\t\t\tclearTimeout(this._resetStateTimeout);\n\t\t\tthis._resetStateTimeout = 0;\n\t\t}\n\t}\n\n\t_onPointerDown(e) {\n\t\tif (!e.shiftKey || (e.button !== 0)) { return false; }\n\n\t\t// Clear the deferred resetState if it hasn't executed yet, otherwise it\n\t\t// will interrupt the interaction and orphan a box element in the container.\n\t\tthis._clearDeferredResetState();\n\t\tthis._resetState();\n\n\t\tDomUtil.disableTextSelection();\n\t\tDomUtil.disableImageDrag();\n\n\t\tthis._startPoint = this._map.pointerEventToContainerPoint(e);\n\n\t\tDomEvent.on(this._container, {\n\t\t\tcontextmenu: DomEvent.stop,\n\t\t\tpointermove: this._onPointerMove,\n\t\t\tpointerup: this._onPointerUp,\n\t\t\tkeydown: this._onKeyDown\n\t\t}, this);\n\t\tDomEvent.on(document, 'keydown', this._onKeyDown, this);\n\t}\n\n\t_onPointerMove(e) {\n\t\tif (!this._moved) {\n\t\t\tthis._moved = true;\n\n\t\t\tthis._box = DomUtil.create('div', 'maplair-zoom-box', this._container);\n\t\t\tthis._container.classList.add('maplair-crosshair');\n\n\t\t\tthis._map.fire('boxzoomstart');\n\t\t}\n\n\t\tthis._point = this._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._container.classList.remove('maplair-crosshair');\n\t\t}\n\n\t\tDomUtil.enableTextSelection();\n\t\tDomUtil.enableImageDrag();\n\n\t\tDomEvent.off(this._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\tDomEvent.off(document, 'keydown', this._onKeyDown, this);\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._clearDeferredResetState();\n\t\tthis._resetStateTimeout = setTimeout(this._resetState.bind(this), 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\tthis._map\n\t\t\t.fitBounds(bounds)\n\t\t\t.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._clearDeferredResetState();\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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;EAEtB,YAAoB,KAAK,MAAM,OAAO,GAAG;EAEzC,KAAK,KAAK,MAAM,QAAS,GAAG,KAAK,EAAE;EACnC,KAAK,KAAK,MAAM,SAAS,GAAG,KAAK,EAAE;CACpC;CAEA,UAAU;EACT,IAAI,KAAK,QAAQ;GAChB,KAAK,KAAK,OAAO;GACjB,KAAK,WAAW,UAAU,OAAO,mBAAmB;EACrD;EAEA,oBAA4B;EAC5B,gBAAwB;EAExB,IAAa,KAAK,YAAY;GAC7B,aAAaD;GACb,aAAa,KAAK;GAClB,WAAW,KAAK;EACjB,GAAG,IAAI;EACP,IAAa,UAAU,WAAW,KAAK,YAAY,IAAI;CACxD;CAEA,aAAa,GAAG;EACf,IAAI,EAAE,WAAW,GAAK;EAEtB,KAAK,QAAQ;EAEb,IAAI,CAAC,KAAK,QAAU;EAGpB,KAAK,yBAAyB;EAC9B,KAAK,qBAAqB,WAAW,KAAK,YAAY,KAAK,IAAI,GAAG,CAAC;EAEnE,MAAM,SAAS,IAAI,aAClB,KAAK,KAAK,uBAAuB,KAAK,WAAW,GACjD,KAAK,KAAK,uBAAuB,KAAK,MAAM,CAAC;EAE9C,KAAK,KAAK,cAAc,CAAC;EACzB,KAAK,KACH,UAAU,MAAM,CAAC,CACjB,KAAK,cAAc,EAAC,eAAe,OAAM,CAAC;CAC7C;CAEA,WAAW,GAAG;EACb,IAAI,EAAE,SAAS,UAAU;GACxB,KAAK,QAAQ;GACb,KAAK,yBAAyB;GAC9B,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}\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}\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;CAC3E;;;;CAKA,cAAc;EACb,IAAa,KAAK,KAAK,YAAY,eAAe,KAAK,gBAAgB,IAAI;CAC5E;;;;;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,UAA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AAK,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"}
@@ -2,7 +2,7 @@ import { setOptions } from "../../core/Util.js";
2
2
  import { Point } from "../../geometry/Point.js";
3
3
  import { CircleMarker } from "../../layer/vector/CircleMarker.js";
4
4
  import { Handler } from "../../core/Handler.js";
5
- //#region src/map/handler/DisplaceHandler.js
5
+ // src/map/handler/DisplaceHandler.js
6
6
  /** @import {MaplairMap} from '../Map.js' */
7
7
  /** @import {Layer} from '../../layer/Layer.js' */
8
8
  /** @import {LayerEvent} from '../../core/Events.js' */
@@ -88,13 +88,11 @@ function displaceable(layer) {
88
88
  * ```
89
89
  */
90
90
  var DisplaceHandler = class DisplaceHandler extends Handler {
91
- static {
92
- this.setDefaultOptions({
93
- gap: 2,
94
- iterations: 80,
95
- maxDistance: Infinity
96
- });
97
- }
91
+ static defaultOptions = {
92
+ gap: 2,
93
+ iterations: 80,
94
+ maxDistance: Infinity
95
+ };
98
96
  /**
99
97
  * @param {...MaplairMap} args The map.
100
98
  */
@@ -273,7 +271,7 @@ var DisplaceHandler = class DisplaceHandler extends Handler {
273
271
  * @param {{ iterations?: number, maxDisplacement?: number }} [options]
274
272
  * @returns {Point[]} the same (displaced) points
275
273
  */
276
- function displace(points, minSeparation, { iterations = DisplaceHandler.prototype.options.iterations, maxDisplacement = Infinity } = {}) {
274
+ function displace(points, minSeparation, { iterations = DisplaceHandler.defaultOptions.iterations, maxDisplacement = Infinity } = {}) {
277
275
  const n = points.length;
278
276
  if (n < 2) return points;
279
277
  const sep = minSeparation;
@@ -343,7 +341,6 @@ function displace(points, minSeparation, { iterations = DisplaceHandler.prototyp
343
341
  }
344
342
  return points;
345
343
  }
346
- //#endregion
347
344
  export { DisplaceHandler, displace };
348
345
 
349
346
  //# sourceMappingURL=DisplaceHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DisplaceHandler.js","names":[],"sources":["../../../../src/map/handler/DisplaceHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as Util from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.js';\nimport {CircleMarker} from '../../layer/vector/CircleMarker.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {Layer} from '../../layer/Layer.js' */\n/** @import {LayerEvent} from '../../core/Events.js' */\n/** @import {LatLng} from '../../geo/LatLng.js' */\n\n/**\n * Options of `DisplaceHandler`.\n * @typedef {object} DisplaceHandlerOptions\n * @property {number} [gap=2] Additional pixel distance between the outlines of two\n * markers.\n * @property {number} [iterations=80] Maximum number of relaxation passes per relayout.\n * @property {number} [maxDistance=Infinity] Maximum distance in meters a marker may be\n * moved away from its true position. Markers which would have to move further stay\n * overlapping. Meters rather than pixels, since the point of the limit is to bound the\n * geographic error. A limit in meters also scales itself: it only bites at the zoom\n * levels where a pixel is worth a lot of ground.\n */\n\n/**\n * Map options of `DisplaceHandler`, the interaction options for displacement.\n * @typedef {object} DisplaceHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|DisplaceHandlerOptions} [displace] Whether to displace\n * overlapping `CircleMarker`s, either `true` or an object overriding the options of\n * `DisplaceHandler`. Needs the `DisplaceHandler` to be added to the map, see there.\n */\n\n/**\n * Handler of `MaplairMap` for displacement, if added to the map (see `DisplaceHandler`).\n * @typedef {object} DisplaceHandlerMapProperties\n * @lends MaplairMap\n * @property {DisplaceHandler} [displace] The displacement handler, if added with the\n * name `displace`.\n */\n\n/**\n * Options of `CircleMarker` for the displacement by `DisplaceHandler`.\n * @typedef {object} DisplaceCircleMarkerOptions\n * @lends CircleMarkerOptions\n * @property {boolean} [displace] Whether to include this marker in the displacement of\n * the map, see `DisplaceHandler`.\n * @property {string} [displaceId] Stable identifier shared across marker instances that\n * represent the same thing on different layers, so that `DisplaceHandler` puts them at\n * the same displaced position.\n */\n\n/**\n * Whether a layer takes part in the displacement. Only these change the layout, so layers\n * that merely come and go on top of the markers — the highlight circle around a tapped or\n * searched bobble, for one — must not trigger a relayout of all of them.\n * @param {Layer} layer\n * @returns {boolean}\n */\nfunction displaceable(layer) {\n\treturn layer instanceof CircleMarker && !!layer.options.displace;\n}\n\n/**\n * Cartographic displacement of overlapping `CircleMarker`s: keeps all circle\n * markers created with `displace: true` free of overlap.\n *\n * Overlap is a screen space phenomenon: whether two markers cover each other\n * depends on their pixel radius and the current zoom level. The displacement is\n * therefore computed in projected pixel space and recomputed on every zoom. The\n * true position of each marker is kept by the handler, the displaced position is\n * applied via `setLatLng`. Since every run starts over from the true position,\n * markers never drift.\n *\n * `maxDistance` bounds how far a marker may be moved away from the truth, in\n * meters. It is worth noting what such a limit costs at low zoom levels: if a\n * marker is 11 km wide on the ground, separating two coincident ones moves each\n * of them by some 6 km, so a limit below that leaves them overlapping.\n *\n * Unlike the default handlers, it isn't added to every map, so that bundlers can\n * drop it from applications that don't use it. Add it to the map class (or to a\n * single map with `DisplaceHandler.addTo(map, 'displace')`), then enable it with\n * the map option `displace`, which is either `true` or an object overriding the\n * handler's options. It can be toggled at runtime via `map.displace.enable()` /\n * `map.displace.disable()`; disabling restores the true positions.\n *\n * @example\n * ```js\n * import { CircleMarker, DisplaceHandler, MaplairMap } from 'maplair';\n *\n * MaplairMap.addInitHook('addHandler', 'displace', DisplaceHandler);\n *\n * const map = new MaplairMap('map', {displace: { maxDistance: 10_000} });\n * new CircleMarker(latlng, { displace: true, radius: 6 }).addTo(map);\n * ```\n */\nexport class DisplaceHandler extends Handler {\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tgap: 2,\n\t\t\titerations: 80,\n\t\t\tmaxDistance: Infinity\n\t\t});\n\t}\n\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\t// the map option `displace` is either `true` or an object overriding the defaults\n\t\tUtil.setOptions(this, this._map.options.displace);\n\n\t\t/**\n\t\t * True (undisplaced) position per marker, kept outside of the marker so that\n\t\t * the displacement cannot clobber it and re-added markers keep their anchor.\n\t\t * @type {WeakMap<CircleMarker, LatLng>}\n\t\t */\n\t\tthis._trueLatLngs = new WeakMap();\n\n\t\t/**\n\t\t * Displaced position per `marker.options.displaceId`, per zoom level. Different\n\t\t * layers (e.g. one per classification) may create separate `CircleMarker`\n\t\t * instances for the same thing; keying by id instead of by marker instance\n\t\t * keeps it at the same displaced position regardless of which layer triggered\n\t\t * the relayout. Cleared whenever a true position changes.\n\t\t * @type {Map<number, Map<string, LatLng>>}\n\t\t */\n\t\tthis._displacedPositions = new Map();\n\n\t\tthis.callInitHooks(DisplaceHandler);\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.on('zoomend', this.schedule, this);\n\t\tthis._map.on('layeradd', this._onLayerAdd, this);\n\t\tthis._map.on('layerremove', this._onLayerRemove, this);\n\t\tthis._map.eachLayer(layer => this._track(layer));\n\t\tthis.schedule();\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks and restores the\n\t * true positions of the markers.\n\t */\n\tremoveHooks() {\n\t\tthis._map.off('zoomend', this.schedule, this);\n\t\tthis._map.off('layeradd', this._onLayerAdd, this);\n\t\tthis._map.off('layerremove', this._onLayerRemove, this);\n\t\tif (this._frame) { cancelAnimationFrame(this._frame); }\n\t\tthis._frame = undefined;\n\t\tthis._restore();\n\t}\n\n\t/**\n\t * Requests a relayout in the next animation frame, at most one per frame.\n\t */\n\tschedule() {\n\t\tif (this._frame) {\n\t\t\treturn;\n\t\t}\n\t\tthis._frame = requestAnimationFrame(() => {\n\t\t\tthis._frame = undefined;\n\t\t\tthis.relayout();\n\t\t});\n\t}\n\n\t/**\n\t * Computes the displacement for all tracked markers in the pixel space of\n\t * the current zoom level and writes the displaced positions back.\n\t */\n\trelayout() {\n\t\tconst map = this._map;\n\t\t/** @type {CircleMarker[]} */\n\t\tconst markers = [];\n\t\tmap.eachLayer((layer) => {\n\t\t\tif (this._trueLatLngs.has(layer)) {\n\t\t\t\tmarkers.push(layer);\n\t\t\t}\n\t\t});\n\t\tif (markers.length < 2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst zoom = map.getZoom();\n\t\tlet cache = this._displacedPositions.get(zoom);\n\t\tif (!cache) {\n\t\t\tcache = new Map();\n\t\t\tthis._displacedPositions.set(zoom, cache);\n\t\t}\n\n\t\t// If every currently visible marker already has a cached position for\n\t\t// this zoom (e.g. the same stations shown on a different layer), reuse\n\t\t// it as-is instead of recomputing the relaxation.\n\t\tif (markers.every(marker => marker.options.displaceId && cache.has(marker.options.displaceId))) {\n\t\t\tfor (const marker of markers) {\n\t\t\t\tthis._moveTo(marker, cache.get(marker.options.displaceId));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst {gap, iterations, maxDistance} = this.options;\n\t\tconst points = markers.map(marker => map.project(this._trueLatLngs.get(marker), zoom));\n\n\t\t// Usually a uniform radius per zoom level; max() as a safeguard.\n\t\tconst radius = markers.reduce((r, marker) => Math.max(r, marker.getRadius()), 0);\n\t\tdisplace(points, 2 * radius + gap, {iterations, maxDisplacement: maxDistance * this._pixelsPerMeter(zoom)});\n\n\t\tfor (let i = 0; i < markers.length; i++) {\n\t\t\tconst latLng = map.unproject(points[i], zoom);\n\t\t\tthis._moveTo(markers[i], latLng);\n\t\t\tif (markers[i].options.displaceId) {\n\t\t\t\tcache.set(markers[i].options.displaceId, latLng);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Scale of the map at `zoom`, measured with the CRS of the map at its\n\t * center. Since a relayout only ever covers one screen, the scale variation\n\t * across the view is ignored.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\t_pixelsPerMeter(zoom) {\n\t\tconst map = this._map;\n\t\tconst center = map.getCenter();\n\t\tconst east = map.unproject(map.project(center, zoom).add(new Point(100, 0)), zoom);\n\t\treturn 100 / map.distance(center, east);\n\t}\n\n\t/**\n\t * Moves a marker to its displaced (or true) position, without taking that\n\t * for a new true position, see `_onMarkerMove`.\n\t * @param {CircleMarker} marker\n\t * @param {LatLng} latLng\n\t */\n\t_moveTo(marker, latLng) {\n\t\tthis._moving = true;\n\t\ttry {\n\t\t\tmarker.setLatLng(latLng);\n\t\t} finally {\n\t\t\tthis._moving = false;\n\t\t}\n\t}\n\n\t/**\n\t * A tracked marker was moved by the application: that is its new true position,\n\t * which invalidates the cached displaced positions.\n\t * @param {Event} event\n\t */\n\t_onMarkerMove(event) {\n\t\tif (this._moving) { return; }\n\t\tthis._trueLatLngs.set(event.target, event.latlng);\n\t\tthis._displacedPositions.clear();\n\t\tif (this._enabled && this._map.hasLayer(event.target)) { this.schedule(); }\n\t}\n\n\t/**\n\t * @param {LayerEvent} event\n\t */\n\t_onLayerAdd(event) {\n\t\tthis._track(event.layer);\n\t\tif (displaceable(event.layer)) { this.schedule(); }\n\t}\n\n\t/**\n\t * @param {LayerEvent} event\n\t */\n\t_onLayerRemove(event) {\n\t\tif (displaceable(event.layer)) { this.schedule(); }\n\t}\n\n\t/**\n\t * Remembers the true position of a marker opted in via `displace: true`.\n\t * Markers seen before keep their previously stored position, so re-adding a\n\t * displaced marker does not anchor it to its displaced position.\n\t * @param {Layer} layer\n\t */\n\t_track(layer) {\n\t\tif (!displaceable(layer)) {\n\t\t\treturn;\n\t\t}\n\t\tif (!this._trueLatLngs.has(layer)) {\n\t\t\tthis._trueLatLngs.set(layer, layer.getLatLng());\n\t\t\tlayer.on('move', this._onMarkerMove, this);\n\t\t}\n\t}\n\n\t/**\n\t * Moves all tracked markers back to their true position.\n\t */\n\t_restore() {\n\t\tthis._map.eachLayer((layer) => {\n\t\t\tconst latLng = this._trueLatLngs.get(layer);\n\t\t\tif (latLng) { this._moveTo(layer, latLng); }\n\t\t});\n\t}\n}\n\n/**\n * Displaces overlapping points in pixel space until they are at least\n * `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed\n * apart by half of its overlap per pass. Neighbour lookup uses a grid (cell\n * size = separation) ⇒ O(n) per iteration.\n *\n * No point ends up further than `maxDisplacement` away from where it started.\n * Points which hit that limit stay overlapping – the limit wins over the\n * separation.\n *\n * @param {Point[]} points Pixel coordinates (modified in place)\n * @param {number} minSeparation Minimum distance between centers, in pixels\n * @param {{ iterations?: number, maxDisplacement?: number }} [options]\n * @returns {Point[]} the same (displaced) points\n */\nexport function displace(\n\tpoints,\n\tminSeparation,\n\t{iterations = DisplaceHandler.prototype.options.iterations, maxDisplacement = Infinity} = {},\n) {\n\tconst n = points.length;\n\tif (n < 2) { return points; }\n\n\tconst sep = minSeparation;\n\tconst sepSq = sep * sep;\n\tconst cell = sep;\n\tconst dx = new Float64Array(n);\n\tconst dy = new Float64Array(n);\n\t// Anchors for `maxDisplacement`, the true positions of the points.\n\tconst ax = Float64Array.from(points, point => point.x);\n\tconst ay = Float64Array.from(points, point => point.y);\n\n\tfor (let iter = 0; iter < iterations; iter++) {\n\t\tdx.fill(0);\n\t\tdy.fill(0);\n\n\t\t// Sort the points into a grid (cell size = separation).\n\t\t/** @type {Map<string, number[]>} */\n\t\tconst grid = new Map();\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst key = `${Math.floor(points[i].x / cell)},${Math.floor(points[i].y / cell)}`;\n\t\t\tconst bucket = grid.get(key);\n\t\t\tif (bucket) {\n\t\t\t\tbucket.push(i);\n\t\t\t} else {\n\t\t\t\tgrid.set(key, [i]);\n\t\t\t}\n\t\t}\n\n\t\tlet overlaps = 0;\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst cx = Math.floor(points[i].x / cell);\n\t\t\tconst cy = Math.floor(points[i].y / cell);\n\t\t\t// Only the 3×3 neighbouring cells can be closer than `sep`.\n\t\t\tfor (let gx = cx - 1; gx <= cx + 1; gx++) {\n\t\t\t\tfor (let gy = cy - 1; gy <= cy + 1; gy++) {\n\t\t\t\t\tconst bucket = grid.get(`${gx},${gy}`);\n\t\t\t\t\tif (!bucket) { continue; }\n\t\t\t\t\tfor (const j of bucket) {\n\t\t\t\t\t\tif (j <= i) { continue; } // visit every pair once\n\t\t\t\t\t\tlet vx = points[i].x - points[j].x;\n\t\t\t\t\t\tlet vy = points[i].y - points[j].y;\n\t\t\t\t\t\tconst distSq = vx * vx + vy * vy;\n\t\t\t\t\t\tif (distSq >= sepSq) { continue; }\n\t\t\t\t\t\toverlaps++;\n\n\t\t\t\t\t\tlet dist;\n\t\t\t\t\t\tif (distSq === 0) {\n\t\t\t\t\t\t\t// Coincident points: deterministic direction derived\n\t\t\t\t\t\t\t// from the index (golden angle) instead of random.\n\t\t\t\t\t\t\tconst angle = i * 2.399963229728653;\n\t\t\t\t\t\t\tvx = Math.cos(angle);\n\t\t\t\t\t\t\tvy = Math.sin(angle);\n\t\t\t\t\t\t\tdist = 1;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdist = Math.sqrt(distSq);\n\t\t\t\t\t\t\tvx /= dist;\n\t\t\t\t\t\t\tvy /= dist;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst push = (sep - dist) / 2;\n\t\t\t\t\t\tdx[i] += vx * push;\n\t\t\t\t\t\tdy[i] += vy * push;\n\t\t\t\t\t\tdx[j] -= vx * push;\n\t\t\t\t\t\tdy[j] -= vy * push;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (overlaps === 0) {\n\t\t\tbreak; // converged – nothing left to do\n\t\t}\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tpoints[i].x += dx[i];\n\t\t\tpoints[i].y += dy[i];\n\n\t\t\t// Pull the point back onto the circle of radius `maxDisplacement`\n\t\t\t// around its anchor. Clamping inside the loop (instead of once at\n\t\t\t// the end) lets the following iterations redistribute along that\n\t\t\t// circle rather than piling up against it.\n\t\t\tconst ox = points[i].x - ax[i];\n\t\t\tconst oy = points[i].y - ay[i];\n\t\t\tconst offsetSq = ox * ox + oy * oy;\n\t\t\tif (offsetSq > maxDisplacement * maxDisplacement) {\n\t\t\t\tconst scale = maxDisplacement / Math.sqrt(offsetSq);\n\t\t\t\tpoints[i].x = ax[i] + ox * scale;\n\t\t\t\tpoints[i].y = ay[i] + oy * scale;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn points;\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAS,aAAa,OAAO;CAC5B,OAAO,iBAAiB,gBAAgB,CAAC,CAAC,MAAM,QAAQ;AACzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,kBAAb,MAAa,wBAAwB,QAAQ;CAC5C;EACC,KAAK,kBAAkB;GACtB,KAAK;GACL,YAAY;GACZ,aAAa;EACd,CAAC;CACF;;;;CAKA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EAEb,WAAgB,MAAM,KAAK,KAAK,QAAQ,QAAQ;;;;;;EAOhD,KAAK,+BAAe,IAAI,QAAQ;;;;;;;;;EAUhC,KAAK,sCAAsB,IAAI,IAAI;EAEnC,KAAK,cAAc,eAAe;CACnC;;;;CAKA,WAAW;EACV,KAAK,KAAK,GAAG,WAAW,KAAK,UAAU,IAAI;EAC3C,KAAK,KAAK,GAAG,YAAY,KAAK,aAAa,IAAI;EAC/C,KAAK,KAAK,GAAG,eAAe,KAAK,gBAAgB,IAAI;EACrD,KAAK,KAAK,WAAU,UAAS,KAAK,OAAO,KAAK,CAAC;EAC/C,KAAK,SAAS;CACf;;;;;CAMA,cAAc;EACb,KAAK,KAAK,IAAI,WAAW,KAAK,UAAU,IAAI;EAC5C,KAAK,KAAK,IAAI,YAAY,KAAK,aAAa,IAAI;EAChD,KAAK,KAAK,IAAI,eAAe,KAAK,gBAAgB,IAAI;EACtD,IAAI,KAAK,QAAU,qBAAqB,KAA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d,IAAI,KAAK,OAAO,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC;KACjC,IAAI,KAAK,OAAO,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC;KACjC,MAAM,SAAS,KAAK,KAAK,KAAK;KAC9B,IAAI,UAAU,OAAS;KACvB;KAEA,IAAI;KACJ,IAAI,WAAW,GAAG;MAGjB,MAAM,QAAQ,IAAI;MAClB,KAAK,KAAK,IAAI,KAAK;MACnB,KAAK,KAAK,IAAI,KAAK;MACnB,OAAO;KACR,OAAO;MACN,OAAO,KAAK,KAAK,MAAM;MACvB,MAAM;MACN,MAAM;KACP;KAEA,MAAM,QAAQ,MAAM,QAAQ;KAC5B,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;IACf;GACD;EAEF;EAEA,IAAI,aAAa,GAChB;EAED,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;GAC3B,OAAO,EAAE,CAAC,KAAK,GAAG;GAClB,OAAO,EAAE,CAAC,KAAK,GAAG;GAMlB,MAAM,KAAK,OAAO,EAAE,CAAC,IAAI,GAAG;GAC5B,MAAM,KAAK,OAAO,EAAE,CAAC,IAAI,GAAG;GAC5B,MAAM,WAAW,KAAK,KAAK,KAAK;GAChC,IAAI,WAAW,kBAAkB,iBAAiB;IACjD,MAAM,QAAQ,kBAAkB,KAAK,KAAK,QAAQ;IAClD,OAAO,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK;IAC3B,OAAO,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK;GAC5B;EACD;CACD;CAEA,OAAO;AACR"}
1
+ {"version":3,"file":"DisplaceHandler.js","names":[],"sources":["../../../../src/map/handler/DisplaceHandler.js"],"sourcesContent":["import {Handler} from '../../core/Handler.js';\nimport * as Util from '../../core/Util.js';\nimport {Point} from '../../geometry/Point.js';\nimport {CircleMarker} from '../../layer/vector/CircleMarker.js';\n/** @import {MaplairMap} from '../Map.js' */\n/** @import {Layer} from '../../layer/Layer.js' */\n/** @import {LayerEvent} from '../../core/Events.js' */\n/** @import {LatLng} from '../../geo/LatLng.js' */\n\n/**\n * Options of `DisplaceHandler`.\n * @typedef {object} DisplaceHandlerOptions\n * @property {number} [gap=2] Additional pixel distance between the outlines of two\n * markers.\n * @property {number} [iterations=80] Maximum number of relaxation passes per relayout.\n * @property {number} [maxDistance=Infinity] Maximum distance in meters a marker may be\n * moved away from its true position. Markers which would have to move further stay\n * overlapping. Meters rather than pixels, since the point of the limit is to bound the\n * geographic error. A limit in meters also scales itself: it only bites at the zoom\n * levels where a pixel is worth a lot of ground.\n */\n\n/**\n * Map options of `DisplaceHandler`, the interaction options for displacement.\n * @typedef {object} DisplaceHandlerMapOptions\n * @lends MaplairMapOptions\n * @property {boolean|DisplaceHandlerOptions} [displace] Whether to displace\n * overlapping `CircleMarker`s, either `true` or an object overriding the options of\n * `DisplaceHandler`. Needs the `DisplaceHandler` to be added to the map, see there.\n */\n\n/**\n * Handler of `MaplairMap` for displacement, if added to the map (see `DisplaceHandler`).\n * @typedef {object} DisplaceHandlerMapProperties\n * @lends MaplairMap\n * @property {DisplaceHandler} [displace] The displacement handler, if added with the\n * name `displace`.\n */\n\n/**\n * Options of `CircleMarker` for the displacement by `DisplaceHandler`.\n * @typedef {object} DisplaceCircleMarkerOptions\n * @lends CircleMarkerOptions\n * @property {boolean} [displace] Whether to include this marker in the displacement of\n * the map, see `DisplaceHandler`.\n * @property {string} [displaceId] Stable identifier shared across marker instances that\n * represent the same thing on different layers, so that `DisplaceHandler` puts them at\n * the same displaced position.\n */\n\n/**\n * Whether a layer takes part in the displacement. Only these change the layout, so layers\n * that merely come and go on top of the markers — the highlight circle around a tapped or\n * searched bobble, for one — must not trigger a relayout of all of them.\n * @param {Layer} layer\n * @returns {boolean}\n */\nfunction displaceable(layer) {\n\treturn layer instanceof CircleMarker && !!layer.options.displace;\n}\n\n/**\n * Cartographic displacement of overlapping `CircleMarker`s: keeps all circle\n * markers created with `displace: true` free of overlap.\n *\n * Overlap is a screen space phenomenon: whether two markers cover each other\n * depends on their pixel radius and the current zoom level. The displacement is\n * therefore computed in projected pixel space and recomputed on every zoom. The\n * true position of each marker is kept by the handler, the displaced position is\n * applied via `setLatLng`. Since every run starts over from the true position,\n * markers never drift.\n *\n * `maxDistance` bounds how far a marker may be moved away from the truth, in\n * meters. It is worth noting what such a limit costs at low zoom levels: if a\n * marker is 11 km wide on the ground, separating two coincident ones moves each\n * of them by some 6 km, so a limit below that leaves them overlapping.\n *\n * Unlike the default handlers, it isn't added to every map, so that bundlers can\n * drop it from applications that don't use it. Add it to the map class (or to a\n * single map with `DisplaceHandler.addTo(map, 'displace')`), then enable it with\n * the map option `displace`, which is either `true` or an object overriding the\n * handler's options. It can be toggled at runtime via `map.displace.enable()` /\n * `map.displace.disable()`; disabling restores the true positions.\n *\n * @example\n * ```js\n * import { CircleMarker, DisplaceHandler, MaplairMap } from 'maplair';\n *\n * MaplairMap.addInitHook('addHandler', 'displace', DisplaceHandler);\n *\n * const map = new MaplairMap('map', {displace: { maxDistance: 10_000} });\n * new CircleMarker(latlng, { displace: true, radius: 6 }).addTo(map);\n * ```\n */\nexport class DisplaceHandler extends Handler {\n\tstatic defaultOptions = {\n\t\tgap: 2,\n\t\titerations: 80,\n\t\tmaxDistance: Infinity\n\t};\n\n\t/**\n\t * @param {...MaplairMap} args The map.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\t// the map option `displace` is either `true` or an object overriding the defaults\n\t\tUtil.setOptions(this, this._map.options.displace);\n\n\t\t/**\n\t\t * True (undisplaced) position per marker, kept outside of the marker so that\n\t\t * the displacement cannot clobber it and re-added markers keep their anchor.\n\t\t * @type {WeakMap<CircleMarker, LatLng>}\n\t\t */\n\t\tthis._trueLatLngs = new WeakMap();\n\n\t\t/**\n\t\t * Displaced position per `marker.options.displaceId`, per zoom level. Different\n\t\t * layers (e.g. one per classification) may create separate `CircleMarker`\n\t\t * instances for the same thing; keying by id instead of by marker instance\n\t\t * keeps it at the same displaced position regardless of which layer triggered\n\t\t * the relayout. Cleared whenever a true position changes.\n\t\t * @type {Map<number, Map<string, LatLng>>}\n\t\t */\n\t\tthis._displacedPositions = new Map();\n\n\t\tthis.callInitHooks(DisplaceHandler);\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.on('zoomend', this.schedule, this);\n\t\tthis._map.on('layeradd', this._onLayerAdd, this);\n\t\tthis._map.on('layerremove', this._onLayerRemove, this);\n\t\tthis._map.eachLayer(layer => this._track(layer));\n\t\tthis.schedule();\n\t}\n\n\t/**\n\t * Called when the handler is disabled, removes the event hooks and restores the\n\t * true positions of the markers.\n\t */\n\tremoveHooks() {\n\t\tthis._map.off('zoomend', this.schedule, this);\n\t\tthis._map.off('layeradd', this._onLayerAdd, this);\n\t\tthis._map.off('layerremove', this._onLayerRemove, this);\n\t\tif (this._frame) { cancelAnimationFrame(this._frame); }\n\t\tthis._frame = undefined;\n\t\tthis._restore();\n\t}\n\n\t/**\n\t * Requests a relayout in the next animation frame, at most one per frame.\n\t */\n\tschedule() {\n\t\tif (this._frame) {\n\t\t\treturn;\n\t\t}\n\t\tthis._frame = requestAnimationFrame(() => {\n\t\t\tthis._frame = undefined;\n\t\t\tthis.relayout();\n\t\t});\n\t}\n\n\t/**\n\t * Computes the displacement for all tracked markers in the pixel space of\n\t * the current zoom level and writes the displaced positions back.\n\t */\n\trelayout() {\n\t\tconst map = this._map;\n\t\t/** @type {CircleMarker[]} */\n\t\tconst markers = [];\n\t\tmap.eachLayer((layer) => {\n\t\t\tif (this._trueLatLngs.has(layer)) {\n\t\t\t\tmarkers.push(layer);\n\t\t\t}\n\t\t});\n\t\tif (markers.length < 2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst zoom = map.getZoom();\n\t\tlet cache = this._displacedPositions.get(zoom);\n\t\tif (!cache) {\n\t\t\tcache = new Map();\n\t\t\tthis._displacedPositions.set(zoom, cache);\n\t\t}\n\n\t\t// If every currently visible marker already has a cached position for\n\t\t// this zoom (e.g. the same stations shown on a different layer), reuse\n\t\t// it as-is instead of recomputing the relaxation.\n\t\tif (markers.every(marker => marker.options.displaceId && cache.has(marker.options.displaceId))) {\n\t\t\tfor (const marker of markers) {\n\t\t\t\tthis._moveTo(marker, cache.get(marker.options.displaceId));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst {gap, iterations, maxDistance} = this.options;\n\t\tconst points = markers.map(marker => map.project(this._trueLatLngs.get(marker), zoom));\n\n\t\t// Usually a uniform radius per zoom level; max() as a safeguard.\n\t\tconst radius = markers.reduce((r, marker) => Math.max(r, marker.getRadius()), 0);\n\t\tdisplace(points, 2 * radius + gap, {iterations, maxDisplacement: maxDistance * this._pixelsPerMeter(zoom)});\n\n\t\tfor (let i = 0; i < markers.length; i++) {\n\t\t\tconst latLng = map.unproject(points[i], zoom);\n\t\t\tthis._moveTo(markers[i], latLng);\n\t\t\tif (markers[i].options.displaceId) {\n\t\t\t\tcache.set(markers[i].options.displaceId, latLng);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Scale of the map at `zoom`, measured with the CRS of the map at its\n\t * center. Since a relayout only ever covers one screen, the scale variation\n\t * across the view is ignored.\n\t * @param {number} zoom\n\t * @returns {number}\n\t */\n\t_pixelsPerMeter(zoom) {\n\t\tconst map = this._map;\n\t\tconst center = map.getCenter();\n\t\tconst east = map.unproject(map.project(center, zoom).add(new Point(100, 0)), zoom);\n\t\treturn 100 / map.distance(center, east);\n\t}\n\n\t/**\n\t * Moves a marker to its displaced (or true) position, without taking that\n\t * for a new true position, see `_onMarkerMove`.\n\t * @param {CircleMarker} marker\n\t * @param {LatLng} latLng\n\t */\n\t_moveTo(marker, latLng) {\n\t\tthis._moving = true;\n\t\ttry {\n\t\t\tmarker.setLatLng(latLng);\n\t\t} finally {\n\t\t\tthis._moving = false;\n\t\t}\n\t}\n\n\t/**\n\t * A tracked marker was moved by the application: that is its new true position,\n\t * which invalidates the cached displaced positions.\n\t * @param {Event} event\n\t */\n\t_onMarkerMove(event) {\n\t\tif (this._moving) { return; }\n\t\tthis._trueLatLngs.set(event.target, event.latlng);\n\t\tthis._displacedPositions.clear();\n\t\tif (this._enabled && this._map.hasLayer(event.target)) { this.schedule(); }\n\t}\n\n\t/**\n\t * @param {LayerEvent} event\n\t */\n\t_onLayerAdd(event) {\n\t\tthis._track(event.layer);\n\t\tif (displaceable(event.layer)) { this.schedule(); }\n\t}\n\n\t/**\n\t * @param {LayerEvent} event\n\t */\n\t_onLayerRemove(event) {\n\t\tif (displaceable(event.layer)) { this.schedule(); }\n\t}\n\n\t/**\n\t * Remembers the true position of a marker opted in via `displace: true`.\n\t * Markers seen before keep their previously stored position, so re-adding a\n\t * displaced marker does not anchor it to its displaced position.\n\t * @param {Layer} layer\n\t */\n\t_track(layer) {\n\t\tif (!displaceable(layer)) {\n\t\t\treturn;\n\t\t}\n\t\tif (!this._trueLatLngs.has(layer)) {\n\t\t\tthis._trueLatLngs.set(layer, layer.getLatLng());\n\t\t\tlayer.on('move', this._onMarkerMove, this);\n\t\t}\n\t}\n\n\t/**\n\t * Moves all tracked markers back to their true position.\n\t */\n\t_restore() {\n\t\tthis._map.eachLayer((layer) => {\n\t\t\tconst latLng = this._trueLatLngs.get(layer);\n\t\t\tif (latLng) { this._moveTo(layer, latLng); }\n\t\t});\n\t}\n}\n\n/**\n * Displaces overlapping points in pixel space until they are at least\n * `minSeparation` apart. Iterative relaxation: every overlapping pair is pushed\n * apart by half of its overlap per pass. Neighbour lookup uses a grid (cell\n * size = separation) ⇒ O(n) per iteration.\n *\n * No point ends up further than `maxDisplacement` away from where it started.\n * Points which hit that limit stay overlapping – the limit wins over the\n * separation.\n *\n * @param {Point[]} points Pixel coordinates (modified in place)\n * @param {number} minSeparation Minimum distance between centers, in pixels\n * @param {{ iterations?: number, maxDisplacement?: number }} [options]\n * @returns {Point[]} the same (displaced) points\n */\nexport function displace(\n\tpoints,\n\tminSeparation,\n\t{iterations = DisplaceHandler.defaultOptions.iterations, maxDisplacement = Infinity} = {},\n) {\n\tconst n = points.length;\n\tif (n < 2) { return points; }\n\n\tconst sep = minSeparation;\n\tconst sepSq = sep * sep;\n\tconst cell = sep;\n\tconst dx = new Float64Array(n);\n\tconst dy = new Float64Array(n);\n\t// Anchors for `maxDisplacement`, the true positions of the points.\n\tconst ax = Float64Array.from(points, point => point.x);\n\tconst ay = Float64Array.from(points, point => point.y);\n\n\tfor (let iter = 0; iter < iterations; iter++) {\n\t\tdx.fill(0);\n\t\tdy.fill(0);\n\n\t\t// Sort the points into a grid (cell size = separation).\n\t\t/** @type {Map<string, number[]>} */\n\t\tconst grid = new Map();\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst key = `${Math.floor(points[i].x / cell)},${Math.floor(points[i].y / cell)}`;\n\t\t\tconst bucket = grid.get(key);\n\t\t\tif (bucket) {\n\t\t\t\tbucket.push(i);\n\t\t\t} else {\n\t\t\t\tgrid.set(key, [i]);\n\t\t\t}\n\t\t}\n\n\t\tlet overlaps = 0;\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst cx = Math.floor(points[i].x / cell);\n\t\t\tconst cy = Math.floor(points[i].y / cell);\n\t\t\t// Only the 3×3 neighbouring cells can be closer than `sep`.\n\t\t\tfor (let gx = cx - 1; gx <= cx + 1; gx++) {\n\t\t\t\tfor (let gy = cy - 1; gy <= cy + 1; gy++) {\n\t\t\t\t\tconst bucket = grid.get(`${gx},${gy}`);\n\t\t\t\t\tif (!bucket) { continue; }\n\t\t\t\t\tfor (const j of bucket) {\n\t\t\t\t\t\tif (j <= i) { continue; } // visit every pair once\n\t\t\t\t\t\tlet vx = points[i].x - points[j].x;\n\t\t\t\t\t\tlet vy = points[i].y - points[j].y;\n\t\t\t\t\t\tconst distSq = vx * vx + vy * vy;\n\t\t\t\t\t\tif (distSq >= sepSq) { continue; }\n\t\t\t\t\t\toverlaps++;\n\n\t\t\t\t\t\tlet dist;\n\t\t\t\t\t\tif (distSq === 0) {\n\t\t\t\t\t\t\t// Coincident points: deterministic direction derived\n\t\t\t\t\t\t\t// from the index (golden angle) instead of random.\n\t\t\t\t\t\t\tconst angle = i * 2.399963229728653;\n\t\t\t\t\t\t\tvx = Math.cos(angle);\n\t\t\t\t\t\t\tvy = Math.sin(angle);\n\t\t\t\t\t\t\tdist = 1;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdist = Math.sqrt(distSq);\n\t\t\t\t\t\t\tvx /= dist;\n\t\t\t\t\t\t\tvy /= dist;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst push = (sep - dist) / 2;\n\t\t\t\t\t\tdx[i] += vx * push;\n\t\t\t\t\t\tdy[i] += vy * push;\n\t\t\t\t\t\tdx[j] -= vx * push;\n\t\t\t\t\t\tdy[j] -= vy * push;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (overlaps === 0) {\n\t\t\tbreak; // converged – nothing left to do\n\t\t}\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tpoints[i].x += dx[i];\n\t\t\tpoints[i].y += dy[i];\n\n\t\t\t// Pull the point back onto the circle of radius `maxDisplacement`\n\t\t\t// around its anchor. Clamping inside the loop (instead of once at\n\t\t\t// the end) lets the following iterations redistribute along that\n\t\t\t// circle rather than piling up against it.\n\t\t\tconst ox = points[i].x - ax[i];\n\t\t\tconst oy = points[i].y - ay[i];\n\t\t\tconst offsetSq = ox * ox + oy * oy;\n\t\t\tif (offsetSq > maxDisplacement * maxDisplacement) {\n\t\t\t\tconst scale = maxDisplacement / Math.sqrt(offsetSq);\n\t\t\t\tpoints[i].x = ax[i] + ox * scale;\n\t\t\t\tpoints[i].y = ay[i] + oy * scale;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn points;\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SA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AM;MACN,MAAM;KACP;KAEA,MAAM,QAAQ,MAAM,QAAQ;KAC5B,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;KACd,GAAG,MAAM,KAAK;IACf;GACD;EAEF;EAEA,IAAI,aAAa,GAChB;EAED,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;GAC3B,OAAO,EAAE,CAAC,KAAK,GAAG;GAClB,OAAO,EAAE,CAAC,KAAK,GAAG;GAMlB,MAAM,KAAK,OAAO,EAAE,CAAC,IAAI,GAAG;GAC5B,MAAM,KAAK,OAAO,EAAE,CAAC,IAAI,GAAG;GAC5B,MAAM,WAAW,KAAK,KAAK,KAAK;GAChC,IAAI,WAAW,kBAAkB,iBAAiB;IACjD,MAAM,QAAQ,kBAAkB,KAAK,KAAK,QAAQ;IAClD,OAAO,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK;IAC3B,OAAO,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK;GAC5B;EACD;CACD;CAEA,OAAO;AACR"}
@@ -1,5 +1,5 @@
1
1
  import { Handler } from "../../core/Handler.js";
2
- //#region src/map/handler/DoubleClickZoomHandler.js
2
+ // src/map/handler/DoubleClickZoomHandler.js
3
3
  /** @import {MaplairMap} from '../Map.js' */
4
4
  /**
5
5
  * Map options of `DoubleClickZoomHandler`.
@@ -65,7 +65,6 @@ var DoubleClickZoomHandler = class DoubleClickZoomHandler extends Handler {
65
65
  MaplairMap.addInitHook("addHandler", "doubleClickZoom", DoubleClickZoomHandler);
66
66
  }
67
67
  };
68
- //#endregion
69
68
  export { DoubleClickZoomHandler };
70
69
 
71
70
  //# sourceMappingURL=DoubleClickZoomHandler.js.map
@@ -1,9 +1,8 @@
1
- import { Point } from "../../geometry/Point.js";
2
1
  import { Bounds } from "../../geometry/Bounds.js";
3
2
  import { LatLngBounds } from "../../geo/LatLngBounds.js";
4
3
  import { Handler } from "../../core/Handler.js";
5
4
  import { Draggable } from "../../dom/Draggable.js";
6
- //#region src/map/handler/DragHandler.js
5
+ // src/map/handler/DragHandler.js
7
6
  /** @import {MaplairMap} from '../Map.js' */
8
7
  /** @import {MaplairEvent, DragEndEvent} from '../../core/Events.js' */
9
8
  /**
@@ -16,13 +15,14 @@ import { Draggable } from "../../dom/Draggable.js";
16
15
  * the same direction for some time. Feels especially nice on touch devices.
17
16
  * @property {number} [inertiaDeceleration=3400] The rate with which the inertial
18
17
  * movement slows down, in pixels/second².
19
- * @property {number} [inertiaMaxSpeed=Infinity] Max speed of the inertial movement,
18
+ * @property {number} [inertiaMaxSpeed=1400] Max speed of the inertial movement,
20
19
  * in pixels/second.
21
20
  * @property {number} [easeLinearity=0.2] The linearity of the easing of the inertial
22
21
  * movement.
23
22
  * @property {boolean} [worldCopyJump=false] With this option enabled, the map tracks
24
23
  * when you pan to another "copy" of the world and seamlessly jumps to the original one
25
- * so that all overlays like markers and vector layers are still visible.
24
+ * so that all overlays like markers and vector layers are still visible. A map with an
25
+ * infinite CRS, such as `SimpleCRS`, does not jump, as it has no copies of the world.
26
26
  * @property {number} [maxBoundsViscosity=0.0] If `maxBounds` is set, this option will
27
27
  * control how solid the bounds are when dragging the map around. The default value of
28
28
  * `0.0` allows the user to drag outside the bounds at normal speed, higher values will
@@ -59,16 +59,13 @@ var DragHandler = class DragHandler extends Handler {
59
59
  const map = this._map;
60
60
  this._draggable = new Draggable(map._mapPane, map._container);
61
61
  this._draggable.on({
62
+ down: this._onDown,
62
63
  dragstart: this._onDragStart,
63
64
  drag: this._onDrag,
64
65
  dragend: this._onDragEnd
65
66
  }, this);
66
67
  this._draggable.on("predrag", this._onPreDragLimit, this);
67
- if (map.options.worldCopyJump) {
68
- this._draggable.on("predrag", this._onPreDragWrap, this);
69
- map.on("zoomend crschange", this._onZoomEnd, this);
70
- map.whenReady(this._onZoomEnd, this);
71
- }
68
+ if (map.options.worldCopyJump) this._draggable.on("predrag", this._onPreDragWrap, this);
72
69
  }
73
70
  this._map._container.classList.add("maplair-grab", "maplair-touch-drag");
74
71
  this._draggable.enable();
@@ -96,6 +93,9 @@ var DragHandler = class DragHandler extends Handler {
96
93
  moving() {
97
94
  return this._draggable?._moving;
98
95
  }
96
+ _onDown() {
97
+ this._map._stop();
98
+ }
99
99
  _onDragStart(e) {
100
100
  const map = this._map;
101
101
  map._stop();
@@ -126,11 +126,6 @@ var DragHandler = class DragHandler extends Handler {
126
126
  this._times.shift();
127
127
  }
128
128
  }
129
- _onZoomEnd() {
130
- const pxCenter = this._map.getSize().divideBy(2), pxWorldCenter = this._map.latLngToLayerPoint([0, 0]);
131
- this._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x;
132
- this._worldWidth = this._map.getPixelWorldBounds().getSize().x;
133
- }
134
129
  _viscousLimit(value, threshold) {
135
130
  return value - (value - threshold) * this._viscosity;
136
131
  }
@@ -145,9 +140,9 @@ var DragHandler = class DragHandler extends Handler {
145
140
  this._draggable._newPos = this._draggable._startPos.add(offset);
146
141
  }
147
142
  _onPreDragWrap() {
148
- const worldWidth = this._worldWidth, halfWidth = Math.round(worldWidth / 2), dx = this._initialWorldOffset, x = this._draggable._newPos.x, newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx, newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx, newX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2;
149
- this._draggable._absPos = new Point(this._draggable._newPos);
150
- this._draggable._newPos.x = newX;
143
+ const draggable = this._draggable;
144
+ draggable._absPos = draggable._newPos;
145
+ draggable._newPos = this._map._wrapWorldCopy(draggable._newPos);
151
146
  }
152
147
  _onDragEnd(e) {
153
148
  const map = this._map, options = map.options, noInertia = !options.inertia || e.noInertia || this._times.length < 2;
@@ -155,8 +150,13 @@ var DragHandler = class DragHandler extends Handler {
155
150
  if (noInertia) map.fire("moveend");
156
151
  else {
157
152
  this._prunePositions(Date.now());
158
- const direction = this._lastPos.subtract(this._positions[0]), duration = (this._lastTime - this._times[0]) / 1e3, ease = options.easeLinearity, speedVector = direction.multiplyBy(ease / duration), speed = speedVector.distanceTo([0, 0]), limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed), decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease);
159
- let offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
153
+ const direction = this._lastPos.subtract(this._positions[0]), duration = (this._lastTime - this._times[0]) / 1e3, ease = options.easeLinearity, speedVector = direction.multiplyBy(ease / duration), speed = speedVector.distanceTo([0, 0]), limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed), maxOffset = map.getSize().divideBy(2);
154
+ let decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease), offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
155
+ if (map._prefersReducedMotion() && !maxOffset.contains(offset)) {
156
+ const k = Math.min(maxOffset.x / Math.abs(offset.x), maxOffset.y / Math.abs(offset.y));
157
+ offset = offset.multiplyBy(k).round();
158
+ decelerationDuration *= Math.sqrt(k);
159
+ }
160
160
  if (!offset.x && !offset.y) map.fire("moveend");
161
161
  else {
162
162
  offset = map._limitOffset(offset, map.options.maxBounds);
@@ -181,7 +181,7 @@ var DragHandler = class DragHandler extends Handler {
181
181
  dragging: true,
182
182
  inertia: true,
183
183
  inertiaDeceleration: 3400,
184
- inertiaMaxSpeed: Infinity,
184
+ inertiaMaxSpeed: 1400,
185
185
  easeLinearity: .2,
186
186
  worldCopyJump: false,
187
187
  maxBoundsViscosity: 0
@@ -189,7 +189,6 @@ var DragHandler = class DragHandler extends Handler {
189
189
  MaplairMap.addInitHook("addHandler", "dragging", DragHandler);
190
190
  }
191
191
  };
192
- //#endregion
193
192
  export { DragHandler };
194
193
 
195
194
  //# sourceMappingURL=DragHandler.js.map
@@ -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';\nimport {Point} from '../../geometry/Point.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=Infinity] 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.\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\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\tmap.on('zoomend crschange', this._onZoomEnd, this);\n\n\t\t\t\tmap.whenReady(this._onZoomEnd, 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_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_onZoomEnd() {\n\t\tconst pxCenter = this._map.getSize().divideBy(2),\n\t\tpxWorldCenter = this._map.latLngToLayerPoint([0, 0]);\n\n\t\tthis._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x;\n\t\tthis._worldWidth = this._map.getPixelWorldBounds().getSize().x;\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\t// TODO refactor to be able to adjust map pane position after zoom\n\t\tconst worldWidth = this._worldWidth,\n\t\thalfWidth = Math.round(worldWidth / 2),\n\t\tdx = this._initialWorldOffset,\n\t\tx = this._draggable._newPos.x,\n\t\tnewX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx,\n\t\tnewX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx,\n\t\tnewX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2;\n\n\t\tthis._draggable._absPos = new Point(this._draggable._newPos);\n\t\tthis._draggable._newPos.x = newX;\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\tdecelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease);\n\t\t\tlet offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();\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: Infinity, // 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,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;CAKA,WAAW;EACV,IAAI,CAAC,KAAK,YAAY;GACrB,MAAM,MAAM,KAAK;GAEjB,KAAK,aAAa,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU;GAE5D,KAAK,WAAW,GAAG;IAClB,WAAW,KAAK;IAChB,MAAM,KAAK;IACX,SAAS,KAAK;GACf,GAAG,IAAI;GAEP,KAAK,WAAW,GAAG,WAAW,KAAK,iBAAiB,IAAI;GACxD,IAAI,IAAI,QAAQ,eAAe;IAC9B,KAAK,WAAW,GAAG,WAAW,KAAK,gBAAgB,IAAI;IACvD,IAAI,GAAG,qBAAqB,KAAK,YAAY,IAAI;IAEjD,IAAI,UAAU,KAAK,YAAY,IAAI;GACpC;EACD;EACA,KA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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\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;;;;CAIxC,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;CAKA,WAAW;EACV,IAAI,CAAC,KAAK,YAAY;GACrB,MAAM,MAAM,KAAK;GAEjB,KAAK,aAAa,IAAI,UAAU,IAAI,UAAU,IAAI,UAAU;GAE5D,KAAK,WAAW,GAAG;IAClB,MAAM,KAAK;IACX,WAAW,KAAK;IAChB,MAAM,KAAK;IACX,SAAS,KAAK;GACf,GAAG,IAAI;GAEP,KAAK,WAAW,GAAG,WAAW,KAAK,iBAAiB,IAAI;GACxD,IAAI,IAAI,QAAQ,eACf,KAAK,WAAW,GAAG,WAAW,KAAK,gB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