I'm using GetInfo to view the cover information and my problem using this command is: The information displayed is not from the cover seen on the map, but from the first cover inserted in the code. I always see information from the cover Layer_21_11_19 even if I'm seeing and clicking on the cover Layer_12_12_19.

Please, does anyone know how to show the information only on the cover I'm seeing and clicking?

map.on('click', function getInfo(e){
 if(e.name !== 'Click'){
  e.name = "Click";
  map.addEventListener('click', (evt) => {
   const projection = map.getView().getProjection().getCode()
   const isGlobal = map.getView().getProjection().isGlobal()
   const viewResolution = view.getResolution();
   const wmsSource = new ol.source.ImageWMS({
    url: 'http://localhost:8080/geoserver/WORK/wms',
     params: {'LAYERS': [
     ]} });
   url = wmsSource.getFeatureInfoUrl(
    {'INFO_FORMAT': 'text/html','FEATURE_COUNT': 1}
    const closer2 = document.getElementById('popup-closer2');
    const content2 = document.getElementById('popup-content2');
    const xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = () => {
     if (xhttp.readyState === 4 && xhttp.status === 200) {
      content2.innerHTML = xhttp.responseText;
     xhttp.open("GET", url, true);
    } else if (e.name === 'Click'){
     e.name = "Unclick";
    } }) } } })

You need to either specify just the layer you are interested in in the LAYERS parameter or increase the number of features returned by increasing FEATURE_COUNT.

  • Thanks for the help. I had already tried to define the layers with QUERY_LAYERS, but if I use this, I only see the information about the layers that are in the query and I want to see the information about the layer that I am clicking. I had also already tried to put FEATURE_COUNT but it doesn't show the information about the layer I'm clicking, it shows 10 informations (10 is an example) of the first layer defined in LAYERS. It is as if GetInfo uses the map area independently, without identifying which layer is active. – Dany Jul 30 '20 at 11:54
  • You need to make sure that LAYERS and QUERY_LAYERS match in the request, this is what GetInfo does use - it has no clue as to which layers you are viewing – Ian Turton Jul 30 '20 at 12:08

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.