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

Feature/annotation cluster #70

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nikischin
Copy link
Contributor

@nikischin nikischin commented Nov 6, 2024

Hi @Nicolapps,

I finally managed to have a working implementation for the clustering. The solution is not perfect, but it I tried many things and this ended to be the most reliant and easy to maintain solution. Technically what it does is return an empty cluster annotation and implementing a new Annotation with the cluster coordinates. I implemented a hook to get the coordinates so it should be easy to implement it by the user. That way we can reuse our Annotation component and do not have to do a complete re-implementation as the annotationForCluster function expects to be returned the MapKit Annotation and not a DOM element and we do not need to do a complete re-implementation of our Annotation and Marker component where we would need to return the component instead of attaching it to the map while also handling the createPortal stuff for the React part.

Let me know what you think about it, I would be happy about a review and can also do some cleanup of the code and example if this is the variant we are agreeing on!

fixes #61

Edit: There is still a major issue in unmounting the cluster annotations unfortunately, not sure if it is possible to fix with the current implementation or if I need to go for another variant. I cannot mark the PR as draft.

@nikischin nikischin marked this pull request as draft December 8, 2024 12:04
@Nicolapps
Copy link
Owner

Hi Tim! Thanks for your PR. If it works for you, I’d prefer to fully review the PR once there are no remaining issues.

Some things I thought about by quickly glancing at your PR:

  • Why is AnnotationCluster supporting a cluster identifier attribute? Is there an advantage in providing this API? We could generate a unique identifier using React’s useId hook,
  • I’m not sure if it is appropriate to pass a MapKit JS type (mapkit.Annotation) in the parameter of annotationForCluster. Maybe it could make sense instead to use the react-mapkit AnnotationProps type instead.
  • Maybe it could be helpful to support a data-like attribute (like the one supported by MapKit JS) if we pass the annotation props in annotationForCluster. But I’m not sure if we have a nice type-safe way to do this (maybe we could just have a string identifier prop and let the user manage the rest if needed).
  • Before we merge this PR, we would need to document AnnotationClusterProps, and fully deprecate annotationForCluster (i.e. marking the prop as @deprecated in the TypeScript file, and possibly emitting a console.warn in the browser console).

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

Successfully merging this pull request may close these issues.

Feature Request: Implement Annotations For Clusters
2 participants