浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。
更新时间:2021-09-20
绘制3D棱柱简介

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

3D棱柱
1添加3D棱柱覆盖物数据
Objective-C
Swift
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];
 let filePath = Bundle.main.path(forResource: "haidian", ofType: "txt")
        let pointsString = try? String(contentsOfFile: filePath!)
        
        let pointsArray = pointsString?.components(separatedBy: "\n")
        
        var points = [BMKMapPoint](repeating: BMKMapPoint(x: 0, y: 0), count: pointsArray!.count)
        for index in 0..<pointsArray!.count {
        let coordinates = pointsArray![index].components(separatedBy: ",")
            let first: String = coordinates.first!
            let last: String = coordinates.last!
            points[index] = BMKMapPointMake(Double(first)!, Double(last)!)
        }
        
        let prism = BMKPrismOverlay(points: &points, count: UInt(Int(pointsArray!.count)))
        prism.height = 1000.0
mapView.add(prism)
2实现代理方法生成对应的view(BMKPrismOverlayView)
Objective-C
Swift
- (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;
}

func mapView(_ mapView: BMKMapView!, viewFor overlay: BMKOverlay!) -> BMKOverlayView! {
        if overlay.isKind(of: BMKPrismOverlay.self) {
            let priseOverlayView = BMKPrismOverlayView(prismOverlay: overlay as! BMKPrismOverlay)
            priseOverlayView.sideFaceColor = UIColor.init(red: 0, green: 0, blue: 0.5, alpha: 1)
            priseOverlayView.topFaceColor = UIColor.init(red: 0, green: 0, blue: 0.5, alpha: 0.4)

            return priseOverlayView
        }
        return nil
    }

3运行程序
效果如下:

3dprism_1.png

  • 文档根本没法用

  • 文档水平很差

  • 文档水平一般

  • 文档不错

  • 文档写的很好

如发现文档错误,或对此文档有更好的建议,请在下方反馈。问题咨询请前往反馈平台提交工单咨询。

提交反馈

拖动标注工具

添加矩形标注

添加箭头标注

完成

取消