Consider adding bulkAddBegin/bulkAddEnd methods #59

Closed
danzel opened this Issue Sep 11, 2012 · 5 comments

Projects

None yet

3 participants

@danzel
Member
danzel commented Sep 11, 2012

Currently when you call addLayer while the MarkerClusterGroup is on the map it will add/remove/update markers on the map as it goes.
Need to investigate if this is a performance issue, if it is then add some new methods:

bulkAddBegin: Stops addLayer from adding/updating/removing layers on the map
bulkAddEnd: Adds all layers that should be on the map to the map.

This is for the cases where you load 1000s more markers via AJAX later.

@mourner
Member
mourner commented Sep 13, 2012

Or you can just do addLayers(array).

@danzel
Member
danzel commented Sep 13, 2012

As always you are a genius :-) That sounds so obvious now!

I'll bring this in with layer support, so you can add/remove layer groups and it'll add/remove their child markers.

@danzel danzel added a commit that referenced this issue Oct 10, 2012
@danzel danzel Add addLayers, takes an array of markers and adds them in bulk for aw…
…esome performance. TODO: Docs+Example. Refs #59
9dab59f
@danzel
Member
danzel commented Oct 10, 2012

This is implemented with addLayers and removeLayers now.

Performance difference of adding markers after adding the MarkerClusterGroup to the map:

Adding 10000 markers
addLayers: 700ms
addLayer in a loop: 4000ms

Removing those 10000 markers:
removeLayers: 1200ms
removeLayer in a loop: 4200ms
clearLayers: 25ms (not really fair!)

Removing half (5000) of them
removeLayers: 620ms
removeLayer in a loop: 2100ms
clearLayers then addLayers the ones we want: 360ms

Removing 100 of them
removeLayers: 90ms
removeLayer in a loop: 100ms
clearLayers then addLayers the ones we want: 675ms

Removing 9000 of them
removeLayers: 1172ms
removeLayer in a loop: 3800ms
clearLayers then addLayers the ones we want: 120ms

Hrm, these really make removeLayers look bad :(

If you are removing lots of layers I definitely recommend clearLayers then addLayers. Will add this to the documentation.
Removing layers can also end up with some badly positioned clusters on the map when removing lots, so it is usually the wrong way to do it anyway.

@danzel danzel closed this Oct 10, 2012
@kylebradshaw

found this when swapping out clusters and it's really handy. I'm leveraging clearLayers() is there a way to do this that animates out the clusters and allows me to animate in the newly loaded ones?

@danzel
Member
danzel commented Dec 19, 2014

Nope sorry.

On Wednesday, 17 December 2014, Kyle Bradshaw notifications@github.com
wrote:

found this when swapping out clusters and it's really handy. I'm
leveraging clearLayers() is there a way to do this that animates out the
clusters and allows me to animate in the newly loaded ones?


Reply to this email directly or view it on GitHub
#59 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment