summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-05-14 16:47:58 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2020-05-26 20:35:05 +0300
commit0489a8d88abca0966b18b028ec0b5bc33180885d (patch)
tree6dc6cf64150be3617a94cfad2e2a175c9021f8b1 /src
parentbbd2e0adeaa7a361e6891a029fc7e54ab3a754fc (diff)
downloadqtlocation-mapboxgl-0489a8d88abca0966b18b028ec0b5bc33180885d.tar.gz
[core] Introduce getPropertyDefaultValue() API for sources
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/source.cpp95
-rw-r--r--src/mbgl/style/sources/tileset_source.cpp8
2 files changed, 91 insertions, 12 deletions
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp
index 9366117fc6..dd3ec4caa6 100644
--- a/src/mbgl/style/source.cpp
+++ b/src/mbgl/style/source.cpp
@@ -6,11 +6,79 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/util/tileset.hpp>
+#include <mapbox/eternal.hpp>
+
namespace mbgl {
namespace style {
static SourceObserver nullObserver;
+namespace {
+
+enum class Property : uint8_t {
+ Volatile,
+ Attribution,
+ TileSize,
+ PrefetchZoomDelta,
+ MaxOverscaleFactorForParentTiles,
+ MinTileUpdateInterval,
+ Type
+};
+
+constexpr const auto sourceProperties = mapbox::eternal::hash_map<mapbox::eternal::string, uint8_t>(
+ {{"volatile", underlying_type(Property::Volatile)},
+ {"attribution", underlying_type(Property::Attribution)},
+ {"tile-size", underlying_type(Property::TileSize)},
+ {"prefetch-zoom-delta", underlying_type(Property::PrefetchZoomDelta)},
+ {"max-overscale-factor-for-parent-tiles", underlying_type(Property::MaxOverscaleFactorForParentTiles)},
+ {"minimum-tile-update-interval", underlying_type(Property::MinTileUpdateInterval)},
+ {"type", underlying_type(Property::Type)}});
+
+Value getSourcePropertyDefaultValue(Property property) {
+ switch (property) {
+ case Property::Volatile:
+ return false;
+ case Property::TileSize:
+ return util::tileSize;
+ case Property::PrefetchZoomDelta:
+ return util::DEFAULT_PREFETCH_ZOOM_DELTA;
+ case Property::Attribution:
+ case Property::MaxOverscaleFactorForParentTiles:
+ case Property::Type:
+ return {};
+ case Property::MinTileUpdateInterval:
+ return 0.0;
+ }
+ assert(false);
+ return NullValue();
+}
+
+Value getSourceProperty(const Source* source, Property property) {
+ using namespace conversion;
+ switch (property) {
+ case Property::Volatile:
+ return source->isVolatile();
+ case Property::Attribution:
+ return makeValue(source->getAttribution());
+ case Property::TileSize:
+ return makeValue(source->getTileSize());
+ case Property::PrefetchZoomDelta:
+ return makeValue(source->getPrefetchZoomDelta());
+ case Property::MaxOverscaleFactorForParentTiles:
+ return makeValue(source->getMaxOverscaleFactorForParentTiles());
+ case Property::MinTileUpdateInterval: {
+ auto seconds =
+ std::chrono::duration_cast<std::chrono::duration<float>>(source->getMinimumTileUpdateInterval());
+ return makeValue(seconds.count());
+ }
+ case Property::Type:
+ return makeValue(source->getTypeInfo()->type);
+ }
+ return NullValue();
+}
+
+} // namespace
+
Source::Source(Immutable<Impl> impl) : baseImpl(std::move(impl)), observer(&nullObserver) {}
Source::~Source() = default;
@@ -114,22 +182,21 @@ optional<conversion::Error> Source::setProperty(const std::string& name, const c
}
Value Source::getProperty(const std::string& name) const {
- using namespace conversion;
- if (name == "type") return makeValue(getTypeInfo()->type);
- if (name == "volatile") return makeValue(isVolatile());
- if (name == "attribution") return makeValue(getAttribution());
- if (name == "tile-size") return makeValue(getTileSize());
- if (name == "prefetch-zoom-delta") return makeValue(getPrefetchZoomDelta());
- if (name == "max-overscale-factor-for-parent-tiles") {
- return makeValue(getMaxOverscaleFactorForParentTiles());
- }
- if (name == "minimum-tile-update-interval") {
- auto seconds = std::chrono::duration_cast<std::chrono::duration<float>>(getMinimumTileUpdateInterval());
- return makeValue(seconds.count());
+ const auto it = sourceProperties.find(name.c_str());
+ if (it != sourceProperties.end()) {
+ return getSourceProperty(this, static_cast<Property>(it->second));
}
return getPropertyInternal(name);
}
+Value Source::getPropertyDefaultValue(const std::string& name) const {
+ const auto it = sourceProperties.find(name.c_str());
+ if (it != sourceProperties.end()) {
+ return getSourcePropertyDefaultValue(static_cast<Property>(it->second));
+ }
+ return getPropertyDefaultValueInternal(name);
+}
+
const SourceTypeInfo* Source::getTypeInfo() const noexcept {
return baseImpl->getTypeInfo();
}
@@ -153,5 +220,9 @@ Value Source::getPropertyInternal(const std::string&) const {
return NullValue();
}
+Value Source::getPropertyDefaultValueInternal(const std::string&) const {
+ return NullValue();
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/tileset_source.cpp b/src/mbgl/style/sources/tileset_source.cpp
index a22ad0a6c7..45bad4e010 100644
--- a/src/mbgl/style/sources/tileset_source.cpp
+++ b/src/mbgl/style/sources/tileset_source.cpp
@@ -76,5 +76,13 @@ Value TilesetSource::getPropertyInternal(const std::string& name) const {
return Value();
}
+Value TilesetSource::getPropertyDefaultValueInternal(const std::string& name) const {
+ using namespace conversion;
+ if (name == "scheme") return makeValue(TilesetScheme::XYZ);
+ if (name == "minzoom") return 0u;
+ if (name == "maxzoom") return util::DEFAULT_MAX_ZOOM;
+ return Value();
+}
+
} // namespace style
} // namespace mbgl