[core] Move generic setProperty() parts to the base Layer class
This commit is contained in:
@@ -66,21 +66,17 @@ public:
|
||||
CustomLayer(const std::string& id,
|
||||
std::unique_ptr<CustomLayerHost> host);
|
||||
|
||||
CustomLayer(const CustomLayer&) = delete;
|
||||
~CustomLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
StyleProperty getProperty(const std::string&) const final;
|
||||
// Private implementation
|
||||
|
||||
class Impl;
|
||||
const Impl& impl() const;
|
||||
|
||||
Mutable<Impl> mutableImpl() const;
|
||||
|
||||
private:
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name,
|
||||
const conversion::Convertible& value) final;
|
||||
StyleProperty getProperty(const std::string&) const final;
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
CustomLayer(const CustomLayer&) = delete;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -110,8 +110,7 @@ public:
|
||||
void setMaxZoom(float);
|
||||
|
||||
// Dynamic properties
|
||||
virtual optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) = 0;
|
||||
optional<conversion::Error> setVisibility(const conversion::Convertible& value);
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
|
||||
|
||||
virtual StyleProperty getProperty(const std::string&) const = 0;
|
||||
virtual Value serialize() const;
|
||||
@@ -142,9 +141,13 @@ public:
|
||||
protected:
|
||||
virtual Mutable<Impl> mutableBaseImpl() const = 0;
|
||||
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;
|
||||
LayerObserver* observer;
|
||||
mapbox::base::WeakPtrFactory<Layer> weakFactory {this};
|
||||
|
||||
private:
|
||||
optional<conversion::Error> setVisibility(const conversion::Convertible& value);
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -20,12 +20,6 @@ public:
|
||||
BackgroundLayer(const std::string& layerID);
|
||||
~BackgroundLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Paint properties
|
||||
|
||||
static PropertyValue<Color> getDefaultBackgroundColor();
|
||||
@@ -56,6 +50,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,12 +20,6 @@ public:
|
||||
CircleLayer(const std::string& layerID, const std::string& sourceID);
|
||||
~CircleLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Paint properties
|
||||
|
||||
static PropertyValue<float> getDefaultCircleBlur();
|
||||
@@ -104,6 +98,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,12 +20,6 @@ public:
|
||||
FillExtrusionLayer(const std::string& layerID, const std::string& sourceID);
|
||||
~FillExtrusionLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Paint properties
|
||||
|
||||
static PropertyValue<float> getDefaultFillExtrusionBase();
|
||||
@@ -86,6 +80,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,12 +20,6 @@ public:
|
||||
FillLayer(const std::string& layerID, const std::string& sourceID);
|
||||
~FillLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Layout properties
|
||||
|
||||
static PropertyValue<float> getDefaultFillSortKey();
|
||||
@@ -86,6 +80,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -21,12 +21,6 @@ public:
|
||||
HeatmapLayer(const std::string& layerID, const std::string& sourceID);
|
||||
~HeatmapLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Paint properties
|
||||
|
||||
static ColorRampPropertyValue getDefaultHeatmapColor();
|
||||
@@ -69,6 +63,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,12 +20,6 @@ public:
|
||||
HillshadeLayer(const std::string& layerID, const std::string& sourceID);
|
||||
~HillshadeLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Paint properties
|
||||
|
||||
static PropertyValue<Color> getDefaultHillshadeAccentColor();
|
||||
@@ -74,6 +68,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,12 +36,6 @@ public:
|
||||
<% } -%>
|
||||
~<%- camelize(type) %>Layer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
<% if (layoutProperties.length) { -%>
|
||||
// Layout properties
|
||||
|
||||
@@ -72,6 +66,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,12 +23,6 @@ public:
|
||||
LineLayer(const std::string& layerID, const std::string& sourceID);
|
||||
~LineLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Layout properties
|
||||
|
||||
static PropertyValue<LineCapType> getDefaultLineCap();
|
||||
@@ -129,6 +123,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,12 +20,6 @@ public:
|
||||
RasterLayer(const std::string& layerID, const std::string& sourceID);
|
||||
~RasterLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Paint properties
|
||||
|
||||
static PropertyValue<float> getDefaultRasterBrightnessMax();
|
||||
@@ -86,6 +80,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -22,12 +22,6 @@ public:
|
||||
SymbolLayer(const std::string& layerID, const std::string& sourceID);
|
||||
~SymbolLayer() final;
|
||||
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
// Layout properties
|
||||
|
||||
static PropertyValue<bool> getDefaultIconAllowOverlap();
|
||||
@@ -290,6 +284,12 @@ public:
|
||||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
|
||||
|
||||
protected:
|
||||
// Dynamic properties
|
||||
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
|
||||
|
||||
StyleProperty getProperty(const std::string& name) const final;
|
||||
Value serialize() const final;
|
||||
|
||||
Mutable<Layer::Impl> mutableBaseImpl() const final;
|
||||
};
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ std::unique_ptr<Layer> CustomLayer::cloneRef(const std::string&) const {
|
||||
|
||||
using namespace conversion;
|
||||
|
||||
optional<Error> CustomLayer::setProperty(const std::string&, const Convertible&) {
|
||||
optional<Error> CustomLayer::setPropertyInternal(const std::string&, const Convertible&) {
|
||||
return Error { "layer doesn't support this property" };
|
||||
}
|
||||
|
||||
|
||||
@@ -143,6 +143,13 @@ void Layer::setObserver(LayerObserver* observer_) {
|
||||
observer = observer_ ? observer_ : &nullObserver;
|
||||
}
|
||||
|
||||
optional<conversion::Error> Layer::setProperty(const std::string& name, const conversion::Convertible& value) {
|
||||
optional<conversion::Error> error = setPropertyInternal(name, value);
|
||||
if (!error) return error; // Successfully set by the derived class implementation.
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return error; // Must be Error{"layer doesn't support this property"}.
|
||||
}
|
||||
|
||||
optional<conversion::Error> Layer::setVisibility(const conversion::Convertible& value) {
|
||||
using namespace conversion;
|
||||
|
||||
|
||||
@@ -211,12 +211,9 @@ Value BackgroundLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> BackgroundLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> BackgroundLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -491,12 +491,9 @@ Value CircleLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> CircleLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> CircleLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -386,12 +386,9 @@ Value FillExtrusionLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> FillExtrusionLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> FillExtrusionLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -371,12 +371,9 @@ Value FillLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> FillLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> FillLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -283,12 +283,9 @@ Value HeatmapLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> HeatmapLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> HeatmapLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -316,12 +316,9 @@ Value HillshadeLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> HillshadeLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> HillshadeLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -271,12 +271,9 @@ Value <%- camelize(type) %>Layer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> <%- camelize(type) %>Layer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> <%- camelize(type) %>Layer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -588,12 +588,9 @@ Value LineLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> LineLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> LineLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -386,12 +386,9 @@ Value RasterLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> RasterLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> RasterLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
@@ -1376,12 +1376,9 @@ Value SymbolLayer::serialize() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
optional<Error> SymbolLayer::setProperty(const std::string& name, const Convertible& value) {
|
||||
optional<Error> SymbolLayer::setPropertyInternal(const std::string& name, const Convertible& value) {
|
||||
const auto it = layerProperties.find(name.c_str());
|
||||
if (it == layerProperties.end()) {
|
||||
if (name == "visibility") return setVisibility(value);
|
||||
return Error{"layer doesn't support this property"};
|
||||
}
|
||||
if (it == layerProperties.end()) return Error{"layer doesn't support this property"};
|
||||
|
||||
auto property = static_cast<Property>(it->second);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user