Skip to content

Instantly share code, notes, and snippets.

@aquelito
Last active December 31, 2018 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aquelito/721918a141455440f33110ea5ce29742 to your computer and use it in GitHub Desktop.
Save aquelito/721918a141455440f33110ea5ce29742 to your computer and use it in GitHub Desktop.
Mapbox GL - Helpers

Mapbox GL

// Get all layers
map.getStyle().layers
// Layer filter array
var filter = [];
filter.push("all");
filter.push(["==", "MY_PROPERTIES_FIELD", 'MY_VALUE']);
filter.push([">=", "MY_PROPERTIES_FIELD", 10]);
filter.push(["<=", "MY_PROPERTIES_FIELD", 20]);
map.setFilter("MY_LAYER", filter);
result.features.forEach(function(ft, ind) {
  ft.properties.stroke = (ind % 2 === 0) ? '#f40' : '#389979';
});

https://bl.ocks.org/andrewharvey/7b61e9bdb4165e8832b7495c2a4f17f7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment