Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

See features in cluster #3318

Closed
popovae opened this issue Oct 7, 2016 · 26 comments
Closed

See features in cluster #3318

popovae opened this issue Oct 7, 2016 · 26 comments

Comments

@popovae
Copy link

popovae commented Oct 7, 2016

Hello!
I know this question was asked several times already, but there is still no workaround!
Using clustering is the only solution in case you have a big amount of pins on map. Unfortunately Supercluster allows you only to "aggregate" points in clusters, but there is no way to return the features inside the cluster back. This makes current clustering algorithm useless for the end user. Simple example: ten points with the same location are clustered...or the ten points with slightly different locations are clustered - how can I get the list of points inside the cluster on click?
I do understand that potentially it can be millions of points inside the cluster...so I can suggest a few solutions:

  1. Have a look at Leaflet Clustering (screenshot ) - it calculates the approximate bounds of the cluster - it can be the solution to do the same, at least developers will be able to query the DB to return the original points...

  2. Or you can store the ID's of the original points in each cluster and even limit the number to 100 for example - in most cases it will be more then enough - devs can at least code something like "if num_of_points_in_cluster > 100, then Zoom In the map else return IDs"

Really hope you will be able to find ANY solution, though the current clustering algorithm is useless and potentially buggy...

@jfirebaugh
Copy link
Contributor

the approximate bounds of the cluster

@mourner Could we combo supercluster + concaveman + polylabel here? Supercluster to figure out the clusters, concaveman to generate a polygon geometry for each one, polylabel to reduce the resulting polygon to a single point for rendering.

@mourner
Copy link
Member

mourner commented Oct 10, 2016

@jfirebaugh I think it's an overkill, and won't really solve the original issue. This needs a proper solution on the supercluster side, but it's not trivial — will think about it.

@popovae
Copy link
Author

popovae commented Oct 10, 2016

@mourner Maybe I'm totally wrong, but if you will store the "starting points" for each cluster on z18 and pass them all the way to z0, then you will be able to make recalculation (on z18 level) on any zoom level you want and return all the containing points... This will (just) reduce the amount of points you need to "store" for each cluster in case there millions and will allow to return all if needed with simple calculations... Sorry if I'm wrong or solution is not the best...just an idea;)

jurm9s3

@mourner
Copy link
Member

mourner commented Dec 15, 2016

Addressing this with a clever technique on the Supercluster side in mapbox/supercluster#31. Now we just need to decide how to properly expose it in Mapbox GL JS API.

@mourner
Copy link
Member

mourner commented Jan 18, 2017

Second part of the puzzle (paginated leaves retrieval) is here mapbox/supercluster#32

@Brodingo
Copy link

Brodingo commented Jan 19, 2017

Could this enhancement lead to additional options for filtering on cluster layers besides point_count? i.e. filter by properties of features contained in the cluster

@mourner
Copy link
Member

mourner commented Jan 20, 2017

@Brodingo no, this is a different feature.

@bobmoff
Copy link

bobmoff commented Feb 20, 2017

@mourner Whats the status?

This feature is a make it or brake it for the app we are working on and if it pops up in a version not to far away in the future i will definitely switch back to mapbox.

@demiurg
Copy link

demiurg commented Sep 22, 2017

Any updates?

@johnlaur
Copy link
Contributor

I can't speak for Mapbox but I can tell you that it is possible to start experimenting with this feature now with production releases of mapbox-gl-js and supercluster libraries.

If you create a clustered layer in mapbox and also create your own instance of supercluster with the same parameters, the two structures can be correlated with the cluster_id property which is now present on each cluster. You can specify custom data aggregation functions or use the get_leaves method on your own supercluster instance.

If you want to style clusters with custom aggregation functions, I would imagine that it's relatively easy to build a supercluster layer and then add the result it as a geojson layer to your map dynamcially in order to make the cluster attributes available for style rules. It may be necessary to transform the supercluster object into something that looks more like GeoJSON to get this to work though.

Until arbex is added and a style syntax is specified there really can't be any more integration work done than this.

@mourner
Copy link
Member

mourner commented Sep 22, 2017

Until arbex is added and a style syntax is specified there really can't be any more integration work done than this.

Actually I think we can add getLeaves and getChildren to GL JS independently of Arbex. The latter is only needed for cluster property aggregation. I'll look into the former after wrapping up heatmaps.

@demiurg
Copy link

demiurg commented Sep 22, 2017

