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

Function pointToTile

src/utils.js:26–50  ·  view source on GitHub ↗
(lon, lat, z, projection, order)

Source from the content-addressed store, hash-verified

24}
25
26export const pointToTile = (lon, lat, z, projection, order) => {
27 const z2 = Math.pow(2, z)
28
29 let tile
30 switch (projection) {
31 case 'mercator':
32 tile = pointToCamera(lon, lat, z, projection)
33 break
34 case 'equirectangular':
35 let x = z2 * (lon / 360 + 0.5)
36 let y = z2 * ((order[1] * -1 * lat) / 180 + 0.5)
37
38 x = x % z2
39 if (x < 0) x = x + z2
40 y = Math.max(Math.min(y, z2), 0)
41 tile = [x, y, z]
42 break
43 default:
44 return
45 }
46 tile[0] = Math.floor(tile[0])
47 tile[1] = Math.min(Math.floor(tile[1]), z2 - 1)
48
49 return tile
50}
51
52export const pointToCamera = (lon, lat, z) => {
53 const sin = Math.sin(lat * d2r)

Callers 2

TilesFunction · 0.90
getTilesOfRegionFunction · 0.85

Calls 1

pointToCameraFunction · 0.85

Tested by

no test coverage detected