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,279 @@
1
+ import {Layer} from './Layer.js';
2
+ import * as Util from '../core/Util.js';
3
+ import {LatLngBounds} from '../geo/LatLngBounds.js';
4
+ import {Bounds} from '../geometry/Bounds.js';
5
+ import * as DomUtil from '../dom/DomUtil.js';
6
+
7
+ /*
8
+ * @class ImageOverlay
9
+ * @inherits Interactive layer
10
+ *
11
+ * Used to load and display a single image over specific bounds of the map. Extends `Layer`.
12
+ *
13
+ * @example
14
+ *
15
+ * ```js
16
+ * const imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',
17
+ * imageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];
18
+ * new ImageOverlay(imageUrl, imageBounds).addTo(map);
19
+ * ```
20
+ */
21
+
22
+ // @constructor ImageOverlay(imageUrl: String, bounds: LatLngBounds, options?: ImageOverlay options)
23
+ // Instantiates an image overlay object given the URL of the image and the
24
+ // geographical bounds it is tied to.
25
+ export class ImageOverlay extends Layer {
26
+
27
+ static {
28
+ // @section
29
+ // @aka ImageOverlay options
30
+ this.setDefaultOptions({
31
+ // @option opacity: Number = 1.0
32
+ // The opacity of the image overlay.
33
+ opacity: 1,
34
+
35
+ // @option alt: String = ''
36
+ // Text for the `alt` attribute of the image (useful for accessibility).
37
+ alt: '',
38
+
39
+ // @option interactive: Boolean = false
40
+ // If `true`, the image overlay will emit [pointer events](#interactive-layer) when clicked or hovered.
41
+ interactive: false,
42
+
43
+ // @option crossOrigin: Boolean|String = false
44
+ // Whether the crossOrigin attribute will be added to the image.
45
+ // If a String is provided, the image will have its crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data.
46
+ // Refer to [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values.
47
+ crossOrigin: false,
48
+
49
+ // @option errorOverlayUrl: String = ''
50
+ // URL to the overlay image to show in place of the overlay that failed to load.
51
+ errorOverlayUrl: '',
52
+
53
+ // @option zIndex: Number = 1
54
+ // The explicit [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index) of the overlay layer.
55
+ zIndex: 1,
56
+
57
+ // @option className: String = ''
58
+ // A custom class name to assign to the image. Empty by default.
59
+ className: '',
60
+
61
+ // @option decoding: String = 'auto'
62
+ // Tells the browser whether to decode the image in a synchronous fashion,
63
+ // as per the [`decoding` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding).
64
+ // If the image overlay is flickering when being added/removed, set
65
+ // this option to `'sync'`.
66
+ decoding: 'auto'
67
+ });
68
+ }
69
+
70
+ constructor(url, bounds, options) { // (String, LatLngBounds, Object)
71
+ super();
72
+ this._url = url;
73
+ this._bounds = new LatLngBounds(bounds);
74
+
75
+ Util.setOptions(this, options);
76
+
77
+ this.callInitHooks(ImageOverlay);
78
+ }
79
+
80
+ onAdd() {
81
+ if (!this._image) {
82
+ this._initImage();
83
+
84
+ if (this.options.opacity < 1) {
85
+ this._updateOpacity();
86
+ }
87
+ }
88
+
89
+ if (this.options.interactive) {
90
+ this._image.classList.add('maplair-interactive');
91
+ this.addInteractiveTarget(this._image);
92
+ }
93
+
94
+ this.getPane().appendChild(this._image);
95
+ this._reset();
96
+ }
97
+
98
+ onRemove() {
99
+ this._image.remove();
100
+ if (this.options.interactive) {
101
+ this.removeInteractiveTarget(this._image);
102
+ }
103
+ }
104
+
105
+ // @method setOpacity(opacity: Number): this
106
+ // Sets the opacity of the overlay.
107
+ setOpacity(opacity) {
108
+ this.options.opacity = opacity;
109
+
110
+ if (this._image) {
111
+ this._updateOpacity();
112
+ }
113
+ return this;
114
+ }
115
+
116
+ setStyle(styleOpts) {
117
+ if (styleOpts.opacity) {
118
+ this.setOpacity(styleOpts.opacity);
119
+ }
120
+ return this;
121
+ }
122
+
123
+ // @method bringToFront(): this
124
+ // Brings the layer to the top of all overlays.
125
+ bringToFront() {
126
+ if (this._map) {
127
+ DomUtil.toFront(this._image);
128
+ }
129
+ return this;
130
+ }
131
+
132
+ // @method bringToBack(): this
133
+ // Brings the layer to the bottom of all overlays.
134
+ bringToBack() {
135
+ if (this._map) {
136
+ DomUtil.toBack(this._image);
137
+ }
138
+ return this;
139
+ }
140
+
141
+ // @method setUrl(url: String): this
142
+ // Changes the URL of the image.
143
+ setUrl(url) {
144
+ this._url = url;
145
+
146
+ if (this._image) {
147
+ this._image.src = url;
148
+ }
149
+ return this;
150
+ }
151
+
152
+ // @method setBounds(bounds: LatLngBounds): this
153
+ // Update the bounds that this ImageOverlay covers
154
+ setBounds(bounds) {
155
+ this._bounds = new LatLngBounds(bounds);
156
+
157
+ if (this._map) {
158
+ this._reset();
159
+ }
160
+ return this;
161
+ }
162
+
163
+ getEvents() {
164
+ const events = {
165
+ zoom: this._reset,
166
+ viewreset: this._reset
167
+ };
168
+
169
+ if (this._zoomAnimated) {
170
+ events.zoomanim = this._animateZoom;
171
+ }
172
+
173
+ return events;
174
+ }
175
+
176
+ // @method setZIndex(value: Number): this
177
+ // Changes the [zIndex](#imageoverlay-zindex) of the image overlay.
178
+ setZIndex(value) {
179
+ this.options.zIndex = value;
180
+ this._updateZIndex();
181
+ return this;
182
+ }
183
+
184
+ // @method getBounds(): LatLngBounds
185
+ // Get the bounds that this ImageOverlay covers
186
+ getBounds() {
187
+ return this._bounds;
188
+ }
189
+
190
+ // @method getElement(): HTMLElement
191
+ // Returns the instance of [`HTMLImageElement`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement)
192
+ // used by this overlay.
193
+ getElement() {
194
+ return this._image;
195
+ }
196
+
197
+ _initImage() {
198
+ const wasElementSupplied = this._url.tagName === 'IMG';
199
+ const img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');
200
+
201
+ img.classList.add('maplair-image-layer');
202
+ if (this._zoomAnimated) { img.classList.add('maplair-zoom-animated'); }
203
+ if (this.options.className) { img.classList.add(...Util.splitWords(this.options.className)); }
204
+
205
+ img.onselectstart = Util.falseFn;
206
+ img.onpointermove = Util.falseFn;
207
+
208
+ // @event load: Event
209
+ // Fired when the ImageOverlay layer has loaded its image
210
+ img.onload = this.fire.bind(this, 'load');
211
+ img.onerror = this._overlayOnError.bind(this);
212
+
213
+ if (this.options.crossOrigin || this.options.crossOrigin === '') {
214
+ img.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;
215
+ }
216
+
217
+ img.decoding = this.options.decoding;
218
+
219
+ if (this.options.zIndex) {
220
+ this._updateZIndex();
221
+ }
222
+
223
+ if (wasElementSupplied) {
224
+ this._url = img.src;
225
+ return;
226
+ }
227
+
228
+ img.src = this._url;
229
+ img.alt = this.options.alt;
230
+ }
231
+
232
+ _animateZoom(e) {
233
+ const scale = this._map.getZoomScale(e.zoom),
234
+ offset = this._map._latLngBoundsToNewLayerBounds(this._bounds, e.zoom, e.center).min;
235
+
236
+ DomUtil.setTransform(this._image, offset, scale);
237
+ }
238
+
239
+ _reset() {
240
+ const image = this._image,
241
+ bounds = new Bounds(
242
+ this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
243
+ this._map.latLngToLayerPoint(this._bounds.getSouthEast())),
244
+ size = bounds.getSize();
245
+
246
+ DomUtil.setPosition(image, bounds.min);
247
+
248
+ image.style.width = `${size.x}px`;
249
+ image.style.height = `${size.y}px`;
250
+ }
251
+
252
+ _updateOpacity() {
253
+ this._image.style.opacity = this.options.opacity;
254
+ }
255
+
256
+ _updateZIndex() {
257
+ if (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {
258
+ this._image.style.zIndex = this.options.zIndex;
259
+ }
260
+ }
261
+
262
+ _overlayOnError() {
263
+ // @event error: Event
264
+ // Fired when the ImageOverlay layer fails to load its image
265
+ this.fire('error');
266
+
267
+ const errorUrl = this.options.errorOverlayUrl;
268
+ if (errorUrl && this._url !== errorUrl) {
269
+ this._url = errorUrl;
270
+ this._image.src = errorUrl;
271
+ }
272
+ }
273
+
274
+ // @method getCenter(): LatLng
275
+ // Returns the center of the ImageOverlay.
276
+ getCenter() {
277
+ return this._bounds.getCenter();
278
+ }
279
+ }
@@ -0,0 +1,273 @@
1
+ import {Evented} from '../core/Events.js';
2
+ import * as Util from '../core/Util.js';
3
+
4
+ /*
5
+ * @class Layer
6
+ * @inherits Evented
7
+ * @aka ILayer
8
+ *
9
+ * A set of methods from the Layer base class that all Maplair layers use.
10
+ * Inherits all methods, options and events from `Evented`.
11
+ *
12
+ * @example
13
+ *
14
+ * ```js
15
+ * const layer = new Marker(latlng).addTo(map);
16
+ * layer.addTo(map);
17
+ * layer.remove();
18
+ * ```
19
+ *
20
+ * @event add: Event
21
+ * Fired after the layer is added to a map
22
+ *
23
+ * @event remove: Event
24
+ * Fired after the layer is removed from a map
25
+ */
26
+
27
+ export class Layer extends Evented {
28
+
29
+ static {
30
+ // Classes extending `Layer` will inherit the following options:
31
+ this.setDefaultOptions({
32
+ // @option pane: String = 'overlayPane'
33
+ // By default the layer will be added to the map's [overlay pane](#map-overlaypane). Overriding this option will cause the layer to be placed on another pane by default.
34
+ // Not effective if the `renderer` option is set (the `renderer` option will override the `pane` option).
35
+ pane: 'overlayPane',
36
+
37
+ // @option attribution: String = null
38
+ // String to be shown in the attribution control, e.g. "&copy; OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.
39
+ attribution: null,
40
+
41
+ bubblingPointerEvents: true
42
+ });
43
+ }
44
+
45
+ /* @section
46
+ * Classes extending `Layer` will inherit the following methods:
47
+ *
48
+ * @method addTo(map: MaplairMap|LayerGroup): this
49
+ * Adds the layer to the given map or layer group.
50
+ */
51
+ addTo(map) {
52
+ map.addLayer(this);
53
+ return this;
54
+ }
55
+
56
+ // @method remove: this
57
+ // Removes the layer from the map it is currently active on.
58
+ remove() {
59
+ return this.removeFrom(this._map || this._mapToAdd);
60
+ }
61
+
62
+ // @method removeFrom(map: MaplairMap): this
63
+ // Removes the layer from the given map
64
+ //
65
+ // @alternative
66
+ // @method removeFrom(group: LayerGroup): this
67
+ // Removes the layer from the given `LayerGroup`
68
+ removeFrom(obj) {
69
+ obj?.removeLayer(this);
70
+ return this;
71
+ }
72
+
73
+ // @method getPane(name? : String): HTMLElement
74
+ // Returns the `HTMLElement` representing the named pane on the map. If `name` is omitted, returns the pane for this layer.
75
+ getPane(name) {
76
+ return this._map.getPane(name ? (this.options[name] || name) : this.options.pane);
77
+ }
78
+
79
+ addInteractiveTarget(targetEl) {
80
+ this._map._targets[Util.stamp(targetEl)] = this;
81
+ return this;
82
+ }
83
+
84
+ removeInteractiveTarget(targetEl) {
85
+ delete this._map._targets[Util.stamp(targetEl)];
86
+ return this;
87
+ }
88
+
89
+ // @method getAttribution: String
90
+ // Used by the `attribution control`, returns the [attribution option](#gridlayer-attribution).
91
+ getAttribution() {
92
+ return this.options.attribution;
93
+ }
94
+
95
+ _layerAdd(e) {
96
+ const map = e.target;
97
+
98
+ // check in case layer gets added and then removed before the map is ready
99
+ if (!map.hasLayer(this)) { return; }
100
+
101
+ this._map = map;
102
+ this._zoomAnimated = map._zoomAnimated;
103
+
104
+ if (this.getEvents) {
105
+ const events = this.getEvents();
106
+ map.on(events, this);
107
+ this.once('remove', () => map.off(events, this));
108
+ }
109
+
110
+ this.onAdd(map);
111
+
112
+ this.fire('add');
113
+ map.fire('layeradd', {layer: this});
114
+ }
115
+
116
+ // Registers this default feature on the map class, called by `MaplairMap` itself.
117
+ static register(MaplairMap) {
118
+ /* @namespace MaplairMap
119
+ * @section Layer events
120
+ *
121
+ * @event layeradd: LayerEvent
122
+ * Fired when a new layer is added to the map.
123
+ *
124
+ * @event layerremove: LayerEvent
125
+ * Fired when some layer is removed from the map
126
+ *
127
+ * @section Methods for Layers and Controls
128
+ */
129
+ MaplairMap.include({
130
+ // @method addLayer(layer: Layer): this
131
+ // Adds the given layer to the map
132
+ addLayer(layer) {
133
+ if (!layer._layerAdd) {
134
+ throw new Error('The provided object is not a Layer.');
135
+ }
136
+
137
+ const id = Util.stamp(layer);
138
+ if (this._layers[id]) { return this; }
139
+ this._layers[id] = layer;
140
+
141
+ layer._mapToAdd = this;
142
+
143
+ if (layer.beforeAdd) {
144
+ layer.beforeAdd(this);
145
+ }
146
+
147
+ this.whenReady(layer._layerAdd, layer);
148
+
149
+ return this;
150
+ },
151
+
152
+ // @method removeLayer(layer: Layer): this
153
+ // Removes the given layer from the map.
154
+ removeLayer(layer) {
155
+ const id = Util.stamp(layer);
156
+
157
+ if (!this._layers[id]) { return this; }
158
+
159
+ if (this._loaded) {
160
+ layer.onRemove(this);
161
+ }
162
+
163
+ delete this._layers[id];
164
+
165
+ if (this._loaded) {
166
+ this.fire('layerremove', {layer});
167
+ layer.fire('remove');
168
+ }
169
+
170
+ layer._map = layer._mapToAdd = null;
171
+
172
+ return this;
173
+ },
174
+
175
+ // @method hasLayer(layer: Layer): Boolean
176
+ // Returns `true` if the given layer is currently added to the map
177
+ hasLayer(layer) {
178
+ return Util.stamp(layer) in this._layers;
179
+ },
180
+
181
+ /* @method eachLayer(fn: Function, context?: Object): this
182
+ * Iterates over the layers of the map, optionally specifying context of the iterator function.
183
+ * ```
184
+ * map.eachLayer(function(layer){
185
+ * layer.bindPopup('Hello');
186
+ * });
187
+ * ```
188
+ */
189
+ eachLayer(method, context) {
190
+ for (const layer of Object.values(this._layers)) {
191
+ method.call(context, layer);
192
+ }
193
+ return this;
194
+ },
195
+
196
+ _addLayers(layers) {
197
+ layers = layers ? (Array.isArray(layers) ? layers : [layers]) : [];
198
+
199
+ for (const layer of layers) {
200
+ this.addLayer(layer);
201
+ }
202
+ },
203
+
204
+ _addZoomLimit(layer) {
205
+ if (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) {
206
+ this._zoomBoundLayers[Util.stamp(layer)] = layer;
207
+ this._updateZoomLevels();
208
+ }
209
+ },
210
+
211
+ _removeZoomLimit(layer) {
212
+ const id = Util.stamp(layer);
213
+
214
+ if (this._zoomBoundLayers[id]) {
215
+ delete this._zoomBoundLayers[id];
216
+ this._updateZoomLevels();
217
+ }
218
+ },
219
+
220
+ _updateZoomLevels() {
221
+ let minZoom = Infinity,
222
+ maxZoom = -Infinity;
223
+ const oldZoomSpan = this._getZoomSpan();
224
+
225
+ for (const l of Object.values(this._zoomBoundLayers)) {
226
+ const options = l.options;
227
+ minZoom = Math.min(minZoom, options.minZoom ?? Infinity);
228
+ maxZoom = Math.max(maxZoom, options.maxZoom ?? -Infinity);
229
+ }
230
+
231
+ this._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;
232
+ this._layersMinZoom = minZoom === Infinity ? undefined : minZoom;
233
+
234
+ // @section Map state change events
235
+ // @event zoomlevelschange: Event
236
+ // Fired when the number of zoomlevels on the map is changed due
237
+ // to adding or removing a layer.
238
+ if (oldZoomSpan !== this._getZoomSpan()) {
239
+ this.fire('zoomlevelschange');
240
+ }
241
+
242
+ if (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) {
243
+ this.setZoom(this._layersMaxZoom);
244
+ }
245
+ if (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {
246
+ this.setZoom(this._layersMinZoom);
247
+ }
248
+ }
249
+ });
250
+ }
251
+ }
252
+
253
+ /* @namespace Layer
254
+ * @section Extension methods
255
+ * @uninheritable
256
+ *
257
+ * Every layer should extend from `Layer` and (re-)implement the following methods.
258
+ *
259
+ * @method onAdd(map: MaplairMap): this
260
+ * Should contain code that creates DOM elements for the layer, adds them to `map panes` where they should belong and puts listeners on relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).
261
+ *
262
+ * @method onRemove(map: MaplairMap): this
263
+ * Should contain all clean up code that removes the layer's elements from the DOM and removes listeners previously added in [`onAdd`](#layer-onadd). Called on [`map.removeLayer(layer)`](#map-removelayer).
264
+ *
265
+ * @method getEvents(): Object
266
+ * This optional method should return an object like `{ viewreset: this._reset }` for [`on`](#evented-on). The event handlers in this object will be automatically added and removed from the map with your layer.
267
+ *
268
+ * @method getAttribution(): String
269
+ * This optional method should return a string containing HTML to be shown on the `Attribution control` whenever the layer is visible.
270
+ *
271
+ * @method beforeAdd(map: MaplairMap): this
272
+ * Optional method. Called on [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map, before events are initialized, without waiting until the map is in a usable state. Use for early initialization only.
273
+ */
@@ -0,0 +1,129 @@
1
+
2
+ import {Layer} from './Layer.js';
3
+ import * as Util from '../core/Util.js';
4
+
5
+ /*
6
+ * @class LayerGroup
7
+ * @inherits Interactive layer
8
+ *
9
+ * Used to group several layers and handle them as one. If you add it to the map,
10
+ * any layers added or removed from the group will be added/removed on the map as
11
+ * well. Extends `Layer`.
12
+ *
13
+ * @example
14
+ *
15
+ * ```js
16
+ * new LayerGroup([marker1, marker2])
17
+ * .addLayer(polyline)
18
+ * .addTo(map);
19
+ * ```
20
+ */
21
+
22
+ // @constructor LayerGroup(layers?: Layer[], options?: Object)
23
+ // Create a layer group, optionally given an initial set of layers and an `options` object.
24
+ export class LayerGroup extends Layer {
25
+
26
+ constructor(layers, options) { // for compatibility of code using `LayerGroup.extend`
27
+ super();
28
+ Util.setOptions(this, options);
29
+
30
+ this._layers = {};
31
+
32
+ for (const layer of layers ?? []) {
33
+ this.addLayer(layer);
34
+ }
35
+
36
+ this.callInitHooks(LayerGroup);
37
+ }
38
+
39
+ // @method addLayer(layer: Layer): this
40
+ // Adds the given layer to the group.
41
+ addLayer(layer) {
42
+ const id = this.getLayerId(layer);
43
+
44
+ this._layers[id] = layer;
45
+
46
+ this._map?.addLayer(layer);
47
+
48
+ return this;
49
+ }
50
+
51
+ // @method removeLayer(layer: Layer): this
52
+ // Removes the given layer from the group.
53
+ // @alternative
54
+ // @method removeLayer(id: Number): this
55
+ // Removes the layer with the given internal ID from the group.
56
+ removeLayer(layer) {
57
+ const id = layer in this._layers ? layer : this.getLayerId(layer);
58
+
59
+ if (this._map && this._layers[id]) {
60
+ this._map.removeLayer(this._layers[id]);
61
+ }
62
+
63
+ delete this._layers[id];
64
+
65
+ return this;
66
+ }
67
+
68
+ // @method hasLayer(layer: Layer): Boolean
69
+ // Returns `true` if the given layer is currently added to the group.
70
+ // @alternative
71
+ // @method hasLayer(id: Number): Boolean
72
+ // Returns `true` if the given internal ID is currently added to the group.
73
+ hasLayer(layer) {
74
+ const layerId = typeof layer === 'number' ? layer : this.getLayerId(layer);
75
+ return layerId in this._layers;
76
+ }
77
+
78
+ // @method clearLayers(): this
79
+ // Removes all the layers from the group.
80
+ clearLayers() {
81
+ return this.eachLayer(this.removeLayer, this);
82
+ }
83
+
84
+ onAdd(map) {
85
+ this.eachLayer(map.addLayer, map);
86
+ }
87
+
88
+ onRemove(map) {
89
+ this.eachLayer(map.removeLayer, map);
90
+ }
91
+
92
+ // @method eachLayer(fn: Function, context?: Object): this
93
+ // Iterates over the layers of the group, optionally specifying context of the iterator function.
94
+ // ```js
95
+ // group.eachLayer(layer => layer.bindPopup('Hello'));
96
+ // ```
97
+ eachLayer(method, context) {
98
+ for (const layer of Object.values(this._layers)) {
99
+ method.call(context, layer);
100
+ }
101
+ return this;
102
+ }
103
+
104
+ // @method getLayer(id: Number): Layer
105
+ // Returns the layer with the given internal ID.
106
+ getLayer(id) {
107
+ return this._layers[id];
108
+ }
109
+
110
+ // @method getLayers(): Layer[]
111
+ // Returns an array of all the layers added to the group.
112
+ getLayers() {
113
+ const layers = [];
114
+ this.eachLayer(layers.push, layers);
115
+ return layers;
116
+ }
117
+
118
+ // @method setZIndex(zIndex: Number): this
119
+ // Calls `setZIndex` on every layer contained in this group, passing the z-index.
120
+ setZIndex(zIndex) {
121
+ return this.eachLayer(l => l.setZIndex?.(zIndex));
122
+ }
123
+
124
+ // @method getLayerId(layer: Layer): Number
125
+ // Returns the internal ID for a layer
126
+ getLayerId(layer) {
127
+ return Util.stamp(layer);
128
+ }
129
+ }