SINTEF-9012 / PruneCluster

Fast and realtime marker clustering for Leaflet
MIT License
552 stars 131 forks source link

Marker Clustering ServerSide #201

Open Luigidefra opened 2 years ago

Luigidefra commented 2 years ago

Hi, i have a little problem... I have 400k points, i used PruneCluster to create Cluster and it very fast, the problem is that i have to send a 400k points json from server to client before to create Cluster with your application... 400k points are equivalent to 26mb and it too big to send to client...

I would like create Cluster on my server and then send only Cluster with your coordinates and counter... is it possible refactoring code in PHP to run server side?

are there any other solutions?

fungiboletus commented 2 years ago

Hello,

is it possible refactoring code in PHP to run server side?

Yes you can probably do. However if your data is never move or change, you can consider using another algorithm server side, based on https://github.com/mourner/flatbush or similar. PruneCluster is a good algorithm when you don't have that much data and it's dynamic/moving.

mngyng commented 2 years ago

What I did was copy the required functions from leaflet.js and include those onto the server. (Not all of them are needed and some of them are front-end specific, making it incompatible with Node.js.)

Following that I created three functions on the server side, for POST requests on "generating clusters", "collecting and doing statistics on members inside of markersArea", and finally "transfering all markers of a certain cluster from backend to frontend if spiderfied (expanded from a cluster into markers)".

Then on the frontend I modified the PruneCluster.js to be included on the client side, making it capable of interacting with the services above.

I ended up with a MESSY CODE that processed a GeoJSON dataset of 100k points/63MB.

Nevertheless, I'll have to say, IT IS SATISFYING to see it actually works.