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.
- package/CHANGELOG.md +2804 -0
- package/LICENSE +27 -0
- package/README.md +40 -0
- package/dist/esm/Maplair.js +71 -0
- package/dist/esm/Maplair.js.map +1 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +13 -0
- package/dist/esm/control/AttributionControl.js +79 -0
- package/dist/esm/control/AttributionControl.js.map +1 -0
- package/dist/esm/control/Control.js +81 -0
- package/dist/esm/control/Control.js.map +1 -0
- package/dist/esm/control/LayersControl.js +220 -0
- package/dist/esm/control/LayersControl.js.map +1 -0
- package/dist/esm/control/ScaleControl.js +72 -0
- package/dist/esm/control/ScaleControl.js.map +1 -0
- package/dist/esm/control/ZoomControl.js +86 -0
- package/dist/esm/control/ZoomControl.js.map +1 -0
- package/dist/esm/core/Browser.js +31 -0
- package/dist/esm/core/Browser.js.map +1 -0
- package/dist/esm/core/Class.js +52 -0
- package/dist/esm/core/Class.js.map +1 -0
- package/dist/esm/core/Events.js +149 -0
- package/dist/esm/core/Events.js.map +1 -0
- package/dist/esm/core/Handler.js +32 -0
- package/dist/esm/core/Handler.js.map +1 -0
- package/dist/esm/core/I18n.js +36 -0
- package/dist/esm/core/I18n.js.map +1 -0
- package/dist/esm/core/Util.js +71 -0
- package/dist/esm/core/Util.js.map +1 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js +74 -0
- package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js +46 -0
- package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -0
- package/dist/esm/dom/DomEvent.js +135 -0
- package/dist/esm/dom/DomEvent.js.map +1 -0
- package/dist/esm/dom/DomUtil.js +107 -0
- package/dist/esm/dom/DomUtil.js.map +1 -0
- package/dist/esm/dom/Draggable.js +107 -0
- package/dist/esm/dom/Draggable.js.map +1 -0
- package/dist/esm/dom/PosAnimation.js +56 -0
- package/dist/esm/dom/PosAnimation.js.map +1 -0
- package/dist/esm/geo/LatLng.js +65 -0
- package/dist/esm/geo/LatLng.js.map +1 -0
- package/dist/esm/geo/LatLngBounds.js +114 -0
- package/dist/esm/geo/LatLngBounds.js.map +1 -0
- package/dist/esm/geo/crs/CRS.js +51 -0
- package/dist/esm/geo/crs/CRS.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3395.js +16 -0
- package/dist/esm/geo/crs/EPSG3395.js.map +1 -0
- package/dist/esm/geo/crs/EPSG3857.js +19 -0
- package/dist/esm/geo/crs/EPSG3857.js.map +1 -0
- package/dist/esm/geo/crs/EPSG4326.js +13 -0
- package/dist/esm/geo/crs/EPSG4326.js.map +1 -0
- package/dist/esm/geo/crs/EarthCRS.js +14 -0
- package/dist/esm/geo/crs/EarthCRS.js.map +1 -0
- package/dist/esm/geo/crs/SimpleCRS.js +23 -0
- package/dist/esm/geo/crs/SimpleCRS.js.map +1 -0
- package/dist/esm/geo/projection/Projection.LonLat.js +19 -0
- package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -0
- package/dist/esm/geo/projection/Projection.Mercator.js +33 -0
- package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js +27 -0
- package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -0
- package/dist/esm/geo/projection/index.js +14 -0
- package/dist/esm/geo/projection/index.js.map +1 -0
- package/dist/esm/geometry/Bounds.js +91 -0
- package/dist/esm/geometry/Bounds.js.map +1 -0
- package/dist/esm/geometry/LineUtil.js +169 -0
- package/dist/esm/geometry/LineUtil.js.map +1 -0
- package/dist/esm/geometry/Point.js +119 -0
- package/dist/esm/geometry/Point.js.map +1 -0
- package/dist/esm/geometry/PolyUtil.js +89 -0
- package/dist/esm/geometry/PolyUtil.js.map +1 -0
- package/dist/esm/geometry/Transformation.js +34 -0
- package/dist/esm/geometry/Transformation.js.map +1 -0
- package/dist/esm/layer/BlanketOverlay.js +87 -0
- package/dist/esm/layer/BlanketOverlay.js.map +1 -0
- package/dist/esm/layer/DivOverlay.js +192 -0
- package/dist/esm/layer/DivOverlay.js.map +1 -0
- package/dist/esm/layer/FeatureGroup.js +40 -0
- package/dist/esm/layer/FeatureGroup.js.map +1 -0
- package/dist/esm/layer/GeoJSON.js +192 -0
- package/dist/esm/layer/GeoJSON.js.map +1 -0
- package/dist/esm/layer/ImageOverlay.js +140 -0
- package/dist/esm/layer/ImageOverlay.js.map +1 -0
- package/dist/esm/layer/Layer.js +119 -0
- package/dist/esm/layer/Layer.js.map +1 -0
- package/dist/esm/layer/LayerGroup.js +58 -0
- package/dist/esm/layer/LayerGroup.js.map +1 -0
- package/dist/esm/layer/Popup.js +224 -0
- package/dist/esm/layer/Popup.js.map +1 -0
- package/dist/esm/layer/SVGOverlay.js +21 -0
- package/dist/esm/layer/SVGOverlay.js.map +1 -0
- package/dist/esm/layer/Tooltip.js +228 -0
- package/dist/esm/layer/Tooltip.js.map +1 -0
- package/dist/esm/layer/VideoOverlay.js +54 -0
- package/dist/esm/layer/VideoOverlay.js.map +1 -0
- package/dist/esm/layer/marker/DefaultIcon.js +50 -0
- package/dist/esm/layer/marker/DefaultIcon.js.map +1 -0
- package/dist/esm/layer/marker/DivIcon.js +37 -0
- package/dist/esm/layer/marker/DivIcon.js.map +1 -0
- package/dist/esm/layer/marker/Icon.js +65 -0
- package/dist/esm/layer/marker/Icon.js.map +1 -0
- package/dist/esm/layer/marker/Marker.Drag.js +77 -0
- package/dist/esm/layer/marker/Marker.Drag.js.map +1 -0
- package/dist/esm/layer/marker/Marker.js +235 -0
- package/dist/esm/layer/marker/Marker.js.map +1 -0
- package/dist/esm/layer/tile/GridLayer.js +447 -0
- package/dist/esm/layer/tile/GridLayer.js.map +1 -0
- package/dist/esm/layer/tile/TileLayer.js +139 -0
- package/dist/esm/layer/tile/TileLayer.js.map +1 -0
- package/dist/esm/layer/tile/WMSTileLayer.js +68 -0
- package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -0
- package/dist/esm/layer/vector/Canvas.js +292 -0
- package/dist/esm/layer/vector/Canvas.js.map +1 -0
- package/dist/esm/layer/vector/Circle.js +35 -0
- package/dist/esm/layer/vector/Circle.js.map +1 -0
- package/dist/esm/layer/vector/CircleMarker.js +69 -0
- package/dist/esm/layer/vector/CircleMarker.js.map +1 -0
- package/dist/esm/layer/vector/Path.js +68 -0
- package/dist/esm/layer/vector/Path.js.map +1 -0
- package/dist/esm/layer/vector/Polygon.js +70 -0
- package/dist/esm/layer/vector/Polygon.js.map +1 -0
- package/dist/esm/layer/vector/Polyline.js +152 -0
- package/dist/esm/layer/vector/Polyline.js.map +1 -0
- package/dist/esm/layer/vector/Rectangle.js +25 -0
- package/dist/esm/layer/vector/Rectangle.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js +31 -0
- package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -0
- package/dist/esm/layer/vector/Renderer.js +39 -0
- package/dist/esm/layer/vector/Renderer.js.map +1 -0
- package/dist/esm/layer/vector/SVG.js +115 -0
- package/dist/esm/layer/vector/SVG.js.map +1 -0
- package/dist/esm/map/Map.js +844 -0
- package/dist/esm/map/Map.js.map +1 -0
- package/dist/esm/map/handler/BoxZoomHandler.js +105 -0
- package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js +27 -0
- package/dist/esm/map/handler/DoubleClickZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/DragHandler.js +133 -0
- package/dist/esm/map/handler/DragHandler.js.map +1 -0
- package/dist/esm/map/handler/KeyboardHandler.js +117 -0
- package/dist/esm/map/handler/KeyboardHandler.js.map +1 -0
- package/dist/esm/map/handler/PinchZoomHandler.js +96 -0
- package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js +50 -0
- package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -0
- package/dist/esm/map/handler/TapHoldHandler.js +77 -0
- package/dist/esm/map/handler/TapHoldHandler.js.map +1 -0
- package/dist/esm/package.js +6 -0
- package/dist/esm/package.js.map +1 -0
- package/dist/images/layers.svg +1 -0
- package/dist/images/logo.svg +1 -0
- package/dist/images/marker-icon.svg +1 -0
- package/dist/images/marker-shadow.svg +1 -0
- package/dist/maplair-global-src.js +6810 -0
- package/dist/maplair-global-src.js.map +1 -0
- package/dist/maplair-global.js +12 -0
- package/dist/maplair-global.js.map +1 -0
- package/dist/maplair-src.js +6704 -0
- package/dist/maplair-src.js.map +1 -0
- package/dist/maplair.css +730 -0
- package/dist/maplair.js +7 -0
- package/dist/maplair.js.map +1 -0
- package/i18n/cs.json +12 -0
- package/i18n/de.json +12 -0
- package/i18n/en.json +12 -0
- package/i18n/es.json +12 -0
- package/i18n/fr.json +12 -0
- package/i18n/hu.json +12 -0
- package/i18n/it.json +12 -0
- package/i18n/rm.json +12 -0
- package/i18n/sk.json +12 -0
- package/i18n/sl.json +12 -0
- package/package.json +87 -0
- package/src/Maplair.js +24 -0
- package/src/control/AttributionControl.js +147 -0
- package/src/control/Control.js +174 -0
- package/src/control/LayersControl.js +444 -0
- package/src/control/ScaleControl.js +141 -0
- package/src/control/ZoomControl.js +147 -0
- package/src/control/index.js +5 -0
- package/src/core/Browser.js +75 -0
- package/src/core/Class.js +97 -0
- package/src/core/Events.js +334 -0
- package/src/core/Handler.js +59 -0
- package/src/core/I18n.js +76 -0
- package/src/core/Util.js +122 -0
- package/src/core/index.js +8 -0
- package/src/dom/DomEvent.DoubleTap.js +120 -0
- package/src/dom/DomEvent.PointerEvents.js +75 -0
- package/src/dom/DomEvent.js +282 -0
- package/src/dom/DomUtil.js +175 -0
- package/src/dom/Draggable.js +204 -0
- package/src/dom/PosAnimation.js +115 -0
- package/src/dom/index.js +9 -0
- package/src/geo/LatLng.js +163 -0
- package/src/geo/LatLngBounds.js +260 -0
- package/src/geo/crs/CRS.js +143 -0
- package/src/geo/crs/EPSG3395.js +19 -0
- package/src/geo/crs/EPSG3857.js +26 -0
- package/src/geo/crs/EPSG4326.js +21 -0
- package/src/geo/crs/EarthCRS.js +32 -0
- package/src/geo/crs/SimpleCRS.js +35 -0
- package/src/geo/crs/index.js +6 -0
- package/src/geo/index.js +7 -0
- package/src/geo/projection/Projection.LonLat.js +30 -0
- package/src/geo/projection/Projection.Mercator.js +53 -0
- package/src/geo/projection/Projection.SphericalMercator.js +46 -0
- package/src/geo/projection/index.js +26 -0
- package/src/geometry/Bounds.js +222 -0
- package/src/geometry/LineUtil.js +299 -0
- package/src/geometry/Point.js +239 -0
- package/src/geometry/PolyUtil.js +129 -0
- package/src/geometry/Transformation.js +67 -0
- package/src/geometry/index.js +8 -0
- package/src/images/layers.svg +1 -0
- package/src/images/logo.svg +1 -0
- package/src/images/marker-icon.svg +1 -0
- package/src/images/marker-shadow.svg +1 -0
- package/src/layer/BlanketOverlay.js +171 -0
- package/src/layer/DivOverlay.js +353 -0
- package/src/layer/FeatureGroup.js +93 -0
- package/src/layer/GeoJSON.js +432 -0
- package/src/layer/ImageOverlay.js +279 -0
- package/src/layer/Layer.js +273 -0
- package/src/layer/LayerGroup.js +129 -0
- package/src/layer/Popup.js +528 -0
- package/src/layer/SVGOverlay.js +47 -0
- package/src/layer/Tooltip.js +469 -0
- package/src/layer/VideoOverlay.js +111 -0
- package/src/layer/index.js +18 -0
- package/src/layer/marker/DefaultIcon.js +79 -0
- package/src/layer/marker/DivIcon.js +76 -0
- package/src/layer/marker/Icon.js +164 -0
- package/src/layer/marker/Marker.Drag.js +161 -0
- package/src/layer/marker/Marker.js +465 -0
- package/src/layer/marker/index.js +5 -0
- package/src/layer/tile/GridLayer.js +901 -0
- package/src/layer/tile/TileLayer.js +299 -0
- package/src/layer/tile/WMSTileLayer.js +133 -0
- package/src/layer/tile/index.js +3 -0
- package/src/layer/vector/Canvas.js +479 -0
- package/src/layer/vector/Circle.js +87 -0
- package/src/layer/vector/CircleMarker.js +110 -0
- package/src/layer/vector/Path.js +145 -0
- package/src/layer/vector/Polygon.js +160 -0
- package/src/layer/vector/Polyline.js +296 -0
- package/src/layer/vector/Rectangle.js +52 -0
- package/src/layer/vector/Renderer.getRenderer.js +48 -0
- package/src/layer/vector/Renderer.js +75 -0
- package/src/layer/vector/SVG.js +216 -0
- package/src/layer/vector/index.js +10 -0
- package/src/map/Map.js +1830 -0
- package/src/map/handler/BoxZoomHandler.js +156 -0
- package/src/map/handler/DoubleClickZoomHandler.js +62 -0
- package/src/map/handler/DragHandler.js +240 -0
- package/src/map/handler/KeyboardHandler.js +188 -0
- package/src/map/handler/PinchZoomHandler.js +157 -0
- package/src/map/handler/ScrollWheelZoomHandler.js +98 -0
- package/src/map/handler/TapHoldHandler.js +111 -0
- package/src/map/index.js +8 -0
- 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
|
+
}
|
package/src/dom/index.js
ADDED
|
@@ -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
|
+
}
|