Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map::pixelForLatLng() returns invalid values when its transform state has a longitude > 180 #2960

Open
clinthidinger opened this issue Oct 23, 2024 · 0 comments
Labels
bug Something isn't working cpp-core

Comments

@clinthidinger
Copy link

Describe the bug
When you move the map to where its transform state has a longitude over 180 (or less than -180), Map::pixelForLatLng() will no longer work.

To Reproduce

  1. In your zoom call, print abs(map->getTransfromState().getLatLng().longitude()).
  2. Also print a value from map->pixelFotLatLng().
  3. Pan and zoom the screen to where the 180th meridian is near the center of the screen. Keep moving the map around until you see the longitude go greater than 180 in the print out.
  4. Once the longitude is over 180, you will notice that the x pixel values from Map::pixelForLatLng() go way out of bounds or negative.

Expected behavior
Map::pixelForLatLng() should return a legit value.

Platform information (please complete the following information):

  • OS: Windows 11
  • Platform GLFW
  • Version c098a12

Hack/Fix

This is my temporary hack:

ScreenCoordinate Map::pixelForLatLng(const LatLng& latLng) const {
    // If the center and point longitudes are not in the same side of the
    // antimeridian, we unwrap the point longitude so it would be seen if
    // e.g. the next antimeridian side is visible.
    LatLng unwrappedLatLng = latLng.wrapped();
    unwrappedLatLng.unwrapForShortestPath(impl->transform.getLatLng());
    auto result = impl->transform.latLngToScreenCoordinate(unwrappedLatLng);

    // Hack: We correct for the case where longitude goes out of bounds.
    if (abs(getTransfromState().getLatLng().longitude()) > 180.0)
    {
        auto const shift = impl->transform.latLngToScreenCoordinate(impl->transform.getLatLng());
        result.x = (getTransfromState().getSize().width / 2.0) + (result.x - shift.x);
    }

    return result;
}

Additional Info

getTransfromState().getLatLng() returns an unwrapped coord, and impl->transform.getLatLng() returns a wrapped coord. I'm not sure if that is the intended design.

Also, I wonder if this is related to #2951 since it also deals with the 180th meridian.

@clinthidinger clinthidinger added the bug Something isn't working label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cpp-core
Projects
None yet
Development

No branches or pull requests

2 participants