![](/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.