本文介绍了在以法律方式更改地图中心和缩放后如何重新加载WMTS Tiles?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一项功能,供用户选择与地图上某个点相对应的列表项.我目前能够设置正确的地图中心和缩放级别,但是在我导致在地图上发生MouseWheelZoom交互之前,地图图块为空白.如何使WMTS图层更新到新的缩放级别和地图范围?

I'm implementing a feature for users to select a list item that corresponds to a point on the map. I am currently able to set the correct map center and the zoom level but the map tiles are blank until I cause a MouseWheelZoom interaction to occur on the map. How do I get my WMTS layers to update to the new zoom level and map extent?

推荐答案

原则上,更改WMTS源的tileUrlFunction将触发刷新,因为这将清除切片缓存.如果您很幸运,并且您的WMTS服务器正确使用了Etags,则只需再次使用相同的url函数即可:

In principle, changing the tileUrlFunction of a WMTS source will trigger a refresh, because that clears the tile cache. If you're lucky and your WMTS server makes proper use of Etags, just using the same url function again will work:

wmtsSource.setTileUrlFunction(wmtsSource.getTileUrlFunction());

如果您的WMTS服务器仅设置了过期标头,则必须在URL后面附加一些内容以强制浏览器重新获取它.假设您使用KVP编码与WMTS服务器通信,则可以通过执行以下操作来实现此目的

If your WMTS server just sets expire headers, you'll have to append something to the url to force the browser to refetch it. Assuming you use KVP encoding to talk to your WMTS server, you could achieve this by doing something like

var random = Math.random();
var originalTileUrlFunction = wmtsSource.getTileUrlFunction();
wmtsSource.setTileUrlFunction(function() {
  return originalTileUrlFunction.apply(this, arguments) + '&' + random;
});

这篇关于在以法律方式更改地图中心和缩放后如何重新加载WMTS Tiles?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-31 15:53