@@ -3,7 +3,7 @@
|
||||
|
||||
#include "engine/guidance/leg_geometry.hpp"
|
||||
#include "engine/douglas_peucker.hpp"
|
||||
#include "util/tiles.hpp"
|
||||
#include "util/viewport.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
@@ -23,25 +23,22 @@ namespace
|
||||
|
||||
unsigned calculateOverviewZoomLevel(const std::vector<LegGeometry> &leg_geometries)
|
||||
{
|
||||
util::FixedLongitude min_lon{std::numeric_limits<int>::max()};
|
||||
util::FixedLongitude max_lon{std::numeric_limits<int>::min()};
|
||||
util::FixedLatitude min_lat{std::numeric_limits<int>::max()};
|
||||
util::FixedLatitude max_lat{std::numeric_limits<int>::min()};
|
||||
util::Coordinate south_west{util::FixedLongitude{std::numeric_limits<int>::max()}, util::FixedLatitude{std::numeric_limits<int>::max()}};
|
||||
util::Coordinate north_east{util::FixedLongitude{std::numeric_limits<int>::min()}, util::FixedLatitude{std::numeric_limits<int>::min()}};
|
||||
|
||||
for (const auto &leg_geometry : leg_geometries)
|
||||
{
|
||||
for (const auto coord : leg_geometry.locations)
|
||||
{
|
||||
min_lon = std::min(min_lon, coord.lon);
|
||||
max_lon = std::max(max_lon, coord.lon);
|
||||
min_lat = std::min(min_lat, coord.lat);
|
||||
max_lat = std::max(max_lat, coord.lat);
|
||||
south_west.lon = std::min(south_west.lon, coord.lon);
|
||||
south_west.lat = std::min(south_west.lat, coord.lat);
|
||||
|
||||
north_east.lon = std::max(north_east.lon, coord.lon);
|
||||
north_east.lat = std::max(north_east.lat, coord.lat);
|
||||
}
|
||||
}
|
||||
|
||||
return util::tiles::getBBMaxZoomTile(toFloating(min_lon), toFloating(min_lat),
|
||||
toFloating(max_lon), toFloating(max_lat))
|
||||
.z;
|
||||
return util::viewport::getFittedZoom(south_west, north_east);
|
||||
}
|
||||
|
||||
std::vector<util::Coordinate> simplifyGeometry(const std::vector<LegGeometry> &leg_geometries,
|
||||
|
||||
@@ -29,20 +29,6 @@ Coordinate::Coordinate(const FloatLongitude lon_, const FloatLatitude lat_)
|
||||
|
||||
Coordinate::Coordinate(const FixedLongitude lon_, const FixedLatitude lat_) : lon(lon_), lat(lat_)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if (0 != (std::abs(static_cast<int>(lon)) >> 30))
|
||||
{
|
||||
std::bitset<32> x_coordinate_vector(static_cast<int>(lon));
|
||||
SimpleLogger().Write(logDEBUG) << "broken lon: " << lon
|
||||
<< ", bits: " << x_coordinate_vector;
|
||||
}
|
||||
if (0 != (std::abs(static_cast<int>(lat)) >> 30))
|
||||
{
|
||||
std::bitset<32> y_coordinate_vector(static_cast<int>(lat));
|
||||
SimpleLogger().Write(logDEBUG) << "broken lat: " << lat
|
||||
<< ", bits: " << y_coordinate_vector;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Coordinate::IsValid() const
|
||||
|
||||
@@ -301,9 +301,26 @@ inline void pixelToDegree(const double shift, double &x, double &y)
|
||||
x = (x - b) / shift * 360.0;
|
||||
// FIXME needs to be simplified
|
||||
const double g = (y - b) / -(shift / (2 * M_PI)) / DEGREE_TO_RAD;
|
||||
static_assert(DEGREE_TO_RAD / (2 * M_PI) - 1/360. < 0.0001, "");
|
||||
y = static_cast<double>(util::coordinate_calculation::mercator::yToLat(g));
|
||||
}
|
||||
|
||||
double degreeToPixel(FloatLongitude lon, unsigned zoom)
|
||||
{
|
||||
const double shift = (1u << zoom) * TILE_SIZE;
|
||||
const double b = shift / 2.0;
|
||||
const double x = b * (1 + static_cast<double>(lon) / 180.0);
|
||||
return x;
|
||||
}
|
||||
|
||||
double degreeToPixel(FloatLatitude lat, unsigned zoom)
|
||||
{
|
||||
const double shift = (1u << zoom) * TILE_SIZE;
|
||||
const double b = shift / 2.0;
|
||||
const double y = b * (1. - latToY(lat) / 180.);
|
||||
return y;
|
||||
}
|
||||
|
||||
// Converts a WMS tile coordinate (z,x,y) into a wsg84 bounding box
|
||||
void xyzToWSG84(const int x, const int y, const int z, double &minx, double &miny, double &maxx, double &maxy)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user