我无法在MKOverlay视图中添加两种不同颜色的MKPolyline视图。关于如何实现这一点的任何想法? 感谢
这是我的代码:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
UIColor *mycolor;
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
mycolor = [UIColor colorWithRed:85.0/255.0 green:133.0/255.0 blue:255.0/255.0 alpha:0.6];
self.routeLineView.fillColor = mycolor;
self.routeLineView.strokeColor = mycolor;
self.routeLineView.lineWidth = 15;
[overlayView addSubview:self.routeLineView];
self.routeLineView2 = [[[MKPolylineView alloc] initWithPolyline:self.routeLine2] autorelease];
mycolor = [UIColor colorWithRed:85.0/255.0 green:19.0/255.0 blue:25.0/255.0 alpha:0.6];
self.routeLineView2.fillColor = mycolor;
self.routeLineView2.strokeColor = mycolor;
self.routeLineView2.lineWidth = 15;
[overlayView addSubview:self.routeLineView2];
return overlayView;
}
答案 0 :(得分:0)
将为您添加到地图的每个叠加层单独调用viewForOverlay
方法。因此,在该方法中,您只返回当前正在调用的叠加层的叠加层视图(即overlay
参数)。
检查请求查看的覆盖图,并仅为该覆盖创建并返回视图。
例如:
if (overlay == self.routeLine)
{
//create and return overlay view for routeLine...
//set color, etc...
return self.routeLineView;
}
else
if (overlay == self.routeLine2)
{
//create and return overlay view for routeLine2...
//set color, etc...
return self.routeLineView2;
}
return nil;
不要做任何addSubview
的事情。只需创建叠加视图并将其返回。