Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[node] Support setLayoutProperty(..., "visibility", ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jun 21, 2016
1 parent 8a9ee26 commit 220fc7a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions platform/node/src/node_style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
2 changes: 2 additions & 0 deletions platform/node/src/node_style_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions platform/node/src/node_style_properties.hpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>);
Expand Down

0 comments on commit 220fc7a

Please sign in to comment.