Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Ability to set generic layer properties using setProperty method #16324

Merged
merged 6 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

- [android] Add jni binding for styleable snapshotter ([#16286](https://github.com/mapbox/mapbox-gl-native/pull/16286))

- [core] Ability to set generic layer properties using setProperty method ([#16324](https://github.com/mapbox/mapbox-gl-native/pull/16324))
This change enables the following new keys for the `mbgl::Layer::setProperty()` API:
- "filter" invokes `setFilter()`
- "minzoom" invokes `setMinZoom()`
- "maxzoom" invokes `setMaxZoom()`
- "source-layer" invokes `setSourceLayer()`

The newly-added API is used in the style-conversion code, which made this code much simpler.

### 🐞 Bug fixes

- [core] Use `TileCoordinates` instead of `LngLat` for `within` expression calculation ([#16319](https://github.com/mapbox/mapbox-gl-native/pull/16319))
Expand Down
16 changes: 6 additions & 10 deletions include/mbgl/gl/custom_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,17 @@ class CustomLayer : public Layer {
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;
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;

CustomLayer(const CustomLayer&) = delete;

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;
Mutable<Layer::Impl> mutableBaseImpl() const final;
};

Expand Down
1 change: 0 additions & 1 deletion include/mbgl/layermanager/layer_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class LayerFactory {

protected:
optional<std::string> getSource(const style::conversion::Convertible& value) const noexcept;
bool initSourceLayerAndFilter(style::Layer*, const style::conversion::Convertible& value) const noexcept;
};

} // namespace mbgl
11 changes: 8 additions & 3 deletions include/mbgl/style/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ class Layer {
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;
Expand Down Expand Up @@ -142,9 +141,15 @@ class Layer {
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);
optional<conversion::Error> setMinZoom(const conversion::Convertible& value);
optional<conversion::Error> setMaxZoom(const conversion::Convertible& value);
};

} // namespace style
Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/background_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class BackgroundLayer : public Layer {
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();
Expand Down Expand Up @@ -56,6 +50,12 @@ class BackgroundLayer : public Layer {
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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/circle_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class CircleLayer : public Layer {
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();
Expand Down Expand Up @@ -104,6 +98,12 @@ class CircleLayer : public Layer {
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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/fill_extrusion_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class FillExtrusionLayer : public Layer {
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();
Expand Down Expand Up @@ -86,6 +80,12 @@ class FillExtrusionLayer : public Layer {
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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/fill_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class FillLayer : public Layer {
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();
Expand Down Expand Up @@ -86,6 +80,12 @@ class FillLayer : public Layer {
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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/heatmap_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ class HeatmapLayer : public Layer {
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();
Expand Down Expand Up @@ -69,6 +63,12 @@ class HeatmapLayer : public Layer {
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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/hillshade_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class HillshadeLayer : public Layer {
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();
Expand Down Expand Up @@ -74,6 +68,12 @@ class HillshadeLayer : public Layer {
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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/layer.hpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/line_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ class LineLayer : public Layer {
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();
Expand Down Expand Up @@ -129,6 +123,12 @@ class LineLayer : public Layer {
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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/raster_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ class RasterLayer : public Layer {
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();
Expand Down Expand Up @@ -86,6 +80,12 @@ class RasterLayer : public Layer {
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;
};

Expand Down
12 changes: 6 additions & 6 deletions include/mbgl/style/layers/symbol_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ class SymbolLayer : public Layer {
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();
Expand Down Expand Up @@ -290,6 +284,12 @@ class SymbolLayer : public Layer {
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;
};

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/gl/custom_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
}

Expand Down
6 changes: 1 addition & 5 deletions src/mbgl/layermanager/circle_layer_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ std::unique_ptr<style::Layer> CircleLayerFactory::createLayer(const std::string&
return nullptr;
}

std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::CircleLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::CircleLayer(id, *source));
}

std::unique_ptr<Bucket> CircleLayerFactory::createBucket(const BucketParameters& parameters, const std::vector<Immutable<style::LayerProperties>>& layers) noexcept {
Expand Down
6 changes: 1 addition & 5 deletions src/mbgl/layermanager/fill_extrusion_layer_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ std::unique_ptr<style::Layer> FillExtrusionLayerFactory::createLayer(const std::
return nullptr;
}

std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::FillExtrusionLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::FillExtrusionLayer(id, *source));
}

std::unique_ptr<Layout> FillExtrusionLayerFactory::createLayout(const LayoutParameters& parameters,
Expand Down
6 changes: 1 addition & 5 deletions src/mbgl/layermanager/fill_layer_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ std::unique_ptr<style::Layer> FillLayerFactory::createLayer(const std::string& i
return nullptr;
}

std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::FillLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::FillLayer(id, *source));
}

std::unique_ptr<Layout>
Expand Down
6 changes: 1 addition & 5 deletions src/mbgl/layermanager/heatmap_layer_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ std::unique_ptr<style::Layer> HeatmapLayerFactory::createLayer(const std::string
return nullptr;
}

std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new style::HeatmapLayer(id, *source));
if (!initSourceLayerAndFilter(layer.get(), value)) {
return nullptr;
}
return layer;
return std::unique_ptr<style::Layer>(new style::HeatmapLayer(id, *source));
}

std::unique_ptr<Bucket> HeatmapLayerFactory::createBucket(const BucketParameters& parameters, const std::vector<Immutable<style::LayerProperties>>& layers) noexcept {
Expand Down
Loading