mapbox-maps-flutter
mapbox-maps-flutter copied to clipboard
Wrong current camera bounds
I always got the wrong camera bounds
(await mapController?.getBounds())?.bounds
Do you have any advice here? @zugaldia @mourner @sbma44 @kkaefer
@dev-m-hussein to get the current camera bounds i did something like that.
This is my MapWidget
MapWidget(
resourceOptions: ResourceOptions(accessToken: mapboxPublicAccessToken),
onMapCreated: _onMapCreated,
onCameraChangeListener: _onCameraChangeListener,
);
And this is the _onCameraChangeListener function
_onMapCreated(MapboxMap mapboxMap) async {
this.mapboxMap = mapboxMap;
}
void _onCameraChangeListener(CameraChangedEventData cameraChangedEventData) {
final camera = await mapboxMap?.getCameraState();
if (camera == null) return;
final coordinateBounds = await mapboxMap?.coordinateBoundsForCamera(
CameraOptions(
center: camera.center, zoom: camera.zoom, pitch: camera.pitch));
// coordinateBounds is good coordinate
}
thanks
Thanks @nathan-poncet for the work around.
Is this bug likely to get worked on in the near future? It's been open for a year and is still in version 2.0.
This isn't a bug, is it?
You can optionally set bounds for the map: https://github.com/mapbox/mapbox-maps-flutter/blob/e8a2fe289a36375d743700a9cb13c5dac1b514e0/lib/src/mapbox_map.dart#L302-L307 The same as you can set a maximum and minimum zoom which is allowed, you can limit your map to a certain area rather than the whole world.
The getBounds
returns those bounds, which are by default the whole world. That's what we see in the image of the original post: https://github.com/mapbox/mapbox-maps-flutter/issues/222#issue-1848485505 . The getter does not return the bounds of the camera state, i.e. what the user currently sees (See above how to get the bounds of the camera state).