如何在单击时获取 wms 图层名称.我以不同的方式尝试过,但我没有得到.我以这种方式有 3 个 wms 层



我有 3 个 wms 层,这样如何获取 wms这些图层的图层名称

var tiled = new ol.layer.Tile({
    visible : false,
    source : new ol.source.TileWMS({
        url : 'http://192.168.4.229:8080/geoserver/geodata/wms',
        params : {
            'FORMAT' : 'image/png',
            'VERSION' : '1.1.1',
            "LAYERS" : 'geodata:ht_line',
            tiled : true,
            "exceptions" : 'application/vnd.ogc.se_inimage',
        }
    })
您可以使用

映射的forEachLayerAtPixel方法执行此操作:

map.on('click', function(e) {
  map.forEachLayerAtPixel(e.pixel, function(layer) {
    // log the LAYERS param of the WMS source
    console.log(layer.getSource().getParams().LAYERS);
  });
});

最新更新