传单:将图层组添加到地图非常慢 [英] Leaflet: adding layer group to map is very slow
本文介绍了传单:将图层组添加到地图非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向传单地图中添加大约2500个图标(每个2 Kb).填充数组没有问题.但是,将图层组添加到地图需要2到5秒钟.有什么建议可以提高性能吗?
I am trying to add some 2500 icons (2 Kb each) to a leaflet map. Filling the array is no problem. Adding the layer group to the map, however, takes between 2 and 5 seconds. Any suggestion how to improve the performance?
var icongroup = [];
for (id in reclist) {
var recname = reclist[id][0];
var posn = reclist[id][1];
var pose = reclist[id][2];
var mapicon = L.icon({iconUrl: icon, iconSize: [26, 29]});
icongroup.push(L.marker([posn, pose], {icon: mapicon}));
}
L.layerGroup(icongroup).addTo(map);
推荐答案
向页面添加数千个标记肯定会增加浏览器的资源.这很有可能是您延迟的原因.
Adding thousands of markers to the page stresses the browser ressources for sure. There is a high chance this is the reason for your delay.
您应该考虑用画布替换标记或将标记聚类.
You should consider replacing your markers by a canvas, or clustering them.
另请参阅:在leafletjs中绘制140K点
这篇关于传单:将图层组添加到地图非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文