(lon, lat, z, projection, order)
| 24 | } |
| 25 | |
| 26 | export 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 | |
| 52 | export const pointToCamera = (lon, lat, z) => { |
| 53 | const sin = Math.sin(lat * d2r) |
no test coverage detected