Note that there are some explanatory texts on larger screens.

plurals
  1. POMKMapView Overlay (image animation)
    primarykey
    data
    text
    <p>I'm trying to animate a radar image on an MKMapView. I have separate images for different times, and I have successfully set an image as an overlay on top of the MKMapView. My problem is when I try to show these different images in a sequence one after each other. I tried a method of adding and removing overlays, but the system does not handle it well at all, with flickering of overlays, and some overlays not being removed, and overall, its not worth it.</p> <p>Could anyone help me find a way to show multiple images (like an animated gif) on top of a MapView in a way that is smooth and fast?</p> <p>Here's my code to overlay the image:</p> <pre><code>- (id)initWithImageData:(NSData*)imageData withLowerLeftCoordinate:(CLLocationCoordinate2D)lowerLeftCoordinate withUpperRightCoordinate:(CLLocationCoordinate2D)upperRightCoordinate { self.radarData = imageData; MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate); MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate); mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y); return self; } - (CLLocationCoordinate2D)coordinate { return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(mapRect), MKMapRectGetMidY(mapRect))); } - (MKMapRect)boundingMapRect { return mapRect; } </code></pre> <p>and here's how I'm setting it up on the MapView:</p> <pre><code>- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)ctx { MapOverlay *mapOverlay = (MapOverlay *)self.overlay; image = [[UIImage alloc] initWithData:mapOverlay.radarData]; MKMapRect theMapRect = [self.overlay boundingMapRect]; CGRect theRect = [self rectForMapRect:theMapRect]; @try { UIGraphicsBeginImageContext(image.size); UIGraphicsPushContext(ctx); [image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:0.5]; UIGraphicsPopContext(); UIGraphicsEndImageContext(); } @catch (NSException *exception) { NSLog(@"Caught an exception while drawing radar on map - %@",[exception description]); } @finally { } } </code></pre> <p>and here's where I'm adding the overlay:</p> <pre><code>- (void)mapRadar { AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; self.mapOverlay = [[MapOverlay alloc] initWithImageData:appDelegate.image withLowerLeftCoordinate:CLLocationCoordinate2DMake(appDelegate.south, appDelegate.west) withUpperRightCoordinate:CLLocationCoordinate2DMake(appDelegate.north, appDelegate.east)]; [self.mapView addOverlay:self.mapOverlay]; [self.mapView setNeedsDisplay]; self.mapView.showsUserLocation = YES; MKMapPoint lowerLeft2 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(appDelegate.south2, appDelegate.west2) ); MKMapPoint upperRight2 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(appDelegate.north2, appDelegate.east2)); MKMapRect localMapRect = MKMapRectMake(lowerLeft2.x, upperRight2.y, upperRight2.x - lowerLeft2.x, lowerLeft2.y - upperRight2.y); [self.mapView setVisibleMapRect:localMapRect animated:YES]; } #pragma Mark - MKOverlayDelgateMethods -(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay{ if([overlay isKindOfClass:[MapOverlay class]]) { MapOverlay *mapOverlay = overlay; self.mapOverlayView = [[MapOverlayView alloc] initWithOverlay:mapOverlay]; } return self.mapOverlayView; } </code></pre> <p>Does anyone have an idea or a solution where I can show a sequence of images on an MKMapView smoothly? At this point, I'm desperate for solutions and can't find it anywhere else, so anything would help me, thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload