添加圖層
// 引入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)
// 添加圖層, 層疊關(guān)系
// this.map.addLayer(layers)
更新圖層
// 獲取到所有圖層
let Layers = this.map.getLayers();
Layers.array_.forEach(e => {
// 遍歷所有圖層 找到當(dāng)前圖層
if (e.ol_uid == activeList.ol_uid) {
// 刪除當(dāng)前圖層
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 }) 貌似沒用
}
})
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。