From 24198ebca86cbe1329a1854f080e3f4638973142 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Mon, 20 Mar 2017 17:32:06 +0200 Subject: [PATCH] [core] Expose Source::getZoomRange --- include/mbgl/style/source.hpp | 5 +++- src/mbgl/annotation/annotation_source.cpp | 2 +- src/mbgl/annotation/annotation_source.hpp | 2 +- src/mbgl/style/source.cpp | 6 ++++- src/mbgl/style/source_impl.hpp | 2 +- .../style/sources/geojson_source_impl.cpp | 2 +- .../style/sources/geojson_source_impl.hpp | 3 ++- src/mbgl/style/tile_source_impl.cpp | 2 +- src/mbgl/style/tile_source_impl.hpp | 4 ++-- test/style/source.test.cpp | 24 +++++++++++++++++++ 10 files changed, 42 insertions(+), 10 deletions(-) diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp index 0901bb195..262fc3010 100644 --- a/include/mbgl/style/source.hpp +++ b/include/mbgl/style/source.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,9 @@ public: std::unique_ptr copy(const std::string& id) const; optional getAttribution() const; - + + Range getZoomRange() const; + std::vector querySourceFeatures(const SourceQueryOptions& options = {}); // Private implementation diff --git a/src/mbgl/annotation/annotation_source.cpp b/src/mbgl/annotation/annotation_source.cpp index a9db9ad8a..7434029c4 100644 --- a/src/mbgl/annotation/annotation_source.cpp +++ b/src/mbgl/annotation/annotation_source.cpp @@ -14,7 +14,7 @@ AnnotationSource::Impl::Impl(Source& base_) : Source::Impl(SourceType::Annotations, AnnotationManager::SourceID, base_) { } -Range AnnotationSource::Impl::getZoomRange() { +Range AnnotationSource::Impl::getZoomRange() const { return { 0, 22 }; } diff --git a/src/mbgl/annotation/annotation_source.hpp b/src/mbgl/annotation/annotation_source.hpp index d995222f3..62d1aa348 100644 --- a/src/mbgl/annotation/annotation_source.hpp +++ b/src/mbgl/annotation/annotation_source.hpp @@ -20,7 +20,7 @@ public: private: uint16_t getTileSize() const final { return util::tileSize; } - Range getZoomRange() final; + Range getZoomRange() const final; std::unique_ptr createTile(const OverscaledTileID&, const style::UpdateParameters&) final; }; diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp index 25c06024d..9ef245ac3 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source.cpp @@ -17,7 +17,11 @@ const std::string& Source::getID() const { optional Source::getAttribution() const { return baseImpl->getAttribution(); } - + +Range Source::getZoomRange() const { + return baseImpl->getZoomRange(); +} + std::vector Source::querySourceFeatures(const SourceQueryOptions& options) { return baseImpl->querySourceFeatures(options); } diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index b9707edaa..fbec2b0eb 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -83,6 +83,7 @@ public: const std::string id; virtual optional getAttribution() const { return {}; }; + virtual Range getZoomRange() const = 0; bool loaded = false; @@ -109,7 +110,6 @@ private: void onTileError(Tile&, std::exception_ptr) override; virtual uint16_t getTileSize() const = 0; - virtual Range getZoomRange() = 0; virtual std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) = 0; std::map renderTiles; diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index c7c375307..5ceb4f71e 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -153,7 +153,7 @@ void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) { }); } -Range GeoJSONSource::Impl::getZoomRange() { +Range GeoJSONSource::Impl::getZoomRange() const { assert(loaded); return { 0, options.maxzoom }; } diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp index eec7cf060..05302d6bc 100644 --- a/src/mbgl/style/sources/geojson_source_impl.hpp +++ b/src/mbgl/style/sources/geojson_source_impl.hpp @@ -28,10 +28,11 @@ public: return util::tileSize; } + Range getZoomRange() const final; + private: void _setGeoJSON(const GeoJSON&); - Range getZoomRange() final; std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; GeoJSONOptions options; diff --git a/src/mbgl/style/tile_source_impl.cpp b/src/mbgl/style/tile_source_impl.cpp index bda602bb5..44a25a8bf 100644 --- a/src/mbgl/style/tile_source_impl.cpp +++ b/src/mbgl/style/tile_source_impl.cpp @@ -113,7 +113,7 @@ void TileSourceImpl::loadDescription(FileSource& fileSource) { }); } -Range TileSourceImpl::getZoomRange() { +Range TileSourceImpl::getZoomRange() const { assert(loaded); return tileset.zoomRange; } diff --git a/src/mbgl/style/tile_source_impl.hpp b/src/mbgl/style/tile_source_impl.hpp index 2b17872d2..1fda3b376 100644 --- a/src/mbgl/style/tile_source_impl.hpp +++ b/src/mbgl/style/tile_source_impl.hpp @@ -36,9 +36,9 @@ public: optional getAttribution() const override; -protected: - Range getZoomRange() final; + Range getZoomRange() const final; +protected: const variant urlOrTileset; const uint16_t tileSize; diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index fb7737e41..feb7b6b05 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -65,6 +66,29 @@ public: } }; +TEST(Source, DefaultZoomRange) { + VectorSource vectorSource("vectorSource", "url"); + vectorSource.baseImpl->loaded = true; + EXPECT_EQ(vectorSource.getZoomRange().min, 0u); + EXPECT_EQ(vectorSource.getZoomRange().max, 22u); + + GeoJSONSource geojsonSource("source"); + geojsonSource.baseImpl->loaded = true; + EXPECT_EQ(geojsonSource.getZoomRange().min, 0u); + EXPECT_EQ(geojsonSource.getZoomRange().max, 18u); + + Tileset tileset; + RasterSource rasterSource("source", tileset, 512); + rasterSource.baseImpl->loaded = true; + EXPECT_EQ(rasterSource.getZoomRange().min, 0u); + EXPECT_EQ(rasterSource.getZoomRange().max, 22u); + EXPECT_EQ(rasterSource.getZoomRange(), tileset.zoomRange); + + AnnotationSource annotationSource; + EXPECT_EQ(annotationSource.getZoomRange().min, 0u); + EXPECT_EQ(annotationSource.getZoomRange().max, 22u); +} + TEST(Source, LoadingFail) { SourceTest test;