Clear WMS layer before redraw on OpenLayers

六眼飞鱼酱① 提交于 2019-12-06 16:46:18

I would use mergeNewParams to set a param that makes the layer draw blank. That method triggers a redraw of the layer. When your callback returns from your update request, you do the opposite to make it draw the layer correctly again.

(I have done something similar to this, but I don't have the source for now)

EDIT:

Or - of course - hide the layers with the visibility property of the layers. :-)

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.

You could listen to WMS layer's loadstart and loadend event and hide/show layer accordingly.

A quick test showed though that you can't set visibility of the layer to false on loadstart because OpenLayers will then stop requesting new images for the layer and it will never be completely loaded. You could though try with layer.display(false/true) and see if it solves your problem. The code should look something like this:

  yourWmsLayer.events.on({
        "loadstart" : function(){
            this.display(false);
        },
        "loadend" : function(){
            this.display(true);
        } 
    });

BTW, if you don't set transitionEffect to "resize" on your WMS layer then the default behavior is that old images are removed before new ones are loaded. Isn't that what you want?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!