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-spatialQuery', name: 'spatialQuery', flag: false, startup: function () { var that = this; topic.subscribe("beginSpatialQuery", lang.hitch(this, this.beginSpatialQuery)); topic.subscribe("closesSpatialQuery", lang.hitch(this, this.closesSpatialQuery)); // topic.publish('getbeginSlope', that.beginSlope); $(`.${that.baseClass}`).find('.closeOUR').click(() => { $(`.${that.baseClass}`).hide(); that.closesSpatialQuery(); }) $(`.${that.baseClass}`).find('.closeOURspatialQueryValue').click(() => { $(`#spatialQueryValue`).hide(); $(`#spatialQueryValuemain`).empty(); }) // that.beginSpatialQuery(); }, beginSpatialQuery: function () { console.log(`${this.name}--kaishi`); var that = this , viewer = that.map; 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 widget = viewer.cesiumWidget; var IDs = []; var dataUrl = "http://www.supermapol.com/realspace/services/data-cbd/rest/data/featureResults.rjson?returnContent=true"; $('#loadingbar').remove(); // try { var promise = scene.open('http://www.supermapol.com/realspace/services/3D-CBDCache20200416/rest/realspace'); Cesium.when(promise, function (layer) { //设置相机位置、视角,便于观察场景 scene.camera.setView({ destination: new Cesium.Cartesian3.fromDegrees(116.4566, 39.9149, 5323.445971240632), orientation: { heading: 0, pitch: -1.5188, roll: 6.283185307179563 } }); var handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon); var tooltip = window.MYcreateTooltip(document.body); $("#searchSpatialQuery").click(function () { // console.log(1) handlerPolygon.activate(); // console.log(2) }); 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) { if (windowPosition.x < 210 && windowPosition.y < 120) { tooltip.setVisible(false); return; } if (handlerPolygon.isDrawing) { tooltip.showAt(windowPosition, '
点击确定查询区域中间点
右键单击结束绘制
'); } else { tooltip.showAt(windowPosition, '点击绘制查询区域第一个点
'); } }); handlerPolygon.drawEvt.addEventListener(function (result) { tooltip.setVisible(false); handlerPolygon.polygon.show = false; handlerPolygon.polyline.show = false; var positions = result.object.positions; var geometries = []; for (var i = 0; i < positions.length; i++) { var position = positions[i]; var cartographic = Cesium.Cartographic.fromCartesian(position); var longitude = Cesium.Math.toDegrees(cartographic.longitude); var latitude = Cesium.Math.toDegrees(cartographic.latitude); var queryPoint = { // 查询点对象 x: longitude, y: latitude }; geometries.push(queryPoint) } query(geometries); }); }, function () { var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?'; widget.showErrorPanel(title, undefined, e); }); // } catch (e) { // if (widget._showRenderLoopErrors) { // var title = '渲染时发生错误,已停止渲染。'; // widget.showErrorPanel(title, undefined, e); // } // } function processCompleted(features) { var selectedFeatures = features; // console.log(selectedFeatures); var color; IDs = []; viewer.entities.removeAll(); for (var i = 0; i < selectedFeatures.length; i++) { var value = selectedFeatures[i].fieldValues["0"]; var feature = selectedFeatures[i]; for (var j = 0; j < feature.fieldNames.length; j++) { var index = j.toString(); if (j == 0) { var des = '| ' + selectedFeatures[i].fieldNames["0"] + ' | ' + selectedFeatures[i].fieldValues["0"] + ' |
|---|---|
| ' + selectedFeatures[i].fieldNames[index] + ' | ' + selectedFeatures[i].fieldValues[index] + ' |