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

╄→尐↘猪︶ㄣ 提交于 2019-12-23 01:19:12

问题


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?


回答1:


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());

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;
});


来源:https://stackoverflow.com/questions/29308830/how-to-reload-wmts-tiles-after-progromattically-changing-the-map-center-and-zoom

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