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,192 @@
1
+ import { setOptions } from "../core/Util.js";
2
+ import { Point } from "../geometry/Point.js";
3
+ import { setPosition, toBack, toFront } from "../dom/DomUtil.js";
4
+ import { LatLng } from "../geo/LatLng.js";
5
+ import { Layer } from "./Layer.js";
6
+ import { FeatureGroup } from "./FeatureGroup.js";
7
+ //#region src/layer/DivOverlay.js
8
+ var DivOverlay = class DivOverlay extends Layer {
9
+ static {
10
+ this.setDefaultOptions({
11
+ interactive: false,
12
+ offset: [0, 0],
13
+ className: "",
14
+ pane: void 0,
15
+ content: ""
16
+ });
17
+ }
18
+ constructor(options, source) {
19
+ super();
20
+ if (options instanceof LatLng || Array.isArray(options)) {
21
+ this._latlng = new LatLng(options);
22
+ setOptions(this, source);
23
+ } else {
24
+ setOptions(this, options);
25
+ this._source = source;
26
+ }
27
+ if (this.options.content) this._content = this.options.content;
28
+ this.callInitHooks(DivOverlay);
29
+ }
30
+ openOn(map) {
31
+ map = arguments.length ? map : this._source._map;
32
+ if (!map.hasLayer(this)) map.addLayer(this);
33
+ return this;
34
+ }
35
+ close() {
36
+ this._map?.removeLayer(this);
37
+ return this;
38
+ }
39
+ toggle(layer) {
40
+ if (this._map) this.close();
41
+ else {
42
+ if (arguments.length) this._source = layer;
43
+ else layer = this._source;
44
+ this._prepareOpen();
45
+ this.openOn(layer._map);
46
+ }
47
+ return this;
48
+ }
49
+ onAdd(map) {
50
+ this._zoomAnimated = map._zoomAnimated;
51
+ if (!this._container) this._initLayout();
52
+ if (map._fadeAnimated) this._container.style.opacity = 0;
53
+ clearTimeout(this._removeTimeout);
54
+ this.getPane().appendChild(this._container);
55
+ this.update();
56
+ if (map._fadeAnimated) this._container.style.opacity = 1;
57
+ this.bringToFront();
58
+ if (this.options.interactive) {
59
+ this._container.classList.add("maplair-interactive");
60
+ this.addInteractiveTarget(this._container);
61
+ }
62
+ }
63
+ onRemove(map) {
64
+ if (map._fadeAnimated) {
65
+ this._container.style.opacity = 0;
66
+ this._removeTimeout = setTimeout(() => this._container.remove(), 200);
67
+ } else this._container.remove();
68
+ if (this.options.interactive) {
69
+ this._container.classList.remove("maplair-interactive");
70
+ this.removeInteractiveTarget(this._container);
71
+ }
72
+ }
73
+ getLatLng() {
74
+ return this._latlng;
75
+ }
76
+ setLatLng(latlng) {
77
+ this._latlng = new LatLng(latlng);
78
+ if (this._map) {
79
+ this._updatePosition();
80
+ this._adjustPan();
81
+ }
82
+ return this;
83
+ }
84
+ getContent() {
85
+ return this._content;
86
+ }
87
+ setContent(content) {
88
+ this._content = content;
89
+ this.update();
90
+ return this;
91
+ }
92
+ getElement() {
93
+ return this._container;
94
+ }
95
+ update() {
96
+ if (!this._map) return;
97
+ this._container.style.visibility = "hidden";
98
+ this._updateContent();
99
+ this._updateLayout();
100
+ this._updatePosition();
101
+ this._container.style.visibility = "";
102
+ this._adjustPan();
103
+ }
104
+ getEvents() {
105
+ const events = {
106
+ zoom: this._updatePosition,
107
+ viewreset: this._updatePosition
108
+ };
109
+ if (this._zoomAnimated) events.zoomanim = this._animateZoom;
110
+ return events;
111
+ }
112
+ isOpen() {
113
+ return !!this._map && this._map.hasLayer(this);
114
+ }
115
+ bringToFront() {
116
+ if (this._map) toFront(this._container);
117
+ return this;
118
+ }
119
+ bringToBack() {
120
+ if (this._map) toBack(this._container);
121
+ return this;
122
+ }
123
+ _prepareOpen(latlng) {
124
+ let source = this._source;
125
+ if (!source._map) return false;
126
+ if (source instanceof FeatureGroup) {
127
+ source = null;
128
+ for (const layer of Object.values(this._source._layers)) if (layer._map) {
129
+ source = layer;
130
+ break;
131
+ }
132
+ if (!source) return false;
133
+ this._source = source;
134
+ }
135
+ if (!latlng) {
136
+ if (source.getCenter) latlng = source.getCenter();
137
+ else if (source.getLatLng) latlng = source.getLatLng();
138
+ else if (source.getBounds) latlng = source.getBounds().getCenter();
139
+ else throw new Error("Unable to get source layer LatLng.");
140
+ }
141
+ this.setLatLng(latlng);
142
+ if (this._map) this.update();
143
+ return true;
144
+ }
145
+ _updateContent() {
146
+ if (!this._content) return;
147
+ const node = this._contentNode;
148
+ const content = typeof this._content === "function" ? this._content(this._source ?? this) : this._content;
149
+ if (typeof content === "string") node.innerHTML = content;
150
+ else {
151
+ while (node.hasChildNodes()) node.removeChild(node.firstChild);
152
+ node.appendChild(content);
153
+ }
154
+ this.fire("contentupdate");
155
+ }
156
+ _updatePosition() {
157
+ if (!this._map) return;
158
+ const pos = this._map.latLngToLayerPoint(this._latlng), anchor = this._getAnchor();
159
+ let offset = new Point(this.options.offset);
160
+ if (this._zoomAnimated) setPosition(this._container, pos.add(anchor));
161
+ else offset = offset.add(pos).add(anchor);
162
+ const bottom = this._containerBottom = -offset.y, left = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;
163
+ this._container.style.bottom = `${bottom}px`;
164
+ this._container.style.left = `${left}px`;
165
+ }
166
+ _getAnchor() {
167
+ return [0, 0];
168
+ }
169
+ static register(MaplairMap) {
170
+ MaplairMap.include({ _initOverlay(OverlayClass, content, latlng, options) {
171
+ let overlay = content;
172
+ if (!(overlay instanceof OverlayClass)) overlay = new OverlayClass(options).setContent(content);
173
+ if (latlng) overlay.setLatLng(latlng);
174
+ return overlay;
175
+ } });
176
+ Layer.include({ _initOverlay(OverlayClass, old, content, options) {
177
+ let overlay = content;
178
+ if (overlay instanceof OverlayClass) {
179
+ setOptions(overlay, options);
180
+ overlay._source = this;
181
+ } else {
182
+ overlay = old && !options ? old : new OverlayClass(options, this);
183
+ overlay.setContent(content);
184
+ }
185
+ return overlay;
186
+ } });
187
+ }
188
+ };
189
+ //#endregion
190
+ export { DivOverlay };
191
+
192
+ //# sourceMappingURL=DivOverlay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DivOverlay.js","names":[],"sources":["../../../src/layer/DivOverlay.js"],"sourcesContent":["import {Layer} from './Layer.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {Point} from '../geometry/Point.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n\n/*\n * @class DivOverlay\n * @inherits Interactive layer\n * Base model for Popup and Tooltip. Inherit from it for custom overlays like plugins.\n */\n\n// @namespace DivOverlay\nexport class DivOverlay extends Layer {\n\n\tstatic {\n\t\t// @section\n\t\t// @aka DivOverlay options\n\t\tthis.setDefaultOptions({\n\t\t\t// @option interactive: Boolean = false\n\t\t\t// If true, the popup/tooltip will listen to the pointer events.\n\t\t\tinteractive: false,\n\n\t\t\t// @option offset: Point = Point(0, 0)\n\t\t\t// The offset of the overlay position.\n\t\t\toffset: [0, 0],\n\n\t\t\t// @option className: String = ''\n\t\t\t// A custom CSS class name to assign to the overlay.\n\t\t\tclassName: '',\n\n\t\t\t// @option pane: String = undefined\n\t\t\t// `Map pane` where the overlay will be added.\n\t\t\tpane: undefined,\n\n\t\t\t// @option content: String|HTMLElement|Function = ''\n\t\t\t// Sets the HTML content of the overlay while initializing. If a function is passed the source layer will be\n\t\t\t// passed to the function. The function should return a `String` or `HTMLElement` to be used in the overlay.\n\t\t\t// String content is rendered as HTML; sanitize untrusted input or pass an `HTMLElement` with safe `textContent` instead.\n\t\t\tcontent: ''\n\t\t});\n\t}\n\n\tconstructor(options, source) {\n\t\tsuper();\n\t\tif (options instanceof LatLng || Array.isArray(options)) {\n\t\t\tthis._latlng = new LatLng(options);\n\t\t\tUtil.setOptions(this, source);\n\t\t} else {\n\t\t\tUtil.setOptions(this, options);\n\t\t\tthis._source = source;\n\t\t}\n\t\tif (this.options.content) {\n\t\t\tthis._content = this.options.content;\n\t\t}\n\n\t\tthis.callInitHooks(DivOverlay);\n\t}\n\n\t// @method openOn(map: MaplairMap): this\n\t// Adds the overlay to the map.\n\t// Alternative to `map.openPopup(popup)`/`.openTooltip(tooltip)`.\n\topenOn(map) {\n\t\tmap = arguments.length ? map : this._source._map; // experimental, not the part of public api\n\t\tif (!map.hasLayer(this)) {\n\t\t\tmap.addLayer(this);\n\t\t}\n\t\treturn this;\n\t}\n\n\t// @method close(): this\n\t// Closes the overlay.\n\t// Alternative to `map.closePopup(popup)`/`.closeTooltip(tooltip)`\n\t// and `layer.closePopup()`/`.closeTooltip()`.\n\tclose() {\n\t\tthis._map?.removeLayer(this);\n\t\treturn this;\n\t}\n\n\t// @method toggle(layer?: Layer): this\n\t// Opens or closes the overlay bound to layer depending on its current state.\n\t// Argument may be omitted only for overlay bound to layer.\n\t// Alternative to `layer.togglePopup()`/`.toggleTooltip()`.\n\ttoggle(layer) {\n\t\tif (this._map) {\n\t\t\tthis.close();\n\t\t} else {\n\t\t\tif (arguments.length) {\n\t\t\t\tthis._source = layer;\n\t\t\t} else {\n\t\t\t\tlayer = this._source;\n\t\t\t}\n\t\t\tthis._prepareOpen();\n\n\t\t\t// open the overlay on the map\n\t\t\tthis.openOn(layer._map);\n\t\t}\n\t\treturn this;\n\t}\n\n\tonAdd(map) {\n\t\tthis._zoomAnimated = map._zoomAnimated;\n\n\t\tif (!this._container) {\n\t\t\tthis._initLayout();\n\t\t}\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 0;\n\t\t}\n\n\t\tclearTimeout(this._removeTimeout);\n\t\tthis.getPane().appendChild(this._container);\n\t\tthis.update();\n\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 1;\n\t\t}\n\n\t\tthis.bringToFront();\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.add('maplair-interactive');\n\t\t\tthis.addInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\tonRemove(map) {\n\t\tif (map._fadeAnimated) {\n\t\t\tthis._container.style.opacity = 0;\n\t\t\tthis._removeTimeout = setTimeout(() => this._container.remove(), 200);\n\t\t} else {\n\t\t\tthis._container.remove();\n\t\t}\n\n\t\tif (this.options.interactive) {\n\t\t\tthis._container.classList.remove('maplair-interactive');\n\t\t\tthis.removeInteractiveTarget(this._container);\n\t\t}\n\t}\n\n\t// @namespace DivOverlay\n\t// @method getLatLng: LatLng\n\t// Returns the geographical point of the overlay.\n\tgetLatLng() {\n\t\treturn this._latlng;\n\t}\n\n\t// @method setLatLng(latlng: LatLng): this\n\t// Sets the geographical point where the overlay will open.\n\tsetLatLng(latlng) {\n\t\tthis._latlng = new LatLng(latlng);\n\t\tif (this._map) {\n\t\t\tthis._updatePosition();\n\t\t\tthis._adjustPan();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// @method getContent: String|HTMLElement|Function)\n\t// Returns the content of the overlay.\n\tgetContent() {\n\t\treturn this._content;\n\t}\n\n\t// @method setContent(htmlContent: String|HTMLElement|Function): this\n\t// Sets the HTML content of the overlay. A `String` argument is rendered as\n\t// HTML; if it may contain untrusted input, sanitize it (e.g. with DOMPurify)\n\t// or pass an `HTMLElement` with safe `textContent` instead. If a function is\n\t// passed the source layer will be passed to the function. The function should\n\t// return a `String` or `HTMLElement` to be used in the overlay.\n\tsetContent(content) {\n\t\tthis._content = content;\n\t\tthis.update();\n\t\treturn this;\n\t}\n\n\t// @method getElement: HTMLElement\n\t// Returns the HTML container of the overlay.\n\tgetElement() {\n\t\treturn this._container;\n\t}\n\n\t// @method update: null\n\t// Updates the overlay content, layout and position. Useful for updating the overlay after something inside changed, e.g. image loaded.\n\tupdate() {\n\t\tif (!this._map) { return; }\n\n\t\tthis._container.style.visibility = 'hidden';\n\n\t\tthis._updateContent();\n\t\tthis._updateLayout();\n\t\tthis._updatePosition();\n\n\t\tthis._container.style.visibility = '';\n\n\t\tthis._adjustPan();\n\t}\n\n\tgetEvents() {\n\t\tconst events = {\n\t\t\tzoom: this._updatePosition,\n\t\t\tviewreset: this._updatePosition\n\t\t};\n\n\t\tif (this._zoomAnimated) {\n\t\t\tevents.zoomanim = this._animateZoom;\n\t\t}\n\t\treturn events;\n\t}\n\n\t// @method isOpen: Boolean\n\t// Returns `true` when the overlay is visible on the map.\n\tisOpen() {\n\t\treturn !!this._map && this._map.hasLayer(this);\n\t}\n\n\t// @method bringToFront: this\n\t// Brings this overlay in front of other overlays (in the same map pane).\n\tbringToFront() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toFront(this._container);\n\t\t}\n\t\treturn this;\n\t}\n\n\t// @method bringToBack: this\n\t// Brings this overlay to the back of other overlays (in the same map pane).\n\tbringToBack() {\n\t\tif (this._map) {\n\t\t\tDomUtil.toBack(this._container);\n\t\t}\n\t\treturn this;\n\t}\n\n\t// prepare bound overlay to open: update latlng pos / content source (for FeatureGroup)\n\t_prepareOpen(latlng) {\n\t\tlet source = this._source;\n\t\tif (!source._map) { return false; }\n\n\t\tif (source instanceof FeatureGroup) {\n\t\t\tsource = null;\n\t\t\tfor (const layer of Object.values(this._source._layers)) {\n\t\t\t\tif (layer._map) {\n\t\t\t\t\tsource = layer;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!source) { return false; } // Unable to get source layer.\n\n\t\t\t// set overlay source to this layer\n\t\t\tthis._source = source;\n\t\t}\n\n\t\tif (!latlng) {\n\t\t\tif (source.getCenter) {\n\t\t\t\tlatlng = source.getCenter();\n\t\t\t} else if (source.getLatLng) {\n\t\t\t\tlatlng = source.getLatLng();\n\t\t\t} else if (source.getBounds) {\n\t\t\t\tlatlng = source.getBounds().getCenter();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Unable to get source layer LatLng.');\n\t\t\t}\n\t\t}\n\t\tthis.setLatLng(latlng);\n\n\t\tif (this._map) {\n\t\t\t// update the overlay (content, layout, etc...)\n\t\t\tthis.update();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t_updateContent() {\n\t\tif (!this._content) { return; }\n\n\t\tconst node = this._contentNode;\n\t\tconst content = (typeof this._content === 'function') ? this._content(this._source ?? this) : this._content;\n\n\t\tif (typeof content === 'string') {\n\t\t\tnode.innerHTML = content;\n\t\t} else {\n\t\t\twhile (node.hasChildNodes()) {\n\t\t\t\tnode.removeChild(node.firstChild);\n\t\t\t}\n\t\t\tnode.appendChild(content);\n\t\t}\n\n\t\t// @namespace DivOverlay\n\t\t// @section DivOverlay events\n\t\t// @event contentupdate: Event\n\t\t// Fired when the content of the overlay is updated\n\t\tthis.fire('contentupdate');\n\t}\n\n\t_updatePosition() {\n\t\tif (!this._map) { return; }\n\n\t\tconst pos = this._map.latLngToLayerPoint(this._latlng),\n\t\tanchor = this._getAnchor();\n\t\tlet offset = new Point(this.options.offset);\n\n\t\tif (this._zoomAnimated) {\n\t\t\tDomUtil.setPosition(this._container, pos.add(anchor));\n\t\t} else {\n\t\t\toffset = offset.add(pos).add(anchor);\n\t\t}\n\n\t\tconst bottom = this._containerBottom = -offset.y,\n\t\tleft = this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x;\n\n\t\t// bottom position the overlay in case the height of the overlay changes (images loading etc)\n\t\tthis._container.style.bottom = `${bottom}px`;\n\t\tthis._container.style.left = `${left}px`;\n\t}\n\n\t_getAnchor() {\n\t\treturn [0, 0];\n\t}\n\n\t// Registers this default feature on the map class, called by `MaplairMap` itself.\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include({\n\t\t\t_initOverlay(OverlayClass, content, latlng, options) {\n\t\t\t\tlet overlay = content;\n\t\t\t\tif (!(overlay instanceof OverlayClass)) {\n\t\t\t\t\toverlay = new OverlayClass(options).setContent(content);\n\t\t\t\t}\n\t\t\t\tif (latlng) {\n\t\t\t\t\toverlay.setLatLng(latlng);\n\t\t\t\t}\n\t\t\t\treturn overlay;\n\t\t\t}\n\t\t});\n\n\t\tLayer.include({\n\t\t\t_initOverlay(OverlayClass, old, content, options) {\n\t\t\t\tlet overlay = content;\n\t\t\t\tif (overlay instanceof OverlayClass) {\n\t\t\t\t\tUtil.setOptions(overlay, options);\n\t\t\t\t\toverlay._source = this;\n\t\t\t\t} else {\n\t\t\t\t\toverlay = (old && !options) ? old : new OverlayClass(options, this);\n\t\t\t\t\toverlay.setContent(content);\n\t\t\t\t}\n\t\t\t\treturn overlay;\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;AAcA,IAAa,aAAb,MAAa,mBAAmB,MAAM;CAErC;EAGC,KAAK,kBAAkB;GAGtB,aAAa;GAIb,QAAQ,CAAC,GA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CAAC;CACb;CAGA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,EAClB,aAAa,cAAc,SAAS,QAAQ,SAAS;GACpD,IAAI,UAAU;GACd,IAAI,EAAE,mBAAmB,eACxB,UAAU,IAAI,aAAa,OAAO,CAAC,CAAC,WAAW,OAAO;GAEvD,IAAI,QACH,QAAQ,UAAU,MAAM;GAEzB,OAAO;EACR,EACD,CAAC;EAED,MAAM,QAAQ,EACb,aAAa,cAAc,KAAK,SAAS,SAAS;GACjD,IAAI,UAAU;GACd,IAAI,mBAAmB,cAAc;IACpC,WAAgB,SAAS,OAAO;IAChC,QAAQ,UAAU;GACnB,OAAO;IACN,UAAW,OAAO,CAAC,UAAW,MAAM,IAAI,aAAa,SAAS,IAAI;IAClE,QAAQ,WAAW,OAAO;GAC3B;GACA,OAAO;EACR,EACD,CAAC;CACF;AACD"}
@@ -0,0 +1,40 @@
1
+ import { LatLngBounds } from "../geo/LatLngBounds.js";
2
+ import { LayerGroup } from "./LayerGroup.js";
3
+ //#region src/layer/FeatureGroup.js
4
+ var FeatureGroup = class FeatureGroup extends LayerGroup {
5
+ constructor(...args) {
6
+ super(...args);
7
+ this.callInitHooks(FeatureGroup);
8
+ }
9
+ addLayer(layer) {
10
+ if (this.hasLayer(layer)) return this;
11
+ layer.addEventParent(this);
12
+ super.addLayer(layer);
13
+ return this.fire("layeradd", { layer });
14
+ }
15
+ removeLayer(layer) {
16
+ if (!this.hasLayer(layer)) return this;
17
+ if (layer in this._layers) layer = this._layers[layer];
18
+ layer.removeEventParent(this);
19
+ super.removeLayer(layer);
20
+ return this.fire("layerremove", { layer });
21
+ }
22
+ setStyle(style) {
23
+ return this.eachLayer((l) => l.setStyle?.(style));
24
+ }
25
+ bringToFront() {
26
+ return this.eachLayer((l) => l.bringToFront?.());
27
+ }
28
+ bringToBack() {
29
+ return this.eachLayer((l) => l.bringToBack?.());
30
+ }
31
+ getBounds() {
32
+ const bounds = new LatLngBounds();
33
+ for (const layer of Object.values(this._layers)) bounds.extend(layer.getBounds ? layer.getBounds() : layer.getLatLng());
34
+ return bounds;
35
+ }
36
+ };
37
+ //#endregion
38
+ export { FeatureGroup };
39
+
40
+ //# sourceMappingURL=FeatureGroup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FeatureGroup.js","names":[],"sources":["../../../src/layer/FeatureGroup.js"],"sourcesContent":["import {LayerGroup} from './LayerGroup.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\n\n/*\n * @class FeatureGroup\n * @inherits LayerGroup\n *\n * Extended `LayerGroup` that makes it easier to do the same thing to all its member layers:\n * * [`bindPopup`](#layer-bindpopup) binds a popup to all of the layers at once (likewise with [`bindTooltip`](#layer-bindtooltip))\n * * Events are propagated to the `FeatureGroup`, so if the group has an event\n * handler, it will handle events from any of the layers. This includes pointer events\n * and custom events.\n * * Has `layeradd` and `layerremove` events\n *\n * @example\n *\n * ```js\n * new FeatureGroup([marker1, marker2, polyline])\n * \t.bindPopup('Hello world!')\n * \t.on('click', function() { alert('Clicked on a member of the group!'); })\n * \t.addTo(map);\n * ```\n */\n\n// @constructor FeatureGroup(layers?: Layer[], options?: Object)\n// Create a feature group, optionally given an initial set of layers and an `options` object.\nexport class FeatureGroup extends LayerGroup {\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(FeatureGroup);\n\t}\n\n\n\taddLayer(layer) {\n\t\tif (this.hasLayer(layer)) {\n\t\t\treturn this;\n\t\t}\n\n\t\tlayer.addEventParent(this);\n\n\t\tsuper.addLayer(layer);\n\n\t\t// @event layeradd: LayerEvent\n\t\t// Fired when a layer is added to this `FeatureGroup`\n\t\treturn this.fire('layeradd', {layer});\n\t}\n\n\tremoveLayer(layer) {\n\t\tif (!this.hasLayer(layer)) {\n\t\t\treturn this;\n\t\t}\n\t\tif (layer in this._layers) {\n\t\t\tlayer = this._layers[layer];\n\t\t}\n\n\t\tlayer.removeEventParent(this);\n\n\t\tsuper.removeLayer(layer);\n\n\t\t// @event layerremove: LayerEvent\n\t\t// Fired when a layer is removed from this `FeatureGroup`\n\t\treturn this.fire('layerremove', {layer});\n\t}\n\n\t// @method setStyle(style: Path options): this\n\t// Sets the given path options to each layer of the group that has a `setStyle` method.\n\tsetStyle(style) {\n\t\treturn this.eachLayer(l => l.setStyle?.(style));\n\t}\n\n\t// @method bringToFront(): this\n\t// Brings the layer group to the top of all other layers\n\tbringToFront() {\n\t\treturn this.eachLayer(l => l.bringToFront?.());\n\t}\n\n\t// @method bringToBack(): this\n\t// Brings the layer group to the back of all other layers\n\tbringToBack() {\n\t\treturn this.eachLayer(l => l.bringToBack?.());\n\t}\n\n\t// @method getBounds(): LatLngBounds\n\t// Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children).\n\tgetBounds() {\n\t\tconst bounds = new LatLngBounds();\n\n\t\tfor (const layer of Object.values(this._layers)) {\n\t\t\tbounds.extend(layer.getBounds ? layer.getBounds() : layer.getLatLng());\n\t\t}\n\t\treturn bounds;\n\t}\n}\n"],"mappings":";;;AA0BA,IAAa,eAAb,MAAa,qBAAqB,WAAW;CAC5C,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,YAAY;CAChC;CAGA,SAAS,OAAO;EACf,IAAI,KAAK,SAAS,KAAK,GACtB,OAAO;EAGR,MAAM,eAAe,IAAI;EAEzB,MAAM,SAAS,KAAK;EAIpB,OAAO,KAAK,KAAK,YAAY,EAAC,MAAK,CAAC;CACrC;CAEA,YAAY,OAAO;EAClB,IAAI,CAAC,KAAK,SAAS,KAAK,GACvB,OAAO;EAER,IAAI,SAAS,KAAK,SACjB,QAAQ,KAAK,QAAQ;EAGtB,MAAM,kBAAkB,IAAI;EAE5B,MAAM,YAAY,KAAK;EAIvB,OAAO,KAAK,KAAK,eAAe,EAAC,MAAK,CAAC;CACxC;CAIA,SAAS,OAAO;EACf,OAAO,KAAK,WAAU,MAAK,EAAE,WAAW,KAAK,CAAC;CAC/C;CAIA,eAAe;EACd,OAAO,KAAK,WAAU,MAAK,EAAE,eAAe,CAAC;CAC9C;CAIA,cAAc;EACb,OAAO,KAAK,WAAU,MAAK,EAAE,cAAc,CAAC;CAC7C;CAIA,YAAY;EACX,MAAM,SAAS,IAAI,aAAa;EAEhC,KAAK,MAAM,SAAS,OAAO,OAAO,KAAK,OAAO,GAC7C,OAAO,OAAO,MAAM,YAAY,MAAM,UAAU,IAAI,MAAM,UAAU,CAAC;EAEtE,OAAO;CACR;AACD"}
@@ -0,0 +1,192 @@
1
+ import { formatNum } from "../core/Util.js";
2
+ import { LatLng } from "../geo/LatLng.js";
3
+ import { isFlat } from "../geometry/LineUtil.js";
4
+ import { LayerGroup } from "./LayerGroup.js";
5
+ import { FeatureGroup } from "./FeatureGroup.js";
6
+ import { Marker } from "./marker/Marker.js";
7
+ import { CircleMarker } from "./vector/CircleMarker.js";
8
+ import { Circle } from "./vector/Circle.js";
9
+ import { Polyline } from "./vector/Polyline.js";
10
+ import { Polygon } from "./vector/Polygon.js";
11
+ //#region src/layer/GeoJSON.js
12
+ var GeoJSON = class GeoJSON extends FeatureGroup {
13
+ constructor(geojson, options) {
14
+ super(void 0, options);
15
+ if (geojson) this.addData(geojson);
16
+ this.callInitHooks(GeoJSON);
17
+ }
18
+ addData(geojson) {
19
+ const features = Array.isArray(geojson) ? geojson : geojson.features;
20
+ if (features) {
21
+ for (const feature of features) if (feature.geometries || feature.geometry || feature.features || feature.coordinates) this.addData(feature);
22
+ return this;
23
+ }
24
+ const options = this.options;
25
+ if (options.filter && !options.filter(geojson)) return this;
26
+ const layer = GeoJSON.geometryToLayer(geojson, options);
27
+ if (!layer) return this;
28
+ layer.feature = GeoJSON.asFeature(geojson);
29
+ layer.defaultOptions = layer.options;
30
+ this.resetStyle(layer);
31
+ if (options.onEachFeature) options.onEachFeature(geojson, layer);
32
+ return this.addLayer(layer);
33
+ }
34
+ resetStyle(layer) {
35
+ if (layer === void 0) return this.eachLayer(this.resetStyle, this);
36
+ layer.options = Object.create(layer.defaultOptions);
37
+ this._setLayerStyle(layer, this.options.style);
38
+ return this;
39
+ }
40
+ setStyle(style) {
41
+ return this.eachLayer((layer) => this._setLayerStyle(layer, style));
42
+ }
43
+ _setLayerStyle(layer, style) {
44
+ if (layer.setStyle) {
45
+ if (typeof style === "function") style = style(layer.feature);
46
+ layer.setStyle(style);
47
+ }
48
+ }
49
+ static geometryToLayer(geojson, options) {
50
+ const geometry = geojson.type === "Feature" ? geojson.geometry : geojson, coords = geometry?.coordinates, layers = [], pointToLayer = options?.pointToLayer, _coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;
51
+ let latlng, latlngs;
52
+ if (!coords && !geometry) return null;
53
+ switch (geometry.type) {
54
+ case "Point":
55
+ latlng = _coordsToLatLng(coords);
56
+ return GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);
57
+ case "MultiPoint":
58
+ for (const coord of coords) {
59
+ latlng = _coordsToLatLng(coord);
60
+ layers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));
61
+ }
62
+ return new FeatureGroup(layers);
63
+ case "LineString":
64
+ case "MultiLineString":
65
+ latlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === "LineString" ? 0 : 1, _coordsToLatLng);
66
+ return new Polyline(latlngs, options);
67
+ case "Polygon":
68
+ case "MultiPolygon":
69
+ latlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === "Polygon" ? 1 : 2, _coordsToLatLng);
70
+ return new Polygon(latlngs, options);
71
+ case "GeometryCollection":
72
+ for (const g of geometry.geometries) {
73
+ const geoLayer = GeoJSON.geometryToLayer({
74
+ geometry: g,
75
+ type: "Feature",
76
+ properties: geojson.properties
77
+ }, options);
78
+ if (geoLayer) layers.push(geoLayer);
79
+ }
80
+ return new FeatureGroup(layers);
81
+ case "FeatureCollection":
82
+ for (const f of geometry.features) {
83
+ const featureLayer = GeoJSON.geometryToLayer(f, options);
84
+ if (featureLayer) layers.push(featureLayer);
85
+ }
86
+ return new FeatureGroup(layers);
87
+ default: throw new Error("Invalid GeoJSON object.");
88
+ }
89
+ }
90
+ static _pointToLayer(pointToLayerFn, geojson, latlng, options) {
91
+ return pointToLayerFn ? pointToLayerFn(geojson, latlng) : new Marker(latlng, options?.markersInheritOptions && options);
92
+ }
93
+ static coordsToLatLng(coords) {
94
+ return new LatLng(coords[1], coords[0], coords[2]);
95
+ }
96
+ static coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {
97
+ return coords.map((coord) => levelsDeep ? GeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) : (_coordsToLatLng || GeoJSON.coordsToLatLng)(coord));
98
+ }
99
+ static latLngToCoords(latlng, precision) {
100
+ latlng = new LatLng(latlng);
101
+ return latlng.alt !== void 0 ? [
102
+ formatNum(latlng.lng, precision),
103
+ formatNum(latlng.lat, precision),
104
+ formatNum(latlng.alt, precision)
105
+ ] : [formatNum(latlng.lng, precision), formatNum(latlng.lat, precision)];
106
+ }
107
+ static latLngsToCoords(latlngs, levelsDeep, close, precision) {
108
+ const coords = latlngs.map((latlng) => levelsDeep ? GeoJSON.latLngsToCoords(latlng, isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) : GeoJSON.latLngToCoords(latlng, precision));
109
+ if (!levelsDeep && close && coords.length > 0) coords.push(coords[0].slice());
110
+ return coords;
111
+ }
112
+ static getFeature(layer, newGeometry) {
113
+ return layer.feature ? {
114
+ ...layer.feature,
115
+ geometry: newGeometry
116
+ } : GeoJSON.asFeature(newGeometry);
117
+ }
118
+ static asFeature(geojson) {
119
+ if (geojson.type === "Feature" || geojson.type === "FeatureCollection") return geojson;
120
+ return {
121
+ type: "Feature",
122
+ properties: {},
123
+ geometry: geojson
124
+ };
125
+ }
126
+ };
127
+ const PointToGeoJSON = { toGeoJSON(precision) {
128
+ return GeoJSON.getFeature(this, {
129
+ type: "Point",
130
+ coordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)
131
+ });
132
+ } };
133
+ Marker.include(PointToGeoJSON);
134
+ Circle.include(PointToGeoJSON);
135
+ CircleMarker.include(PointToGeoJSON);
136
+ Polyline.include({ toGeoJSON(precision) {
137
+ const multi = !isFlat(this._latlngs);
138
+ const coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);
139
+ return GeoJSON.getFeature(this, {
140
+ type: `${multi ? "Multi" : ""}LineString`,
141
+ coordinates: coords
142
+ });
143
+ } });
144
+ Polygon.include({ toGeoJSON(precision) {
145
+ const holes = !isFlat(this._latlngs), multi = holes && !isFlat(this._latlngs[0]);
146
+ let coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);
147
+ if (!holes) coords = [coords];
148
+ return GeoJSON.getFeature(this, {
149
+ type: `${multi ? "Multi" : ""}Polygon`,
150
+ coordinates: coords
151
+ });
152
+ } });
153
+ LayerGroup.include({
154
+ toMultiPoint(precision) {
155
+ const coords = [];
156
+ this.eachLayer((layer) => {
157
+ coords.push(layer.toGeoJSON(precision).geometry.coordinates);
158
+ });
159
+ return GeoJSON.getFeature(this, {
160
+ type: "MultiPoint",
161
+ coordinates: coords
162
+ });
163
+ },
164
+ toGeoJSON(precision) {
165
+ const type = this.feature?.geometry?.type;
166
+ if (type === "MultiPoint") return this.toMultiPoint(precision);
167
+ const isGeometryCollection = type === "GeometryCollection", jsons = [];
168
+ this.eachLayer((layer) => {
169
+ if (layer.toGeoJSON) {
170
+ const json = layer.toGeoJSON(precision);
171
+ if (isGeometryCollection) jsons.push(json.geometry);
172
+ else {
173
+ const feature = GeoJSON.asFeature(json);
174
+ if (feature.type === "FeatureCollection") jsons.push(...feature.features);
175
+ else jsons.push(feature);
176
+ }
177
+ }
178
+ });
179
+ if (isGeometryCollection) return GeoJSON.getFeature(this, {
180
+ geometries: jsons,
181
+ type: "GeometryCollection"
182
+ });
183
+ return {
184
+ type: "FeatureCollection",
185
+ features: jsons
186
+ };
187
+ }
188
+ });
189
+ //#endregion
190
+ export { GeoJSON };
191
+
192
+ //# sourceMappingURL=GeoJSON.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeoJSON.js","names":["Util.formatNum","LineUtil.isFlat"],"sources":["../../../src/layer/GeoJSON.js"],"sourcesContent":["import {LayerGroup} from './LayerGroup.js';\nimport {FeatureGroup} from './FeatureGroup.js';\nimport * as Util from '../core/Util.js';\nimport {Marker} from './marker/Marker.js';\nimport {Circle} from './vector/Circle.js';\nimport {CircleMarker} from './vector/CircleMarker.js';\nimport {Polyline} from './vector/Polyline.js';\nimport {Polygon} from './vector/Polygon.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport * as LineUtil from '../geometry/LineUtil.js';\n\n\n/*\n * @class GeoJSON\n * @inherits FeatureGroup\n *\n * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse\n * GeoJSON data and display it on the map. Extends `FeatureGroup`.\n *\n * @example\n *\n * ```js\n * new GeoJSON(data, {\n * \tstyle: function (feature) {\n * \t\treturn {color: feature.properties.color};\n * \t}\n * }).bindPopup(function (layer) {\n * \treturn layer.feature.properties.description;\n * }).addTo(map);\n * ```\n */\n\n// @namespace GeoJSON\n// @constructor GeoJSON(geojson?: Object, options?: GeoJSON options)\n// Creates a GeoJSON layer. Optionally accepts an object in\n// [GeoJSON format](https://tools.ietf.org/html/rfc7946) to display on the map\n// (you can alternatively add it later with `addData` method) and an `options` object.\nexport class GeoJSON extends FeatureGroup {\n\n\t/* @section\n\t * @aka GeoJSON options\n\t *\n\t * @option pointToLayer: Function = *\n\t * A `Function` defining how GeoJSON points spawn Maplair layers. It is internally\n\t * called when data is added, passing the GeoJSON point feature and its `LatLng`.\n\t * The default is to spawn a default `Marker`:\n\t * ```js\n\t * function(geoJsonPoint, latlng) {\n\t * \treturn new Marker(latlng);\n\t * }\n\t * ```\n\t *\n\t * @option style: Function = *\n\t * A `Function` defining the `Path options` for styling GeoJSON lines and polygons,\n\t * called internally when data is added.\n\t * The default value is to not override any defaults:\n\t * ```js\n\t * function (geoJsonFeature) {\n\t * \treturn {}\n\t * }\n\t * ```\n\t *\n\t * @option onEachFeature: Function = *\n\t * A `Function` that will be called once for each created `Feature`, after it has\n\t * been created and styled. Useful for attaching events and popups to features.\n\t * It will receive the `feature` as the first argument and its corresponding\n\t * spawned `layer` from [`asFeature`](#geojson-asFeature) as the second.\n\t * The default is to do nothing with the newly created layers:\n\t * ```js\n\t * function (feature, layer) {}\n\t * ```\n\t *\n\t * @option filter: Function = *\n\t * A `Function` that will be used to decide whether to include a feature or not.\n\t * The default is to include all features:\n\t * ```js\n\t * function (geoJsonFeature) {\n\t * \treturn true;\n\t * }\n\t * ```\n\t * Note: dynamically changing the `filter` option will have effect only on newly\n\t * added data. It will _not_ re-evaluate already included features.\n\t *\n\t * @option coordsToLatLng: Function = *\n\t * A `Function` that will be used for converting GeoJSON coordinates to `LatLng`s.\n\t * The default is the `coordsToLatLng` static method.\n\t *\n\t * @option markersInheritOptions: Boolean = false\n\t * Whether default Markers for \"Point\" type Features inherit from group options.\n\t */\n\n\tconstructor(geojson, options) {\n\t\tsuper(undefined, options);\n\n\t\tif (geojson) {\n\t\t\tthis.addData(geojson);\n\t\t}\n\n\t\tthis.callInitHooks(GeoJSON);\n\t}\n\n\t// @method addData( <GeoJSON> data ): this\n\t// Adds a GeoJSON object to the layer.\n\taddData(geojson) {\n\t\tconst features = Array.isArray(geojson) ? geojson : geojson.features;\n\n\t\tif (features) {\n\t\t\tfor (const feature of features) {\n\t\t\t\t// only add this if geometry or geometries are set and not null\n\t\t\t\tif (feature.geometries || feature.geometry || feature.features || feature.coordinates) {\n\t\t\t\t\tthis.addData(feature);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn this;\n\t\t}\n\n\t\tconst options = this.options;\n\n\t\tif (options.filter && !options.filter(geojson)) { return this; }\n\n\t\tconst layer = GeoJSON.geometryToLayer(geojson, options);\n\t\tif (!layer) {\n\t\t\treturn this;\n\t\t}\n\t\tlayer.feature = GeoJSON.asFeature(geojson);\n\n\t\tlayer.defaultOptions = layer.options;\n\t\tthis.resetStyle(layer);\n\n\t\tif (options.onEachFeature) {\n\t\t\toptions.onEachFeature(geojson, layer);\n\t\t}\n\n\t\treturn this.addLayer(layer);\n\t}\n\n\t// @method resetStyle( <Path> layer? ): this\n\t// Resets the given vector layer's style to the original GeoJSON style, useful for resetting style after hover events.\n\t// If `layer` is omitted, the style of all features in the current layer is reset.\n\tresetStyle(layer) {\n\t\tif (layer === undefined) {\n\t\t\treturn this.eachLayer(this.resetStyle, this);\n\t\t}\n\t\t// reset any custom styles\n\t\tlayer.options = Object.create(layer.defaultOptions);\n\t\tthis._setLayerStyle(layer, this.options.style);\n\t\treturn this;\n\t}\n\n\t// @method setStyle( <Function> style ): this\n\t// Changes styles of GeoJSON vector layers with the given style function.\n\tsetStyle(style) {\n\t\treturn this.eachLayer(layer => this._setLayerStyle(layer, style));\n\t}\n\n\t_setLayerStyle(layer, style) {\n\t\tif (layer.setStyle) {\n\t\t\tif (typeof style === 'function') {\n\t\t\t\tstyle = style(layer.feature);\n\t\t\t}\n\t\t\tlayer.setStyle(style);\n\t\t}\n\t}\n\n\t// @section\n\t// There are several static functions which can be called without instantiating GeoJSON:\n\n\t// @function geometryToLayer(featureData: Object, options?: GeoJSON options): Layer\n\t// Creates a `Layer` from a given GeoJSON feature. Can use a custom\n\t// [`pointToLayer`](#geojson-pointtolayer) and/or [`coordsToLatLng`](#geojson-coordstolatlng)\n\t// functions if provided as options.\n\tstatic geometryToLayer(geojson, options) {\n\n\t\tconst geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,\n\t\tcoords = geometry?.coordinates,\n\t\tlayers = [],\n\t\tpointToLayer = options?.pointToLayer,\n\t\t_coordsToLatLng = options?.coordsToLatLng ?? GeoJSON.coordsToLatLng;\n\t\tlet latlng, latlngs;\n\n\t\tif (!coords && !geometry) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (geometry.type) {\n\t\tcase 'Point':\n\t\t\tlatlng = _coordsToLatLng(coords);\n\t\t\treturn GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options);\n\n\t\tcase 'MultiPoint':\n\t\t\tfor (const coord of coords) {\n\t\t\t\tlatlng = _coordsToLatLng(coord);\n\t\t\t\tlayers.push(GeoJSON._pointToLayer(pointToLayer, geojson, latlng, options));\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'LineString':\n\t\tcase 'MultiLineString':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, _coordsToLatLng);\n\t\t\treturn new Polyline(latlngs, options);\n\n\t\tcase 'Polygon':\n\t\tcase 'MultiPolygon':\n\t\t\tlatlngs = GeoJSON.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, _coordsToLatLng);\n\t\t\treturn new Polygon(latlngs, options);\n\n\t\tcase 'GeometryCollection':\n\t\t\tfor (const g of geometry.geometries) {\n\t\t\t\tconst geoLayer = GeoJSON.geometryToLayer({\n\t\t\t\t\tgeometry: g,\n\t\t\t\t\ttype: 'Feature',\n\t\t\t\t\tproperties: geojson.properties\n\t\t\t\t}, options);\n\n\t\t\t\tif (geoLayer) {\n\t\t\t\t\tlayers.push(geoLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tcase 'FeatureCollection':\n\t\t\tfor (const f of geometry.features) {\n\t\t\t\tconst featureLayer = GeoJSON.geometryToLayer(f, options);\n\n\t\t\t\tif (featureLayer) {\n\t\t\t\t\tlayers.push(featureLayer);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new FeatureGroup(layers);\n\n\t\tdefault:\n\t\t\tthrow new Error('Invalid GeoJSON object.');\n\t\t}\n\t}\n\n\tstatic _pointToLayer(pointToLayerFn, geojson, latlng, options) {\n\t\treturn pointToLayerFn ?\n\t\t\tpointToLayerFn(geojson, latlng) :\n\t\t\tnew Marker(latlng, options?.markersInheritOptions && options);\n\t}\n\n\t// @function coordsToLatLng(coords: Array): LatLng\n\t// Creates a `LatLng` object from an array of 2 numbers (longitude, latitude)\n\t// or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points.\n\tstatic coordsToLatLng(coords) {\n\t\treturn new LatLng(coords[1], coords[0], coords[2]);\n\t}\n\n\t// @function coordsToLatLngs(coords: Array, levelsDeep?: Number, coordsToLatLng?: Function): Array\n\t// Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array.\n\t// `levelsDeep` specifies the nesting level (0 is for an array of points, 1 for an array of arrays of points, etc., 0 by default).\n\t// Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function.\n\tstatic coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {\n\t\treturn coords.map(coord => (levelsDeep ?\n\t\t\tGeoJSON.coordsToLatLngs(coord, levelsDeep - 1, _coordsToLatLng) :\n\t\t\t(_coordsToLatLng || GeoJSON.coordsToLatLng)(coord)));\n\t}\n\n\t// @function latLngToCoords(latlng: LatLng, precision?: Number|false): Array\n\t// Reverse of [`coordsToLatLng`](#geojson-coordstolatlng)\n\t// Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\tstatic latLngToCoords(latlng, precision) {\n\t\tlatlng = new LatLng(latlng);\n\t\treturn latlng.alt !== undefined ?\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :\n\t\t\t[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];\n\t}\n\n\t// @function latLngsToCoords(latlngs: Array, levelsDeep?: Number, close?: Boolean, precision?: Number|false): Array\n\t// Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs)\n\t// `close` determines whether the first point should be appended to the end of the array to close the feature, only used when `levelsDeep` is 0. False by default.\n\t// Coordinates values are rounded with [`formatNum`](#util-formatnum) function.\n\tstatic latLngsToCoords(latlngs, levelsDeep, close, precision) {\n\t\t// Check for flat arrays required to ensure unbalanced arrays are correctly converted in recursion\n\t\tconst coords = latlngs.map(latlng => (levelsDeep ?\n\t\t\tGeoJSON.latLngsToCoords(latlng, LineUtil.isFlat(latlng) ? 0 : levelsDeep - 1, close, precision) :\n\t\t\tGeoJSON.latLngToCoords(latlng, precision)));\n\n\t\tif (!levelsDeep && close && coords.length > 0) {\n\t\t\tcoords.push(coords[0].slice());\n\t\t}\n\n\t\treturn coords;\n\t}\n\n\t// @function getFeature(layer: Layer, newGeometry: Object): Object\n\t// Returns GeoJSON geometries/features of layer with new GeoJSON geometry.\n\tstatic getFeature(layer, newGeometry) {\n\t\treturn layer.feature ?\n\t\t\t{...layer.feature, geometry: newGeometry} :\n\t\t\tGeoJSON.asFeature(newGeometry);\n\t}\n\n\t// @function asFeature(geojson: Object): Object\n\t// Normalize GeoJSON geometries/features into GeoJSON features.\n\tstatic asFeature(geojson) {\n\t\tif (geojson.type === 'Feature' || geojson.type === 'FeatureCollection') {\n\t\t\treturn geojson;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'Feature',\n\t\t\tproperties: {},\n\t\t\tgeometry: geojson\n\t\t};\n\t}\n\n}\n\nconst PointToGeoJSON = {\n\ttoGeoJSON(precision) {\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'Point',\n\t\t\tcoordinates: GeoJSON.latLngToCoords(this.getLatLng(), precision)\n\t\t});\n\t}\n};\n\n// @namespace Marker\n// @section Other methods\n// @method toGeoJSON(precision?: Number|false): Object\n// Coordinates values are rounded with [`formatNum`](#util-formatnum) function with given `precision`.\n// Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the marker (as a GeoJSON `Point` Feature).\nMarker.include(PointToGeoJSON);\n\n// @namespace CircleMarker\n// @method toGeoJSON(precision?: Number|false): Object\n// Coordinates values are rounded with [`formatNum`](#util-formatnum) function with given `precision`.\n// Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the circle marker (as a GeoJSON `Point` Feature).\nCircle.include(PointToGeoJSON);\nCircleMarker.include(PointToGeoJSON);\n\n\n// @namespace Polyline\n// @method toGeoJSON(precision?: Number|false): Object\n// Coordinates values are rounded with [`formatNum`](#util-formatnum) function with given `precision`.\n// Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the polyline (as a GeoJSON `LineString` or `MultiLineString` Feature).\nPolyline.include({\n\ttoGeoJSON(precision) {\n\t\tconst multi = !LineUtil.isFlat(this._latlngs);\n\n\t\tconst coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision);\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}LineString`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n});\n\n// @namespace Polygon\n// @method toGeoJSON(precision?: Number|false): Object\n// Coordinates values are rounded with [`formatNum`](#util-formatnum) function with given `precision`.\n// Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature).\nPolygon.include({\n\ttoGeoJSON(precision) {\n\t\tconst holes = !LineUtil.isFlat(this._latlngs),\n\t\tmulti = holes && !LineUtil.isFlat(this._latlngs[0]);\n\n\t\tlet coords = GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision);\n\n\t\tif (!holes) {\n\t\t\tcoords = [coords];\n\t\t}\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: `${multi ? 'Multi' : ''}Polygon`,\n\t\t\tcoordinates: coords\n\t\t});\n\t}\n});\n\n\n// @namespace LayerGroup\nLayerGroup.include({\n\ttoMultiPoint(precision) {\n\t\tconst coords = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tcoords.push(layer.toGeoJSON(precision).geometry.coordinates);\n\t\t});\n\n\t\treturn GeoJSON.getFeature(this, {\n\t\t\ttype: 'MultiPoint',\n\t\t\tcoordinates: coords\n\t\t});\n\t},\n\n\t// @method toGeoJSON(precision?: Number|false): Object\n\t// Coordinates values are rounded with [`formatNum`](#util-formatnum) function with given `precision`.\n\t// Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation of the layer group (as a GeoJSON `FeatureCollection`, `GeometryCollection`, or `MultiPoint`).\n\ttoGeoJSON(precision) {\n\n\t\tconst type = this.feature?.geometry?.type;\n\n\t\tif (type === 'MultiPoint') {\n\t\t\treturn this.toMultiPoint(precision);\n\t\t}\n\n\t\tconst isGeometryCollection = type === 'GeometryCollection',\n\t\tjsons = [];\n\n\t\tthis.eachLayer((layer) => {\n\t\t\tif (layer.toGeoJSON) {\n\t\t\t\tconst json = layer.toGeoJSON(precision);\n\t\t\t\tif (isGeometryCollection) {\n\t\t\t\t\tjsons.push(json.geometry);\n\t\t\t\t} else {\n\t\t\t\t\tconst feature = GeoJSON.asFeature(json);\n\t\t\t\t\t// Squash nested feature collections\n\t\t\t\t\tif (feature.type === 'FeatureCollection') {\n\t\t\t\t\t\tjsons.push(...feature.features);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tjsons.push(feature);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tif (isGeometryCollection) {\n\t\t\treturn GeoJSON.getFeature(this, {\n\t\t\t\tgeometries: jsons,\n\t\t\t\ttype: 'GeometryCollection'\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'FeatureCollection',\n\t\t\tfeatures: jsons\n\t\t};\n\t}\n});\n"],"mappings":";;;;;;;;;;;AAqCA,IAAa,UAAb,MAAa,gBAAgB,aAAa;CAsDzC,YAAY,SAAS,SAAS;EAC7B,MAAM,KAAA,GAAW,OAAO;EAExB,IAAI,SACH,KAAK,QAAQ,OAAO;EAGrB,KAAK,cAAc,OAAO;CAC3B;CAIA,QAAQ,SAAS;EAChB,MAAM,WAAW,MAAM,QAAQ,OAAO,IAAI,UAAU,QAAQ;EAE5D,IAAI,UAAU;GACb,KAAK,MAAM,WAAW,UAErB,IAAI,QAAQ,cAAc,QAAQ,YAAY,QAAQ,YAAY,QAAQ,a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AU;EACX;CACD;AACD,CAAC"}
@@ -0,0 +1,140 @@
1
+ import { falseFn, setOptions, splitWords } from "../core/Util.js";
2
+ import { create, setPosition, setTransform, toBack, toFront } from "../dom/DomUtil.js";
3
+ import { Bounds } from "../geometry/Bounds.js";
4
+ import { LatLngBounds } from "../geo/LatLngBounds.js";
5
+ import { Layer } from "./Layer.js";
6
+ //#region src/layer/ImageOverlay.js
7
+ var ImageOverlay = class ImageOverlay extends Layer {
8
+ static {
9
+ this.setDefaultOptions({
10
+ opacity: 1,
11
+ alt: "",
12
+ interactive: false,
13
+ crossOrigin: false,
14
+ errorOverlayUrl: "",
15
+ zIndex: 1,
16
+ className: "",
17
+ decoding: "auto"
18
+ });
19
+ }
20
+ constructor(url, bounds, options) {
21
+ super();
22
+ this._url = url;
23
+ this._bounds = new LatLngBounds(bounds);
24
+ setOptions(this, options);
25
+ this.callInitHooks(ImageOverlay);
26
+ }
27
+ onAdd() {
28
+ if (!this._image) {
29
+ this._initImage();
30
+ if (this.options.opacity < 1) this._updateOpacity();
31
+ }
32
+ if (this.options.interactive) {
33
+ this._image.classList.add("maplair-interactive");
34
+ this.addInteractiveTarget(this._image);
35
+ }
36
+ this.getPane().appendChild(this._image);
37
+ this._reset();
38
+ }
39
+ onRemove() {
40
+ this._image.remove();
41
+ if (this.options.interactive) this.removeInteractiveTarget(this._image);
42
+ }
43
+ setOpacity(opacity) {
44
+ this.options.opacity = opacity;
45
+ if (this._image) this._updateOpacity();
46
+ return this;
47
+ }
48
+ setStyle(styleOpts) {
49
+ if (styleOpts.opacity) this.setOpacity(styleOpts.opacity);
50
+ return this;
51
+ }
52
+ bringToFront() {
53
+ if (this._map) toFront(this._image);
54
+ return this;
55
+ }
56
+ bringToBack() {
57
+ if (this._map) toBack(this._image);
58
+ return this;
59
+ }
60
+ setUrl(url) {
61
+ this._url = url;
62
+ if (this._image) this._image.src = url;
63
+ return this;
64
+ }
65
+ setBounds(bounds) {
66
+ this._bounds = new LatLngBounds(bounds);
67
+ if (this._map) this._reset();
68
+ return this;
69
+ }
70
+ getEvents() {
71
+ const events = {
72
+ zoom: this._reset,
73
+ viewreset: this._reset
74
+ };
75
+ if (this._zoomAnimated) events.zoomanim = this._animateZoom;
76
+ return events;
77
+ }
78
+ setZIndex(value) {
79
+ this.options.zIndex = value;
80
+ this._updateZIndex();
81
+ return this;
82
+ }
83
+ getBounds() {
84
+ return this._bounds;
85
+ }
86
+ getElement() {
87
+ return this._image;
88
+ }
89
+ _initImage() {
90
+ const wasElementSupplied = this._url.tagName === "IMG";
91
+ const img = this._image = wasElementSupplied ? this._url : create("img");
92
+ img.classList.add("maplair-image-layer");
93
+ if (this._zoomAnimated) img.classList.add("maplair-zoom-animated");
94
+ if (this.options.className) img.classList.add(...splitWords(this.options.className));
95
+ img.onselectstart = falseFn;
96
+ img.onpointermove = falseFn;
97
+ img.onload = this.fire.bind(this, "load");
98
+ img.onerror = this._overlayOnError.bind(this);
99
+ if (this.options.crossOrigin || this.options.crossOrigin === "") img.crossOrigin = this.options.crossOrigin === true ? "" : this.options.crossOrigin;
100
+ img.decoding = this.options.decoding;
101
+ if (this.options.zIndex) this._updateZIndex();
102
+ if (wasElementSupplied) {
103
+ this._url = img.src;
104
+ return;
105
+ }
106
+ img.src = this._url;
107
+ img.alt = this.options.alt;
108
+ }
109
+ _animateZoom(e) {
110
+ const scale = this._map.getZoomScale(e.zoom), offset = this._map._latLngBoundsToNewLayerBounds(this._bounds, e.zoom, e.center).min;
111
+ setTransform(this._image, offset, scale);
112
+ }
113
+ _reset() {
114
+ const image = this._image, bounds = new Bounds(this._map.latLngToLayerPoint(this._bounds.getNorthWest()), this._map.latLngToLayerPoint(this._bounds.getSouthEast())), size = bounds.getSize();
115
+ setPosition(image, bounds.min);
116
+ image.style.width = `${size.x}px`;
117
+ image.style.height = `${size.y}px`;
118
+ }
119
+ _updateOpacity() {
120
+ this._image.style.opacity = this.options.opacity;
121
+ }
122
+ _updateZIndex() {
123
+ if (this._image && this.options.zIndex !== void 0 && this.options.zIndex !== null) this._image.style.zIndex = this.options.zIndex;
124
+ }
125
+ _overlayOnError() {
126
+ this.fire("error");
127
+ const errorUrl = this.options.errorOverlayUrl;
128
+ if (errorUrl && this._url !== errorUrl) {
129
+ this._url = errorUrl;
130
+ this._image.src = errorUrl;
131
+ }
132
+ }
133
+ getCenter() {
134
+ return this._bounds.getCenter();
135
+ }
136
+ };
137
+ //#endregion
138
+ export { ImageOverlay };
139
+
140
+ //# sourceMappingURL=ImageOverlay.js.map