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-clippingPlanes', name: 'clippingPlanes', flag: false, startup: function () { var that = this; topic.subscribe("beginclippingPlanes", lang.hitch(this, this.beginclippingPlanes)); topic.subscribe("closesclippingPlanes", lang.hitch(this, this.closesclippingPlanes)); // topic.publish('getbeginSlope', that.beginSlope); $(`.${that.baseClass}`).find('.closeOUR').click(() => { $(`.${that.baseClass}`).hide(); that.closesclippingPlanes(); }) // that.beginclippingPlanes(); }, beginclippingPlanes: function (promise) { // console.log(`${this.name}--kaishi`); var that = this; var viewer = that.map; // 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; // try{ //场景添加S3M图层服务 that.isClearBut = true; // that.promise = scene.open(window.MYURL_CONFIG.SCENE_BIMBUILDING); // console.log(promise, 444444444444444) that.promise = promise.src; 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 // } // }); // var name = scene.layers._layers._hash; // for (var a in name) { // name = a; // } // console.log(name) var layer = scene.layers.find(promise.name); // console.log(layer, 55555555555555) if (layer == undefined) { console.log('不支持') window.layer.tips('该图层不支持平面裁剪!', '.SelectLayerTool', { tips: [3, 'red'] }); if ($(".jimu-widget-clippingPlanes").is(":visible")) {//判断是否隐藏 $(".jimu-widget-clippingPlanes").hide(); topic.publish('closesclippingPlanes'); } return; } layer.selectEnabled = false; // //设置被裁剪对象的颜色 layer.clipLineColor = new Cesium.Color(1, 1, 1, 0); that.BIMLayer = layer; // if (!scene.pickPositionSupported) { // alert('不支持深度纹理,无法拾取位置!'); // } // }, 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 clampMode = Cesium.ClampMode.Space; that.tooltip = window.MYcreateTooltip(document.body); that.handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, clampMode); var i = 0; that.handlerPolygon.activeEvt.addEventListener(function (isActive) { if (isActive == true) { viewer.enableCursorStyle = false; viewer._element.style.cursor = ''; $('body').removeClass('drawCur').addClass('drawCur'); that.isClearBut = false; Usebody(); i = 0; } else { viewer.enableCursorStyle = true; $('body').removeClass('drawCur'); if (that.isClearBut == false) { if (i < 3) { that.tooltip.setVisible(false); layer.tips('不足三个点请重新绘画!', '#polygonclippingPlanes', { tips: [3, 'red'] }); } } Endbody(); } }); that.handlerPolygon.movingEvt.addEventListener(function (windowPosition) { // console.log(i) if (that.handlerPolygon.isDrawing) { that.tooltip.showAt(windowPosition, '
只需要设置三个点!
'); } else { that.tooltip.showAt(windowPosition, '点击绘制第一个点
'); } if (i == 3) { that.tooltip.showAt(windowPosition, '请点击右键!
'); } if (i > 3) { that.tooltip.showAt(windowPosition, '超过3个的点不生效!
'); } }); that.handlerPolygon.drawEvt.addEventListener(function (result) { var positions = result.object.positions; // console.log(that.handlerPolygon.polygon, 12434) that.tooltip.setVisible(false); that.handlerPolygon.polygon.show = false; // 通过多边形的顶点设置裁剪面,裁剪方向为裁剪面的法线方向 that.BIMLayer.setCustomClipPlane(positions[0], positions[1], positions[2]); }); var Usebody = () => { i = 0; $('.cesium-widget').click(() => { i++; }) } var Endbody = () => { i = 0; $(".cesium-widget").unbind() } $('#polygonclippingPlanes').click(function () { that.handlerPolygon.activate(); }); $('#clearclippingPlanes').click(function () { that.isClearBut = true; that.handlerPolygon.clear(); that.isClearBut = false; //清除裁剪结果 that.BIMLayer.clearCustomClipBox(); Endbody(); // if () }); $('#toolbarclippingPlanes').show(); $('#loadingbar').remove(); if (!scene.pickPositionSupported) { alert('不支持深度拾取,无法进行鼠标交互绘制!'); } }, tooltip: '', handlerPolygon: '', BIMLayer: '', isClearBut: '', promise: '', closesclippingPlanes: function (froms) { // console.log(`${this.name}--guanbi`); var that = this; that.isClearBut = true; if (that.handlerPolygon) { that.handlerPolygon.clear(); } that.isClearBut = false; //清除裁剪结果 if (that.BIMLayer != '') { that.BIMLayer.clearCustomClipBox(); } $(".cesium-widget").unbind(); // if (that.promise != '') { // Cesium.when(that.promise, function (layer) { // for (var i = 0; i < layer.length; i++) { // that.map.scene.layers.remove(layer[i].name) // } // }) // } }, 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); } }); });