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

How to make zoomToBoundingBox like android osm #92

Open
krymtn opened this issue Jun 15, 2023 · 3 comments
Open

How to make zoomToBoundingBox like android osm #92

krymtn opened this issue Jun 15, 2023 · 3 comments

Comments

@krymtn
Copy link

krymtn commented Jun 15, 2023

I want to zoom the map with existing markers (minLat, minLng, maxLat, maxLng). Is there any way to initialize MapViewPosition with bounding paramaters.

@mikes222
Copy link
Owner

Interesting problem. The position is easy. It is the center of the bounding box.

With the help of PixelProjection.latLonToPixel() you could calculate the absolute pixels for the left-upper and right-bottom bounding box. So you know how many pixels must be visible in the view.

ViewModel.mapDimension gives you the current width/height of the view or determine it by yourself e.g. with LayoutBuilder.

scaleFactor can be calculated then by dividing the necessary mappixels by the available screenpixels.

Since the scaleFactor is a function of 2^zoomLevel (see ScaleFactor.dart) with a little play-around you should be able to calculate the correct zoomLevel.

I would be happy if you create a PullRequest with this new feature so that it is availabe to others too.

@krymtn
Copy link
Author

krymtn commented Jun 16, 2023

Thank you Mike, I will be busy next week on this calculation in my local. I will inform you.

@krymtn
Copy link
Author

krymtn commented Jun 20, 2023

PixelProjection constructor needs PixelProjection(int zoomLevel, this.tileSize) what's the correct init values. BTW, I found left-upper and right bottom coordinates but couldn't calculate the mappixels with Mappoint values.

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

2 participants