[core, node] Implement bindings for addLayer
This commit is contained in:
@@ -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
|
||||
|
||||
208
include/mbgl/style/conversion/layer.hpp
Normal file
208
include/mbgl/style/conversion/layer.hpp
Normal file
@@ -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
|
||||
133
include/mbgl/style/conversion/make_property_setters.hpp
Normal file
133
include/mbgl/style/conversion/make_property_setters.hpp
Normal file
@@ -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
|
||||
45
include/mbgl/style/conversion/make_property_setters.hpp.ejs
Normal file
45
include/mbgl/style/conversion/make_property_setters.hpp.ejs
Normal file
@@ -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
|
||||
55
include/mbgl/style/conversion/property_setter.hpp
Normal file
55
include/mbgl/style/conversion/property_setter.hpp
Normal file
@@ -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
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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}));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
<% } -%>
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,122 +219,18 @@ 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);
|
||||
layer = std::move(*converted);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 {
|
||||
std::set<FontStack> result;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "circle-blur: value must be a number"]
|
||||
[1, "WARNING", "ParseStyle", "value must be a number"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"type": "circle",
|
||||
"source": "mapbox",
|
||||
"paint": {
|
||||
"circle-blur": null
|
||||
"circle-blur": "no"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "circle-color: value must be a string"]
|
||||
[1, "WARNING", "ParseStyle", "value must be a string"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"type": "circle",
|
||||
"source": "mapbox",
|
||||
"paint": {
|
||||
"circle-color": null
|
||||
"circle-color": 1
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "circle-opacity: value must be a number"]
|
||||
[1, "WARNING", "ParseStyle", "value must be a number"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"type": "circle",
|
||||
"source": "mapbox",
|
||||
"paint": {
|
||||
"circle-opacity": null
|
||||
"circle-opacity": "no"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "circle-radius: value must be a number"]
|
||||
[1, "WARNING", "ParseStyle", "value must be a number"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"type": "circle",
|
||||
"source": "mapbox",
|
||||
"paint": {
|
||||
"circle-radius": null
|
||||
"circle-radius": "no"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -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"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "line-width: function value must specify stops"]
|
||||
[1, "WARNING", "ParseStyle", "function value must specify stops"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "line-opacity: value must be a number"]
|
||||
[1, "WARNING", "ParseStyle", "value must be a number"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"paint": {
|
||||
"line-color": "#008",
|
||||
"line-width": 0.9,
|
||||
"line-opacity": null
|
||||
"line-opacity": "no"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -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"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"type": "line",
|
||||
"source": "mapbox",
|
||||
"paint": {
|
||||
"line-translate": null
|
||||
"line-translate": "no"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "line-width: value must be a number"]
|
||||
[1, "WARNING", "ParseStyle", "value must be a number"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"source-layer": "waterway",
|
||||
"filter": ["in", "type", "river", "canal"],
|
||||
"paint": {
|
||||
"line-width": null
|
||||
"line-width": "no"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -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"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
[1, "WARNING", "ParseStyle", "text-size: value must be a number"]
|
||||
[1, "WARNING", "ParseStyle", "value must be a number"]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"source-layer": "country_label",
|
||||
"filter": ["==", "$type", "Point"],
|
||||
"layout": {
|
||||
"text-size": null
|
||||
"text-size": "no"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user