diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-05-08 14:47:51 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2020-05-26 20:35:04 +0300 |
commit | 1237e91a16d6b22df88c3fa25f3bc29b7734f88e (patch) | |
tree | 7fed4540b2e87d6899f52c821630a20abd18af94 | |
parent | a6ea8d01cbfd48ba823d2e80442f741f7fcec328 (diff) | |
download | qtlocation-mapboxgl-1237e91a16d6b22df88c3fa25f3bc29b7734f88e.tar.gz |
[core] Universal getter for TilesetSource
-rw-r--r-- | include/mbgl/style/conversion_impl.hpp | 9 | ||||
-rw-r--r-- | include/mbgl/style/sources/tileset_source.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/style/sources/tileset_source.cpp | 33 |
3 files changed, 28 insertions, 15 deletions
diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index 9f3f636335..51a7a7db57 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -8,6 +8,7 @@ #include <mbgl/style/rotation.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/util/feature.hpp> +#include <mbgl/util/geo.hpp> #include <mbgl/util/geojson.hpp> #include <mbgl/util/optional.hpp> #include <mbgl/util/serializable.hpp> @@ -343,6 +344,14 @@ struct ValueFactory<Rotation> { static Value make(const Rotation& rotation) { return {rotation.getAngle()}; } }; +template <> +struct ValueFactory<LatLngBounds> { + static Value make(const LatLngBounds& bounds) { + std::vector<mapbox::base::Value> value{bounds.west(), bounds.south(), bounds.east(), bounds.north()}; + return value; + } +}; + template <typename T> Value makeValue(T&& arg) { return ValueFactory<std::decay_t<T>>::make(std::forward<T>(arg)); diff --git a/include/mbgl/style/sources/tileset_source.hpp b/include/mbgl/style/sources/tileset_source.hpp index 73e2b733ad..25f6efe4d0 100644 --- a/include/mbgl/style/sources/tileset_source.hpp +++ b/include/mbgl/style/sources/tileset_source.hpp @@ -20,6 +20,7 @@ public: protected: TilesetSource(Immutable<Impl>, variant<std::string, Tileset> urlOrTileset); + Value getPropertyInternal(const std::string&) const override; const variant<std::string, Tileset> urlOrTileset; }; diff --git a/src/mbgl/style/sources/tileset_source.cpp b/src/mbgl/style/sources/tileset_source.cpp index 7de970969f..a22ad0a6c7 100644 --- a/src/mbgl/style/sources/tileset_source.cpp +++ b/src/mbgl/style/sources/tileset_source.cpp @@ -2,7 +2,6 @@ #include <mbgl/style/conversion/tileset.hpp> #include <mbgl/style/conversion_impl.hpp> -#include <mbgl/tile/tile.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/enum.hpp> @@ -41,23 +40,13 @@ namespace { void serializeTileSet(Value& value, const mbgl::Tileset& tileset) { assert(value.getObject()); + using namespace conversion; PropertyMap* properties = value.getObject(); - std::vector<mapbox::base::Value> tiles; - tiles.reserve(tileset.tiles.size()); - for (const auto& tile : tileset.tiles) tiles.emplace_back(tile); - - properties->insert({"tiles", std::move(tiles)}); + properties->insert({"tiles", makeValue(tileset.tiles)}); properties->insert({"minzoom", tileset.zoomRange.min}); properties->insert({"maxzoom", tileset.zoomRange.max}); - properties->insert({"scheme", conversion::makeValue(tileset.scheme)}); - - if (tileset.bounds.has_value()) { - properties->insert({"bounds", - std::vector<mapbox::base::Value>{tileset.bounds->southwest().longitude(), - tileset.bounds->southwest().latitude(), - tileset.bounds->northeast().longitude(), - tileset.bounds->northeast().latitude()}}); - } + properties->insert({"scheme", makeValue(tileset.scheme)}); + properties->insert({"bounds", makeValue(tileset.bounds)}); } } // namespace @@ -73,5 +62,19 @@ Value TilesetSource::serialize() const { return result; } +Value TilesetSource::getPropertyInternal(const std::string& name) const { + using namespace conversion; + if (auto* tileset = getTileset()) { + if (name == "tiles") return makeValue(tileset->tiles); + if (name == "minzoom") return tileset->zoomRange.min; + if (name == "maxzoom") return tileset->zoomRange.max; + if (name == "scheme") return makeValue(tileset->scheme); + if (name == "bounds") return makeValue(tileset->bounds); + } else if (auto url = getURL()) { + if (name == "url") return makeValue(*url); + } + return Value(); +} + } // namespace style } // namespace mbgl |