自定義飛行路線管理

超圖飛行管理是提前在桌面端定義好飛行路線,然後進行飛行,但是在業務中,有時候需要根據業務需要進行飛行,比如根據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);
	    });
	  });

 

發佈了31 篇原創文章 · 獲贊 4 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章