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

Map::cameraForLatLngBounds returns incorrect CameraOptions #8737

Closed

Description

@tobrun

Been looking into an user reported bug that has the camera positioned above New York City and is trying to move the camera to a LatLngBounds in China.

For the following China bounds:

screenshot at 2017-04-13 10 10 42

The following center coordinate is calculated with Map::cameraForLatLngBounds:

screenshot at 2017-04-13 10 11 15

This results in centering the camera on the east coast

image

While we were expecting: [34.6212005,104.1363335]

screenshot at 2017-04-13 10 22 10

Data to reproduce this with

New York City = [40.712730, -74.005953], z=12
China bounds = [15.68169,73.499857], [53.560711, 134.77281]

GL-JS is handling the use-case described above correctly, see here.

Activity

  1. added
    Core
    on Apr 13, 2017
  2. tobrun commented on Apr 13, 2017

    @tobrun
    MemberAuthor

    I added a unit test to validate the behaviour:

    TEST(Map, LatLngBoundsToCamera) {
        MapTest test;
        Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
    
        map.setLatLngZoom({ 40.712730, -74.005953 }, 12);
        
        LatLngBounds bounds = LatLngBounds::hull({15.68169,73.499857},{53.560711, 134.77281});
        CameraOptions virtualCamera = map.cameraForLatLngBounds(bounds, {});
        ASSERT_NEAR(virtualCamera.center->latitude(), 34.6212005, 1e-7);
        ASSERT_NEAR(virtualCamera.center->longitude(), 104.1363335, 1e-7);
    }

    Failure the difference between virtualCamera.center->latitude() and 34.6212005 is 2.2965077241166512, which exceeds 1e-7, where
    virtualCamera.center->latitude() evaluates to 36.917708224116652,
    34.6212005 evaluates to 34.6212005, and
    1e-7 evaluates to 9.9999999999999995e-08.

    Failure the difference between virtualCamera.center->longitude() and 104.1363335 is 179.9999999999998, which exceeds 1e-7, where
    virtualCamera.center->longitude() evaluates to -75.863666499999795,
    104.1363335 evaluates to 104.13633350000001, and
    1e-7 evaluates to 9.9999999999999995e-08.

    This seems to produce the same results as what I had seen during debugging.

  3. jfirebaugh commented on Apr 13, 2017

    @jfirebaugh
    Contributor

    @brunoabinader, could you take a look here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Core

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions