TransWikia.com

GetFeatureInfo for multiples layers openlayers 6

Geographic Information Systems Asked by user68481 on December 23, 2020

I’m trying to get information from several layers in Openlayers 6, but it only returns information from one. I define the layers and a source with the url and the layers as params

var spDo = new ol.layer.Image({
    title:'DO's',
    baseLayer:false,
    source: new ol.source.ImageWMS({
       url: 'http://localhost:8080/geoserver/grap/wms',
       params: {'LAYERS': 'land:do_s'},
       serverType: 'geoserver',
    }),
    visible:true,
    active:false,
    //opacity: 0.4,
    displayInLayerSwitcher:false
});
var spParc = new ol.layer.Image({
    title:'Parcels',
    baseLayer:false,
    source: new ol.source.ImageWMS({
        url: 'http://localhost:8080/geoserver/grap/wms',
        params: {'LAYERS': 'land:geo_land'},
        serverType: 'geoserver',
    }),
    visible:true,
    active:false,
    //opacity: 0.4,
    displayInLayerSwitcher:false
});
var spParCom = new ol.layer.Image({
    title:'Control Parcels',
    baseLayer:false,
    source: new ol.source.ImageWMS({
        url: 'http://localhost:8080/geoserver/grap/wms',
        params: {'LAYERS': 'land:vw_parcels'},
        serverType: 'geoserver',
    }),
    visible:true,
    active:false,
    //opacity: 0.4,
    displayInLayerSwitcher:false
});
var demRequest= new ol.source.ImageWMS({
    url: 'http://localhost:8080/geoserver/grap/wms',
    params: {'LAYERS': 'land:do_s, land:geo_land, land:vw_parcels'},
});
map.on('singleclick', function (evt) {
    document.getElementById('info').innerHTML = '';
    var viewResolution = /** @type {number} */ (view.getResolution());
    var url = demRequest.getFeatureInfoUrl(
        evt.coordinate,
        viewResolution,
        EPSG:3857',
       {
        'INFO_FORMAT': 'text/html',
        'QUERY_LAYERS': 'land:do_s, land:geo_land, land:vw_parcels
       }
    );
    if (url) {
        fetch(url)
         .then(function (response) { return response.text(); })
         .then(function (html) {
        document.getElementById('info').innerHTML = html;
    });
    }
});

I don’t understand the problem, I define the list of the layers in the url params and in the ‘QUERY_LAYERS’ according to the documentation.

The server response contains the three layers:

 ...REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=land%3Ado_s%2Cland%3Ageo_land%2Cland%3Avw_parcels&LAYERS=land%3Ado_s%2Cland%3Ageo_land%2Cland%3Avw_parcels&INFO_FORMAT=text%2Fhtml...

2 Answers

In general, the best way to debug these issues is to look in the Network tag of the debugger and see what URL is actually being sent to the server and what its response is.

In your case I think you will see that the LAYERS parameter of the request only contains the name of one layer. The standard requires all the layers in the QUERY_LAYERS parameter to be in the LAYERS parameter in the same order. This allows the server to "draw" the right picture of the map so it can work out what you have clicked on.

If it isn't that then edit your question to show what is returned by the server (or failing that look in the server log file to see what went wrong).

Answered by Ian Turton on December 23, 2020

As an example a query that works with the demo data that comes with GeoServer installation. Notice the FEATURE_COUNT parameter. The default value is 1 and even it should mean the maximum number of features per layer by the WMS standard, GeoServer counts all the layers together and with FEATURE_COUNT=1 it returns the result only from the first queried layer.

http://localhost:8080/geoserver/topp/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=topp%3Atasmania_water_bodies,topp%3Atasmania_state_boundaries&STYLES&LAYERS=topp%3Atasmania_water_bodies,topp%3Atasmania_state_boundaries&exceptions=application%2Fvnd.ogc.se_inimage&INFO_FORMAT=text%2Fhtml&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG%3A4326&WIDTH=101&HEIGHT=101&BBOX=146.60969816378798%2C-42.06637984372225%2C146.88710294894423%2C-41.788975058566

The same as text for clarity.

http://localhost:8080/geoserver/topp/wms?
SERVICE=WMS&VERSION=1.1.1&
REQUEST=GetFeatureInfo&
FORMAT=image/png&TRANSPARENT=true&
QUERY_LAYERS=topp:tasmania_water_bodies,topp:tasmania_state_boundaries&
STYLES&
LAYERS=topp:tasmania_water_bodies,topp:tasmania_state_boundaries&
exceptions=application/vnd.ogc.se_inimage&
INFO_FORMAT=text/html&
FEATURE_COUNT=50&
X=50&
Y=50&
SRS=EPSG:4326&
WIDTH=101&
HEIGHT=101&
BBOX=146.60969816378798,-42.06637984372225,146.88710294894423,-41.788975058566

Answered by user30184 on December 23, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP