flutter-mapbox-gl / maps

A Mapbox GL flutter package for creating custom maps
Other
1.04k stars 503 forks source link

Ios zoom and camera position not working well #1327

Closed Andre-Coelhoo closed 1 year ago

Andre-Coelhoo commented 1 year ago

Soo i tested this in a physical android and iOS, and simulator android and iOS. Both tests in the iOS I get a problem. Some times when I change screens in my app the camera position changes and the zoom also changes. something that doest happen in the android at all. I can provide some code about this.

apboxMap( trackCameraPosition: true, compassEnabled: false, annotationOrder: MapUtils.annotationOrder, minMaxZoomPreference: MinMaxZoomPreference(5, maxZoom.toDouble()), gestureRecognizers: MapUtils.gestureRecognizers, onStyleLoadedCallback: () async { if(state is Completed){ await addBackgroundFloorToMap(context); await addNewAreasToMap(site, context); await addNewNodesToMap(site, customer, context); } }, logoViewMargins: Point(-100, -100), attributionButtonMargins: Point(-100, -100), onMapClick: (point, coordinates) { _mapManager?.cleanPin(); context.read().closePersonCard(); }, onCameraIdle: () { final camera = _controller?.cameraPosition; if (camera != null && !camera.zoom.isNaN) { print("camera zoom: " + camera.zoom.toString()); final mapManager = context.read().mapManager; if (camera.zoom > 20 && mapManager?.size != 30) { mapManager?.size = 30; addNewNodesToMap(site, customer, context); mapManager?.recoverPin(); } else if (camera.zoom <= 20 && mapManager?.size != 20) { mapManager?.size = 20; addNewNodesToMap(site, customer, context); mapManager?.recoverPin(); } } }, onMapCreated: (MapboxMapController controller) async { this._controller = controller; context.read().mapboxController = controller;

                MapUtils.fitBound(controller, floorPlan);

              _mapManager = MapManager(controller);
              context.read<MapboxMapCubit>().mapManager = _mapManager;

              controller.onSymbolTapped.add(_onSymbolTapped);
            },
            accessToken: const String.fromEnvironment("ACCESS_TOKEN"),
            initialCameraPosition: MapUtils.getInitialCurrent(site),
          ),

          static void fitBound(MapboxMapController _controller, FloorPlan floorPlan) {
var bottomRightCorner =
    floorPlan.coords?.bottomRightCorner?.coords?.toLatLng;
var topLeftCorner = floorPlan.coords?.topLeftCorner?.coords?.toLatLng;

if (bottomRightCorner != null && topLeftCorner != null) {
  var bounds = LatLngBounds(
    southwest: LatLng(
      min(bottomRightCorner.latitude, topLeftCorner.latitude),
      min(bottomRightCorner.longitude, topLeftCorner.longitude),
    ),
    northeast: LatLng(
      max(bottomRightCorner.latitude, topLeftCorner.latitude),
      max(bottomRightCorner.longitude, topLeftCorner.longitude),
    ),
  );

  _controller.animateCamera(
    CameraUpdate.newLatLngBounds(
      bounds,
      left: 10,
      top: 10,
      right: 10,
      bottom: 10,
    ),
  );
}

}

static CameraPosition getInitialCurrent(Site site) { final double? lat = GetIt.I().get("currentLocationLat") as double?; final double? log = GetIt.I().get("currentLocationLog") as double?; final double? zoom = GetIt.I().get("currentLocationZoom") as double?;

if (lat != null && log != null && zoom != null) {
  return CameraPosition(
    target: LatLng(lat, log),
    zoom: zoom,
  );
}

return CameraPosition(
  target: site.siteInfo?.location.toLatLng ?? LatLng(0, 0),
  zoom: 10,
);

}

         static bool hasValuesSaved() {
final double? lat =
    GetIt.I<SharedPreferences>().get("currentLocationLat") as double?;
final double? log =
    GetIt.I<SharedPreferences>().get("currentLocationLog") as double?;
final double? zoom =
    GetIt.I<SharedPreferences>().get("currentLocationZoom") as double?;

return lat != null && log != null && zoom != null;

}

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Andre-Coelhoo commented 1 year ago

Can anyone give me any updates on this.