在openlayers(5/6)中使用clusterSource时,我可以很好地对功能进行聚类。
除了作为我的clustersource的源的vectorsource之外,它还在不断更改数据。
我有一个websocket可为我提供所需的位置信息(例如水运中的船只或Flightradar24上的飞机)
底层源代码的每一次更改都让我有种感觉,我的聚类工作就完成了。
有没有办法邮寄该更新?还是手动调用?
我可以缓冲输入流并一次处理更多的消息(例如每3秒更新1000个位置)
我希望在处理完这1000条消息之后进行聚类。
现在它变得如此缓慢,以至于我感觉到它在每条消息中都会发生(所以每3秒1000次)
另一种优化方法是仅对当前可见的项目进行聚类(在聚类距离一侧的边缘带有缓冲区)
我认为这将节省大量计算。
这里有人可以帮我吗?
现在我有这样的东西(在元代码中):
const features = {}; //my own reference collection
const buffer = []; //it's get filled somewhere else (constantly)
function processBuffer() {
//here we like to pause the clustering logic
buffer.forEach(function(message){
let feature = features[message.id];
if (feature) {
//existing feature
feature.getGeometry().setCoordinates(message.coord);
} else {
//new feature
feature = ... create feature ...
vectorSource.addFeature(feature);
}
});
//here we like to continue the clustering logic
//reset buffer
buffer.length = 0;
}
setInterval(processBuffer, 3000);
最佳答案
通过使用.clear()
和.addFeatures()
的数组替换源中的所有功能应该更有效。