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-digTheEarth', name: 'digTheEarth', flag: false, startup: function () { var that = this; topic.subscribe("beginDigTheEarth", lang.hitch(this, this.beginDigTheEarth)); topic.subscribe("closesDigTheEarth", lang.hitch(this, this.closesDigTheEarth)); // topic.publish('getbeginSlope', that.beginSlope); $(`.${that.baseClass}`).find('.closeOUR').click(() => { $(`.${that.baseClass}`).hide(); that.closesDigTheEarth(); }) $("#beginigTheEarth").click(() => { that.beginDigTheEarth(); }) }, beginDigTheEarth: function () { var that = this , viewer = that.map; // console.log('kaishi'); // viewer.imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({ // url: 'https://dev.virtualearth.net', // mapStyle: Cesium.BingMapsStyle.AERIAL, // key: 'AkOyUpgDCoz063AWW1WfHnxp5222UBdxLOp1XvRv0tuebQnr2S7UcZkiLgME7gX0' // })); var scene = viewer.scene; // 设置相机视角 // viewer.scene.camera.setView({ // destination: Cesium.Cartesian3.fromDegrees(88.3648, 29.0946, 90000), // orientation: { // heading: 6.10547067016156, // pitch: -0.8475077031996778, // roll: 6.2831853016686185 // } // }); var tooltip = window.MYcreateTooltip(viewer._element); // console.log(viewer._element, 534) //绘制多边形 var handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, 0); handlerPolygon.activeEvt.addEventListener(function (isActive) { if (isActive == true) { viewer.enableCursorStyle = false; viewer._element.style.cursor = ''; $('body').removeClass('drawCur').addClass('drawCur'); } else { viewer.enableCursorStyle = true; $('body').removeClass('drawCur'); } }); handlerPolygon.movingEvt.addEventListener(function (windowPosition) { // console.log(windowPosition,534) // console.log(handlerPolygon.isDrawing,555) // console.log(viewer._element, 534) if (windowPosition.x < 200 && windowPosition.y < 150) { tooltip.setVisible(false); return; } if (handlerPolygon.isDrawing) { tooltip.showAt(windowPosition, '
点击确定开挖区域中间点
右键单击结束绘制,进行开挖
'); } else { tooltip.showAt(windowPosition, '点击绘制开挖区域第一个点
'); } }); handlerPolygon.drawEvt.addEventListener(function (result) { if (!result.object.positions) { tooltip.showAt(result, '请绘制正确的多边形
'); handlerPolygon.polygon.show = false; handlerPolygon.polyline.show = false; handlerPolygon.deactivate(); handlerPolygon.activate(); return; }; var array = [].concat(result.object.positions); tooltip.setVisible(false); var positions = []; for (var i = 0, len = array.length; i < len; i++) { var cartographic = Cesium.Cartographic.fromCartesian(array[i]); var longitude = Cesium.Math.toDegrees(cartographic.longitude); var latitude = Cesium.Math.toDegrees(cartographic.latitude); var h = cartographic.height; if (positions.indexOf(longitude) == -1 && positions.indexOf(latitude) == -1) { positions.push(longitude); positions.push(latitude); positions.push(h); } } var dep = $('#depth').val(); viewer.scene.globe.removeAllExcavationRegion(); viewer.scene.globe.addExcavationRegion({ name: 'ggg', position: positions, height: dep, transparent: false }); handlerPolygon.polygon.show = false; handlerPolygon.polyline.show = false; handlerPolygon.deactivate(); handlerPolygon.activate(); }); handlerPolygon.activate(); document.getElementById("cleardigTheEarth").onclick = function () { // viewer.scene.globe.removeAllExcavationRegion(); // if (handlerPolygon.polygon) { // handlerPolygon.polygon.show = false; // } // if (handlerPolygon.polyline) { // handlerPolygon.polyline.show = false; // } // handlerPolygon.polygon.show = false; // handlerPolygon.polyline.show = false; that.closesDigTheEarth(); }; if (!scene.pickPositionSupported) { alert('不支持深度纹理,无法绘制多边形,地形开挖功能无法使用!'); } $('#toolbardigTheEarth').show(); $('#loadingbar').remove(); that.handlerPolygon = handlerPolygon; that.tooltip = tooltip; }, handlerPolygon: '', tooltip: '', closesDigTheEarth: function () { // console.log('gaunbi'); var that = this; that.map.scene.globe.removeAllExcavationRegion(); if (that.handlerPolygon.polygon) { that.handlerPolygon.polygon.show = false; } if (that.handlerPolygon.polyline) { that.handlerPolygon.polyline.show = false; } if (that.handlerPolygon.deactivate) { that.handlerPolygon.deactivate(); } if(that.tooltip.setVisible){ that.tooltip.setVisible(false); } }, 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); } }); });