Reputation: 51
When I add 3000 or more markers to Mapbox map, sometimes it stops working, or sometimes it is very slow. What is the solution?
Upvotes: 2
Views: 3572
Reputation: 914
If you absolutely need to use markers and make dynamic updates to them, make sure that you properly dispose of old markers whenever they are updated. Keep track of markers that have been added and then remove them with .remove()
.
There is no built-in garbage collection for markers so they will hog memory even when they're not appearing on the map. Disposing of the old markers will make significant performance improvements that make it possible to work with more markers.
Upvotes: 0
Reputation: 126527
The right solution is to use a symbol
layer instead. https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#symbol
Upvotes: 1