Get the Canvas bounding box

89 views
Skip to first unread message

Franck Ernewein

unread,
Nov 13, 2014, 10:59:51 AM11/13/14
to leafl...@googlegroups.com
Hello,

I created a Canvas Tile and I would like to know the bounding box (lat/lng) of each canvas when it draws.

I tried to convert the TilePoint into a bounding box with the following code

var map = L.mapbox.map('mymap', '...'), ;
var canvasOverlay = L.tileLayer.canvas();
canvasOverlay
.drawTile = function(canvas, tilePoint, zoom) {
 
var NE = map.containerPointToLatLng(tilePoint);
 
var SW = map.containerPointToLatLng(new L.Point(tilePoint.y + 1, tilePoint.x + 1));
};
canvasOverlay
.addTo(map);


but what I get seems to be wrong.
I don't know how to convert the tilePoint in to 2 LatLng coordinates (North East and South West points).

Thanks

Franck Ernewein

unread,
Nov 13, 2014, 12:23:45 PM11/13/14
to leafl...@googlegroups.com
If it could help somebody, 
finally I found how to convert a TilePoint in LatLng coordinates :

n = 2 ^ zoom
lon_deg = xtile / n * 360.0 - 180.0
lat_rad = arctan(sinh(π * (1 - 2 * ytile / n)))
lat_deg = lat_rad * 180.0 / π
tilePoint.x, tilePoint.y, zoom
and 
tilePoint.x + 1, tilePoint.y + 1, zoom

And I get the bounding box of each canvas tile. \o/
Reply all
Reply to author
Forward
0 new messages