Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Camera position for LatLngBounds when crossing IDL #11733

Closed
LukasPaczos opened this issue Apr 19, 2018 · 2 comments
Closed

Camera position for LatLngBounds when crossing IDL #11733

LukasPaczos opened this issue Apr 19, 2018 · 2 comments
Labels
Android Mapbox Maps SDK for Android Core The cross-platform C++ core, aka mbgl

Comments

@LukasPaczos
Copy link
Member

When using mbgl::Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transform& transform, const EdgeInsets& padding) we are calculating the bounds width without taking IDL into account, or in other words, not by the shortest possible path.

It's reproducible with below Android code:

mapView.getMapAsync(new OnMapReadyCallback() {
  @Override
  public void onMapReady(MapboxMap mapboxMap) {
    mapboxMap.addOnCameraIdleListener(() ->
      Timber.e("Camera IDLE: %s, zoom: %f", mapboxMap.getCameraPosition().target, mapboxMap.getCameraPosition().zoom));

    //crossing IDL
    LatLngBounds latLngBounds = LatLngBounds.from(16.5, -172.8, -35.127709, 172.6);
    CameraPosition cameraPosition = mapboxMap.getCameraForLatLngBounds(latLngBounds, new int[] {0, 0, 0, 0});
    mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

    //not crossing IDL
    new Handler().postDelayed(() -> {
      LatLngBounds latLngBounds1 = LatLngBounds.from(16.5, -162.8, -35.127709, -177.4);
      CameraPosition cameraPosition1 = mapboxMap.getCameraForLatLngBounds(latLngBounds1, new int[] {0, 0, 0, 0});
      mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition1));
    }, 2500);
  }
});

which gives us this results:

Camera IDLE: LatLng [latitude=0.0, longitude=-0.10000000000923137, altitude=0.0], zoom: 0.000000
Camera IDLE: LatLng [latitude=-10.357079043959077, longitude=-170.10000000000286, altitude=0.0], zoom: 2.729140
@LukasPaczos LukasPaczos added the Core The cross-platform C++ core, aka mbgl label Apr 19, 2018
@LukasPaczos
Copy link
Member Author

Also noticed, that when creating mbgl::LatLngBounds object with mbgl::LatLngBounds::hull, we are always getting a bound that doesn't cross the antimeridian because of the implementation of mbgl::LatLngBounds::extend, unless the values are unwrapped.

@1ec5
Copy link
Contributor

1ec5 commented Apr 20, 2018

#11265 fixed a similar issue for iOS and macOS. mbgl::LatLngBounds has methods like unwrapForShortestPath() to account for ambiguity when spanning the antimeridian. Note that fixing this issue may reveal latent issues in other methods that deal with cameras.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

No branches or pull requests

2 participants