mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

Wrong current camera bounds

Open dev-m-hussein opened this issue 1 year ago • 4 comments

I always got the wrong camera bounds (await mapController?.getBounds())?.bounds

Screenshot 2023-08-13 at 11 28 43 AM

Do you have any advice here? @zugaldia @mourner @sbma44 @kkaefer

dev-m-hussein avatar Aug 13 '23 08:08 dev-m-hussein

@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
  }

nathan-poncet avatar Aug 18 '23 13:08 nathan-poncet

thanks

fodedoumbouya avatar Mar 19 '24 08:03 fodedoumbouya

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.

noforeignland avatar Aug 18 '24 11:08 noforeignland

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).

Xennis avatar Aug 18 '24 19:08 Xennis