Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

markerclusterer - Best practices for handling thousands of markers with Leaflet

I'm doing some tests with an HTML map in conjunction with Leaflet. Server side I have a Ruby Sinatra app serving json markers fetched by a MySQL table. What are the best practices working with 2k-5k and potentially more markers?

  • Load all the markers in the first place and then delegate everything to Leaflet.markercluster.
  • Load the markers every time the map viewport change, sending southWest & northEast points to the server, elaborate the clipping server side and then sync the marker buffer client side with the server-fetched entries (what I'm doing right now).
  • A mix of the two above approaches.

Thanks, Luca

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Few months has passed since I originally posted the question and I made it through!

As @Brett DeWoody correctly noted the right approach is to be strictly related to the number od DOM elements on the screen (I'm referring mainly to markers). The more the merrier if you device is faster (CPU especially). Since the app I was developing has both desktop and tablet as target devices, CPU was a relevant factor just like the marker-density of different geo-areas.

I decided to separate DBase querying/fetching and map representation/displaying. Basically the user adjusts controls/inputs to filter the whole dataset, afterwards records are fetched and Leaflet.markercluster does the job of representation. When a filter is modified the cycle starts over. User can choose the map zoom level of clusterization depending on their CPU power.

In my particular scenario the above mentioned represented the best approach (verified by console.time). I found that viewport optimisation was good for lower marker-density areas (a pity).

Hope it may be helpful.

Cheers, Luca


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...