From 0a219d182c422e181b29c9dcc60c18ceafe1db48 Mon Sep 17 00:00:00 2001 From: zmiao Date: Tue, 17 Sep 2019 18:00:37 +0300 Subject: [PATCH] [Core] Fix wrong `maxzoom` setting of tileSet when using URL source (#15581) * [core] Take max/min zoom option from style if they are set * [core] std::move input value * [Core] Add changelogs * [Core] Fix clang-format reported error * [Core] fix clang-tidy reported error --- include/mbgl/style/sources/vector_source.hpp | 5 ++++- platform/android/CHANGELOG.md | 1 + platform/ios/CHANGELOG.md | 1 + platform/macos/CHANGELOG.md | 1 + platform/node/CHANGELOG.md | 1 + src/mbgl/style/conversion/source.cpp | 21 ++++++++++++++++++-- src/mbgl/style/sources/vector_source.cpp | 15 ++++++++++---- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/include/mbgl/style/sources/vector_source.hpp b/include/mbgl/style/sources/vector_source.hpp index ece7f5615..97f0a7e5a 100644 --- a/include/mbgl/style/sources/vector_source.hpp +++ b/include/mbgl/style/sources/vector_source.hpp @@ -12,7 +12,8 @@ namespace style { class VectorSource final : public Source { public: - VectorSource(std::string id, variant urlOrTileset); + VectorSource(std::string id, variant urlOrTileset, optional maxZoom = nullopt, + optional minZoom = nullopt); ~VectorSource() final; const variant& getURLOrTileset() const; @@ -31,6 +32,8 @@ private: const variant urlOrTileset; std::unique_ptr req; mapbox::base::WeakPtrFactory weakFactory {this}; + optional maxZoom; + optional minZoom; }; template <> diff --git a/platform/android/CHANGELOG.md b/platform/android/CHANGELOG.md index a7fd332b6..734647e4c 100644 --- a/platform/android/CHANGELOG.md +++ b/platform/android/CHANGELOG.md @@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to ### Bug fixes - Fixed constant repainting for the sources with invisible layers, caused by `RenderSource::hasFadingTiles()` returning `true` all the time. [#15600](https://github.com/mapbox/mapbox-gl-native/pull/15600) - Fixed an issue that caused the state of CompassView not up to date when `UiSettings.setCompassEnabled()` is set to true. [#15606](https://github.com/mapbox/mapbox-gl-native/pull/15606) + - Fixed an issue that `maxzoom` in style `Sources` option was ignored when URL resource is provided. It may cause problems such as extra tiles downloading at higher zoom level than `maxzoom`, or problems that wrong setting of `overscaledZ` in `OverscaledTileID` that will be passed to `SymbolLayout`, leading wrong rendering appearance. [#15581](https://github.com/mapbox/mapbox-gl-native/pull/15581) ## 8.4.0-alpha.2 - September 11, 2019 [Changes](https://github.com/mapbox/mapbox-gl-native/compare/android-v8.4.0-alpha.1...android-v8.4.0-alpha.2) since [Mapbox Maps SDK for Android v8.4.0-alpha.1](https://github.com/mapbox/mapbox-gl-native/releases/tag/android-v8.4.0-alpha.1): diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 8515fd467..f2394d1b8 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### Styles and rendering * Added an `-[MGLMapSnapshotter startWithOverlayHandler:completionHandler:]` method to provide the snapshot's current `CGContext` in order to perform custom drawing on `MGLMapSnapShot` objects. ([#15530](https://github.com/mapbox/mapbox-gl-native/pull/15530)) +* Fixed an issue that `maxzoom` in style `Sources` option was ignored when URL resource is provided. It may cause problems such as extra tiles downloading at higher zoom level than `maxzoom`, or problems that wrong setting of `overscaledZ` in `OverscaledTileID` that will be passed to `SymbolLayout`, leading wrong rendering appearance. ([#15581](https://github.com/mapbox/mapbox-gl-native/pull/15581)) ### Performance improvements diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index da9a179ad..888d4c526 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -18,6 +18,7 @@ * Fixed a rendering issue of `collisionBox` when `text-translate` or `icon-translate` is enabled. ([#15467](https://github.com/mapbox/mapbox-gl-native/pull/15467)) * Fixed an issue of integer overflow when converting `tileCoordinates` to `LatLon`, which caused issues such as `queryRenderedFeatures` and `querySourceFeatures` returning incorrect coordinates at zoom levels 20 and higher. ([#15560](https://github.com/mapbox/mapbox-gl-native/pull/15560)) * Added an `-[MGLMapSnapshotter startWithOverlayHandler:completionHandler:]` method to provide the snapshot's current `CGContext` in order to perform custom drawing on `MGLMapSnapShot` objects. ([#15530](https://github.com/mapbox/mapbox-gl-native/pull/15530)) +* Fixed an issue that `maxzoom` in style `Sources` option was ignored when URL resource is provided. It may cause problems such as extra tiles downloading at higher zoom level than `maxzoom`, or problems that wrong setting of `overscaledZ` in `OverscaledTileID` that will be passed to `SymbolLayout`, leading wrong rendering appearance. ([#15581](https://github.com/mapbox/mapbox-gl-native/pull/15581)) ### Styles and rendering diff --git a/platform/node/CHANGELOG.md b/platform/node/CHANGELOG.md index 519f30aaa..486dd44e1 100644 --- a/platform/node/CHANGELOG.md +++ b/platform/node/CHANGELOG.md @@ -5,6 +5,7 @@ * Fixed a rendering issue of `collisionBox` when `text-translate` or `icon-translate` is enabled. ([#15467](https://github.com/mapbox/mapbox-gl-native/pull/15467)) * Fixed an issue of integer overflow when converting `tileCoordinates` to `LatLon`, which caused issues such as `queryRenderedFeatures` and `querySourceFeatures` returning incorrect coordinates at zoom levels 20 and higher. ([#15560](https://github.com/mapbox/mapbox-gl-native/pull/15560)) * Add typechecking while constructing legacy filter to prevent converting an unexpected filter type [#15389](https://github.com/mapbox/mapbox-gl-native/pull/15389). +* Fixed an issue that `maxzoom` in style `Sources` option was ignored when URL resource is provided. It may cause problems such as extra tiles downloading at higher zoom level than `maxzoom`, or problems that wrong setting of `overscaledZ` in `OverscaledTileID` that will be passed to `SymbolLayout`, leading wrong rendering appearance. ([#15581](https://github.com/mapbox/mapbox-gl-native/pull/15581)) # 4.2.0 - Add an option to set whether or not an image should be treated as a SDF ([#15054](https://github.com/mapbox/mapbox-gl-native/issues/15054)) diff --git a/src/mbgl/style/conversion/source.cpp b/src/mbgl/style/conversion/source.cpp index 5ecbd3b47..de41adc89 100644 --- a/src/mbgl/style/conversion/source.cpp +++ b/src/mbgl/style/conversion/source.cpp @@ -86,8 +86,25 @@ static optional> convertVectorSource(const std::string& if (!urlOrTileset) { return nullopt; } - - return { std::make_unique(id, std::move(*urlOrTileset)) }; + auto maxzoomValue = objectMember(value, "maxzoom"); + optional maxzoom; + if (maxzoomValue) { + maxzoom = toNumber(*maxzoomValue); + if (!maxzoom || *maxzoom < 0 || *maxzoom > std::numeric_limits::max()) { + error.message = "invalid maxzoom"; + return nullopt; + } + } + auto minzoomValue = objectMember(value, "minzoom"); + optional minzoom; + if (minzoomValue) { + minzoom = toNumber(*minzoomValue); + if (!minzoom || *minzoom < 0 || *minzoom > std::numeric_limits::max()) { + error.message = "invalid minzoom"; + return nullopt; + } + } + return {std::make_unique(id, std::move(*urlOrTileset), std::move(maxzoom), std::move(minzoom))}; } static optional> convertGeoJSONSource(const std::string& id, diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp index f103a7768..a69ff632d 100644 --- a/src/mbgl/style/sources/vector_source.cpp +++ b/src/mbgl/style/sources/vector_source.cpp @@ -11,10 +11,12 @@ namespace mbgl { namespace style { -VectorSource::VectorSource(std::string id, variant urlOrTileset_) +VectorSource::VectorSource(std::string id, variant urlOrTileset_, optional maxZoom_, + optional minZoom_) : Source(makeMutable(std::move(id))), - urlOrTileset(std::move(urlOrTileset_)) { -} + urlOrTileset(std::move(urlOrTileset_)), + maxZoom(std::move(maxZoom_)), + minZoom(std::move(minZoom_)) {} VectorSource::~VectorSource() = default; @@ -61,7 +63,12 @@ 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;