自定义飞行路线管理

5 篇文章 0 订阅

超图飞行管理是提前在桌面端定义好飞行路线,然后进行飞行,但是在业务中,有时候需要根据业务需要进行飞行,比如根据GPS取到的点进行实际路径飞行。实现思路:先定义一个空的飞行路径,也可以定义一个只包含一个点的飞行路径来进行定位。然后增加自定义站点,代码如下:

 

 var points = [
	        {
	        x: 116.71275583943516,
	    	y: 39.895403435720063,
	        z: -5,
	        altitude: -5.1428938554599881,
	        duration: 11.623106459071682,
	        heading: 0.260995919619558,
	            index:0
	        },
	        {x: 116.71261436907912,
	            y: 39.895686008451534,
	            z: -5,
	            altitude: -5.9814573479816318,
	            duration: 12.33481700746625,
	            heading: 0.0340212,
	            index: 1
	        },{
	            x: 116.71246024545442,
	            y: 39.895982950739153,
	            z: -5,
	            duration:10.964990729795865,
	            altitude: -5.5469268001616001,
	            heading: 0.23512687249191,
	            index: 2
	        },{
	            x: 116.71240014157664,
	            y: 39.896118795529922,
	            z: -5,
	            duration:11.157674687612483,
	            altitude: -4.2948793824762106,
	            heading: 0.205987951731911,
	            index: 3
	        },{
	            altitude: -5.673985555768013,
	            duration: 10,
	            heading: 0.038466827467274554,
	            index: 4,
	            x: 116.71217389893071,
	            y: 39.896766717130667,
	            z: -5
	        },{
	            x: 116.712101305757,
	            y: 39.897437426384997,
	            z: -5,
	            duration:11.157674687612483,
	            altitude: -4.2948793824762106,
	            heading: 0.205987951731911,
	            index: 3
	        }
	    ];


	  let routes = new Cesium.RouteCollection();
		var host = document.location.toString().match(/file:\/\//)?"http://localhost:8080":'http://' + document.location.host;
		var fpfUrl =host+test.fpf';
		routes.fromFile(fpfUrl);//添加飞行文件
		
	  Cesium.when(routes.readyPromise, () => {

	    var route = routes.get(0);
	    this.flyManager = new Cesium.FlyManager({scene: this.viewer.scene, routes: routes});
	    this.flyManager.stopArrived.addEventListener((routeStop) => {
//	      routeStop.waitTime = 3;//修改站点的停留时间
	      routeStop.tilt = 0;//站点俯仰角
//	      routeStop.heading = scene.camera.heading;//站点方位角
	      routeStop.altitude=-6;//站点高度
	      console.log("到达站点:"+routeStop.stopName+"方位角:"+scene.camera.heading);
	      console.log("到达站点:"+routeStop.stopName+"方位角:"+scene.camera.altitude);
	    });

//	    points.map(el => {
//	      route.addStop(el)
//	    });
//	    var points=data;
//	    points.sort(up);
//	    console.log(points);
	    
	    Cesium.when(this.flyManager.readyPromise, () => {
	    	  var allStops = this.flyManager.getAllRouteStops();
              var route = this.flyManager.currentRoute;
              var stop = route.get(0);
              this.flyManager.viewToStop(stop);
              this.flyManager.currentIndex=1;//飞行路线可以添加多个route,设置索引来加载不同的路线
              for(var k = 0; k < points.length ;k++){
                  var position = Cesium.Cartesian3.fromDegrees(parseFloat(points[k].x),parseFloat( points[k].y), parseFloat(points[k].z));
                  var name = "站" + k;
                  var routeStop = new Cesium.RouteStop({
                      point:position,
                      heading:scene.camera.heading,
                      tilt:0,
                      stopName:name,
//                      speed:23,
//                      waitTime: 5,
                      index:k,//points[k].index,
                      duration:3, //points[k].duration,
                      altitude:-20//points[k].altitude
                  })
                  console.log("相机方位角:"+scene.camera.heading);
              route.addStop(routeStop);
             }
              setTimeout(function(){
              	if(globe.globeAlpha<0.1){
              		this.flyManager.play();
              	}
              },7000);
	    });
	  });

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值