/**
* 添加单个矢量图层
*/
addVectorLayer() {
let workspace = 'xxx'
let name = 'yyy';
let layer = new VectorLayer({
source: new VectorSource({
url: 'geoserver/'+ workspace +
'/ows?service=WFS&version=1.0.0&request=GetFeature&typeName='+ workspace + ':' + name +
'&outputFormat=application%2Fjson',
format: new format()
}),
visible: true,
opacity: 1
})
this.map.addLayer(layer)
}
设置图层的显示与隐藏
//显示
layer.setVisible(true)
//隐藏
layer.setVisible(false)