2

I've two simple problems, but I can't fix it by my own :o(

My OL-map features a basemap and a cql-filtered WMS from my local geoserver (topp:states).

  1. The map is just shown, when i click the filterform -> how can i load the map befor filtering?

  2. the filter wors fine but when i change the parameter and click the filterform again a new map-instance comes up in my website! -> how can i reload (just) the map with the filtered wms?

Any Help? I'm so thankfull for a "code-supplement" of my code: this is my code:

document.getElementById("submitBtn").addEventListener("click", getFilteredMap);

function getFilteredMap(){

    var a = document.getElementById("persons").value;
    var b = document.getElementById("cars").value;
    var c = document.getElementById("penners").value;

var filterstring = 'PERSONS>' + a + 'AND CARPOOL>' + b + 'AND UNEMPLOY>' + c;


    var layers = [
        new ol.layer.Tile({
            source: new ol.source.MapQuest({layer: 'osm'})
        }),
        new ol.layer.Image({
            source: new ol.source.ImageWMS({url: 'http://localhost:8082/geoserver/wms',
            params: {'LAYERS':'topp:states', 'cql_filter': filterstring},
            serverType: 'geoserver'})}                  
        )
    ];      

var map = new ol.Map({
    layers: layers,
    target: 'map',
    view: new ol.View({
        center: [0, 0],
        zoom: 2
    })
});}    

I think i can't make it the layer variable a global variable beacuae i neet to compute the new cql-statement wich is a part of my layer-variable.

Maybee i'm wrong ?!

can you correct my code snipplet?

1

You could try making your layers variable a global variable and then updating this on its own. Currently you are creating a new map and new layers every time you call getFilteredMap()?

I think you can use layer[1].getSource().updateParams({params}); to update the topp:states layer.

  • Hey thank you so much! It worked now! I didn't know that i've to use the index of the array to select the layer (layer 2 = index 1). This worked for me: layers[1].getSource().updateParams({'LAYERS':'topp:states','cql_filter': filterstring}); – crazypix Jan 13 '16 at 8:34

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.