所谓路径漫游:即创建一个动态对象和一条由多点组成的线,然后让动态对象沿着线飞行
首先绘制一条线,实际上路径漫游是不需要绘制线的,我这里只是为了确认动态对象是否沿着线路在飞行,代码如下:
//绘制路径 double[] cVerticesArray = null; cVerticesArray = new double[] { 116.35, 27.98, 0, 116.45, 28.98, 0, 116.45, 28.11, 0, 116.65, 28.45, 0, }; ILineString pILineString = sgWorld.Creator.GeometryCreator.CreateLineStringGeometry(cVerticesArray); IColor66 color = sgWorld.Creator.CreateColor(255, 0, 0, 125); var polyline = sgWorld.Creator.CreatePolyline(pILineString, color);
接下来创建动态对象,代码如下:
var dynamicObject = this.sgWorld.Creator.CreateDynamicObject(0, DynamicMotionStyle.MOTION_GROUND_VEHICLE, DynamicObjectType.DYNAMIC_IMAGE_LABEL, @"F:\项目管理\智慧抚州\使用的Fly\data11\汽车图标\整车.png", 50, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, "", "动态对象");
参数说明:
第一个参数0:一组 IRouteWaypoint66对象,后续向动态对象中添加
第二个参数DynamicMotionStyle:移动方式,是一个枚举类型,具体的效果大家可以去试一下
第三个参数DynamicObjectType:动态对象类型,是一个枚举类型,该参数也决定了你第四个参数的文件类型
第四个参数:由于第三个参数选择的Image_label,这里我选择了一张图片
第五个参数50:文件缩放大小
第六个参数AltitudeTypeCode:高度模式
动态对象创建完成之后就是创建路径的拐点,代码如下:
var wayPoint1 = this.sgWorld.Creator.CreateRouteWaypoint(116.35, 27.98, 0, 2000); var wayPoint2 = this.sgWorld.Creator.CreateRouteWaypoint(116.45, 28.98, 0, 2000); var wayPoint3 = this.sgWorld.Creator.CreateRouteWaypoint(116.55, 28.11, 0, 800); var wayPoint4 = this.sgWorld.Creator.CreateRouteWaypoint(116.65, 28.45, 0, 800);
然后将拐点添加到动态对象中:
dynamicObject.Waypoints.AddWaypoint(wayPoint1); dynamicObject.Waypoints.AddWaypoint(wayPoint2); dynamicObject.Waypoints.AddWaypoint(wayPoint3); dynamicObject.Waypoints.AddWaypoint(wayPoint4); dynamicObject.CircularRoute = false; dynamicObject.RestartRoute(0);
最后调用飞行到对象,就可以实现路径漫游效果:
sgWorld.Navigate.FlyTo(dynamicObject.ID, ActionCode.AC_JUMP);