我在 CALayer(在 MKOverlay 上)上有一个带有一系列动画图像的 MKOverlay。每当我在地图上移动或缩放时,都会再次添加 MKOverlay,这会导致同一叠加层的多个版本一次又一次地出现。有没有办法可以将叠加层设置为只显示一次?
这是我将叠加层添加到地图的代码:
- (void)mapRadar {
[self.mapView removeOverlay:self.mapOverlay];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.mapOverlay = [[MapOverlay alloc] initWithLowerLeftCoordinate:CLLocationCoordinate2DMake(appDelegate.south, appDelegate.west) withUpperRightCoordinate:CLLocationCoordinate2DMake(appDelegate.north, appDelegate.east)];
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);
MKMapPoint lowerLeft = MKMapPointForCoordinate(CLLocationCoordinate2DMake(appDelegate.south, appDelegate.west) );
MKMapPoint upperRight = MKMapPointForCoordinate(CLLocationCoordinate2DMake(appDelegate.north, appDelegate.east));
MKMapRect nationalSectorMapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);
[self.mapView addOverlay:[MKCircle circleWithMapRect:nationalSectorMapRect]];
[self.mapView setNeedsDisplay];
[self.mapView setVisibleMapRect:localMapRect animated:YES];
}
#pragma Mark - MKOverlayDelgateMethods
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay{
MapOverlayView* circleView = [[MapOverlayView alloc] initWithCircle:(MKCircle *)overlay];
return circleView;
}