mapbox / abaculus

Library for creating static maps from tiles based on center or corner lng,lat coordinates. Uses node-blend.
ISC License
127 stars 38 forks source link

Fix bug where there are white lines between tiles when scale*256 isn't whole number #19

Closed samwillis closed 7 years ago

samwillis commented 8 years ago

When (scale*256)%1 > 0.5 there are white lines between tiles, rounding down when calculating tileSize fixes the issue.

I don't understand the code completely but I believe that this results in the tiles packing together towards the middle of the image. Therefore a few extra pixels of map are shown from the edge tiles and so the edge tiles may be a little out of alignment from the expected coods. I think this is an OK tradeoff as its only vary slight and not having the white lines is obviously more important.

The alignment between the tiles does not seem to be affected at all, there is no missing slice of map between them.

(I wander if somewhere during the tile generation process the tile size is rounded down, could be the source of the error?)

springmeyer commented 8 years ago

@samwillis - thanks for the contribution and for looking into this. Can you post some images describing the problem in more detail? As it stands right now I'm hesitant to accept this without a stronger case of the problem and what it solves exactly. /cc @camilleanne

samwillis commented 8 years ago

Hi Dane,

The easiest way for you to reproduce the problem is with Mapbox Studio Classic (I am also experiencing it with Tessera - https://github.com/mojodna/tessera). When running Studio Classic if you visit the url (scale 2.2):

http://localhost:3000/static/10/28.3468,40.8398,29.477,41.2819@2.2x.png?id=tmpstyle:///Applications/Mapbox%20Studio.app/Contents/Resources/app/node_modules/mapbox-machine-styles/node_modules/mapbox-studio-wheatpaste

there are no white line between the tiles and 256*2.2 = 563.2, therefore currently tileSize is rounded down.

wheatpaste-z10_28 3468_40 8398_29 477_41 2819_2 scale 2 2

However, if you visit (scale 2.3):

http://localhost:3000/static/10/28.3468,40.8398,29.477,41.2819@2.3x.png?id=tmpstyle:///Applications/Mapbox%20Studio.app/Contents/Resources/app/node_modules/mapbox-machine-styles/node_modules/mapbox-studio-wheatpaste

there is a single pixel white line between all the tiles and 256*2.3 = 588.8, therefore currently tileSize is rounded up. It seems that rounding up is causing the white lines to appear, I think abaculus thinks it is using tiles one pixel bigger than are being drawn.

wheatpaste-z10_28 3468_40 8398_29 477_41 2819_2 scale 2 3

To reproduce the error with Tessera you need to use this branch https://github.com/mojodna/tessera/pull/36 as Tessera currently doesn't allow arbitrary scales in the same way as Studio Classic.

samwillis commented 8 years ago

To add the the previous comment, this is the image returned from the second url (scale 2.3) with a patched version of tessera. wheatpaste-z10_28 3468_40 8398_29 477_41 2819_2 7 As you can see the while lines are gone.

If you open all three images in separate tabs and tab between them you can see that the first two are showing exactly the same area, with the second one showing the white lines. The third images (with the white lines fixed) seems to pull the tiles from the second image together towards the centre of the image, this results in the image showing a couple of extra pixels of map around the outside.

I don't understand the complete process well enough to know why this is the case. However if it was a choice between one bug or the other, not having the white lines seems to be preferable.