全部服务产品
开发者频道
定价
登录
绘制3D棱柱
下载开发文档
绘制3D棱柱简介

Since6.4.0起iOS地图SDK支持3D棱柱(BMKPrismOverlay)绘制。提供一组多边形有序序列的点,根据序列点和高度生成3D棱柱。

3D棱柱绘制
1. 添加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];
2. 实现代理方法生成对应的view(BMKPrismOverlayView)
- (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;
}
3. 运行程序

效果如下:

3dprism_1.png

上一篇

OpenGL绘制

下一篇

绘制3D建筑物

本篇文章对您是否有帮助?