@eturnity/eturnity_maths 6.34.0 → 6.34.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/package.json +1 -1
- package/src/geo.js +59 -1
package/package.json
CHANGED
package/src/geo.js
CHANGED
|
@@ -2,8 +2,66 @@ import {
|
|
|
2
2
|
earthRadius
|
|
3
3
|
} from './config'
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
export function lon2tile(lon,zoom) { return (Math.floor((lon+180)/360*Math.pow(2,zoom))); }
|
|
7
|
+
export function lat2tile(lat,zoom) { return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom))); }
|
|
8
|
+
export function tile2long(x,z) {
|
|
9
|
+
return (x/Math.pow(2,z)*360-180);
|
|
10
|
+
}
|
|
11
|
+
export function tile2lat(y,z) {
|
|
12
|
+
var n=Math.PI-2*Math.PI*y/Math.pow(2,z);
|
|
13
|
+
return (180/Math.PI*Math.atan(0.5*(Math.exp(n)-Math.exp(-n))));
|
|
14
|
+
}
|
|
15
|
+
export function latLngToTileXY(lat,lng,zoom){
|
|
16
|
+
const xTile = lon2tile(lng,zoom)
|
|
17
|
+
const yTile = lat2tile(lat,zoom)
|
|
18
|
+
return {
|
|
19
|
+
x:xTile,
|
|
20
|
+
y:yTile
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function tileXYZToLatLng(x,y,zoom){
|
|
25
|
+
const longitude=tile2long(x,zoom)
|
|
26
|
+
const latitude=tile2lat(y,zoom)
|
|
27
|
+
return {lat: latitude,lng: longitude};
|
|
28
|
+
}
|
|
5
29
|
|
|
6
|
-
export function
|
|
30
|
+
export function tileToCorners(x,y,zoom,lat,lng){
|
|
31
|
+
const tileAltitude=0
|
|
32
|
+
const tileLatLng=tileXYZToLatLng(x,y,zoom)
|
|
33
|
+
const deltaLat=tileLatLng.lat-lat
|
|
34
|
+
const deltaLng=tileLatLng.lng-lng
|
|
35
|
+
let { x:x_mm, y:y_mm }=deltaLatLngToDistance(deltaLat, deltaLng, lat)
|
|
36
|
+
let size=(earthRadius * 2000 * Math.PI / Math.pow(2.0, zoom))*Math.cos(lat*Math.PI/180)
|
|
37
|
+
let corner0={
|
|
38
|
+
x:x_mm,
|
|
39
|
+
y:y_mm,
|
|
40
|
+
z:tileAltitude
|
|
41
|
+
}
|
|
42
|
+
let corner1={
|
|
43
|
+
x:x_mm+size,
|
|
44
|
+
y:y_mm,
|
|
45
|
+
z:tileAltitude
|
|
46
|
+
}
|
|
47
|
+
let corner2={
|
|
48
|
+
x:x_mm+size,
|
|
49
|
+
y:y_mm-size,
|
|
50
|
+
z:tileAltitude
|
|
51
|
+
}
|
|
52
|
+
let corner3={
|
|
53
|
+
x:x_mm,
|
|
54
|
+
y:y_mm-size,
|
|
55
|
+
z:tileAltitude
|
|
56
|
+
}
|
|
57
|
+
return [
|
|
58
|
+
corner3,
|
|
59
|
+
corner0,
|
|
60
|
+
corner1,
|
|
61
|
+
corner2,
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
export function distanceToDeltaLatLng(x, y, latitude) {
|
|
7
65
|
//x,y,z in ENU coords
|
|
8
66
|
let lat = (180 / Math.PI) * (y / 1000) / earthRadius
|
|
9
67
|
let lng =((180 / Math.PI) * (x / 1000) / earthRadius)/(Math.cos(((latitude) * Math.PI) / 180))
|