Leaflet.js: is it possible to filter geoJSON properties by property?

I look around and see a lot of information on how to show / hide layers. This is cool, but since I can add arbitrary properties to the geoJSON functions, I kind of expect that I can filter them out accordingly.

For example, if I have functions 1, 2, and 3 with these properties

  • small | red | sweet
  • big | green | sour
  • small | red | hot

How can I filter them by size? Or by color or flavor?

+3
source share
2 answers

http://leafletjs.com/examples/geojson.html

Yes, you can add a filter function, for example:

L.geoJson(someFeatures, {
    filter: function(feature, layer) {
        return feature.properties.show_on_map;
    }
}).addTo(map);

, , SO : : GeoJson?

+4

Leaflet.tagFilterButton.

tags , /. :

L.geoJson(jsonObject, {
    pointToLayer: function(feature, latlng) {
        L.marker(latlng, {
            tags: ['small', 'red', 'sweet']
        });
    }
}).addTo( map );

L.control.tagFilterButton({
    data: ['small', 'red', 'sweet']
}).addTo( map );
0

All Articles