-
Notifications
You must be signed in to change notification settings - Fork 220
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
Adding ref to access underlying cluster instance. #152
Conversation
@venits Can you please consider looking into this again. You can add the functionality in the next release. You don't necessarily have to merge this approach. Exposing the cluster engine might be helpful in some instances like keeping the track of all the children of the cluster. |
@nikhil2kumar yep I will add this functionality by the end of this week :) |
OMG, thank you for this! I was pulling my hair out for the past few hours, pulling multiple coworkers into why I couldn't get a proper ref for my MapView to change the region in my FunctionComponent. When i changed back over to the default I applied this PR patch manually and had to also export the map ref in the
I am getting a good map ref back.. For reference, here's how i've implemented it in a FunctionComponent:
With some other code and markers it allows me to do interactions like this: |
For reference, here is the patch with my changes: File:
|
This looks great. :) |
Good news 🎉 In version This is example how to use it: import React, { useRef } from "react";
import MapView from "react-native-map-clustering";
const App = () => {
const superCluster = useRef();
return <MapView superClusterRef={superCluster}>
{/* markers */}
</MapView>;
};
export default App; If you want to get all markers inside cluster you can call a function like this: const markers = superCluster.current.getLeaves(cluster.id, Infinity); Thank you for contributing 💖 |
Sometimes we might need to access the cluster engine for performing certain operations or to get all the coordinates within the cluster. This is where this method would come handy.