MCPcopy Create free account
hub / github.com/carbonplan/maps / pointToCamera

Function pointToCamera

src/utils.js:52–63  ·  view source on GitHub ↗
(lon, lat, z)

Source from the content-addressed store, hash-verified

50}
51
52export const pointToCamera = (lon, lat, z) => {
53 const sin = Math.sin(lat * d2r)
54 const z2 = Math.pow(2, z)
55
56 let x = z2 * (lon / 360 + 0.5)
57 let y = z2 * (0.5 - (0.25 * Math.log((1 + sin) / (1 - sin))) / Math.PI)
58
59 x = x % z2
60 y = Math.max(Math.min(y, z2), 0)
61 if (x < 0) x = x + z2
62 return [x, y, z]
63}
64
65export const cameraToPoint = (x, y, z) => {
66 const z2 = Math.pow(2, z)

Callers 2

TilesFunction · 0.90
pointToTileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected