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.



1 Answer 1


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


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

  • 2
    I was with you on the Cat and Alligator, but you lost me with the elephant drawing...I'm just not seeing it. :-D
    – Vadim
    Commented Mar 29, 2012 at 17:05
  • 2
    @Vadim : LOL. It's only the profile of its head (ear and trunk) and the trunk is pointed at the cat. It's a work of art. And yes these animals are to scale. ;)
    – CaptDragon
    Commented Mar 29, 2012 at 17:08
  • 1
    thanks for your help @CaptDragon, really appreciate it. I'll give it a try. I presume you aren't from West Africa? High crocodile mortality rates.... Commented Mar 30, 2012 at 9:21
  • Yes, high mortality rates from the same Croc.
    – CaptDragon
    Commented Mar 30, 2012 at 13:10
  • 1
    Well, looks like we lost it to the crocodiles. Commented Feb 6, 2014 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.