From 1f8910de186f35216791a17a683a55f01031ec81 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Tue, 21 Mar 2017 16:28:11 +0200 Subject: Make Source::getZoomRange return an optional range --- include/mbgl/style/source.hpp | 3 +-- src/mbgl/annotation/annotation_source.cpp | 4 ++-- src/mbgl/annotation/annotation_source.hpp | 3 ++- src/mbgl/style/source.cpp | 2 +- src/mbgl/style/source_impl.cpp | 8 ++++---- src/mbgl/style/source_impl.hpp | 2 +- src/mbgl/style/sources/geojson_source_impl.cpp | 8 +++++--- src/mbgl/style/sources/geojson_source_impl.hpp | 2 +- src/mbgl/style/tile_source_impl.cpp | 8 +++++--- src/mbgl/style/tile_source_impl.hpp | 3 +-- test/style/source.test.cpp | 25 ++++++++++++++++--------- 11 files changed, 39 insertions(+), 29 deletions(-) diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp index 262fc3010c..0e6e32b112 100644 --- a/include/mbgl/style/source.hpp +++ b/include/mbgl/style/source.hpp @@ -56,8 +56,7 @@ public: std::unique_ptr copy(const std::string& id) const; optional getAttribution() const; - - Range getZoomRange() const; + optional> getZoomRange() const; std::vector querySourceFeatures(const SourceQueryOptions& options = {}); diff --git a/src/mbgl/annotation/annotation_source.cpp b/src/mbgl/annotation/annotation_source.cpp index 7434029c4b..c52836c500 100644 --- a/src/mbgl/annotation/annotation_source.cpp +++ b/src/mbgl/annotation/annotation_source.cpp @@ -14,8 +14,8 @@ AnnotationSource::Impl::Impl(Source& base_) : Source::Impl(SourceType::Annotations, AnnotationManager::SourceID, base_) { } -Range AnnotationSource::Impl::getZoomRange() const { - return { 0, 22 }; +optional> AnnotationSource::Impl::getZoomRange() const { + return { { 0, 22 } }; } void AnnotationSource::Impl::loadDescription(FileSource&) { diff --git a/src/mbgl/annotation/annotation_source.hpp b/src/mbgl/annotation/annotation_source.hpp index 62d1aa3488..07e00dc52d 100644 --- a/src/mbgl/annotation/annotation_source.hpp +++ b/src/mbgl/annotation/annotation_source.hpp @@ -18,9 +18,10 @@ public: void loadDescription(FileSource&) final; + optional> getZoomRange() const final; + private: uint16_t getTileSize() const final { return util::tileSize; } - 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 9ef245ac34..f10fc6916b 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source.cpp @@ -18,7 +18,7 @@ optional Source::getAttribution() const { return baseImpl->getAttribution(); } -Range Source::getZoomRange() const { +optional> Source::getZoomRange() const { return baseImpl->getZoomRange(); } diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index 1f8301629f..356d420e19 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -91,15 +91,15 @@ void Source::Impl::updateTiles(const UpdateParameters& parameters) { } const uint16_t tileSize = getTileSize(); - const Range zoomRange = getZoomRange(); + const optional> zoomRange = getZoomRange(); // Determine the overzooming/underzooming amounts and required tiles. int32_t overscaledZoom = util::coveringZoomLevel(parameters.transformState.getZoom(), type, tileSize); int32_t tileZoom = overscaledZoom; std::vector idealTiles; - if (overscaledZoom >= zoomRange.min) { - int32_t idealZoom = std::min(zoomRange.max, overscaledZoom); + if (overscaledZoom >= zoomRange->min) { + int32_t idealZoom = std::min(zoomRange->max, overscaledZoom); // Make sure we're not reparsing overzoomed raster tiles. if (type == SourceType::Raster) { @@ -142,7 +142,7 @@ void Source::Impl::updateTiles(const UpdateParameters& parameters) { renderTiles.clear(); algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn, renderTileFn, - idealTiles, zoomRange, tileZoom); + idealTiles, *zoomRange, tileZoom); if (type != SourceType::Annotations) { size_t conservativeCacheSize = diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index fbec2b0eba..b4941dc638 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -83,7 +83,7 @@ public: const std::string id; virtual optional getAttribution() const { return {}; }; - virtual Range getZoomRange() const = 0; + virtual optional> getZoomRange() const = 0; bool loaded = false; diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 5ceb4f71e0..b050e5482e 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -153,9 +153,11 @@ void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) { }); } -Range GeoJSONSource::Impl::getZoomRange() const { - assert(loaded); - return { 0, options.maxzoom }; +optional> GeoJSONSource::Impl::getZoomRange() const { + if (loaded) { + return { { 0, options.maxzoom }}; + } + return {}; } std::unique_ptr GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID, diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp index 05302d6bc0..b827a0b26c 100644 --- a/src/mbgl/style/sources/geojson_source_impl.hpp +++ b/src/mbgl/style/sources/geojson_source_impl.hpp @@ -28,7 +28,7 @@ public: return util::tileSize; } - Range getZoomRange() const final; + optional> getZoomRange() const final; private: void _setGeoJSON(const GeoJSON&); diff --git a/src/mbgl/style/tile_source_impl.cpp b/src/mbgl/style/tile_source_impl.cpp index 44fb01b0ee..daa6389a8e 100644 --- a/src/mbgl/style/tile_source_impl.cpp +++ b/src/mbgl/style/tile_source_impl.cpp @@ -113,9 +113,11 @@ void TileSourceImpl::loadDescription(FileSource& fileSource) { }); } -Range TileSourceImpl::getZoomRange() const { - assert(loaded); - return tileset.zoomRange; +optional> TileSourceImpl::getZoomRange() const { + if (loaded) { + return tileset.zoomRange; + } + return {}; } optional TileSourceImpl::getAttribution() const { diff --git a/src/mbgl/style/tile_source_impl.hpp b/src/mbgl/style/tile_source_impl.hpp index 1fda3b3769..2993caf20a 100644 --- a/src/mbgl/style/tile_source_impl.hpp +++ b/src/mbgl/style/tile_source_impl.hpp @@ -35,8 +35,7 @@ public: } optional getAttribution() const override; - - Range getZoomRange() const final; + optional> getZoomRange() const final; protected: const variant urlOrTileset; diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index 6bb18d188b..f637f1ccde 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -23,6 +25,8 @@ #include +#include + using namespace mbgl; class SourceTest { @@ -68,25 +72,28 @@ public: TEST(Source, DefaultZoomRange) { VectorSource vectorSource("vectorSource", "url"); + EXPECT_FALSE(vectorSource.getZoomRange()); vectorSource.baseImpl->loaded = true; - EXPECT_EQ(vectorSource.getZoomRange().min, 0u); - EXPECT_EQ(vectorSource.getZoomRange().max, 22u); + EXPECT_EQ(vectorSource.getZoomRange()->min, 0u); + EXPECT_EQ(vectorSource.getZoomRange()->max, 22u); GeoJSONSource geojsonSource("source"); + EXPECT_FALSE(geojsonSource.getZoomRange()); geojsonSource.baseImpl->loaded = true; - EXPECT_EQ(geojsonSource.getZoomRange().min, 0u); - EXPECT_EQ(geojsonSource.getZoomRange().max, 18u); + EXPECT_EQ(geojsonSource.getZoomRange()->min, 0u); + EXPECT_EQ(geojsonSource.getZoomRange()->max, 18u); Tileset tileset; RasterSource rasterSource("source", tileset, 512); + EXPECT_FALSE(rasterSource.getZoomRange()); rasterSource.baseImpl->loaded = true; - EXPECT_EQ(rasterSource.getZoomRange().min, 0u); - EXPECT_EQ(rasterSource.getZoomRange().max, 22u); - EXPECT_EQ(rasterSource.getZoomRange(), tileset.zoomRange); + 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); + EXPECT_EQ(annotationSource.getZoomRange()->min, 0u); + EXPECT_EQ(annotationSource.getZoomRange()->max, 22u); } TEST(Source, LoadingFail) { -- cgit v1.2.1