位置不断变化的openlayers集群非常慢 [英] openlayers clustering is very slow with ever changing positions
问题描述
在openlayers(5/6)中使用clusterSource时,我可以很好地对功能进行聚类.
when using a clusterSource in openlayers (5/6) i can cluster features nicely.
除了作为我的clustersource来源的vectorsource以外,它会不断更改数据. 我有一个websocket可以为我提供所需的位置信息(例如,海上运输的船只或Flightradar24上的飞机) 底层源代码的每一次更改都让我有种感觉,我的聚类工作就完成了. 有没有办法邮寄该更新?还是手动调用?
Except the vectorsource that is the source of my clustersource changes data constantly. I have a websockets that feeds me positions of stuff (like ships in marinetrafic or airplanes on flightradar24) I got the feeling with every change in the underlying source, my clustering gets done all over. Is there a way to postphone that update? or call it manually?
我可以缓冲输入流并一次处理更多的消息(例如每3秒更新1000个位置) 我希望在处理完这1000条消息之后进行聚类. 现在它变得如此缓慢,以至于我感觉到它在每条消息中都会发生(所以每3秒1000次)
I can buffer the input stream and process a higher number of messages at once (like 1000 position updates every 3 seconds) And i want the clustering to happen AFTER i processed those 1000 messages. It gets so slow now that i got the feeling it happens every message (so 1000 times every 3 seconds)
另一种优化方法是仅对当前可见的项目进行聚类(在聚类距离一侧的边缘周围有一个缓冲区) 我认为这将节省大量计算.
An other optimalisation would be to only cluster the items that are currently visible (with a buffer around the edges the side of the cluster distance) That would save a lot of calculation in my opinion.
这里有人可以帮我吗?
现在我得到了这样的信息(以元代码):
right now i got something like this (in meta-code):
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()
通过数组替换源中的所有功能应该更加有效.
Replacing all the features in the source via an array using .clear()
and .addFeatures()
should be much more efficient.
这篇关于位置不断变化的openlayers集群非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!