在 openlayers (5/6) 中使用 clusterSource 时,我可以很好地对功能进行聚类。
除了作为我的 clustersource 源的矢量源不断更改数据。 我有一个 websockets 可以为我提供位置信息(例如 Marinetrafic 中的船只或 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()
通过数组替换源中的所有功能应该会更加高效。
关于javascript - openlayers 集群非常慢,位置不断变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59628754/