maplair 4.0.0-alpha.1

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 (262) hide show
  1. package/CHANGELOG.md +2804 -0
  2. package/LICENSE +27 -0
  3. package/README.md +40 -0
  4. package/dist/esm/Maplair.js +71 -0
  5. package/dist/esm/Maplair.js.map +1 -0
  6. package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
  7. package/dist/esm/control/AttributionControl.js +79 -0
  8. package/dist/esm/control/AttributionControl.js.map +1 -0
  9. package/dist/esm/control/Control.js +81 -0
  10. package/dist/esm/control/Control.js.map +1 -0
  11. package/dist/esm/control/LayersControl.js +220 -0
  12. package/dist/esm/control/LayersControl.js.map +1 -0
  13. package/dist/esm/control/ScaleControl.js +72 -0
  14. package/dist/esm/control/ScaleControl.js.map +1 -0
  15. package/dist/esm/control/ZoomControl.js +86 -0
  16. package/dist/esm/control/ZoomControl.js.map +1 -0
  17. package/dist/esm/core/Browser.js +31 -0
  18. package/dist/esm/core/Browser.js.map +1 -0
  19. package/dist/esm/core/Class.js +52 -0
  20. package/dist/esm/core/Class.js.map +1 -0
  21. package/dist/esm/core/Events.js +149 -0
  22. package/dist/esm/core/Events.js.map +1 -0
  23. package/dist/esm/core/Handler.js +32 -0
  24. package/dist/esm/core/Handler.js.map +1 -0
  25. package/dist/esm/core/I18n.js +36 -0
  26. package/dist/esm/core/I18n.js.map +1 -0
  27. package/dist/esm/core/Util.js +71 -0
  28. package/dist/esm/core/Util.js.map +1 -0
  29. package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
  30. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
  31. package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
  32. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
  33. package/dist/esm/dom/DomEvent.js +135 -0
  34. package/dist/esm/dom/DomEvent.js.map +1 -0
  35. package/dist/esm/dom/DomUtil.js +107 -0
  36. package/dist/esm/dom/DomUtil.js.map +1 -0
  37. package/dist/esm/dom/Draggable.js +107 -0
  38. package/dist/esm/dom/Draggable.js.map +1 -0
  39. package/dist/esm/dom/PosAnimation.js +56 -0
  40. package/dist/esm/dom/PosAnimation.js.map +1 -0
  41. package/dist/esm/geo/LatLng.js +65 -0
  42. package/dist/esm/geo/LatLng.js.map +1 -0
  43. package/dist/esm/geo/LatLngBounds.js +114 -0
  44. package/dist/esm/geo/LatLngBounds.js.map +1 -0
  45. package/dist/esm/geo/crs/CRS.js +51 -0
  46. package/dist/esm/geo/crs/CRS.js.map +1 -0
  47. package/dist/esm/geo/crs/EPSG3395.js +16 -0
  48. package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
  49. package/dist/esm/geo/crs/EPSG3857.js +19 -0
  50. package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
  51. package/dist/esm/geo/crs/EPSG4326.js +13 -0
  52. package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
  53. package/dist/esm/geo/crs/EarthCRS.js +14 -0
  54. package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
  55. package/dist/esm/geo/crs/SimpleCRS.js +23 -0
  56. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
  57. package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
  58. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
  59. package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
  60. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
  61. package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
  62. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
  63. package/dist/esm/geo/projection/index.js +14 -0
  64. package/dist/esm/geo/projection/index.js.map +1 -0
  65. package/dist/esm/geometry/Bounds.js +91 -0
  66. package/dist/esm/geometry/Bounds.js.map +1 -0
  67. package/dist/esm/geometry/LineUtil.js +169 -0
  68. package/dist/esm/geometry/LineUtil.js.map +1 -0
  69. package/dist/esm/geometry/Point.js +119 -0
  70. package/dist/esm/geometry/Point.js.map +1 -0
  71. package/dist/esm/geometry/PolyUtil.js +89 -0
  72. package/dist/esm/geometry/PolyUtil.js.map +1 -0
  73. package/dist/esm/geometry/Transformation.js +34 -0
  74. package/dist/esm/geometry/Transformation.js.map +1 -0
  75. package/dist/esm/layer/BlanketOverlay.js +87 -0
  76. package/dist/esm/layer/BlanketOverlay.js.map +1 -0
  77. package/dist/esm/layer/DivOverlay.js +192 -0
  78. package/dist/esm/layer/DivOverlay.js.map +1 -0
  79. package/dist/esm/layer/FeatureGroup.js +40 -0
  80. package/dist/esm/layer/FeatureGroup.js.map +1 -0
  81. package/dist/esm/layer/GeoJSON.js +192 -0
  82. package/dist/esm/layer/GeoJSON.js.map +1 -0
  83. package/dist/esm/layer/ImageOverlay.js +140 -0
  84. package/dist/esm/layer/ImageOverlay.js.map +1 -0
  85. package/dist/esm/layer/Layer.js +119 -0
  86. package/dist/esm/layer/Layer.js.map +1 -0
  87. package/dist/esm/layer/LayerGroup.js +58 -0
  88. package/dist/esm/layer/LayerGroup.js.map +1 -0
  89. package/dist/esm/layer/Popup.js +224 -0
  90. package/dist/esm/layer/Popup.js.map +1 -0
  91. package/dist/esm/layer/SVGOverlay.js +21 -0
  92. package/dist/esm/layer/SVGOverlay.js.map +1 -0
  93. package/dist/esm/layer/Tooltip.js +228 -0
  94. package/dist/esm/layer/Tooltip.js.map +1 -0
  95. package/dist/esm/layer/VideoOverlay.js +54 -0
  96. package/dist/esm/layer/VideoOverlay.js.map +1 -0
  97. package/dist/esm/layer/marker/DefaultIcon.js +50 -0
  98. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
  99. package/dist/esm/layer/marker/DivIcon.js +37 -0
  100. package/dist/esm/layer/marker/DivIcon.js.map +1 -0
  101. package/dist/esm/layer/marker/Icon.js +65 -0
  102. package/dist/esm/layer/marker/Icon.js.map +1 -0
  103. package/dist/esm/layer/marker/Marker.Drag.js +77 -0
  104. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
  105. package/dist/esm/layer/marker/Marker.js +235 -0
  106. package/dist/esm/layer/marker/Marker.js.map +1 -0
  107. package/dist/esm/layer/tile/GridLayer.js +447 -0
  108. package/dist/esm/layer/tile/GridLayer.js.map +1 -0
  109. package/dist/esm/layer/tile/TileLayer.js +139 -0
  110. package/dist/esm/layer/tile/TileLayer.js.map +1 -0
  111. package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
  112. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
  113. package/dist/esm/layer/vector/Canvas.js +292 -0
  114. package/dist/esm/layer/vector/Canvas.js.map +1 -0
  115. package/dist/esm/layer/vector/Circle.js +35 -0
  116. package/dist/esm/layer/vector/Circle.js.map +1 -0
  117. package/dist/esm/layer/vector/CircleMarker.js +69 -0
  118. package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
  119. package/dist/esm/layer/vector/Path.js +68 -0
  120. package/dist/esm/layer/vector/Path.js.map +1 -0
  121. package/dist/esm/layer/vector/Polygon.js +70 -0
  122. package/dist/esm/layer/vector/Polygon.js.map +1 -0
  123. package/dist/esm/layer/vector/Polyline.js +152 -0
  124. package/dist/esm/layer/vector/Polyline.js.map +1 -0
  125. package/dist/esm/layer/vector/Rectangle.js +25 -0
  126. package/dist/esm/layer/vector/Rectangle.js.map +1 -0
  127. package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
  128. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
  129. package/dist/esm/layer/vector/Renderer.js +39 -0
  130. package/dist/esm/layer/vector/Renderer.js.map +1 -0
  131. package/dist/esm/layer/vector/SVG.js +115 -0
  132. package/dist/esm/layer/vector/SVG.js.map +1 -0
  133. package/dist/esm/map/Map.js +844 -0
  134. package/dist/esm/map/Map.js.map +1 -0
  135. package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
  136. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
  137. package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
  138. package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
  139. package/dist/esm/map/handler/DragHandler.js +133 -0
  140. package/dist/esm/map/handler/DragHandler.js.map +1 -0
  141. package/dist/esm/map/handler/KeyboardHandler.js +117 -0
  142. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
  143. package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
  144. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
  145. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
  146. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
  147. package/dist/esm/map/handler/TapHoldHandler.js +77 -0
  148. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
  149. package/dist/esm/package.js +6 -0
  150. package/dist/esm/package.js.map +1 -0
  151. package/dist/images/layers.svg +1 -0
  152. package/dist/images/logo.svg +1 -0
  153. package/dist/images/marker-icon.svg +1 -0
  154. package/dist/images/marker-shadow.svg +1 -0
  155. package/dist/maplair-global-src.js +6810 -0
  156. package/dist/maplair-global-src.js.map +1 -0
  157. package/dist/maplair-global.js +12 -0
  158. package/dist/maplair-global.js.map +1 -0
  159. package/dist/maplair-src.js +6704 -0
  160. package/dist/maplair-src.js.map +1 -0
  161. package/dist/maplair.css +730 -0
  162. package/dist/maplair.js +7 -0
  163. package/dist/maplair.js.map +1 -0
  164. package/i18n/cs.json +12 -0
  165. package/i18n/de.json +12 -0
  166. package/i18n/en.json +12 -0
  167. package/i18n/es.json +12 -0
  168. package/i18n/fr.json +12 -0
  169. package/i18n/hu.json +12 -0
  170. package/i18n/it.json +12 -0
  171. package/i18n/rm.json +12 -0
  172. package/i18n/sk.json +12 -0
  173. package/i18n/sl.json +12 -0
  174. package/package.json +87 -0
  175. package/src/Maplair.js +24 -0
  176. package/src/control/AttributionControl.js +147 -0
  177. package/src/control/Control.js +174 -0
  178. package/src/control/LayersControl.js +444 -0
  179. package/src/control/ScaleControl.js +141 -0
  180. package/src/control/ZoomControl.js +147 -0
  181. package/src/control/index.js +5 -0
  182. package/src/core/Browser.js +75 -0
  183. package/src/core/Class.js +97 -0
  184. package/src/core/Events.js +334 -0
  185. package/src/core/Handler.js +59 -0
  186. package/src/core/I18n.js +76 -0
  187. package/src/core/Util.js +122 -0
  188. package/src/core/index.js +8 -0
  189. package/src/dom/DomEvent.DoubleTap.js +120 -0
  190. package/src/dom/DomEvent.PointerEvents.js +75 -0
  191. package/src/dom/DomEvent.js +282 -0
  192. package/src/dom/DomUtil.js +175 -0
  193. package/src/dom/Draggable.js +204 -0
  194. package/src/dom/PosAnimation.js +115 -0
  195. package/src/dom/index.js +9 -0
  196. package/src/geo/LatLng.js +163 -0
  197. package/src/geo/LatLngBounds.js +260 -0
  198. package/src/geo/crs/CRS.js +143 -0
  199. package/src/geo/crs/EPSG3395.js +19 -0
  200. package/src/geo/crs/EPSG3857.js +26 -0
  201. package/src/geo/crs/EPSG4326.js +21 -0
  202. package/src/geo/crs/EarthCRS.js +32 -0
  203. package/src/geo/crs/SimpleCRS.js +35 -0
  204. package/src/geo/crs/index.js +6 -0
  205. package/src/geo/index.js +7 -0
  206. package/src/geo/projection/Projection.LonLat.js +30 -0
  207. package/src/geo/projection/Projection.Mercator.js +53 -0
  208. package/src/geo/projection/Projection.SphericalMercator.js +46 -0
  209. package/src/geo/projection/index.js +26 -0
  210. package/src/geometry/Bounds.js +222 -0
  211. package/src/geometry/LineUtil.js +299 -0
  212. package/src/geometry/Point.js +239 -0
  213. package/src/geometry/PolyUtil.js +129 -0
  214. package/src/geometry/Transformation.js +67 -0
  215. package/src/geometry/index.js +8 -0
  216. package/src/images/layers.svg +1 -0
  217. package/src/images/logo.svg +1 -0
  218. package/src/images/marker-icon.svg +1 -0
  219. package/src/images/marker-shadow.svg +1 -0
  220. package/src/layer/BlanketOverlay.js +171 -0
  221. package/src/layer/DivOverlay.js +353 -0
  222. package/src/layer/FeatureGroup.js +93 -0
  223. package/src/layer/GeoJSON.js +432 -0
  224. package/src/layer/ImageOverlay.js +279 -0
  225. package/src/layer/Layer.js +273 -0
  226. package/src/layer/LayerGroup.js +129 -0
  227. package/src/layer/Popup.js +528 -0
  228. package/src/layer/SVGOverlay.js +47 -0
  229. package/src/layer/Tooltip.js +469 -0
  230. package/src/layer/VideoOverlay.js +111 -0
  231. package/src/layer/index.js +18 -0
  232. package/src/layer/marker/DefaultIcon.js +79 -0
  233. package/src/layer/marker/DivIcon.js +76 -0
  234. package/src/layer/marker/Icon.js +164 -0
  235. package/src/layer/marker/Marker.Drag.js +161 -0
  236. package/src/layer/marker/Marker.js +465 -0
  237. package/src/layer/marker/index.js +5 -0
  238. package/src/layer/tile/GridLayer.js +901 -0
  239. package/src/layer/tile/TileLayer.js +299 -0
  240. package/src/layer/tile/WMSTileLayer.js +133 -0
  241. package/src/layer/tile/index.js +3 -0
  242. package/src/layer/vector/Canvas.js +479 -0
  243. package/src/layer/vector/Circle.js +87 -0
  244. package/src/layer/vector/CircleMarker.js +110 -0
  245. package/src/layer/vector/Path.js +145 -0
  246. package/src/layer/vector/Polygon.js +160 -0
  247. package/src/layer/vector/Polyline.js +296 -0
  248. package/src/layer/vector/Rectangle.js +52 -0
  249. package/src/layer/vector/Renderer.getRenderer.js +48 -0
  250. package/src/layer/vector/Renderer.js +75 -0
  251. package/src/layer/vector/SVG.js +216 -0
  252. package/src/layer/vector/index.js +10 -0
  253. package/src/map/Map.js +1830 -0
  254. package/src/map/handler/BoxZoomHandler.js +156 -0
  255. package/src/map/handler/DoubleClickZoomHandler.js +62 -0
  256. package/src/map/handler/DragHandler.js +240 -0
  257. package/src/map/handler/KeyboardHandler.js +188 -0
  258. package/src/map/handler/PinchZoomHandler.js +157 -0
  259. package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
  260. package/src/map/handler/TapHoldHandler.js +111 -0
  261. package/src/map/index.js +8 -0
  262. package/src/maplair.css +730 -0
