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

cameraTargetBounds behaves weird on iOS #274

Closed stefanschaller closed 1 year ago

stefanschaller commented 1 year ago

Similar to the issue: https://github.com/maplibre/flutter-maplibre-gl/issues/273, but on iOS.

We need to restrict the visible area to a specific country, since we don't want to show the whole world.

Minimal example to reproduce the issue:

MaplibreMap(
        cameraTargetBounds: CameraTargetBounds(
          LatLngBounds(
            northeast: const LatLng(52.278241, 8.289185),
            southwest: const LatLng(48.558432, 1.016235),
          ),
        ),
        initialCameraPosition: const CameraPosition(
          target: LatLng(50.834060793873505, 4.340443996254663),
          zoom: 14,
        ),
      )

I'm using the following versions:

Flutter:3.10.5
MapLibre: ec9808e22eaca1c21c0728def02a3b3e96e298a5

  maplibre_gl:
    git:
      url: https://github.com/maplibre/flutter-maplibre-gl
      ref: main

The bounding box is working, but behaves weird and the experience doesn't feel good. I just figured out, that the web + Android implementation is using the native function: nativeSetLatLngBounds, but on iOS we do the following:

func mapView(_ mapView: MGLMapView, shouldChangeFrom _: MGLMapCamera,
                 to newCamera: MGLMapCamera) -> Bool
    {
        guard let bbox = cameraTargetBounds else { return true }

        ........

        // Test if the newCameraCenter and newVisibleCoordinates are inside bbox.
        let inside = MGLCoordinateInCoordinateBounds(newCameraCenter, bbox)
        let intersects = MGLCoordinateInCoordinateBounds(newVisibleCoordinates.ne, bbox) &&
            MGLCoordinateInCoordinateBounds(newVisibleCoordinates.sw, bbox)

        return inside && intersects
    }

How could I reproduce the "weird" feeling?

Use my minimal example code above and zoom in to the edge of the bounding box. Try to zoom out in the near of the bounding box. it should be clear after checking that case by yourself. You could also compare the behaviors with the web implementation, since it behaves correct on that platform.

m0nac0 commented 1 year ago

I tried to investigate whether this feature has recently been added to the native iOS library and noticed you guys just got this merged, very nice! 👍 😄

stefanschaller commented 1 year ago

@m0nac0 Yeah, I will update the native iOS package ASAP. We just need a new pod version

m0nac0 commented 1 year ago

We just need a new pod version

I think we have to wait for a new native release first, right?

But I noticed there is no pod yet for native iOS v.5.13.0. So I opened a PR for that https://github.com/m0nac0/flutter-maplibre-podspecs/pull/2, but I think we'd first want to pin the dependency in the example app https://github.com/maplibre/flutter-maplibre-gl/pull/276

JulianBissekkou commented 1 year ago

Fixed in https://github.com/maplibre/flutter-maplibre-gl/pull/277