maplibre / flutter-maplibre-gl

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)
https://pub.dev/packages/maplibre_gl
Other
226 stars 125 forks source link

CameraUpdate newLatLngBounds with bottom not working in iOS #299

Open thanhnha241199 opened 1 year ago

thanhnha241199 commented 1 year ago

This is my code

Screenshot 2023-09-12 at 00 12 30

iOS: Simulator Screenshot - iPhone 14 Plus - 2023-09-12 at 00 10 07

android: Screenshot_1694452293

razorness commented 11 months ago

Also facing this issue on iOS 15.8 (iPhone 6s).

m0nac0 commented 11 months ago

Can you please try explicitly providing a duration to the animateCamera call?

giboin commented 10 months ago

I experience the same issue, the centering is not the same on iOS and android when using CameraUpdate.newLatLngBounds.

On iOS, you can use MapLibreMapController.updateContentInsets before moving the camera to get the same centering than CameraUpdate.newLatLngBounds with insets on android, but using MapLibreMapController.updateContentInsets on android gives yet another centering.

So from what I see, only this snippet has a coherent behavior :

  /// Center the map on the given [viewPort] taking into account
  /// the given [insets].
  Future<void> centerOnViewPort(
    MaplibreMapController controller, {
    required LatLngBounds viewPort,
    EdgeInsets? insets,
  }) async {
    if (defaultTargetPlatform == TargetPlatform.iOS) {
      await controller.updateContentInsets(insets ?? EdgeInsets.zero, true);
      await controller.animateCamera(CameraUpdate.newLatLngBounds(viewPort));
    } else {
      await controller.animateCamera(
        CameraUpdate.newLatLngBounds(
          viewPort,
          bottom: insets?.bottom ?? 0,
          top: insets?.top ?? 0,
          left: insets?.left ?? 0,
          right: insets?.right ?? 0,
        ),
      );
    }
  }

FYI, using CameraUpdate.newCameraPosition and MapLibreMapController.updateContentInsets works well on both android and iOS

giboin commented 10 months ago

Can you please try explicitly providing a duration to the animateCamera call?

providing a duration doesn't change change the behavior on my side

(but it was quite helpful to debug so thanks for the idea 😅)