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

since6.4.0起支持动态轨迹绘制,开发者可以提供轨迹数据,来动态展示轨迹。支持监听轨迹绘制状态。

绘制动态轨迹
1添加动态轨迹覆盖物数据
Objective-C
Swift
// 添加动态轨迹overlay
    BMKTraceOverlay *traceOverlay = [BMKTraceOverlay traceOverlayWithCoordinates:_coords count:_coordsCounts option:self.animationOption];
    traceOverlay.delegate = self;
    [self.mapView addOverlay:traceOverlay];
// 设置动画参数
- (BMKTraceOverlayOption *)animationOption {
    if (!_animationOption) {
        _animationOption = [[BMKTraceOverlayOption alloc] init];
        _animationOption.animate = YES;
        _animationOption.delay = 0.0;
        _animationOption.duration = 3.0;
        _animationOption.fromValue = 0.0;
        _animationOption.toValue = 1.0;
        _animationOption.easingCurve = BMKTraceOverlayAnimationEasingCurveLinear;
        _animationOption.trackMove = YES;
//        _animationOption.pointMove = YES;
    }
    return _animationOption;
}

/// 轨迹图层
    lazy var traceOverlay: BMKTraceOverlay = {
        let overlay = BMKTraceOverlay(coordinates: &coords, count: coordsCount, option: traceOverlayOption)
        overlay.delegate = self
        return overlay
    }()
    
    /// 轨迹动画选项
    lazy var traceOverlayOption: BMKTraceOverlayOption = {
        let option = BMKTraceOverlayOption()
        option.duration = 3.0
        option.easingCurve = .linear
        option.trackMove = true // 是否跟踪轨迹动画,地图跟随移动
        
        return option
    }()
 /// 添加 traceOverlay
            mapView.add(traceOverlay)

2实现代理方法生成对应的view(BMKTraceOverlayView)
Objective-C
Swift
- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay {


    if ([overlay isKindOfClass:[BMKTraceOverlay class]]) {
        BMKTraceOverlayView *traceOverlayView = [[BMKTraceOverlayView alloc] initWithTraceOverlay:overlay];
        traceOverlayView.strokeColor = [UIColor blueColor];
        traceOverlayView.fillColor = [UIColor blueColor];
        traceOverlayView.lineWidth = 8.0;
        return traceOverlayView;
    }
    
    return nil;
}

  func mapView(_ mapView: BMKMapView!, viewFor overlay: BMKOverlay!) -> BMKOverlayView! {
        let traceOverlayView = BMKTraceOverlayView(overlay: overlay)
        traceOverlayView?.fillColor = UIColor.blue
        traceOverlayView?.strokeColor = UIColor.blue
        traceOverlayView?.lineWidth = 8
        
        return traceOverlayView
    }

3运行程序
效果如下:
  • https://mapopen-pub-iossdk.bj.bcebos.com/map/video/dynamictory_video_2.mov
  • 文档根本没法用

  • 文档水平很差

  • 文档水平一般

  • 文档不错

  • 文档写的很好

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

提交反馈

拖动标注工具

添加矩形标注

添加箭头标注

完成

取消