![](/img/trans.png)
[英]How to remove style from individual feature of a Vector Layer in Open Layers?
[英]remove layer from open layers not working
我正在嘗試從GeoServer添加圖層; 它工作正常,但刪除圖層無效。 這是我的代碼:
function loadTOCLayer(layerName) {
var tl = new ol.layer.Tile({
extent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
source: new ol.source.TileWMS( /** @type {olx.source.TileWMSOptions} */ ({
url: 'http://172.16.1.58:8080/geoserver/KBJNL/gwc/service/wms',
params: {
'LAYERS': layerName,
'TILED': true
},
serverType: 'geoserver'
}))
});
map.addLayer(tl);
}
function removeTOCLayer(ss) {
map.removeLayer(ss);
}
您正在混合圖層名稱和圖層參考。 您必須按名稱保留圖層索引。 嘗試這個:
var layersByName = {};
function loadTOCLayer(layerName) {
var tl = new ol.layer.Tile({
extent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
source: new ol.source.TileWMS( /** @type {olx.source.TileWMSOptions} */ ({
url: 'http://172.16.1.58:8080/geoserver/KBJNL/gwc/service/wms',
params: {
'LAYERS': layerName,
'TILED': true
},
serverType: 'geoserver'
}))
});
layersByName[layerName] = tl;
map.addLayer(tl);
}
function removeTOCLayer(ss) {
map.removeLayer(layersByName[ss]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.