添加图层
// 引入1
import { Map, View } from "ol";
import Image from "ol/layer/Image";
import ImageWMS from "ol/source/ImageWMS";
// 新建
this.map = new Map({
view: new View({
center: [110.14, 32.57],
zoom: 9,
projection: new Projection({
code: "EPSG:4490",
units: 'm',
}),
maxResolution: 1.40625 * 2 * 2,
minZoom: 0,
maxZoom: 20
}),
layers: [],
target: 'map'
})
// 加载图层
var layers = new Image({
source: new ImageWMS({
url: 'url',
params: {
'LAYERS': 'name',
'VERSION': '1.1.1',
'STYLES': '',
'REQUEST': 'GetMap',
'SRS': 'EPSG:4490',
'exceptions': 'application/vnd.ogc.se_inimage'
},
serverType: 'geoserver',
})
})
// 添加到指定位置
this.map.getLayers().insertAt(1,layers)
// 添加图层, 层叠关系
// this.map.addLayer(layers)
更新图层
// 获取到所有图层
let Layers = this.map.getLayers();
Layers.array_.forEach(e => {
// 遍历所有图层 找到当前图层
if (e.ol_uid == activeList.ol_uid) {
// 删除当前图层
this.map.removeLayer(e)
var layers = new Image({
source: new ImageWMS({
url: 'url',
params: {
'LAYERS': 'name',
'VERSION': '1.1.1',
'STYLES': '',
'REQUEST': 'GetMap',
'SRS': 'EPSG:4490',
'exceptions': 'application/vnd.ogc.se_inimage'
},
serverType: 'geoserver',
})
})
// 重新添加图层
this.map.addLayer(layers)
// 还试过 e.getSource().refresh({ force: true, active: true }) 貌似没用
}
})
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。