Obtaining Layer name when clicking on the map

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Obtaining Layer name when clicking on the map

Jsantos
Hello all,

I have 4 layers in the map and need to determine the layer that I clicked in. I have the following code inside  map.on('singleclick', function (evt) , but feature is always undefined.

var displayFeatureInfo = function(pixel ) {
  var feature = map.forEachFeatureAtPixel(pixel, function(feature, layer) {
    return feature;
    });

My layers are like this one:

var wmsSourceWatermains = new ol.source.TileWMS({
    url: 'http://192.168.1.113:8080/geoserver/wms',
    params: { 'LAYERS': 'watermains' },
    serverType: 'geoserver'

});


I create the layers with :

var layers = [

    new ol.layer.Tile({
      source: new ol.source.OSM()
    }),
     
    new ol.layer.Tile({
     source: wmsSourcePzones
    }),

   new ol.layer.Tile({
       source: wmsSourcePrv_stns
   }),

    new ol.layer.Tile({
     source: wmsSourceWatermains
    }),

];

Any help will be very much appreciated.
TIA
Jsantos