viewer_spatialquery.vue
8.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!--
* 1、地图分屏效果
* @Author: jiangbotao
* @Date: 2019-12-03 22:52:56
* @LastEditors: jiangbotao
* @LastEditTime: 2019-12-07 23:25:28
* @FilePath: \superglobevue\src\components\viewer.vue
-->
<template>
<div>
<div id="cesiumContainer" v-bind:style="styleObject"></div>
<div id='loadingbar' class="spinner">
<div class="spinner-container container1">
<div class="circle1"></div>
<div class="circle2"></div>
<div class="circle3"></div>
<div class="circle4"></div>
</div>
<div class="spinner-container container2">
<div class="circle1"></div>
<div class="circle2"></div>
<div class="circle3"></div>
<div class="circle4"></div>
</div>
<div class="spinner-container container3">
<div class="circle1"></div>
<div class="circle2"></div>
<div class="circle3"></div>
<div class="circle4"></div>
</div>
</div>
<div id="toolbar" class="param-container tool-bar">
<div>
<button id="search" >查询</button>
</div>
</div>
</div>
</template>
<script>
import URL_CONFIG from "./../config/urlConfig.vue";
const Cesium = window.Cesium;
const SuperMap = window.SuperMap;
export default {
data: function() {
return {
styleObject: {
width: "100%",
position: "absolute",
top: "0px",
bottom: "0px",
left: "0px",
backgroundColor: "#000000"
},
smviewer: {}
};
},
mounted: function() {
var __this = this;
__this.viewer = new Cesium.Viewer('cesiumContainer', { animation: true });
var scene = __this.viewer.scene;
var widget = __this.viewer.cesiumWidget;
// 隐藏logo
$(".cesium-widget-credits")[0].style.visibility = "hidden";
$(".cesium-viewer-animationContainer")[0].style.visibility="hidden";
// 隐藏导航工具
// $(".cesium-viewer-navigationContainer")[0].style.visibility="hidden";
// 添加OSM地图
let osm = Cesium.createOpenStreetMapImageryProvider({
url: "https://tile-a.openstreetmap.fr/hot",
fileExtension:"png"
});
__this.viewer.imageryLayers.addImageryProvider(osm);
try {
var groundPromise = scene.addS3MTilesLayerByScp(URL_CONFIG.SCP_CBD_GROUND1, {
name: 'ground'
});
var buildPromise = scene.addS3MTilesLayerByScp(URL_CONFIG.SCP_CBD_BUILD, {
name: 'build'
});
Cesium.when([groundPromise, buildPromise], function(layers) {
scene.camera.setView({
destination : Cesium.Cartesian3.fromDegrees(116.4566, 39.9149, 5323.445971240632),
orientation : {
heading : 3.1612,
pitch : -1.5188,
roll : 6.283185307179563
}
});
var positions = null;
// 绘制面
var handlerPolygon = new Cesium.DrawHandler(__this.viewer, Cesium.DrawMode.Polygon, 0);
handlerPolygon.drawEvt.addEventListener(function(polygon){
var points = polygon.object.positions;
var arr = [];
if(points && points instanceof Array && points.length >= 3){
for(var i = 0, j = points.length; i < j; i++){
var point = __this.convertPoint(points[i]);
if(point){
arr.push(point);
}
}
}
var linearRing = new SuperMap.Geometry.LinearRing(arr);
var searchPolygon = new SuperMap.Geometry.Polygon(linearRing);
query(searchPolygon);
});
$("#search").on("click", function(){
handlerPolygon.activeEvt.addEventListener(function(isActive){
if(isActive === true){
__this.viewer.enableCursorStyle = false;
__this.viewer._element.style.cursor = '';
$('body').removeClass('drawCur').addClass('drawCur');
}else{
__this.viewer.enableCursorStyle = true;
$('body').removeClass('drawCur');
}
});
handlerPolygon && handlerPolygon.deactivate();
handlerPolygon && handlerPolygon.activate();
});
var IDs=[];
function processCompleted(queryEventArgs){
var selectedFeatures = queryEventArgs.originResult.features;
var color;
IDs=[];
__this.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>';
}
}
__this.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/location4.png',
width:30,
height:40,
},
name : selectedFeatures[i].fieldValues["11"],
description: des
});
IDs.push(parseInt(value)+11);
}
var buildingLayer = scene.layers.find("Building@CBD");
if(IDs.length>0){
// buildingLayer.setSelection(IDs);
}
}
function query(drawGeometryArgs){
var getFeaturesByGeometryParameters, getFeaturesByGeometryService;
getFeaturesByGeometryParameters = new SuperMap.REST.GetFeaturesByGeometryParameters({
datasetNames: ["二维数据:building"],
toIndex:-1,
spatialQueryMode:SuperMap.REST.SpatialQueryMode.CONTAIN,
geometry: drawGeometryArgs
});
console.log('aa');
var url = 'http://www.supermapol.com/realspace/services/data-cbd/rest/data';
getFeaturesByGeometryService = new SuperMap.REST.GetFeaturesByGeometryService(url, {
eventListeners: {
"processCompleted": processCompleted,
"processFailed": processFailed
}
});
getFeaturesByGeometryService.processAsync(getFeaturesByGeometryParameters);
}
function processFailed(e) {
alert(e.error.errorMsg);
}
}, function() {
var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
widget.showErrorPanel(title, undefined, e);
});
} catch (e) {
if (widget._showRenderLoopErrors) {
var title = '渲染时发生错误,已停止渲染。';
widget.showErrorPanel(title, undefined, e);
}
}
$("#loadingbar").remove();
},
methods:{
convertPoint : function(point){
var lonlatPoint = Cesium.Cartographic.fromCartesian(point);
var x = Cesium.Math.toDegrees(lonlatPoint.longitude);
var y = Cesium.Math.toDegrees(lonlatPoint.latitude);
if(x && y){
return new SuperMap.Geometry.Point(x, y);
}
return undefined;
}
}
};
</script>
<style>
.sm-compass {
pointer-events: auto;
position: absolute;
right: 10px;
top: 10px;
width: 128px;
height: 128px;
overflow: hidden;
}
.sm-zoom {
top: 130px;
}
.drawCur{
cursor: url(/images/cur/draw.cur), auto;
}
.cesium-infoBox{
top: 20;
left: 0;
transition: opacity 0.2s;
}
</style>