Thank you very much for this quick and thorough reply on a Friday evening :) I will look into the supercluster feature.

@ryanbaumann
Copy link
Contributor

ryanbaumann commented Sep 22, 2017

@demiurg

Using the latest version of Supercluster with GL JS, below are two solutions you could use today, prior to updates making it into the latest GL JS APIs:

  1. Get features under a cluster
  2. Aggregate clusters by property value

@johnlaur
Copy link
Contributor

@mourner Thanks! These two functions are mostly what I personally needed anyway. But don't forget as sure as you publish it, we will undoubtedly want to have custom property aggregation on heatmap layers as well! 😂

@demiurg
Copy link

demiurg commented Sep 22, 2017

Was able to get this to work thanks to examples!

@Brodingo
Copy link

Amazing examples, thank you @ryanbaumann

@shkfnly
Copy link

shkfnly commented Jan 6, 2018

@ryanbaumann i'm getting a problem with your implementation where the cluster_id being returned isn't found in the super cluster. any thoughts?

edit: The supercluster version is 3.0.2, but 2.3.0 in your example

@johnlaur
Copy link
Contributor

johnlaur commented Jan 6, 2018

@shkfnly make sure the version of supercluster you are using corresponds to the version built as a dependency of the version of mapbox-gl-js you are using. I believe the method by which cluster_id were assigned was changed at some point to be unique (vs unique within each zoom level) and the examples may no longer work.

@jasonbell
Copy link

Is anyone using a successful workaround for issues of clustering and click events?
Is there any indication of updating the bundled Supercluster library inside Mapbox GL JS?

We have an almost working click to expand cluster action, but it fails in certain conditions. Cluster click uses getClusterExpansionZoom and works a few times. Then returns error noted in mapbox/supercluster#42.

Looks like Supercluster 3.0.2 would fix it, but that introduces other issues as noted above.

@mourner
Copy link
Member

mourner commented Jan 26, 2018

@jasonbell I think we should just update supercluster to 3.0.2 in GL JS — this shouldn't introduce any issues other than having to match version if you're using supercluster "outside" in the app logic.

@jasonbell
Copy link

@mourner That sounds great. I was going to give that go this weekend to get past this roadblock. Is a new issue needed to track the dependency update?

@johnlaur
Copy link
Contributor

johnlaur commented Jan 29, 2018

I just want to say that it is a real shame that @mourner and others have done all of this great and powerful work on supercluster and it remains better to work with clusters completely outside of mapbox-gl-js. I understand the desire to have feature parity across language libraries, but it is really holding back a powerful tool. We are doing a lot of neat stats visualizations using custom property aggregations, filtering, and introspection that supercluster eneables. Luckily in our case since the library is so efficient, we are able to do this in on the main thread in a duplicate dataset without too much trouble, but it would be great to somehow have an api for lower level access to the internal cluster. For many of us it doesn't mean a hill of beans to whether or not these features are ever added to the Unity SDK or whatever.

@ghost
Copy link

ghost commented Feb 27, 2018

@mourner Another user rallying for a Supercluster update. I just ran into a use case yesterday where I need the ability to get the features in a cluster.

I am playing with mapboxgl-spiderifier but it is using a fork of mapbox-gl-js, which I would rather not use. The reason it was forked I believe is because it needed this exact feature. That is, to get features in a cluster (e.g. getChildren).

My point data is very dense so I needed a "spidering" technique to help out. I'd rather not maintain two copies of Supercluster in my project.

@lamuertepeluda
Copy link

Any chance to get an e.t.a. for this feature? It's a while since it has been opened and there are a lot of similar ones opened. Having a separate thread running a copy of supercluster on the same dataset is really bad for both memory and performances.
I read a lot of issues where it's said that the problem is the lack of style spec support for this feature, but I think that map and reduce functions could be just passed as GeoJSON source parameters, while the cluster custom properties could be returned in the cluster features as for cluster_id and point_count.
This would at least allow for displaying a stats popup when hovering on the cluster, or selecting a cluster feature...

@thuanmb
Copy link

thuanmb commented Mar 18, 2018

For those who are ReactJS lover. This is a solution to show the points at same location using spiderifier.
https://github.com/thuanmb/react-mapbox-gl-cluster

This library detect if you're clicking on a cluster that have same points location or not. If yes, it will show a spiderifier. If no it will do zooming.

@mourner
Copy link
Member

mourner commented Jun 18, 2018

Hey friends, can you check out the PR for this at #6829? Would love some feedback on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests