Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

  var wmsSource = new ol.layer.Tile({
            source: new ol.source.TileWMS({
                url: wmsIp()+'/geoserver/test/wms',
                params: { 
                    'LAYERS': 'LayerName',
                    'singleTile': true 
                }
            })
        })
  map.addLayer(wmsSource);
  
  map.on("click",function(e){
    //在这个map的点击函数里获取wmsSource图层的名称
  
  })
  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
265 views
Welcome To Ask or Share your Answers For Others

1 Answer

你说的图层名称应该不是变量名称,但是在openlayers中,layer没有具体的名称这一属性,所以我们只有去自定义属性

var wmsLayer = new ol.layer.Tile({
    name: 'layerName',
    source: youSource
})

然后获取,直接layer.get就可以

wmsLayer.get('name')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...