diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-22 16:28:21 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-24 09:39:51 -0700 |
commit | 16c435b1517b15a5ea8654987979ef58800b838b (patch) | |
tree | 8f81c4e202e1337d0966a06f27842d45a113fded | |
parent | c4e4cc5081965d03132eea754c27ece3c95961cb (diff) | |
download | qtlocation-mapboxgl-16c435b1517b15a5ea8654987979ef58800b838b.tar.gz |
[core, node] Implement bindings for addLayer
83 files changed, 841 insertions, 815 deletions
diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp index eff7e293a3..2cb3ced376 100644 --- a/include/mbgl/style/conversion.hpp +++ b/include/mbgl/style/conversion.hpp @@ -28,6 +28,8 @@ namespace conversion { The implementation of `convert` requires that the following are legal expressions for a value `v` of type `const V&`: + * `isUndefined(v)` -- returns a boolean indication whether `v` is undefined or a JSON null + * `isArray(v)` -- returns a boolean indicating whether `v` represents a JSON array * `arrayLength(v)` -- called only if `isArray(v)`; returns a size_t length * `arrayMember(v)` -- called only if `isArray(v)`; returns `V` or `V&` @@ -36,6 +38,9 @@ namespace conversion { * `objectMember(v, name)` -- called only if `isObject(v)`; `name` is `const char *`; return value: * is true when evaluated in a boolean context iff the named member exists * is convertable to a `V` or `V&` when dereferenced + * `eachMember(v, [] (const std::string&, const V&) -> optional<Error> {...})` -- called + only if `isObject(v)`; calls the provided lambda once for each key and value of the object; + short-circuits if any call returns an `Error` * `toBool(v)` -- returns `optional<bool>`, absence indicating `v` is not a JSON boolean * `toNumber(v)` -- returns `optional<float>`, absence indicating `v` is not a JSON number diff --git a/include/mbgl/style/conversion/layer.hpp b/include/mbgl/style/conversion/layer.hpp new file mode 100644 index 0000000000..0539dcf9ad --- /dev/null +++ b/include/mbgl/style/conversion/layer.hpp @@ -0,0 +1,208 @@ +#pragma once + +#include <mbgl/style/layer.hpp> +#include <mbgl/style/layers/background_layer.hpp> +#include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/layers/line_layer.hpp> +#include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/constant.hpp> +#include <mbgl/style/conversion/filter.hpp> +#include <mbgl/style/conversion/make_property_setters.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +template <class V> +optional<Error> setLayoutProperty(Layer& layer, const std::string& name, const V& value) { + static const auto setters = makeLayoutPropertySetters<V>(); + auto it = setters.find(name); + if (it == setters.end()) { + return Error { "property not found" }; + } + return it->second(layer, value); +} + +template <class V> +optional<Error> setPaintProperty(Layer& layer, const std::string& name, const V& value, const optional<std::string>& klass) { + static const auto setters = makePaintPropertySetters<V>(); + auto it = setters.find(name); + if (it == setters.end()) { + return Error { "property not found" }; + } + return it->second(layer, value, klass); +} + +template <class V> +optional<Error> setPaintProperties(Layer& layer, const V& value) { + return eachMember(value, [&] (const std::string& paintName, const V& paintValue) -> optional<Error> { + if (paintName.compare(0, 5, "paint") != 0) { + return {}; + } + + optional<std::string> klass; + if (paintName.compare(0, 6, "paint.") == 0) { + klass = paintName.substr(6); + } + + return eachMember(paintValue, [&] (const std::string& k, const V& v) { + return setPaintProperty(layer, k, v, klass); + }); + }); +} + +template <> +struct Converter<std::unique_ptr<Layer>> { +public: + template <class V> + Result<std::unique_ptr<Layer>> operator()(const V& value) const { + if (!isObject(value)) { + return Error { "layer must be an object" }; + } + + auto idValue = objectMember(value, "id"); + if (!idValue) { + return Error { "layer must have an id" }; + } + + optional<std::string> id = toString(*idValue); + if (!id) { + return Error { "layer id must be a string" }; + } + + auto typeValue = objectMember(value, "type"); + if (!typeValue) { + return Error { "layer must have a type" }; + } + + optional<std::string> type = toString(*typeValue); + if (!type) { + return Error { "layer type must be a string" }; + } + + Result<std::unique_ptr<Layer>> converted; + + if (*type == "fill") { + converted = convertVectorLayer<FillLayer>(*id, value); + } else if (*type == "line") { + converted = convertVectorLayer<LineLayer>(*id, value); + } else if (*type == "circle") { + converted = convertVectorLayer<CircleLayer>(*id, value); + } else if (*type == "symbol") { + converted = convertVectorLayer<SymbolLayer>(*id, value); + } else if (*type == "raster") { + converted = convertRasterLayer(*id, value); + } else if (*type == "background") { + converted = convertBackgroundLayer(*id, value); + } else { + return Error { "invalid layer type" }; + } + + if (!converted) { + return converted; + } + + std::unique_ptr<Layer> layer = std::move(*converted); + + auto minzoomValue = objectMember(value, "minzoom"); + if (minzoomValue) { + optional<float> minzoom = toNumber(*minzoomValue); + if (!minzoom) { + return Error { "minzoom must be numeric" }; + } + layer->setMinZoom(*minzoom); + } + + auto maxzoomValue = objectMember(value, "maxzoom"); + if (maxzoomValue) { + optional<float> maxzoom = toNumber(*maxzoomValue); + if (!maxzoom) { + return Error { "maxzoom must be numeric" }; + } + layer->setMaxZoom(*maxzoom); + } + + auto layoutValue = objectMember(value, "layout"); + if (layoutValue) { + if (!isObject(*layoutValue)) { + return Error { "layout must be an object" }; + } + optional<Error> error = eachMember(*layoutValue, [&] (const std::string& k, const V& v) { + return setLayoutProperty(*layer, k, v); + }); + if (error) { + return *error; + } + } + + optional<Error> error = setPaintProperties(*layer, value); + if (error) { + return *error; + } + + return std::move(layer); + } + +private: + template <class LayerType, class V> + Result<std::unique_ptr<Layer>> convertVectorLayer(const std::string& id, const V& value) const { + auto sourceValue = objectMember(value, "source"); + if (!sourceValue) { + return Error { "layer must have a source" }; + } + + optional<std::string> source = toString(*sourceValue); + if (!source) { + return Error { "layer source must be a string" }; + } + + std::unique_ptr<LayerType> layer = std::make_unique<LayerType>(id, *source); + + auto sourceLayerValue = objectMember(value, "source-layer"); + if (sourceLayerValue) { + optional<std::string> sourceLayer = toString(*sourceLayerValue); + if (!sourceLayer) { + return Error { "layer source-layer must be a string" }; + } + layer->setSourceLayer(*sourceLayer); + } + + auto filterValue = objectMember(value, "filter"); + if (filterValue) { + Result<Filter> filter = convert<Filter>(*filterValue); + if (!filter) { + return filter.error(); + } + layer->setFilter(*filter); + } + + return std::move(layer); + } + + template <class V> + Result<std::unique_ptr<Layer>> convertRasterLayer(const std::string& id, const V& value) const { + auto sourceValue = objectMember(value, "source"); + if (!sourceValue) { + return Error { "layer must have a source" }; + } + + optional<std::string> source = toString(*sourceValue); + if (!source) { + return Error { "layer source must be a string" }; + } + + return std::make_unique<RasterLayer>(id, *source); + } + + template <class V> + Result<std::unique_ptr<Layer>> convertBackgroundLayer(const std::string& id, const V&) const { + return std::make_unique<BackgroundLayer>(id); + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/make_property_setters.hpp b/include/mbgl/style/conversion/make_property_setters.hpp new file mode 100644 index 0000000000..4c0089deaf --- /dev/null +++ b/include/mbgl/style/conversion/make_property_setters.hpp @@ -0,0 +1,133 @@ +// This file is generated. Edit make_property_setters.hpp.ejs, then run `make style-code`. + +#include <mbgl/style/conversion/property_setter.hpp> + +#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/layers/line_layer.hpp> +#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/style/layers/background_layer.hpp> + +#include <unordered_map> + +namespace mbgl { +namespace style { +namespace conversion { + +template <class V> +auto makeLayoutPropertySetters() { + std::unordered_map<std::string, LayoutPropertySetter<V>> result; + + result["visibility"] = &setVisibility<V>; + + + result["line-cap"] = makePropertySetter<V>(&LineLayer::setLineCap); + result["line-join"] = makePropertySetter<V>(&LineLayer::setLineJoin); + result["line-miter-limit"] = makePropertySetter<V>(&LineLayer::setLineMiterLimit); + result["line-round-limit"] = makePropertySetter<V>(&LineLayer::setLineRoundLimit); + + result["symbol-placement"] = makePropertySetter<V>(&SymbolLayer::setSymbolPlacement); + result["symbol-spacing"] = makePropertySetter<V>(&SymbolLayer::setSymbolSpacing); + result["symbol-avoid-edges"] = makePropertySetter<V>(&SymbolLayer::setSymbolAvoidEdges); + result["icon-allow-overlap"] = makePropertySetter<V>(&SymbolLayer::setIconAllowOverlap); + result["icon-ignore-placement"] = makePropertySetter<V>(&SymbolLayer::setIconIgnorePlacement); + result["icon-optional"] = makePropertySetter<V>(&SymbolLayer::setIconOptional); + result["icon-rotation-alignment"] = makePropertySetter<V>(&SymbolLayer::setIconRotationAlignment); + result["icon-size"] = makePropertySetter<V>(&SymbolLayer::setIconSize); + result["icon-text-fit"] = makePropertySetter<V>(&SymbolLayer::setIconTextFit); + result["icon-text-fit-padding"] = makePropertySetter<V>(&SymbolLayer::setIconTextFitPadding); + result["icon-image"] = makePropertySetter<V>(&SymbolLayer::setIconImage); + result["icon-rotate"] = makePropertySetter<V>(&SymbolLayer::setIconRotate); + result["icon-padding"] = makePropertySetter<V>(&SymbolLayer::setIconPadding); + result["icon-keep-upright"] = makePropertySetter<V>(&SymbolLayer::setIconKeepUpright); + result["icon-offset"] = makePropertySetter<V>(&SymbolLayer::setIconOffset); + result["text-pitch-alignment"] = makePropertySetter<V>(&SymbolLayer::setTextPitchAlignment); + result["text-rotation-alignment"] = makePropertySetter<V>(&SymbolLayer::setTextRotationAlignment); + result["text-field"] = makePropertySetter<V>(&SymbolLayer::setTextField); + result["text-font"] = makePropertySetter<V>(&SymbolLayer::setTextFont); + result["text-size"] = makePropertySetter<V>(&SymbolLayer::setTextSize); + result["text-max-width"] = makePropertySetter<V>(&SymbolLayer::setTextMaxWidth); + result["text-line-height"] = makePropertySetter<V>(&SymbolLayer::setTextLineHeight); + result["text-letter-spacing"] = makePropertySetter<V>(&SymbolLayer::setTextLetterSpacing); + result["text-justify"] = makePropertySetter<V>(&SymbolLayer::setTextJustify); + result["text-anchor"] = makePropertySetter<V>(&SymbolLayer::setTextAnchor); + result["text-max-angle"] = makePropertySetter<V>(&SymbolLayer::setTextMaxAngle); + result["text-rotate"] = makePropertySetter<V>(&SymbolLayer::setTextRotate); + result["text-padding"] = makePropertySetter<V>(&SymbolLayer::setTextPadding); + result["text-keep-upright"] = makePropertySetter<V>(&SymbolLayer::setTextKeepUpright); + result["text-transform"] = makePropertySetter<V>(&SymbolLayer::setTextTransform); + result["text-offset"] = makePropertySetter<V>(&SymbolLayer::setTextOffset); + result["text-allow-overlap"] = makePropertySetter<V>(&SymbolLayer::setTextAllowOverlap); + result["text-ignore-placement"] = makePropertySetter<V>(&SymbolLayer::setTextIgnorePlacement); + result["text-optional"] = makePropertySetter<V>(&SymbolLayer::setTextOptional); + + + + + return result; +} + +template <class V> +auto makePaintPropertySetters() { + std::unordered_map<std::string, PaintPropertySetter<V>> result; + + result["fill-antialias"] = makePropertySetter<V>(&FillLayer::setFillAntialias); + result["fill-opacity"] = makePropertySetter<V>(&FillLayer::setFillOpacity); + result["fill-color"] = makePropertySetter<V>(&FillLayer::setFillColor); + result["fill-outline-color"] = makePropertySetter<V>(&FillLayer::setFillOutlineColor); + result["fill-translate"] = makePropertySetter<V>(&FillLayer::setFillTranslate); + result["fill-translate-anchor"] = makePropertySetter<V>(&FillLayer::setFillTranslateAnchor); + result["fill-pattern"] = makePropertySetter<V>(&FillLayer::setFillPattern); + + result["line-opacity"] = makePropertySetter<V>(&LineLayer::setLineOpacity); + result["line-color"] = makePropertySetter<V>(&LineLayer::setLineColor); + result["line-translate"] = makePropertySetter<V>(&LineLayer::setLineTranslate); + result["line-translate-anchor"] = makePropertySetter<V>(&LineLayer::setLineTranslateAnchor); + result["line-width"] = makePropertySetter<V>(&LineLayer::setLineWidth); + result["line-gap-width"] = makePropertySetter<V>(&LineLayer::setLineGapWidth); + result["line-offset"] = makePropertySetter<V>(&LineLayer::setLineOffset); + result["line-blur"] = makePropertySetter<V>(&LineLayer::setLineBlur); + result["line-dasharray"] = makePropertySetter<V>(&LineLayer::setLineDasharray); + result["line-pattern"] = makePropertySetter<V>(&LineLayer::setLinePattern); + + result["icon-opacity"] = makePropertySetter<V>(&SymbolLayer::setIconOpacity); + result["icon-color"] = makePropertySetter<V>(&SymbolLayer::setIconColor); + result["icon-halo-color"] = makePropertySetter<V>(&SymbolLayer::setIconHaloColor); + result["icon-halo-width"] = makePropertySetter<V>(&SymbolLayer::setIconHaloWidth); + result["icon-halo-blur"] = makePropertySetter<V>(&SymbolLayer::setIconHaloBlur); + result["icon-translate"] = makePropertySetter<V>(&SymbolLayer::setIconTranslate); + result["icon-translate-anchor"] = makePropertySetter<V>(&SymbolLayer::setIconTranslateAnchor); + result["text-opacity"] = makePropertySetter<V>(&SymbolLayer::setTextOpacity); + result["text-color"] = makePropertySetter<V>(&SymbolLayer::setTextColor); + result["text-halo-color"] = makePropertySetter<V>(&SymbolLayer::setTextHaloColor); + result["text-halo-width"] = makePropertySetter<V>(&SymbolLayer::setTextHaloWidth); + result["text-halo-blur"] = makePropertySetter<V>(&SymbolLayer::setTextHaloBlur); + result["text-translate"] = makePropertySetter<V>(&SymbolLayer::setTextTranslate); + result["text-translate-anchor"] = makePropertySetter<V>(&SymbolLayer::setTextTranslateAnchor); + + result["circle-radius"] = makePropertySetter<V>(&CircleLayer::setCircleRadius); + result["circle-color"] = makePropertySetter<V>(&CircleLayer::setCircleColor); + result["circle-blur"] = makePropertySetter<V>(&CircleLayer::setCircleBlur); + result["circle-opacity"] = makePropertySetter<V>(&CircleLayer::setCircleOpacity); + result["circle-translate"] = makePropertySetter<V>(&CircleLayer::setCircleTranslate); + result["circle-translate-anchor"] = makePropertySetter<V>(&CircleLayer::setCircleTranslateAnchor); + + result["raster-opacity"] = makePropertySetter<V>(&RasterLayer::setRasterOpacity); + result["raster-hue-rotate"] = makePropertySetter<V>(&RasterLayer::setRasterHueRotate); + result["raster-brightness-min"] = makePropertySetter<V>(&RasterLayer::setRasterBrightnessMin); + result["raster-brightness-max"] = makePropertySetter<V>(&RasterLayer::setRasterBrightnessMax); + result["raster-saturation"] = makePropertySetter<V>(&RasterLayer::setRasterSaturation); + result["raster-contrast"] = makePropertySetter<V>(&RasterLayer::setRasterContrast); + result["raster-fade-duration"] = makePropertySetter<V>(&RasterLayer::setRasterFadeDuration); + + result["background-color"] = makePropertySetter<V>(&BackgroundLayer::setBackgroundColor); + result["background-pattern"] = makePropertySetter<V>(&BackgroundLayer::setBackgroundPattern); + result["background-opacity"] = makePropertySetter<V>(&BackgroundLayer::setBackgroundOpacity); + + return result; +} + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/make_property_setters.hpp.ejs b/include/mbgl/style/conversion/make_property_setters.hpp.ejs new file mode 100644 index 0000000000..493c68ea31 --- /dev/null +++ b/include/mbgl/style/conversion/make_property_setters.hpp.ejs @@ -0,0 +1,45 @@ +// This file is generated. Edit make_property_setters.hpp.ejs, then run `make style-code`. + +#include <mbgl/style/conversion/property_setter.hpp> + +<% for (const layer of locals.layers) { -%> +#include <mbgl/style/layers/<%- layer.type %>_layer.hpp> +<% } -%> + +#include <unordered_map> + +namespace mbgl { +namespace style { +namespace conversion { + +template <class V> +auto makeLayoutPropertySetters() { + std::unordered_map<std::string, LayoutPropertySetter<V>> result; + + result["visibility"] = &setVisibility<V>; + +<% for (const layer of locals.layers) { -%> +<% for (const property of layer.layoutProperties) { -%> + result["<%- property.name %>"] = makePropertySetter<V>(&<%- camelize(layer.type) %>Layer::set<%- camelize(property.name) %>); +<% } -%> + +<% } -%> + return result; +} + +template <class V> +auto makePaintPropertySetters() { + std::unordered_map<std::string, PaintPropertySetter<V>> result; + +<% for (const layer of locals.layers) { -%> +<% for (const property of layer.paintProperties) { -%> + result["<%- property.name %>"] = makePropertySetter<V>(&<%- camelize(layer.type) %>Layer::set<%- camelize(property.name) %>); +<% } -%> + +<% } -%> + return result; +} + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/property_setter.hpp b/include/mbgl/style/conversion/property_setter.hpp new file mode 100644 index 0000000000..38dd934252 --- /dev/null +++ b/include/mbgl/style/conversion/property_setter.hpp @@ -0,0 +1,55 @@ +#include <mbgl/style/layer.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/constant.hpp> +#include <mbgl/style/conversion/property_value.hpp> + +#include <functional> +#include <string> + +namespace mbgl { +namespace style { +namespace conversion { + +template <class V> +using LayoutPropertySetter = std::function<optional<Error> (Layer&, const V&)>; + +template <class V> +using PaintPropertySetter = std::function<optional<Error> (Layer&, const V&, const optional<std::string>&)>; + +template <class V, class L, class T, class...Args> +auto makePropertySetter(void (L::*setter)(PropertyValue<T>, const Args&...args)) { + return [setter] (Layer& layer, const V& value, const Args&...args) -> optional<Error> { + L* typedLayer = layer.as<L>(); + if (!typedLayer) { + return Error { "layer doesn't support this property" }; + } + + Result<PropertyValue<T>> typedValue = convert<PropertyValue<T>>(value); + if (!typedValue) { + return typedValue.error(); + } + + (typedLayer->*setter)(*typedValue, args...); + return {}; + }; +} + +template <class V> +optional<Error> setVisibility(Layer& layer, const V& value) { + if (isUndefined(value)) { + layer.setVisibility(VisibilityType::Visible); + return {}; + } + + Result<VisibilityType> visibility = convert<VisibilityType>(value); + if (!visibility) { + return visibility.error(); + } + + layer.setVisibility(*visibility); + return {}; +} + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp index 840643abbe..de95b56155 100644 --- a/include/mbgl/style/conversion/property_value.hpp +++ b/include/mbgl/style/conversion/property_value.hpp @@ -13,7 +13,9 @@ template <class T> struct Converter<PropertyValue<T>> { template <class V> Result<PropertyValue<T>> operator()(const V& value) const { - if (isObject(value)) { + if (isUndefined(value)) { + return {}; + } else if (isObject(value)) { Result<Function<T>> function = convert<Function<T>>(value); if (!function) { return function.error(); diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 2eb84ee499..ac97ec2e6d 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -19,13 +19,13 @@ public: // Paint properties PropertyValue<Color> getBackgroundColor() const; - void setBackgroundColor(PropertyValue<Color>); + void setBackgroundColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<std::string> getBackgroundPattern() const; - void setBackgroundPattern(PropertyValue<std::string>); + void setBackgroundPattern(PropertyValue<std::string>, const optional<std::string>& klass = {}); PropertyValue<float> getBackgroundOpacity() const; - void setBackgroundOpacity(PropertyValue<float>); + void setBackgroundOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); // Private implementation diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index 9c2b458d4b..c8d99ab30e 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -27,22 +27,22 @@ public: // Paint properties PropertyValue<float> getCircleRadius() const; - void setCircleRadius(PropertyValue<float>); + void setCircleRadius(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<Color> getCircleColor() const; - void setCircleColor(PropertyValue<Color>); + void setCircleColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<float> getCircleBlur() const; - void setCircleBlur(PropertyValue<float>); + void setCircleBlur(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getCircleOpacity() const; - void setCircleOpacity(PropertyValue<float>); + void setCircleOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<std::array<float, 2>> getCircleTranslate() const; - void setCircleTranslate(PropertyValue<std::array<float, 2>>); + void setCircleTranslate(PropertyValue<std::array<float, 2>>, const optional<std::string>& klass = {}); PropertyValue<TranslateAnchorType> getCircleTranslateAnchor() const; - void setCircleTranslateAnchor(PropertyValue<TranslateAnchorType>); + void setCircleTranslateAnchor(PropertyValue<TranslateAnchorType>, const optional<std::string>& klass = {}); // Private implementation diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 90538dd3ea..e70d67f538 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -27,25 +27,25 @@ public: // Paint properties PropertyValue<bool> getFillAntialias() const; - void setFillAntialias(PropertyValue<bool>); + void setFillAntialias(PropertyValue<bool>, const optional<std::string>& klass = {}); PropertyValue<float> getFillOpacity() const; - void setFillOpacity(PropertyValue<float>); + void setFillOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<Color> getFillColor() const; - void setFillColor(PropertyValue<Color>); + void setFillColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<Color> getFillOutlineColor() const; - void setFillOutlineColor(PropertyValue<Color>); + void setFillOutlineColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<std::array<float, 2>> getFillTranslate() const; - void setFillTranslate(PropertyValue<std::array<float, 2>>); + void setFillTranslate(PropertyValue<std::array<float, 2>>, const optional<std::string>& klass = {}); PropertyValue<TranslateAnchorType> getFillTranslateAnchor() const; - void setFillTranslateAnchor(PropertyValue<TranslateAnchorType>); + void setFillTranslateAnchor(PropertyValue<TranslateAnchorType>, const optional<std::string>& klass = {}); PropertyValue<std::string> getFillPattern() const; - void setFillPattern(PropertyValue<std::string>); + void setFillPattern(PropertyValue<std::string>, const optional<std::string>& klass = {}); // Private implementation diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 60365be906..aaae30287c 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -54,7 +54,7 @@ public: <% for (const property of paintProperties) { -%> PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; - void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>); + void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>, const optional<std::string>& klass = {}); <% } -%> // Private implementation diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 4ffeee114a..abcb425b96 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -43,34 +43,34 @@ public: // Paint properties PropertyValue<float> getLineOpacity() const; - void setLineOpacity(PropertyValue<float>); + void setLineOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<Color> getLineColor() const; - void setLineColor(PropertyValue<Color>); + void setLineColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<std::array<float, 2>> getLineTranslate() const; - void setLineTranslate(PropertyValue<std::array<float, 2>>); + void setLineTranslate(PropertyValue<std::array<float, 2>>, const optional<std::string>& klass = {}); PropertyValue<TranslateAnchorType> getLineTranslateAnchor() const; - void setLineTranslateAnchor(PropertyValue<TranslateAnchorType>); + void setLineTranslateAnchor(PropertyValue<TranslateAnchorType>, const optional<std::string>& klass = {}); PropertyValue<float> getLineWidth() const; - void setLineWidth(PropertyValue<float>); + void setLineWidth(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getLineGapWidth() const; - void setLineGapWidth(PropertyValue<float>); + void setLineGapWidth(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getLineOffset() const; - void setLineOffset(PropertyValue<float>); + void setLineOffset(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getLineBlur() const; - void setLineBlur(PropertyValue<float>); + void setLineBlur(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<std::vector<float>> getLineDasharray() const; - void setLineDasharray(PropertyValue<std::vector<float>>); + void setLineDasharray(PropertyValue<std::vector<float>>, const optional<std::string>& klass = {}); PropertyValue<std::string> getLinePattern() const; - void setLinePattern(PropertyValue<std::string>); + void setLinePattern(PropertyValue<std::string>, const optional<std::string>& klass = {}); // Private implementation diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index 372434e46d..dea0c26bf3 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -22,25 +22,25 @@ public: // Paint properties PropertyValue<float> getRasterOpacity() const; - void setRasterOpacity(PropertyValue<float>); + void setRasterOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getRasterHueRotate() const; - void setRasterHueRotate(PropertyValue<float>); + void setRasterHueRotate(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getRasterBrightnessMin() const; - void setRasterBrightnessMin(PropertyValue<float>); + void setRasterBrightnessMin(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getRasterBrightnessMax() const; - void setRasterBrightnessMax(PropertyValue<float>); + void setRasterBrightnessMax(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getRasterSaturation() const; - void setRasterSaturation(PropertyValue<float>); + void setRasterSaturation(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getRasterContrast() const; - void setRasterContrast(PropertyValue<float>); + void setRasterContrast(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getRasterFadeDuration() const; - void setRasterFadeDuration(PropertyValue<float>); + void setRasterFadeDuration(PropertyValue<float>, const optional<std::string>& klass = {}); // Private implementation diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index b21c8deaf7..77b63d9b91 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -133,46 +133,46 @@ public: // Paint properties PropertyValue<float> getIconOpacity() const; - void setIconOpacity(PropertyValue<float>); + void setIconOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<Color> getIconColor() const; - void setIconColor(PropertyValue<Color>); + void setIconColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<Color> getIconHaloColor() const; - void setIconHaloColor(PropertyValue<Color>); + void setIconHaloColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<float> getIconHaloWidth() const; - void setIconHaloWidth(PropertyValue<float>); + void setIconHaloWidth(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getIconHaloBlur() const; - void setIconHaloBlur(PropertyValue<float>); + void setIconHaloBlur(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<std::array<float, 2>> getIconTranslate() const; - void setIconTranslate(PropertyValue<std::array<float, 2>>); + void setIconTranslate(PropertyValue<std::array<float, 2>>, const optional<std::string>& klass = {}); PropertyValue<TranslateAnchorType> getIconTranslateAnchor() const; - void setIconTranslateAnchor(PropertyValue<TranslateAnchorType>); + void setIconTranslateAnchor(PropertyValue<TranslateAnchorType>, const optional<std::string>& klass = {}); PropertyValue<float> getTextOpacity() const; - void setTextOpacity(PropertyValue<float>); + void setTextOpacity(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<Color> getTextColor() const; - void setTextColor(PropertyValue<Color>); + void setTextColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<Color> getTextHaloColor() const; - void setTextHaloColor(PropertyValue<Color>); + void setTextHaloColor(PropertyValue<Color>, const optional<std::string>& klass = {}); PropertyValue<float> getTextHaloWidth() const; - void setTextHaloWidth(PropertyValue<float>); + void setTextHaloWidth(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<float> getTextHaloBlur() const; - void setTextHaloBlur(PropertyValue<float>); + void setTextHaloBlur(PropertyValue<float>, const optional<std::string>& klass = {}); PropertyValue<std::array<float, 2>> getTextTranslate() const; - void setTextTranslate(PropertyValue<std::array<float, 2>>); + void setTextTranslate(PropertyValue<std::array<float, 2>>, const optional<std::string>& klass = {}); PropertyValue<TranslateAnchorType> getTextTranslateAnchor() const; - void setTextTranslateAnchor(PropertyValue<TranslateAnchorType>); + void setTextTranslateAnchor(PropertyValue<TranslateAnchorType>, const optional<std::string>& klass = {}); // Private implementation diff --git a/package.json b/package.json index 592559175f..97edceb9c9 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "express": "^4.11.1", "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#59e998295d548f208ee3ec10cdd21ff2630e2079", "mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#194fc55b6a7dd54c1e2cf2dd9048fbb5e836716d", - "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#9a7de2fb72607be6ffa0040bf3d84651719a45e3", + "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#1633d164231dddf006777366de82178bf34fe866", "node-gyp": "^3.3.1", "request": "^2.72.0", "tape": "^4.5.1" diff --git a/platform/node/src/node_conversion.hpp b/platform/node/src/node_conversion.hpp index 03c13b5846..2418a7a6e4 100644 --- a/platform/node/src/node_conversion.hpp +++ b/platform/node/src/node_conversion.hpp @@ -8,11 +8,17 @@ #include <mbgl/util/optional.hpp> #include <mbgl/util/feature.hpp> +#include <mbgl/style/conversion.hpp> namespace mbgl { namespace style { namespace conversion { +inline bool isUndefined(v8::Local<v8::Value> value) { + Nan::HandleScope scope; + return value->IsUndefined() || value->IsNull(); +} + inline bool isArray(v8::Local<v8::Value> value) { Nan::HandleScope scope; return value->IsArray(); @@ -35,16 +41,31 @@ inline bool isObject(v8::Local<v8::Value> value) { inline optional<v8::Local<v8::Value>> objectMember(v8::Local<v8::Value> value, const char * name) { Nan::EscapableHandleScope scope; - if (!Nan::Has(value.As<v8::Array>(), Nan::New(name).ToLocalChecked()).FromJust()) { + if (!Nan::Has(value->ToObject(), Nan::New(name).ToLocalChecked()).FromJust()) { return {}; } - Nan::MaybeLocal<v8::Value> result = Nan::Get(value.As<v8::Array>(), Nan::New(name).ToLocalChecked()); + Nan::MaybeLocal<v8::Value> result = Nan::Get(value->ToObject(), Nan::New(name).ToLocalChecked()); if (result.IsEmpty()) { return {}; } return scope.Escape(result.ToLocalChecked()); } +template <class Fn> +optional<Error> eachMember(v8::Local<v8::Value> value, Fn&& fn) { + Nan::HandleScope scope; + v8::Local<v8::Array> names = value->ToObject()->GetOwnPropertyNames(); + for (uint32_t i = 0; i < names->Length(); ++i) { + v8::Local<v8::Value> k = Nan::Get(names, i).ToLocalChecked(); + v8::Local<v8::Value> v = Nan::Get(value->ToObject(), k).ToLocalChecked(); + optional<Error> result = fn(*Nan::Utf8String(k), v); + if (result) { + return result; + } + } + return {}; +} + inline optional<bool> toBool(v8::Local<v8::Value> value) { Nan::HandleScope scope; if (!value->IsBoolean()) { diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index e6ee84ee53..c73d3850f2 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -1,12 +1,12 @@ #include "node_map.hpp" #include "node_request.hpp" #include "node_feature.hpp" -#include "node_style_properties.hpp" +#include "node_conversion.hpp" #include <mbgl/platform/default/headless_display.hpp> #include <mbgl/util/exception.hpp> -#include <mbgl/style/layer.hpp> -#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/conversion/layer.hpp> +#include <mbgl/style/conversion/filter.hpp> #include <unistd.h> @@ -56,6 +56,7 @@ NAN_MODULE_INIT(NodeMap::Init) { Nan::SetPrototypeMethod(tpl, "release", Release); Nan::SetPrototypeMethod(tpl, "addClass", AddClass); + Nan::SetPrototypeMethod(tpl, "addLayer", AddLayer); Nan::SetPrototypeMethod(tpl, "setLayoutProperty", SetLayoutProperty); Nan::SetPrototypeMethod(tpl, "setPaintProperty", SetPaintProperty); Nan::SetPrototypeMethod(tpl, "setFilter", SetFilter); @@ -483,7 +484,30 @@ NAN_METHOD(NodeMap::AddClass) { info.GetReturnValue().SetUndefined(); } -void NodeMap::setProperty(const Nan::FunctionCallbackInfo<v8::Value>& info, const PropertySetters& setters) { +NAN_METHOD(NodeMap::AddLayer) { + using namespace mbgl::style; + using namespace mbgl::style::conversion; + + auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder()); + if (!nodeMap->map) return Nan::ThrowError(releasedMessage()); + + if (info.Length() != 1) { + return Nan::ThrowTypeError("One argument required"); + } + + Result<std::unique_ptr<Layer>> layer = convert<std::unique_ptr<Layer>>(info[0]); + if (!layer) { + Nan::ThrowTypeError(layer.error().message); + return; + } + + nodeMap->map->addLayer(std::move(*layer)); +} + +NAN_METHOD(NodeMap::SetLayoutProperty) { + using namespace mbgl::style; + using namespace mbgl::style::conversion; + auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder()); if (!nodeMap->map) return Nan::ThrowError(releasedMessage()); @@ -504,30 +528,57 @@ void NodeMap::setProperty(const Nan::FunctionCallbackInfo<v8::Value>& info, cons return Nan::ThrowTypeError("Second argument must be a string"); } - auto it = setters.find(*Nan::Utf8String(info[1])); - if (it == setters.end()) { - return Nan::ThrowTypeError("property not found"); - } - - if (!it->second(*layer, info[2])) { - return; + mbgl::optional<Error> error = setLayoutProperty(*layer, *Nan::Utf8String(info[1]), info[2]); + if (error) { + return Nan::ThrowTypeError(error->message); } nodeMap->map->update(mbgl::Update::RecalculateStyle); info.GetReturnValue().SetUndefined(); } -NAN_METHOD(NodeMap::SetLayoutProperty) { - static const PropertySetters setters = makeLayoutPropertySetters(); - setProperty(info, setters); -} - NAN_METHOD(NodeMap::SetPaintProperty) { - static const PropertySetters setters = makePaintPropertySetters(); - setProperty(info, setters); + using namespace mbgl::style; + using namespace mbgl::style::conversion; + + auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder()); + if (!nodeMap->map) return Nan::ThrowError(releasedMessage()); + + if (info.Length() < 3) { + return Nan::ThrowTypeError("Three arguments required"); + } + + if (!info[0]->IsString()) { + return Nan::ThrowTypeError("First argument must be a string"); + } + + mbgl::style::Layer* layer = nodeMap->map->getLayer(*Nan::Utf8String(info[0])); + if (!layer) { + return Nan::ThrowTypeError("layer not found"); + } + + if (!info[1]->IsString()) { + return Nan::ThrowTypeError("Second argument must be a string"); + } + + mbgl::optional<std::string> klass; + if (info.Length() == 4 && info[3]->IsString()) { + klass = std::string(*Nan::Utf8String(info[3])); + } + + mbgl::optional<Error> error = setPaintProperty(*layer, *Nan::Utf8String(info[1]), info[2], klass); + if (error) { + return Nan::ThrowTypeError(error->message); + } + + nodeMap->map->update(mbgl::Update::RecalculateStyle); + info.GetReturnValue().SetUndefined(); } NAN_METHOD(NodeMap::SetFilter) { + using namespace mbgl::style; + using namespace mbgl::style::conversion; + auto nodeMap = Nan::ObjectWrap::Unwrap<NodeMap>(info.Holder()); if (!nodeMap->map) return Nan::ThrowError(releasedMessage()); @@ -544,23 +595,39 @@ NAN_METHOD(NodeMap::SetFilter) { return Nan::ThrowTypeError("layer not found"); } - mbgl::style::Filter filter; + Filter filter; if (!info[1]->IsNull() && !info[1]->IsUndefined()) { - mbgl::style::conversion::Result<mbgl::style::Filter> converted - = mbgl::style::conversion::convertFilter(info[1]); - if (converted.is<mbgl::style::conversion::Error>()) { - Nan::ThrowTypeError(converted.get<mbgl::style::conversion::Error>().message); + Result<Filter> converted = convert<Filter>(info[1]); + if (!converted) { + Nan::ThrowTypeError(converted.error().message); return; } - filter = std::move(converted.get<mbgl::style::Filter>()); + filter = std::move(*converted); } - if (!setFilter(*layer, filter)) { + if (layer->is<FillLayer>()) { + layer->as<FillLayer>()->setFilter(filter); + info.GetReturnValue().SetUndefined(); + return; + } + if (layer->is<LineLayer>()) { + layer->as<LineLayer>()->setFilter(filter); + info.GetReturnValue().SetUndefined(); + return; + } + if (layer->is<SymbolLayer>()) { + layer->as<SymbolLayer>()->setFilter(filter); + info.GetReturnValue().SetUndefined(); + return; + } + if (layer->is<CircleLayer>()) { + layer->as<CircleLayer>()->setFilter(filter); + info.GetReturnValue().SetUndefined(); return; } - info.GetReturnValue().SetUndefined(); + Nan::ThrowTypeError("layer doesn't support filters"); } NAN_METHOD(NodeMap::DumpDebugLogs) { diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp index 58773e33da..8e4b073134 100644 --- a/platform/node/src/node_map.hpp +++ b/platform/node/src/node_map.hpp @@ -1,7 +1,5 @@ #pragma once -#include "node_style.hpp" - #include <mbgl/map/map.hpp> #include <mbgl/storage/file_source.hpp> #include <mbgl/platform/default/headless_view.hpp> @@ -28,14 +26,13 @@ public: static NAN_METHOD(Render); static NAN_METHOD(Release); static NAN_METHOD(AddClass); + static NAN_METHOD(AddLayer); static NAN_METHOD(SetLayoutProperty); static NAN_METHOD(SetPaintProperty); static NAN_METHOD(SetFilter); static NAN_METHOD(DumpDebugLogs); static NAN_METHOD(QueryRenderedFeatures); - static void setProperty(const Nan::FunctionCallbackInfo<v8::Value>&, const PropertySetters&); - void startRender(RenderOptions options); void renderFinished(); diff --git a/platform/node/src/node_style.hpp b/platform/node/src/node_style.hpp deleted file mode 100644 index 9befd00d10..0000000000 --- a/platform/node/src/node_style.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once - -#include "node_conversion.hpp" - -#include <mbgl/style/layer.hpp> -#include <mbgl/style/conversion.hpp> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wshadow" -#include <nan.h> -#pragma GCC diagnostic pop - -#include <functional> -#include <string> -#include <unordered_map> - -namespace node_mbgl { - -using PropertySetter = std::function<bool (mbgl::style::Layer&, const v8::Local<v8::Value>&)>; -using PropertySetters = std::unordered_map<std::string, PropertySetter>; - -template <class L, class V> -PropertySetter makePropertySetter(void (L::*setter)(mbgl::style::PropertyValue<V>)) { - return [setter] (mbgl::style::Layer& layer, const v8::Local<v8::Value>& value) { - L* typedLayer = layer.as<L>(); - if (!typedLayer) { - Nan::ThrowTypeError("layer doesn't support this property"); - return false; - } - - if (value->IsNull() || value->IsUndefined()) { - (typedLayer->*setter)(mbgl::style::PropertyValue<V>()); - return true; - } - - mbgl::style::conversion::Result<mbgl::style::PropertyValue<V>> typedValue - = mbgl::style::conversion::convertPropertyValue<V>(value); - if (typedValue.template is<mbgl::style::conversion::Error>()) { - Nan::ThrowTypeError(typedValue.template get<mbgl::style::conversion::Error>().message); - return false; - } - - (typedLayer->*setter)(typedValue.template get<mbgl::style::PropertyValue<V>>()); - return true; - }; -} - -inline bool setVisibility(mbgl::style::Layer& layer, const v8::Local<v8::Value>& value) { - if (value->IsNull() || value->IsUndefined()) { - layer.setVisibility(mbgl::style::VisibilityType::Visible); - return true; - } - - if (!value->IsString()) { - Nan::ThrowTypeError("visibility value must be \"visible\" or \"none\""); - return false; - } - - layer.setVisibility(std::string(*Nan::Utf8String(value)) == "none" - ? mbgl::style::VisibilityType::None - : mbgl::style::VisibilityType::Visible); - - return true; -} - -} diff --git a/platform/node/src/node_style_properties.hpp b/platform/node/src/node_style_properties.hpp deleted file mode 100644 index 0e3100207a..0000000000 --- a/platform/node/src/node_style_properties.hpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "node_style.hpp" - -#include <mbgl/style/layers/fill_layer.hpp> -#include <mbgl/style/layers/line_layer.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> -#include <mbgl/style/layers/circle_layer.hpp> -#include <mbgl/style/layers/raster_layer.hpp> -#include <mbgl/style/layers/background_layer.hpp> - -namespace node_mbgl { - -inline PropertySetters makeLayoutPropertySetters() { - using namespace mbgl::style; - PropertySetters result; - - result["visibility"] = &setVisibility; - - - result["line-cap"] = makePropertySetter(&LineLayer::setLineCap); - result["line-join"] = makePropertySetter(&LineLayer::setLineJoin); - result["line-miter-limit"] = makePropertySetter(&LineLayer::setLineMiterLimit); - result["line-round-limit"] = makePropertySetter(&LineLayer::setLineRoundLimit); - - result["symbol-placement"] = makePropertySetter(&SymbolLayer::setSymbolPlacement); - result["symbol-spacing"] = makePropertySetter(&SymbolLayer::setSymbolSpacing); - result["symbol-avoid-edges"] = makePropertySetter(&SymbolLayer::setSymbolAvoidEdges); - result["icon-allow-overlap"] = makePropertySetter(&SymbolLayer::setIconAllowOverlap); - result["icon-ignore-placement"] = makePropertySetter(&SymbolLayer::setIconIgnorePlacement); - result["icon-optional"] = makePropertySetter(&SymbolLayer::setIconOptional); - result["icon-rotation-alignment"] = makePropertySetter(&SymbolLayer::setIconRotationAlignment); - result["icon-size"] = makePropertySetter(&SymbolLayer::setIconSize); - result["icon-text-fit"] = makePropertySetter(&SymbolLayer::setIconTextFit); - result["icon-text-fit-padding"] = makePropertySetter(&SymbolLayer::setIconTextFitPadding); - result["icon-image"] = makePropertySetter(&SymbolLayer::setIconImage); - result["icon-rotate"] = makePropertySetter(&SymbolLayer::setIconRotate); - result["icon-padding"] = makePropertySetter(&SymbolLayer::setIconPadding); - result["icon-keep-upright"] = makePropertySetter(&SymbolLayer::setIconKeepUpright); - result["icon-offset"] = makePropertySetter(&SymbolLayer::setIconOffset); - result["text-pitch-alignment"] = makePropertySetter(&SymbolLayer::setTextPitchAlignment); - result["text-rotation-alignment"] = makePropertySetter(&SymbolLayer::setTextRotationAlignment); - result["text-field"] = makePropertySetter(&SymbolLayer::setTextField); - result["text-font"] = makePropertySetter(&SymbolLayer::setTextFont); - result["text-size"] = makePropertySetter(&SymbolLayer::setTextSize); - result["text-max-width"] = makePropertySetter(&SymbolLayer::setTextMaxWidth); - result["text-line-height"] = makePropertySetter(&SymbolLayer::setTextLineHeight); - result["text-letter-spacing"] = makePropertySetter(&SymbolLayer::setTextLetterSpacing); - result["text-justify"] = makePropertySetter(&SymbolLayer::setTextJustify); - result["text-anchor"] = makePropertySetter(&SymbolLayer::setTextAnchor); - result["text-max-angle"] = makePropertySetter(&SymbolLayer::setTextMaxAngle); - result["text-rotate"] = makePropertySetter(&SymbolLayer::setTextRotate); - result["text-padding"] = makePropertySetter(&SymbolLayer::setTextPadding); - result["text-keep-upright"] = makePropertySetter(&SymbolLayer::setTextKeepUpright); - result["text-transform"] = makePropertySetter(&SymbolLayer::setTextTransform); - result["text-offset"] = makePropertySetter(&SymbolLayer::setTextOffset); - result["text-allow-overlap"] = makePropertySetter(&SymbolLayer::setTextAllowOverlap); - result["text-ignore-placement"] = makePropertySetter(&SymbolLayer::setTextIgnorePlacement); - result["text-optional"] = makePropertySetter(&SymbolLayer::setTextOptional); - - - - - return result; -} - -inline PropertySetters makePaintPropertySetters() { - using namespace mbgl::style; - PropertySetters result; - - result["fill-antialias"] = makePropertySetter(&FillLayer::setFillAntialias); - result["fill-opacity"] = makePropertySetter(&FillLayer::setFillOpacity); - result["fill-color"] = makePropertySetter(&FillLayer::setFillColor); - result["fill-outline-color"] = makePropertySetter(&FillLayer::setFillOutlineColor); - result["fill-translate"] = makePropertySetter(&FillLayer::setFillTranslate); - result["fill-translate-anchor"] = makePropertySetter(&FillLayer::setFillTranslateAnchor); - result["fill-pattern"] = makePropertySetter(&FillLayer::setFillPattern); - - result["line-opacity"] = makePropertySetter(&LineLayer::setLineOpacity); - result["line-color"] = makePropertySetter(&LineLayer::setLineColor); - result["line-translate"] = makePropertySetter(&LineLayer::setLineTranslate); - result["line-translate-anchor"] = makePropertySetter(&LineLayer::setLineTranslateAnchor); - result["line-width"] = makePropertySetter(&LineLayer::setLineWidth); - result["line-gap-width"] = makePropertySetter(&LineLayer::setLineGapWidth); - result["line-offset"] = makePropertySetter(&LineLayer::setLineOffset); - result["line-blur"] = makePropertySetter(&LineLayer::setLineBlur); - result["line-dasharray"] = makePropertySetter(&LineLayer::setLineDasharray); - result["line-pattern"] = makePropertySetter(&LineLayer::setLinePattern); - - result["icon-opacity"] = makePropertySetter(&SymbolLayer::setIconOpacity); - result["icon-color"] = makePropertySetter(&SymbolLayer::setIconColor); - result["icon-halo-color"] = makePropertySetter(&SymbolLayer::setIconHaloColor); - result["icon-halo-width"] = makePropertySetter(&SymbolLayer::setIconHaloWidth); - result["icon-halo-blur"] = makePropertySetter(&SymbolLayer::setIconHaloBlur); - result["icon-translate"] = makePropertySetter(&SymbolLayer::setIconTranslate); - result["icon-translate-anchor"] = makePropertySetter(&SymbolLayer::setIconTranslateAnchor); - result["text-opacity"] = makePropertySetter(&SymbolLayer::setTextOpacity); - result["text-color"] = makePropertySetter(&SymbolLayer::setTextColor); - result["text-halo-color"] = makePropertySetter(&SymbolLayer::setTextHaloColor); - result["text-halo-width"] = makePropertySetter(&SymbolLayer::setTextHaloWidth); - result["text-halo-blur"] = makePropertySetter(&SymbolLayer::setTextHaloBlur); - result["text-translate"] = makePropertySetter(&SymbolLayer::setTextTranslate); - result["text-translate-anchor"] = makePropertySetter(&SymbolLayer::setTextTranslateAnchor); - - result["circle-radius"] = makePropertySetter(&CircleLayer::setCircleRadius); - result["circle-color"] = makePropertySetter(&CircleLayer::setCircleColor); - result["circle-blur"] = makePropertySetter(&CircleLayer::setCircleBlur); - result["circle-opacity"] = makePropertySetter(&CircleLayer::setCircleOpacity); - result["circle-translate"] = makePropertySetter(&CircleLayer::setCircleTranslate); - result["circle-translate-anchor"] = makePropertySetter(&CircleLayer::setCircleTranslateAnchor); - - result["raster-opacity"] = makePropertySetter(&RasterLayer::setRasterOpacity); - result["raster-hue-rotate"] = makePropertySetter(&RasterLayer::setRasterHueRotate); - result["raster-brightness-min"] = makePropertySetter(&RasterLayer::setRasterBrightnessMin); - result["raster-brightness-max"] = makePropertySetter(&RasterLayer::setRasterBrightnessMax); - result["raster-saturation"] = makePropertySetter(&RasterLayer::setRasterSaturation); - result["raster-contrast"] = makePropertySetter(&RasterLayer::setRasterContrast); - result["raster-fade-duration"] = makePropertySetter(&RasterLayer::setRasterFadeDuration); - - result["background-color"] = makePropertySetter(&BackgroundLayer::setBackgroundColor); - result["background-pattern"] = makePropertySetter(&BackgroundLayer::setBackgroundPattern); - result["background-opacity"] = makePropertySetter(&BackgroundLayer::setBackgroundOpacity); - - return result; -} - -inline bool setFilter(mbgl::style::Layer& layer, const mbgl::style::Filter& filter) { - using namespace mbgl::style; - - if (layer.is<FillLayer>()) { - layer.as<FillLayer>()->setFilter(filter); - return true; - } - if (layer.is<LineLayer>()) { - layer.as<LineLayer>()->setFilter(filter); - return true; - } - if (layer.is<SymbolLayer>()) { - layer.as<SymbolLayer>()->setFilter(filter); - return true; - } - if (layer.is<CircleLayer>()) { - layer.as<CircleLayer>()->setFilter(filter); - return true; - } - - Nan::ThrowTypeError("layer doesn't support filters"); - return false; -} - -} diff --git a/platform/node/src/node_style_properties.hpp.ejs b/platform/node/src/node_style_properties.hpp.ejs deleted file mode 100644 index bfd3f74ca5..0000000000 --- a/platform/node/src/node_style_properties.hpp.ejs +++ /dev/null @@ -1,53 +0,0 @@ -#include "node_style.hpp" - -<% for (const layer of locals.layers) { -%> -#include <mbgl/style/layers/<%- layer.type %>_layer.hpp> -<% } -%> - -namespace node_mbgl { - -inline PropertySetters makeLayoutPropertySetters() { - using namespace mbgl::style; - PropertySetters result; - - result["visibility"] = &setVisibility; - -<% for (const layer of locals.layers) { -%> -<% for (const property of layer.layoutProperties) { -%> - result["<%- property.name %>"] = makePropertySetter(&<%- camelize(layer.type) %>Layer::set<%- camelize(property.name) %>); -<% } -%> - -<% } -%> - return result; -} - -inline PropertySetters makePaintPropertySetters() { - using namespace mbgl::style; - PropertySetters result; - -<% for (const layer of locals.layers) { -%> -<% for (const property of layer.paintProperties) { -%> - result["<%- property.name %>"] = makePropertySetter(&<%- camelize(layer.type) %>Layer::set<%- camelize(property.name) %>); -<% } -%> - -<% } -%> - return result; -} - -inline bool setFilter(mbgl::style::Layer& layer, const mbgl::style::Filter& filter) { - using namespace mbgl::style; - -<% for (const layer of locals.layers) { -%> -<% if (layer.type !== 'raster' && layer.type !== 'background' && layer.type !== 'custom') { -%> - if (layer.is<<%- camelize(layer.type) %>Layer>()) { - layer.as<<%- camelize(layer.type) %>Layer>()->setFilter(filter); - return true; - } -<% } -%> -<% } -%> - - Nan::ThrowTypeError("layer doesn't support filters"); - return false; -} - -} diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index 7859c65a0e..642da1174b 100644 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -111,5 +111,5 @@ for (const layer of layers) { fs.writeFileSync(`src/mbgl/style/layers/${layer.type}_layer_properties.cpp`, propertiesCpp(layer)); } -const nodeStyleCpp = ejs.compile(fs.readFileSync('platform/node/src/node_style_properties.hpp.ejs', 'utf8'), {strict: true}); -fs.writeFileSync('platform/node/src/node_style_properties.hpp', nodeStyleCpp({layers: layers})); +const propertySettersHpp = ejs.compile(fs.readFileSync('include/mbgl/style/conversion/make_property_setters.hpp.ejs', 'utf8'), {strict: true}); +fs.writeFileSync('include/mbgl/style/conversion/make_property_setters.hpp', propertySettersHpp({layers: layers})); diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp index 33ad2e32ac..d2bf866e8e 100644 --- a/src/mbgl/style/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -5,7 +5,6 @@ #include <mbgl/style/filter.hpp> #include <mbgl/renderer/render_pass.hpp> #include <mbgl/util/noncopyable.hpp> -#include <mbgl/util/rapidjson.hpp> #include <mbgl/tile/geometry_tile_data.hpp> #include <memory> @@ -46,8 +45,8 @@ public: // Create an identical copy of this layer. virtual std::unique_ptr<Layer> clone() const = 0; - virtual void parseLayout(const JSValue& value) = 0; - virtual void parsePaints(const JSValue& value) = 0; + // Create a layer, copying all properties except id, ref, and paint properties from this layer. + virtual std::unique_ptr<Layer> cloneRef(const std::string& id) const = 0; // If the layer has a ref, the ref. Otherwise, the id. const std::string& bucketName() const; diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index aeb4067503..42cd76d01f 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -23,6 +23,14 @@ std::unique_ptr<Layer> BackgroundLayer::Impl::clone() const { return std::make_unique<BackgroundLayer>(*this); } +std::unique_ptr<Layer> BackgroundLayer::Impl::cloneRef(const std::string& id_) const { + auto result = std::make_unique<BackgroundLayer>(*this); + result->impl->id = id_; + result->impl->ref = this->id; + result->impl->paint = BackgroundPaintProperties(); + return std::move(result); +} + // Layout properties @@ -33,24 +41,24 @@ PropertyValue<Color> BackgroundLayer::getBackgroundColor() const { return impl->paint.backgroundColor.get(); } -void BackgroundLayer::setBackgroundColor(PropertyValue<Color> value) { - impl->paint.backgroundColor.set(value); +void BackgroundLayer::setBackgroundColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.backgroundColor.set(value, klass); } PropertyValue<std::string> BackgroundLayer::getBackgroundPattern() const { return impl->paint.backgroundPattern.get(); } -void BackgroundLayer::setBackgroundPattern(PropertyValue<std::string> value) { - impl->paint.backgroundPattern.set(value); +void BackgroundLayer::setBackgroundPattern(PropertyValue<std::string> value, const optional<std::string>& klass) { + impl->paint.backgroundPattern.set(value, klass); } PropertyValue<float> BackgroundLayer::getBackgroundOpacity() const { return impl->paint.backgroundOpacity.get(); } -void BackgroundLayer::setBackgroundOpacity(PropertyValue<float> value) { - impl->paint.backgroundOpacity.set(value); +void BackgroundLayer::setBackgroundOpacity(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.backgroundOpacity.set(value, klass); } } // namespace style diff --git a/src/mbgl/style/layers/background_layer_impl.cpp b/src/mbgl/style/layers/background_layer_impl.cpp index 0c09c5d158..ea389b828e 100644 --- a/src/mbgl/style/layers/background_layer_impl.cpp +++ b/src/mbgl/style/layers/background_layer_impl.cpp @@ -4,10 +4,6 @@ namespace mbgl { namespace style { -void BackgroundLayer::Impl::parsePaints(const JSValue& layer) { - paint.parse(layer); -} - void BackgroundLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp index 19e2a062a4..abbb740f42 100644 --- a/src/mbgl/style/layers/background_layer_impl.hpp +++ b/src/mbgl/style/layers/background_layer_impl.hpp @@ -10,9 +10,7 @@ namespace style { class BackgroundLayer::Impl : public Layer::Impl { public: std::unique_ptr<Layer> clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; + std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; bool recalculate(const CalculationParameters&) override; diff --git a/src/mbgl/style/layers/background_layer_properties.cpp b/src/mbgl/style/layers/background_layer_properties.cpp index a20cedf12c..558093a255 100644 --- a/src/mbgl/style/layers/background_layer_properties.cpp +++ b/src/mbgl/style/layers/background_layer_properties.cpp @@ -5,12 +5,6 @@ namespace mbgl { namespace style { -void BackgroundPaintProperties::parse(const JSValue& value) { - backgroundColor.parse("background-color", value); - backgroundPattern.parse("background-pattern", value); - backgroundOpacity.parse("background-opacity", value); -} - void BackgroundPaintProperties::cascade(const CascadeParameters& parameters) { backgroundColor.cascade(parameters); backgroundPattern.cascade(parameters); diff --git a/src/mbgl/style/layers/background_layer_properties.hpp b/src/mbgl/style/layers/background_layer_properties.hpp index 88a2ef1478..6c5a7c57ca 100644 --- a/src/mbgl/style/layers/background_layer_properties.hpp +++ b/src/mbgl/style/layers/background_layer_properties.hpp @@ -5,7 +5,6 @@ #include <mbgl/style/types.hpp> #include <mbgl/style/layout_property.hpp> #include <mbgl/style/paint_property.hpp> -#include <mbgl/util/rapidjson.hpp> namespace mbgl { namespace style { @@ -15,7 +14,6 @@ class CalculationParameters; class BackgroundPaintProperties { public: - void parse(const JSValue&); void cascade(const CascadeParameters&); bool recalculate(const CalculationParameters&); diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index 8066d7fd3c..a47d723548 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -24,6 +24,14 @@ std::unique_ptr<Layer> CircleLayer::Impl::clone() const { return std::make_unique<CircleLayer>(*this); } +std::unique_ptr<Layer> CircleLayer::Impl::cloneRef(const std::string& id_) const { + auto result = std::make_unique<CircleLayer>(*this); + result->impl->id = id_; + result->impl->ref = this->id; + result->impl->paint = CirclePaintProperties(); + return std::move(result); +} + // Source const std::string& CircleLayer::getSourceID() const { @@ -57,48 +65,48 @@ PropertyValue<float> CircleLayer::getCircleRadius() const { return impl->paint.circleRadius.get(); } -void CircleLayer::setCircleRadius(PropertyValue<float> value) { - impl->paint.circleRadius.set(value); +void CircleLayer::setCircleRadius(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.circleRadius.set(value, klass); } PropertyValue<Color> CircleLayer::getCircleColor() const { return impl->paint.circleColor.get(); } -void CircleLayer::setCircleColor(PropertyValue<Color> value) { - impl->paint.circleColor.set(value); +void CircleLayer::setCircleColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.circleColor.set(value, klass); } PropertyValue<float> CircleLayer::getCircleBlur() const { return impl->paint.circleBlur.get(); } -void CircleLayer::setCircleBlur(PropertyValue<float> value) { - impl->paint.circleBlur.set(value); +void CircleLayer::setCircleBlur(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.circleBlur.set(value, klass); } PropertyValue<float> CircleLayer::getCircleOpacity() const { return impl->paint.circleOpacity.get(); } -void CircleLayer::setCircleOpacity(PropertyValue<float> value) { - impl->paint.circleOpacity.set(value); +void CircleLayer::setCircleOpacity(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.circleOpacity.set(value, klass); } PropertyValue<std::array<float, 2>> CircleLayer::getCircleTranslate() const { return impl->paint.circleTranslate.get(); } -void CircleLayer::setCircleTranslate(PropertyValue<std::array<float, 2>> value) { - impl->paint.circleTranslate.set(value); +void CircleLayer::setCircleTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { + impl->paint.circleTranslate.set(value, klass); } PropertyValue<TranslateAnchorType> CircleLayer::getCircleTranslateAnchor() const { return impl->paint.circleTranslateAnchor.get(); } -void CircleLayer::setCircleTranslateAnchor(PropertyValue<TranslateAnchorType> value) { - impl->paint.circleTranslateAnchor.set(value); +void CircleLayer::setCircleTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { + impl->paint.circleTranslateAnchor.set(value, klass); } } // namespace style diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp index d64759e743..e08d9df146 100644 --- a/src/mbgl/style/layers/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -8,10 +8,6 @@ namespace mbgl { namespace style { -void CircleLayer::Impl::parsePaints(const JSValue& layer) { - paint.parse(layer); -} - void CircleLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } diff --git a/src/mbgl/style/layers/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp index 463f3ca18d..555691b6b4 100644 --- a/src/mbgl/style/layers/circle_layer_impl.hpp +++ b/src/mbgl/style/layers/circle_layer_impl.hpp @@ -10,9 +10,7 @@ namespace style { class CircleLayer::Impl : public Layer::Impl { public: std::unique_ptr<Layer> clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; + std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; bool recalculate(const CalculationParameters&) override; diff --git a/src/mbgl/style/layers/circle_layer_properties.cpp b/src/mbgl/style/layers/circle_layer_properties.cpp index b21df1e2d0..045c73ba63 100644 --- a/src/mbgl/style/layers/circle_layer_properties.cpp +++ b/src/mbgl/style/layers/circle_layer_properties.cpp @@ -5,15 +5,6 @@ namespace mbgl { namespace style { -void CirclePaintProperties::parse(const JSValue& value) { - circleRadius.parse("circle-radius", value); - circleColor.parse("circle-color", value); - circleBlur.parse("circle-blur", value); - circleOpacity.parse("circle-opacity", value); - circleTranslate.parse("circle-translate", value); - circleTranslateAnchor.parse("circle-translate-anchor", value); -} - void CirclePaintProperties::cascade(const CascadeParameters& parameters) { circleRadius.cascade(parameters); circleColor.cascade(parameters); diff --git a/src/mbgl/style/layers/circle_layer_properties.hpp b/src/mbgl/style/layers/circle_layer_properties.hpp index 87091e7b59..40d37dc392 100644 --- a/src/mbgl/style/layers/circle_layer_properties.hpp +++ b/src/mbgl/style/layers/circle_layer_properties.hpp @@ -5,7 +5,6 @@ #include <mbgl/style/types.hpp> #include <mbgl/style/layout_property.hpp> #include <mbgl/style/paint_property.hpp> -#include <mbgl/util/rapidjson.hpp> namespace mbgl { namespace style { @@ -15,7 +14,6 @@ class CalculationParameters; class CirclePaintProperties { public: - void parse(const JSValue&); void cascade(const CascadeParameters&); bool recalculate(const CalculationParameters&); diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp index 214d4ce663..a0686e353c 100644 --- a/src/mbgl/style/layers/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -33,6 +33,11 @@ std::unique_ptr<Layer> CustomLayer::Impl::clone() const { return std::make_unique<CustomLayer>(*this); } +std::unique_ptr<Layer> CustomLayer::Impl::cloneRef(const std::string&) const { + assert(false); + return std::make_unique<CustomLayer>(*this); +} + void CustomLayer::Impl::initialize() { assert(initializeFn); initializeFn(context); diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp index 00e576b6a3..ffa892ddf8 100644 --- a/src/mbgl/style/layers/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -25,9 +25,7 @@ public: private: std::unique_ptr<Layer> clone() const override; - - void parseLayout(const JSValue&) final {} - void parsePaints(const JSValue&) final {} + std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) final {} bool recalculate(const CalculationParameters&) final; diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 7d7d1a9e27..44894aff33 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -24,6 +24,14 @@ std::unique_ptr<Layer> FillLayer::Impl::clone() const { return std::make_unique<FillLayer>(*this); } +std::unique_ptr<Layer> FillLayer::Impl::cloneRef(const std::string& id_) const { + auto result = std::make_unique<FillLayer>(*this); + result->impl->id = id_; + result->impl->ref = this->id; + result->impl->paint = FillPaintProperties(); + return std::move(result); +} + // Source const std::string& FillLayer::getSourceID() const { @@ -57,56 +65,56 @@ PropertyValue<bool> FillLayer::getFillAntialias() const { return impl->paint.fillAntialias.get(); } -void FillLayer::setFillAntialias(PropertyValue<bool> value) { - impl->paint.fillAntialias.set(value); +void FillLayer::setFillAntialias(PropertyValue<bool> value, const optional<std::string>& klass) { + impl->paint.fillAntialias.set(value, klass); } PropertyValue<float> FillLayer::getFillOpacity() const { return impl->paint.fillOpacity.get(); } -void FillLayer::setFillOpacity(PropertyValue<float> value) { - impl->paint.fillOpacity.set(value); +void FillLayer::setFillOpacity(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.fillOpacity.set(value, klass); } PropertyValue<Color> FillLayer::getFillColor() const { return impl->paint.fillColor.get(); } -void FillLayer::setFillColor(PropertyValue<Color> value) { - impl->paint.fillColor.set(value); +void FillLayer::setFillColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.fillColor.set(value, klass); } PropertyValue<Color> FillLayer::getFillOutlineColor() const { return impl->paint.fillOutlineColor.get(); } -void FillLayer::setFillOutlineColor(PropertyValue<Color> value) { - impl->paint.fillOutlineColor.set(value); +void FillLayer::setFillOutlineColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.fillOutlineColor.set(value, klass); } PropertyValue<std::array<float, 2>> FillLayer::getFillTranslate() const { return impl->paint.fillTranslate.get(); } -void FillLayer::setFillTranslate(PropertyValue<std::array<float, 2>> value) { - impl->paint.fillTranslate.set(value); +void FillLayer::setFillTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { + impl->paint.fillTranslate.set(value, klass); } PropertyValue<TranslateAnchorType> FillLayer::getFillTranslateAnchor() const { return impl->paint.fillTranslateAnchor.get(); } -void FillLayer::setFillTranslateAnchor(PropertyValue<TranslateAnchorType> value) { - impl->paint.fillTranslateAnchor.set(value); +void FillLayer::setFillTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { + impl->paint.fillTranslateAnchor.set(value, klass); } PropertyValue<std::string> FillLayer::getFillPattern() const { return impl->paint.fillPattern.get(); } -void FillLayer::setFillPattern(PropertyValue<std::string> value) { - impl->paint.fillPattern.set(value); +void FillLayer::setFillPattern(PropertyValue<std::string> value, const optional<std::string>& klass) { + impl->paint.fillPattern.set(value, klass); } } // namespace style diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp index 3d847127c9..2992312514 100644 --- a/src/mbgl/style/layers/fill_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_layer_impl.cpp @@ -8,10 +8,6 @@ namespace mbgl { namespace style { -void FillLayer::Impl::parsePaints(const JSValue& layer) { - paint.parse(layer); -} - void FillLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } diff --git a/src/mbgl/style/layers/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp index a37dd76ace..fc6578ecd1 100644 --- a/src/mbgl/style/layers/fill_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_layer_impl.hpp @@ -10,9 +10,7 @@ namespace style { class FillLayer::Impl : public Layer::Impl { public: std::unique_ptr<Layer> clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; + std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; bool recalculate(const CalculationParameters&) override; diff --git a/src/mbgl/style/layers/fill_layer_properties.cpp b/src/mbgl/style/layers/fill_layer_properties.cpp index a4714689f9..9a55cbc145 100644 --- a/src/mbgl/style/layers/fill_layer_properties.cpp +++ b/src/mbgl/style/layers/fill_layer_properties.cpp @@ -5,16 +5,6 @@ namespace mbgl { namespace style { -void FillPaintProperties::parse(const JSValue& value) { - fillAntialias.parse("fill-antialias", value); - fillOpacity.parse("fill-opacity", value); - fillColor.parse("fill-color", value); - fillOutlineColor.parse("fill-outline-color", value); - fillTranslate.parse("fill-translate", value); - fillTranslateAnchor.parse("fill-translate-anchor", value); - fillPattern.parse("fill-pattern", value); -} - void FillPaintProperties::cascade(const CascadeParameters& parameters) { fillAntialias.cascade(parameters); fillOpacity.cascade(parameters); diff --git a/src/mbgl/style/layers/fill_layer_properties.hpp b/src/mbgl/style/layers/fill_layer_properties.hpp index fb60b90258..82981a9b64 100644 --- a/src/mbgl/style/layers/fill_layer_properties.hpp +++ b/src/mbgl/style/layers/fill_layer_properties.hpp @@ -5,7 +5,6 @@ #include <mbgl/style/types.hpp> #include <mbgl/style/layout_property.hpp> #include <mbgl/style/paint_property.hpp> -#include <mbgl/util/rapidjson.hpp> namespace mbgl { namespace style { @@ -15,7 +14,6 @@ class CalculationParameters; class FillPaintProperties { public: - void parse(const JSValue&); void cascade(const CascadeParameters&); bool recalculate(const CalculationParameters&); diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index 4f78d6b55e..017691c8ec 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -37,6 +37,14 @@ std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::clone() const { return std::make_unique<<%- camelize(type) %>Layer>(*this); } +std::unique_ptr<Layer> <%- camelize(type) %>Layer::Impl::cloneRef(const std::string& id_) const { + auto result = std::make_unique<<%- camelize(type) %>Layer>(*this); + result->impl->id = id_; + result->impl->ref = this->id; + result->impl->paint = <%- camelize(type) %>PaintProperties(); + return std::move(result); +} + <% if (type !== 'background') { -%> // Source @@ -83,8 +91,8 @@ PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.get(); } -void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) { - impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.set(value); +void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value, const optional<std::string>& klass) { + impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.set(value, klass); } <% } -%> diff --git a/src/mbgl/style/layers/layer_properties.cpp.ejs b/src/mbgl/style/layers/layer_properties.cpp.ejs index 8fef8d29c4..b781a4a9d9 100644 --- a/src/mbgl/style/layers/layer_properties.cpp.ejs +++ b/src/mbgl/style/layers/layer_properties.cpp.ejs @@ -11,12 +11,6 @@ namespace mbgl { namespace style { <% if (layoutProperties.length) { -%> -void <%- camelize(type) %>LayoutProperties::parse(const JSValue& value) { -<% for (const property of layoutProperties) { -%> - <%- camelizeWithLeadingLowercase(property.name) %>.parse(<%- JSON.stringify(property.name) %>, value); -<% } -%> -} - void <%- camelize(type) %>LayoutProperties::recalculate(const CalculationParameters& parameters) { <% for (const property of layoutProperties) { -%> <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters); @@ -24,12 +18,6 @@ void <%- camelize(type) %>LayoutProperties::recalculate(const CalculationParamet } <% } -%> -void <%- camelize(type) %>PaintProperties::parse(const JSValue& value) { -<% for (const property of paintProperties) { -%> - <%- camelizeWithLeadingLowercase(property.name) %>.parse(<%- JSON.stringify(property.name) %>, value); -<% } -%> -} - void <%- camelize(type) %>PaintProperties::cascade(const CascadeParameters& parameters) { <% for (const property of paintProperties) { -%> <%- camelizeWithLeadingLowercase(property.name) %>.cascade(parameters); diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs index 60f40efa8e..a485621ac6 100644 --- a/src/mbgl/style/layers/layer_properties.hpp.ejs +++ b/src/mbgl/style/layers/layer_properties.hpp.ejs @@ -10,7 +10,6 @@ #include <mbgl/style/types.hpp> #include <mbgl/style/layout_property.hpp> #include <mbgl/style/paint_property.hpp> -#include <mbgl/util/rapidjson.hpp> namespace mbgl { namespace style { @@ -21,7 +20,6 @@ class CalculationParameters; <% if (layoutProperties.length) { -%> class <%- camelize(type) %>LayoutProperties { public: - void parse(const JSValue&); void recalculate(const CalculationParameters&); <% for (const property of layoutProperties) { -%> @@ -32,7 +30,6 @@ public: <% } -%> class <%- camelize(type) %>PaintProperties { public: - void parse(const JSValue&); void cascade(const CascadeParameters&); bool recalculate(const CalculationParameters&); diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index e720d1fcfb..3ad72cda16 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -24,6 +24,14 @@ std::unique_ptr<Layer> LineLayer::Impl::clone() const { return std::make_unique<LineLayer>(*this); } +std::unique_ptr<Layer> LineLayer::Impl::cloneRef(const std::string& id_) const { + auto result = std::make_unique<LineLayer>(*this); + result->impl->id = id_; + result->impl->ref = this->id; + result->impl->paint = LinePaintProperties(); + return std::move(result); +} + // Source const std::string& LineLayer::getSourceID() const { @@ -85,80 +93,80 @@ PropertyValue<float> LineLayer::getLineOpacity() const { return impl->paint.lineOpacity.get(); } -void LineLayer::setLineOpacity(PropertyValue<float> value) { - impl->paint.lineOpacity.set(value); +void LineLayer::setLineOpacity(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.lineOpacity.set(value, klass); } PropertyValue<Color> LineLayer::getLineColor() const { return impl->paint.lineColor.get(); } -void LineLayer::setLineColor(PropertyValue<Color> value) { - impl->paint.lineColor.set(value); +void LineLayer::setLineColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.lineColor.set(value, klass); } PropertyValue<std::array<float, 2>> LineLayer::getLineTranslate() const { return impl->paint.lineTranslate.get(); } -void LineLayer::setLineTranslate(PropertyValue<std::array<float, 2>> value) { - impl->paint.lineTranslate.set(value); +void LineLayer::setLineTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { + impl->paint.lineTranslate.set(value, klass); } PropertyValue<TranslateAnchorType> LineLayer::getLineTranslateAnchor() const { return impl->paint.lineTranslateAnchor.get(); } -void LineLayer::setLineTranslateAnchor(PropertyValue<TranslateAnchorType> value) { - impl->paint.lineTranslateAnchor.set(value); +void LineLayer::setLineTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { + impl->paint.lineTranslateAnchor.set(value, klass); } PropertyValue<float> LineLayer::getLineWidth() const { return impl->paint.lineWidth.get(); } -void LineLayer::setLineWidth(PropertyValue<float> value) { - impl->paint.lineWidth.set(value); +void LineLayer::setLineWidth(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.lineWidth.set(value, klass); } PropertyValue<float> LineLayer::getLineGapWidth() const { return impl->paint.lineGapWidth.get(); } -void LineLayer::setLineGapWidth(PropertyValue<float> value) { - impl->paint.lineGapWidth.set(value); +void LineLayer::setLineGapWidth(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.lineGapWidth.set(value, klass); } PropertyValue<float> LineLayer::getLineOffset() const { return impl->paint.lineOffset.get(); } -void LineLayer::setLineOffset(PropertyValue<float> value) { - impl->paint.lineOffset.set(value); +void LineLayer::setLineOffset(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.lineOffset.set(value, klass); } PropertyValue<float> LineLayer::getLineBlur() const { return impl->paint.lineBlur.get(); } -void LineLayer::setLineBlur(PropertyValue<float> value) { - impl->paint.lineBlur.set(value); +void LineLayer::setLineBlur(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.lineBlur.set(value, klass); } PropertyValue<std::vector<float>> LineLayer::getLineDasharray() const { return impl->paint.lineDasharray.get(); } -void LineLayer::setLineDasharray(PropertyValue<std::vector<float>> value) { - impl->paint.lineDasharray.set(value); +void LineLayer::setLineDasharray(PropertyValue<std::vector<float>> value, const optional<std::string>& klass) { + impl->paint.lineDasharray.set(value, klass); } PropertyValue<std::string> LineLayer::getLinePattern() const { return impl->paint.linePattern.get(); } -void LineLayer::setLinePattern(PropertyValue<std::string> value) { - impl->paint.linePattern.set(value); +void LineLayer::setLinePattern(PropertyValue<std::string> value, const optional<std::string>& klass) { + impl->paint.linePattern.set(value, klass); } } // namespace style diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp index 589b129ee6..3cdd90b7fd 100644 --- a/src/mbgl/style/layers/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -8,14 +8,6 @@ namespace mbgl { namespace style { -void LineLayer::Impl::parseLayout(const JSValue& value) { - layout.parse(value); -} - -void LineLayer::Impl::parsePaints(const JSValue& layer) { - paint.parse(layer); -} - void LineLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp index 3356dc2ceb..e130bc01bc 100644 --- a/src/mbgl/style/layers/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -10,9 +10,7 @@ namespace style { class LineLayer::Impl : public Layer::Impl { public: std::unique_ptr<Layer> clone() const override; - - void parseLayout(const JSValue&) override; - void parsePaints(const JSValue&) override; + std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; bool recalculate(const CalculationParameters&) override; diff --git a/src/mbgl/style/layers/line_layer_properties.cpp b/src/mbgl/style/layers/line_layer_properties.cpp index 7c74f6de04..2d6092745e 100644 --- a/src/mbgl/style/layers/line_layer_properties.cpp +++ b/src/mbgl/style/layers/line_layer_properties.cpp @@ -5,13 +5,6 @@ namespace mbgl { namespace style { -void LineLayoutProperties::parse(const JSValue& value) { - lineCap.parse("line-cap", value); - lineJoin.parse("line-join", value); - lineMiterLimit.parse("line-miter-limit", value); - lineRoundLimit.parse("line-round-limit", value); -} - void LineLayoutProperties::recalculate(const CalculationParameters& parameters) { lineCap.calculate(parameters); lineJoin.calculate(parameters); @@ -19,19 +12,6 @@ void LineLayoutProperties::recalculate(const CalculationParameters& parameters) lineRoundLimit.calculate(parameters); } -void LinePaintProperties::parse(const JSValue& value) { - lineOpacity.parse("line-opacity", value); - lineColor.parse("line-color", value); - lineTranslate.parse("line-translate", value); - lineTranslateAnchor.parse("line-translate-anchor", value); - lineWidth.parse("line-width", value); - lineGapWidth.parse("line-gap-width", value); - lineOffset.parse("line-offset", value); - lineBlur.parse("line-blur", value); - lineDasharray.parse("line-dasharray", value); - linePattern.parse("line-pattern", value); -} - void LinePaintProperties::cascade(const CascadeParameters& parameters) { lineOpacity.cascade(parameters); lineColor.cascade(parameters); diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp index 0bc08f1988..e7dbddf442 100644 --- a/src/mbgl/style/layers/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -5,7 +5,6 @@ #include <mbgl/style/types.hpp> #include <mbgl/style/layout_property.hpp> #include <mbgl/style/paint_property.hpp> -#include <mbgl/util/rapidjson.hpp> namespace mbgl { namespace style { @@ -15,7 +14,6 @@ class CalculationParameters; class LineLayoutProperties { public: - void parse(const JSValue&); void recalculate(const CalculationParameters&); LayoutProperty<LineCapType> lineCap { LineCapType::Butt }; @@ -26,7 +24,6 @@ public: class LinePaintProperties { public: - void parse(const JSValue&); void cascade(const CascadeParameters&); bool recalculate(const CalculationParameters&); diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index cdba19ac4e..d4e121babe 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -24,6 +24,14 @@ std::unique_ptr<Layer> RasterLayer::Impl::clone() const { return std::make_unique<RasterLayer>(*this); } +std::unique_ptr<Layer> RasterLayer::Impl::cloneRef(const std::string& id_) const { + auto result = std::make_unique<RasterLayer>(*this); + result->impl->id = id_; + result->impl->ref = this->id; + result->impl->paint = RasterPaintProperties(); + return std::move(result); +} + // Source const std::string& RasterLayer::getSourceID() const { @@ -40,56 +48,56 @@ PropertyValue<float> RasterLayer::getRasterOpacity() const { return impl->paint.rasterOpacity.get(); } -void RasterLayer::setRasterOpacity(PropertyValue<float> value) { - impl->paint.rasterOpacity.set(value); +void RasterLayer::setRasterOpacity(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.rasterOpacity.set(value, klass); } PropertyValue<float> RasterLayer::getRasterHueRotate() const { return impl->paint.rasterHueRotate.get(); } -void RasterLayer::setRasterHueRotate(PropertyValue<float> value) { - impl->paint.rasterHueRotate.set(value); +void RasterLayer::setRasterHueRotate(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.rasterHueRotate.set(value, klass); } PropertyValue<float> RasterLayer::getRasterBrightnessMin() const { return impl->paint.rasterBrightnessMin.get(); } -void RasterLayer::setRasterBrightnessMin(PropertyValue<float> value) { - impl->paint.rasterBrightnessMin.set(value); +void RasterLayer::setRasterBrightnessMin(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.rasterBrightnessMin.set(value, klass); } PropertyValue<float> RasterLayer::getRasterBrightnessMax() const { return impl->paint.rasterBrightnessMax.get(); } -void RasterLayer::setRasterBrightnessMax(PropertyValue<float> value) { - impl->paint.rasterBrightnessMax.set(value); +void RasterLayer::setRasterBrightnessMax(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.rasterBrightnessMax.set(value, klass); } PropertyValue<float> RasterLayer::getRasterSaturation() const { return impl->paint.rasterSaturation.get(); } -void RasterLayer::setRasterSaturation(PropertyValue<float> value) { - impl->paint.rasterSaturation.set(value); +void RasterLayer::setRasterSaturation(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.rasterSaturation.set(value, klass); } PropertyValue<float> RasterLayer::getRasterContrast() const { return impl->paint.rasterContrast.get(); } -void RasterLayer::setRasterContrast(PropertyValue<float> value) { - impl->paint.rasterContrast.set(value); +void RasterLayer::setRasterContrast(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.rasterContrast.set(value, klass); } PropertyValue<float> RasterLayer::getRasterFadeDuration() const { return impl->paint.rasterFadeDuration.get(); } -void RasterLayer::setRasterFadeDuration(PropertyValue<float> value) { - impl->paint.rasterFadeDuration.set(value); +void RasterLayer::setRasterFadeDuration(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.rasterFadeDuration.set(value, klass); } } // namespace style diff --git a/src/mbgl/style/layers/raster_layer_impl.cpp b/src/mbgl/style/layers/raster_layer_impl.cpp index 4854ec041d..879bfa4559 100644 --- a/src/mbgl/style/layers/raster_layer_impl.cpp +++ b/src/mbgl/style/layers/raster_layer_impl.cpp @@ -4,10 +4,6 @@ namespace mbgl { namespace style { -void RasterLayer::Impl::parsePaints(const JSValue& layer) { - paint.parse(layer); -} - void RasterLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } diff --git a/src/mbgl/style/layers/raster_layer_impl.hpp b/src/mbgl/style/layers/raster_layer_impl.hpp index 6812b469a6..a5b396e2ed 100644 --- a/src/mbgl/style/layers/raster_layer_impl.hpp +++ b/src/mbgl/style/layers/raster_layer_impl.hpp @@ -10,9 +10,7 @@ namespace style { class RasterLayer::Impl : public Layer::Impl { public: std::unique_ptr<Layer> clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; + std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; bool recalculate(const CalculationParameters&) override; diff --git a/src/mbgl/style/layers/raster_layer_properties.cpp b/src/mbgl/style/layers/raster_layer_properties.cpp index 0e6afc5e9c..68d9d1d35d 100644 --- a/src/mbgl/style/layers/raster_layer_properties.cpp +++ b/src/mbgl/style/layers/raster_layer_properties.cpp @@ -5,16 +5,6 @@ namespace mbgl { namespace style { -void RasterPaintProperties::parse(const JSValue& value) { - rasterOpacity.parse("raster-opacity", value); - rasterHueRotate.parse("raster-hue-rotate", value); - rasterBrightnessMin.parse("raster-brightness-min", value); - rasterBrightnessMax.parse("raster-brightness-max", value); - rasterSaturation.parse("raster-saturation", value); - rasterContrast.parse("raster-contrast", value); - rasterFadeDuration.parse("raster-fade-duration", value); -} - void RasterPaintProperties::cascade(const CascadeParameters& parameters) { rasterOpacity.cascade(parameters); rasterHueRotate.cascade(parameters); diff --git a/src/mbgl/style/layers/raster_layer_properties.hpp b/src/mbgl/style/layers/raster_layer_properties.hpp index 1581ca6687..ddfb833e12 100644 --- a/src/mbgl/style/layers/raster_layer_properties.hpp +++ b/src/mbgl/style/layers/raster_layer_properties.hpp @@ -5,7 +5,6 @@ #include <mbgl/style/types.hpp> #include <mbgl/style/layout_property.hpp> #include <mbgl/style/paint_property.hpp> -#include <mbgl/util/rapidjson.hpp> namespace mbgl { namespace style { @@ -15,7 +14,6 @@ class CalculationParameters; class RasterPaintProperties { public: - void parse(const JSValue&); void cascade(const CascadeParameters&); bool recalculate(const CalculationParameters&); diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 905caa0310..c26123f0ec 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -24,6 +24,14 @@ std::unique_ptr<Layer> SymbolLayer::Impl::clone() const { return std::make_unique<SymbolLayer>(*this); } +std::unique_ptr<Layer> SymbolLayer::Impl::cloneRef(const std::string& id_) const { + auto result = std::make_unique<SymbolLayer>(*this); + result->impl->id = id_; + result->impl->ref = this->id; + result->impl->paint = SymbolPaintProperties(); + return std::move(result); +} + // Source const std::string& SymbolLayer::getSourceID() const { @@ -295,112 +303,112 @@ PropertyValue<float> SymbolLayer::getIconOpacity() const { return impl->paint.iconOpacity.get(); } -void SymbolLayer::setIconOpacity(PropertyValue<float> value) { - impl->paint.iconOpacity.set(value); +void SymbolLayer::setIconOpacity(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.iconOpacity.set(value, klass); } PropertyValue<Color> SymbolLayer::getIconColor() const { return impl->paint.iconColor.get(); } -void SymbolLayer::setIconColor(PropertyValue<Color> value) { - impl->paint.iconColor.set(value); +void SymbolLayer::setIconColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.iconColor.set(value, klass); } PropertyValue<Color> SymbolLayer::getIconHaloColor() const { return impl->paint.iconHaloColor.get(); } -void SymbolLayer::setIconHaloColor(PropertyValue<Color> value) { - impl->paint.iconHaloColor.set(value); +void SymbolLayer::setIconHaloColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.iconHaloColor.set(value, klass); } PropertyValue<float> SymbolLayer::getIconHaloWidth() const { return impl->paint.iconHaloWidth.get(); } -void SymbolLayer::setIconHaloWidth(PropertyValue<float> value) { - impl->paint.iconHaloWidth.set(value); +void SymbolLayer::setIconHaloWidth(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.iconHaloWidth.set(value, klass); } PropertyValue<float> SymbolLayer::getIconHaloBlur() const { return impl->paint.iconHaloBlur.get(); } -void SymbolLayer::setIconHaloBlur(PropertyValue<float> value) { - impl->paint.iconHaloBlur.set(value); +void SymbolLayer::setIconHaloBlur(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.iconHaloBlur.set(value, klass); } PropertyValue<std::array<float, 2>> SymbolLayer::getIconTranslate() const { return impl->paint.iconTranslate.get(); } -void SymbolLayer::setIconTranslate(PropertyValue<std::array<float, 2>> value) { - impl->paint.iconTranslate.set(value); +void SymbolLayer::setIconTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { + impl->paint.iconTranslate.set(value, klass); } PropertyValue<TranslateAnchorType> SymbolLayer::getIconTranslateAnchor() const { return impl->paint.iconTranslateAnchor.get(); } -void SymbolLayer::setIconTranslateAnchor(PropertyValue<TranslateAnchorType> value) { - impl->paint.iconTranslateAnchor.set(value); +void SymbolLayer::setIconTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { + impl->paint.iconTranslateAnchor.set(value, klass); } PropertyValue<float> SymbolLayer::getTextOpacity() const { return impl->paint.textOpacity.get(); } -void SymbolLayer::setTextOpacity(PropertyValue<float> value) { - impl->paint.textOpacity.set(value); +void SymbolLayer::setTextOpacity(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.textOpacity.set(value, klass); } PropertyValue<Color> SymbolLayer::getTextColor() const { return impl->paint.textColor.get(); } -void SymbolLayer::setTextColor(PropertyValue<Color> value) { - impl->paint.textColor.set(value); +void SymbolLayer::setTextColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.textColor.set(value, klass); } PropertyValue<Color> SymbolLayer::getTextHaloColor() const { return impl->paint.textHaloColor.get(); } -void SymbolLayer::setTextHaloColor(PropertyValue<Color> value) { - impl->paint.textHaloColor.set(value); +void SymbolLayer::setTextHaloColor(PropertyValue<Color> value, const optional<std::string>& klass) { + impl->paint.textHaloColor.set(value, klass); } PropertyValue<float> SymbolLayer::getTextHaloWidth() const { return impl->paint.textHaloWidth.get(); } -void SymbolLayer::setTextHaloWidth(PropertyValue<float> value) { - impl->paint.textHaloWidth.set(value); +void SymbolLayer::setTextHaloWidth(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.textHaloWidth.set(value, klass); } PropertyValue<float> SymbolLayer::getTextHaloBlur() const { return impl->paint.textHaloBlur.get(); } -void SymbolLayer::setTextHaloBlur(PropertyValue<float> value) { - impl->paint.textHaloBlur.set(value); +void SymbolLayer::setTextHaloBlur(PropertyValue<float> value, const optional<std::string>& klass) { + impl->paint.textHaloBlur.set(value, klass); } PropertyValue<std::array<float, 2>> SymbolLayer::getTextTranslate() const { return impl->paint.textTranslate.get(); } -void SymbolLayer::setTextTranslate(PropertyValue<std::array<float, 2>> value) { - impl->paint.textTranslate.set(value); +void SymbolLayer::setTextTranslate(PropertyValue<std::array<float, 2>> value, const optional<std::string>& klass) { + impl->paint.textTranslate.set(value, klass); } PropertyValue<TranslateAnchorType> SymbolLayer::getTextTranslateAnchor() const { return impl->paint.textTranslateAnchor.get(); } -void SymbolLayer::setTextTranslateAnchor(PropertyValue<TranslateAnchorType> value) { - impl->paint.textTranslateAnchor.set(value); +void SymbolLayer::setTextTranslateAnchor(PropertyValue<TranslateAnchorType> value, const optional<std::string>& klass) { + impl->paint.textTranslateAnchor.set(value, klass); } } // namespace style diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index eeceb52078..0243b1dfa5 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -5,14 +5,6 @@ namespace mbgl { namespace style { -void SymbolLayer::Impl::parseLayout(const JSValue& value) { - layout.parse(value); -} - -void SymbolLayer::Impl::parsePaints(const JSValue& layer) { - paint.parse(layer); -} - void SymbolLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index 9727cc6480..7765d6790e 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -13,9 +13,7 @@ namespace style { class SymbolLayer::Impl : public Layer::Impl { public: std::unique_ptr<Layer> clone() const override; - - void parseLayout(const JSValue&) override; - void parsePaints(const JSValue&) override; + std::unique_ptr<Layer> cloneRef(const std::string& id) const override; void cascade(const CascadeParameters&) override; bool recalculate(const CalculationParameters&) override; diff --git a/src/mbgl/style/layers/symbol_layer_properties.cpp b/src/mbgl/style/layers/symbol_layer_properties.cpp index d77d10700c..59a73d3d59 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.cpp +++ b/src/mbgl/style/layers/symbol_layer_properties.cpp @@ -5,43 +5,6 @@ namespace mbgl { namespace style { -void SymbolLayoutProperties::parse(const JSValue& value) { - symbolPlacement.parse("symbol-placement", value); - symbolSpacing.parse("symbol-spacing", value); - symbolAvoidEdges.parse("symbol-avoid-edges", value); - iconAllowOverlap.parse("icon-allow-overlap", value); - iconIgnorePlacement.parse("icon-ignore-placement", value); - iconOptional.parse("icon-optional", value); - iconRotationAlignment.parse("icon-rotation-alignment", value); - iconSize.parse("icon-size", value); - iconTextFit.parse("icon-text-fit", value); - iconTextFitPadding.parse("icon-text-fit-padding", value); - iconImage.parse("icon-image", value); - iconRotate.parse("icon-rotate", value); - iconPadding.parse("icon-padding", value); - iconKeepUpright.parse("icon-keep-upright", value); - iconOffset.parse("icon-offset", value); - textPitchAlignment.parse("text-pitch-alignment", value); - textRotationAlignment.parse("text-rotation-alignment", value); - textField.parse("text-field", value); - textFont.parse("text-font", value); - textSize.parse("text-size", value); - textMaxWidth.parse("text-max-width", value); - textLineHeight.parse("text-line-height", value); - textLetterSpacing.parse("text-letter-spacing", value); - textJustify.parse("text-justify", value); - textAnchor.parse("text-anchor", value); - textMaxAngle.parse("text-max-angle", value); - textRotate.parse("text-rotate", value); - textPadding.parse("text-padding", value); - textKeepUpright.parse("text-keep-upright", value); - textTransform.parse("text-transform", value); - textOffset.parse("text-offset", value); - textAllowOverlap.parse("text-allow-overlap", value); - textIgnorePlacement.parse("text-ignore-placement", value); - textOptional.parse("text-optional", value); -} - void SymbolLayoutProperties::recalculate(const CalculationParameters& parameters) { symbolPlacement.calculate(parameters); symbolSpacing.calculate(parameters); @@ -79,23 +42,6 @@ void SymbolLayoutProperties::recalculate(const CalculationParameters& parameters textOptional.calculate(parameters); } -void SymbolPaintProperties::parse(const JSValue& value) { - iconOpacity.parse("icon-opacity", value); - iconColor.parse("icon-color", value); - iconHaloColor.parse("icon-halo-color", value); - iconHaloWidth.parse("icon-halo-width", value); - iconHaloBlur.parse("icon-halo-blur", value); - iconTranslate.parse("icon-translate", value); - iconTranslateAnchor.parse("icon-translate-anchor", value); - textOpacity.parse("text-opacity", value); - textColor.parse("text-color", value); - textHaloColor.parse("text-halo-color", value); - textHaloWidth.parse("text-halo-width", value); - textHaloBlur.parse("text-halo-blur", value); - textTranslate.parse("text-translate", value); - textTranslateAnchor.parse("text-translate-anchor", value); -} - void SymbolPaintProperties::cascade(const CascadeParameters& parameters) { iconOpacity.cascade(parameters); iconColor.cascade(parameters); diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index 378562d605..a269969cb8 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -5,7 +5,6 @@ #include <mbgl/style/types.hpp> #include <mbgl/style/layout_property.hpp> #include <mbgl/style/paint_property.hpp> -#include <mbgl/util/rapidjson.hpp> namespace mbgl { namespace style { @@ -15,7 +14,6 @@ class CalculationParameters; class SymbolLayoutProperties { public: - void parse(const JSValue&); void recalculate(const CalculationParameters&); LayoutProperty<SymbolPlacementType> symbolPlacement { SymbolPlacementType::Point }; @@ -56,7 +54,6 @@ public: class SymbolPaintProperties { public: - void parse(const JSValue&); void cascade(const CascadeParameters&); bool recalculate(const CalculationParameters&); diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index f5045b47fc..db1a1ebf28 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -3,7 +3,6 @@ #include <mbgl/style/property_value.hpp> #include <mbgl/style/property_parsing.hpp> #include <mbgl/style/property_evaluator.hpp> -#include <mbgl/util/rapidjson.hpp> #include <utility> @@ -25,12 +24,6 @@ public: currentValue = value_; } - void parse(const char * name, const JSValue& layout) { - if (layout.HasMember(name)) { - currentValue = parseProperty<T>(name, layout[name]); - } - } - void calculate(const CalculationParameters& parameters) { if (currentValue) { PropertyEvaluator<T> evaluator(parameters, defaultValue); diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 7bb2e68b80..b982fe76e2 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -8,7 +8,6 @@ #include <mbgl/style/calculation_parameters.hpp> #include <mbgl/util/constants.hpp> #include <mbgl/util/interpolate.hpp> -#include <mbgl/util/std.hpp> #include <mbgl/util/rapidjson.hpp> #include <map> @@ -28,47 +27,28 @@ public: } PaintProperty(const PaintProperty& other) - : values(other.values), + : defaultValue(other.defaultValue), + values(other.values), transitions(other.transitions) { } + PaintProperty& operator=(const PaintProperty& other) { + defaultValue = other.defaultValue; + values = other.values; + transitions = other.transitions; + return *this; + } + const PropertyValue<T>& get() const { return values.at(ClassID::Default); } - void set(const PropertyValue<T>& value_) { - values[ClassID::Default] = value_; + void set(const PropertyValue<T>& value_, const optional<std::string>& klass) { + values[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = value_; } - void parse(const char* name, const JSValue& layer) { - mbgl::util::erase_if(values, [] (const auto& p) { return p.first != ClassID::Fallback; }); - - std::string transitionName = { name }; - transitionName += "-transition"; - - for (auto it = layer.MemberBegin(); it != layer.MemberEnd(); ++it) { - const std::string paintName { it->name.GetString(), it->name.GetStringLength() }; - if (paintName.compare(0, 5, "paint") != 0) - continue; - - bool isClass = paintName.compare(0, 6, "paint.") == 0; - if (isClass && paintName.length() <= 6) - continue; - - ClassID classID = isClass ? ClassDictionary::Get().lookup(paintName.substr(6)) : ClassID::Default; - - if (it->value.HasMember(name)) { - if (auto v = parseProperty<T>(name, it->value[name])) { - values.emplace(classID, v); - } - } - - if (it->value.HasMember(transitionName.c_str())) { - if (auto v = parseTransitionOptions(name, it->value[transitionName.c_str()])) { - transitions.emplace(classID, *v); - } - } - } + void setTransition(const TransitionOptions& transition, const optional<std::string>& klass) { + transitions[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = transition; } void cascade(const CascadeParameters& params) { diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index a0f4dd24c9..ac263dbc57 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -11,7 +11,7 @@ #include <mbgl/style/layers/background_layer.hpp> #include <mbgl/style/rapidjson_conversion.hpp> #include <mbgl/style/conversion.hpp> -#include <mbgl/style/conversion/filter.hpp> +#include <mbgl/style/conversion/layer.hpp> #include <mbgl/platform/log.hpp> @@ -219,120 +219,16 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique return; } - layer = reference->baseImpl->copy(id, ref, reference->baseImpl->source); - layer->baseImpl->parsePaints(value); + layer = reference->baseImpl->cloneRef(id); + conversion::setPaintProperties(*layer, value); } else { - // Otherwise, parse the source/source-layer/filter/render keys to form the bucket. - if (!value.HasMember("type")) { - Log::Warning(Event::ParseStyle, "layer '%s' is missing a type", id.c_str()); + conversion::Result<std::unique_ptr<Layer>> converted = conversion::convert<std::unique_ptr<Layer>>(value); + if (!converted) { + Log::Warning(Event::ParseStyle, converted.error().message); return; } - - const JSValue& typeVal = value["type"]; - if (!typeVal.IsString()) { - Log::Warning(Event::ParseStyle, "layer '%s' has an invalid type", id.c_str()); - return; - } - - std::string type { typeVal.GetString(), typeVal.GetStringLength() }; - std::string source; - - if (value.HasMember("source")) { - const JSValue& value_source = value["source"]; - if (value_source.IsString()) { - source = { value_source.GetString(), value_source.GetStringLength() }; - auto source_it = sourcesMap.find(source); - if (source_it == sourcesMap.end()) { - Log::Warning(Event::ParseStyle, "can't find source '%s' required for layer '%s'", source.c_str(), id.c_str()); - } - } else { - Log::Warning(Event::ParseStyle, "source of layer '%s' must be a string", id.c_str()); - } - } - - if (type == "fill") { - layer = std::make_unique<FillLayer>(id, source); - } else if (type == "line") { - layer = std::make_unique<LineLayer>(id, source); - } else if (type == "circle") { - layer = std::make_unique<CircleLayer>(id, source); - } else if (type == "symbol") { - layer = std::make_unique<SymbolLayer>(id, source); - } else if (type == "raster") { - layer = std::make_unique<RasterLayer>(id, source); - } else if (type == "background") { - layer = std::make_unique<BackgroundLayer>(id); - } else { - Log::Warning(Event::ParseStyle, "unknown type '%s' for layer '%s'", type.c_str(), id.c_str()); - return; - } - - Layer::Impl* impl = layer->baseImpl.get(); - - if (value.HasMember("source-layer")) { - const JSValue& value_source_layer = value["source-layer"]; - if (value_source_layer.IsString()) { - impl->sourceLayer = { value_source_layer.GetString(), value_source_layer.GetStringLength() }; - } else { - Log::Warning(Event::ParseStyle, "source-layer of layer '%s' must be a string", impl->id.c_str()); - } - } - - if (value.HasMember("filter")) { - conversion::Result<Filter> filter = conversion::convert<Filter>(value["filter"]); - if (filter) { - impl->filter = *filter; - } else { - Log::Warning(Event::ParseStyle, filter.error().message); - } - } - - if (value.HasMember("minzoom")) { - const JSValue& min_zoom = value["minzoom"]; - if (min_zoom.IsNumber()) { - impl->minZoom = min_zoom.GetDouble(); - } else { - Log::Warning(Event::ParseStyle, "minzoom of layer %s must be numeric", impl->id.c_str()); - } - } - - if (value.HasMember("maxzoom")) { - const JSValue& max_zoom = value["maxzoom"]; - if (max_zoom.IsNumber()) { - impl->maxZoom = max_zoom.GetDouble(); - } else { - Log::Warning(Event::ParseStyle, "maxzoom of layer %s must be numeric", impl->id.c_str()); - } - } - - if (value.HasMember("layout")) { - parseVisibility(*layer, value["layout"]); - impl->parseLayout(value["layout"]); - } - - impl->parsePaints(value); - } -} - -void Parser::parseVisibility(Layer& layer, const JSValue& value) { - Layer::Impl& impl = *layer.baseImpl; - - if (!value.HasMember("visibility")) { - return; - } - - if (!value["visibility"].IsString()) { - Log::Warning(Event::ParseStyle, "value of 'visibility' must be a string"); - return; + layer = std::move(*converted); } - - const auto enumValue = Enum<VisibilityType>::toEnum({ value["visibility"].GetString(), value["visibility"].GetStringLength() }); - if (!enumValue) { - Log::Warning(Event::ParseStyle, "value of 'visibility' must be a valid enumeration value"); - return; - } - - impl.visibility = *enumValue; } std::vector<FontStack> Parser::fontStacks() const { diff --git a/src/mbgl/style/parser.hpp b/src/mbgl/style/parser.hpp index 30da0dd2b0..faf80cee93 100644 --- a/src/mbgl/style/parser.hpp +++ b/src/mbgl/style/parser.hpp @@ -34,7 +34,6 @@ private: void parseSources(const JSValue&); void parseLayers(const JSValue&); void parseLayer(const std::string& id, const JSValue&, std::unique_ptr<Layer>&); - void parseVisibility(Layer&, const JSValue& value); std::unordered_map<std::string, const Source*> sourcesMap; std::unordered_map<std::string, std::pair<const JSValue&, std::unique_ptr<Layer>>> layersMap; diff --git a/src/mbgl/style/rapidjson_conversion.hpp b/src/mbgl/style/rapidjson_conversion.hpp index 1d9f88efa3..ecf044fb64 100644 --- a/src/mbgl/style/rapidjson_conversion.hpp +++ b/src/mbgl/style/rapidjson_conversion.hpp @@ -2,11 +2,16 @@ #include <mbgl/util/rapidjson.hpp> #include <mbgl/util/feature.hpp> +#include <mbgl/style/conversion.hpp> namespace mbgl { namespace style { namespace conversion { +inline bool isUndefined(const JSValue& value) { + return value.IsNull(); +} + inline bool isArray(const JSValue& value) { return value.IsArray(); } @@ -30,6 +35,17 @@ inline const JSValue* objectMember(const JSValue& value, const char * name) { return &value[name]; } +template <class Fn> +optional<Error> eachMember(const JSValue& value, Fn&& fn) { + for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it) { + optional<Error> result = fn({it->name.GetString(), it->name.GetStringLength()}, it->value); + if (result) { + return result; + } + } + return {}; +} + inline optional<bool> toBool(const JSValue& value) { if (!value.IsBool()) { return {}; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index cb48790c9f..9073894cc2 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -141,6 +141,8 @@ Layer* Style::getLayer(const std::string& id) const { } void Style::addLayer(std::unique_ptr<Layer> layer, optional<std::string> before) { + // TODO: verify source + if (SymbolLayer* symbolLayer = layer->as<SymbolLayer>()) { if (!symbolLayer->impl->spriteAtlas) { symbolLayer->impl->spriteAtlas = spriteAtlas.get(); diff --git a/test/fixtures/style_parser/circle-blur.info.json b/test/fixtures/style_parser/circle-blur.info.json index 60306e20c8..40c4632c0e 100644 --- a/test/fixtures/style_parser/circle-blur.info.json +++ b/test/fixtures/style_parser/circle-blur.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "circle-blur: value must be a number"] + [1, "WARNING", "ParseStyle", "value must be a number"] ] } } diff --git a/test/fixtures/style_parser/circle-blur.style.json b/test/fixtures/style_parser/circle-blur.style.json index 8140ad5e47..9c82142c21 100644 --- a/test/fixtures/style_parser/circle-blur.style.json +++ b/test/fixtures/style_parser/circle-blur.style.json @@ -12,7 +12,7 @@ "type": "circle", "source": "mapbox", "paint": { - "circle-blur": null + "circle-blur": "no" } }] } diff --git a/test/fixtures/style_parser/circle-color.info.json b/test/fixtures/style_parser/circle-color.info.json index 9d569ad53d..0dfa6371b7 100644 --- a/test/fixtures/style_parser/circle-color.info.json +++ b/test/fixtures/style_parser/circle-color.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "circle-color: value must be a string"] + [1, "WARNING", "ParseStyle", "value must be a string"] ] } } diff --git a/test/fixtures/style_parser/circle-color.style.json b/test/fixtures/style_parser/circle-color.style.json index 44c32f99ce..e9c508304b 100644 --- a/test/fixtures/style_parser/circle-color.style.json +++ b/test/fixtures/style_parser/circle-color.style.json @@ -12,7 +12,7 @@ "type": "circle", "source": "mapbox", "paint": { - "circle-color": null + "circle-color": 1 } }] } diff --git a/test/fixtures/style_parser/circle-opacity.info.json b/test/fixtures/style_parser/circle-opacity.info.json index bb77cebd1e..40c4632c0e 100644 --- a/test/fixtures/style_parser/circle-opacity.info.json +++ b/test/fixtures/style_parser/circle-opacity.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "circle-opacity: value must be a number"] + [1, "WARNING", "ParseStyle", "value must be a number"] ] } } diff --git a/test/fixtures/style_parser/circle-opacity.style.json b/test/fixtures/style_parser/circle-opacity.style.json index 601e81a51b..a993182b1b 100644 --- a/test/fixtures/style_parser/circle-opacity.style.json +++ b/test/fixtures/style_parser/circle-opacity.style.json @@ -12,7 +12,7 @@ "type": "circle", "source": "mapbox", "paint": { - "circle-opacity": null + "circle-opacity": "no" } }] } diff --git a/test/fixtures/style_parser/circle-radius.info.json b/test/fixtures/style_parser/circle-radius.info.json index 285e962d74..40c4632c0e 100644 --- a/test/fixtures/style_parser/circle-radius.info.json +++ b/test/fixtures/style_parser/circle-radius.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "circle-radius: value must be a number"] + [1, "WARNING", "ParseStyle", "value must be a number"] ] } } diff --git a/test/fixtures/style_parser/circle-radius.style.json b/test/fixtures/style_parser/circle-radius.style.json index a7fb28b2d3..f12cebff97 100644 --- a/test/fixtures/style_parser/circle-radius.style.json +++ b/test/fixtures/style_parser/circle-radius.style.json @@ -12,7 +12,7 @@ "type": "circle", "source": "mapbox", "paint": { - "circle-radius": null + "circle-radius": "no" } }] } diff --git a/test/fixtures/style_parser/function-numeric.info.json b/test/fixtures/style_parser/function-numeric.info.json index 906cccf106..7dd5a69561 100644 --- a/test/fixtures/style_parser/function-numeric.info.json +++ b/test/fixtures/style_parser/function-numeric.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "line-width: function stop must be an array"] + [1, "WARNING", "ParseStyle", "function stop must be an array"] ] } } diff --git a/test/fixtures/style_parser/function-type.info.json b/test/fixtures/style_parser/function-type.info.json index 8a844bf7c1..c9e26537f7 100644 --- a/test/fixtures/style_parser/function-type.info.json +++ b/test/fixtures/style_parser/function-type.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "line-width: function value must specify stops"] + [1, "WARNING", "ParseStyle", "function value must specify stops"] ] } } diff --git a/test/fixtures/style_parser/line-opacity.info.json b/test/fixtures/style_parser/line-opacity.info.json index 63af59e280..40c4632c0e 100644 --- a/test/fixtures/style_parser/line-opacity.info.json +++ b/test/fixtures/style_parser/line-opacity.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "line-opacity: value must be a number"] + [1, "WARNING", "ParseStyle", "value must be a number"] ] } } diff --git a/test/fixtures/style_parser/line-opacity.style.json b/test/fixtures/style_parser/line-opacity.style.json index 712b2b6f50..7d29fb312a 100644 --- a/test/fixtures/style_parser/line-opacity.style.json +++ b/test/fixtures/style_parser/line-opacity.style.json @@ -16,7 +16,7 @@ "paint": { "line-color": "#008", "line-width": 0.9, - "line-opacity": null + "line-opacity": "no" } }] } diff --git a/test/fixtures/style_parser/line-translate.info.json b/test/fixtures/style_parser/line-translate.info.json index a23e17012e..16df094290 100644 --- a/test/fixtures/style_parser/line-translate.info.json +++ b/test/fixtures/style_parser/line-translate.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "line-translate: value must be an array of two numbers"] + [1, "WARNING", "ParseStyle", "value must be an array of two numbers"] ] } } diff --git a/test/fixtures/style_parser/line-translate.style.json b/test/fixtures/style_parser/line-translate.style.json index a32b2d8ee4..4890a8b6df 100644 --- a/test/fixtures/style_parser/line-translate.style.json +++ b/test/fixtures/style_parser/line-translate.style.json @@ -12,7 +12,7 @@ "type": "line", "source": "mapbox", "paint": { - "line-translate": null + "line-translate": "no" } }] } diff --git a/test/fixtures/style_parser/line-width.info.json b/test/fixtures/style_parser/line-width.info.json index 9e549a0228..40c4632c0e 100644 --- a/test/fixtures/style_parser/line-width.info.json +++ b/test/fixtures/style_parser/line-width.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "line-width: value must be a number"] + [1, "WARNING", "ParseStyle", "value must be a number"] ] } } diff --git a/test/fixtures/style_parser/line-width.style.json b/test/fixtures/style_parser/line-width.style.json index e5fe6fa8e1..1f677460c4 100644 --- a/test/fixtures/style_parser/line-width.style.json +++ b/test/fixtures/style_parser/line-width.style.json @@ -14,7 +14,7 @@ "source-layer": "waterway", "filter": ["in", "type", "river", "canal"], "paint": { - "line-width": null + "line-width": "no" } }] } diff --git a/test/fixtures/style_parser/stop-zoom-value.info.json b/test/fixtures/style_parser/stop-zoom-value.info.json index 3abf1867a4..386dce9d29 100644 --- a/test/fixtures/style_parser/stop-zoom-value.info.json +++ b/test/fixtures/style_parser/stop-zoom-value.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "fill-opacity: function stop must have two elements"] + [1, "WARNING", "ParseStyle", "function stop must have two elements"] ] } } diff --git a/test/fixtures/style_parser/stops-array.info.json b/test/fixtures/style_parser/stops-array.info.json index b82f5a97d7..ed66513fee 100644 --- a/test/fixtures/style_parser/stops-array.info.json +++ b/test/fixtures/style_parser/stops-array.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "line-width: function stops must be an array"] + [1, "WARNING", "ParseStyle", "function stops must be an array"] ] } } diff --git a/test/fixtures/style_parser/text-size.info.json b/test/fixtures/style_parser/text-size.info.json index b412c6beed..40c4632c0e 100644 --- a/test/fixtures/style_parser/text-size.info.json +++ b/test/fixtures/style_parser/text-size.info.json @@ -1,7 +1,7 @@ { "default": { "log": [ - [1, "WARNING", "ParseStyle", "text-size: value must be a number"] + [1, "WARNING", "ParseStyle", "value must be a number"] ] } } diff --git a/test/fixtures/style_parser/text-size.style.json b/test/fixtures/style_parser/text-size.style.json index ee6a6c39e4..dafa87d63b 100644 --- a/test/fixtures/style_parser/text-size.style.json +++ b/test/fixtures/style_parser/text-size.style.json @@ -14,7 +14,7 @@ "source-layer": "country_label", "filter": ["==", "$type", "Point"], "layout": { - "text-size": null + "text-size": "no" } }] } |