在重新绘制OpenLayers之前清除WMS图层 [英] Clear WMS layer before redraw on OpenLayers

查看:1998
本文介绍了在重新绘制OpenLayers之前清除WMS图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用OpenLayers(Vector和WMS)成功显示多个图层。
我的应用程序允许用户修改一些参数,这些参数将:

*修改绑定

*修改地图中心

*修改WMS图像

我使用Ajax来避免页面重新加载,它工作得很好,但是当某些图层需要一段时间加载时,尚未重新绘制的其他图层仍会在后台显示(但根本不相关)到我的新语境)。
我想在重新询问服务器以获取新图像之前清除WMS图层(如果可能),但还没有找到任何内容。
我通过调用removeAllFeature()来在向量层上执行此操作;



感谢您的帮助!



<当用户点击按钮时,这是我的伪代码:

  $。getJSON(url / updateMapConfig.php ,
{
data:$(this).serialize(),
ajax:'true',
cache:'false'
},
function(j){
if(j.result =='ok'){
var layersToShow = [];
//刷新矢量图层
(var i = 0 ; i< map.layers.length; i ++){
if(map.layers [i] .isVector){
map.layers [i] .removeAllFeatures();
map.layers [i] .refresh({force:true}); //向量图层
}
}
//为(var i = 0; i< map)刷新可见图层
.layers.length; i ++){
if(map.layers [i] .visibility&&!map.layers [i] .isBaseLayer&&!map.layers [i] .isVecto r){//刷新可见的非基础
map.layers [i] .redraw(true); //其他图层
}
}
//设置新边界
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);
//移动到目的地点
if(j.poiCenter!=){
eval(map.setCenter(new OpenLayers.LonLat(+ j.poiCenter +)) );
}
}
}
);


解决方案

我终于找到了使用clearGrid的快乐结局( )在重绘它们之前对每一层进行操作。



我还发现如果有任何正在运行,此函数将停止平铺加载。
示例我有两个基础层:EmptyLayer和WhateverTiledBGLayer。
如果花费20秒加载WhateverTiledBGLayer图块,即使用户选择切换到空图层,我也可以看到服务器对WhateverTiledBGLayer上剩余图块的请求。



简单地调用WhateverTiledBGLayer.clearGrid()将停止请求图层。



感谢您的帮助。


I'm currently successfully displaying multiple layers using OpenLayers (Vector and WMS). My application allow the user to modify some parameters, which will :
* modify bound
* modify map center
* modify the WMS image
I use Ajax to avoid page reload, it works nicely, however when some layers take a while to load, the others which are not yet redrawn are still shown in the background (but aren't related at all to my new context). I would like to clear WMS layers (if possible) before re-asking the server for the new image but didn't find anything yet. I do this on the vector layer by calling removeAllFeature();

Thanks for any help !

Here is my pseudo-code when the user click the button :

$.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+"))");  
        }  
      }  
    }  
);  

解决方案

I finally found out an happy ending using the clearGrid() function on every layer before redrawing them.

I also found that this function will stop tile loading if any is running. Example I had two base layer : EmptyLayer and WhateverTiledBGLayer. if it tooks 20s to load WhateverTiledBGLayer tiles, even if the user chose to switch to empty layer, I could see the request done to the server for the remaining tiles on WhateverTiledBGLayer.

Simply calling WhateverTiledBGLayer.clearGrid() will stop requesting layers.

Thanks for help.

这篇关于在重新绘制OpenLayers之前清除WMS图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