flutter_map icon indicating copy to clipboard operation
flutter_map copied to clipboard

[BUG] `tileSize` parameter is broken

Open bramp opened this issue 1 year ago • 2 comments

What is the bug?

The TileProvider(tileSize: ) argument does not seem to produce desired maps when set to a value different than 256.

JaffaKetchup did testing in https://github.com/fleaflet/flutter_map/pull/1668#issuecomment-1738056062 here are the appropriate screenshots that show the issues:

0101 0100

These maps are all meant to be centered on England, and you can see that wrapping around the global does not work correctly.

If we also look at MapBox's Static API, a 512 tile, is the same as the 256 tile with the same x, y and z, just at a higher resolution.

How can we reproduce it?

Checkout the example Retina/TileSize page: https://github.com/fleaflet/flutter_map/pull/1668 or create a map with

TileLayer(
   tileSize: 512
)

Do you have a potential solution?

Sorry no.

Platforms

Chrome

Severity

Erroneous: Prevents normal functioning and causes errors in the console

bramp avatar Sep 27 '23 22:09 bramp

Just to note, they are not all necessarily supposed to be centered on England. However, when changing the FM tile size setting, the map does just 'jump' to a different location, which is incorrect.

JaffaKetchup avatar Sep 28 '23 06:09 JaffaKetchup

Having this issue as well. Another thing is that this changes where markers or polylines for example are rendered. When using a 512 tile server and setting the tileSize to 512, my polylines are rendered in the middle of a sea: image

In comparison to their correct location when using 256 (default): image

V3ntus avatar Dec 04 '23 00:12 V3ntus

I have same issue. Tile request for 256 is 4x of 512 btw, which will affect cost.

readyiman avatar Jun 05 '24 02:06 readyiman

The issue occurs because of these lines:

https://github.com/fleaflet/flutter_map/blob/6170df99ce85126259e9caced13969309dd045cf/lib/src/geo/crs.dart#L62-L66

These assume a tile size of 256. Manually changing these to 512 when using tileSize 512 restores correct functionality.

However, fixing this is likely to be a little difficult, because the Crs is completely seperate to any TileLayer. Although we sometimes have requests to support a different Crs per TileLayer, this comment - https://github.com/fleaflet/flutter_map/issues/890#issuecomment-840154372 - covers why that's possibly a bad idea.

Therefore, there is an issue here of overall structure - the Crs should not really depend on a value from the TileLayer, but neither should the other layers if we move the multiplication out (or add an argument). I'm really not sure what the best way to solve this is.

JaffaKetchup avatar Jun 06 '24 09:06 JaffaKetchup

To fix this issue, use zoomOffset: -1. There's not really much we can do (as described above), and it was also the fix recommended on Leaflet: https://github.com/Leaflet/Leaflet/issues/4391. I'll add this to the documentation.

JaffaKetchup avatar Jun 06 '24 13:06 JaffaKetchup

To fix this issue, use zoomOffset: -1.

I can confirm this solution does work.

readyiman avatar Jun 07 '24 02:06 readyiman