Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding bulkAddBegin/bulkAddEnd methods #59

Closed
danzel opened this issue Sep 11, 2012 · 6 comments
Closed

Consider adding bulkAddBegin/bulkAddEnd methods #59

danzel opened this issue Sep 11, 2012 · 6 comments

Comments

@danzel
Copy link
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
Copy link
Member

mourner commented Sep 13, 2012

Or you can just do addLayers(array).

@danzel
Copy link
Member Author

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 added a commit that referenced this issue Oct 10, 2012
@danzel
Copy link
Member Author

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 as completed Oct 10, 2012
@kylebradshaw
Copy link

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
Copy link
Member Author

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)
.

@Azmisov
Copy link

Azmisov commented Oct 28, 2017

Based on @danzel's benchmarks, the optimal cutoff to start using clearLayers would be > 39% of markers getting removed (using exponential interpolation). Would need to do more testing to see if that holds for variable sample sizes, different browsers, and different computers though. But that's probably a good rough number to start with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants