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,115 @@
1
+ import {Evented} from '../core/Events.js';
2
+ import * as DomUtil from '../dom/DomUtil.js';
3
+
4
+
5
+ /*
6
+ * @class PosAnimation
7
+ * @inherits Evented
8
+ * Used internally for panning animations and utilizing CSS Transitions for modern browsers.
9
+ *
10
+ * @example
11
+ * ```js
12
+ * const myPositionMarker = new Marker([48.864716, 2.294694]).addTo(map);
13
+ *
14
+ * myPositionMarker.on("click", function() {
15
+ * const pos = map.latLngToLayerPoint(myPositionMarker.getLatLng());
16
+ * pos.y -= 25;
17
+ * const fx = new PosAnimation();
18
+ *
19
+ * fx.once('end',function() {
20
+ * pos.y += 25;
21
+ * fx.run(myPositionMarker._icon, pos, 0.8);
22
+ * });
23
+ *
24
+ * fx.run(myPositionMarker._icon, pos, 0.3);
25
+ * });
26
+ *
27
+ * ```
28
+ *
29
+ * @constructor PosAnimation()
30
+ * Creates a `PosAnimation` object.
31
+ *
32
+ */
33
+
34
+ export class PosAnimation extends Evented {
35
+ constructor(...args) {
36
+ super(...args);
37
+ this.callInitHooks(PosAnimation);
38
+ }
39
+
40
+ // @method run(el: HTMLElement, newPos: Point, duration?: Number, easeLinearity?: Number)
41
+ // Run an animation of a given element to a new position, optionally setting
42
+ // duration in seconds (`0.25` by default) and easing linearity factor (3rd
43
+ // argument of the [cubic bezier curve](https://cubic-bezier.com/#0,0,.5,1),
44
+ // `0.5` by default).
45
+ run(el, newPos, duration, easeLinearity) {
46
+ this.stop();
47
+
48
+ this._el = el;
49
+ this._inProgress = true;
50
+ this._duration = duration ?? 0.25;
51
+ this._easeOutPower = 1 / Math.max(easeLinearity ?? 0.5, 0.2);
52
+
53
+ this._startPos = DomUtil.getPosition(el);
54
+ this._offset = newPos.subtract(this._startPos);
55
+ this._startTime = Date.now();
56
+
57
+ // @event start: Event
58
+ // Fired when the animation starts
59
+ this.fire('start');
60
+
61
+ this._animate();
62
+ }
63
+
64
+ // @method stop()
65
+ // Stops the animation (if currently running).
66
+ stop() {
67
+ if (!this._inProgress) { return; }
68
+
69
+ this._step(true);
70
+ this._complete();
71
+ }
72
+
73
+ _animate() {
74
+ // animation loop
75
+ this._animId = requestAnimationFrame(this._animate.bind(this));
76
+ this._step();
77
+ }
78
+
79
+ _step(round) {
80
+ const elapsed = (Date.now()) - this._startTime,
81
+ duration = this._duration * 1000;
82
+
83
+ if (elapsed < duration) {
84
+ this._runFrame(this._easeOut(elapsed / duration), round);
85
+ } else {
86
+ this._runFrame(1);
87
+ this._complete();
88
+ }
89
+ }
90
+
91
+ _runFrame(progress, round) {
92
+ const pos = this._startPos.add(this._offset.multiplyBy(progress));
93
+ if (round) {
94
+ pos._round();
95
+ }
96
+ DomUtil.setPosition(this._el, pos);
97
+
98
+ // @event step: Event
99
+ // Fired continuously during the animation.
100
+ this.fire('step');
101
+ }
102
+
103
+ _complete() {
104
+ cancelAnimationFrame(this._animId);
105
+
106
+ this._inProgress = false;
107
+ // @event end: Event
108
+ // Fired when the animation ends.
109
+ this.fire('end');
110
+ }
111
+
112
+ _easeOut(t) {
113
+ return 1 - (1 - t) ** this._easeOutPower;
114
+ }
115
+ }
@@ -0,0 +1,9 @@
1
+ export {PosAnimation} from './PosAnimation.js';
2
+
3
+ import * as DomEvent from './DomEvent.js';
4
+ export {DomEvent};
5
+
6
+ import * as DomUtil from './DomUtil.js';
7
+ export {DomUtil};
8
+
9
+ export {Draggable} from './Draggable.js';
@@ -0,0 +1,163 @@
1
+ import * as Util from '../core/Util.js';
2
+ import {EarthCRS} from './crs/EarthCRS.js';
3
+ import {LatLngBounds} from './LatLngBounds.js';
4
+
5
+ /* @class LatLng
6
+ *
7
+ * Represents a geographical point with a certain latitude and longitude.
8
+ *
9
+ * @example
10
+ *
11
+ * ```
12
+ * const latlng = new LatLng(50.5, 30.5);
13
+ * ```
14
+ *
15
+ * All Maplair methods that accept LatLng objects also accept them in a simple Array form and simple object form (unless noted otherwise), so these lines are equivalent:
16
+ *
17
+ * ```
18
+ * map.panTo([50, 30]);
19
+ * map.panTo({lat: 50, lng: 30});
20
+ * map.panTo({lat: 50, lon: 30});
21
+ * map.panTo(new LatLng(50, 30));
22
+ * ```
23
+ *
24
+ * Note that `LatLng` does not inherit from Maplair's `Class` object,
25
+ * which means new classes can't inherit from it, and new methods
26
+ * can't be added to it with the `include` function.
27
+ */
28
+
29
+ // @constructor LatLng(latitude: Number, longitude: Number, altitude?: Number): LatLng
30
+ // Creates an object representing a geographical point with the given latitude and longitude (and optionally altitude).
31
+
32
+ // @alternative
33
+ // @constructor LatLng(coords: LatLng)
34
+ // Expects a LatLng object instead.
35
+
36
+ // @alternative
37
+ // @constructor LatLng(coords: Array): LatLng
38
+ // Expects an array of the form `[Number, Number]` or `[Number, Number, Number]` instead.
39
+
40
+ // @alternative
41
+ // @constructor LatLng(coords: Object): LatLng
42
+ // Expects an plain object of the form `{lat: Number, lng: Number}` or `{lat: Number, lng: Number, alt: Number}` instead.
43
+ // You can also use `lon` in place of `lng` in the object form.
44
+ export class LatLng {
45
+ constructor(lat, lng, alt) {
46
+ const valid = LatLng.validate(lat, lng, alt);
47
+ if (!valid) {
48
+ throw new Error(`Invalid LatLng object: (${lat}, ${lng})`);
49
+ }
50
+
51
+ let _lat, _lng, _alt;
52
+ if (lat instanceof LatLng) {
53
+ _lat = lat.lat;
54
+ _lng = lat.lng;
55
+ _alt = lat.alt;
56
+ } else if (Array.isArray(lat) && typeof lat[0] !== 'object') {
57
+ if (lat.length === 3) {
58
+ _lat = lat[0];
59
+ _lng = lat[1];
60
+ _alt = lat[2];
61
+ } else if (lat.length === 2) {
62
+ _lat = lat[0];
63
+ _lng = lat[1];
64
+ }
65
+ } else if (typeof lat === 'object' && 'lat' in lat) {
66
+ _lat = lat.lat;
67
+ _lng = 'lng' in lat ? lat.lng : lat.lon;
68
+ _alt = lat.alt;
69
+ } else {
70
+ _lat = lat;
71
+ _lng = lng;
72
+ _alt = alt;
73
+ }
74
+
75
+ // @property lat: Number
76
+ // Latitude in degrees
77
+ this.lat = +_lat;
78
+
79
+ // @property lng: Number
80
+ // Longitude in degrees
81
+ this.lng = +_lng;
82
+
83
+ // @property alt: Number
84
+ // Altitude in meters (optional)
85
+ if (_alt !== undefined) {
86
+ this.alt = +_alt;
87
+ }
88
+ }
89
+
90
+ // @section
91
+ // There are several static functions which can be called without instantiating LatLng:
92
+
93
+ // @function validate(latitude: Number, longitude: Number, altitude?: Number): Boolean
94
+ // Returns `true` if the LatLng object can be properly initialized.
95
+
96
+ // @alternative
97
+ // @function validate(coords: Array): Boolean
98
+ // Expects an array of the form `[Number, Number]` or `[Number, Number, Number]`.
99
+ // Returns `true` if the LatLng object can be properly initialized.
100
+
101
+ // @alternative
102
+ // @function validate(coords: Object): Boolean
103
+ // Returns `true` if the LatLng object can be properly initialized.
104
+
105
+ // eslint-disable-next-line no-unused-vars
106
+ static validate(lat, lng, alt) {
107
+ if (lat instanceof LatLng || (typeof lat === 'object' && lat !== null && 'lat' in lat)) {
108
+ return true;
109
+ } else if (lat && Array.isArray(lat) && typeof lat[0] !== 'object') {
110
+ if (lat.length === 3 || lat.length === 2) {
111
+ return true;
112
+ }
113
+ return false;
114
+ } else if ((lat || lat === 0) && (lng || lng === 0)) {
115
+ return true;
116
+ }
117
+ return false;
118
+ }
119
+
120
+ // @method equals(otherLatLng: LatLng, maxMargin?: Number): Boolean
121
+ // Returns `true` if the given `LatLng` point is at the same position (within a small margin of error). The margin of error can be overridden by setting `maxMargin` to a small number.
122
+ equals(obj, maxMargin) {
123
+ if (!obj) { return false; }
124
+
125
+ obj = new LatLng(obj);
126
+
127
+ const margin = Math.max(
128
+ Math.abs(this.lat - obj.lat),
129
+ Math.abs(this.lng - obj.lng));
130
+
131
+ return margin <= (maxMargin ?? 1.0E-9);
132
+ }
133
+
134
+ // @method toString(precision?: Number): String
135
+ // Returns a string representation of the point (for debugging purposes).
136
+ toString(precision) {
137
+ return `LatLng(${Util.formatNum(this.lat, precision)}, ${Util.formatNum(this.lng, precision)})`;
138
+ }
139
+
140
+ // @method distanceTo(otherLatLng: LatLng): Number
141
+ // Returns the distance (in meters) to the given `LatLng` calculated using the [Haversine formula](https://en.wikipedia.org/wiki/Haversine_formula).
142
+ distanceTo(other) {
143
+ return EarthCRS.distance(this, new LatLng(other));
144
+ }
145
+
146
+ // @method wrap(): LatLng
147
+ // Returns a new `LatLng` object with the longitude wrapped so it's always between -180 and +180 degrees.
148
+ wrap() {
149
+ return EarthCRS.wrapLatLng(this);
150
+ }
151
+
152
+ // @method toBounds(sizeInMeters: Number): LatLngBounds
153
+ // Returns a new `LatLngBounds` object in which each boundary is `sizeInMeters/2` meters apart from the `LatLng`.
154
+ toBounds(sizeInMeters) {
155
+ const latAccuracy = 180 * sizeInMeters / 40075017,
156
+ lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);
157
+
158
+ return new LatLngBounds(
159
+ [this.lat - latAccuracy, this.lng - lngAccuracy],
160
+ [this.lat + latAccuracy, this.lng + lngAccuracy]);
161
+ }
162
+
163
+ };
@@ -0,0 +1,260 @@
1
+ import {LatLng} from './LatLng.js';
2
+
3
+ /*
4
+ * @class LatLngBounds
5
+ *
6
+ * Represents a rectangular geographical area on a map.
7
+ *
8
+ * @example
9
+ *
10
+ * ```js
11
+ * const corner1 = new LatLng(40.712, -74.227),
12
+ * corner2 = new LatLng(40.774, -74.125),
13
+ * bounds = new LatLngBounds(corner1, corner2);
14
+ * ```
15
+ *
16
+ * All Maplair methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:
17
+ *
18
+ * ```js
19
+ * map.fitBounds([
20
+ * [40.712, -74.227],
21
+ * [40.774, -74.125]
22
+ * ]);
23
+ * ```
24
+ *
25
+ * Caution: if the area crosses the antimeridian (often confused with the International Date Line), you must specify corners _outside_ the [-180, 180] degrees longitude range.
26
+ *
27
+ * Note that `LatLngBounds` does not inherit from Maplair's `Class` object,
28
+ * which means new classes can't inherit from it, and new methods
29
+ * can't be added to it with the `include` function.
30
+ */
31
+
32
+ // TODO International date line?
33
+
34
+ // @constructor LatLngBounds(corner1: LatLng, corner2: LatLng)
35
+ // Creates a `LatLngBounds` object by defining two diagonally opposite corners of the rectangle.
36
+
37
+ // @alternative
38
+ // @constructor LatLngBounds(latlngs: LatLng[])
39
+ // Creates a `LatLngBounds` object defined by the geographical points it contains. Very useful for zooming the map to fit a particular set of locations with [`fitBounds`](#map-fitbounds).
40
+
41
+ // @alternative
42
+ // @constructor LatLngBounds(bounds: LatLngBounds)
43
+ // Creates a copy of the given `LatLngBounds` object.
44
+ export class LatLngBounds {
45
+ constructor(corner1, corner2) { // (LatLng, LatLng) or (LatLng[])
46
+ if (!corner1) { return; }
47
+
48
+ if (corner1 instanceof LatLngBounds) {
49
+ if (corner1.isValid()) {
50
+ this._southWest = new LatLng(corner1._southWest);
51
+ this._northEast = new LatLng(corner1._northEast);
52
+ }
53
+ return;
54
+ }
55
+
56
+ const latlngs = corner2 ? [corner1, corner2] : corner1;
57
+
58
+ for (const latlng of latlngs) {
59
+ this.extend(latlng);
60
+ }
61
+ }
62
+
63
+ // @method extend(latlng: LatLng): this
64
+ // Extend the bounds to contain the given point
65
+
66
+ // @alternative
67
+ // @method extend(otherBounds: LatLngBounds): this
68
+ // Extend the bounds to contain the given bounds
69
+ extend(obj) {
70
+ const sw = this._southWest,
71
+ ne = this._northEast;
72
+ let sw2, ne2;
73
+
74
+ if (obj instanceof LatLng) {
75
+ sw2 = obj;
76
+ ne2 = obj;
77
+
78
+ } else if (obj instanceof LatLngBounds) {
79
+ sw2 = obj._southWest;
80
+ ne2 = obj._northEast;
81
+
82
+ if (!sw2 || !ne2) { return this; }
83
+
84
+ } else {
85
+ if (!obj) {
86
+ return this;
87
+ }
88
+ if (LatLng.validate(obj)) {
89
+ return this.extend(new LatLng(obj));
90
+ }
91
+ return this.extend(new LatLngBounds(obj));
92
+ }
93
+
94
+ if (!sw && !ne) {
95
+ this._southWest = new LatLng(sw2.lat, sw2.lng);
96
+ this._northEast = new LatLng(ne2.lat, ne2.lng);
97
+ } else {
98
+ sw.lat = Math.min(sw2.lat, sw.lat);
99
+ sw.lng = Math.min(sw2.lng, sw.lng);
100
+ ne.lat = Math.max(ne2.lat, ne.lat);
101
+ ne.lng = Math.max(ne2.lng, ne.lng);
102
+ }
103
+
104
+ return this;
105
+ }
106
+
107
+ // @method pad(bufferRatio: Number): LatLngBounds
108
+ // Returns bounds created by extending or retracting the current bounds by a given ratio in each direction.
109
+ // For example, a ratio of 0.5 extends the bounds by 50% in each direction.
110
+ // Negative values will retract the bounds.
111
+ pad(bufferRatio) {
112
+ const sw = this._southWest,
113
+ ne = this._northEast,
114
+ heightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio,
115
+ widthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio;
116
+
117
+ return new LatLngBounds(
118
+ new LatLng(sw.lat - heightBuffer, sw.lng - widthBuffer),
119
+ new LatLng(ne.lat + heightBuffer, ne.lng + widthBuffer));
120
+ }
121
+
122
+ // @method getCenter(): LatLng
123
+ // Returns the center point of the bounds.
124
+ getCenter() {
125
+ return new LatLng(
126
+ (this._southWest.lat + this._northEast.lat) / 2,
127
+ (this._southWest.lng + this._northEast.lng) / 2);
128
+ }
129
+
130
+ // @method getSouthWest(): LatLng
131
+ // Returns the south-west point of the bounds.
132
+ getSouthWest() {
133
+ return this._southWest;
134
+ }
135
+
136
+ // @method getNorthEast(): LatLng
137
+ // Returns the north-east point of the bounds.
138
+ getNorthEast() {
139
+ return this._northEast;
140
+ }
141
+
142
+ // @method getNorthWest(): LatLng
143
+ // Returns the north-west point of the bounds.
144
+ getNorthWest() {
145
+ return new LatLng(this.getNorth(), this.getWest());
146
+ }
147
+
148
+ // @method getSouthEast(): LatLng
149
+ // Returns the south-east point of the bounds.
150
+ getSouthEast() {
151
+ return new LatLng(this.getSouth(), this.getEast());
152
+ }
153
+
154
+ // @method getWest(): Number
155
+ // Returns the west longitude of the bounds
156
+ getWest() {
157
+ return this._southWest.lng;
158
+ }
159
+
160
+ // @method getSouth(): Number
161
+ // Returns the south latitude of the bounds
162
+ getSouth() {
163
+ return this._southWest.lat;
164
+ }
165
+
166
+ // @method getEast(): Number
167
+ // Returns the east longitude of the bounds
168
+ getEast() {
169
+ return this._northEast.lng;
170
+ }
171
+
172
+ // @method getNorth(): Number
173
+ // Returns the north latitude of the bounds
174
+ getNorth() {
175
+ return this._northEast.lat;
176
+ }
177
+
178
+ // @method contains(otherBounds: LatLngBounds): Boolean
179
+ // Returns `true` if the rectangle contains the given one.
180
+
181
+ // @alternative
182
+ // @method contains (latlng: LatLng): Boolean
183
+ // Returns `true` if the rectangle contains the given point.
184
+ contains(obj) { // (LatLngBounds) or (LatLng) -> Boolean
185
+ if (LatLng.validate(obj)) {
186
+ obj = new LatLng(obj);
187
+ } else {
188
+ obj = new LatLngBounds(obj);
189
+ }
190
+
191
+ const sw = this._southWest,
192
+ ne = this._northEast;
193
+ let sw2, ne2;
194
+
195
+ if (obj instanceof LatLngBounds) {
196
+ sw2 = obj.getSouthWest();
197
+ ne2 = obj.getNorthEast();
198
+ } else {
199
+ sw2 = ne2 = obj;
200
+ }
201
+
202
+ return (sw2.lat >= sw.lat) && (ne2.lat <= ne.lat) &&
203
+ (sw2.lng >= sw.lng) && (ne2.lng <= ne.lng);
204
+ }
205
+
206
+ // @method intersects(otherBounds: LatLngBounds): Boolean
207
+ // Returns `true` if the rectangle intersects the given bounds. Two bounds intersect if they have at least one point in common.
208
+ intersects(bounds) {
209
+ bounds = new LatLngBounds(bounds);
210
+
211
+ const sw = this._southWest,
212
+ ne = this._northEast,
213
+ sw2 = bounds.getSouthWest(),
214
+ ne2 = bounds.getNorthEast(),
215
+
216
+ latIntersects = (ne2.lat >= sw.lat) && (sw2.lat <= ne.lat),
217
+ lngIntersects = (ne2.lng >= sw.lng) && (sw2.lng <= ne.lng);
218
+
219
+ return latIntersects && lngIntersects;
220
+ }
221
+
222
+ // @method overlaps(otherBounds: LatLngBounds): Boolean
223
+ // Returns `true` if the rectangle overlaps the given bounds. Two bounds overlap if their intersection is an area.
224
+ overlaps(bounds) {
225
+ bounds = new LatLngBounds(bounds);
226
+
227
+ const sw = this._southWest,
228
+ ne = this._northEast,
229
+ sw2 = bounds.getSouthWest(),
230
+ ne2 = bounds.getNorthEast(),
231
+
232
+ latOverlaps = (ne2.lat > sw.lat) && (sw2.lat < ne.lat),
233
+ lngOverlaps = (ne2.lng > sw.lng) && (sw2.lng < ne.lng);
234
+
235
+ return latOverlaps && lngOverlaps;
236
+ }
237
+
238
+ // @method toBBoxString(): String
239
+ // Returns a string with bounding box coordinates in a 'southwest_lng,southwest_lat,northeast_lng,northeast_lat' format. Useful for sending requests to web services that return geo data.
240
+ toBBoxString() {
241
+ return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()].join(',');
242
+ }
243
+
244
+ // @method equals(otherBounds: LatLngBounds, maxMargin?: Number): Boolean
245
+ // Returns `true` if the rectangle is equivalent (within a small margin of error) to the given bounds. The margin of error can be overridden by setting `maxMargin` to a small number.
246
+ equals(bounds, maxMargin) {
247
+ if (!bounds) { return false; }
248
+
249
+ bounds = new LatLngBounds(bounds);
250
+
251
+ return this._southWest.equals(bounds.getSouthWest(), maxMargin) &&
252
+ this._northEast.equals(bounds.getNorthEast(), maxMargin);
253
+ }
254
+
255
+ // @method isValid(): Boolean
256
+ // Returns `true` if the bounds are properly initialized.
257
+ isValid() {
258
+ return !!(this._southWest && this._northEast);
259
+ }
260
+ }
@@ -0,0 +1,143 @@
1
+
2
+ import {Bounds} from '../../geometry/Bounds.js';
3
+ import {LatLng} from '../LatLng.js';
4
+ import {LatLngBounds} from '../LatLngBounds.js';
5
+ import * as Util from '../../core/Util.js';
6
+
7
+ /*
8
+ * @namespace CRS
9
+ * @crs CRS.Base
10
+ * Object that defines coordinate reference systems for projecting
11
+ * geographical points into pixel (screen) coordinates and back (and to
12
+ * coordinates in other units for [WMS](https://en.wikipedia.org/wiki/Web_Map_Service) services). See
13
+ * [spatial reference system](https://en.wikipedia.org/wiki/Spatial_reference_system).
14
+ *
15
+ * Maplair defines the most usual CRSs by default. If you want to use a
16
+ * CRS not defined by default, take a look at the
17
+ * [Proj4Maplair](https://github.com/kartena/Proj4Leaflet) plugin.
18
+ *
19
+ * Note that the CRS instances do not inherit from Maplair's `Class` object,
20
+ * and can't be instantiated. Also, new classes can't inherit from them,
21
+ * and methods can't be added to them with the `include` function.
22
+ */
23
+
24
+ export class CRS {
25
+ static projection = undefined;
26
+ static transformation = undefined;
27
+
28
+ // @method latLngToPoint(latlng: LatLng, zoom: Number): Point
29
+ // Projects geographical coordinates into pixel coordinates for a given zoom.
30
+ static latLngToPoint(latlng, zoom) {
31
+ const projectedPoint = this.projection.project(latlng),
32
+ scale = this.scale(zoom);
33
+
34
+ return this.transformation._transform(projectedPoint, scale);
35
+ }
36
+
37
+ // @method pointToLatLng(point: Point, zoom: Number): LatLng
38
+ // The inverse of `latLngToPoint`. Projects pixel coordinates on a given
39
+ // zoom into geographical coordinates.
40
+ static pointToLatLng(point, zoom) {
41
+ const scale = this.scale(zoom),
42
+ untransformedPoint = this.transformation.untransform(point, scale);
43
+
44
+ return this.projection.unproject(untransformedPoint);
45
+ }
46
+
47
+ // @method project(latlng: LatLng): Point
48
+ // Projects geographical coordinates into coordinates in units accepted for
49
+ // this CRS (e.g. meters for EPSG:3857, for passing it to WMS services).
50
+ static project(latlng) {
51
+ return this.projection.project(latlng);
52
+ }
53
+
54
+ // @method unproject(point: Point): LatLng
55
+ // Given a projected coordinate returns the corresponding LatLng.
56
+ // The inverse of `project`.
57
+ static unproject(point) {
58
+ return this.projection.unproject(point);
59
+ }
60
+
61
+ // @method scale(zoom: Number): Number
62
+ // Returns the scale used when transforming projected coordinates into
63
+ // pixel coordinates for a particular zoom. For example, it returns
64
+ // `256 * 2^zoom` for Mercator-based CRS.
65
+ static scale(zoom) {
66
+ return 256 * 2 ** zoom;
67
+ }
68
+
69
+ // @method zoom(scale: Number): Number
70
+ // Inverse of `scale()`, returns the zoom level corresponding to a scale
71
+ // factor of `scale`.
72
+ static zoom(scale) {
73
+ return Math.log(scale / 256) / Math.LN2;
74
+ }
75
+
76
+ // @method getProjectedBounds(zoom: Number): Bounds
77
+ // Returns the projection's bounds scaled and transformed for the provided `zoom`.
78
+ static getProjectedBounds(zoom) {
79
+ if (this.infinite) { return null; }
80
+
81
+ const b = this.projection.bounds,
82
+ s = this.scale(zoom),
83
+ min = this.transformation.transform(b.min, s),
84
+ max = this.transformation.transform(b.max, s);
85
+
86
+ return new Bounds(min, max);
87
+ }
88
+
89
+ // @method distance(latlng1: LatLng, latlng2: LatLng): Number
90
+ // Returns the distance between two geographical coordinates.
91
+
92
+ // @property code: String
93
+ // Standard code name of the CRS passed into WMS services (e.g. `'EPSG:3857'`)
94
+ //
95
+ // @property wrapLng: Number[]
96
+ // An array of two numbers defining whether the longitude (horizontal) coordinate
97
+ // axis wraps around a given range and how. Defaults to `[-180, 180]` in most
98
+ // geographical CRSs. If `undefined`, the longitude axis does not wrap around.
99
+ //
100
+ // @property wrapLat: Number[]
101
+ // Like `wrapLng`, but for the latitude (vertical) axis.
102
+
103
+ // wrapLng: [min, max],
104
+ // wrapLat: [min, max],
105
+
106
+ // @property infinite: Boolean
107
+ // If true, the coordinate space will be unbounded (infinite in both axes)
108
+ static infinite = false;
109
+
110
+ // @method wrapLatLng(latlng: LatLng): LatLng
111
+ // Returns a `LatLng` where lat and lng has been wrapped according to the
112
+ // CRS's `wrapLat` and `wrapLng` properties, if they are outside the CRS's bounds.
113
+ static wrapLatLng(latlng) {
114
+ latlng = new LatLng(latlng);
115
+ const lng = this.wrapLng ? Util.wrapNum(latlng.lng, this.wrapLng, true) : latlng.lng,
116
+ lat = this.wrapLat ? Util.wrapNum(latlng.lat, this.wrapLat, true) : latlng.lat,
117
+ alt = latlng.alt;
118
+
119
+ return new LatLng(lat, lng, alt);
120
+ }
121
+
122
+ // @method wrapLatLngBounds(bounds: LatLngBounds): LatLngBounds
123
+ // Returns a `LatLngBounds` with the same size as the given one, ensuring
124
+ // that its center is within the CRS's bounds.
125
+ static wrapLatLngBounds(bounds) {
126
+ bounds = new LatLngBounds(bounds);
127
+ const center = bounds.getCenter(),
128
+ newCenter = this.wrapLatLng(center),
129
+ latShift = center.lat - newCenter.lat,
130
+ lngShift = center.lng - newCenter.lng;
131
+
132
+ if (latShift === 0 && lngShift === 0) {
133
+ return bounds;
134
+ }
135
+
136
+ const sw = bounds.getSouthWest(),
137
+ ne = bounds.getNorthEast(),
138
+ newSw = new LatLng(sw.lat - latShift, sw.lng - lngShift),
139
+ newNe = new LatLng(ne.lat - latShift, ne.lng - lngShift);
140
+
141
+ return new LatLngBounds(newSw, newNe);
142
+ }
143
+ }