I am using the iOS 7 MapKit APIs to produce 3D camera movements on a map that displays an MKDirectionsRequest-produced path. The path is rendered by MKOverlayRenderer like so:
-(void)showRoute:(MKDirectionsResponse *)response
{
for (MKRoute *route in response.routes)
{
[self.map
addOverlay:route.polyline level:MKOverlayLevelAboveRoads];
}
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay
{
MKPolylineRenderer *renderer =
[[MKPolylineRenderer alloc] initWithOverlay:overlay];
UIColor *mapOverlayColor = [UIColor colorWithRed:((float)22 / 255.0f) green:((float)126 / 255.0f) blue:((float)251 / 255.0f) alpha:0.8];
renderer.strokeColor = mapOverlayColor;
renderer.lineWidth = 13.0;
return renderer;
}
It's working well except for one issue. When I zoom or pan around the path with MKMapCameras (and without them, if I simply do so as the user), the path is jagged as shown in this screenshot:
I tested to see if switching to MKOverlayLevelAboveLabels makes a difference but sadly the outcome was the same.
Does anyone have suggestions as to how to improve the rendering? Does switching to a geodesic path make a difference and if so, how would I implement this here?
MKPolylineRenderer is seriously broken as it will not redraw offscreen and it has faulty logic for calculating its cliprect which causes endcap artifacts to be left on the screen. Removing and readding the overlay did nothing for me. Trying to fix the line width does work but you will still get endcap problems with larger line widths. Using the roadSizeForZoomLevel option wont work either (lineWidth = 0)
To get rid of the endcap artifacts that never go away I used the renderer from the Breadcrumb sample app. Now I just have the occasionally unacceptable issue of the redrawing when moving the map around.
The breadrumb renderer I think is what the PolylineRenderer was supposed to be but someone broke it. But even still its not clear how one would force offscreen redraws (Im not a core graphics expert but given that apple maps app doesnt exhibit this behavior Im sure a guru could figure it out.
Anyway if you at least want a renderer that wont leave junk on the screen use the Breadcrumb renderer. Thats the best I could find. If you really need a better mapkit try googmaps