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-SQLQuery',
name: 'SQLQuery',
flag: false,
startup: function () {
var that = this;
topic.subscribe("beginSQL", lang.hitch(this, this.beginSQL));
topic.subscribe("closesSQL", lang.hitch(this, this.closesSQL));
// topic.publish('beginSQL', that.beginSQL);
$(`.${that.baseClass}`).find('.closeOUR').click(() => {
$(`.${that.baseClass}`).hide();
that.closesSQL();
})
// that.beginSQL();
},
beginSQL: function () {
var that = this
, viewer = that.map
, 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 buildingLayer;
var IDs = [];
$('#loadingbar').remove();
var URL_CONFIG = {
SCENE_CBD: 'http://www.supermapol.com/realspace/services/3D-CBDCache20200416/rest/realspace',
}
var promise = scene.open(URL_CONFIG.SCENE_CBD);
// try {
Cesium.when(promise, function (layers) {
// console.log(layers, 1111)
//设置相机位置、视角,便于观察场景
scene.camera.setView({
destination: new Cesium.Cartesian3.fromDegrees(116.4566, 39.9149, 5323.445971240632),
orientation: {
heading: 0,
pitch: -1.5188,
roll: 0
}
});
var camera = scene.camera;
buildingLayer = scene.layers.find("Building@CBD");
buildingLayer.indexedDBSetting.isAttributesSave = true;//保存属性
//点击属性查询
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (evt) {
var position = scene.pickPosition(evt.position);
if (buildingLayer.getSelection().length > 0) {
const selectedId = Number(buildingLayer.getSelection()[0]);
buildingLayer.getAttributesById([selectedId]).then(function (atts) {
if (atts) {
console.log(atts);
viewer.entities.removeAll();
var length = Object.keys(atts).length;
var des;
for (var i = 0; i < length; i++) {
var key = Object.keys(atts)[i];
var value = atts[key];
var index = i.toString();
if (i == 0) {
des = '
' + '| ' + key + ' | ' + value + ' |
';
} else if (i == length - 1) {
des += '| ' + key + ' | ' + value + ' |
' + "
";
} else {
des += '| ' + key + ' | ' + value + ' |
';
}
}
viewer.entities.add({
position: position,
billboard: {
image: './images/addL/dworgin.png',
width: 30,
height: 40,
},
name: atts["MODELNAME"],
description: des
});
}
}
)
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
$("#SQLQuerysearch").click(function () {
doSqlQuery($("#SQL").val());
});
$("#SQLQueryposition").change(function () {
if (this.value == "1") {
camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.45756824765414, 39.9151525065, 303.9282348283207),
orientation: {
heading: 3.361386,
pitch: -0.543285,
roll: 6.283185307179563
}
});
}
if (this.value == "2") {
camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.45898554643348, 39.90943026228571, 32.707476595524625),
orientation: {
heading: 6.016771,
pitch: -0.300416,
roll: 0.0
}
});
}
if (this.value == "3") {
camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.43518565219966, 39.95097107746538, 2078.0503226706123),
orientation: {
heading: 2.718565,
pitch: -0.415366,
roll: 0.0
}
});
}
if (this.value == "4") {
camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.48368313561016, 39.911532190450295, 369.08993153401934),
orientation: {
heading: 4.771817,
pitch: -0.190922,
roll: 0.0
}
});
}
})
}, function () {
var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
widget.showErrorPanel(title, undefined, e);
});
// } catch (e) {
// if (widget._showRenderLoopErrors) {
// var title = '渲染时发生错误,已停止渲染。';
// widget.showErrorPanel(title, undefined, e);
// }
// }
function onQueryComplete(features) {
var selectedFeatures = features;
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"] + ' |
';
} else if (j == feature.fieldNames.length - 1) {
des += '| ' + selectedFeatures[i].fieldNames[index] + ' | ' + selectedFeatures[i].fieldValues[index] + ' |
' + "
";
} else {
des += '| ' + selectedFeatures[i].fieldNames[index] + ' | ' + selectedFeatures[i].fieldValues[index] + ' |
';
}
}
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/dwblue.png',
width: 30,
height: 40,
},
name: selectedFeatures[i].fieldValues["11"],
description: des,
SQLData: selectedFeatures[i]//设置数据
});
IDs.push(parseInt(value) + 11);
}
if (IDs.length > 0) {
buildingLayer.setSelection(IDs);
}
}
function doSqlQuery(sqlStr) {
var sqlParameter = {
"datasetNames": ["二维数据:Building"],
getFeatureMode: "SQL",
queryParameter: {
attributeFilter: sqlStr
}
};
var url = "http://www.supermapol.com/realspace/services/data-cbd/rest/data/featureResults.rjson?returnContent=true";
var queryData = JSON.stringify(sqlParameter);
$.ajax({
type: "post",
url: url,
data: queryData,
success: function (result) {
var resultObj = JSON.parse(result);
console.log(resultObj);
if (resultObj.featureCount > 0) {
onQueryComplete(resultObj.features);
}
},
error: function (msg) {
console.log(msg);
},
// complete: function () {
// console.log("complete");
// }
})
// $.ajax({
// url: url,
// async: true,
// data: queryData,
// method: "POST"
// }).done(function (result) {
// var resultObj = JSON.parse(result);
// console.log(resultObj);
// if (resultObj.featureCount > 0) {
// onQueryComplete(resultObj.features);
// }
//
// })
}
function processFailed(queryEventArgs) {
alert('查询失败!');
}
that.promise = promise;
},
promise: '',
closesSQL: function () {
var that = this
, viewer = this.map;
viewer.entities.removeAll();
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);
}
});
});