4

I'm working on a Ruby on Rails application that is showing road signs on the map(leaflet). So, user can browse map and road signs, great. But, if there are a lot of signs and user wants to zoom out, there are obvious problems for my app.

  • First problem is to prevent loading a lot of elements (signs) at the same time.
  • And the second problem is to have clear view of elements on the map.

This:

enter image description here

Insted of this:

enter image description here

Solution by my research is to cluster elements by locations as user is zoom-ing in and out. More precisely, using k-means algorithm.

My questions are :

  1. Are there some done solutions for this?
  2. If done solutions not exists, how to use k-means algorithm with zoom level?

I'm using Postgres database with Postgis extension and Ruby on Rails build API.

Mr.Code
  • 313
  • 2
  • 8
  • 1
    There are superb answers here: https://gis.stackexchange.com/questions/11567/spatial-clustering-with-postgis – Alexander Dec 21 '18 at 11:34
  • @alexander That are clustering algorithms but not anwsering my question – Mr.Code Dec 22 '18 at 02:42
  • It is more usual to do this server side, for example, Leaflet's marker cluster control. This way you omly have one server round trip. – John Powell Dec 26 '18 at 18:27
  • 1
    @JohnPowell app is divided on server side API (Rails) and Front end (React), so if I want to use marker cluster control I need to send all of data at once from API to Front end to cluster control to work. Am I wrong? – Mr.Code Dec 27 '18 at 11:42
  • That is correct. So it will be slower the first time to load, but much, much quicker on zoom. – John Powell Dec 27 '18 at 21:48
  • @JohnPowell but the goal is to optimize loading elements on a page, not sure if that is the best approach I'm looking for – Mr.Code Dec 28 '18 at 00:15
  • @bKapusta Hey ! I'm facing pretty much the same situation as you did not so long ago. Did you find something interesting you might want to share please ? =) Any hint would be much appreciated ! ;-) – Pagehey May 23 '19 at 08:38
  • @Pagehey Well, depends. You can do server-side clustering but it's a bit complicated and a bit slow. I found another solution for this to filter markers and then cluster them trough front-side. – Mr.Code Jun 03 '19 at 08:20

0 Answers0