diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-09-08 13:49:48 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2017-09-28 15:47:21 -0700 |
commit | 8fae8a16452a5ae17f424d1720a0aea75d0ac33a (patch) | |
tree | eba9051d4f5c9d7ebacbf608a4183ee151c10a92 | |
parent | 64c75b442c4d387e4867757abf49462c561e5955 (diff) | |
download | qtlocation-mapboxgl-8fae8a16452a5ae17f424d1720a0aea75d0ac33a.tar.gz |
[core] Add minzoom to GeoJSONOptions
-rw-r--r-- | include/mbgl/style/conversion/geojson_options.hpp | 10 | ||||
-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, 14 insertions, 1 deletions
diff --git a/include/mbgl/style/conversion/geojson_options.hpp b/include/mbgl/style/conversion/geojson_options.hpp index 19383d90ce..1c9c18250c 100644 --- a/include/mbgl/style/conversion/geojson_options.hpp +++ b/include/mbgl/style/conversion/geojson_options.hpp @@ -14,6 +14,16 @@ struct Converter<GeoJSONOptions> { optional<GeoJSONOptions> operator()(const V& value, Error& error) const { GeoJSONOptions options; + const auto minzoomValue = objectMember(value, "minzoom"); + if (minzoomValue) { + if (toNumber(*minzoomValue)) { + options.minzoom = static_cast<uint8_t>(*toNumber(*minzoomValue)); + } else { + error = { "GeoJSON source minzoom value must be a number" }; + return {}; + } + } + 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 2dcfec51aa..5bdf1ef957 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -12,6 +12,7 @@ namespace style { 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 efa4018b46..fd6d7d3013 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -71,7 +71,7 @@ GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON) GeoJSONSource::Impl::~Impl() = default; Range<uint8_t> GeoJSONSource::Impl::getZoomRange() const { - return { 0, options.maxzoom }; + return { options.minzoom, options.maxzoom }; } GeoJSONData* GeoJSONSource::Impl::getData() const { diff --git a/test/style/conversion/geojson_options.test.cpp b/test/style/conversion/geojson_options.test.cpp index e6bd984f36..a798ad6559 100644 --- a/test/style/conversion/geojson_options.test.cpp +++ b/test/style/conversion/geojson_options.test.cpp @@ -33,6 +33,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); @@ -61,6 +62,7 @@ TEST(GeoJSONOptions, FullConversion) { GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error); // GeoJSON-VT + ASSERT_EQ(converted.minzoom, 0); ASSERT_EQ(converted.maxzoom, 1); ASSERT_EQ(converted.buffer, 2); ASSERT_EQ(converted.tolerance, 3); |