@@ -0,0 +1,844 @@
1
+ import { setOptions, stamp } from "../core/Util.js";
2
+ import { Point } from "../geometry/Point.js";
3
+ import Browser_default from "../core/Browser.js";
4
+ import { disablePointerDetection, enablePointerDetection } from "../dom/DomEvent.PointerEvents.js";
5
+ import { getPointerPosition, isExternalTarget, off, on } from "../dom/DomEvent.js";
6
+ import { create, get, getPosition, preventOutline, setPosition, setTransform } from "../dom/DomUtil.js";
7
+ import { Control } from "../control/Control.js";
8
+ import { AttributionControl } from "../control/AttributionControl.js";
9
+ import { ZoomControl } from "../control/ZoomControl.js";
10
+ import { Evented } from "../core/Events.js";
11
+ import { PosAnimation } from "../dom/PosAnimation.js";
12
+ import { Bounds } from "../geometry/Bounds.js";
13
+ import { LatLngBounds } from "../geo/LatLngBounds.js";
14
+ import { LatLng } from "../geo/LatLng.js";
15
+ import { EPSG3857 } from "../geo/crs/EPSG3857.js";
16
+ import { Layer } from "../layer/Layer.js";
17
+ import { DivOverlay } from "../layer/DivOverlay.js";
18
+ import { Popup } from "../layer/Popup.js";
19
+ import { Tooltip } from "../layer/Tooltip.js";
20
+ import { Renderer_getRenderer_exports } from "../layer/vector/Renderer.getRenderer.js";
21
+ import { BoxZoomHandler } from "./handler/BoxZoomHandler.js";
22
+ import { DoubleClickZoomHandler } from "./handler/DoubleClickZoomHandler.js";
23
+ import { DragHandler } from "./handler/DragHandler.js";
24
+ import { KeyboardHandler } from "./handler/KeyboardHandler.js";
25
+ import { PinchZoomHandler } from "./handler/PinchZoomHandler.js";
26
+ import { ScrollWheelZoomHandler } from "./handler/ScrollWheelZoomHandler.js";
27
+ import { TapHoldHandler } from "./handler/TapHoldHandler.js";
28
+ //#region src/map/Map.js
29
+ var MaplairMap = class MaplairMap extends Evented {
30
+ static {
31
+ this.setDefaultOptions({
32
+ crs: EPSG3857,
33
+ center: void 0,
34
+ zoom: void 0,
35
+ minZoom: void 0,
36
+ maxZoom: void 0,
37
+ layers: [],
38
+ maxBounds: void 0,
39
+ renderer: void 0,
40
+ zoomAnimation: !Browser_default.reducedMotion,
41
+ zoomAnimationThreshold: 4,
42
+ fadeAnimation: !Browser_default.reducedMotion,
43
+ markerZoomAnimation: true,
44
+ markerCulling: false,
45
+ transform3DLimit: 8388608,
46
+ zoomSnap: 1,
47
+ zoomDelta: 1,
48
+ trackResize: true
49
+ });
50
+ }
51
+ constructor(id, options) {
52
+ super();
53
+ options = setOptions(this, options);
54
+ this._handlers = [];
55
+ this._layers = {};
56
+ this._zoomBoundLayers = {};
57
+ this._sizeChanged = true;
58
+ this._initContainer(id);
59
+ this._initLayout();
60
+ this._initEvents();
61
+ if (options.maxBounds) this.setMaxBounds(options.maxBounds);
62
+ if (options.zoom !== void 0) this._zoom = this._limitZoom(options.zoom);
63
+ if (options.center && options.zoom !== void 0) this.setView(new LatLng(options.center), options.zoom, { reset: true });
64
+ this.callInitHooks(MaplairMap);
65
+ this._zoomAnimated = this.options.zoomAnimation;
66
+ if (this._zoomAnimated) this._createAnimProxy();
67
+ this._addLayers(this.options.layers);
68
+ }
69
+ setView(center, zoom, options) {
70
+ zoom = zoom === void 0 ? this._zoom : this._limitZoom(zoom);
71
+ center = this._limitCenter(new LatLng(center), zoom, this.options.maxBounds);
72
+ options ??= {};
73
+ this._stop();
74
+ if (this._loaded && !options.reset && options !== true) {
75
+ if (options.animate !== void 0) {
76
+ options.zoom = {
77
+ animate: options.animate,
78
+ ...options.zoom
79
+ };
80
+ options.pan = {
81
+ animate: options.animate,
82
+ duration: options.duration,
83
+ ...options.pan
84
+ };
85
+ }
86
+ if (this._zoom !== zoom ? this._tryAnimatedZoom && this._tryAnimatedZoom(center, zoom, options.zoom) : this._tryAnimatedPan(center, options.pan)) {
87
+ clearTimeout(this._sizeTimer);
88
+ return this;
89
+ }
90
+ }
91
+ this._resetView(center, zoom, options.pan?.noMoveStart);
92
+ return this;
93
+ }
94
+ setZoom(zoom, options) {
95
+ if (!this._loaded) {
96
+ this._zoom = zoom;
97
+ return this;
98
+ }
99
+ return this.setView(this.getCenter(), zoom, { zoom: options });
100
+ }
101
+ zoomIn(delta, options) {
102
+ delta ??= this.options.zoomDelta;
103
+ return this.setZoom(this._zoom + delta, options);
104
+ }
105
+ zoomOut(delta, options) {
106
+ delta ??= this.options.zoomDelta;
107
+ return this.setZoom(this._zoom - delta, options);
108
+ }
109
+ setZoomAround(latlng, zoom, options) {
110
+ const scale = this.getZoomScale(zoom), viewHalf = this.getSize().divideBy(2), centerOffset = (latlng instanceof Point ? latlng : this.latLngToContainerPoint(latlng)).subtract(viewHalf).multiplyBy(1 - 1 / scale), newCenter = this.containerPointToLatLng(viewHalf.add(centerOffset));
111
+ return this.setView(newCenter, zoom, { zoom: options });
112
+ }
113
+ _getBoundsCenterZoom(bounds, options) {
114
+ options ??= {};
115
+ bounds = bounds.getBounds ? bounds.getBounds() : new LatLngBounds(bounds);
116
+ const paddingTL = new Point(options.paddingTopLeft || options.padding || [0, 0]), paddingBR = new Point(options.paddingBottomRight || options.padding || [0, 0]);
117
+ let zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR));
118
+ zoom = typeof options.maxZoom === "number" ? Math.min(options.maxZoom, zoom) : zoom;
119
+ if (zoom === Infinity) return {
120
+ center: bounds.getCenter(),
121
+ zoom
122
+ };
123
+ const paddingOffset = paddingBR.subtract(paddingTL).divideBy(2), swPoint = this.project(bounds.getSouthWest(), zoom), nePoint = this.project(bounds.getNorthEast(), zoom);
124
+ return {
125
+ center: this.unproject(swPoint.add(nePoint).divideBy(2).add(paddingOffset), zoom),
126
+ zoom
127
+ };
128
+ }
129
+ fitBounds(bounds, options) {
130
+ bounds = new LatLngBounds(bounds);
131
+ if (!bounds.isValid()) throw new Error("Bounds are not valid.");
132
+ const target = this._getBoundsCenterZoom(bounds, options);
133
+ return this.setView(target.center, target.zoom, options);
134
+ }
135
+ fitWorld(options) {
136
+ return this.fitBounds([[-90, -180], [90, 180]], options);
137
+ }
138
+ panTo(center, options) {
139
+ return this.setView(center, this._zoom, { pan: options });
140
+ }
141
+ panBy(offset, options) {
142
+ offset = new Point(offset).round();
143
+ options ??= {};
144
+ if (!offset.x && !offset.y) return this.fire("moveend");
145
+ if (options.animate !== true && !this.getSize().contains(offset)) {
146
+ this._resetView(this.unproject(this.project(this.getCenter()).add(offset)), this.getZoom());
147
+ return this;
148
+ }
149
+ if (!this._panAnim) {
150
+ this._panAnim = new PosAnimation();
151
+ this._panAnim.on({
152
+ "step": this._onPanTransitionStep,
153
+ "end": this._onPanTransitionEnd
154
+ }, this);
155
+ }
156
+ if (!options.noMoveStart) this.fire("movestart");
157
+ if (!Browser_default.reducedMotion && options.animate !== false) {
158
+ this._mapPane.classList.add("maplair-pan-anim");
159
+ const newPos = this._getMapPanePos().subtract(offset).round();
160
+ this._panAnim.run(this._mapPane, newPos, options.duration || .25, options.easeLinearity);
161
+ } else {
162
+ this._rawPanBy(offset);
163
+ this.fire("move").fire("moveend");
164
+ }
165
+ return this;
166
+ }
167
+ flyTo(targetCenter, targetZoom, options) {
168
+ options ??= {};
169
+ if (Browser_default.reducedMotion || options.animate === false) return this.setView(targetCenter, targetZoom, options);
170
+ this._stop();
171
+ const from = this.project(this.getCenter()), to = this.project(targetCenter), size = this.getSize(), startZoom = this._zoom;
172
+ targetCenter = new LatLng(targetCenter);
173
+ targetZoom = targetZoom === void 0 ? startZoom : this._limitZoom(targetZoom);
174
+ const w0 = Math.max(size.x, size.y), w1 = w0 * this.getZoomScale(startZoom, targetZoom), u1 = to.distanceTo(from) || 1, rho = 1.42, rho2 = rho * rho;
175
+ function r(i) {
176
+ const s1 = i ? -1 : 1, s2 = i ? w1 : w0, b = (w1 * w1 - w0 * w0 + s1 * rho2 * rho2 * u1 * u1) / (2 * s2 * rho2 * u1), sq = Math.sqrt(b * b + 1) - b;
177
+ return sq < 15e-9 ? -18 : Math.log(sq);
178
+ }
179
+ function sinh(n) {
180
+ return (Math.exp(n) - Math.exp(-n)) / 2;
181
+ }
182
+ function cosh(n) {
183
+ return (Math.exp(n) + Math.exp(-n)) / 2;
184
+ }
185
+ function tanh(n) {
186
+ return sinh(n) / cosh(n);
187
+ }
188
+ const r0 = r(0);
189
+ function w(s) {
190
+ return w0 * (cosh(r0) / cosh(r0 + rho * s));
191
+ }
192
+ function u(s) {
193
+ return w0 * (cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2;
194
+ }
195
+ function easeOut(t) {
196
+ return 1 - (1 - t) ** 1.5;
197
+ }
198
+ const start = Date.now(), S = (r(1) - r0) / rho, duration = options.duration ? 1e3 * options.duration : 1e3 * S * .8;
199
+ const frame = () => {
200
+ const t = (Date.now() - start) / duration, s = easeOut(t) * S;
201
+ if (t <= 1) {
202
+ this._flyToFrame = requestAnimationFrame(frame);
203
+ this._move(this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1)), startZoom), this.getScaleZoom(w0 / w(s), startZoom), { flyTo: true });
204
+ } else this._move(targetCenter, targetZoom)._moveEnd(true);
205
+ };
206
+ this._moveStart(true, options.noMoveStart);
207
+ frame(this);
208
+ return this;
209
+ }
210
+ flyToBounds(bounds, options) {
211
+ const target = this._getBoundsCenterZoom(bounds, options);
212
+ return this.flyTo(target.center, target.zoom, options);
213
+ }
214
+ setMaxBounds(bounds) {
215
+ bounds = new LatLngBounds(bounds);
216
+ if (this.listens("moveend", this._panInsideMaxBounds)) this.off("moveend", this._panInsideMaxBounds);
217
+ if (!bounds.isValid()) {
218
+ this.options.maxBounds = null;
219
+ return this;
220
+ }
221
+ this.options.maxBounds = bounds;
222
+ if (this._loaded) this._panInsideMaxBounds();
223
+ return this.on("moveend", this._panInsideMaxBounds);
224
+ }
225
+ setMinZoom(zoom) {
226
+ const oldZoom = this.options.minZoom;
227
+ this.options.minZoom = zoom;
228
+ if (this._loaded && oldZoom !== zoom) {
229
+ this.fire("zoomlevelschange");
230
+ if (this.getZoom() < this.options.minZoom) return this.setZoom(zoom);
231
+ }
232
+ return this;
233
+ }
234
+ setMaxZoom(zoom) {
235
+ const oldZoom = this.options.maxZoom;
236
+ this.options.maxZoom = zoom;
237
+ if (this._loaded && oldZoom !== zoom) {
238
+ this.fire("zoomlevelschange");
239
+ if (this.getZoom() > this.options.maxZoom) return this.setZoom(zoom);
240
+ }
241
+ return this;
242
+ }
243
+ panInsideBounds(bounds, options) {
244
+ this._enforcingBounds = true;
245
+ const center = this.getCenter(), newCenter = this._limitCenter(center, this._zoom, new LatLngBounds(bounds));
246
+ if (!center.equals(newCenter)) this.panTo(newCenter, options);
247
+ this._enforcingBounds = false;
248
+ return this;
249
+ }
250
+ panInside(latlng, options) {
251
+ options ??= {};
252
+ const paddingTL = new Point(options.paddingTopLeft || options.padding || [0, 0]), paddingBR = new Point(options.paddingBottomRight || options.padding || [0, 0]), pixelCenter = this.project(this.getCenter()), pixelPoint = this.project(latlng), pixelBounds = this.getPixelBounds(), paddedBounds = new Bounds([pixelBounds.min.add(paddingTL), pixelBounds.max.subtract(paddingBR)]), paddedSize = paddedBounds.getSize();
253
+ if (!paddedBounds.contains(pixelPoint)) {
254
+ this._enforcingBounds = true;
255
+ const centerOffset = pixelPoint.subtract(paddedBounds.getCenter());
256
+ const offset = paddedBounds.extend(pixelPoint).getSize().subtract(paddedSize);
257
+ pixelCenter.x += centerOffset.x < 0 ? -offset.x : offset.x;
258
+ pixelCenter.y += centerOffset.y < 0 ? -offset.y : offset.y;
259
+ this.panTo(this.unproject(pixelCenter), options);
260
+ this._enforcingBounds = false;
261
+ }
262
+ return this;
263
+ }
264
+ invalidateSize(options) {
265
+ if (!this._loaded) return this;
266
+ options = {
267
+ animate: false,
268
+ pan: true,
269
+ ...options === true ? { animate: true } : options
270
+ };
271
+ const oldSize = this.getSize();
272
+ this._sizeChanged = true;
273
+ this._lastCenter = null;
274
+ const newSize = this.getSize(), oldCenter = oldSize.divideBy(2).round(), newCenter = newSize.divideBy(2).round(), offset = oldCenter.subtract(newCenter);
275
+ if (!offset.x && !offset.y) return this;
276
+ if (options.animate && options.pan) this.panBy(offset);
277
+ else {
278
+ if (options.pan) this._rawPanBy(offset);
279
+ this.fire("move");
280
+ if (options.debounceMoveend) {
281
+ clearTimeout(this._sizeTimer);
282
+ this._sizeTimer = setTimeout(this.fire.bind(this, "moveend"), 200);
283
+ } else this.fire("moveend");
284
+ }
285
+ return this.fire("resize", {
286
+ oldSize,
287
+ newSize
288
+ });
289
+ }
290
+ stop() {
291
+ this.setZoom(this._limitZoom(this._zoom));
292
+ if (!this.options.zoomSnap) this.fire("viewreset");
293
+ return this._stop();
294
+ }
295
+ locate(options) {
296
+ options = this._locateOptions = {
297
+ timeout: 1e4,
298
+ watch: false,
299
+ ...options
300
+ };
301
+ if (!("geolocation" in navigator)) {
302
+ this._handleGeolocationError({
303
+ code: 0,
304
+ message: "Geolocation not supported."
305
+ });
306
+ return this;
307
+ }
308
+ const onResponse = this._handleGeolocationResponse.bind(this), onError = this._handleGeolocationError.bind(this);
309
+ if (options.watch) {
310
+ if (this._locationWatchId !== void 0) navigator.geolocation.clearWatch(this._locationWatchId);
311
+ this._locationWatchId = navigator.geolocation.watchPosition(onResponse, onError, options);
312
+ } else navigator.geolocation.getCurrentPosition(onResponse, onError, options);
313
+ return this;
314
+ }
315
+ stopLocate() {
316
+ navigator.geolocation?.clearWatch?.(this._locationWatchId);
317
+ if (this._locateOptions) this._locateOptions.setView = false;
318
+ return this;
319
+ }
320
+ _handleGeolocationError(error) {
321
+ if (!this._container._maplair_id) return;
322
+ const c = error.code, message = error.message || (c === 1 ? "permission denied" : c === 2 ? "position unavailable" : "timeout");
323
+ if (this._locateOptions.setView && !this._loaded) this.fitWorld();
324
+ this.fire("locationerror", {
325
+ code: c,
326
+ message: `Geolocation error: ${message}.`
327
+ });
328
+ }
329
+ _handleGeolocationResponse(pos) {
330
+ if (!this._container._maplair_id) return;
331
+ const lat = pos.coords.latitude, lng = pos.coords.longitude, latlng = new LatLng(lat, lng), bounds = latlng.toBounds(pos.coords.accuracy * 2), options = this._locateOptions;
332
+ if (options.setView) {
333
+ const zoom = this.getBoundsZoom(bounds);
334
+ this.setView(latlng, options.maxZoom ? Math.min(zoom, options.maxZoom) : zoom);
335
+ }
336
+ const data = {
337
+ latlng,
338
+ bounds,
339
+ timestamp: pos.timestamp
340
+ };
341
+ for (const i in pos.coords) if (typeof pos.coords[i] === "number") data[i] = pos.coords[i];
342
+ this.fire("locationfound", data);
343
+ }
344
+ addHandler(name, HandlerClass) {
345
+ if (!HandlerClass) return this;
346
+ const handler = this[name] = new HandlerClass(this);
347
+ this._handlers.push(handler);
348
+ if (this.options[name]) handler.enable();
349
+ return this;
350
+ }
351
+ remove() {
352
+ this._initEvents(true);
353
+ if (this.options.maxBounds) this.off("moveend", this._panInsideMaxBounds);
354
+ if (this._containerId !== this._container._maplair_id) throw new Error("Map container is being reused by another instance");
355
+ delete this._container._maplair_id;
356
+ delete this._containerId;
357
+ if (this._locationWatchId !== void 0) this.stopLocate();
358
+ this._stop();
359
+ disablePointerDetection(this._container);
360
+ this._mapPane.remove();
361
+ if (this._clearControlPos) this._clearControlPos();
362
+ if (this._resizeRequest) {
363
+ cancelAnimationFrame(this._resizeRequest);
364
+ this._resizeRequest = null;
365
+ }
366
+ this._clearHandlers();
367
+ clearTimeout(this._transitionEndTimer);
368
+ clearTimeout(this._sizeTimer);
369
+ if (this._loaded) this.fire("unload");
370
+ this._destroyAnimProxy();
371
+ for (const layer of Object.values(this._layers)) layer.remove();
372
+ for (const pane of Object.values(this._panes)) pane.remove();
373
+ this._layers = {};
374
+ this._panes = {};
375
+ delete this._mapPane;
376
+ delete this._renderer;
377
+ return this;
378
+ }
379
+ createPane(name, container) {
380
+ const className = `maplair-pane${name ? ` maplair-${name.replace("Pane", "")}-pane` : ""}`, pane = create("div", className, container || this._mapPane);
381
+ if (name) this._panes[name] = pane;
382
+ return pane;
383
+ }
384
+ getCenter() {
385
+ this._checkIfLoaded();
386
+ if (this._lastCenter && !this._moved()) return new LatLng(this._lastCenter);
387
+ return this.layerPointToLatLng(this._getCenterLayerPoint());
388
+ }
389
+ getZoom() {
390
+ return this._zoom;
391
+ }
392
+ getBounds() {
393
+ const bounds = this.getPixelBounds(), sw = this.unproject(bounds.getBottomLeft()), ne = this.unproject(bounds.getTopRight());
394
+ return new LatLngBounds(sw, ne);
395
+ }
396
+ getMinZoom() {
397
+ return this.options.minZoom ?? this._layersMinZoom ?? 0;
398
+ }
399
+ getMaxZoom() {
400
+ return this.options.maxZoom ?? this._layersMaxZoom ?? Infinity;
401
+ }
402
+ getBoundsZoom(bounds, inside, padding) {
403
+ bounds = new LatLngBounds(bounds);
404
+ padding = new Point(padding ?? [0, 0]);
405
+ let zoom = this.getZoom() ?? 0;
406
+ const min = this.getMinZoom(), max = this.getMaxZoom(), nw = bounds.getNorthWest(), se = bounds.getSouthEast(), size = this.getSize().subtract(padding), boundsSize = new Bounds(this.project(se, zoom), this.project(nw, zoom)).getSize(), snap = this.options.zoomSnap, scalex = size.x / boundsSize.x, scaley = size.y / boundsSize.y, scale = inside ? Math.max(scalex, scaley) : Math.min(scalex, scaley);
407
+ zoom = this.getScaleZoom(scale, zoom);
408
+ if (snap) {
409
+ zoom = Math.round(zoom / (snap / 100)) * (snap / 100);
410
+ zoom = inside ? Math.ceil(zoom / snap) * snap : Math.floor(zoom / snap) * snap;
411
+ }
412
+ return Math.max(min, Math.min(max, zoom));
413
+ }
414
+ getSize() {
415
+ if (!this._size || this._sizeChanged) {
416
+ this._size = new Point(this._container.clientWidth || 0, this._container.clientHeight || 0);
417
+ this._sizeChanged = false;
418
+ }
419
+ return new Point(this._size);
420
+ }
421
+ getPixelBounds(center, zoom) {
422
+ const topLeftPoint = this._getTopLeftPoint(center, zoom);
423
+ return new Bounds(topLeftPoint, topLeftPoint.add(this.getSize()));
424
+ }
425
+ getPixelOrigin() {
426
+ this._checkIfLoaded();
427
+ return this._pixelOrigin;
428
+ }
429
+ getPixelWorldBounds(zoom) {
430
+ return this.options.crs.getProjectedBounds(zoom ?? this.getZoom());
431
+ }
432
+ getPane(pane) {
433
+ return typeof pane === "string" ? this._panes[pane] : pane;
434
+ }
435
+ getPanes() {
436
+ return this._panes;
437
+ }
438
+ getContainer() {
439
+ return this._container;
440
+ }
441
+ getZoomScale(toZoom, fromZoom) {
442
+ const crs = this.options.crs;
443
+ fromZoom ??= this._zoom;
444
+ return crs.scale(toZoom) / crs.scale(fromZoom);
445
+ }
446
+ getScaleZoom(scale, fromZoom) {
447
+ const crs = this.options.crs;
448
+ fromZoom ??= this._zoom;
449
+ const zoom = crs.zoom(scale * crs.scale(fromZoom));
450
+ return isNaN(zoom) ? Infinity : zoom;
451
+ }
452
+ project(latlng, zoom) {
453
+ zoom ??= this._zoom;
454
+ return this.options.crs.latLngToPoint(new LatLng(latlng), zoom);
455
+ }
456
+ unproject(point, zoom) {
457
+ zoom ??= this._zoom;
458
+ return this.options.crs.pointToLatLng(new Point(point), zoom);
459
+ }
460
+ layerPointToLatLng(point) {
461
+ const projectedPoint = new Point(point).add(this.getPixelOrigin());
462
+ return this.unproject(projectedPoint);
463
+ }
464
+ latLngToLayerPoint(latlng) {
465
+ return this.project(new LatLng(latlng))._round()._subtract(this.getPixelOrigin());
466
+ }
467
+ wrapLatLng(latlng) {
468
+ return this.options.crs.wrapLatLng(new LatLng(latlng));
469
+ }
470
+ wrapLatLngBounds(bounds) {
471
+ return this.options.crs.wrapLatLngBounds(new LatLngBounds(bounds));
472
+ }
473
+ distance(latlng1, latlng2) {
474
+ return this.options.crs.distance(new LatLng(latlng1), new LatLng(latlng2));
475
+ }
476
+ containerPointToLayerPoint(point) {
477
+ return new Point(point).subtract(this._getMapPanePos());
478
+ }
479
+ layerPointToContainerPoint(point) {
480
+ return new Point(point).add(this._getMapPanePos());
481
+ }
482
+ containerPointToLatLng(point) {
483
+ const layerPoint = this.containerPointToLayerPoint(new Point(point));
484
+ return this.layerPointToLatLng(layerPoint);
485
+ }
486
+ latLngToContainerPoint(latlng) {
487
+ return this.layerPointToContainerPoint(this.latLngToLayerPoint(new LatLng(latlng)));
488
+ }
489
+ pointerEventToContainerPoint(e) {
490
+ return getPointerPosition(e, this._container);
491
+ }
492
+ pointerEventToLayerPoint(e) {
493
+ return this.containerPointToLayerPoint(this.pointerEventToContainerPoint(e));
494
+ }
495
+ pointerEventToLatLng(e) {
496
+ return this.layerPointToLatLng(this.pointerEventToLayerPoint(e));
497
+ }
498
+ _initContainer(id) {
499
+ const container = this._container = get(id);
500
+ if (!container) throw new Error("Map container not found.");
501
+ else if (container._maplair_id) throw new Error("Map container is already initialized.");
502
+ enablePointerDetection(container);
503
+ on(container, "scroll", this._onScroll, this);
504
+ this._containerId = stamp(container);
505
+ }
506
+ _initLayout() {
507
+ const container = this._container;
508
+ this._fadeAnimated = this.options.fadeAnimation;
509
+ const classes = ["maplair-container", "maplair-touch"];
510
+ if (Browser_default.retina) classes.push("maplair-retina");
511
+ if (Browser_default.safari) classes.push("maplair-safari");
512
+ if (this._fadeAnimated) classes.push("maplair-fade-anim");
513
+ container.classList.add(...classes);
514
+ const { position } = getComputedStyle(container);
515
+ if (position !== "absolute" && position !== "relative" && position !== "fixed" && position !== "sticky") container.style.position = "relative";
516
+ this._initPanes();
517
+ if (this._initControlPos) this._initControlPos();
518
+ }
519
+ _initPanes() {
520
+ const panes = this._panes = {};
521
+ this._paneRenderers = {};
522
+ this._mapPane = this.createPane("mapPane", this._container);
523
+ setPosition(this._mapPane, new Point(0, 0));
524
+ this.createPane("tilePane");
525
+ this.createPane("overlayPane");
526
+ this.createPane("shadowPane");
527
+ this.createPane("markerPane");
528
+ this.createPane("tooltipPane");
529
+ this.createPane("popupPane");
530
+ if (!this.options.markerZoomAnimation) {
531
+ panes.markerPane.classList.add("maplair-zoom-hide");
532
+ panes.shadowPane.classList.add("maplair-zoom-hide");
533
+ }
534
+ }
535
+ _resetView(center, zoom, noMoveStart) {
536
+ setPosition(this._mapPane, new Point(0, 0));
537
+ const loading = !this._loaded;
538
+ this._loaded = true;
539
+ zoom = this._limitZoom(zoom);
540
+ this.fire("viewprereset");
541
+ const zoomChanged = this._zoom !== zoom;
542
+ this._moveStart(zoomChanged, noMoveStart)._move(center, zoom)._moveEnd(zoomChanged);
543
+ this.fire("viewreset");
544
+ if (loading) this.fire("load");
545
+ }
546
+ _moveStart(zoomChanged, noMoveStart) {
547
+ if (zoomChanged) this.fire("zoomstart");
548
+ if (!noMoveStart) this.fire("movestart");
549
+ return this;
550
+ }
551
+ _move(center, zoom, data, suppressEvent) {
552
+ if (zoom === void 0) zoom = this._zoom;
553
+ const zoomChanged = this._zoom !== zoom;
554
+ this._zoom = zoom;
555
+ this._lastCenter = center;
556
+ this._pixelOrigin = this._getNewPixelOrigin(center);
557
+ if (!suppressEvent) {
558
+ if (zoomChanged || data?.pinch) this.fire("zoom", data);
559
+ this.fire("move", data);
560
+ } else if (data?.pinch) this.fire("zoom", data);
561
+ return this;
562
+ }
563
+ _moveEnd(zoomChanged) {
564
+ if (zoomChanged) this.fire("zoomend");
565
+ return this.fire("moveend");
566
+ }
567
+ _stop() {
568
+ cancelAnimationFrame(this._flyToFrame);
569
+ cancelAnimationFrame(this._zoomAnimFrame);
570
+ this._panAnim?.stop();
571
+ return this;
572
+ }
573
+ _rawPanBy(offset) {
574
+ setPosition(this._mapPane, this._getMapPanePos().subtract(offset));
575
+ }
576
+ _getZoomSpan() {
577
+ return this.getMaxZoom() - this.getMinZoom();
578
+ }
579
+ _panInsideMaxBounds() {
580
+ if (!this._enforcingBounds) this.panInsideBounds(this.options.maxBounds);
581
+ }
582
+ _checkIfLoaded() {
583
+ if (!this._loaded) throw new Error("Set map center and zoom first.");
584
+ }
585
+ _initEvents(remove) {
586
+ this._targets = {};
587
+ this._targets[stamp(this._container)] = this;
588
+ (remove ? off : on)(this._container, "click dblclick pointerdown pointerup pointerover pointerout pointermove contextmenu keypress keydown keyup", this._handleDOMEvent, this);
589
+ if (this.options.trackResize) {
590
+ if (!remove) {
591
+ if (!this._resizeObserver) this._resizeObserver = new ResizeObserver(this._onResize.bind(this));
592
+ this._resizeObserver.observe(this._container);
593
+ } else this._resizeObserver.disconnect();
594
+ }
595
+ if (this.options.transform3DLimit) (remove ? this.off : this.on).call(this, "moveend", this._onMoveEnd);
596
+ }
597
+ _onResize() {
598
+ cancelAnimationFrame(this._resizeRequest);
599
+ this._resizeRequest = requestAnimationFrame(() => {
600
+ this.invalidateSize({ debounceMoveend: true });
601
+ });
602
+ }
603
+ _onScroll() {
604
+ this._container.scrollTop = 0;
605
+ this._container.scrollLeft = 0;
606
+ }
607
+ _onMoveEnd() {
608
+ const pos = this._getMapPanePos();
609
+ if (Math.max(Math.abs(pos.x), Math.abs(pos.y)) >= this.options.transform3DLimit) this._resetView(this.getCenter(), this.getZoom());
610
+ }
611
+ _findEventTargets(e, type) {
612
+ let targets = [], target, src = e.target || e.srcElement, dragging = false;
613
+ const isHover = type === "pointerout" || type === "pointerover";
614
+ while (src) {
615
+ target = this._targets[stamp(src)];
616
+ if (target && (type === "click" || type === "preclick") && this._draggableMoved(target)) {
617
+ dragging = true;
618
+ break;
619
+ }
620
+ if (target && target.listens(type, true)) {
621
+ if (isHover && !isExternalTarget(src, e)) break;
622
+ targets.push(target);
623
+ if (isHover) break;
624
+ }
625
+ if (src === this._container) break;
626
+ src = src.parentNode;
627
+ }
628
+ if (!targets.length && !dragging && !isHover && this.listens(type, true)) targets = [this];
629
+ return targets;
630
+ }
631
+ _isClickDisabled(el) {
632
+ while (el && el !== this._container) {
633
+ if (el["_maplair_disable_click"] || !el.parentNode) return true;
634
+ el = el.parentNode;
635
+ }
636
+ }
637
+ _handleDOMEvent(e) {
638
+ const el = e.target ?? e.srcElement;
639
+ if (!this._loaded || el["_maplair_disable_events"] || e.type === "click" && this._isClickDisabled(el)) return;
640
+ const type = e.type;
641
+ if (type === "pointerdown") preventOutline(el);
642
+ this._fireDOMEvent(e, type);
643
+ }
644
+ static _pointerEvents = [
645
+ "click",
646
+ "dblclick",
647
+ "pointerover",
648
+ "pointerout",
649
+ "contextmenu"
650
+ ];
651
+ _fireDOMEvent(e, type, canvasTargets) {
652
+ if (type === "click") this._fireDOMEvent(e, "preclick", canvasTargets);
653
+ let targets = this._findEventTargets(e, type);
654
+ if (canvasTargets) targets = [...canvasTargets.filter((t) => t.listens(type, true)), ...targets];
655
+ if (!targets.length) return;
656
+ if (type === "contextmenu") e.preventDefault();
657
+ const target = targets[0];
658
+ const data = { originalEvent: e };
659
+ if (e.type !== "keypress" && e.type !== "keydown" && e.type !== "keyup") {
660
+ const isMarker = target.getLatLng && (!target._pxRadius || target._pxRadius <= 10);
661
+ data.containerPoint = isMarker ? this.latLngToContainerPoint(target.getLatLng()) : this.pointerEventToContainerPoint(e);
662
+ data.layerPoint = this.containerPointToLayerPoint(data.containerPoint);
663
+ data.latlng = isMarker ? target.getLatLng() : this.layerPointToLatLng(data.layerPoint);
664
+ }
665
+ for (const t of targets) {
666
+ t.fire(type, data, true);
667
+ if (data.originalEvent._stopped || t.options.bubblingPointerEvents === false && MaplairMap._pointerEvents.includes(type)) return;
668
+ }
669
+ }
670
+ _draggableMoved(obj) {
671
+ obj = obj.dragging?.enabled() ? obj : this;
672
+ return obj.dragging?.moved() || this.boxZoom?.moved();
673
+ }
674
+ _clearHandlers() {
675
+ for (const handler of this._handlers) handler.disable();
676
+ }
677
+ whenReady(callback, context) {
678
+ if (this._loaded) callback.call(context || this, { target: this });
679
+ else this.on("load", callback, context);
680
+ return this;
681
+ }
682
+ _getMapPanePos() {
683
+ return getPosition(this._mapPane);
684
+ }
685
+ _moved() {
686
+ const pos = this._getMapPanePos();
687
+ return pos && !pos.equals([0, 0]);
688
+ }
689
+ _getTopLeftPoint(center, zoom) {
690
+ return (center && zoom !== void 0 ? this._getNewPixelOrigin(center, zoom) : this.getPixelOrigin()).subtract(this._getMapPanePos());
691
+ }
692
+ _getNewPixelOrigin(center, zoom) {
693
+ const viewHalf = this.getSize()._divideBy(2);
694
+ return this.project(center, zoom)._subtract(viewHalf)._add(this._getMapPanePos())._round();
695
+ }
696
+ _latLngToNewLayerPoint(latlng, zoom, center) {
697
+ const topLeft = this._getNewPixelOrigin(center, zoom);
698
+ return this.project(latlng, zoom)._subtract(topLeft);
699
+ }
700
+ _latLngBoundsToNewLayerBounds(latLngBounds, zoom, center) {
701
+ const topLeft = this._getNewPixelOrigin(center, zoom);
702
+ return new Bounds([
703
+ this.project(latLngBounds.getSouthWest(), zoom)._subtract(topLeft),
704
+ this.project(latLngBounds.getNorthWest(), zoom)._subtract(topLeft),
705
+ this.project(latLngBounds.getSouthEast(), zoom)._subtract(topLeft),
706
+ this.project(latLngBounds.getNorthEast(), zoom)._subtract(topLeft)
707
+ ]);
708
+ }
709
+ _getCenterLayerPoint() {
710
+ return this.containerPointToLayerPoint(this.getSize()._divideBy(2));
711
+ }
712
+ _getCenterOffset(latlng) {
713
+ return this.latLngToLayerPoint(latlng).subtract(this._getCenterLayerPoint());
714
+ }
715
+ _limitCenter(center, zoom, bounds) {
716
+ if (!bounds) return center;
717
+ const centerPoint = this.project(center, zoom), viewHalf = this.getSize().divideBy(2), viewBounds = new Bounds(centerPoint.subtract(viewHalf), centerPoint.add(viewHalf)), offset = this._getBoundsOffset(viewBounds, bounds, zoom);
718
+ if (Math.abs(offset.x) <= 1 && Math.abs(offset.y) <= 1) return center;
719
+ return this.unproject(centerPoint.add(offset), zoom);
720
+ }
721
+ _limitOffset(offset, bounds) {
722
+ if (!bounds) return offset;
723
+ const viewBounds = this.getPixelBounds(), newBounds = new Bounds(viewBounds.min.add(offset), viewBounds.max.add(offset));
724
+ return offset.add(this._getBoundsOffset(newBounds, bounds));
725
+ }
726
+ _getBoundsOffset(pxBounds, maxBounds, zoom) {
727
+ const projectedMaxBounds = new Bounds(this.project(maxBounds.getNorthEast(), zoom), this.project(maxBounds.getSouthWest(), zoom)), minOffset = projectedMaxBounds.min.subtract(pxBounds.min), maxOffset = projectedMaxBounds.max.subtract(pxBounds.max), dx = this._rebound(minOffset.x, -maxOffset.x), dy = this._rebound(minOffset.y, -maxOffset.y);
728
+ return new Point(dx, dy);
729
+ }
730
+ _rebound(left, right) {
731
+ return left + right > 0 ? Math.round(left - right) / 2 : Math.max(0, Math.ceil(left)) - Math.max(0, Math.floor(right));
732
+ }
733
+ _limitZoom(zoom) {
734
+ const min = this.getMinZoom(), max = this.getMaxZoom(), snap = this.options.zoomSnap;
735
+ if (snap) zoom = Math.round(zoom / snap) * snap;
736
+ return Math.max(min, Math.min(max, zoom));
737
+ }
738
+ _onPanTransitionStep() {
739
+ this.fire("move");
740
+ }
741
+ _onPanTransitionEnd() {
742
+ this._mapPane.classList.remove("maplair-pan-anim");
743
+ this.fire("moveend");
744
+ }
745
+ _tryAnimatedPan(center, options) {
746
+ const offset = this._getCenterOffset(center)._trunc();
747
+ if (options?.animate !== true && !this.getSize().contains(offset)) return false;
748
+ this.panBy(offset, options);
749
+ return true;
750
+ }
751
+ _createAnimProxy() {
752
+ this._proxy = create("div", "maplair-proxy maplair-zoom-animated");
753
+ this._panes.mapPane.appendChild(this._proxy);
754
+ this.on("zoomanim", this._animateProxyZoom, this);
755
+ this.on("load moveend", this._animMoveEnd, this);
756
+ on(this._proxy, "transitionend", this._catchTransitionEnd, this);
757
+ }
758
+ _animateProxyZoom(e) {
759
+ const transform = this._proxy.style.transform;
760
+ setTransform(this._proxy, this.project(e.center, e.zoom), this.getZoomScale(e.zoom, 1));
761
+ if (transform === this._proxy.style.transform && this._animatingZoom) this._onZoomTransitionEnd();
762
+ }
763
+ _animMoveEnd() {
764
+ const c = this.getCenter();
765
+ const z = this.getZoom();
766
+ setTransform(this._proxy, this.project(c, z), this.getZoomScale(z, 1));
767
+ }
768
+ _destroyAnimProxy() {
769
+ if (this._proxy) {
770
+ off(this._proxy, "transitionend", this._catchTransitionEnd, this);
771
+ this._proxy.remove();
772
+ this.off("zoomanim", this._animateProxyZoom, this);
773
+ this.off("load moveend", this._animMoveEnd, this);
774
+ delete this._proxy;
775
+ }
776
+ }
777
+ _catchTransitionEnd(e) {
778
+ if (this._animatingZoom && e.propertyName.includes("transform")) this._onZoomTransitionEnd();
779
+ }
780
+ _nothingToAnimate() {
781
+ return !this._container.getElementsByClassName("maplair-zoom-animated").length;
782
+ }
783
+ _tryAnimatedZoom(center, zoom, options) {
784
+ if (this._animatingZoom) return true;
785
+ options ??= {};
786
+ if (!this._zoomAnimated || options.animate === false || this._nothingToAnimate() || Math.abs(zoom - this._zoom) > this.options.zoomAnimationThreshold) return false;
787
+ const scale = this.getZoomScale(zoom), offset = this._getCenterOffset(center)._divideBy(1 - 1 / scale);
788
+ if (options.animate !== true && !this.getSize().contains(offset)) return false;
789
+ this._zoomAnimFrame = requestAnimationFrame(() => {
790
+ this._zoomAnimFrame = null;
791
+ this._moveStart(true, options.noMoveStart ?? false)._animateZoom(center, zoom, true);
792
+ });
793
+ return true;
794
+ }
795
+ _animateZoom(center, zoom, startAnim, noUpdate) {
796
+ if (!this._mapPane) return;
797
+ if (startAnim) {
798
+ this._animatingZoom = true;
799
+ this._animateToCenter = center;
800
+ this._animateToZoom = zoom;
801
+ this._mapPane.classList.add("maplair-zoom-anim");
802
+ }
803
+ this.fire("zoomanim", {
804
+ center,
805
+ zoom,
806
+ noUpdate
807
+ });
808
+ if (!this._tempFireZoomEvent) this._tempFireZoomEvent = this._zoom !== this._animateToZoom;
809
+ this._move(this._animateToCenter, this._animateToZoom, void 0, true);
810
+ this._transitionEndTimer = setTimeout(this._onZoomTransitionEnd.bind(this), 250);
811
+ }
812
+ _onZoomTransitionEnd() {
813
+ if (!this._animatingZoom) return;
814
+ this._mapPane?.classList.remove("maplair-zoom-anim");
815
+ this._animatingZoom = false;
816
+ this._move(this._animateToCenter, this._animateToZoom, void 0, true);
817
+ if (this._tempFireZoomEvent) this.fire("zoom");
818
+ delete this._tempFireZoomEvent;
819
+ this.fire("move");
820
+ this._moveEnd(true);
821
+ }
822
+ };
823
+ for (const feature of [
824
+ AttributionControl,
825
+ Control,
826
+ DivOverlay,
827
+ Layer,
828
+ BoxZoomHandler,
829
+ DoubleClickZoomHandler,
830
+ DragHandler,
831
+ KeyboardHandler,
832
+ PinchZoomHandler,
833
+ ScrollWheelZoomHandler,
834
+ TapHoldHandler,
835
+ Popup,
836
+ Tooltip,
837
+ Renderer_getRenderer_exports,
838
+ ZoomControl
839
+ ]) feature.register(MaplairMap);
840
+ const Map = MaplairMap;
841
+ //#endregion
842
+ export { Map, MaplairMap };
843
+
844
+ //# sourceMappingURL=Map.js.map