I'm running into an issue.

I have an array of value coming from a JSON POST.
After retrieving these values and storing them into a var, I need to filter an OpenLayers layer with this values.

I'm using this :

mapFilterbyStation = new OpenLayers.Filter.Logical({
        type: OpenLayers.Filter.Logical.AND,
        filters: [
            new OpenLayers.Filter.Comparison({
                type: OpenLayers.Filter.Comparison.EQUAL_TO,
                property: "id4geoserv",
                value: stationsParse

where stationsParse is an array of values.

Problem, is that the value to filter can only contains : number or string, according to the OpenLayers docs : http://dev.openlayers.org/releases/OpenLayers-2.10/doc/apidocs/files/OpenLayers/Filter/Comparison-js.html

Is there a way to achieve what I want using filters ?

I was thinking about iterate on each value stored in my array, and create a filter for each of them, but this solution looks ugly for me.

I'm surprised there is nothing to filter on multiple values from the same parameters in OpenLayers.

So if anyone has a tips ;) !


You're going to have to iterate. It's a logical AND and it takes an array of filters.

If you think it looks ugly create a function that will return the array of filters given your values.

  • Yep, I guess this is what I am going to do. Anyway, I'm surprised you can't pass several values inside one EQUAL_TO filter. I think I'm gonna check if OpenLayers3 has this feature availible. – Stranded Kid Feb 7 '14 at 20:45
  • 2
    In a way, this makes sense. Most programming languages require the programmer to specify the relationship between every parameter and value. (side note: in some instances, you can use the mergeNewParams function to apply a CQL filter encoded as a string). – Brynne Feb 7 '14 at 23:20

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.