diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-05-18 18:25:03 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2020-05-26 20:35:05 +0300 |
commit | 3bf695ebd92f0703679fef469f4407b93e4b20a2 (patch) | |
tree | b945230f0ca78ed7fef0100fba0d2d203c0ecb25 | |
parent | 5b3f7b3c9e7d6cb378fbaea24aac0c3ca2a60032 (diff) | |
download | qtlocation-mapboxgl-3bf695ebd92f0703679fef469f4407b93e4b20a2.tar.gz |
[core] Static default property values API for layers
Introduce
`style::StyleProperty LayerManager::getPropertyDefaultValue(const std::string& type, const std::string& property)`
50 files changed, 143 insertions, 81 deletions
diff --git a/include/mbgl/layermanager/background_layer_factory.hpp b/include/mbgl/layermanager/background_layer_factory.hpp index f2fa2f7a56..91619f1f9d 100644 --- a/include/mbgl/layermanager/background_layer_factory.hpp +++ b/include/mbgl/layermanager/background_layer_factory.hpp @@ -9,6 +9,7 @@ protected: const style::LayerTypeInfo* getTypeInfo() const noexcept final; std::unique_ptr<style::Layer> createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/circle_layer_factory.hpp b/include/mbgl/layermanager/circle_layer_factory.hpp index aaf5fddfb6..560551251a 100644 --- a/include/mbgl/layermanager/circle_layer_factory.hpp +++ b/include/mbgl/layermanager/circle_layer_factory.hpp @@ -12,6 +12,7 @@ protected: std::unique_ptr<GeometryTileLayer> tileLayer, const std::vector<Immutable<style::LayerProperties>>& group) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/fill_extrusion_layer_factory.hpp b/include/mbgl/layermanager/fill_extrusion_layer_factory.hpp index fbaa5c1254..79fcb4d343 100644 --- a/include/mbgl/layermanager/fill_extrusion_layer_factory.hpp +++ b/include/mbgl/layermanager/fill_extrusion_layer_factory.hpp @@ -10,6 +10,7 @@ protected: std::unique_ptr<style::Layer> createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; std::unique_ptr<Layout> createLayout(const LayoutParameters&, std::unique_ptr<GeometryTileLayer>, const std::vector<Immutable<style::LayerProperties>>&) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/fill_layer_factory.hpp b/include/mbgl/layermanager/fill_layer_factory.hpp index 09afb0dc3a..c3d67e1dc4 100644 --- a/include/mbgl/layermanager/fill_layer_factory.hpp +++ b/include/mbgl/layermanager/fill_layer_factory.hpp @@ -10,6 +10,7 @@ protected: std::unique_ptr<style::Layer> createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; std::unique_ptr<Layout> createLayout(const LayoutParameters&, std::unique_ptr<GeometryTileLayer>, const std::vector<Immutable<style::LayerProperties>>&) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/heatmap_layer_factory.hpp b/include/mbgl/layermanager/heatmap_layer_factory.hpp index 2d0e1a5a02..c13ec9998a 100644 --- a/include/mbgl/layermanager/heatmap_layer_factory.hpp +++ b/include/mbgl/layermanager/heatmap_layer_factory.hpp @@ -10,6 +10,7 @@ protected: std::unique_ptr<style::Layer> createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<Immutable<style::LayerProperties>>&) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/hillshade_layer_factory.hpp b/include/mbgl/layermanager/hillshade_layer_factory.hpp index 25b4f6c2c4..4095bb9d4f 100644 --- a/include/mbgl/layermanager/hillshade_layer_factory.hpp +++ b/include/mbgl/layermanager/hillshade_layer_factory.hpp @@ -9,6 +9,7 @@ protected: const style::LayerTypeInfo* getTypeInfo() const noexcept final; std::unique_ptr<style::Layer> createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/layer_factory.hpp b/include/mbgl/layermanager/layer_factory.hpp index afa25bf92d..758aae7f04 100644 --- a/include/mbgl/layermanager/layer_factory.hpp +++ b/include/mbgl/layermanager/layer_factory.hpp @@ -34,6 +34,8 @@ public: virtual std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<Immutable<style::LayerProperties>>&) noexcept; /// Returns a new Layout instance on success call; returns `nullptr` otherwise. virtual std::unique_ptr<Layout> createLayout(const LayoutParameters&, std::unique_ptr<GeometryTileLayer>, const std::vector<Immutable<style::LayerProperties>>&) noexcept; + /// Returns the default value for the given source property + virtual style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept; protected: optional<std::string> getSource(const style::conversion::Convertible& value) const noexcept; diff --git a/include/mbgl/layermanager/layer_manager.hpp b/include/mbgl/layermanager/layer_manager.hpp index c6802dbb49..799c378ccb 100644 --- a/include/mbgl/layermanager/layer_manager.hpp +++ b/include/mbgl/layermanager/layer_manager.hpp @@ -44,6 +44,8 @@ public: /// Returns a new Layout instance on success call; returns `nullptr` otherwise. std::unique_ptr<Layout> createLayout(const LayoutParameters&, std::unique_ptr<GeometryTileLayer>, const std::vector<Immutable<style::LayerProperties>>&) noexcept; + /// Returns the default value for the given layer type and property name. + style::StyleProperty getPropertyDefaultValue(const std::string& type, const std::string& property); /** * @brief a build-time flag to enable/disable annotations in mapbox-gl-native core. diff --git a/include/mbgl/layermanager/line_layer_factory.hpp b/include/mbgl/layermanager/line_layer_factory.hpp index 803f550e57..87b5a1c739 100644 --- a/include/mbgl/layermanager/line_layer_factory.hpp +++ b/include/mbgl/layermanager/line_layer_factory.hpp @@ -12,6 +12,7 @@ protected: std::unique_ptr<GeometryTileLayer> tileLayer, const std::vector<Immutable<style::LayerProperties>>& group) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/location_indicator_layer_factory.hpp b/include/mbgl/layermanager/location_indicator_layer_factory.hpp index 8d8e3b9a40..4119229dd2 100644 --- a/include/mbgl/layermanager/location_indicator_layer_factory.hpp +++ b/include/mbgl/layermanager/location_indicator_layer_factory.hpp @@ -10,6 +10,7 @@ protected: std::unique_ptr<style::Layer> createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/raster_layer_factory.hpp b/include/mbgl/layermanager/raster_layer_factory.hpp index d82137ee81..23db9707a2 100644 --- a/include/mbgl/layermanager/raster_layer_factory.hpp +++ b/include/mbgl/layermanager/raster_layer_factory.hpp @@ -9,6 +9,7 @@ protected: const style::LayerTypeInfo* getTypeInfo() const noexcept final; std::unique_ptr<style::Layer> createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/layermanager/symbol_layer_factory.hpp b/include/mbgl/layermanager/symbol_layer_factory.hpp index 38f382e96c..8a8ff0c534 100644 --- a/include/mbgl/layermanager/symbol_layer_factory.hpp +++ b/include/mbgl/layermanager/symbol_layer_factory.hpp @@ -12,6 +12,7 @@ protected: std::unique_ptr<GeometryTileLayer> tileLayer, const std::vector<Immutable<style::LayerProperties>>& group) noexcept final; std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; + style::StyleProperty getPropertyDefaultValue(const std::string& property) const noexcept final; }; } // namespace mbgl diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 333990a13b..1bd3071368 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -114,7 +114,7 @@ public: // Dynamic properties optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value); StyleProperty getProperty(const std::string& name) const; - StyleProperty getPropertyDefaultValue(const std::string& name) const; + static StyleProperty getPropertyDefaultValue(const std::string& name); Value serialize() const override; // Private implementation @@ -146,7 +146,6 @@ protected: virtual optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) = 0; virtual StyleProperty getPropertyInternal(const std::string&) const = 0; - virtual StyleProperty getPropertyDefaultValueInternal(const std::string&) const; 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 2d4e57def0..a75fcaff0b 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -47,12 +47,11 @@ public: Mutable<Impl> mutableImpl() const; BackgroundLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 9311da1c51..701d6dc145 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -101,12 +101,11 @@ public: Mutable<Impl> mutableImpl() const; CircleLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 de2055560f..d4c860403e 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -77,12 +77,11 @@ public: Mutable<Impl> mutableImpl() const; FillExtrusionLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 35f0ffd755..056ca4c329 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -77,12 +77,11 @@ public: Mutable<Impl> mutableImpl() const; FillLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 18d91e9067..9d24549f98 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -60,12 +60,11 @@ public: Mutable<Impl> mutableImpl() const; HeatmapLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 97f0b60186..9e5b7a009f 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -65,12 +65,11 @@ public: Mutable<Impl> mutableImpl() const; HillshadeLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 f835d5fd9d..d20d148e77 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -69,12 +69,11 @@ public: Mutable<Impl> mutableImpl() const; <%- camelize(type) %>Layer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 f80da0b8c8..92d2159a23 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -120,12 +120,11 @@ public: Mutable<Impl> mutableImpl() const; LineLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 f8f567c84f..e111fc184d 100644 --- a/include/mbgl/style/layers/location_indicator_layer.hpp +++ b/include/mbgl/style/layers/location_indicator_layer.hpp @@ -104,12 +104,11 @@ public: Mutable<Impl> mutableImpl() const; LocationIndicatorLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 d6c73e48b8..9cee177cfc 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -77,12 +77,11 @@ public: Mutable<Impl> mutableImpl() const; RasterLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) 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 0427a06a4f..6a54e38d3c 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -282,12 +282,11 @@ public: Mutable<Impl> mutableImpl() const; SymbolLayer(Immutable<Impl>); std::unique_ptr<Layer> cloneRef(const std::string& id) const final; - + static StyleProperty getPropertyDefaultValue(const std::string&); protected: // Dynamic properties optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getPropertyInternal(const std::string& name) const final; - StyleProperty getPropertyDefaultValueInternal(const std::string&) const final; Value serialize() const final; Mutable<Layer::Impl> mutableBaseImpl() const final; diff --git a/src/mbgl/layermanager/background_layer_factory.cpp b/src/mbgl/layermanager/background_layer_factory.cpp index b20e9a1930..3e004a8911 100644 --- a/src/mbgl/layermanager/background_layer_factory.cpp +++ b/src/mbgl/layermanager/background_layer_factory.cpp @@ -20,4 +20,8 @@ std::unique_ptr<RenderLayer> BackgroundLayerFactory::createRenderLayer(Immutable return std::make_unique<RenderBackgroundLayer>(staticImmutableCast<style::BackgroundLayer::Impl>(impl)); } +style::StyleProperty BackgroundLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::BackgroundLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/circle_layer_factory.cpp b/src/mbgl/layermanager/circle_layer_factory.cpp index 5bde1ede8b..862bb90ea8 100644 --- a/src/mbgl/layermanager/circle_layer_factory.cpp +++ b/src/mbgl/layermanager/circle_layer_factory.cpp @@ -33,4 +33,8 @@ std::unique_ptr<RenderLayer> CircleLayerFactory::createRenderLayer(Immutable<sty return std::make_unique<RenderCircleLayer>(staticImmutableCast<style::CircleLayer::Impl>(impl)); } +style::StyleProperty CircleLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::CircleLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp b/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp index 079d1a0947..b9e1adc25a 100644 --- a/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp +++ b/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp @@ -33,4 +33,8 @@ std::unique_ptr<RenderLayer> FillExtrusionLayerFactory::createRenderLayer(Immuta return std::make_unique<RenderFillExtrusionLayer>(staticImmutableCast<style::FillExtrusionLayer::Impl>(impl)); } +style::StyleProperty FillExtrusionLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::FillExtrusionLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/fill_layer_factory.cpp b/src/mbgl/layermanager/fill_layer_factory.cpp index 94f3f47ce8..43b7419a04 100644 --- a/src/mbgl/layermanager/fill_layer_factory.cpp +++ b/src/mbgl/layermanager/fill_layer_factory.cpp @@ -40,4 +40,8 @@ std::unique_ptr<RenderLayer> FillLayerFactory::createRenderLayer(Immutable<style return std::make_unique<RenderFillLayer>(staticImmutableCast<style::FillLayer::Impl>(impl)); } +style::StyleProperty FillLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::FillLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/heatmap_layer_factory.cpp b/src/mbgl/layermanager/heatmap_layer_factory.cpp index babbe8993b..d673c868ba 100644 --- a/src/mbgl/layermanager/heatmap_layer_factory.cpp +++ b/src/mbgl/layermanager/heatmap_layer_factory.cpp @@ -29,4 +29,8 @@ std::unique_ptr<RenderLayer> HeatmapLayerFactory::createRenderLayer(Immutable<st return std::make_unique<RenderHeatmapLayer>(staticImmutableCast<style::HeatmapLayer::Impl>(impl)); } +style::StyleProperty HeatmapLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::HeatmapLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/hillshade_layer_factory.cpp b/src/mbgl/layermanager/hillshade_layer_factory.cpp index c2981e17ed..630a5ac4e6 100644 --- a/src/mbgl/layermanager/hillshade_layer_factory.cpp +++ b/src/mbgl/layermanager/hillshade_layer_factory.cpp @@ -25,4 +25,8 @@ std::unique_ptr<RenderLayer> HillshadeLayerFactory::createRenderLayer(Immutable< return std::make_unique<RenderHillshadeLayer>(staticImmutableCast<style::HillshadeLayer::Impl>(impl)); } +style::StyleProperty HillshadeLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::HillshadeLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/layer_factory.cpp b/src/mbgl/layermanager/layer_factory.cpp index 9db96f62ca..0fa0c8d862 100644 --- a/src/mbgl/layermanager/layer_factory.cpp +++ b/src/mbgl/layermanager/layer_factory.cpp @@ -37,4 +37,8 @@ std::unique_ptr<Layout> LayerFactory::createLayout(const LayoutParameters&, return nullptr; } +style::StyleProperty LayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::Layer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/layer_manager.cpp b/src/mbgl/layermanager/layer_manager.cpp index 377d3acce4..b68ae9dce1 100644 --- a/src/mbgl/layermanager/layer_manager.cpp +++ b/src/mbgl/layermanager/layer_manager.cpp @@ -53,4 +53,11 @@ std::unique_ptr<RenderLayer> LayerManager::createRenderLayer(Immutable<style::La return factory->createRenderLayer(std::move(impl)); } +style::StyleProperty LayerManager::getPropertyDefaultValue(const std::string& type, const std::string& property) { + if (LayerFactory* factory = getFactory(type)) { + return factory->getPropertyDefaultValue(property); + } + return {}; +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/line_layer_factory.cpp b/src/mbgl/layermanager/line_layer_factory.cpp index 03751fef06..edf36b4af5 100644 --- a/src/mbgl/layermanager/line_layer_factory.cpp +++ b/src/mbgl/layermanager/line_layer_factory.cpp @@ -38,4 +38,8 @@ std::unique_ptr<RenderLayer> LineLayerFactory::createRenderLayer(Immutable<style return std::make_unique<RenderLineLayer>(staticImmutableCast<style::LineLayer::Impl>(impl)); } +style::StyleProperty LineLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::LineLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/location_indicator_layer_factory.cpp b/src/mbgl/layermanager/location_indicator_layer_factory.cpp index 67f7280e93..aca3d1ea04 100644 --- a/src/mbgl/layermanager/location_indicator_layer_factory.cpp +++ b/src/mbgl/layermanager/location_indicator_layer_factory.cpp @@ -22,4 +22,9 @@ std::unique_ptr<RenderLayer> LocationIndicatorLayerFactory::createRenderLayer( staticImmutableCast<style::LocationIndicatorLayer::Impl>(impl)); } +style::StyleProperty LocationIndicatorLayerFactory::getPropertyDefaultValue(const std::string& property) const + noexcept { + return style::LocationIndicatorLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/raster_layer_factory.cpp b/src/mbgl/layermanager/raster_layer_factory.cpp index 172d445477..0da0fe820e 100644 --- a/src/mbgl/layermanager/raster_layer_factory.cpp +++ b/src/mbgl/layermanager/raster_layer_factory.cpp @@ -25,4 +25,8 @@ std::unique_ptr<RenderLayer> RasterLayerFactory::createRenderLayer(Immutable<sty return std::make_unique<RenderRasterLayer>(staticImmutableCast<style::RasterLayer::Impl>(impl)); } +style::StyleProperty RasterLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::RasterLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/layermanager/symbol_layer_factory.cpp b/src/mbgl/layermanager/symbol_layer_factory.cpp index 5f3de27bb5..05fe42dfdb 100644 --- a/src/mbgl/layermanager/symbol_layer_factory.cpp +++ b/src/mbgl/layermanager/symbol_layer_factory.cpp @@ -30,4 +30,8 @@ std::unique_ptr<RenderLayer> SymbolLayerFactory::createRenderLayer(Immutable<sty return std::make_unique<RenderSymbolLayer>(staticImmutableCast<style::SymbolLayer::Impl>(impl)); } +style::StyleProperty SymbolLayerFactory::getPropertyDefaultValue(const std::string& property) const noexcept { + return style::SymbolLayer::getPropertyDefaultValue(property); +} + } // namespace mbgl diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp index 73480cc2f7..da048ad2fa 100644 --- a/src/mbgl/style/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -258,12 +258,13 @@ StyleProperty Layer::getProperty(const std::string& name) const { return getPropertyInternal(name); } -StyleProperty Layer::getPropertyDefaultValue(const std::string& name) const { +// static +StyleProperty Layer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it != layerProperties.end()) { return getLayerPropertyDefaultValue(static_cast<Property>(it->second)); } - return getPropertyDefaultValueInternal(name); + return {}; } optional<conversion::Error> Layer::setVisibility(const conversion::Convertible& value) { @@ -288,9 +289,5 @@ const LayerTypeInfo* Layer::getTypeInfo() const noexcept { return baseImpl->getTypeInfo(); } -StyleProperty Layer::getPropertyDefaultValueInternal(const std::string&) const { - return {}; -} - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index c3679a97b6..336cd33599 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -278,10 +278,11 @@ StyleProperty BackgroundLayer::getPropertyInternal(const std::string& name) cons return getLayerProperty(*this, name); } -StyleProperty BackgroundLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty BackgroundLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index f83e57eb25..8c81d8a23f 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -684,10 +684,11 @@ StyleProperty CircleLayer::getPropertyInternal(const std::string& name) const { return getLayerProperty(*this, name); } -StyleProperty CircleLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty CircleLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index d11626d897..50afe80ea3 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -525,10 +525,11 @@ StyleProperty FillExtrusionLayer::getPropertyInternal(const std::string& name) c return getLayerProperty(*this, name); } -StyleProperty FillExtrusionLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty FillExtrusionLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 1023d73191..83049a33f0 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -502,10 +502,11 @@ StyleProperty FillLayer::getPropertyInternal(const std::string& name) const { return getLayerProperty(*this, name); } -StyleProperty FillLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty FillLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp index f58a885233..4f86519b31 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -374,10 +374,11 @@ StyleProperty HeatmapLayer::getPropertyInternal(const std::string& name) const { return getLayerProperty(*this, name); } -StyleProperty HeatmapLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty HeatmapLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 333dbb2780..b5fef6e628 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -418,10 +418,11 @@ StyleProperty HillshadeLayer::getPropertyInternal(const std::string& name) const return getLayerProperty(*this, name); } -StyleProperty HillshadeLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty HillshadeLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index 27211a77f1..903d713755 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -339,10 +339,11 @@ StyleProperty <%- camelize(type) %>Layer::getPropertyInternal(const std::string& return getLayerProperty(*this, name); } -StyleProperty <%- camelize(type) %>Layer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty <%- camelize(type) %>Layer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index cb12b05c7c..f5b5df9af7 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -800,10 +800,11 @@ StyleProperty LineLayer::getPropertyInternal(const std::string& name) const { return getLayerProperty(*this, name); } -StyleProperty LineLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty LineLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/location_indicator_layer.cpp b/src/mbgl/style/layers/location_indicator_layer.cpp index cbd47684cb..b02e044c96 100644 --- a/src/mbgl/style/layers/location_indicator_layer.cpp +++ b/src/mbgl/style/layers/location_indicator_layer.cpp @@ -684,10 +684,11 @@ StyleProperty LocationIndicatorLayer::getPropertyInternal(const std::string& nam return getLayerProperty(*this, name); } -StyleProperty LocationIndicatorLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty LocationIndicatorLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index cad24f43a5..6db4feb65e 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -503,10 +503,11 @@ StyleProperty RasterLayer::getPropertyInternal(const std::string& name) const { return getLayerProperty(*this, name); } -StyleProperty RasterLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty RasterLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 529d6868f2..b9f0b70209 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -1875,10 +1875,11 @@ StyleProperty SymbolLayer::getPropertyInternal(const std::string& name) const { return getLayerProperty(*this, name); } -StyleProperty SymbolLayer::getPropertyDefaultValueInternal(const std::string& name) const { +// static +StyleProperty SymbolLayer::getPropertyDefaultValue(const std::string& name) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) { - return {}; + return Layer::getPropertyDefaultValue(name); } switch (static_cast<Property>(it->second)) { diff --git a/test/style/conversion/layer.test.cpp b/test/style/conversion/layer.test.cpp index 4016307373..df40aee057 100644 --- a/test/style/conversion/layer.test.cpp +++ b/test/style/conversion/layer.test.cpp @@ -164,33 +164,4 @@ TEST(StyleConversion, SetLayerGenericProperties) { const JSValue newMaxZoom(22.0f); layer->setProperty("maxzoom", Convertible(&newMaxZoom)); EXPECT_EQ(22.0f, layer->getMaxZoom()); -} - -TEST(StyleConversion, GetLayerGenericPropertyDefaultValues) { - auto layer = parseLayer(R"JSON({ - "type": "symbol", - "id": "symbol", - "source": "composite" - })JSON"); - - ASSERT_NE(nullptr, layer); - StyleProperty maxzoom = layer->getPropertyDefaultValue("maxzoom"); - EXPECT_EQ(StyleProperty::Kind::Constant, maxzoom.getKind()); - EXPECT_EQ(Value(std::numeric_limits<double>::infinity()), maxzoom.getValue()); - - StyleProperty minzoom = layer->getPropertyDefaultValue("minzoom"); - EXPECT_EQ(StyleProperty::Kind::Constant, minzoom.getKind()); - EXPECT_EQ(Value(-std::numeric_limits<double>::infinity()), minzoom.getValue()); - - StyleProperty visibility = layer->getPropertyDefaultValue("visibility"); - EXPECT_EQ(StyleProperty::Kind::Constant, visibility.getKind()); - EXPECT_EQ(Value("visible"), visibility.getValue()); - - StyleProperty symbolSpacing = layer->getPropertyDefaultValue("symbol-spacing"); - EXPECT_EQ(StyleProperty::Kind::Constant, symbolSpacing.getKind()); - EXPECT_EQ(Value(SymbolSpacing::defaultValue()), symbolSpacing.getValue()); - - StyleProperty nonexistent = layer->getPropertyDefaultValue("nonexistent"); - EXPECT_EQ(StyleProperty::Kind::Undefined, nonexistent.getKind()); - EXPECT_EQ(Value(), nonexistent.getValue()); }
\ No newline at end of file diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp index 84bad2830b..335557d312 100644 --- a/test/style/style_layer.test.cpp +++ b/test/style/style_layer.test.cpp @@ -1,5 +1,6 @@ #include <mbgl/gl/custom_layer.hpp> #include <mbgl/gl/custom_layer_impl.hpp> +#include <mbgl/layermanager/layer_manager.hpp> #include <mbgl/style/conversion/filter.hpp> #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/expression/dsl.hpp> @@ -412,3 +413,31 @@ TEST(Layer, SymbolLayerOverrides) { EXPECT_FALSE(updated.get<TextColor>().isConstant()); } } + +namespace { + +void checkGetPropertyDefaultValue(const std::string& layerType, + const std::string& property, + const mbgl::Value& expected) { + auto result = LayerManager::get()->getPropertyDefaultValue(layerType, property); + EXPECT_EQ(expected, result.getValue()) << layerType << " layer, " << property << " property"; + if (expected) { + EXPECT_NE(StyleProperty::Kind::Undefined, result.getKind()) + << layerType << " layer, " << property << " property"; + } else { + EXPECT_EQ(StyleProperty::Kind::Undefined, result.getKind()) + << layerType << " layer, " << property << " property"; + } +} + +} // namespace + +TEST(Layer, GetLayerPropertyDefaultValues) { + using namespace mbgl::style; + checkGetPropertyDefaultValue("symbol", "maxzoom", std::numeric_limits<double>::infinity()); + checkGetPropertyDefaultValue("symbol", "minzoom", -std::numeric_limits<double>::infinity()); + checkGetPropertyDefaultValue("symbol", "visibility", "visible"); + checkGetPropertyDefaultValue("symbol", "symbol-spacing", SymbolSpacing::defaultValue()); + checkGetPropertyDefaultValue("line", "symbol-spacing", {}); + checkGetPropertyDefaultValue("nonexistent", "nonexistent", {}); +}
\ No newline at end of file |