随着位置的不断变化,openlayers 集群非常缓慢
openlayers clustering is very slow with ever changing positions
在 openlayers (5/6) 中使用 clusterSource 时,我可以很好地聚类特征。
除了作为我的 clustersource 源的 vectorsource 不断更改数据。
我有一个 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()
通过数组替换源中的所有功能应该更有效。
如果您的数据太多,则不应全部显示。
- 对矢量图层使用最小-最大分辨率
- 不要从服务器发送您无法在即时 bbox 中显示的数据。
在 openlayers (5/6) 中使用 clusterSource 时,我可以很好地聚类特征。
除了作为我的 clustersource 源的 vectorsource 不断更改数据。 我有一个 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()
通过数组替换源中的所有功能应该更有效。
如果您的数据太多,则不应全部显示。
- 对矢量图层使用最小-最大分辨率
- 不要从服务器发送您无法在即时 bbox 中显示的数据。