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-BOXTailoring',
|
name: 'BOXTailoring',
|
flag: false,
|
startup: function () {
|
var that = this;
|
topic.subscribe("beginBOXTailoring", lang.hitch(this, this.beginBOXTailoring));
|
topic.subscribe("closesBOXTailoring", lang.hitch(this, this.closesBOXTailoring));
|
// topic.publish('getbeginSlope', that.beginSlope);
|
$(`.${that.baseClass}`).find('.closeOUR').click(() => {
|
$(`.${that.baseClass}`).hide();
|
that.closesBOXTailoring();
|
})
|
// 设置滑块,体验感
|
that.defaultLayui();
|
|
// $('#beginBOXTailoringG').click(() => {
|
// that.beginBOXTailoring();
|
// })
|
|
|
},
|
defaultLayui: function () {
|
var that = this;
|
layui.use(function () {
|
var slider = layui.slider //滑块
|
//滑块
|
var sliderInst1 = slider.render({
|
elem: '#lengthBOXTailoring'
|
// , input: true //输入框
|
, value: that.Nowlength
|
, disabled: true
|
, change: function (value) {
|
// console.log(value) //得到开始值
|
}
|
});
|
var sliderInst2 = slider.render({
|
elem: '#widthBOXTailoring'
|
// , input: true //输入框
|
, value: that.Nowwidth
|
, disabled: true
|
, change: function (value) {
|
// console.log(value) //得到开始值
|
}
|
});
|
var sliderInst3 = slider.render({
|
elem: '#heightBOXTailoring'
|
// , input: true //输入框
|
, value: that.Nowheight
|
, disabled: true
|
, change: function (value) {
|
// console.log(value) //得到开始值
|
}
|
});
|
var sliderInst4 = slider.render({
|
elem: '#rotateBOXTailoring'
|
// , input: true //输入框
|
, value: that.Nowrotate
|
, max: 360
|
, disabled: true
|
, change: function (value) {
|
// console.log(value) //得到开始值
|
}
|
});
|
})
|
},
|
Nowlength: 5,
|
Nowwidth: 5,
|
Nowheight: 5,
|
Nowrotate: 0,
|
beginBOXTailoring: function (pro) {
|
console.log(`${this.name}--kaishi`);
|
var that = this;
|
var promise = window.mySanweiShujuOpens[pro.id];
|
// var promise = window.mySanweiShujuOpens;
|
// console.log(pro.ZName);
|
// console.log(promise);
|
// return;
|
|
var viewer = that.map;
|
// viewer.imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({
|
// url: 'https://dev.virtualearth.net',
|
// mapStyle: Cesium.BingMapsStyle.AERIAL,
|
// key: window.MYURL_CONFIG.BING_MAP_KEY
|
// }));
|
var scene = viewer.scene;
|
var widget = viewer.cesiumWidget;
|
$('#toolbarBOXTailoring').show();
|
$('#loadingbarBOXTailoring').remove();
|
// 场景添加S3M图层服务
|
// that.promise = scene.open(window.MYURL_CONFIG.SCENE_BIMBUILDING);
|
that.promise = promise;
|
Cesium.when(that.promise, function (layers) {
|
// 精准定位
|
// scene.camera.setView({
|
// destination: new Cesium.Cartesian3(-2180753.065987198, 4379023.266141494, 4092583.575045952),
|
// orientation: {
|
// heading: 4.0392222751147955,
|
// pitch: 0.010279641987852584,
|
// roll: 1.240962888005015e-11
|
// }
|
// });
|
|
// 设置裁剪线颜色
|
setAllLayersClipColor();
|
var boxEntity = undefined;
|
var $clipMode = $('#clipModeBOXTailoring')
|
, Nowlength = that.Nowlength
|
, Nowwidth = that.Nowwidth
|
, Nowheight = that.Nowheight
|
, Nowrotate = that.Nowrotate;
|
var tooltip = window.MYcreateTooltip(document.body);
|
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
|
var isBegin = false;//设置不重复添加盒子
|
|
$('#beginBOXTailoringG').click(() => {
|
if (isBegin) {
|
layer.tips('请先清除,再添加', '#clearboxBOXTailoring', {
|
tips: [3, 'red']
|
});
|
return false;
|
}
|
isBegin = true;
|
layui.use(function () {
|
var slider = layui.slider //滑块
|
//滑块
|
var sliderInst1 = slider.render({
|
elem: '#lengthBOXTailoring'
|
// , input: true //输入框
|
, value: Nowlength
|
, disabled: false
|
, change: function (value) {
|
// console.log(value) //得到开始值
|
Nowlength = Number(value);
|
that.Nowlength = Number(value);
|
if (!boxEntity) {
|
return;
|
}
|
var dim = boxEntity.box.dimensions.getValue();
|
var newValue = Number(value);
|
boxEntity.box.dimensions = new Cesium.Cartesian3(newValue, dim.y, dim.z);
|
setClipBox();
|
}
|
});
|
var sliderInst2 = slider.render({
|
elem: '#widthBOXTailoring'
|
// , input: true //输入框
|
, value: Nowwidth
|
, disabled: false
|
, change: function (value) {
|
// console.log(value) //得到开始值
|
Nowwidth = Number(value);
|
that.Nowwidth = Number(value);
|
if (!boxEntity) {
|
return;
|
}
|
var dim = boxEntity.box.dimensions.getValue();
|
var newValue = Number(value);
|
boxEntity.box.dimensions = new Cesium.Cartesian3(dim.x, newValue, dim.z);
|
setClipBox();
|
}
|
});
|
var sliderInst3 = slider.render({
|
elem: '#heightBOXTailoring'
|
// , input: true //输入框
|
, value: Nowheight
|
, disabled: false
|
, change: function (value) {
|
// console.log(value) //得到开始值
|
Nowheight = Number(value);
|
that.Nowheight = Number(value);
|
if (!boxEntity) {
|
return;
|
}
|
var dim = boxEntity.box.dimensions.getValue();
|
var newValue = Number(value);
|
boxEntity.box.dimensions = new Cesium.Cartesian3(dim.x, dim.y, newValue);
|
setClipBox();
|
}
|
});
|
var sliderInst4 = slider.render({
|
elem: '#rotateBOXTailoring'
|
// , input: true //输入框
|
, value: Nowrotate
|
, disabled: false
|
, max: 360
|
, change: function (value) {
|
// console.log(value) //得到开始值
|
Nowrotate = Number(value);
|
that.Nowrotate = Number(value);
|
if (!boxEntity) {
|
return;
|
}
|
var position = boxEntity.position.getValue(0);
|
var newValue = Number(value);
|
var rotate = Cesium.Math.toRadians(newValue);
|
var hpr = new Cesium.HeadingPitchRoll(rotate, 0, 0);
|
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
|
boxEntity.orientation = orientation;
|
setClipBox();
|
}
|
});
|
})
|
|
|
|
handler.setInputAction(function (evt) {
|
tooltip.showAt(evt.endPosition, '<p>点击模型,添加裁剪盒子</p>');
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
handler.setInputAction(function (evt) {
|
var clipMode = $clipMode.val();
|
var length = Number(Nowlength);
|
var width = Number(Nowwidth);
|
var height = Number(Nowheight);
|
var rotate = Cesium.Math.toRadians(parseFloat(Nowrotate));
|
// 获取鼠标点击的笛卡尔坐标
|
var cartesian = scene.pickPosition(evt.position);
|
var boxOption = {
|
dimensions: new Cesium.Cartesian3(length, width, height),
|
position: cartesian,
|
clipMode: clipMode,
|
heading: rotate
|
};
|
var hpr = new Cesium.HeadingPitchRoll(rotate, 0, 0);
|
var orientation = Cesium.Transforms.headingPitchRollQuaternion(cartesian, hpr);
|
boxEntity = viewer.entities.add({
|
box: {
|
dimensions: new Cesium.Cartesian3(length, width, height),
|
material: Cesium.Color.fromRandom({
|
alpha: 0.1
|
})
|
},
|
position: cartesian,
|
orientation: orientation
|
});
|
setAllLayersClipOptions(boxOption);
|
tooltip.setVisible(false);
|
handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
})
|
$("#customBOXTailoring").on("click", function () {
|
if (!boxEntity) {
|
return;
|
}
|
if (!isBegin) {
|
layer.tips('请先添加盒子', '#beginBOXTailoringG', {
|
tips: [3, 'red']
|
});
|
return false;
|
}
|
handler.setInputAction(
|
function (movement) {
|
tooltip.showAt(movement.endPosition, '<p>点击模型,移动裁剪盒子</p>');
|
var cartesian = viewer.scene.pickPosition(movement.startPosition);
|
boxEntity.position = cartesian;
|
handler.setInputAction(function (evt) {
|
setClipBox();
|
tooltip.setVisible(false);
|
handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE
|
);
|
});
|
$('#clearboxBOXTailoring').click(function () {
|
// for (var i = 0, j = layers.length; i < j; i++) {
|
// layers[i].clearCustomClipBox();
|
// };
|
// viewer.entities.removeAll();
|
// that.defaultLayui();
|
if (!isBegin) {
|
layer.tips('请先添加盒子', '#beginBOXTailoringG', {
|
tips: [3, 'red']
|
});
|
return false;
|
}
|
isBegin = false;
|
that.closesBOXTailoring();
|
});
|
|
handler.setInputAction(function () {
|
setClipBox();
|
handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
$clipMode.change(function () {
|
setClipBox();
|
});
|
|
function setClipBox() {
|
var newDim = boxEntity.box.dimensions.getValue();
|
var position = boxEntity.position.getValue(0);
|
var clipMode = $clipMode.val();
|
var heading = Cesium.Math.toRadians(Nowrotate);
|
var boxOptions = {
|
dimensions: newDim,
|
position: position,
|
clipMode: clipMode,
|
heading: heading
|
};
|
setAllLayersClipOptions(boxOptions);
|
}
|
|
function setAllLayersClipColor() {
|
for (var i = 0, j = layers.length; i < j; i++) {
|
layers[i].clipLineColor = new Cesium.Color(1, 1, 1, 0);
|
}
|
}
|
|
function setAllLayersClipOptions(boxOptions) {
|
for (var i = 0, j = layers.length; i < j; i++) {
|
layers[i].setCustomClipBox(boxOptions);
|
}
|
}
|
|
}, function (e) {
|
if (widget._showRenderLoopErrors) {
|
var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
|
widget.showErrorPanel(title, undefined, e);
|
}
|
});
|
|
|
},
|
promise: 'null',
|
closesBOXTailoring: function (froms) {
|
console.log(`${this.name}--guanbi`);
|
var that = this;
|
if (that.promise != 'null') {
|
Cesium.when(that.promise, function (layers) {
|
for (var i = 0, j = layers.length; i < j; i++) {
|
layers[i].clearCustomClipBox();
|
};
|
that.map.entities.removeAll();
|
that.defaultLayui();
|
})
|
}
|
|
},
|
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);
|
}
|
|
});
|
});
|