diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-11-25 15:39:22 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-03-20 18:14:03 +0100 |
commit | ffd0e21baa5593e4719ecccd01be77173e47be3f (patch) | |
tree | 84a89ad53045faa6d39631add86d98f1814a21b4 | |
parent | 24198ebca86cbe1329a1854f080e3f4638973142 (diff) | |
download | qtlocation-mapboxgl-ffd0e21baa5593e4719ecccd01be77173e47be3f.tar.gz |
[core] Add minzoom to GeoJSONOptions
-rw-r--r-- | include/mbgl/style/conversion/geojson_options.hpp | 9 | ||||
-rw-r--r-- | include/mbgl/style/sources/geojson_source.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/style/sources/geojson_source_impl.cpp | 2 | ||||
-rw-r--r-- | test/style/conversion/geojson_options.test.cpp | 2 |
4 files changed, 13 insertions, 1 deletions
diff --git a/include/mbgl/style/conversion/geojson_options.hpp b/include/mbgl/style/conversion/geojson_options.hpp index 880090b402..df426ce98f 100644 --- a/include/mbgl/style/conversion/geojson_options.hpp +++ b/include/mbgl/style/conversion/geojson_options.hpp @@ -14,6 +14,15 @@ struct Converter<GeoJSONOptions> { Result<GeoJSONOptions> operator()(const V& value) const { GeoJSONOptions options; + const auto minzoomValue = objectMember(value, "minzoom"); + if (minzoomValue) { + if (toNumber(*minzoomValue)) { + options.minzoom = static_cast<uint8_t>(*toNumber(*minzoomValue)); + } else { + return Error{ "GeoJSON source minzoom value must be a number" }; + } + } + const auto maxzoomValue = objectMember(value, "maxzoom"); if (maxzoomValue) { if (toNumber(*maxzoomValue)) { diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index ede0301725..cff8a34644 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -26,6 +26,7 @@ using SuperclusterPointer = std::unique_ptr<mapbox::supercluster::Supercluster>; struct GeoJSONOptions { // GeoJSON-VT options + uint8_t minzoom = 0; uint8_t maxzoom = 18; uint16_t buffer = 128; double tolerance = 0.375; diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 5ceb4f71e0..d17e888885 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -155,7 +155,7 @@ void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) { Range<uint8_t> GeoJSONSource::Impl::getZoomRange() const { assert(loaded); - return { 0, options.maxzoom }; + return { options.minzoom, options.maxzoom }; } std::unique_ptr<Tile> GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID, diff --git a/test/style/conversion/geojson_options.test.cpp b/test/style/conversion/geojson_options.test.cpp index ddf261ea52..dc4d077c02 100644 --- a/test/style/conversion/geojson_options.test.cpp +++ b/test/style/conversion/geojson_options.test.cpp @@ -30,6 +30,7 @@ TEST(GeoJSONOptions, RetainsDefaults) { GeoJSONOptions defaults; // GeoJSON-VT + ASSERT_EQ(converted.minzoom, defaults.minzoom); ASSERT_EQ(converted.maxzoom, defaults.maxzoom); ASSERT_EQ(converted.buffer, defaults.buffer); ASSERT_EQ(converted.tolerance, defaults.tolerance); @@ -57,6 +58,7 @@ TEST(GeoJSONOptions, FullConversion) { GeoJSONOptions converted = *convert<GeoJSONOptions>(raw); // GeoJSON-VT + ASSERT_EQ(converted.minzoom, 0); ASSERT_EQ(converted.maxzoom, 1); ASSERT_EQ(converted.buffer, 2); ASSERT_EQ(converted.tolerance, 3); |