diff options
Diffstat (limited to 'include/mbgl/style')
20 files changed, 178 insertions, 15 deletions
diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp index 2c83d1561b..29af9fac91 100644 --- a/include/mbgl/style/conversion.hpp +++ b/include/mbgl/style/conversion.hpp @@ -17,9 +17,12 @@ class ConversionTraits; class Convertible; -template <class T, class Enable = void> +template <typename T, typename Enable = void> struct Converter; +template <typename T, typename Enable = void> +struct ValueFactory; + } // namespace conversion } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index f049ba4ffb..3e1b8455e5 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -1,11 +1,21 @@ #pragma once +#include <mbgl/style/color_ramp_property_value.hpp> #include <mbgl/style/conversion.hpp> -#include <mbgl/util/optional.hpp> +#include <mbgl/style/layer.hpp> +#include <mbgl/style/property_value.hpp> +#include <mbgl/style/transition_options.hpp> #include <mbgl/util/feature.hpp> #include <mbgl/util/geojson.hpp> +#include <mbgl/util/optional.hpp> +#include <mbgl/util/traits.hpp> + +#include <mapbox/value.hpp> +#include <array> +#include <chrono> #include <string> +#include <type_traits> namespace mbgl { namespace style { @@ -288,6 +298,81 @@ optional<T> convert(const Convertible& value, Error& error, Args&&...args) { return Converter<T>()(value, error, std::forward<Args>(args)...); } +template <> +struct ValueFactory<ColorRampPropertyValue> { + static Value make(const ColorRampPropertyValue& value) { return value.getExpression().serialize(); } +}; + +template <> +struct ValueFactory<TransitionOptions> { + static Value make(const TransitionOptions& value) { + return mapbox::base::ValueArray{ + {std::chrono::duration_cast<std::chrono::milliseconds>(value.duration.value_or(mbgl::Duration::zero())) + .count(), + std::chrono::duration_cast<std::chrono::milliseconds>(value.delay.value_or(mbgl::Duration::zero())) + .count(), + value.enablePlacementTransitions}}; + } +}; + +template <> +struct ValueFactory<Color> { + static Value make(const Color& color) { return color.toObject(); } +}; + +template <typename T> +struct ValueFactory<T, typename std::enable_if<(!std::is_enum<T>::value && !is_linear_container<T>::value)>::type> { + static Value make(const T& arg) { return {arg}; } +}; + +template <typename T> +struct ValueFactory<T, typename std::enable_if<std::is_enum<T>::value>::type> { + static Value make(T arg) { return {Enum<T>::toString(arg)}; } +}; + +template <typename T> +struct ValueFactory<T, typename std::enable_if<is_linear_container<T>::value>::type> { + static Value make(const T& arg) { + mapbox::base::ValueArray result; + result.reserve(arg.size()); + for (const auto& item : arg) { + result.emplace_back(ValueFactory<std::decay_t<decltype(item)>>::make(item)); + } + return result; + } +}; + +template <> +struct ValueFactory<Position> { + static Value make(const Position& position) { + return ValueFactory<std::array<float, 3>>::make(position.getSpherical()); + } +}; + +template <typename T> +Value makeValue(T&& arg) { + return ValueFactory<std::decay_t<T>>::make(std::forward<T>(arg)); +} + +template <typename T> +StyleProperty makeStyleProperty(const PropertyValue<T>& value) { + return value.match([](const Undefined&) -> StyleProperty { return {}; }, + [](const T& t) -> StyleProperty { + return {makeValue(t), StyleProperty::Kind::Constant}; + }, + [](const PropertyExpression<T>& fn) -> StyleProperty { + return {fn.getExpression().serialize(), StyleProperty::Kind::Expression}; + }); +} + +inline StyleProperty makeStyleProperty(const TransitionOptions& value) { + return {makeValue(value), StyleProperty::Kind::Transition}; +} + +inline StyleProperty makeStyleProperty(const ColorRampPropertyValue& value) { + return {makeValue(value), StyleProperty::Kind::Expression}; +} + } // namespace conversion } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/expression/collator.hpp b/include/mbgl/style/expression/collator.hpp index 2a79e55556..51ba426fad 100644 --- a/include/mbgl/style/expression/collator.hpp +++ b/include/mbgl/style/expression/collator.hpp @@ -1,10 +1,9 @@ #pragma once -#include <mbgl/util/feature.hpp> +#include <mbgl/i18n/collator.hpp> #include <mbgl/util/optional.hpp> #include <string> -#include <memory> namespace mbgl { namespace style { @@ -20,8 +19,7 @@ public: std::string resolvedLocale() const; private: - class Impl; - std::shared_ptr<Impl> impl; + platform::Collator collator; }; } // namespace expression diff --git a/include/mbgl/style/expression/formatted.hpp b/include/mbgl/style/expression/formatted.hpp index f4f08e9197..bb3d609c91 100644 --- a/include/mbgl/style/expression/formatted.hpp +++ b/include/mbgl/style/expression/formatted.hpp @@ -48,7 +48,8 @@ public: bool operator==(const Formatted& ) const; std::string toString() const; - + mbgl::Value toObject() const; + bool empty() const { return sections.empty() || sections.at(0).text.empty(); } @@ -59,13 +60,18 @@ public: } // namespace expression namespace conversion { - + template <> -struct Converter<mbgl::style::expression::Formatted> { +struct Converter<expression::Formatted> { public: - optional<mbgl::style::expression::Formatted> operator()(const Convertible& value, Error& error) const; + optional<expression::Formatted> operator()(const Convertible& value, Error& error) const; }; - + +template <> +struct ValueFactory<expression::Formatted> { + static Value make(const expression::Formatted& formatted) { return formatted.toObject(); } +}; + } // namespace conversion } // namespace style diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 35577411eb..b50ca75067 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -1,9 +1,10 @@ #pragma once +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/style_property.hpp> +#include <mbgl/style/types.hpp> #include <mbgl/util/immutable.hpp> #include <mbgl/util/optional.hpp> -#include <mbgl/style/types.hpp> -#include <mbgl/style/conversion.hpp> #include <mapbox/weak.hpp> #include <mapbox/type_wrapper.hpp> @@ -110,9 +111,12 @@ public: // Dynamic properties virtual optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) = 0; - virtual optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) = 0; + virtual optional<conversion::Error> setPaintProperty(const std::string& name, + const conversion::Convertible& value) = 0; optional<conversion::Error> setVisibility(const conversion::Convertible& value); + virtual StyleProperty getProperty(const std::string&) const = 0; + // Private implementation // TODO : We should not have public mutable data members. class Impl; diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 4a73ae4a0b..ebdce35d0f 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<Color> getDefaultBackgroundColor(); diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index f171805806..842094f944 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> getDefaultCircleBlur(); diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 4ae59dfae3..c193cfb8d9 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -71,7 +71,7 @@ public: // Dynamic properties optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; - + StyleProperty getProperty(const std::string&) const final; // Private implementation class Impl; diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index 2e89032ae7..76c2359617 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> getDefaultFillExtrusionBase(); diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 0c4369de4c..9ec33d7e96 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<bool> getDefaultFillAntialias(); diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 2023d8c21e..2dec03b927 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -25,6 +25,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static ColorRampPropertyValue getDefaultHeatmapColor(); diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index f6b04a0062..824606c29b 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<Color> getDefaultHillshadeAccentColor(); diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 638db5fe4b..7b60fcf6ea 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -40,6 +40,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + <% if (layoutProperties.length) { -%> // Layout properties diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 8f1d51295c..4f2cf53708 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -27,6 +27,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Layout properties static PropertyValue<LineCapType> getDefaultLineCap(); diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index ba2ea45428..bff38d42ac 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -24,6 +24,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Paint properties static PropertyValue<float> getDefaultRasterBrightnessMax(); diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index b60e991f49..92e214919a 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -26,6 +26,8 @@ public: optional<conversion::Error> setLayoutProperty(const std::string& name, const conversion::Convertible& value) final; optional<conversion::Error> setPaintProperty(const std::string& name, const conversion::Convertible& value) final; + StyleProperty getProperty(const std::string& name) const final; + // Layout properties static PropertyValue<bool> getDefaultIconAllowOverlap(); diff --git a/include/mbgl/style/light.hpp b/include/mbgl/style/light.hpp index 9a82eb14b5..7434fb2882 100644 --- a/include/mbgl/style/light.hpp +++ b/include/mbgl/style/light.hpp @@ -6,6 +6,7 @@ #include <mbgl/style/conversion.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/style/style_property.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/style/types.hpp> #include <mbgl/util/immutable.hpp> @@ -22,6 +23,7 @@ public: // Dynamic properties optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value); + StyleProperty getProperty(const std::string&) const; static LightAnchorType getDefaultAnchor(); PropertyValue<LightAnchorType> getAnchor() const; diff --git a/include/mbgl/style/light.hpp.ejs b/include/mbgl/style/light.hpp.ejs index a5b907b4dc..e4661dc59b 100644 --- a/include/mbgl/style/light.hpp.ejs +++ b/include/mbgl/style/light.hpp.ejs @@ -9,6 +9,7 @@ #include <mbgl/style/conversion.hpp> #include <mbgl/style/property_value.hpp> +#include <mbgl/style/style_property.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/style/types.hpp> #include <mbgl/util/immutable.hpp> @@ -25,6 +26,7 @@ public: // Dynamic properties optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value); + StyleProperty getProperty(const std::string&) const; <% for (const property of properties) { -%> static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>(); diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index a256ad6f15..549393e9b2 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -2,6 +2,7 @@ #include <mbgl/style/expression/expression.hpp> #include <mbgl/style/source.hpp> +#include <mbgl/tile/tile_id.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/geojson.hpp> #include <mbgl/util/optional.hpp> @@ -34,6 +35,20 @@ struct GeoJSONOptions { using ClusterProperties = std::unordered_map<std::string, ClusterExpression>; ClusterProperties clusterProperties; }; +class GeoJSONData { +public: + static std::shared_ptr<GeoJSONData> create(const GeoJSON&, const GeoJSONOptions&); + + virtual ~GeoJSONData() = default; + virtual mapbox::feature::feature_collection<int16_t> getTile(const CanonicalTileID&) = 0; + + // SuperclusterData + virtual mapbox::feature::feature_collection<double> getChildren(const std::uint32_t) = 0; + virtual mapbox::feature::feature_collection<double> getLeaves(const std::uint32_t, + const std::uint32_t limit = 10u, + const std::uint32_t offset = 0u) = 0; + virtual std::uint8_t getClusterExpansionZoom(std::uint32_t) = 0; +}; class GeoJSONSource final : public Source { public: @@ -42,8 +57,10 @@ public: void setURL(const std::string& url); void setGeoJSON(const GeoJSON&); + void setGeoJSONData(std::shared_ptr<GeoJSONData>); optional<std::string> getURL() const; + const GeoJSONOptions& getOptions() const; class Impl; const Impl& impl() const; diff --git a/include/mbgl/style/style_property.hpp b/include/mbgl/style/style_property.hpp new file mode 100644 index 0000000000..fc34078dec --- /dev/null +++ b/include/mbgl/style/style_property.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include <mbgl/util/feature.hpp> + +namespace mbgl { +namespace style { + +/** + * @brief Generic representation of a style property. + */ +class StyleProperty { +public: + enum class Kind : uint8_t { Undefined, Constant, Expression, Transition }; + StyleProperty(Value value_, Kind kind_) : value(std::move(value_)), kind(kind_) {} + StyleProperty() = default; + const Value& getValue() const { return value; } + Value& getValue() { return value; } + Kind getKind() const { return kind; } + +private: + Value value; + Kind kind = Kind::Undefined; +}; + +} // namespace style +} // namespace mbgl |