我目前使用OpenLayers(Vector和WMS)成功显示多个图层。 我的应用程序允许用户修改一些参数,这将:
*修改势必
*修改地图中心
*修改WMS图像
我使用Ajax来避免页面重载,它工作得很好,但是当一些层需要一段时间才能加载,其他尚未重绘的图像仍会显示在背景中(但与我的新上下文无关)。 我想在重新向服务器请求新图像之前清除WMS图层(如果可能),但尚未找到任何东西。 我在矢量图层上通过调用removeAllFeature();在OpenLayers上重绘之前清除WMS图层
感谢您的帮助!
这里是我的伪代码,当用户点击该按钮:
$.getJSON("url/updateMapConfig.php",
{
data: $(this).serialize() ,
ajax: 'true',
cache: 'false'
},
function(j){
if (j.result == 'ok') {
var layersToShow = [];
// Refresh vector layer
for(var i=0;i<map.layers.length;i++) {
if (map.layers[i].isVector) {
map.layers[i].removeAllFeatures();
map.layers[i].refresh({force:true}); // Vector layer
}
}
// Refresh visible layers
for(var i=0;i<map.layers.length;i++) {
if (map.layers[i].visibility && !map.layers[i].isBaseLayer && !map.layers[i].isVector) { // Refresh visible non base
map.layers[i].redraw(true); // Other layer
}
}
// Set new bounds
var bounds = new OpenLayers.Bounds();
bounds.extend(new OpenLayers.LonLat(j.bounds.xmin-100, j.bounds.ymin-100));
bounds.extend(new OpenLayers.LonLat(parseInt(j.bounds.xmax)+100, parseInt(j.bounds.ymax)+100));
map.zoomToExtent(bounds);
// Move to destination point
if (j.poiCenter != "") {
eval("map.setCenter(new OpenLayers.LonLat("+j.poiCenter+"))");
}
}
}
);
谢谢,我试过:map.layers [i] .setVisibility(false); \t \t \t \t \t map.layers [i]中。setVisibility(真);然而,这层仍然保留,直到重绘,足够奇怪。我会尝试mergeNewParams – 2011-02-11 08:43:10
也许你必须在设置可视性时强制重绘?尽管看起来不太可能... – 2011-02-11 10:48:41