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

5

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

  • 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 Mar 29 '12 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 Mar 29 '12 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.... – James Lewis Mar 30 '12 at 9:21
  • Yes, high mortality rates from the same Croc. – CaptDragon Mar 30 '12 at 13:10
  • 1
    Well, looks like we lost it to the crocodiles. – Devdatta Tengshe Feb 6 '14 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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