mapsforge_flutter icon indicating copy to clipboard operation
mapsforge_flutter copied to clipboard

How to make zoomToBoundingBox like android osm

Open krymtn opened this issue 2 years ago • 3 comments

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

krymtn avatar Jun 15 '23 10:06 krymtn

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.

mikes222 avatar Jun 15 '23 21:06 mikes222

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

krymtn avatar Jun 16 '23 07:06 krymtn

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.

krymtn avatar Jun 20 '23 14:06 krymtn