diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2018-01-05 06:35:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-05 06:35:31 -0800 |
commit | 10a44050f485a18f8dd6523aca6a7a9f82f7afc7 (patch) | |
tree | fea7f30e35b3228b5989250ff9db225e12bd10ed /include | |
parent | bfa4cea24c2ab3973f845fda6da6d4a9e8f03e56 (diff) | |
download | qtlocation-mapboxgl-10a44050f485a18f8dd6523aca6a7a9f82f7afc7.tar.gz |
Support TileJSON bounds property (#10701)
* [core] Parse TileJSON bounds property
* [core] Add TileRange and LatLngBounds::contains(CanonicalTileID)
Move LatLngBounds::contains impl to cpp file
* [core] Skip tile creation outside of tileset bounds
* [core] Fix TileRange for wrapped bounds and use for CustomTileLoader instead of LatLngBounds comparisons for tiles.
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/util/geo.hpp | 78 | ||||
-rw-r--r-- | include/mbgl/util/projection.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/util/tileset.hpp | 13 |
3 files changed, 16 insertions, 79 deletions
diff --git a/include/mbgl/util/geo.hpp b/include/mbgl/util/geo.hpp index 60043ee156..dacdb968f3 100644 --- a/include/mbgl/util/geo.hpp +++ b/include/mbgl/util/geo.hpp @@ -158,81 +158,11 @@ public: return (sw.wrapped().longitude() > ne.wrapped().longitude()); } - bool contains(const LatLng& point, LatLng::WrapMode wrap = LatLng::Unwrapped) const { - bool containsLatitude = point.latitude() >= sw.latitude() && - point.latitude() <= ne.latitude(); - if (!containsLatitude) { - return false; - } - - bool containsUnwrappedLongitude = point.longitude() >= sw.longitude() && - point.longitude() <= ne.longitude(); - if (containsUnwrappedLongitude) { - return true; - } else if (wrap == LatLng::Wrapped) { - LatLngBounds wrapped(sw.wrapped(), ne.wrapped()); - auto ptLon = point.wrapped().longitude(); - if (crossesAntimeridian()) { - return (ptLon >= wrapped.sw.longitude() && - ptLon <= util::LONGITUDE_MAX) || - (ptLon <= wrapped.ne.longitude() && - ptLon >= -util::LONGITUDE_MAX); - } else { - return (ptLon >= wrapped.sw.longitude() && - ptLon <= wrapped.ne.longitude()); - } - } - return false; - } + bool contains(const CanonicalTileID& tileID) const; + bool contains(const LatLng& point, LatLng::WrapMode wrap = LatLng::Unwrapped) const; + bool contains(const LatLngBounds& area, LatLng::WrapMode wrap = LatLng::Unwrapped) const; - bool contains(const LatLngBounds& area, LatLng::WrapMode wrap = LatLng::Unwrapped) const { - bool containsLatitude = area.north() <= north() && area.south() >= south(); - if (!containsLatitude) { - return false; - } - - bool containsUnwrapped = area.east() <= east() && area.west() >= west(); - if(containsUnwrapped) { - return true; - } else if (wrap == LatLng::Wrapped) { - LatLngBounds wrapped(sw.wrapped(), ne.wrapped()); - LatLngBounds other(area.sw.wrapped(), area.ne.wrapped()); - if (crossesAntimeridian() & !area.crossesAntimeridian()) { - return (other.east() <= util::LONGITUDE_MAX && other.west() >= wrapped.west()) || - (other.east() <= wrapped.east() && other.west() >= -util::LONGITUDE_MAX); - } else { - return other.east() <= wrapped.east() && other.west() >= wrapped.west(); - } - } - return false; - } - - bool intersects(const LatLngBounds area, LatLng::WrapMode wrap = LatLng::Unwrapped) const { - bool latitudeIntersects = area.north() > south() && area.south() < north(); - if (!latitudeIntersects) { - return false; - } - - bool longitudeIntersects = area.east() > west() && area.west() < east(); - if (longitudeIntersects) { - return true; - } else if (wrap == LatLng::Wrapped) { - LatLngBounds wrapped(sw.wrapped(), ne.wrapped()); - LatLngBounds other(area.sw.wrapped(), area.ne.wrapped()); - if (crossesAntimeridian()) { - return area.crossesAntimeridian() || - other.east() > wrapped.west() || - other.west() < wrapped.east(); - } else if (other.crossesAntimeridian()){ - return other.east() > wrapped.west() || - other.west() < wrapped.east(); - } else { - return other.east() > wrapped.west() && - other.west() < wrapped.east(); - } - } - return false; - } + bool intersects(const LatLngBounds area, LatLng::WrapMode wrap = LatLng::Unwrapped) const; private: LatLng sw; diff --git a/include/mbgl/util/projection.hpp b/include/mbgl/util/projection.hpp index 1613af3b36..b4a34521a4 100644 --- a/include/mbgl/util/projection.hpp +++ b/include/mbgl/util/projection.hpp @@ -78,6 +78,10 @@ public: return project_(latLng, worldSize(scale)); } + static Point<double> project(const LatLng& latLng, uint8_t zoom) { + return project_(latLng, std::pow(2.0, zoom)); + } + static LatLng unproject(const Point<double>& p, double scale, LatLng::WrapMode wrapMode = LatLng::Unwrapped) { auto p2 = p * util::DEGREES_MAX / worldSize(scale); return LatLng { diff --git a/include/mbgl/util/tileset.hpp b/include/mbgl/util/tileset.hpp index 5a03e1a9da..7bef0e89ed 100644 --- a/include/mbgl/util/tileset.hpp +++ b/include/mbgl/util/tileset.hpp @@ -2,7 +2,8 @@ #include <mbgl/util/range.hpp> #include <mbgl/util/constants.hpp> - +#include <mbgl/util/optional.hpp> +#include <mbgl/util/geo.hpp> #include <tuple> #include <vector> #include <string> @@ -18,6 +19,7 @@ public: Range<uint8_t> zoomRange; std::string attribution; Scheme scheme; + optional<LatLngBounds> bounds; Tileset(std::vector<std::string> tiles_ = std::vector<std::string>(), Range<uint8_t> zoomRange_ = { 0, util::DEFAULT_MAX_ZOOM }, @@ -26,13 +28,14 @@ public: : tiles(std::move(tiles_)), zoomRange(std::move(zoomRange_)), attribution(std::move(attribution_)), - scheme(scheme_) {} + scheme(scheme_), + bounds() {} - // TileJSON also includes center, zoom, and bounds, but they are not used by mbgl. + // TileJSON also includes center and zoom but they are not used by mbgl. friend bool operator==(const Tileset& lhs, const Tileset& rhs) { - return std::tie(lhs.tiles, lhs.zoomRange, lhs.attribution, lhs.scheme) - == std::tie(rhs.tiles, rhs.zoomRange, rhs.attribution, rhs.scheme); + return std::tie(lhs.tiles, lhs.zoomRange, lhs.attribution, lhs.scheme, lhs.bounds) + == std::tie(rhs.tiles, rhs.zoomRange, rhs.attribution, rhs.scheme, rhs.bounds); } }; |