全部服务产品
开发者频道
定价
登录
绘制动态轨迹
下载开发文档
绘制动态轨迹简介

Since6.4.0起支持动态轨迹绘制,开发者可以提供轨迹数据,来动态展示轨迹。支持监听轨迹绘制状态。Since 6.5.6起iOS地图SDK动态轨迹支持渐变色绘制和.gltf+.bin模型加载,并支持动画播放。

绘制动态轨迹
1. 添加动态轨迹覆盖物数据
BMKTraceOverlay *traceOverlay = [BMKTraceOverlay traceOverlayWithCoordinates:_coords count:_coordsCount option:self.animationOption];
/// 是否使用渐变色轨迹
/// 注意:要配合strokeColors使用,否则无效
traceOverlay.isGradientColor = YES;
/// 是否使用发光轨迹
traceOverlay.isTrackBloom = YES;
traceOverlay.bloomSpeed = 5.0f;
traceOverlay.delegate = self;
[self.mapView addOverlay:traceOverlay];
/// 轨迹动画选项
- (BMKTraceOverlayOption *)animationOption {
if (!_animationOption) {
_animationOption = [[BMKTraceOverlayOption alloc] init];
_animationOption.animate = YES; // 是否动画
_animationOption.delay = 0.0; // 动画延迟开始时间
_animationOption.duration = 10.0; // 动画时间
_animationOption.fromValue = 0.0;
_animationOption.toValue = 1.0;
_animationOption.easingCurve = BMKTraceOverlayAnimationEasingCurveLinear;
_animationOption.trackMove = NO; // 是否跟踪轨迹动画(地图跟随移动)
_animationOption.pointMove = YES;
BMKTrace3DModelOption *option = [[BMKTrace3DModelOption alloc] init];
option.scale = 5;
option.modelName = @"scenes";
option.rotateX = 90;
option.rotateY = -90;
option.type = BMK3DModelTypeGLTF;
option.modelYawAxis = BMKTraceOverlay3DModelYawAxisY;
option.modelPath = [NSString stringWithFormat:@"%@/Model3D", [NSBundle mainBundle].bundlePath];
option.animationIsEnable = YES;
option.animationSpeed = 1;
option.animationRepeatCount = 0;
option.animationIndex = 1;
_animationOption.modelOption = option;
}
return _animationOption;
}
2. 实现代理方法生成对应的view(BMKTraceOverlayView)
#pragma mark - <BMKMapViewDelegate>
- (__kindof BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay {
if ([overlay isKindOfClass:[BMKTraceOverlay class]]) {
BMKTraceOverlayView *polylineView = [[BMKTraceOverlayView alloc] initWithTraceOverlay:overlay];
/// 纯色
// polylineView.strokeColor = [UIColor blueColor];
// polylineView.fillColor = [UIColor blueColor];
/// 渐变色颜色
/// 注意:strokeColors 长度与轨迹点的个数必须保持一致
polylineView.strokeColors = [_colors copy];
polylineView.lineWidth = 8.0;
return polylineView;
}
return nil;
}
3. 轨迹暂停和继续

自v6.5.9起支持轨迹暂停和继续

// 暂停轨迹动画绘制
[self.traceOverlay pauseTraceOverlayDraw];
// 继续轨迹动画绘制
[self.traceOverlay resumeTraceOverlayDraw];
4. 运行程序

效果如下:

上一篇

绘制3D模型

下一篇

文字覆盖物

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