OL3:强制重绘图层 [英] OL3: force redraw layer

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

问题描述

我目前正在使用新版本的OpenLayers,OL3升级OpenLayers客户端版本2.13.1。我的设置包括Mapserver作为WMS映射服务器和之前提到的OpenLayers客户端。

i am currently upgrading OpenLayers client version 2.13.1 with the new version of OpenLayers, OL3. My setup consist of Mapserver as a WMS mapping server and previously mentioned OpenLayers client.

在旧系统中,我支持用户交互,如果用户点击一些map的一部分,mapfile再次生成,因此我强制重绘图层以使地图的某些部分变为彩色。 OL2版本中的代码示例:

In old system I made support for user interaction in the way that if a user click on some part of map, the mapfile gets generated again, and as a result I force to redraw layer to get some part of map colored. Example of the code in the OL2 version:

$.ajax({
  params: ...
  success: function (data) {
    if (data.success) {
      gisLayer.redraw(true);
    }
  }
});

我想在OL3中获得相同的功能,但没有重绘功能。我找到了两个有用的函数,但是为了获得相同的功能还有其他的事情要做:
- layer.getSource()。updatePaarams(params);和
- map.render();

I want to get the same functionality in OL3, but there is no redraw function. I found two functions that are useful, but there is additional things to do in order to get the same functionality: - layer.getSource().updateParams(params); and - map.render();

我还创建了一个更复杂的例子,其中我得到了代码工作,但获取的请求WMS切片包含附加参数作为获取请求唯一的密钥。示例代码如上:

I also created a little bit more complicated example, in which I get code to working, but the requests for getting WMS tiles contains additional parameter as a key to get requests unique. The example code is above:

var params = layer.getSource().getParams();
params.t = getUniqueParam();
layer.getSource().updateParams(params);

好的,就是这种情况,我想问的是,是否有任何可用的功能,可以强制重绘图层,而无需在WMS请求中添加aditional参数? AFAIK的问题是浏览器缓存图像,如果请求是相同的,那么之前,浏览器会再次显示旧图像。

Ok, That is the situation, all I want to ask is if there is any function available, that can force layers to be redrawn, without adding aditional parameter in the WMS requests? AFAIK the "problem" is that browser cache images, and if the request is the same, that was before, browser shows old images again.

感谢您的帮助。

推荐答案

你能检查一下这是否有效?

Can you check if this does the trick?

yourLayerSource.dispatchChangeEvent(); 

这篇关于OL3:强制重绘图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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