Hinaba Zala
Hinaba Zala

Reputation: 51

Why is mapbox map so slow when you add 3000 or more amount of markers?

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

Answers (2)

interpolack
interpolack

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

Steve Bennett
Steve Bennett

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

Related Questions