define([
|
'dojo/_base/declare',
|
'dojo/_base/lang',
|
'dojo/_base/array',
|
'dojo/_base/html',
|
'dojo/topic',
|
'jimu/BaseWidget',
|
],
|
function (declare,
|
lang,
|
array,
|
html,
|
topic,
|
BaseWidget
|
) {
|
return declare([BaseWidget], {
|
baseClass: 'jimu-widget-throughSee',
|
name: 'throughSee',
|
flag: false,
|
startup: function () {
|
var that = this;
|
topic.subscribe("beginthroughSee", lang.hitch(this, this.beginthroughSee));
|
topic.subscribe("closesthroughSee", lang.hitch(this, this.closesthroughSee));
|
// topic.publish('getbeginSlope', that.beginSlope);
|
$(`.${that.baseClass}`).find('.closeOUR').click(() => {
|
$(`.${that.baseClass}`).hide();
|
that.closesthroughSee();
|
})
|
|
|
// that.beginthroughSee();
|
|
},
|
beginthroughSee: function () {
|
console.log(`${this.name}--kaishi`);
|
var that = this;
|
|
var viewer = that.map;
|
|
if (!viewer.scene.pickPositionSupported) {
|
alert('不支持深度纹理,通视分析功能无法使用(无法添加观测点目标点)!');
|
}
|
$("#toolbarthroughSee").show();
|
$('#loadingbar').remove();
|
var scene = viewer.scene;
|
scene.shadowMap.darkness = 1.275; //设置第二重烘焙纹理的效果(明暗程度)
|
scene.skyAtmosphere.brightnessShift = 0.4; //修改大气的亮度
|
scene.debugShowFramesPerSecond = false;
|
scene.hdrEnabled = false;
|
scene.sun.show = false;
|
// 01设置环境光的强度-新处理CBD场景
|
scene.lightSource.ambientLightColor = new Cesium.Color(0.65, 0.65, 0.65, 1);
|
// 添加光源
|
var position1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531, 480);
|
//光源方向点
|
|
var targetPosition1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531, 430);
|
var dirLightOptions = {
|
targetPosition: targetPosition1,
|
color: new Cesium.Color(1.0, 1.0, 1.0, 1),
|
intensity: 0.55
|
};
|
directionalLight_1 = new Cesium.DirectionalLight(position1, dirLightOptions);
|
scene.addLightSource(directionalLight_1);
|
var sightline = new Cesium.Sightline(scene);
|
|
var widget = viewer.cesiumWidget;
|
// try {
|
|
// var promise = scene.open(window.MYURL_CONFIG.SCENE_CBD);
|
// Cesium.when.all(promise, function (layer) {
|
// scene.camera.setView({
|
// destination: new Cesium.Cartesian3.fromDegrees(116.44621857300415, 39.899281526734555, 216.7793905027196),
|
// orientation: {
|
// heading: 0.41348036210986194,
|
// pitch: -0.13636490404291735,
|
// roll: 6.283185307179563
|
// }
|
// });
|
// for (var i = 0; i < layer.length; i++) {
|
// layer[i].selectEnabled = false;
|
// }
|
|
sightline.build();
|
// }, function (e) {
|
// if (widget._showRenderLoopErrors) {
|
// var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
|
// widget.showErrorPanel(title, undefined, e);
|
// }
|
// });
|
// } catch (e) {
|
// if (widget._showRenderLoopErrors) {
|
// var title = '渲染时发生错误,已停止渲染。';
|
// widget.showErrorPanel(title, undefined, e);
|
// }
|
// }
|
|
|
var addViewFlag = false;//当前点击状态是否是 添加观察点
|
var addTargetFlag = false;//当前点击状态是否是 添加目标点
|
var mv = false;//当前点击状态是否是 添加观察点
|
var tf = false;//当前点击状态是否是 添加目标点
|
|
var num = 0;//添加的目标点的点号
|
that.couldRemove = false;//是否能移除目标点
|
that.tooltip = window.MYcreateTooltip(viewer._element)
|
var handlerPoint = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
|
handlerPoint.drawEvt.addEventListener(function (result) {
|
//添加观察点
|
if (addViewFlag) {
|
var point = result.object;
|
// point.show = false;
|
var position = result.object.position;
|
|
//将获取的点的位置转化成经纬度
|
var cartographic = Cartesian2toDegrees(position);
|
|
//设置观察点
|
sightline.viewPosition = cartographic;
|
addViewFlag = false;
|
}
|
handlerPoint.deactivate();
|
});
|
|
|
|
|
that.handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
|
|
document.getElementById("addViewPointthroughSee").onclick = function () {
|
if (tf == false) {
|
addViewFlag = true;
|
|
if (handlerPoint.active) {
|
return;
|
}
|
viewer.entities.removeAll();
|
if (that.couldRemove) {
|
sightline.removeAllTargetPoint();
|
}
|
handlerPoint.activate();
|
that.handler.setInputAction(function (evt) {
|
|
//鼠标移动,更新最后一次添加的目标点的位置
|
var position = scene.pickPosition(evt.endPosition);
|
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
if (addViewFlag || addTargetFlag) {
|
viewer.enableCursorStyle = false;
|
viewer._element.style.cursor = '';
|
$('body').removeClass('drawCur').addClass('drawCur');
|
}
|
//鼠标移动事件,更新点
|
that.handler.setInputAction(function (evt) {
|
that.tooltip.showAt(evt.endPosition, '<p>点击确定观察点</p>');
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
//鼠标点击事件,添加点
|
that.handler.setInputAction(function (e) {
|
$('body').removeClass('drawCur');
|
mv = true;
|
that.tooltip.setVisible(false);
|
that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
} else {
|
layer.tips('正在添加目标点,请先右键关闭', $('#addViewPointthroughSee'), { tips: [1, 'red'] });
|
}
|
}
|
|
|
document.getElementById("addTargetPointthroughSee").onclick = function () {
|
if (mv) {
|
addViewFlag = false;
|
addTargetFlag = true;
|
tf = true;
|
if (addViewFlag || addTargetFlag) {
|
viewer.enableCursorStyle = false;
|
viewer._element.style.cursor = '';
|
$('body').removeClass('drawCur').addClass('drawCur');
|
}
|
|
//鼠标点击事件,添加点
|
that.handler.setInputAction(function (e) {
|
var position = scene.pickPosition(e.position);
|
addTarget(position);
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
//鼠标移动事件,更新点
|
that.handler.setInputAction(function (evt) {
|
|
//鼠标移动,更新最后一次添加的目标点的位置
|
var position = scene.pickPosition(evt.endPosition);
|
|
if (num > 0) {
|
sightline.removeTargetPoint("point0");
|
|
var cartographic = Cartesian2toDegrees(position);
|
|
var flag = sightline.addTargetPoint({
|
position: cartographic,
|
name: "point0"
|
});
|
}
|
that.tooltip.showAt(evt.endPosition, '<p>点击确定目标点右键结束</p>');
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
//鼠标右键事件,结束
|
that.handler.setInputAction(function () {
|
viewer.enableCursorStyle = true;
|
$('body').removeClass('drawCur');
|
that.tooltip.setVisible(false);
|
that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
tf = false;
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
} else {
|
layer.tips('未添加观察点', $('#addTargetPointthroughSee'), { tips: [1, 'red'] });
|
}
|
};
|
|
document.getElementById("clearthroughSee").onclick = function () {
|
if (tf == false) {
|
addViewFlag = false;
|
addTargetFlag = false;
|
mv = false;
|
tf = false;
|
handlerPoint.clear();
|
that.tooltip.setVisible(false);
|
viewer.entities.removeAll();
|
that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
if (that.couldRemove) {
|
sightline.removeAllTargetPoint();
|
that.couldRemove = false;
|
}
|
viewer.enableCursorStyle = true;
|
$('body').removeClass('drawCur');
|
} else {
|
layer.tips('正在添加目标点,请先右键关闭', $('#clearthroughSee'), { tips: [1, 'red'] });
|
|
}
|
}
|
|
|
|
|
//添加通视点
|
function addTarget(CartesianPosition) {
|
if (addViewFlag === false && addTargetFlag) {
|
num += 1;
|
//将获取的点的位置转化成经纬度
|
var cartographic = Cartesian2toDegrees(CartesianPosition);
|
//添加目标点
|
var name = "point" + num;
|
var flag = sightline.addTargetPoint({
|
position: cartographic,
|
name: name
|
});
|
that.couldRemove = true;
|
}
|
}
|
|
//笛卡尔转换为经纬度
|
function Cartesian2toDegrees(position) {
|
var cartographic = Cesium.Cartographic.fromCartesian(position);
|
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
var height = cartographic.height;
|
|
return [longitude, latitude, height];
|
}
|
|
// that.promise = promise;
|
that.addViewFlag = addViewFlag;
|
that.addTargetFlag = addTargetFlag;
|
that.handlerPoint = handlerPoint;
|
that.sightline = sightline;
|
|
},
|
// promise: '',
|
addViewFlag: '',
|
addTargetFlag: '',
|
couldRemove: '',
|
sightline: '',
|
tooltip: '',
|
handler: '',
|
handlerPoint: '',
|
closesthroughSee: function (froms) {
|
console.log(`${this.name}--guanbi`);
|
that = this;
|
|
// Cesium.when.all(that.promise, function (layer) {
|
// for (var i = 0; i < layer.length; i++) {
|
// that.map.scene.layers.remove(layer[i].name)
|
// }
|
// })
|
if (that.handler.removeInputAction) {
|
that.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
that.handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
}
|
if (that.tooltip.setVisible) {
|
that.tooltip.setVisible(false);
|
}
|
if (that.handlerPoint.clear) {
|
that.handlerPoint.clear();
|
}
|
that.addViewFlag = false;
|
that.addTargetFlag = false;
|
|
that.map.entities.removeAll();
|
if (that.couldRemove) {
|
that.sightline.removeAllTargetPoint();
|
that.couldRemove = false;
|
}
|
that.map.enableCursorStyle = true;
|
$('body').removeClass('drawCur');
|
},
|
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);
|
}
|
|
});
|
});
|