mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:17:35 +00:00
Maps: Add LatLngBounds struct
This commit is contained in:
parent
baf2121636
commit
2bdd39f198
2 changed files with 18 additions and 2 deletions
|
@ -47,8 +47,16 @@ static double nice_round_number(double number)
|
||||||
|
|
||||||
double MapWidget::LatLng::distance_to(LatLng const& other) const
|
double MapWidget::LatLng::distance_to(LatLng const& other) const
|
||||||
{
|
{
|
||||||
double const earth_radius = 6371000.0;
|
return EARTH_RADIUS * 2.0 * asin(sqrt(pow(sin((AK::to_radians(other.latitude) - AK::to_radians(latitude)) / 2.0), 2.0) + cos(AK::to_radians(latitude)) * cos(AK::to_radians(other.latitude)) * pow(sin((AK::to_radians(other.longitude) - AK::to_radians(longitude)) / 2.0), 2.0)));
|
||||||
return earth_radius * 2.0 * asin(sqrt(pow(sin((AK::to_radians(other.latitude) - AK::to_radians(latitude)) / 2.0), 2.0) + cos(AK::to_radians(latitude)) * cos(AK::to_radians(other.latitude)) * pow(sin((AK::to_radians(other.longitude) - AK::to_radians(longitude)) / 2.0), 2.0)));
|
}
|
||||||
|
|
||||||
|
int MapWidget::LatLngBounds::get_zoom() const
|
||||||
|
{
|
||||||
|
double distance_meters = north_west.distance_to(south_east);
|
||||||
|
int zoom = ZOOM_MIN;
|
||||||
|
while (distance_meters < EARTH_RADIUS / pow(2, zoom - 1) && zoom != ZOOM_MAX)
|
||||||
|
++zoom;
|
||||||
|
return min(zoom + 1, ZOOM_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MapWidget class
|
// MapWidget class
|
||||||
|
|
|
@ -27,6 +27,13 @@ public:
|
||||||
double distance_to(LatLng const& other) const;
|
double distance_to(LatLng const& other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct LatLngBounds {
|
||||||
|
LatLng north_west;
|
||||||
|
LatLng south_east;
|
||||||
|
|
||||||
|
int get_zoom() const;
|
||||||
|
};
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
Optional<String> tile_provider {};
|
Optional<String> tile_provider {};
|
||||||
LatLng center;
|
LatLng center;
|
||||||
|
@ -141,6 +148,7 @@ private:
|
||||||
|
|
||||||
static int constexpr TILE_SIZE = 256;
|
static int constexpr TILE_SIZE = 256;
|
||||||
static double constexpr LATITUDE_MAX = 85.0511287798066;
|
static double constexpr LATITUDE_MAX = 85.0511287798066;
|
||||||
|
static int constexpr EARTH_RADIUS = 6371000.0;
|
||||||
static size_t constexpr TILES_CACHE_MAX = 256;
|
static size_t constexpr TILES_CACHE_MAX = 256;
|
||||||
static constexpr size_t TILES_DOWNLOAD_PARALLEL_MAX = 8;
|
static constexpr size_t TILES_DOWNLOAD_PARALLEL_MAX = 8;
|
||||||
static int constexpr ZOOM_MIN = 2;
|
static int constexpr ZOOM_MIN = 2;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue