Search code examples
iosmkmapviewmkoverlay

How often is drawMapRect:zoomScale:inContext: supposed to be called?


I have a custom MKOverlayRenderer. I add an MKOverlay (also custom) to the MKMapView after the first region change (when it moves from the default location to the user's). The rendering speed was pretty laggy, so I logged the function calls.

2016-07-20 14:03:21.486 MyApp[360:38679] mapView:regionDidChangeAnimated:
2016-07-20 14:03:22.351 MyApp[360:38679] addOverlay:level:
2016-07-20 14:03:22.353 MyApp[360:38679] mapView:rendererForOverlay:
2016-07-20 14:03:22.460 MyApp[360:38709] drawMapRect:zoomScale:inContext:
2016-07-20 14:03:22.460 MyApp[360:38706] drawMapRect:zoomScale:inContext:
2016-07-20 14:03:22.501 MyApp[360:38709] drawMapRect:zoomScale:inContext:
2016-07-20 14:03:22.504 MyApp[360:38706] drawMapRect:zoomScale:inContext:
2016-07-20 14:03:22.504 MyApp[360:38707] drawMapRect:zoomScale:inContext:
2016-07-20 14:03:22.560 MyApp[360:38707] drawMapRect:zoomScale:inContext:
2016-07-20 14:03:22.562 MyApp[360:38709] drawMapRect:zoomScale:inContext:
2016-07-20 14:03:22.582 MyApp[360:38713] drawMapRect:zoomScale:inContext:

This is without touching the device. Is drawMapRect:zoomScale:inContext supposed to be called repeatedly like this?


Solution

  • Is drawMapRect:zoomScale:inContext supposed to be called repeatedly like this?

    Yes. The visible map is composed of tiles. drawMapRect:zoomScale:inContext: is called once for each tile (as you would know if your implementation actually looked at the incoming rect parameter).