0

I'm trying to refresh a source with some parameter. There is a text input control on the html page, I look forward to updating the map based on user input after clicking the button, but it doesn't work.

The code is below:

var untiled = new ol.layer.Image({
    source: new ol.source.ImageWMS({
      ratio: 1,
      url: 'http://localhost:8080/geoserver/newyork/wms',
      params: {         
            "LAYERS": 'newyork:viewStation',
            "viewparams": 'id:'+10
      }
    })
  });

var map =new ol.Map({
    target:'map',
    layers:[
        new ol.layer.Tile({
            source:new ol.source.OSM()
        }),
        untiled
    ],
    view: new ol.View({
        center:new ol.proj.fromLonLat([-73.9,40.8]),
        zoom:10
    })
});

function repaint(){
    var num=document.getElementById('textfield').value;
    untiled.getSource().updateParams({'id':num});
    untiled.getSource().refresh();
}

var bnt=document.getElementById('button');
bnt.addEventListener('click',repaint)
2
  • 1
    If you want to update viewparams you will need untiled.getSource().updateParams({"viewparams": 'id:'+num});
    – Mike
    Oct 15, 2020 at 9:03
  • It works! Thank you Mike
    – Nemo
    Oct 15, 2020 at 10:14

1 Answer 1

1

To update viewparams you will need

untiled.getSource().updateParams({"viewparams": 'id:'+num});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.