[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

@@ -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#2e95c51a6ed0efd1d8cda03f6b5391a6639900ae",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#87d237a9d7372325fffd0c04036b2d77e601e72b",
"node-gyp": "^3.3.1",
"request": "^2.72.0",
"tape": "^4.5.1"

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) %>);