Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Some tiles not rendered in a custom MKTileOverlay

I have a custom MKTileOverlay in my iOS project using MapKit, it works fine most of the time. However, after zooming in/out a few times and panning the map some of the tiles are not being drawn.

At first I thought it was a simple case of tiles not being loaded so I subclassed the MKTileOverlay and added logging in the console. It showed that all tiles were loaded perfectly fine and delivered to the result block.

As I was running out of ideas I created a local tile generator that just returns images with their path x/y/z and frame drawn to see what tiles are missing.

Missing tile example image

Unfortunately the problem persists even with locally generated tiles so it has nothing to do with Internet connectivity. Another weird behaviour is that if I have two custom overlays on top of one another, it will be exactly the same tiles that are not being rendered on both overlays.

The only solution I can think of right now is subclassing the tile renderer and making sure that everything is displayed as there is no way to know that the tile is not rendered. This, however, sounds like a lot of work and a "reinventing the wheel" kinda task...

like image 812
pppd Avatar asked Nov 07 '16 08:11

pppd


1 Answers

We were also experiencing this problem of missing tiles - trying to draw map tiles around New Zealand. The MKOverlayRenderer was not even requesting the tiles. We went down a rabbit hole thinking it must be because New Zealand is near the 180/0 latitude boundary. Nope. It was because the sub-classed method:-

- (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData * __nullable data, NSError * __nullable error))result;

Must always call the result method even if there is no data to return! To give credit where credit is due this was the source of the solution for us:-

MKTileOverlay not drawing every tile?

like image 143
goelectric Avatar answered Nov 15 '22 04:11

goelectric