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-filyL',
|
name: 'filyL',
|
flightTool: null,
|
allRoutes: null,
|
flag: false,
|
startup: function () {
|
var that = this;
|
topic.subscribe("beginfilyL", lang.hitch(this, this.beginfilyL));
|
topic.subscribe("closesfilyL", lang.hitch(this, this.closesfilyL));
|
// topic.publish('getbeginSlope', that.beginSlope);
|
$(`.${that.baseClass}`).find('.closeOUR').click(() => {
|
$(`.${that.baseClass}`).hide();
|
that.closesfilyL();
|
})
|
|
|
// that.beginfilyL();
|
|
|
|
},
|
beginfilyL: function () {
|
console.log(`${this.name}--kaishi`);
|
var that = this;
|
var viewer = that.map;
|
//飞机飞行
|
this.flag = true;
|
this.init();
|
|
},
|
init: function init(evt) {
|
var self = this;
|
var that = this;
|
var viewer = that.map
|
, scene = viewer.scene;
|
//实例化飞行工具
|
self.flightTool = new Fly_NZC(self.map);
|
|
//获取全部路线数据
|
$.ajax({
|
url: "./widgets/filyL/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;
|
|
$("#flightRoutefilyL").empty();
|
$('#passPointfilyL').empty();
|
|
// if (data.code == 200) {
|
for (var i = 0; i < data.length; i++) {
|
$("#flightRoutefilyL").append('<option value = ' + data[i].name + ' > ' + data[i].name + ' </option>');
|
}
|
// }
|
|
|
self._loadRoute(self.allRoutes[0].sites);
|
|
$("#flightRoutefilyL").on("change", function (e) {
|
var selectRoute = self.allRoutes.find(function (x) {
|
return x.name == $("#flightRoutefilyL").val();
|
});
|
self._loadRoute(selectRoute.sites);
|
});
|
|
//初始加载默认路线
|
//self._loadRoute(self.allRoutes[0].sites);
|
}
|
});
|
|
//开始漫游
|
$("#ksfilyL").click(function () {
|
self.flightTool.flyManager.play();
|
});
|
//暂停漫游
|
$("#ztfilyL").click(function () {
|
self.flightTool.flyManager.pause();
|
});
|
//停止漫游
|
$("#tzfilyL").click(function () {
|
self.flightTool.flyManager.stop();
|
});
|
//删除路线
|
$("#detelefilyL").click(function () {
|
self.flightTool.RouteCollection.removeAllSites();
|
|
$("#passPointfilyL").empty();
|
});
|
|
//绘制路线
|
// var pointHandler = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);//添加鼠标点事件
|
var dataArr = [],
|
id = 3;
|
|
// pointHandler.drawEvt.addEventListener(function (result) {
|
|
// });
|
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
|
|
$("#addfilyL").click(function () {
|
var liStr = "<li class='item'>途径点" + ($("#passPointfilyL").children().length + 1) + "</li>";
|
var liDom = $(liStr);
|
var lat = 0;
|
var lng = 0;
|
var height = 0;
|
// 鼠标移动时间回调
|
handler.setInputAction(function (e) {
|
// 若此标记为false,则激活对可视域分析对象的操作
|
// console.log(e,1213486)
|
// //获取鼠标屏幕坐标,并将其转化成笛卡尔坐标
|
var position = e.endPosition;
|
var last = scene.pickPosition(position);
|
console.log(position, 'position')
|
// 将鼠标当前点坐标转化成经纬度
|
// var cartographic = Cesium.Cartographic.fromCartesian(last);
|
// lat = Cesium.Math.toDegrees(cartographic.longitude);
|
// lng = Cesium.Math.toDegrees(cartographic.latitude);
|
// height = cartographic.height;
|
var ray = viewer.camera.getPickRay(position);
|
var cartesian = viewer.scene.globe.pick(ray, viewer.scene);
|
// console.log(cartesian, 'cartesian')
|
|
lat = cartesian.y;
|
lng = cartesian.x;
|
height = cartesian.z;
|
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
// 鼠标左键时间回调
|
handler.setInputAction(function (e) {
|
var data = {};
|
data.ids = id;
|
data.position_x = lng;
|
data.position_y = lat;
|
data.position_z = height + 10;
|
data.heading = 0;
|
data.pitch = -1;
|
data.roll = 0;
|
// data.heading = 6.108652381980;
|
// data.pitch = -0.653625804871;
|
// data.roll = 0;
|
data.time = 10;
|
dataArr.push(data);
|
// console.log(dataArr, 'dataArr');
|
// console.log(id, 'id')
|
|
self.flightTool.RouteCollection.AddSite(data);
|
// console.log(id, 'id2')
|
liDom.on('click', data, function (event) {
|
// console.log(event)
|
var site = self.flightTool.RouteCollection.getSiteByIndex(event.data.id);
|
self.flightTool.flyManager.viewToSite(data);
|
});
|
|
$('#passPointfilyL').append(liDom);
|
self.flightTool.RouteCollection.AddSiteByView(id);
|
id++;
|
handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
|
// var liStr = "<li class='item'>途径点" + ($("#passPointfilyL").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.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) {
|
// });
|
|
// $('#passPointfilyL').append(liDom);
|
|
// self.flightTool.RouteCollection.AddSiteByView(id);
|
// id++;
|
});
|
//视角固定
|
$("#openViewL").click(function () {
|
self.flightTool.flyManager.openView();
|
})
|
//导出路线
|
$("#exportfilyL").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: $('#routeNamefilyL').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));
|
},
|
|
closesfilyL: function (froms) {
|
console.log(`${this.name}--guanbi`);
|
// var that = this;
|
|
var self = this;
|
if (item == this.name && this.flag == true) {
|
this.flag = false;
|
// $('.jimu-widget-filyL').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) {
|
console.log(route)
|
var self = this;
|
$("#passPointfilyL").empty();
|
self.flightTool.RouteCollection.AddRoute(route);
|
for (var j = 0; j < route.length; j++) {
|
var liStr = "<li class='item'>q途径点" + (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);
|
});
|
$('#passPointfilyL').append(liDom);
|
}
|
},
|
onOpen: function () {
|
|
},
|
|
onClose: function () {
|
//面板关闭的时候触发 (when this panel is closed trigger)
|
console.log('jies')
|
},
|
|
onMinimize: function () {
|
this.resize();
|
},
|
|
onMaximize: function () {
|
this.resize();
|
},
|
|
resize: function () {
|
|
},
|
|
destroy: function () {
|
//销毁的时候触发
|
//todo
|
//do something before this func
|
this.inherited(arguments);
|
}
|
|
});
|
});
|