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

fix missing repeats of CanvasSource when it crosses the antimeridian #7273

Merged
merged 3 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,21 @@ class Transform {
* @private
*/
getVisibleUnwrappedCoordinates(tileID: CanonicalTileID) {
const ul = this.pointCoordinate(new Point(0, 0), 0);
const ur = this.pointCoordinate(new Point(this.width, 0), 0);
const w0 = Math.floor(ul.column);
const w1 = Math.floor(ur.column);
const result = [new UnwrappedTileID(0, tileID)];
if (this._renderWorldCopies) {
for (let w = w0; w <= w1; w++) {
const utl = this.pointCoordinate(new Point(0, 0), 0);
const utr = this.pointCoordinate(new Point(this.width, 0), 0);
const ubl = this.pointCoordinate(new Point(this.width, this.height), 0);
const ubr = this.pointCoordinate(new Point(0, this.height), 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain how this fixes the rotation issue, @ansis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using all four corners is necessary since the leftmost/rightmost points could be any of the corners. The following two lines with the Math.min and Math.max handle the case when the map is upside down

const w0 = Math.floor(Math.min(utl.column, utr.column, ubl.column, ubr.column));
const w1 = Math.floor(Math.max(utl.column, utr.column, ubl.column, ubr.column));

// Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.
// Both sources draw outside the tile boundaries of the tile that "contains them" so we need
// to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.
const extraWorldCopy = 1;

for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {
if (w === 0) continue;
result.push(new UnwrappedTileID(w, tileID));
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"version": 8,
"metadata": {
"test": {
"width": 512,
"height": 64
}
},
"center": [
-10,
0
],
"zoom": 0,
"sources": {
"image": {
"type": "image",
"coordinates": [
[
-270,
-80
],
[
90,
-80
],
[
90,
80
],
[
-270,
80
]
],
"url": "local://image/0.png"
}
},
"layers": [
{
"id": "image",
"type": "raster",
"source": "image",
"paint": {
"raster-fade-duration": 0
}
}
]
}
2 changes: 1 addition & 1 deletion test/unit/geo/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ test('transform', (t) => {
transform.center = { lng: -170.01, lat: 0.01 };

let unwrappedCoords = transform.getVisibleUnwrappedCoordinates(new CanonicalTileID(0, 0, 0));
t.equal(unwrappedCoords.length, 2);
t.equal(unwrappedCoords.length, 4);

//getVisibleUnwrappedCoordinates should honor _renderWorldCopies
transform._renderWorldCopies = false;
Expand Down