[GIS] Openlayers dynamic filtering/styling of geojson layer

geojsonopenlayers-2

I'm working with Openlayers and overlaying a geojson file representing species type over OSM. I have an HTML form that allows users to select a species type and I then need to filter the geojson layer based on the selection. I then want the map to redraw, displaying only the filtered features.

I've tried CQL and messed around with styling but I'm not getting very far. Does anyone have any experience of doing this?

Thanks in advance.

James

Best Answer

The OpenLayers.Format.GeoJSON read operation takes in a filter function see documentation

OR

You could do something like this:

if (html.checked == true) {
    feature.style.display = "block";
} else {
    feature.style.display = "none";
}

Working Example/DEMO

enter image description here