[英]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.