p-lr / MapView

A Fast, memory efficient Android library to display tiled maps, with support for markers, paths, and rotation.
Apache License 2.0
184 stars 38 forks source link

Blank tiles #20

Closed uyt95 closed 3 years ago

uyt95 commented 3 years ago

Hi

I'm having issues with a number of blank tiles. Sometimes when zooming those tiles get filled in at specific zoom ranges, but most of the time they are blank. Depending on the map the number of blank tiles ranges between 0 and +-30. For a specific map, the number of blank tiles and the location of the blank tiles are consistent across app restarts. I'm only using a level count of 1 and no errors are thrown while loading the map and the tiles.

Do you have any idea what could be the cause of this?

Thanks in advance!

p-lr commented 3 years ago

Hi,

I tried to reproduce it locally, in a demo with a single level. No blank tiles. Which version of MapView are you using?

uyt95 commented 3 years ago

Hi, at first I was using version 2.1.3. I upgraded to 2.1.4 and the issue remains. I've created a demo that always reproduces the issue for me with a lot of blank tiles: https://github.com/uyt95/BlankTilesDemo

p-lr commented 3 years ago

I've tried your demo on my device and on two emulators, and I never saw a blank tile. Nice map BTW. This is really surprising. Have you reproduced your issue on other devices?

Also, I have a remark about your TileStreamProvider:

TileStreamProvider { row, col, _ ->
   try {
      application.assets.open("tiles/${col}x${row}.jpg")
   } catch (e: Exception) {
      null
   }
}

If on your device, there's something wrong when reading a tile file from the assets, you silently catch the exception. You should add e.printStackTrace() before returning null. You might see some exceptions in logcat. This might come from permission issues.

uyt95 commented 3 years ago

I wasn't able to reproduce it on other devices, but I found the cause. Xiaomi devices have a bad forced dark mode implementation that sometimes overwrites tiles with a blank tile. To fix this, I added the following to my application style: <item name="android:forceDarkAllowed">false</item>

Thanks for your help!