瀏覽代碼

Merge pull request #705 from bpezan/bettermap

better performance when adding thousands of markers to bettermap.
Rashid Khan 12 年之前
父節點
當前提交
3f80ef0dcb
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      src/app/panels/bettermap/module.js

+ 6 - 2
src/app/panels/bettermap/module.js

@@ -213,14 +213,18 @@ function (angular, app, _, L, localRequire) {
               layerGroup.clearLayers();
               layerGroup.clearLayers();
             }
             }
 
 
+            var markerList = [];
+
             _.each(scope.data, function(p) {
             _.each(scope.data, function(p) {
               if(!_.isUndefined(p.tooltip) && p.tooltip !== '') {
               if(!_.isUndefined(p.tooltip) && p.tooltip !== '') {
-                layerGroup.addLayer(L.marker(p.coordinates).bindLabel(p.tooltip));
+                markerList.push(L.marker(p.coordinates).bindLabel(p.tooltip));
               } else {
               } else {
-                layerGroup.addLayer(L.marker(p.coordinates));
+                markerList.push(L.marker(p.coordinates));
               }
               }
             });
             });
 
 
+            layerGroup.addLayers(markerList);
+
             layerGroup.addTo(map);
             layerGroup.addTo(map);
 
 
             map.fitBounds(_.pluck(scope.data,'coordinates'));
             map.fitBounds(_.pluck(scope.data,'coordinates'));