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: Expose MapContext #13

Open
derekr opened this issue Feb 2, 2023 · 8 comments
Open

Feature: Expose MapContext #13

derekr opened this issue Feb 2, 2023 · 8 comments

Comments

@derekr
Copy link
Contributor

derekr commented Feb 2, 2023

Hey! Digging the project so far! The API and code organization are great. Was wondering if exporting MapContext or a useMapContext hook would be inline with the API you want to support. I'm trying to use refs per the storybook examples, but find it a little clunky and unreliable for certain use cases. Particularly I want to author an Annotation component for custom images instead of using Marker and noticed Marker is consuming the map context instead of refs which feels like a nicer API for extending or building on top of mapkit-react.

@Nicolapps
Copy link
Owner

Thank you for your suggestion! For the Annotation component, adding it as part of the mapkit-react library is definitely the way to go (thank you very much for your PR!). Do you have other use cases in mind where an API change would be helpful?

@derekr
Copy link
Contributor Author

derekr commented Feb 3, 2023

The other thing I can think of is maybe custom map controls. Positioning isn't dependent coordinates, but you want access to the map instance to call methods.

function AnnotationsCount() {
  const map = useMap()
  return <div>{ map.annotations.length }</div>
}

<Map>
  <AnnotationsCount />
</Map>

@nikischin
Copy link
Contributor

This alternative implementation here could give an idea how a useMap hook could look like: https://github.com/chrisdrackett/react-mapkit/blob/main/src/useMap.tsx

Would be cool to implement something similar in this library!

@nikischin
Copy link
Contributor

The other thing I can think of is maybe custom map controls. Positioning isn't dependent coordinates, but you want access to the map instance to call methods.

function AnnotationsCount() {
  const map = useMap()
  return <div>{ map.annotations.length }</div>
}

<Map>
  <AnnotationsCount />
</Map>

Hi @derekr,

I was thinking about how an implementation of this could look like and how to make it beneficial recently.

The problem with your example I came up with, is that it could be only used within the component as you already pointed out in your example, as there could be many components within a React application. So usually - looking at the storybook examples - it is supposed to render additional divs outside the component and not inside I suppose.

Also I was thinking about additional controls over the map which might be rendered outside the however, I don't really see a good way of how to give the context the information which component am I looking for.

Could you provide additional information about the expected usages and how to get benefits out of this implementation. I agree it could be very nice to have such a hook, however, I cannot yet think of a suitable implementation.

@remib18
Copy link

remib18 commented Jul 23, 2024

Hi everyone,

I'm wondering if anyone is currently working on this issue. I really need this feature and would be happy to help out if needed. Please let me know how I can help!

@nikischin
Copy link
Contributor

Hey @remib18 I don't think anyone is currently working on this feature, so you are very welcome to participate!

The last thing I personally was working on is the annotation clustering. I made some progress there already but got stuck and haven't yet have time to further investigate. Should be not anything related to this one.

@Nicolapps
Copy link
Owner

Thank you @remib18 for your interest in the project! What is the use case you would need access to the map context for?

@remib18
Copy link

remib18 commented Jul 30, 2024

Thank you @remib18 for your interest in the project! What is the use case you would need access to the map context for?

Hey!

I'm updating an old codebase to React. Since I have already implemented geocoding and reverse geocoding using the native MapKit API, it would be practical to have access to the MapKit API within the map context. Moreover, I don't see any particular reason to hide the map context. However, I might be wrong, or there could be other ways to access it that I'm not aware of.

Thanks!

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

No branches or pull requests

4 participants