This is OpenLayers 2 code I'm upgrading to OpenLayers 3 (OL3). A set of filters (for example fromDate and toDate to for query) are created and inserted. How can I do this in OpenLayers 3?

I have a set of parameters which the user changes before the query. Filter is not a part of OL3, so how can I create such request to GeoServer with my parameters? Can anyone provide an example of OL3 syntax?

       // create filter
        var dateFilter = new OL.Filter.Comparison({
        type : OL.Filter.Comparison.BETWEEN,
        property : "stdate",
        lowerBoundary : date.fromDate,
        upperBoundary : date.toDate

        var filter = ns.query.constructFilterString(filterBbox, date, attr);

This is where the request is created.

    // GetFeature request with filter, callback handles result from server
        TYPENAME : "floats",
        FILTER : filter
    }, displayFeatures);

    // fires a GetFeature WFS request to server
       function getFeature(callback) {
    // some default parameters that will be set automatically if not
       var parameters = {
        REQUEST : "GetFeature",
        SERVICE : "WFS",
        VERSION : "1.0",
        OUTPUTFORMAT : "json",
        TYPENAME : "floats",
        FILTER : filter

      asyncGetRequest(parameters, callback);

Since OL3 does not have filter I used CQL filter. I exchanged FILTER : filter with CQL_FILTER : filter in the parameterlist. See http://docs.geoserver.org/stable/en/user/tutorials/cql/cql_tutorial.html

The differense is that CQL Filter has to be build in SQL syntax before added to the parameterlist.


var filter_list = [];    
var dateFilterString = 'stdate BETWEEN ' + formFactory.getFromDate() + ' AND ' + formFactory.getToDate();

*******add more filters********
var filter =  filter_list.join(' AND ');
  • Hi. This is nice information, but can you please write an example with all your full code, so I can clearly understand how you set the layer and the WFS and the filter? Thanks – slevin Nov 1 '15 at 19:40

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.