Leaflet / Leaflet/Leaflet.VectorGrid

Geoson filter and function (element)

Open
#183 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
676
Forks
202
PR merge metrics
No merged PRs in 30d

Description

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)
}) 

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue mentions L.vectorGrid.slicer and the vectorTileLayerStyles.sliced callback, but names no repository file or test. Start by tracing how sliced GeoJSON properties reach that callback and check existing filtering examples or tests. Done means the requested property filter reliably controls which polygons are displayed.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.