- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay{
if ([overlay isKindOfClass:[MulticolorPolylineSegment class]]) {
MulticolorPolylineSegment *polyLine = (MulticolorPolylineSegment *)overlay;
MKPolylineRenderer *aRenderer = [[MKPolylineRenderer alloc] initWithPolyline:polyLine];
aRenderer.strokeColor = polyLine.color;
// aRenderer.fillColor = [UIColor redColor];
aRenderer.lineCap = kCGLineCapRound;
aRenderer.lineJoin = kCGLineJoinBevel;
// aRenderer.lineDashPhase = 66;
aRenderer.miterLimit = 40;
aRenderer.lineWidth = 6;
return aRenderer;
}}
代码显示了在地图上运行的路径。我尝试了很多方法,但我不知道如何解决它。
答案 0 :(得分:2)
您可以在自己的下方添加第二个MKPolyline。然后将这个渲染为你的影子。
self.backgroundPolyline = [MKPolyline polylineWithCoordinates:coordinates
count:count];
self.backgroundPolyline.title = BACKGROUND;
[self.mapView insertOverlay:self.backgroundPolyline
belowOverlay:self.routePolyline];
…
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
return [[MKTileOverlayRenderer alloc] initWithOverlay:overlay];
}else if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolylineRenderer* aView = [[MKPolylineRenderer alloc] initWithPolyline:(MKPolyline*)overlay];
if([overlay.title isEqualToString:BACKGROUND]) {
aView.strokeColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
aView.lineWidth = 8;
}else{
aView.strokeColor = [[UIColor redColor] colorWithAlphaComponent:1];
aView.lineWidth = 2;
}
return aView;
}
return nil;
}