如何向MKPolylineRenderer添加阴影或边缘?

时间:2015-02-03 20:41:22

标签: ios mapkit shadow

- (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;
}}

代码显示了在地图上运行的路径。我尝试了很多方法,但我不知道如何解决它。

1 个答案:

答案 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;
}