///////////////////////////////////////////////////////////////////////////
|
// 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,
|
startup: function startup() {
|
var self = this;
|
// this.inherited(arguments);
|
this.init();
|
|
$('.close-flyrouter').click(function () {
|
$('.jimu-widget-FlyRoute').hide();
|
self.flightTool.RouteCollection.removeAllSites();
|
$("#passPoint").empty();
|
});
|
},
|
|
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
|
url: 'http://sw797.com:82/blade-ycreal/flyroute/selectFname',
|
|
type: "POST",
|
dataType: "json",
|
success: function success(data) {
|
if (data.data.length == undefined) return;
|
// let datas = data.data;
|
self.allRoutes = data.data;
|
// if (data.code == 200) {
|
for (var i = 0; i < data.data.length; i++) {
|
$("#flightRoute").append('<option value = ' + data.data[i].flyname + ' > ' + data.data[i].flyname + ' </option>');
|
}
|
// }
|
|
|
// 初始加载默认路线
|
// $.ajax({
|
// url: 'http://sw797.com:82/blade-ycreal/flyroute/selectInfo?fnid=' + data.data[0].id,
|
// type: 'post',
|
// dataType: 'JSON',
|
// success: function (data) {
|
// self._loadRoute(data.data);
|
// }
|
// })
|
}
|
});
|
|
$("#flightRoute").on("change", function (e) {
|
var selectRoute = self.allRoutes.find(function (x) {
|
if (x.flyname == $("#flightRoute").val()) {
|
return x
|
}
|
});
|
|
$.ajax({
|
url: 'http://sw797.com:82/blade-ycreal/flyroute/selectInfo?fnid=' + selectRoute.id,
|
type: 'post',
|
dataType: 'JSON',
|
success: function (data) {
|
self._loadRoute(data.data);
|
}
|
})
|
|
});
|
|
//开始漫游
|
$("#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 = 3;
|
dataArr.push(data);
|
|
liDom.on('click', data, function (event) {
|
});
|
|
$('#passPoint').append(liDom);
|
|
self.flightTool.RouteCollection.AddSiteByView(id);
|
id++;
|
});
|
|
//导出路线
|
$("#export").click(function () {
|
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));
|
|
topic.subscribe("stopflays", lang.hitch(this, this.stopFlay));
|
},
|
|
_executeRoam: function _executeRoam(data) {
|
var that = this;
|
|
this.flightTool.flyManager.stop();
|
|
this.flightTool.RouteCollection.removeAllSites();
|
|
var selectRoute = this.allRoutes.find(function (x) {
|
if (x.flyname == data) {
|
return x
|
}
|
});
|
|
$.ajax({
|
url: 'http://sw797.com:82/blade-ycreal/flyroute/selectInfo?fnid=' + selectRoute.id,
|
type: 'post',
|
dataType: 'JSON',
|
success: function (data) {
|
for (var i = 0; i < data.data.length; i++) {
|
var cartesian3 = Cesium.Cartesian3.fromDegrees(data.data[i].lgtd, data.data[i].lttd, data.data[i].height + 10000000000);
|
var site = {
|
"ids": data.data[i].id,
|
"position_x": cartesian3.x,
|
"position_y": cartesian3.y,
|
"position_z": cartesian3.z,
|
"pitch": Cesium.Math.toRadians(data.data[i].pitch),
|
"heading": Cesium.Math.toRadians(data.data[i].heading),
|
"roll": Cesium.Math.toRadians(data.data[i].roll),
|
"time": data.data[i].time
|
};
|
that.flightTool.allSites[i] = site;
|
}
|
that.flightTool.flyManager.play();
|
|
|
}
|
})
|
|
|
},
|
|
_stopFlay: function _stopFlay(data) {
|
if (data) {
|
this.flightTool.flyManager.stop();
|
this.flightTool.RouteCollection.removeAllSites();
|
}
|
},
|
|
stopFlay: function stopFlay() {
|
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);
|
}
|
|
});
|
});
|