Heavy-handedly fix clipping errors at the edges of z0 and z1 tiles

This commit is contained in:
Eric Fischer
2014-10-15 17:03:30 -07:00
parent 8fec4ef9fc
commit 3bdcc3ca90
2 changed files with 31 additions and 8 deletions
+25 -2
View File
@@ -61,8 +61,31 @@ void latlon2tile(double lat, double lon, int zoom, unsigned int *x, unsigned int
double lat_rad = lat * M_PI / 180;
unsigned long long n = 1LL << zoom;
*x = n * ((lon + 180) / 360);
*y = n * (1 - (log(tan(lat_rad) + 1/cos(lat_rad)) / M_PI)) / 2;
long long llx = n * ((lon + 180) / 360);
long long lly = n * (1 - (log(tan(lat_rad) + 1/cos(lat_rad)) / M_PI)) / 2;
if (lat >= 85.0511) {
lly = 0;
}
if (lat <= -85.0511) {
lly = n - 1;
}
if (llx < 0) {
llx = 0;
}
if (lly < 0) {
lly = 0;
}
if (llx >= n) {
llx = n - 1;
}
if (lly >= n) {
lly = n - 1;
}
*x = llx;
*y = lly;
}
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames