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,19 @@
|
|
|
1
|
+
import {EarthCRS} from './EarthCRS.js';
|
|
2
|
+
import {Mercator} from '../projection/Projection.Mercator.js';
|
|
3
|
+
import {Transformation} from '../../geometry/Transformation.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* @namespace CRS
|
|
7
|
+
* @crs EPSG3395
|
|
8
|
+
*
|
|
9
|
+
* Rarely used by some commercial tile providers. Uses Elliptical Mercator projection.
|
|
10
|
+
*/
|
|
11
|
+
export class EPSG3395 extends EarthCRS {
|
|
12
|
+
static code = 'EPSG:3395';
|
|
13
|
+
static projection = Mercator;
|
|
14
|
+
|
|
15
|
+
static transformation = (() => {
|
|
16
|
+
const scale = 0.5 / (Math.PI * Mercator.R);
|
|
17
|
+
return new Transformation(scale, 0.5, -scale, 0.5);
|
|
18
|
+
})();
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {EarthCRS} from './EarthCRS.js';
|
|
2
|
+
import {SphericalMercator} from '../projection/Projection.SphericalMercator.js';
|
|
3
|
+
import {Transformation} from '../../geometry/Transformation.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* @namespace CRS
|
|
7
|
+
* @crs EPSG3857
|
|
8
|
+
*
|
|
9
|
+
* The most common CRS for online maps, used by almost all free and commercial
|
|
10
|
+
* tile providers. Uses Spherical Mercator projection. Set in by default in
|
|
11
|
+
* Map's `crs` option.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export class EPSG3857 extends EarthCRS {
|
|
15
|
+
static code = 'EPSG:3857';
|
|
16
|
+
static projection = SphericalMercator;
|
|
17
|
+
|
|
18
|
+
static transformation = (() => {
|
|
19
|
+
const scale = 0.5 / (Math.PI * SphericalMercator.R);
|
|
20
|
+
return new Transformation(scale, 0.5, -scale, 0.5);
|
|
21
|
+
})();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class EPSG900913 extends EPSG3857 {
|
|
25
|
+
static code = 'EPSG:900913';
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {EarthCRS} from './EarthCRS.js';
|
|
2
|
+
import {LonLat} from '../projection/Projection.LonLat.js';
|
|
3
|
+
import {Transformation} from '../../geometry/Transformation.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* @namespace CRS
|
|
7
|
+
* @crs EPSG4326
|
|
8
|
+
*
|
|
9
|
+
* A common CRS among GIS enthusiasts. Uses simple Equirectangular projection.
|
|
10
|
+
*
|
|
11
|
+
* Maplair complies with the [TMS coordinate scheme for EPSG:4326](https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#global-geodetic).
|
|
12
|
+
* If you are using a `TileLayer` with this CRS, ensure that there are two 256x256 pixel tiles covering the
|
|
13
|
+
* whole earth at zoom level zero, and that the tile coordinate origin is (-180,+90),
|
|
14
|
+
* or (-180,-90) for `TileLayer`s with [the `tms` option](#tilelayer-tms) set.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export class EPSG4326 extends EarthCRS {
|
|
18
|
+
static code = 'EPSG:4326';
|
|
19
|
+
static projection = LonLat;
|
|
20
|
+
static transformation = new Transformation(1 / 180, 1, -1 / 180, 0.5);
|
|
21
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {CRS} from './CRS.js';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* @namespace CRS
|
|
5
|
+
* @crs EarthCRS
|
|
6
|
+
*
|
|
7
|
+
* Serves as the base for CRS that are global such that they cover the earth.
|
|
8
|
+
* Can only be used as the base for other CRS and cannot be used directly,
|
|
9
|
+
* since it does not have a `code`, `projection` or `transformation`. `distance()` returns
|
|
10
|
+
* meters.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export class EarthCRS extends CRS {
|
|
14
|
+
static wrapLng = [-180, 180];
|
|
15
|
+
|
|
16
|
+
// Mean Earth Radius, as recommended for use by
|
|
17
|
+
// the International Union of Geodesy and Geophysics,
|
|
18
|
+
// see https://rosettacode.org/wiki/Haversine_formula
|
|
19
|
+
static R = 6371000;
|
|
20
|
+
|
|
21
|
+
// distance between two geographical points using Haversine approximation
|
|
22
|
+
static distance(latlng1, latlng2) {
|
|
23
|
+
const rad = Math.PI / 180,
|
|
24
|
+
lat1 = latlng1.lat * rad,
|
|
25
|
+
lat2 = latlng2.lat * rad,
|
|
26
|
+
sinDLat = Math.sin((latlng2.lat - latlng1.lat) * rad / 2),
|
|
27
|
+
sinDLon = Math.sin((latlng2.lng - latlng1.lng) * rad / 2),
|
|
28
|
+
a = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon,
|
|
29
|
+
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
30
|
+
return this.R * c;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {CRS} from './CRS.js';
|
|
2
|
+
import {LonLat} from '../projection/Projection.LonLat.js';
|
|
3
|
+
import {Transformation} from '../../geometry/Transformation.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* @namespace CRS
|
|
7
|
+
* @crs SimpleCRS
|
|
8
|
+
*
|
|
9
|
+
* A simple CRS that maps longitude and latitude into `x` and `y` directly.
|
|
10
|
+
* May be used for maps of flat surfaces (e.g. game maps). Note that the `y`
|
|
11
|
+
* axis should still be inverted (going from bottom to top). `distance()` returns
|
|
12
|
+
* simple euclidean distance.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export class SimpleCRS extends CRS {
|
|
16
|
+
static projection = LonLat;
|
|
17
|
+
static transformation = new Transformation(1, 0, -1, 0);
|
|
18
|
+
|
|
19
|
+
static scale(zoom) {
|
|
20
|
+
return 2 ** zoom;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static zoom(scale) {
|
|
24
|
+
return Math.log(scale) / Math.LN2;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static distance(latlng1, latlng2) {
|
|
28
|
+
const dx = latlng2.lng - latlng1.lng,
|
|
29
|
+
dy = latlng2.lat - latlng1.lat;
|
|
30
|
+
|
|
31
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static infinite = true;
|
|
35
|
+
}
|
package/src/geo/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {LatLng} from '../LatLng.js';
|
|
2
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
3
|
+
import {Point} from '../../geometry/Point.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* @namespace Projection
|
|
7
|
+
* @section
|
|
8
|
+
* Maplair comes with a set of already defined Projections out of the box:
|
|
9
|
+
*
|
|
10
|
+
* @projection Projection.LonLat
|
|
11
|
+
*
|
|
12
|
+
* Equirectangular, or Plate Carree projection — the most simple projection,
|
|
13
|
+
* mostly used by GIS enthusiasts. Directly maps `x` as longitude, and `y` as
|
|
14
|
+
* latitude. Also suitable for flat worlds, e.g. game maps. Used by the
|
|
15
|
+
* `EPSG:4326` and `Simple` CRS.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const LonLat = {
|
|
19
|
+
project(latlng) {
|
|
20
|
+
latlng = new LatLng(latlng);
|
|
21
|
+
return new Point(latlng.lng, latlng.lat);
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
unproject(point) {
|
|
25
|
+
point = new Point(point);
|
|
26
|
+
return new LatLng(point.y, point.x);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
bounds: new Bounds([-180, -90], [180, 90])
|
|
30
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {LatLng} from '../LatLng.js';
|
|
2
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
3
|
+
import {Point} from '../../geometry/Point.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* @namespace Projection
|
|
7
|
+
* @projection Projection.Mercator
|
|
8
|
+
*
|
|
9
|
+
* Elliptical Mercator projection — more complex than Spherical Mercator. Assumes that Earth is an ellipsoid. Used by the EPSG:3395 CRS.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const earthRadius = 6378137;
|
|
13
|
+
|
|
14
|
+
export const Mercator = {
|
|
15
|
+
R: earthRadius,
|
|
16
|
+
R_MINOR: 6356752.314245179,
|
|
17
|
+
|
|
18
|
+
bounds: new Bounds([-20037508.34279, -15496570.73972], [20037508.34279, 18764656.23138]),
|
|
19
|
+
|
|
20
|
+
project(latlng) {
|
|
21
|
+
latlng = new LatLng(latlng);
|
|
22
|
+
const d = Math.PI / 180,
|
|
23
|
+
r = this.R,
|
|
24
|
+
tmp = this.R_MINOR / r,
|
|
25
|
+
e = Math.sqrt(1 - tmp * tmp);
|
|
26
|
+
let y = latlng.lat * d;
|
|
27
|
+
const con = e * Math.sin(y);
|
|
28
|
+
|
|
29
|
+
const ts = Math.tan(Math.PI / 4 - y / 2) / ((1 - con) / (1 + con)) ** (e / 2);
|
|
30
|
+
y = -r * Math.log(Math.max(ts, 1E-10));
|
|
31
|
+
|
|
32
|
+
return new Point(latlng.lng * d * r, y);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
unproject(point) {
|
|
36
|
+
point = new Point(point);
|
|
37
|
+
const d = 180 / Math.PI,
|
|
38
|
+
r = this.R,
|
|
39
|
+
tmp = this.R_MINOR / r,
|
|
40
|
+
e = Math.sqrt(1 - tmp * tmp),
|
|
41
|
+
ts = Math.exp(-point.y / r);
|
|
42
|
+
let phi = Math.PI / 2 - 2 * Math.atan(ts);
|
|
43
|
+
|
|
44
|
+
for (let i = 0, dphi = 0.1, con; i < 15 && Math.abs(dphi) > 1e-7; i++) {
|
|
45
|
+
con = e * Math.sin(phi);
|
|
46
|
+
con = ((1 - con) / (1 + con)) ** (e / 2);
|
|
47
|
+
dphi = Math.PI / 2 - 2 * Math.atan(ts * con) - phi;
|
|
48
|
+
phi += dphi;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return new LatLng(phi * d, point.x * d / r);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {LatLng} from '../LatLng.js';
|
|
2
|
+
import {Bounds} from '../../geometry/Bounds.js';
|
|
3
|
+
import {Point} from '../../geometry/Point.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* @namespace Projection
|
|
7
|
+
* @projection Projection.SphericalMercator
|
|
8
|
+
*
|
|
9
|
+
* Spherical Mercator projection — the most common projection for online maps,
|
|
10
|
+
* used by almost all free and commercial tile providers. Assumes that Earth is
|
|
11
|
+
* a sphere. Used by the `EPSG:3857` CRS.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const earthRadius = 6378137;
|
|
15
|
+
|
|
16
|
+
export const SphericalMercator = {
|
|
17
|
+
|
|
18
|
+
R: earthRadius,
|
|
19
|
+
MAX_LATITUDE: 85.0511287798,
|
|
20
|
+
|
|
21
|
+
project(latlng) {
|
|
22
|
+
latlng = new LatLng(latlng);
|
|
23
|
+
const d = Math.PI / 180,
|
|
24
|
+
max = this.MAX_LATITUDE,
|
|
25
|
+
lat = Math.max(Math.min(max, latlng.lat), -max),
|
|
26
|
+
sin = Math.sin(lat * d);
|
|
27
|
+
|
|
28
|
+
return new Point(
|
|
29
|
+
this.R * latlng.lng * d,
|
|
30
|
+
this.R * Math.log((1 + sin) / (1 - sin)) / 2);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
unproject(point) {
|
|
34
|
+
point = new Point(point);
|
|
35
|
+
const d = 180 / Math.PI;
|
|
36
|
+
|
|
37
|
+
return new LatLng(
|
|
38
|
+
(2 * Math.atan(Math.exp(point.y / this.R)) - (Math.PI / 2)) * d,
|
|
39
|
+
point.x * d / this.R);
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
bounds: (() => {
|
|
43
|
+
const d = earthRadius * Math.PI;
|
|
44
|
+
return new Bounds([-d, -d], [d, d]);
|
|
45
|
+
})()
|
|
46
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @class Projection
|
|
3
|
+
|
|
4
|
+
* An object with methods for projecting geographical coordinates of the world onto
|
|
5
|
+
* a flat surface (and back). See [Map projection](https://en.wikipedia.org/wiki/Map_projection).
|
|
6
|
+
|
|
7
|
+
* @property bounds: Bounds
|
|
8
|
+
* The bounds (specified in CRS units) where the projection is valid
|
|
9
|
+
|
|
10
|
+
* @method project(latlng: LatLng): Point
|
|
11
|
+
* Projects geographical coordinates into a 2D point.
|
|
12
|
+
* Only accepts actual `LatLng` instances, not arrays.
|
|
13
|
+
|
|
14
|
+
* @method unproject(point: Point): LatLng
|
|
15
|
+
* The inverse of `project`. Projects a 2D point into a geographical location.
|
|
16
|
+
* Only accepts actual `Point` instances, not arrays.
|
|
17
|
+
|
|
18
|
+
* Note that the projection instances do not inherit from Maplair's `Class` object,
|
|
19
|
+
* and can't be instantiated. Also, new classes can't inherit from them,
|
|
20
|
+
* and methods can't be added to them with the `include` function.
|
|
21
|
+
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export {LonLat} from './Projection.LonLat.js';
|
|
25
|
+
export {Mercator} from './Projection.Mercator.js';
|
|
26
|
+
export {SphericalMercator} from './Projection.SphericalMercator.js';
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import {Point} from './Point.js';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* @class Bounds
|
|
5
|
+
*
|
|
6
|
+
* Represents a rectangular area in pixel coordinates.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```js
|
|
11
|
+
* const p1 = new Point(10, 10),
|
|
12
|
+
* p2 = new Point(40, 60),
|
|
13
|
+
* bounds = new Bounds(p1, p2);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* All Maplair methods that accept `Bounds` 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
|
+
* otherBounds.intersects([[10, 10], [40, 60]]);
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Note that `Bounds` does not inherit from Maplair's `Class` object,
|
|
23
|
+
* which means new classes can't inherit from it, and new methods
|
|
24
|
+
* can't be added to it with the `include` function.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// @constructor Bounds(corner1: Point, corner2: Point)
|
|
29
|
+
// Creates a Bounds object from two corners coordinate pairs.
|
|
30
|
+
// @alternative
|
|
31
|
+
// @constructor Bounds(points: Point[])
|
|
32
|
+
// Creates a Bounds object from the given array of points.
|
|
33
|
+
|
|
34
|
+
// @alternative
|
|
35
|
+
// @constructor Bounds(bounds: Bounds)
|
|
36
|
+
// Creates a copy of the given Bounds object.
|
|
37
|
+
export class Bounds {
|
|
38
|
+
constructor(a, b) {
|
|
39
|
+
if (!a) { return; }
|
|
40
|
+
|
|
41
|
+
if (a instanceof Bounds) {
|
|
42
|
+
if (a.isValid()) {
|
|
43
|
+
this.min = new Point(a.min);
|
|
44
|
+
this.max = new Point(a.max);
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const points = b ? [a, b] : a;
|
|
50
|
+
for (const point of points) {
|
|
51
|
+
this.extend(point);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// @method extend(point: Point): this
|
|
56
|
+
// Extends the bounds to contain the given point.
|
|
57
|
+
|
|
58
|
+
// @alternative
|
|
59
|
+
// @method extend(otherBounds: Bounds): this
|
|
60
|
+
// Extend the bounds to contain the given bounds
|
|
61
|
+
extend(obj) {
|
|
62
|
+
let min2, max2;
|
|
63
|
+
if (!obj) { return this; }
|
|
64
|
+
|
|
65
|
+
if (obj instanceof Point || typeof obj[0] === 'number' || 'x' in obj) {
|
|
66
|
+
min2 = max2 = new Point(obj);
|
|
67
|
+
} else {
|
|
68
|
+
obj = new Bounds(obj);
|
|
69
|
+
min2 = obj.min;
|
|
70
|
+
max2 = obj.max;
|
|
71
|
+
|
|
72
|
+
if (!min2 || !max2) { return this; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// @property min: Point
|
|
76
|
+
// The top left corner of the rectangle.
|
|
77
|
+
// @property max: Point
|
|
78
|
+
// The bottom right corner of the rectangle.
|
|
79
|
+
if (!this.min && !this.max) {
|
|
80
|
+
this.min = new Point(min2);
|
|
81
|
+
this.max = new Point(max2);
|
|
82
|
+
} else {
|
|
83
|
+
this.min.x = Math.min(min2.x, this.min.x);
|
|
84
|
+
this.max.x = Math.max(max2.x, this.max.x);
|
|
85
|
+
this.min.y = Math.min(min2.y, this.min.y);
|
|
86
|
+
this.max.y = Math.max(max2.y, this.max.y);
|
|
87
|
+
}
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// @method getCenter(round?: Boolean): Point
|
|
92
|
+
// Returns the center point of the bounds.
|
|
93
|
+
getCenter(round) {
|
|
94
|
+
return new Point(
|
|
95
|
+
(this.min.x + this.max.x) / 2,
|
|
96
|
+
(this.min.y + this.max.y) / 2, round);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// @method getBottomLeft(): Point
|
|
100
|
+
// Returns the bottom-left point of the bounds.
|
|
101
|
+
getBottomLeft() {
|
|
102
|
+
return new Point(this.min.x, this.max.y);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// @method getTopRight(): Point
|
|
106
|
+
// Returns the top-right point of the bounds.
|
|
107
|
+
getTopRight() { // -> Point
|
|
108
|
+
return new Point(this.max.x, this.min.y);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// @method getTopLeft(): Point
|
|
112
|
+
// Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).
|
|
113
|
+
getTopLeft() {
|
|
114
|
+
return this.min; // left, top
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// @method getBottomRight(): Point
|
|
118
|
+
// Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).
|
|
119
|
+
getBottomRight() {
|
|
120
|
+
return this.max; // right, bottom
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// @method getSize(): Point
|
|
124
|
+
// Returns the size of the given bounds
|
|
125
|
+
getSize() {
|
|
126
|
+
return this.max.subtract(this.min);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// @method contains(otherBounds: Bounds): Boolean
|
|
130
|
+
// Returns `true` if the rectangle contains the given one.
|
|
131
|
+
// @alternative
|
|
132
|
+
// @method contains(point: Point): Boolean
|
|
133
|
+
// Returns `true` if the rectangle contains the given point.
|
|
134
|
+
contains(obj) {
|
|
135
|
+
let min, max;
|
|
136
|
+
|
|
137
|
+
if (typeof obj[0] === 'number' || obj instanceof Point) {
|
|
138
|
+
obj = new Point(obj);
|
|
139
|
+
} else {
|
|
140
|
+
obj = new Bounds(obj);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (obj instanceof Bounds) {
|
|
144
|
+
min = obj.min;
|
|
145
|
+
max = obj.max;
|
|
146
|
+
} else {
|
|
147
|
+
min = max = obj;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (min.x >= this.min.x) &&
|
|
151
|
+
(max.x <= this.max.x) &&
|
|
152
|
+
(min.y >= this.min.y) &&
|
|
153
|
+
(max.y <= this.max.y);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// @method intersects(otherBounds: Bounds): Boolean
|
|
157
|
+
// Returns `true` if the rectangle intersects the given bounds. Two bounds
|
|
158
|
+
// intersect if they have at least one point in common.
|
|
159
|
+
intersects(bounds) { // (Bounds) -> Boolean
|
|
160
|
+
bounds = new Bounds(bounds);
|
|
161
|
+
|
|
162
|
+
const min = this.min,
|
|
163
|
+
max = this.max,
|
|
164
|
+
min2 = bounds.min,
|
|
165
|
+
max2 = bounds.max,
|
|
166
|
+
xIntersects = (max2.x >= min.x) && (min2.x <= max.x),
|
|
167
|
+
yIntersects = (max2.y >= min.y) && (min2.y <= max.y);
|
|
168
|
+
|
|
169
|
+
return xIntersects && yIntersects;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// @method overlaps(otherBounds: Bounds): Boolean
|
|
173
|
+
// Returns `true` if the rectangle overlaps the given bounds. Two bounds
|
|
174
|
+
// overlap if their intersection is an area.
|
|
175
|
+
overlaps(bounds) { // (Bounds) -> Boolean
|
|
176
|
+
bounds = new Bounds(bounds);
|
|
177
|
+
|
|
178
|
+
const min = this.min,
|
|
179
|
+
max = this.max,
|
|
180
|
+
min2 = bounds.min,
|
|
181
|
+
max2 = bounds.max,
|
|
182
|
+
xOverlaps = (max2.x > min.x) && (min2.x < max.x),
|
|
183
|
+
yOverlaps = (max2.y > min.y) && (min2.y < max.y);
|
|
184
|
+
|
|
185
|
+
return xOverlaps && yOverlaps;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// @method isValid(): Boolean
|
|
189
|
+
// Returns `true` if the bounds are properly initialized.
|
|
190
|
+
isValid() {
|
|
191
|
+
return !!(this.min && this.max);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
// @method pad(bufferRatio: Number): Bounds
|
|
196
|
+
// Returns bounds created by extending or retracting the current bounds by a given ratio in each direction.
|
|
197
|
+
// For example, a ratio of 0.5 extends the bounds by 50% in each direction.
|
|
198
|
+
// Negative values will retract the bounds.
|
|
199
|
+
pad(bufferRatio) {
|
|
200
|
+
const min = this.min,
|
|
201
|
+
max = this.max,
|
|
202
|
+
heightBuffer = Math.abs(min.x - max.x) * bufferRatio,
|
|
203
|
+
widthBuffer = Math.abs(min.y - max.y) * bufferRatio;
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
return new Bounds(
|
|
207
|
+
new Point(min.x - heightBuffer, min.y - widthBuffer),
|
|
208
|
+
new Point(max.x + heightBuffer, max.y + widthBuffer));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
// @method equals(otherBounds: Bounds): Boolean
|
|
213
|
+
// Returns `true` if the rectangle is equivalent to the given bounds.
|
|
214
|
+
equals(bounds) {
|
|
215
|
+
if (!bounds) { return false; }
|
|
216
|
+
|
|
217
|
+
bounds = new Bounds(bounds);
|
|
218
|
+
|
|
219
|
+
return this.min.equals(bounds.getTopLeft()) &&
|
|
220
|
+
this.max.equals(bounds.getBottomRight());
|
|
221
|
+
}
|
|
222
|
+
}
|