Since6.4.0起iOS地图SDK支持3D棱柱(BMKPrismOverlay)绘制。提供一组多边形有序序列的点,根据序列点和高度生成3D棱柱。
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"haidian" ofType:@"txt"];NSString *pointsString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];NSArray<NSString *> *pointsArray = [pointsString componentsSeparatedByString:@"\n"];BMKMapPoint points[pointsArray.count];for (NSUInteger i = 0; i < pointsArray.count; ++i) {if ([pointsArray[i] rangeOfString:@","].location != NSNotFound) {NSArray<NSString *> *tmpPoints = [pointsArray[i] componentsSeparatedByString:@","];points[i] = BMKMapPointMake([tmpPoints.firstObject doubleValue], [tmpPoints.lastObject doubleValue]);}}BMKPrismOverlay *_prism = [BMKPrismOverlay prismOverlayWithPoints:points count:pointsArray.count];_prism.height = 1000.f;[_mapView addOverlay:_prism];
- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay {if ([overlay isKindOfClass:[BMKPrismOverlay class]]) {BMKPrismOverlayView *prismOverlayView = [[BMKPrismOverlayView alloc] initWithPrismOverlay:(BMKPrismOverlay *)overlay];if ([overlay isEqual:_prismOverlay]) {prismOverlayView.sideFaceColor = [UIColor colorWithRed:0 green:0 blue:0.5 alpha:1.0];prismOverlayView.topFaceColor = [UIColor colorWithRed:0.0 green:0 blue:0.5 alpha:0.4];return prismOverlayView;}return nil;}return nil;}
效果如下:
上一篇
下一篇
本篇文章对您是否有帮助?