#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { namespace style { using namespace conversion; struct DataDrivenSingleFloatProperty : DataDrivenPaintProperty { static float defaultValue() { return 1.f; } }; struct DataDrivenColorProperty : DataDrivenPaintProperty { static mbgl::Color defaultValue() { return mbgl::Color::black(); } static constexpr auto expressionType() { return expression::type::ColorType{}; }; using EvaluatorType = DataDrivenPropertyEvaluator; }; class PluginLayerProperty { public: enum class PropertyType { Unknown, SingleFloat, Color }; public: PropertyType _propertyType = PropertyType::Unknown; std::string _propertyName; void setPropertyValue(const conversion::Convertible& value); public: const PropertyValue& getSingleFloat() const; void setSingleFloat(const PropertyValue& value); float _defaultSingleFloatValue = 1.0; float _singleFloatValue = 0; PropertyValue _singleFloatProperty; void setCurrentSingleFloatValue(float value); // Color const PropertyValue& getColor() const; void setColor(const PropertyValue& value); mbgl::Color _defaultColorValue = mbgl::Color::black(); mbgl::Color _dataDrivenColorValue = mbgl::Color::black(); PropertyValue _dataDrivenColorProperty; void setCurrentColorValue(mbgl::Color value); // Return this property as json std::string asJSON(); private: }; class PluginLayerPropertyManager { public: PluginLayerProperty* getProperty(const std::string& propertyName); void addProperty(PluginLayerProperty* property); std::string propertiesAsJSON(); std::vector getProperties(); private: std::map _properties; }; class PluginLayer::Impl : public Layer::Impl { public: Impl(std::string layerID, std::string sourceID, LayerTypeInfo layerTypeInfo, const std::string& layerProperties); using Layer::Impl::Impl; bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; const LayerTypeInfo* getTypeInfo() const noexcept final { return &_layerTypeInfo; } void setRenderFunction(OnRenderLayer renderFunction) { _renderFunction = renderFunction; } void setUpdateFunction(OnUpdateLayer updateFunction) { _updateFunction = updateFunction; } void setUpdatePropertiesFunction(OnUpdateLayerProperties updateLayerPropertiesFunction) { _updateLayerPropertiesFunction = updateLayerPropertiesFunction; } //! The property manager handles all of the custom properties for this layer type / instance PluginLayerPropertyManager _propertyManager; //! Optional: Called when the layer is expected to render itself. OnRenderLayer _renderFunction; //! Optional: Called when the layer is expected to update it's animations/etc. // TODO: Does this need to be here or can it be done via the render function. Potentially, we could // have this method called on a background thread/etc or use another way to parallalize work OnUpdateLayer _updateFunction; //! Optional: Called when the layer properties change. The properties are passed as JSON for now OnUpdateLayerProperties _updateLayerPropertiesFunction; private: LayerTypeInfo _layerTypeInfo; std::string _layerProperties; }; } // namespace style } // namespace mbgl