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

Single reusable map instance #245

Closed
AAverin opened this issue Mar 15, 2020 · 5 comments
Closed

Single reusable map instance #245

AAverin opened this issue Mar 15, 2020 · 5 comments
Labels
enhancement New feature or request stale

Comments

@AAverin
Copy link
Contributor

AAverin commented Mar 15, 2020

Having many places where map can be displayed, it's very expensive to create new instance every time.
Is there some way in library of Flutter in general to somehow have single map instance that would be lazy initialized and later reused everywhere, just calling onMapCreated() callback when it's displayed?

@AAverin
Copy link
Contributor Author

AAverin commented Aug 14, 2020

Would be great to get any update on this issue. How is this solved in Android and iOS Mapbox SDK? Can we reuse any approach?

@m0nac0
Copy link
Collaborator

m0nac0 commented Aug 14, 2020

@AAverin Two potential hurdles I can think of right now: some users may want to instantiate more than one map at the same time, so we'd have to always keep one map instance around and be able to instantiate more. But also other users expect the memory to be released when the map isn't shown anymore, so making the map reusable would have to be configurable somehow.
Have you tried wrapping the MapboxMap widget in awidget with AutomaticKeepAliveClientMixin or something similar in flutter to make sure the widget doesn't get disposed?

@m0nac0 m0nac0 added the enhancement New feature or request label Aug 14, 2020
@AAverin
Copy link
Contributor Author

AAverin commented Aug 14, 2020

I am now struggling with this exactly. AutomaticKeepAliveClientMixin is a bit confusing to understand.
I have a tab with the map, and I am now keeping this whole tab alive. Problem is, this tab is supposed to still update once in a while, so I do need to somehow reset this keepAlive.
I was also thinking to wrap the while MapboxMap into AutomaticKeepAliveClientMixin, but then I have to pass all the callbacks through the state, this would mean there will be no way to change after it was created the first time.
The whole point here is to have a map that can be modified without re-creating it all the time

@AAverin
Copy link
Contributor Author

AAverin commented Aug 14, 2020

This, indeed, needs to be configurable somehow, because different users will have different needs.
For my app specifically, I have a common list of items, and click on every item opens another screen with 3 tabs, one of which is a map. Potentially, I can have hundreds of maps in the app and initialising it every time user opens the tab is very expensive, especially taking into account that user might switch between tabs on the inner screen many times.
So to make it work, I really need some way to keep the same map alive and reuse it everywhere. But, at the same time, I need to clean the state because I have markers on the map or I might need to change the map style.

@stale
Copy link

stale bot commented Jan 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 14, 2022
@AAverin AAverin closed this as completed Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

2 participants