How to find out map tile coordinates from latitude

2019-04-26 18:21发布

I'm using Mapbox vector tiles to gather specific data from a backend process. In the examples, they provide a link of a Manhattan tile:

http://a.tiles.mapbox.com/v3/examples.map-zr0njcqy/14/4823/6160.png

being the tile z/x/y coordinates 14/4823/6160

I know from navigating the map that the position of latitude 40.706119 and longitude -74.017554 is inside that tile.

I also deduct from how map works that working with zoom 14 the entire map is composed from 16384 x 16384 tiles being 14/0/0 the top left tile.

Yet taking the 180 degrees of latitude and 360 of longitude with the total tile cols and rows gives me 14/7464/4486 which is not the same tile. (Unless I didn't do it right?)

The question

How do I get the tile coordinates knowing the latitude and longitude?

标签: mapbox
1条回答
Summer. ? 凉城
2楼-- · 2019-04-26 18:44

Digging in mapbox-studio source code I've found this little helper object:

https://github.com/mapbox/mapbox-studio/blob/5ac2ead1e523b24c8b8ad8655babb66389166e87/ext/sphericalmercator.js

that can be used like this:

> var a = new SphericalMercator()
> a.xyz([-74.017554, 40.706119], 14)
Object { minX: 4823, minY: NaN, maxX: NaN, maxY: 6160 }

14/4823/6160

查看更多
登录 后发表回答