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, '<p>点击确定查询区域中间点</p><p>右键单击结束绘制</p>');
|
} else {
|
tooltip.showAt(windowPosition, '<p>点击绘制查询区域第一个点</p>');
|
}
|
});
|
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 = '<table class="cesium-infoBox-defaultTable"><tbody>' + '<tr><th>' + selectedFeatures[i].fieldNames["0"] + '</th><td>' + selectedFeatures[i].fieldValues["0"] + '</td></tr>';
|
} else if (j == feature.fieldNames.length - 1) {
|
des += '<tr><th>' + selectedFeatures[i].fieldNames[index] + '</th><td>' + selectedFeatures[i].fieldValues[index] + '</td></tr>' + "</tbody></table>";
|
} else {
|
des += '<tr><th>' + selectedFeatures[i].fieldNames[index] + '</th><td>' + selectedFeatures[i].fieldValues[index] + '</td></tr>';
|
}
|
}
|
viewer.entities.add({
|
position: Cesium.Cartesian3.fromDegrees(parseFloat(selectedFeatures[i].fieldValues["12"]), parseFloat(selectedFeatures[i].fieldValues["13"]), parseFloat(selectedFeatures[i].fieldValues["16"])),
|
billboard: {
|
image: './images/addL/dworgin.png',
|
width: 30,
|
height: 40,
|
|
},
|
name: selectedFeatures[i].fieldValues["11"],
|
description: des,
|
spatialQueryData: selectedFeatures[i]
|
});
|
IDs.push(parseInt(value) + 11);
|
}
|
// console.log(des);
|
var buildingLayer = scene.layers.find("Building@CBD");
|
if (IDs.length > 0) {
|
buildingLayer.setSelection(IDs);
|
}
|
}
|
|
function query(queryPoints) {
|
var queryObj = {
|
"getFeatureMode": "SPATIAL",
|
"spatialQueryMode": "CONTAIN",
|
"datasetNames": ["二维数据:Building"],
|
"geometry": {
|
// id: 0,
|
// style: null,
|
// parts: [queryPoints.length],
|
points: queryPoints,
|
type: "REGION"
|
}
|
};
|
|
var queryData = JSON.stringify(queryObj); // 转化为JSON字符串作为查询参数
|
|
$.ajax({
|
type: "post",
|
url: dataUrl,
|
data: queryData,
|
success: function (result) {
|
var resultObj = JSON.parse(result);
|
// console.log(resultObj);
|
if (resultObj.featureCount > 0) {
|
processCompleted(resultObj.features);
|
}
|
},
|
error: function (msg) {
|
console.log(msg);
|
},
|
// complete: function () {
|
// console.log("complete");
|
// }
|
})
|
}
|
|
function processFailed(e) {
|
alert(e.error.errorMsg);
|
}
|
|
that.promise = promise;
|
},
|
promise: '',
|
closesSpatialQuery: function (froms) {
|
var that = this
|
, viewer = that.map;
|
viewer.entities.removeAll();
|
$(`#spatialQueryValue`).hide();
|
$(`#spatialQueryValuemain`).empty();
|
|
Cesium.when(that.promise, function (layer) {
|
for (var i = 0; i < layer.length; i++) {
|
that.map.scene.layers.remove(layer[i].name)
|
}
|
})
|
|
console.log(`${this.name}--guanbi`);
|
},
|
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);
|
}
|
|
});
|
});
|