I'm updating an iOS 6 app for iOS 7 and discovered that the way overlays are handled has completely changed in iOS 7.
We're drawing a light grey overlay over the entire map. In iOS 6 everything works perfectly, in iOS 7 we get no overlay.
In viewDidLoad
I have the following:
CLLocationCoordinate2D worldCoords[4] = { {90,-180}, {90,180}, {-90,180}, {-90,-180} };
MKPolygon *worldOverlay = [MKPolygon polygonWithCoordinates:worldCoords
count:4];
[self.mapView addOverlay:worldOverlay];
Then, for iOS 6 . . .
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if (![overlay isKindOfClass:[MKPolygon class]]) {
return nil;
}
MKPolygon *polygon = (MKPolygon *)overlay;
MKPolygonView *view = [[MKPolygonView alloc] initWithPolygon:polygon];
view.fillColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4];
return view;
}
For iOS 7 . . .
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if (![overlay isKindOfClass:[MKPolygon class]]) {
return nil;
}
MKPolygon *polygon = (MKPolygon *)overlay;
MKPolygonRenderer *renderer = [[MKPolygonRenderer alloc] initWithPolygon:polygon];
renderer.fillColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4];
return renderer;
}
Using breakpoints, I verified that the mapView:rendererForOverlay:
method is being called and that the renderer
object it's returning has the fillColor
property set correctly.
Any thoughts as to why we're not seeing the overlay?
All of your code is absolutely valid - I plugged it into my test map controller and it works perfectly if I do one small change:
CLLocationCoordinate2D worldCoords[4] = { {43,-100}, {43,-80}, {25,-80}, {25,-100} };
So, the problem is not in the renderer per se. I believe it has something to do with specifying 180th Meridian - Apple has made some changes to support regions spanning the 180th Meridian in iOS7. I don't need it since focusing exclusively on North America so I skipped it but there is a 2013 WWDC video where they talk about it - see What's New in MapKit session around 4:42: https://developer.apple.com/wwdc/videos/
Cheers,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With