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

PrecisionPoint TransformState::latLngToPoint dateline issue #4155

Closed
tobrun opened this issue Mar 1, 2016 · 9 comments · Fixed by #4275
Closed

PrecisionPoint TransformState::latLngToPoint dateline issue #4155

tobrun opened this issue Mar 1, 2016 · 9 comments · Fixed by #4275
Assignees
Labels

Comments

@tobrun
Copy link
Member

tobrun commented Mar 1, 2016

Issue in mbgl when calculating points based on LatLng from the left side of the dateline after crossing the dateline from left to right. This is a follow up issue for #3995.

An example:

Take this LatLng:

LatLng [longitude=-179.64576449708883, latitude=-16.83408606795382, altitude=0.0]

before crossing the dateline latLngToPoint is giving us Point[x=455.80133, y= 746.6456]
while after crossing the dateline latLngToPoint is giving us Point[x=393667.44, y=747.1837].
Normally we should see a small decrease in value not a big increase.

@tobrun tobrun added the bug label Mar 1, 2016
@tobrun
Copy link
Member Author

tobrun commented Mar 1, 2016

Related method in transform_state.cpp:

PrecisionPoint TransformState::latLngToPoint(const LatLng& latLng) const {
    return coordinateToPoint(latLngToCoordinate(latLng));
}

which on his turn calls:

PrecisionPoint TransformState::coordinateToPoint(const TileCoordinate& coord) const {
    mat4 mat = coordinatePointMatrix(coord.zoom);
    matrix::vec4 p;
    matrix::vec4 c = {{ coord.column, coord.row, 0, 1 }};
    matrix::transformMat4(p, c, mat);
    return { p[0] / p[3], height - p[1] / p[3] };
}

and

TileCoordinate TransformState::latLngToCoordinate(const LatLng& latLng) const {
    const double tileZoom = getZoom();
    const double k = zoomScale(tileZoom) / worldSize();
    return {
        lngX(latLng.longitude) * k,
        latY(latLng.latitude) * k,
        tileZoom
    };
}

@1ec5
Copy link
Contributor

1ec5 commented Mar 1, 2016

I can reproduce this issue in the iOS SDK. From my location in California, if I zoom out to z0 and pan west, the user location annotation disappears as soon as the map view’s center point crosses the antimeridian. The iOS SDK similarly positions the user location annotation using Transform::latLngToPoint() (via Map::pixelForLatLng() and -[MGLMapView convertCoordinate:toPointToView:]).

@tobrun
Copy link
Member Author

tobrun commented Mar 5, 2016

To make this problem a bit more visual, see this clip where I'm visualising the touch events.

@brunoabinader
Copy link
Member

@tobrun @1ec5 this should have been fixed in fd123de - could you please test using this hash?

@tobrun
Copy link
Member Author

tobrun commented Mar 6, 2016

@brunoabinader I'm on it, currently building specifically from that commit.

@tobrun
Copy link
Member Author

tobrun commented Mar 6, 2016

The user location and camera are LatLng [longitude=179.931, latitude=-16.945]
At that time the user location is converted to x: 77.64928 and y: 918.33923

Just before crossing the dateline the camera is on LatLng [longitude=179.99965655644286, latitude=-16.91392665410768] the values are x: 40.649273 and y: 906.33923.

Just after crossing the dateline the camera is on LatLng [longitude=-179.99907836847547, latitude=-16.91429282823615] the values are x: 3601749.0 and y: 618666.6

While it should be almost the same as before crossing, the x value should be a bit lower.

@tobrun
Copy link
Member Author

tobrun commented Mar 6, 2016

Here is the related video showing it,
note that the hash mentioned above contained this flashing regression from #4174.
which is no longer a problem on master.

@brunoabinader brunoabinader self-assigned this Mar 7, 2016
@brunoabinader
Copy link
Member

On it 👍

@brunoabinader
Copy link
Member

👉 #4214.

@brunoabinader brunoabinader added this to the android-v4.0.0 milestone Mar 7, 2016
brunoabinader added a commit that referenced this issue Mar 10, 2016
If the center and point coordinates are not in the same side of the
antimeridian, we need to unwrap the point longitude to make sure
it can still be seen from the visible side of the antimeridian that is
opposite to the center side.

Fixes #4155.
brunoabinader added a commit that referenced this issue Mar 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants