///////////////////////////////////////////////////////////////////////////
|
// Copyright © 2020 zhongsong. All Rights Reserved.
|
// 模块描述:飞行路线
|
///////////////////////////////////////////////////////////////////////////
|
define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', 'dojo/_base/html', 'dojo/topic', 'jimu/BaseWidget', './fly', './FileSaver'], function (declare, lang, array, html, topic, BaseWidget) {
|
return declare([BaseWidget], {
|
baseClass: 'jimu-widget-FlyRoute',
|
name: 'FlyRoute',
|
flightTool: null,
|
allRoutes: null,
|
flag: false,
|
startup: function startup() {
|
topic.subscribe("openFlyRoute", lang.hitch(this, this.openFlyRoute));
|
topic.subscribe("closeFlyRoute", lang.hitch(this, this.closeFlyRoute));
|
var self = this;
|
// this.inherited(arguments);
|
|
|
$('.close-flyrouter').click(function () {
|
self.closeFlyRoute('FlyRoute');
|
$('.jimu-widget-visualAngle').find('.v-a-Two').removeClass('on');//清楚样式
|
topic.publish('closeFly', 'closeFly');
|
});
|
},
|
|
init: function init(evt) {
|
var self = this;
|
//实例化飞行工具
|
self.flightTool = new Fly_NZC(self.map);
|
|
//获取全部路线数据
|
$.ajax({
|
url: "./widgets/FlyRoute/flyroute.json",
|
// http://sw797.com:82/blade-ycreal/flyroute/detail?id=1
|
// type: "POST",
|
dataType: "json",
|
success: function success(data) {
|
if (data.length == undefined) return;
|
// let datas = data.data;
|
self.allRoutes = data;
|
|
$("#flightRoute").empty();
|
$('#passPoint').empty();
|
|
// if (data.code == 200) {
|
for (var i = 0; i < data.length; i++) {
|
$("#flightRoute").append('<option value = ' + data[i].name + ' > ' + data[i].name + ' </option>');
|
}
|
// }
|
|
|
self._loadRoute(self.allRoutes[0].sites);
|
|
$("#flightRoute").on("change", function (e) {
|
var selectRoute = self.allRoutes.find(function (x) {
|
return x.name == $("#flightRoute").val();
|
});
|
self._loadRoute(selectRoute.sites);
|
});
|
|
//初始加载默认路线
|
//self._loadRoute(self.allRoutes[0].sites);
|
}
|
});
|
|
//开始漫游
|
$("#ks").click(function () {
|
self.flightTool.flyManager.play();
|
});
|
//暂停漫游
|
$("#zt").click(function () {
|
self.flightTool.flyManager.pause();
|
});
|
//停止漫游
|
$("#tz").click(function () {
|
self.flightTool.flyManager.stop();
|
});
|
//删除路线
|
$("#detele").click(function () {
|
self.flightTool.RouteCollection.removeAllSites();
|
$("#passPoint").empty();
|
});
|
|
//绘制路线
|
var dataArr = [],
|
id = 0;
|
$("#add").click(function () {
|
var liStr = "<li class='item'>途径点" + ($("#passPoint").children().length + 1) + "</li>";
|
var liDom = $(liStr);
|
|
var camera = self.map.scene.camera;
|
|
var cartographic = Cesium.Cartographic.fromCartesian(camera.position);
|
var lat = Cesium.Math.toDegrees(cartographic.latitude);
|
var lng = Cesium.Math.toDegrees(cartographic.longitude);
|
var height = cartographic.height;
|
|
var data = {};
|
data.id = id;
|
data.lgtd = lng;
|
data.lttd = lat;
|
data.height = height;
|
data.heading = Cesium.Math.toDegrees(camera.heading);
|
data.pitch = Cesium.Math.toDegrees(camera.pitch);
|
data.roll = Cesium.Math.toDegrees(camera.roll);
|
data.time = null;
|
dataArr.push(data);
|
|
liDom.on('click', data, function (event) {
|
});
|
|
$('#passPoint').append(liDom);
|
|
self.flightTool.RouteCollection.AddSiteByView(id);
|
id++;
|
});
|
|
//导出路线
|
$("#export").click(function () {
|
for (var i = 0; i < dataArr.length - 1; i++) {
|
var a = Cesium.Cartesian3.fromDegrees(dataArr[i].lgtd, dataArr[i].lttd, dataArr[i].height);
|
var b = Cesium.Cartesian3.fromDegrees(dataArr[i + 1].lgtd, dataArr[i + 1].lttd, dataArr[i + 1].height);
|
var c = self.getSpaceDistance([a, b]);
|
dataArr[i].time = c;
|
}
|
|
var data = {
|
name: $('#routeName').val(),
|
sites: dataArr
|
};
|
var content = JSON.stringify(data);
|
var blob = new Blob([content], {
|
type: "text/plain;charset=utf-8"
|
});
|
saveAs(blob, "save.json");
|
dataArr = [];
|
});
|
|
topic.subscribe("autoRoam", lang.hitch(this, this._executeRoam));
|
|
topic.subscribe("stopflay", lang.hitch(this, this._stopFlay));
|
},
|
|
openFlyRoute: function (item) {
|
if (item == this.name) {
|
this.flag = true;
|
this.init();
|
$('.jimu-widget-FlyRoute').show();
|
}
|
},
|
|
closeFlyRoute: function (item) {
|
var self = this;
|
if (item == this.name && this.flag == true) {
|
this.flag = false;
|
$('.jimu-widget-FlyRoute').hide();
|
$('.jimu-widget-visualAngle .v-a-One').addClass('on').siblings().removeClass('on');
|
self.flightTool.flyManager.stop();
|
self.flightTool.RouteCollection.removeAllSites();
|
}
|
},
|
|
//空间两点距离计算函数
|
getSpaceDistance: function getSpaceDistance(positions) {
|
var distance = 0;
|
for (var i = 0; i < positions.length - 1; i++) {
|
|
var point1cartographic = Cesium.Cartographic.fromCartesian(positions[i]);
|
var point2cartographic = Cesium.Cartographic.fromCartesian(positions[i + 1]);
|
/**根据经纬度计算出距离**/
|
var geodesic = new Cesium.EllipsoidGeodesic();
|
geodesic.setEndPoints(point1cartographic, point2cartographic);
|
var s = geodesic.surfaceDistance;
|
//返回两点之间的距离
|
s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
|
distance = distance + s;
|
}
|
return (distance / 70);
|
},
|
|
_executeRoam: function _executeRoam(data) {
|
this.flightTool.flyManager.stop();
|
this.flightTool.RouteCollection.removeAllSites();
|
var selectRoute = this.allRoutes.find(function (x) {
|
return x.name == data;
|
});
|
for (var i = 0; i < selectRoute.sites.length; i++) {
|
var cartesian3 = Cesium.Cartesian3.fromDegrees(selectRoute.sites[i].lgtd, selectRoute.sites[i].lttd, selectRoute.sites[i].height);
|
var site = {
|
"ids": selectRoute.sites[i].id,
|
"position_x": cartesian3.x,
|
"position_y": cartesian3.y,
|
"position_z": cartesian3.z,
|
"pitch": Cesium.Math.toRadians(selectRoute.sites[i].pitch),
|
"heading": Cesium.Math.toRadians(selectRoute.sites[i].heading),
|
"roll": Cesium.Math.toRadians(selectRoute.sites[i].roll),
|
"time": selectRoute.sites[i].time
|
};
|
this.flightTool.allSites[i] = site;
|
}
|
this.flightTool.flyManager.play();
|
},
|
|
_stopFlay: function _stopFlay(data) {
|
if (data) {
|
this.flightTool.flyManager.stop();
|
this.flightTool.RouteCollection.removeAllSites();
|
}
|
},
|
|
_loadRoute: function _loadRoute(route) {
|
var self = this;
|
$("#passPoint").empty();
|
self.flightTool.RouteCollection.AddRoute(route);
|
for (var j = 0; j < route.length; j++) {
|
var liStr = "<li class='item'>途径点" + (j + 1) + "</li>";
|
var liDom = $(liStr);
|
liDom.on('click', route[j], function (event) {
|
var site = self.flightTool.RouteCollection.getSiteByIndex(event.data.id);
|
self.flightTool.flyManager.viewToSite(site);
|
});
|
$('#passPoint').append(liDom);
|
}
|
},
|
|
onOpen: function onOpen() {
|
//面板打开的时候触发 (when open this panel trigger)
|
},
|
|
onClose: function onClose() {
|
//面板关闭的时候触发 (when this panel is closed trigger)
|
},
|
|
onMinimize: function onMinimize() {
|
this.resize();
|
},
|
|
onMaximize: function onMaximize() {
|
this.resize();
|
},
|
|
resize: function resize() { },
|
|
destroy: function destroy() {
|
//销毁的时候触发
|
//todo
|
//do something before this func
|
this.inherited(arguments);
|
}
|
|
});
|
});
|