I'm updating a WMS-Layer in a OL3-Map.

I tried to reload the wms-layer with updated clq_filter-params.

Can anyone correct my code or give me a working example?

// initialize filtervariable to show all states
var filterstring = "PERSONS>1";

// WMS Layer with cql-filter var filterstring
    var layers = [
            new ol.layer.Image({extent: [-13884991, 2870341, -7455066, 6338219],
            source: new ol.source.ImageWMS({url: 'http://demo.opengeo.org/geoserver/wms',
            params: {'LAYERS':'topp:states','cql_filter': filterstring},
            serverType: 'geoserver'})}                  

// OL Karte mit WMS
var map = new ol.Map({
    layers: layers,
    target: 'map',
    view: new ol.View({
    center: [-10997148, 4569099],
    zoom: 4

// get Filtervalue from form and replace clq-filter in ol.layer.tile params  
document.getElementById("submitBtn").addEventListener("click", func1);
    function func1(){
        var a=document.getElementById("zahl").value;
        var filterstring = "PERSONS>" + a;

I haven't tested this but I'm pretty sure that:

var filterstring = "PERSONS>" + a;

should be

filterstring = "PERSONS>" + a;

otherwise the global filterString is hidden by the local one.


you can use this example.

function createparams() {MinPrice, MaxPrice, MinArea, MaxArea}
var MinPrice = document.getElementById('MinPrice').value;
var MaxPrice = document.getElementById('MaxPrice').value;
var MinArea = document.getElementById('MinArea').value;
var MaxArea = document.getElementById('MaxArea').value;
var cql = "'(price Between " +MinPrice.toString()+ ' AND '+ MaxPrice.toString()+ ') AND (area Between '+MinArea.toString()+ ' AND '+ MaxArea.toString()+ ")'";

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.