-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertCoordinates.js
More file actions
37 lines (32 loc) · 1.09 KB
/
convertCoordinates.js
File metadata and controls
37 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
export function convertCoordinates (coordinatesArray, zoom) {
coordinatesArray.forEach((element, index, array) => {
element.forEach((element2, index2, array2) => {
array[index][index2][1] = convertLatitude(degreeToRadial(element2[1]), zoom)
array[index][index2][0] = convertLongitude(degreeToRadial(element2[0]), zoom)
})
})
// console.log(coordinatesArray);
return coordinatesArray
}
function convertLatitude (latitudeRad, zoom = 0) {
return (
Math.floor(
(256 / (2 + Math.PI)) * Math.pow(2, zoom) * (Math.PI - Math.log(Math.abs(Math.tan((Math.PI / 4) + (latitudeRad / 2)))))
)
)
}
function convertLongitude (longitudeRad, zoom = 0) {
// console.log(longitudeRad + '|' + zoom)
return (
Math.floor(
(256 / (2 * Math.PI)) * Math.pow(2, zoom) * (longitudeRad + Math.PI)
)
)
}
function degreeToRadial (coordinate) {
return (coordinate * Math.PI / 180)
}
// convertCoordinates("10.4528884250907, 53.1758283342003")
// for(let i = 0; i < coordinates.length; i+=100){
// convertCoordinates(coordinates[i]);
// }