[node] Support setLayoutProperty(..., "visibility", ...)

This commit is contained in:
John Firebaugh
2016-06-21 16:28:18 -07:00
parent 8a9ee26b0e
commit 220fc7adc9
4 changed files with 23 additions and 1 deletions

View File

@@ -46,4 +46,22 @@ PropertySetter makePropertySetter(void (L::*setter)(mbgl::style::PropertyValue<V
};
}
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;
}
}

View File

@@ -13,6 +13,8 @@ inline PropertySetters makeLayoutPropertySetters() {
using namespace mbgl::style;
PropertySetters result;
result["visibility"] = &setVisibility;
result["line-cap"] = makePropertySetter(&LineLayer::setLineCap);
result["line-join"] = makePropertySetter(&LineLayer::setLineJoin);

View File

@@ -10,6 +10,8 @@ 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) %>);