This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Integrating Mapbox's Supercluster with react-map-gl #507
Comments
@winston-bosan if still relevant I manage to do it. Maybe will send a PR here |
@jamalx31 how did you go about implementing it? |
@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? |
@mlg87 @tstirrat15 I will try to raise a PR this week if not I will share a code snippet maybe one of you could |
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:
|
@jamalx31 this is awesome. Thank you! |
Hmm... It's interesting to me that this doesn't use the underlying cluster functionality exposed by |
Has this feature, as described by @tstirrat15 , made it into react-map-gl? |
@JasonLunsford Did you find a solution for this? Would appreciate any help |
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. |
Hi, thank you: could you please give me an example of a PinGroup component? |
Using @jamalx31 's code as reference:
The What should I change to fix it but having the same result? |
Super basic PinGroup component with the number of markers in the cluster |
Is there an official support for clusters now? This is a must-have feature for any map library IMHO. |
Any update on this? I was kind of surprised that this isn't officially supported yet... |
Should we create a pull request and add the cluster component of @jamalx31 ? 🤔 |
Bump. I am considering going to raw mapboxgl.js now because of the lack of cluster support. We have a lot of data, spread across the whole world. Not being able to cluster it efficiently, just doesn't make sense in our use-case. |
@Pessimistress , https://uber.github.io/react-map-gl/#/Examples/clusters -> in this example, it clusters Points layer. How about clustering custom markers? It is possible to execute it using this package? |
@Pessimistress @jamalx31 This isn't working code, just what I spent several hours on. A potentially-workable concept to help react-map-gl provide "cluster" support in your source, unless there is no way to access the marker with DOM... then forget this @howdyhyber If by custom markers you mean image markers, I have custom markers as well. Since clustering only works on layers in latter example (and the former example in this thread uses mapbox-js-gl) I tried to use refs & also tried document.getElementByID, to see if markers overlap, then hide all overlaps or re-render when viewport changes from last Here is inside componentDidUpdate
Please let me know if I'm wrong and it is possible to use refs or getElementById on markers, but I just read a similar question of Leaflet which say it is NOT possible for them |
@NickCarducci sorry I didn't work on this project for over 2 years. I'm surprised this issue is still open. |
@jamalx31 happy to help apply it if you give hint to my example. quickly to start
|
@NickCarducci, everyone. here's a working example of the supercluster with custom markers for leaves.
https://github.com/jamalx31/mapbox-supercluster-example |
@jamalx31 in Group component's props I had an extra If so, can I show image/pin then (count === 1), by editing Cluster component? wavepoint.la |
@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 |
@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) |
@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 |
@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 |
What is the difference between |
@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 |
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. |
I have done the same. |
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 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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?
The text was updated successfully, but these errors were encountered: