Skip to content

Instantly share code, notes, and snippets.

@aquelito

aquelito/mapbox-gl.js.md

Last active Dec 31, 2018
Embed
What would you like to do?
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