From 79f4efbd08338968f0e0e8b1a1a29432cfbcf135 Mon Sep 17 00:00:00 2001
From: liuyg <376836862@qq.com>
Date: Tue, 29 Jun 2021 15:04:20 +0800
Subject: [PATCH] +
---
widgets/BOXInteractive/Widget.js | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 229 insertions(+), 0 deletions(-)
diff --git a/widgets/BOXInteractive/Widget.js b/widgets/BOXInteractive/Widget.js
new file mode 100644
index 0000000..146379b
--- /dev/null
+++ b/widgets/BOXInteractive/Widget.js
@@ -0,0 +1,229 @@
+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-BOXInteractive',
+ name: 'BOXInteractive',
+ flag: false,
+ startup: function () {
+ var that = this;
+ topic.subscribe("beginBOXInteractive", lang.hitch(this, this.beginBOXInteractive));
+ topic.subscribe("closesBOXInteractive", lang.hitch(this, this.closesBOXInteractive));
+ // topic.publish('getbeginSlope', that.beginSlope);
+ $(`.${that.baseClass}`).find('.closeOUR').click(() => {
+ $(`.${that.baseClass}`).hide();
+ that.closesBOXInteractive();
+ })
+
+
+ that.beginBOXInteractive();
+
+ },
+ beginBOXInteractive: function () {
+ console.log(`${this.name}--kaishi`);
+ var that = this;
+
+ var viewer = that.map;
+ var URL_CONFIG = window.MYURL_CONFIG;
+ viewer.imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({
+ url: 'https://dev.virtualearth.net',
+ mapStyle: Cesium.BingMapsStyle.AERIAL,
+ key: URL_CONFIG.BING_MAP_KEY
+ }));
+
+ var scene = viewer.scene;
+ var widget = viewer.cesiumWidget;
+ $('#toolbarBOXInteractive').show();
+ $('#loadingbarBOXInteractive').remove();
+
+ var promise = scene.open(URL_CONFIG.SCENE_BIMBUILDING);
+ Cesium.when(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 = $('#clipModeBOXInteractive');
+
+ var tooltip = window.MYcreateTooltip(document.body);
+
+ //交互绘制box
+
+ // Cesium.DrawMode.Box = 4;
+ // console.log(Cesium.DrawMode.Box, 4634343)
+ // var handlerBox = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Box);
+ var handlerBox = new Cesium.DrawHandler(viewer, 4);
+ var editorBox;
+
+ handlerBox.activeEvt.addEventListener(function (isActive) {
+ if (isActive == true) {
+ viewer.enableCursorStyle = false;
+ viewer._element.style.cursor = '';
+ $('body').removeClass('drawCurshizi').addClass('drawCurshizi');
+ }
+ else {
+ viewer.enableCursorStyle = true;
+ $('body').removeClass('drawCurshizi');
+ }
+ });
+ handlerBox.movingEvt.addEventListener(function (windowPosition) {
+
+ if (handlerBox.isDrawing) {
+ tooltip.showAt(windowPosition, '<p>点击鼠标左键结束矩形绘制,移动鼠标绘制box高度。</p><p>右键结束绘制.</p>');
+ } else {
+ tooltip.showAt(windowPosition, '<p>点击鼠标左键,开始绘制矩形作为box底面</p>');
+ }
+
+ });
+ handlerBox.drawEvt.addEventListener(function (e) {
+ console.log(88888888888888888888)
+ tooltip.setVisible(false);
+ // boxEntity = e.object;
+ // var newDim = boxEntity.box.dimensions.getValue();
+ // var position = boxEntity.position.getValue(0);
+ // var boxOption = {
+ // dimensions: newDim,
+ // position: position,
+ // clipMode: $clipMode.val(),
+ // heading: 0
+ // };
+
+ // //box编辑
+ // editorBox = new Cesium.BoxEditor(viewer, boxEntity);
+
+ // editorBox.editEvt.addEventListener(function (e) {
+ // boxEntity.box.dimensions = e.dimensions
+ // boxEntity.position = e.position;
+ // boxEntity.orientation = e.orientation;
+
+ // setClipBox();
+ // });
+ // editorBox.distanceDisplayCondition = new Cesium.DistanceDisplayCondition(0, 950);
+ // editorBox.activate();
+ // setAllLayersClipOptions(boxOption);
+ // tooltip.setVisible(false);
+ // handlerBox.clear();
+ // handlerBox.deactivate();
+ });
+ handlerBox.activate();
+
+ $('#clearboxBOXInteractive').click(function () {
+ for (var i = 0, j = layers.length; i < j; i++) {
+ layers[i].clearCustomClipBox();
+ };
+ editorBox.deactivate();
+ viewer.entities.removeAll();
+ handlerBox.clear();
+ handlerBox.deactivate();
+ handlerBox.activate();
+
+ });
+
+ $clipMode.change(function () {
+ setClipBox();
+ });
+
+ function setClipBox() {
+ var clipMode = $clipMode.val();
+ if (typeof (boxEntity) == "undefined") {
+ return;
+ }
+ var newDim = boxEntity.box.dimensions.getValue();
+ var position = boxEntity.position.getValue(0);
+
+ var heading = 0;
+ if (typeof (boxEntity.orientation) != "undefined") {
+ let rotationM3 = Cesium.Matrix3.fromQuaternion(boxEntity.orientation._value, new Cesium.Matrix3());
+ let localFrame = Cesium.Matrix4.fromRotationTranslation(rotationM3, Cesium.Cartesian3.ZERO, new Cesium.Matrix4());
+ let inverse = Cesium.Matrix4.inverse(Cesium.Transforms.eastNorthUpToFixedFrame(position), new Cesium.Matrix4());
+ let hprm = Cesium.Matrix4.multiply(inverse, localFrame, new Cesium.Matrix4());
+ var rotation = Cesium.Matrix4.getMatrix3(hprm, new Cesium.Matrix3());
+ let hpr = Cesium.HeadingPitchRoll.fromQuaternion(Cesium.Quaternion.fromRotationMatrix(rotation));
+ heading = hpr.heading;
+ }
+
+
+ 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);
+ console.log(layers[i].clipLineColor, 4444444444444)
+ }
+ }
+
+ function setAllLayersClipOptions(boxOptions) {
+ console.log(5555555555555)
+ 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);
+ }
+ });
+
+ },
+ closesBOXInteractive: function (froms) {
+ console.log(`${this.name}--guanbi`);
+ var that = this;
+ },
+ 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);
+ }
+
+ });
+ });
--
Gitblit v1.9.3