1
votes

I'm trying to build a function to dynamically filter markers on the map. Check a value in in each feature.properties.value against some criteria. I'm wondering what to do on each filtering event:

  • Just remove/clear the whole geojsonlayer (all markers) and update (getJSON) new markers again where I check them against a filter criteria before I add them to the geojson layer.

or

  • Iterate through each layer in the geojson layer, check each layers properties against a criteria, remove those that does not match and the then update (getJSON) new markers and check them against the criteria.

or

  • Update (getJSON) and run a loop over each feature and split them up in different layergroups by criteria from the start. Then hide/show (?) each layergroup if they match the criteria.

Do you know any other ways to do it? How would you do it? Thinking of scaling/performance..

(I'm also going to store each marker id in an array and check to avoid adding duplicates.)

1

1 Answers

0
votes

It depends on the filesize of the geojson you load. For smaller geojson you could delete and reload, for bigger imho it's better iterating on each layer and apply to it some function.

Here's how I did it https://github.com/sabas/GenoaPortStats/blob/gh-pages/globalTraffic/2013/choropleth.loading.html#L92

(thinking about performance, seems slow, but it's the easiest way)