I am attempting to draw a nice MKPolyline
on an MKPolylineView
. Everything is going great so far - the polyline draws just as I want it to and when I want it to using the following code:
[[self map] addOverlay:routeLine];
And this method to tell the app how to draw it:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
MKOverlayView* overlayView = nil;
self.routeLineView = [[MKPolylineView alloc] initWithPolyline:[self routeLine]];
[[self routeLineView] setFillColor:[UIColor colorWithRed:167/255.0f green:210/255.0f blue:244/255.0f alpha:1.0]];
[[self routeLineView] setStrokeColor:[UIColor colorWithRed:0/255.0f green:136/255.0f blue:255/255.0f alpha:1.0]];
[[self routeLineView] setLineWidth:15.0];
[[self routeLineView] setLineCap:kCGLineCapRound];
overlayView = [self routeLineView];
return overlayView;
}
As a result I get a line with a solid blue. The blue I see is not however the fill color with the stroke I am expecting - it is the blue of the stroke color. There is no fill color when I use this method. Why doesn't it draw the fill color on the polyline?
After investigating further, I found this tidbit of information in the Quick Help section of Xcode:
The MKPolylineView class provides the visual representation for an MKPolyline annotation object. This view strokes the path represented by the annotation. (This class does not fill the area enclosed by the path.) You can change the color and other drawing attributes of the path by modifying the properties inherited from the MKOverlayPathView class.
That just sounds ridiculous. I have to use this class to set the fill color, but I can't use this class to draw the fill color? That just seems very odd considering it already draws the stroke. The last line in this explanation from the documentation is a little unclear but seems to provide an answer - I'm just having a hard time coding / finding the answer. I don't have an MKOverlayPathView
in my project (what is that anyway?) but it seems to be the solution - does anyone know how to use it?
MKPolylineView
is a subclass ofMKOverlayPathView
. Regardless, you just want to useMKPolygon
(and create the associatedMKPolygonView
) instead ofMKPolyline
.MKPolygon
draws both the stroke and the fill. – Induna