[英]Force refresh openlayers 5.3 cluster source with bbox strategy
我正在将OpenLayers用于我们的javascript地图应用程序。 有一个具有自定义加载器功能的群集层(这意味着数据是通过此功能从数据库加载的),并且行为设置为bbox ,这意味着该层在用户每次移动地图时都会刷新。
let vectorSource = new sourceVector({
strategy: bbox,
loader: function(extent, resolution, projection) {
Log.warn("refresh attempt");
// other long code that is not important and works well
}
});
let clusterSource = new Cluster({
distance: 25,
source: vectorSource
});
但是,我处于底层数据被用户更改的情况,我需要手动刷新地图。
我尝试了很多发现的方法,例如:
clusterSource.refresh(); // does nothing
layer.set('visible', false);
layer.set('visible', true); // does nothing
map.removeLayer(layer);
map.addLayer(layer); // does nothing
clusterSource.clear(true); // removes all items from the map but does not call loader function to load them again
clusterSource.loadedExtentsRtree_.clear(); // does nothing
到目前为止,唯一有效的方法是将地图移到其他位置然后返回:
let originalCenter = [
map.getView().getCenter()[0],
map.getView().getCenter()[1]
];
let newCenter = [
map.getView().getCenter()[0] + 50,
map.getView().getCenter()[1] + 50
];
setTimeout(() => {
map.getView().animate({
center: newCenter,
duration: 0
});
setTimeout(() => {
map.getView().animate({
center: originalCenter,
duration: 0
});
}, 10);
}, 10);
但这当然会使地图在那儿来回闪烁 ,我想避免这种情况。 对于这个实际可行的问题,有一些隐藏的解决方案吗? 我只想强制集群层调用已定义的加载器函数 ,但我并不认为这会成为问题。
感谢您的任何提示,Vojtech
感谢迈克的建议,我找到了解决方案。
解决方案如下(关键是使用群集源的内部vectorSource):
clusterSource.getSource().clear();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.