summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-05-11 19:11:31 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2020-05-26 20:35:05 +0300
commit0b3aa88d11ec221f6d0afc4f1921e00a5b195805 (patch)
tree93670492d9155d362898c3ab741deef357680203
parent893c2840354d4783f5e29f450bad99dcb1892fa2 (diff)
downloadqtlocation-mapboxgl-0b3aa88d11ec221f6d0afc4f1921e00a5b195805.tar.gz
[core] Enable source volatile flag initalization in style
The source `volatile` flag value can be defined in the style as following: ``` "example_source": { "volatile": true } ```
-rw-r--r--src/mbgl/style/conversion/source.cpp13
-rw-r--r--test/map/map.test.cpp4
2 files changed, 16 insertions, 1 deletions
diff --git a/src/mbgl/style/conversion/source.cpp b/src/mbgl/style/conversion/source.cpp
index 14e020594a..80c8b893f7 100644
--- a/src/mbgl/style/conversion/source.cpp
+++ b/src/mbgl/style/conversion/source.cpp
@@ -9,6 +9,18 @@ namespace mbgl {
namespace style {
namespace conversion {
+namespace {
+bool setObjectMember(std::unique_ptr<Source>& source, const Convertible& value, const char* member, Error& error) {
+ if (auto memberValue = objectMember(value, member)) {
+ if (auto error_ = source->setProperty(member, *memberValue)) {
+ error = *error_;
+ return false;
+ }
+ }
+ return true;
+}
+} // namespace
+
optional<std::unique_ptr<Source>> Converter<std::unique_ptr<Source>>::operator()(const Convertible& value,
Error& error,
const std::string& id) const {
@@ -32,6 +44,7 @@ optional<std::unique_ptr<Source>> Converter<std::unique_ptr<Source>>::operator()
auto source = SourceManager::get()->createSource(tname, id, value, error);
if (!source) return nullopt;
+ if (!setObjectMember(source, value, "volatile", error)) return nullopt;
return source;
}
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 0370f51707..1d266b72e2 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -1059,7 +1059,8 @@ TEST(Map, UniversalStyleGetter) {
},
"mapbox-streets": {
"type": "vector",
- "url": "http://api.example.com/tilejson.json"
+ "url": "http://api.example.com/tilejson.json",
+ "volatile": true
},
"image": {
"type": "image",
@@ -1120,6 +1121,7 @@ TEST(Map, UniversalStyleGetter) {
ASSERT_TRUE(streetsSource);
checkConstProperty(streetsSource, "url", "http://api.example.com/tilejson.json");
checkConstProperty(streetsSource, "tiles", NullValue());
+ checkConstProperty(streetsSource, "volatile", true);
// Image source properties
Source* imageSource = test.map.getStyle().getSource("image");
ASSERT_TRUE(imageSource);