summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzmiao <zmiao.jamie@gmail.com>2019-09-06 21:54:19 +0300
committerzmiao <zmiao.jamie@gmail.com>2019-09-17 14:24:30 +0300
commit44f45fbfd9eb26c378cb83ed1baac192aefcde06 (patch)
tree634b63b75c9dcfbc7e369a0d253af2759c7e44e0
parent5254876b39f0f25e727db18e516f1de81679fb41 (diff)
downloadqtlocation-mapboxgl-44f45fbfd9eb26c378cb83ed1baac192aefcde06.tar.gz
[core] Take max/min zoom option from style if they are set
-rw-r--r--include/mbgl/style/sources/vector_source.hpp4
-rw-r--r--src/mbgl/style/conversion/source.cpp21
-rw-r--r--src/mbgl/style/sources/vector_source.cpp9
3 files changed, 28 insertions, 6 deletions
diff --git a/include/mbgl/style/sources/vector_source.hpp b/include/mbgl/style/sources/vector_source.hpp
index ece7f5615a..3fb2e592fa 100644
--- a/include/mbgl/style/sources/vector_source.hpp
+++ b/include/mbgl/style/sources/vector_source.hpp
@@ -12,7 +12,7 @@ namespace style {
class VectorSource final : public Source {
public:
- VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset);
+ VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset, optional<float> maxZoom = nullopt, optional<float> minZoom = nullopt);
~VectorSource() final;
const variant<std::string, Tileset>& getURLOrTileset() const;
@@ -31,6 +31,8 @@ private:
const variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;
mapbox::base::WeakPtrFactory<Source> weakFactory {this};
+ optional<float> maxZoom;
+ optional<float> minZoom;
};
template <>
diff --git a/src/mbgl/style/conversion/source.cpp b/src/mbgl/style/conversion/source.cpp
index 5ecbd3b474..9e926953c2 100644
--- a/src/mbgl/style/conversion/source.cpp
+++ b/src/mbgl/style/conversion/source.cpp
@@ -86,8 +86,25 @@ static optional<std::unique_ptr<Source>> convertVectorSource(const std::string&
if (!urlOrTileset) {
return nullopt;
}
-
- return { std::make_unique<VectorSource>(id, std::move(*urlOrTileset)) };
+ auto maxzoomValue = objectMember(value, "maxzoom");
+ optional<float> maxzoom;
+ if (maxzoomValue) {
+ maxzoom = toNumber(*maxzoomValue);
+ if (!maxzoom || *maxzoom < 0 || *maxzoom > std::numeric_limits<uint8_t>::max()) {
+ error.message = "invalid maxzoom";
+ return nullopt;
+ }
+ }
+ auto minzoomValue = objectMember(value, "minzoom");
+ optional<float> minzoom;
+ if (minzoomValue) {
+ minzoom = toNumber(*minzoomValue);
+ if (!minzoom || *minzoom < 0 || *minzoom > std::numeric_limits<uint8_t>::max()) {
+ error.message = "invalid minzoom";
+ return nullopt;
+ }
+ }
+ return { std::make_unique<VectorSource>(id, std::move(*urlOrTileset), maxzoom, minzoom) };
}
static optional<std::unique_ptr<Source>> convertGeoJSONSource(const std::string& id,
diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp
index f103a7768f..5b5196ea2c 100644
--- a/src/mbgl/style/sources/vector_source.cpp
+++ b/src/mbgl/style/sources/vector_source.cpp
@@ -11,9 +11,11 @@
namespace mbgl {
namespace style {
-VectorSource::VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset_)
+VectorSource::VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset_, optional<float> maxZoom_, optional<float> minZoom_)
: Source(makeMutable<Impl>(std::move(id))),
- urlOrTileset(std::move(urlOrTileset_)) {
+ urlOrTileset(std::move(urlOrTileset_)),
+ maxZoom(maxZoom_),
+ minZoom(minZoom_) {
}
VectorSource::~VectorSource() = default;
@@ -61,7 +63,8 @@ void VectorSource::loadDescription(FileSource& fileSource) {
observer->onSourceError(*this, std::make_exception_ptr(util::StyleParseException(error.message)));
return;
}
-
+ if (maxZoom) tileset->zoomRange.max = *maxZoom;
+ if (minZoom) tileset->zoomRange.min = *minZoom;
util::mapbox::canonicalizeTileset(*tileset, url, getType(), util::tileSize);
bool changed = impl().tileset != *tileset;