简体   繁体   English

在以法律方式更改地图中心和缩放后如何重新加载WMTS Tile?

[英]How to reload WMTS Tiles after progromattically changing the map center and zoom?

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. 我目前能够设置正确的地图中心和缩放级别,但是在我导致在地图上发生MouseWheelZoom交互之前,地图图块为空白。 How do I get my WMTS layers to update to the new zoom level and map extent? 如何使WMTS图层更新到新的缩放级别和地图范围?

In principle, changing the tileUrlFunction of a WMTS source will trigger a refresh, because that clears the tile cache. 原则上,更改WMTS源的tileUrlFunction将触发刷新,因为这将清除图块缓存。 If you're lucky and your WMTS server makes proper use of Etags, just using the same url function again will work: 如果您很幸运,并且您的WMTS服务器正确使用了Etags,则只需再次使用相同的url函数即可:

wmtsSource.setTileUrlFunction(wmtsSource.getTileUrlFunction());

If your WMTS server just sets expire headers, you'll have to append something to the url to force the browser to refetch it. 如果您的WMTS服务器只设置了到期标头,则必须在URL后面附加一些内容以强制浏览器重新获取它。 Assuming you use KVP encoding to talk to your WMTS server, you could achieve this by doing something like 假设您使用KVP编码与WMTS服务器通信,则可以通过执行以下操作来实现此目的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM