0

How can I check if a map is loaded into MKKapview ? I mean... asking the map view to be ready - and not waiting for notification mapViewDidFinishLoadingMap: which doesn't notify if it is already buffered ?

My usecase for better understanding the problem: My App should print a map which is created in the background, using MKMapview. Loading the map can take a while, so without checking the readyness, the map will be incomplete. This can clearly be seen in the preview. Using mapViewDidFinishLoadingMap: helps for the first time. But if I print again just with a slightly different region, I will not get the notification.

This is my code snippest

-(IBAction)print:(id)sender {
    [self prepareClonedMap];
}

-(void) prepareClonedMap {
        [self cloneMap:scaling];
        // I would like here ...  if ( mapIsReady ) [self executePrint];
}

-(void)mapViewDidFinishLoadingMap:(MKMapView *)mapView {
      [self executePrint];
}

-(void)executePrint {
   // make MKMapSnapshot
   // create printoperation
   .....
}

-(void)cloneMap:(CGFloat) factor {
    NSRect myframe;
    // expand to max factor

    myframe=mapView.frame;
    myframe.size.height = myframe.size.height * factor,
    myframe.size.width  = myframe.size.width  * factor;

    // reduce to max dimensions
    myframe.size = [self maxDimensionWithRatio:myframe.size];
    [cloneView setFrame:myframe];
    [cloneView setRegion:[mapView region]];
}
  • What does `cloneMap` do? How do you make the `MKMapSnapshot`? – Willeke Jan 19 '19 at 17:34
  • I have added cloneMap to the code above. The view is part of the xib file. MKSnapshotter is just like the documentation of Apple describes. My only options are size and region. Then I call it by `[mapSnapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error)` – Christian Krueger Jan 19 '19 at 18:06
  • have a look at https://stackoverflow.com/a/11870288/1244597 – AamirR Jan 19 '19 at 19:01
  • Possible duplicate of [Detecting when MapView tiles are displayed](https://stackoverflow.com/questions/11728189/detecting-when-mapview-tiles-are-displayed) – AamirR Jan 19 '19 at 19:02
  • 1
    The documentation of `MKMapSnapshotter` says "The snapshotter object always captures the best image possible, loading all of the available map tiles before capturing the image.". How can we reproduce the issue? I tried but my test app is very basic and works. – Willeke Jan 19 '19 at 23:05
  • Thank you for your hint , Willeke ! It is exactly what I assume meanwhile. The root cause of my problem is probably somewhere else. Reproducing isn't so easy, it looks that sometimes not all informations are on the map. In any case, I can see the map in preview. – Christian Krueger Feb 12 '19 at 09:48
  • I found out, that TWO mapViews in an App are problematic. Having only one map , and printing from this runs fine ! No issue with tilings or whatever. The idea was to clone the map ( in higher resolution and size) in background and print from there. This doesn't work – Christian Krueger Mar 22 '19 at 16:25

0 Answers0