Cecilie
Cecilie

Reputation: 13

Create filtered request to wms/wfs openlayers 3

I need to create a filtered WMS request to Geoserver. I am rewriting an openlayers 2 application which make these requests using OpenLayers.Filter. How can this be done in Openlayers 3 where the Filters are removed from the API?

Here is an example how the query is in Openlayers 2:

function dateFilter(date) {
    var dateTimeFilterArray = [];

    var dateFilter = new OL.Filter.Comparison({
        type : OL.Filter.Comparison.BETWEEN,
        property : "stdate",
        lowerBoundary : date.fromDate,
        upperBoundary : date.toDate
    });

    dateTimeFilterArray.push(dateFilter);

    var timeFilter = new OL.Filter.Comparison({
        type : OL.Filter.Comparison.BETWEEN,
        property : "sttime",
        lowerBoundary : date.fromTime,
        upperBoundary : date.toTime
    });

    dateTimeFilterArray.push(timeFilter);

    return combineFilters(dateTimeFilterArray);
}

Upvotes: 1

Views: 4390

Answers (1)

ahocevar
ahocevar

Reputation: 5648

For WMS requests to GeoServer, you can use CQL filters, e.g.

function dateFilter(date) {
  var dateFilter =
      'stdate BETWEEN ' + date.fromDate + ' AND ' + date.toDate;
  var timeFilter =
      'sttime BETWEEN ' + date.fromTime + ' AND ' + date.toTime;
  return '(' + dateFilter + ') AND (' timeFilter + ')';
}

wmsSource.updateParams({
  CQL_FILTER: dateFilter(date)
});

Please read up on date and time literals in the ECQL reference to make sure you use the correct date and time format for the CQL filter. My snippet above assumes that the properties of your date object are in the correct format already. It also assumes that your current combineFilters() function combines the filters using logical AND.

Upvotes: 3

Related Questions