|
|
|
@ -19,6 +19,7 @@ |
|
|
|
|
#include "util/coding.h" |
|
|
|
|
#include "util/string_util.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// There are two types of keys. The first type of key-values
|
|
|
|
|
// maps a geo location to the set of object ids and their values.
|
|
|
|
@ -352,8 +353,8 @@ Status GeoDBImpl::searchQuadIds(const GeoPosition& position, |
|
|
|
|
Pixel bottomRight = PositionToPixel(bottomRightPos, Detail); |
|
|
|
|
|
|
|
|
|
// how many level of details to look for
|
|
|
|
|
int numberOfTilesAtMaxDepth = static_cast<int>(floor((bottomRight.x - topLeft.x) / 256)); |
|
|
|
|
int zoomLevelsToRise = static_cast<int>(floor(::log(numberOfTilesAtMaxDepth) / ::log(2))); |
|
|
|
|
int numberOfTilesAtMaxDepth = static_cast<int>(std::floor((bottomRight.x - topLeft.x) / 256)); |
|
|
|
|
int zoomLevelsToRise = static_cast<int>(std::floor(std::log(numberOfTilesAtMaxDepth) / std::log(2))); |
|
|
|
|
zoomLevelsToRise++; |
|
|
|
|
int levels = std::max(0, Detail - zoomLevelsToRise); |
|
|
|
|
|
|
|
|
@ -390,10 +391,10 @@ GeoDBImpl::Pixel GeoDBImpl::PositionToPixel(const GeoPosition& pos, |
|
|
|
|
double latitude = clip(pos.latitude, MinLatitude, MaxLatitude); |
|
|
|
|
double x = (pos.longitude + 180) / 360; |
|
|
|
|
double sinLatitude = sin(latitude * PI / 180); |
|
|
|
|
double y = 0.5 - ::log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * PI); |
|
|
|
|
double y = 0.5 - std::log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * PI); |
|
|
|
|
double mapSize = MapSize(levelOfDetail); |
|
|
|
|
double X = floor(clip(x * mapSize + 0.5, 0, mapSize - 1)); |
|
|
|
|
double Y = floor(clip(y * mapSize + 0.5, 0, mapSize - 1)); |
|
|
|
|
double X = std::floor(clip(x * mapSize + 0.5, 0, mapSize - 1)); |
|
|
|
|
double Y = std::floor(clip(y * mapSize + 0.5, 0, mapSize - 1)); |
|
|
|
|
return Pixel((unsigned int)X, (unsigned int)Y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -408,8 +409,8 @@ GeoPosition GeoDBImpl::PixelToPosition(const Pixel& pixel, int levelOfDetail) { |
|
|
|
|
|
|
|
|
|
// Converts a Pixel to a Tile
|
|
|
|
|
GeoDBImpl::Tile GeoDBImpl::PixelToTile(const Pixel& pixel) { |
|
|
|
|
unsigned int tileX = static_cast<unsigned int>(floor(pixel.x / 256)); |
|
|
|
|
unsigned int tileY = static_cast<unsigned int>(floor(pixel.y / 256)); |
|
|
|
|
unsigned int tileX = static_cast<unsigned int>(std::floor(pixel.x / 256)); |
|
|
|
|
unsigned int tileY = static_cast<unsigned int>(std::floor(pixel.y / 256)); |
|
|
|
|
return Tile(tileX, tileY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|