Integrating Mapbox's Supercluster with react-map-gl #1377
Replies: 39 comments 3 replies
-
@winston-bosan if still relevant I manage to do it. Maybe will send a PR here |
Beta Was this translation helpful? Give feedback.
-
@jamalx31 how did you go about implementing it? |
Beta Was this translation helpful? Give feedback.
-
@jamalx31 I'd also be curious. This seems like it would be something nice to have in this library. If you're not keen on PRing, can you at least share the implementation so that someone else could go about PRing it? |
Beta Was this translation helpful? Give feedback.
-
@mlg87 @tstirrat15 I will try to raise a PR this week if not I will share a code snippet maybe one of you could |
Beta Was this translation helpful? Give feedback.
-
Sorry a bit busy and will take me longer but her is the code for the Cluster component and how to use it:
and use it like this:
|
Beta Was this translation helpful? Give feedback.
-
@jamalx31 this is awesome. Thank you! |
Beta Was this translation helpful? Give feedback.
-
Hmm... It's interesting to me that this doesn't use the underlying cluster functionality exposed by |
Beta Was this translation helpful? Give feedback.
-
Has this feature, as described by @tstirrat15 , made it into react-map-gl? |
Beta Was this translation helpful? Give feedback.
-
@JasonLunsford Did you find a solution for this? Would appreciate any help |
Beta Was this translation helpful? Give feedback.
-
For everybody getting errors -> supercluster was updated you now have to call new Supercluster instead of supercluster.
Also, it might be good for some people to know that PinGroup is a component you have to build and that it will be the replacement for the other pins when the clustering is happening. Just to make this clear as it wasn't clear to me from the beginning. |
Beta Was this translation helpful? Give feedback.
-
Hi, thank you: could you please give me an example of a PinGroup component? |
Beta Was this translation helpful? Give feedback.
-
Using @jamalx31 's code as reference:
The What should I change to fix it but having the same result? |
Beta Was this translation helpful? Give feedback.
-
Super basic PinGroup component with the number of markers in the cluster |
Beta Was this translation helpful? Give feedback.
-
Is there an official support for clusters now? This is a must-have feature for any map library IMHO. |
Beta Was this translation helpful? Give feedback.
-
Any update on this? I was kind of surprised that this isn't officially supported yet... |
Beta Was this translation helpful? Give feedback.
-
@NickCarducci I'm not sure I understand your question. can you explain a bit more what you need to do and what is the issue |
Beta Was this translation helpful? Give feedback.
-
@jamalx31 the image/pin should show when there is only one image/pin. this is caused by either one of two problems: (1) , as you see on the bottom right the lone event still has the Group/Cluster Component instead of the image.. I will look into these supercluster settings for my first time too, at first glance it looks like the following in
(2) |
Beta Was this translation helpful? Give feedback.
-
@NickCarducci the supercluster uses those values to decide when to merge leaves into a group (numbers in your case) and when to show individual leaves (photo in your case). but it should never create a group of one individual leave. I think the issue is in the 2nd point you mentioned. Im still not sure why you do |
Beta Was this translation helpful? Give feedback.
-
@jamalx31 I have two datasets inside Group, React sometimes renders multiple times onMount (though each item has their own key >:/). Maybe reactMapGL catches it (more than once). I don't think I'll have my solution soon, but my users can get by with a nice onClick on the marker to zoom into the maximum to-cluster that is allowed by aforementioned "those values". I'll reply or edit this comment with anything conclusive but as of now consider this solved in my book... thank you gj |
Beta Was this translation helpful? Give feedback.
-
What is the difference between |
Beta Was this translation helpful? Give feedback.
-
@gajus depends on your use case. The Cluster API seems to be so limited, e.g you can't build your custom markers. With supercluster you have more flexibility |
Beta Was this translation helpful? Give feedback.
-
I have switched to https://github.com/urbica/react-map-gl now because of this limitation. The Urbica variant has a very similar API, provides a cluster integration that works nicely and thus allowed me to boost the performance of my map drastically. Eventually, I will need server-side clustering, too, but for now it serves my purpose. |
Beta Was this translation helpful? Give feedback.
-
I have done the same. |
Beta Was this translation helpful? Give feedback.
-
After some more time with react, today I was able to get same functionality as @jamalx31 using his class but with
Thanks so much! p.s. I have it working without the urbica package, also please notice the only props triggering a change for this component was children; their keys, element and innerRef named ref from popper.js are still passed as props. So I put minZoom, maxZoom, radius, extent, nodeSize in state of this child |
Beta Was this translation helpful? Give feedback.
-
I tried the above solution(s), and while it "works" and renders everything correctly. It is incredibly slow and sluggish when you move the map with 3,500 points rendered as just 6 clusters. The urbica version somehow manages to do this with great performance. I think because it uses the map events directly rather than a react life-cycle to trigger viewport updates. The react-mapbox-gl library also manages to do this with good performance... I'm trying to migrate from react-mapbox-gl to react-map-gl. But this is the one problem I haven't found a solution to yet. has anyone figured out a way to implement this with custom clusters and keep a reasonable performance? in this version of react-map-gl? |
Beta Was this translation helpful? Give feedback.
-
I was just updating to the newest react functions for the thread. This is visgl version still. |
Beta Was this translation helpful? Give feedback.
-
I have also tried https://github.com/urbica/react-map-gl, but the fact that it is typeless for typescript and that it doesn't render clusters on moving the map doesn't make me wants to stick with it. I will stick to react-map-gl because I have the feeling that it is currently the best maintained mapbox dependency for react; although I think having supercluster integrated would be a super thing and improve performances :) At first I tried to display symbols through the Layer component with clusters flag enabled, it is a nice thing, but the customisation for symbol is super limited. Thus I found out that I had to use Marker to display custom images on my map. And without knowing that a supercluster dependency exist to create clusters from a set of points and bounds, I would basically have crashed my project because displaying 1000 markers make the map unusable. |
Beta Was this translation helpful? Give feedback.
-
Please any update on this yet? |
Beta Was this translation helpful? Give feedback.
-
So 5 years and this is unfinised? Just when I had ported my codebase to use this repo and realize it doesnt have clusters :( |
Beta Was this translation helpful? Give feedback.
-
It does have clusters, but I wasn't able to figure out display spider when markers are overlapping each other :/ Is there a way to do this? |
Beta Was this translation helpful? Give feedback.
-
Hello! As my title suggests, since mapbox-gl already supports supercluster internally with newly updated spiderfying and other cool jazz, I am wondering if there is a best practice or if anyone has had the experience implementing a clustering layer within react-map-gl wrapper. Or something similar to this?
Beta Was this translation helpful? Give feedback.
All reactions