hen*_*nes 3 objective-c mapkit ios mkoverlay mkoverlaypathrenderer
我将两个不同的MKGeodesicPolyline实例添加到MKMapView这样的
CLLocation *LAX = [[CLLocation alloc] ...];
CLLocation *JFK = [[CLLocation alloc] ...];
CLLocation *LHR = [[CLLocation alloc] ...];
CLLocationCoordinate2D laxToJfkCoords[2] = {LAX.coordinate, JFK.coordinate};
CLLocationCoordinate2D jfkToLhrCoords[2] = {JFK.coordinate, LHR.coordinate};
MKGeodesicPolyline *laxToJfk = [MKGeodesicPolyline polylineWithCoordinates:laxToJfkCoords count:2];
MKGeodesicPolyline *jfkToLhr = [MKGeodesicPolyline polylineWithCoordinates:jfkToLhrCoords count:2];
[mapView addOverlay:laxToJfk];
[mapView addOverlay:jfkToLhr];
Run Code Online (Sandbox Code Playgroud)
我想用需要在rendererForOverlay委托方法中配置的不同样式来渲染这两个叠加层。
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay {
if (![overlay isKindOfClass:[MKPolyline class]]) {
return nil;
}
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:(MKPolyline *)overlay];
renderer.lineWidth = 3.0f;
// How to set different colors for LAX-JFK and JFK-LHR?
renderer.strokeColor = [UIColor blueColor];
return renderer;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是有哪些选项可以识别上述方法中的两个不同叠加层?
这是我目前考虑的:
MKGeodesicPolyline是通过静态工厂方法初始化的。overlay参数与这些参数进行比较。这确实有效,但感觉有点笨拙。此外,对于两个以上的叠加层,需要使用NSSet或扩展此方法NSArray。我还能做些什么来简化这个吗?似乎MKGeodesicPolyline没有任何可用于标记的属性。
| 归档时间: |
|
| 查看次数: |
264 次 |
| 最近记录: |