SINTEF-9012 / PruneCluster

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

Have a look at SuperCluster by MapBox #120

Open simison opened 8 years ago

simison commented 8 years ago

https://www.mapbox.com/blog/supercluster/

Thoughts?

fungiboletus commented 8 years ago

That's neat :smiley:

Each clustering step for a specific zoom level requires indexing points from the earlier step. But after the clustering process, having an index for each zoom allows us to instantly query clusters for any map view.

This will probably be the main difference with PruneCluster, as PruneCluster builds its clusters on the fly directly for the final zoom level. So if zoomed on a huge dynamic dataset, PruneCluster might be slightly faster but Supercluster seems so fast that's maybe not a big difference.

I look foward to see how it works with dynamic datasets, to see if the clusters are stable. And maybe also if the memory usage is ok.

Working on PruneCluster was useful and interesting, but two years later I am happy to see new better solutions :-)

Congrats to @mourner, it's impressive.

JatGitHub commented 8 years ago

Must say that you documentation is way better! I love your work!

Op 1-4-2016 om 20:36 schreef Antoine Pultier:

That's neat :smiley:

Each clustering step for a specific zoom level requires indexing
points from the earlier step. But after the clustering process,
having an index for each zoom allows us to instantly query
clusters for any map view.

This will probably be the main difference with PruneCluster, as PruneCluster builds its clusters on the fly directly for the final zoom level. So if zoomed on a huge dynamic dataset, PruneCluster might be slightly faster but Supercluster seems so fast that's maybe not a big difference.

I look foward to see how it works with dynamic datasets, to see if the clusters are stable. And maybe also if the memory usage is ok.

Working on PruneCluster was useful and interesting, but two years later I am happy to see new better solutions :-)

Congrats to @mourner https://github.com/mourner, it's impressive.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/SINTEF-9012/PruneCluster/issues/120#issuecomment-204507409

myflowpl commented 7 years ago

The category and filter features of PruneCluster just blows my mind! It was something i was planning to build on top of Leaflet.markerclustering, but i'm glad i found this repo.

Categories in SuperCluster are not implemntet (yet) so it's main reason i'm not going to use it. But it has out of the box support of NodeJs:

var index = supercluster({
    radius: 40,
    maxZoom: 16
});
index.load(points);
index.getClusters([-180, -85, 180, 85], 2);

it's basically the same code for node and browsers

@yellowiscool is it possible to use PruneCluster in NodeJs?

I successfully manage to run Leaflet.markerclustering on the server for last year in my production app, and i'm going to migrate to PruneCluster. If you can give me some tips it will definitely seed up the process and i'm willing to do PR with my work in case anyone else needs server side clustering.

myflowpl commented 7 years ago

@yellowiscool any hints? I'm just going to try to run it on nodejs so any guide will be helpful

fungiboletus commented 7 years ago

Hei hei,

I think PruneCluster.ts should already work in NodeJS. LeafletAdapter.ts probably needs some modifications. I see a few window.setTimeout that you may need to replace with NodeJS's setTimeout and setImmediate. I would be interesting to see what you can do server side.

myflowpl commented 7 years ago

yes, i just got it working on the server

right now I have usage like this:

let cluster = new PruneCluster.PruneCluster();
let spots = []; // lots of spots
spots.forEach((spot)=>{
    cluster.RegisterMarker(new PruneCluster.Marker(spot.lat, spot.lon))
})
let bounds = {};// define the bounds you need the clusters for
let clusters = cluster.ProcessView(bounds); // here we have nice array of the clusters

I just added few lines to PruneCluster.ts, you have to define your Project and UnProject methods, so i just used CRS form leaflet

    // These methods should be defined by the user
    // public Project: (lat: number, lng: number) => Point;
    // public UnProject: (x: number, y: number) => Position;

    private crs = L.CRS.EPSG3857;
    Project (lat, lng) { // (LatLng[, Number]) -> Point
        return this.crs.latLngToPoint(L.latLng([lat, lng]), 0);
    }
    UnProject (x,y) { // (Point[, Number]) -> LatLng
        return this.crs.pointToLatLng(L.point(x,y), 0);
    }

right now i'm trying to add the zoom parameter to the cluster.ProcessView(bounds)

I just try to avoid using LeafletAdapter.ts, not sure if it will be possible, but probably will know in few hours :)

PS you don't publish d.ts files to npm, later we should fix it so everyone can just npm install prunecluster and have nice ts experience, but i hope to do some PR with my work so i'll fix it then

fungiboletus commented 7 years ago

Avoiding LeafletAdapter should be possible. Feel free to create a PR to publish the d.ts files. We can also continue the conversation in a new issue to stop spamming the others :)