Skip to content

Commit 9539575

Browse files
committed
Fix to performance problem
This fixes a problem where initialising a map with many markers (e.g. 100 or more) was slow. The slowness was caused by the fact that addNewMarker called replot for each point. This fix causes the map only to replot after all points have been added.
1 parent ec4d110 commit 9539575

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/leaflet.plotter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ L.Polyline.plotter = L.Polyline.extend({
5555
}
5656
},
5757
_bindMapClick: function(){
58-
this._map.on('click', this._addNewMarker, this);
58+
this._map.on('click', this._onMapClick, this);
5959
},
6060
_unbindMapClick: function(){
6161
this._map.off('click', this._addNewMarker, this);
@@ -97,11 +97,14 @@ L.Polyline.plotter = L.Polyline.extend({
9797
this._lineMarkers.splice(this._lineMarkers.indexOf(e.target), 1);
9898
this._replot();
9999
},
100+
_onMapClick: function(e){
101+
this._addNewMarker(e);
102+
this._replot();
103+
},
100104
_addNewMarker: function(e){
101105
var newMarker = this._getNewMarker(e.latlng, { icon: this._editIcon });
102106
this._addToMapAndBindMarker(newMarker);
103107
this._lineMarkers.push(newMarker);
104-
this._replot();
105108
},
106109
_redrawHalfwayPoints: function(){
107110
for(index in this._halfwayPointMarkers){
@@ -139,6 +142,7 @@ L.Polyline.plotter = L.Polyline.extend({
139142
)
140143
});
141144
}
145+
this._replot();
142146
},
143147
_redraw: function(){
144148
this.setLatLngs([]);

0 commit comments

Comments
 (0)