Leaflet / Leaflet.VectorGrid

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0
598 stars 194 forks source link

Geoson filter and function (element) #183

Open soli004 opened 5 years ago

soli004 commented 5 years ago

I have a hard time to implement this filter

// After this function call 'filtered' contains the filtered list of GeoJSON features
var filtered = geoJson.filter(
function(element) {
// We are only interested in elements which do not contain 'Mån'
return element.indexOf("Mån") != -1;
}
);

It will filter out all properties that does not contain the letter combination "Mån" (Monday). The result is that I want to see all polygons on the map that does not contain this letter combination. I just can't figure out how to use with this below... is it possible?

var no_monday = new L.layerGroup();
$.getJSON("..data/polygons.geojson", function(json) {

var vectorGrid =  L.vectorGrid.slicer(json, {
maxZoom: 20,
zIndex: 5,
rendererFactory: L.svg.tile,
vectorTileLayerStyles: {
sliced: function(properties, zoom){  //filter goes here!?

return {
weight: 0.5,
color: '#ffffff',
opacity: 1,
fill: true,
fillColor: '#ff0000',
stroke: true,
fillOpacity: 0.6
}
}},
interactive: true,
})

.on('click', function(e) {
var properties = e.layer.properties;
L.popup()
.setContent(
"<b>Comments</b>" + properties.T_1_txt + 
"<br>WeekDays: " + '<b>' + properties.Days_1 + '</b>' +
"<br>Date from: " + '<i>' + properties.Date + '</i>' )
.setLatLng(e.latlng)
.openOn(map);
})
vectorGrid.addTo(no_monday)
})