我有 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);
});
});