summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-05-06 16:54:09 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2020-05-26 20:35:04 +0300
commit670c4a34b12ffd37ce1aa2dcfdff0f65930fd759 (patch)
treed52831126cb86a650778495afc9901e88eb8397b
parent40adc001eb9b97055ad139b431a8f286dece932d (diff)
downloadqtlocation-mapboxgl-670c4a34b12ffd37ce1aa2dcfdff0f65930fd759.tar.gz
[core] Layer::getProperty() returns generic properties
Now `Layer::getProperty()` returns the following generic properties: -"visibility" -"minzoom" -"maxzoom" -"filter" -"source-layer" -"source" -"type"
-rw-r--r--include/mbgl/gl/custom_layer.hpp2
-rw-r--r--include/mbgl/style/conversion_impl.hpp22
-rw-r--r--include/mbgl/style/layer.hpp4
-rw-r--r--include/mbgl/style/layers/background_layer.hpp3
-rw-r--r--include/mbgl/style/layers/circle_layer.hpp3
-rw-r--r--include/mbgl/style/layers/fill_extrusion_layer.hpp3
-rw-r--r--include/mbgl/style/layers/fill_layer.hpp3
-rw-r--r--include/mbgl/style/layers/heatmap_layer.hpp3
-rw-r--r--include/mbgl/style/layers/hillshade_layer.hpp3
-rw-r--r--include/mbgl/style/layers/layer.hpp.ejs3
-rw-r--r--include/mbgl/style/layers/line_layer.hpp3
-rw-r--r--include/mbgl/style/layers/location_indicator_layer.hpp3
-rw-r--r--include/mbgl/style/layers/raster_layer.hpp3
-rw-r--r--include/mbgl/style/layers/symbol_layer.hpp3
-rw-r--r--src/mbgl/gl/custom_layer.cpp2
-rw-r--r--src/mbgl/style/layer.cpp26
-rw-r--r--src/mbgl/style/layers/background_layer.cpp2
-rw-r--r--src/mbgl/style/layers/circle_layer.cpp2
-rw-r--r--src/mbgl/style/layers/fill_extrusion_layer.cpp2
-rw-r--r--src/mbgl/style/layers/fill_layer.cpp2
-rw-r--r--src/mbgl/style/layers/heatmap_layer.cpp2
-rw-r--r--src/mbgl/style/layers/hillshade_layer.cpp2
-rw-r--r--src/mbgl/style/layers/layer.cpp.ejs2
-rw-r--r--src/mbgl/style/layers/line_layer.cpp2
-rw-r--r--src/mbgl/style/layers/location_indicator_layer.cpp2
-rw-r--r--src/mbgl/style/layers/raster_layer.cpp2
-rw-r--r--src/mbgl/style/layers/symbol_layer.cpp2
27 files changed, 66 insertions, 45 deletions
diff --git a/include/mbgl/gl/custom_layer.hpp b/include/mbgl/gl/custom_layer.hpp
index f879cda806..18f4d2a02f 100644
--- a/include/mbgl/gl/custom_layer.hpp
+++ b/include/mbgl/gl/custom_layer.hpp
@@ -75,7 +75,7 @@ public:
private:
optional<conversion::Error> setPropertyInternal(const std::string& name,
const conversion::Convertible& value) final;
- StyleProperty getProperty(const std::string&) const final;
+ StyleProperty getPropertyInternal(const std::string&) const final;
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
};
diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp
index 692760195e..7e57b551fa 100644
--- a/include/mbgl/style/conversion_impl.hpp
+++ b/include/mbgl/style/conversion_impl.hpp
@@ -349,17 +349,23 @@ Value makeValue(T&& arg) {
}
template <typename T>
+inline StyleProperty makeConstantStyleProperty(T&& value) {
+ return {makeValue(std::forward<T>(value)), StyleProperty::Kind::Constant};
+}
+
+template <typename T>
+inline StyleProperty makeExpressionStyleProperty(T&& value) {
+ return {makeValue(std::forward<T>(value)), StyleProperty::Kind::Expression};
+}
+
+template <typename T>
StyleProperty makeStyleProperty(const PropertyValue<T>& value) {
return value.match([](const Undefined&) -> StyleProperty { return {}; },
- [](const Color& c) -> StyleProperty {
- return {makeValue(c), StyleProperty::Kind::Expression};
- },
+ [](const Color& c) -> StyleProperty { return makeExpressionStyleProperty(c); },
[](const PropertyExpression<T>& fn) -> StyleProperty {
- return {fn.getExpression().serialize(), StyleProperty::Kind::Expression};
+ return makeExpressionStyleProperty(fn.getExpression());
},
- [](const auto& t) -> StyleProperty {
- return {makeValue(t), StyleProperty::Kind::Constant};
- });
+ [](const auto& t) -> StyleProperty { return makeConstantStyleProperty(t); });
}
inline StyleProperty makeStyleProperty(const TransitionOptions& value) {
@@ -369,7 +375,7 @@ inline StyleProperty makeStyleProperty(const TransitionOptions& value) {
inline StyleProperty makeStyleProperty(const ColorRampPropertyValue& value) {
if (value.isUndefined()) return {};
- return {makeValue(value), StyleProperty::Kind::Expression};
+ return makeExpressionStyleProperty(value);
}
} // namespace conversion
diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp
index b1bc647b8b..a7e18757ac 100644
--- a/include/mbgl/style/layer.hpp
+++ b/include/mbgl/style/layer.hpp
@@ -113,8 +113,7 @@ public:
// Dynamic properties
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
-
- virtual StyleProperty getProperty(const std::string&) const = 0;
+ StyleProperty getProperty(const std::string& name) const;
Value serialize() const override;
// Private implementation
@@ -145,6 +144,7 @@ protected:
void serializeProperty(Value&, const StyleProperty&, const char* propertyName, bool isPaint) const;
virtual optional<conversion::Error> setPropertyInternal(const std::string& name,
const conversion::Convertible& value) = 0;
+ virtual StyleProperty getPropertyInternal(const std::string&) const = 0;
LayerObserver* observer;
mapbox::base::WeakPtrFactory<Layer> weakFactory {this};
diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp
index 6217484dca..7b87340486 100644
--- a/include/mbgl/style/layers/background_layer.hpp
+++ b/include/mbgl/style/layers/background_layer.hpp
@@ -51,8 +51,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp
index bb1ccbfae8..b2828432e1 100644
--- a/include/mbgl/style/layers/circle_layer.hpp
+++ b/include/mbgl/style/layers/circle_layer.hpp
@@ -105,8 +105,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp
index e823e63b84..76733b9331 100644
--- a/include/mbgl/style/layers/fill_extrusion_layer.hpp
+++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp
@@ -81,8 +81,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp
index a5f61a0c88..a7ef607c7d 100644
--- a/include/mbgl/style/layers/fill_layer.hpp
+++ b/include/mbgl/style/layers/fill_layer.hpp
@@ -81,8 +81,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp
index cbe353a6c4..5670f15e3d 100644
--- a/include/mbgl/style/layers/heatmap_layer.hpp
+++ b/include/mbgl/style/layers/heatmap_layer.hpp
@@ -64,8 +64,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp
index 2f50f92640..a6e3cea3f0 100644
--- a/include/mbgl/style/layers/hillshade_layer.hpp
+++ b/include/mbgl/style/layers/hillshade_layer.hpp
@@ -69,8 +69,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs
index 114fb1e346..cede9fc6af 100644
--- a/include/mbgl/style/layers/layer.hpp.ejs
+++ b/include/mbgl/style/layers/layer.hpp.ejs
@@ -73,8 +73,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp
index 1f3e8b04c2..a4e4dc9a2b 100644
--- a/include/mbgl/style/layers/line_layer.hpp
+++ b/include/mbgl/style/layers/line_layer.hpp
@@ -124,8 +124,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/location_indicator_layer.hpp b/include/mbgl/style/layers/location_indicator_layer.hpp
index 8d70bc18d3..503b070667 100644
--- a/include/mbgl/style/layers/location_indicator_layer.hpp
+++ b/include/mbgl/style/layers/location_indicator_layer.hpp
@@ -108,8 +108,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp
index 2f10b7cbea..40b42e30d7 100644
--- a/include/mbgl/style/layers/raster_layer.hpp
+++ b/include/mbgl/style/layers/raster_layer.hpp
@@ -81,8 +81,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp
index df54b7ad0b..b4f1247bbf 100644
--- a/include/mbgl/style/layers/symbol_layer.hpp
+++ b/include/mbgl/style/layers/symbol_layer.hpp
@@ -286,8 +286,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
-
- StyleProperty getProperty(const std::string& name) const final;
+ StyleProperty getPropertyInternal(const std::string& name) const final;
Value serialize() const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;
diff --git a/src/mbgl/gl/custom_layer.cpp b/src/mbgl/gl/custom_layer.cpp
index 47d1e6ea87..d174a5833b 100644
--- a/src/mbgl/gl/custom_layer.cpp
+++ b/src/mbgl/gl/custom_layer.cpp
@@ -42,7 +42,7 @@ optional<Error> CustomLayer::setPropertyInternal(const std::string&, const Conve
return Error { "layer doesn't support this property" };
}
-StyleProperty CustomLayer::getProperty(const std::string&) const {
+StyleProperty CustomLayer::getPropertyInternal(const std::string&) const {
return {};
}
diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp
index b1c14191be..9510c9df97 100644
--- a/src/mbgl/style/layer.cpp
+++ b/src/mbgl/style/layer.cpp
@@ -203,6 +203,32 @@ optional<conversion::Error> Layer::setProperty(const std::string& name, const co
return error;
}
+StyleProperty Layer::getProperty(const std::string& name) const {
+ using namespace conversion;
+ if (name == "visibility") {
+ return makeConstantStyleProperty(getVisibility());
+ }
+ if (name == "minzoom") {
+ return makeConstantStyleProperty(getMinZoom());
+ }
+ if (name == "maxzoom") {
+ return makeConstantStyleProperty(getMaxZoom());
+ }
+ if (name == "filter") {
+ return makeExpressionStyleProperty(getFilter());
+ }
+ if (name == "source-layer") {
+ return makeConstantStyleProperty(getSourceLayer());
+ }
+ if (name == "source") {
+ return makeConstantStyleProperty(getSourceID());
+ }
+ if (name == "type") {
+ return makeConstantStyleProperty(getTypeInfo()->type);
+ }
+ return getPropertyInternal(name);
+}
+
optional<conversion::Error> Layer::setVisibility(const conversion::Convertible& value) {
using namespace conversion;
diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp
index d4d9805eca..55f0868796 100644
--- a/src/mbgl/style/layers/background_layer.cpp
+++ b/src/mbgl/style/layers/background_layer.cpp
@@ -274,7 +274,7 @@ optional<Error> BackgroundLayer::setPropertyInternal(const std::string& name, co
return Error{"layer doesn't support this property"};
}
-StyleProperty BackgroundLayer::getProperty(const std::string& name) const {
+StyleProperty BackgroundLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp
index bf415ea42d..9fd3492c16 100644
--- a/src/mbgl/style/layers/circle_layer.cpp
+++ b/src/mbgl/style/layers/circle_layer.cpp
@@ -680,7 +680,7 @@ optional<Error> CircleLayer::setPropertyInternal(const std::string& name, const
return Error{"layer doesn't support this property"};
}
-StyleProperty CircleLayer::getProperty(const std::string& name) const {
+StyleProperty CircleLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp
index 86f204d826..d40f42fe6e 100644
--- a/src/mbgl/style/layers/fill_extrusion_layer.cpp
+++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp
@@ -521,7 +521,7 @@ optional<Error> FillExtrusionLayer::setPropertyInternal(const std::string& name,
return Error{"layer doesn't support this property"};
}
-StyleProperty FillExtrusionLayer::getProperty(const std::string& name) const {
+StyleProperty FillExtrusionLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp
index 1fc50f36bb..7f057d7d2e 100644
--- a/src/mbgl/style/layers/fill_layer.cpp
+++ b/src/mbgl/style/layers/fill_layer.cpp
@@ -498,7 +498,7 @@ optional<Error> FillLayer::setPropertyInternal(const std::string& name, const Co
return Error{"layer doesn't support this property"};
}
-StyleProperty FillLayer::getProperty(const std::string& name) const {
+StyleProperty FillLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp
index e51775d1d6..3e90dcb33a 100644
--- a/src/mbgl/style/layers/heatmap_layer.cpp
+++ b/src/mbgl/style/layers/heatmap_layer.cpp
@@ -370,7 +370,7 @@ optional<Error> HeatmapLayer::setPropertyInternal(const std::string& name, const
return Error{"layer doesn't support this property"};
}
-StyleProperty HeatmapLayer::getProperty(const std::string& name) const {
+StyleProperty HeatmapLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp
index d3e3ac6dc5..22aec9ca6e 100644
--- a/src/mbgl/style/layers/hillshade_layer.cpp
+++ b/src/mbgl/style/layers/hillshade_layer.cpp
@@ -414,7 +414,7 @@ optional<Error> HillshadeLayer::setPropertyInternal(const std::string& name, con
return Error{"layer doesn't support this property"};
}
-StyleProperty HillshadeLayer::getProperty(const std::string& name) const {
+StyleProperty HillshadeLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs
index 8fd4b1fef0..383d7444d6 100644
--- a/src/mbgl/style/layers/layer.cpp.ejs
+++ b/src/mbgl/style/layers/layer.cpp.ejs
@@ -335,7 +335,7 @@ optional<Error> <%- camelize(type) %>Layer::setPropertyInternal(const std::strin
return Error{"layer doesn't support this property"};
}
-StyleProperty <%- camelize(type) %>Layer::getProperty(const std::string& name) const {
+StyleProperty <%- camelize(type) %>Layer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp
index 7c1131a684..9c6250984f 100644
--- a/src/mbgl/style/layers/line_layer.cpp
+++ b/src/mbgl/style/layers/line_layer.cpp
@@ -796,7 +796,7 @@ optional<Error> LineLayer::setPropertyInternal(const std::string& name, const Co
return Error{"layer doesn't support this property"};
}
-StyleProperty LineLayer::getProperty(const std::string& name) const {
+StyleProperty LineLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/location_indicator_layer.cpp b/src/mbgl/style/layers/location_indicator_layer.cpp
index b3590d78e4..8ef8aa41fc 100644
--- a/src/mbgl/style/layers/location_indicator_layer.cpp
+++ b/src/mbgl/style/layers/location_indicator_layer.cpp
@@ -680,7 +680,7 @@ optional<Error> LocationIndicatorLayer::setPropertyInternal(const std::string& n
return Error{"layer doesn't support this property"};
}
-StyleProperty LocationIndicatorLayer::getProperty(const std::string& name) const {
+StyleProperty LocationIndicatorLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp
index 72a2f4d632..d8f8bbb892 100644
--- a/src/mbgl/style/layers/raster_layer.cpp
+++ b/src/mbgl/style/layers/raster_layer.cpp
@@ -499,7 +499,7 @@ optional<Error> RasterLayer::setPropertyInternal(const std::string& name, const
return Error{"layer doesn't support this property"};
}
-StyleProperty RasterLayer::getProperty(const std::string& name) const {
+StyleProperty RasterLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}
diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp
index e94c476b46..4fd9e653dd 100644
--- a/src/mbgl/style/layers/symbol_layer.cpp
+++ b/src/mbgl/style/layers/symbol_layer.cpp
@@ -1871,7 +1871,7 @@ optional<Error> SymbolLayer::setPropertyInternal(const std::string& name, const
return Error{"layer doesn't support this property"};
}
-StyleProperty SymbolLayer::getProperty(const std::string& name) const {
+StyleProperty SymbolLayer::getPropertyInternal(const std::string& name) const {
return getLayerProperty(*this, name);
}