viewer_ymo.vue
7.99 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!--
* 显示基本的三维Globe
* 1、添加SuperMap发布的地形数据
* 2、添加SuperMap发布的影像数据
* 3、淹没区分析
* 3.1 Entity分析
* 3.2 Primitive分析
* @Author: jiangbotao
* @Date: 2019-12-02 09:05:50
* @LastEditors: jiangbotao
* @LastEditTime: 2019-12-09 12:22:02
* @FilePath: \WebGL_Webpack_Vue\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 class="param-item">
<button type="button" id="draw" class="button black">绘制分析面</button>
<button type="button" id="begin" class="button black">淹没分析</button>
<button type="button" id="clear" class="button black">清除</button>
</div>
</div>
</div>
</template>
<script>
import URL_CONFIG from "./../config/urlConfig.vue";
const Cesium = window.Cesium;
export default {
data: function() {
return {
styleObject:{
width: '100%',
position: "absolute",
top: "0px",
bottom: "0px",
left: "0px",
backgroundColor: "#000000"
},
viewer:{}
}
},
mounted: function(){
var __this = this;
__this.viewer=new Cesium.Viewer("cesiumContainer", {
terrainProvider : new Cesium.CesiumTerrainProvider({
url : URL_CONFIG.SiChuan_TERRAIN,
isSct : true//地形服务源自SuperMap iServer发布时需设置isSct为true
}),
});
var scene = __this.viewer.scene;
var widget = __this.viewer.cesiumWidget;
// 隐藏logo
$(".cesium-widget-credits")[0].style.visibility="hidden";
// 隐藏导航工具
// $(".cesium-viewer-navigationContainer")[0].style.visibility="hidden";
// 添加数据服务
this.addLayers(__this.viewer);
var clampMode = 0; // 空间模式
var handlerPolygon;
var positions = null;
var positions2d = null;
// 绘制面
handlerPolygon = new Cesium.DrawHandler(__this.viewer, Cesium.DrawMode.Polygon);
handlerPolygon.drawEvt.addEventListener(function(polygon){
var array = [].concat(polygon.object.positions);
positions = [];
positions2d = [];
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);
// 淹没分析时的固定底面
positions2d.push(longitude);
positions2d.push(latitude);
positions2d.push(1000.0);
}
}
return positions;
});
$("#draw").click(function(){
handlerPolygon && handlerPolygon.deactivate();
handlerPolygon && handlerPolygon.activate();
});
$("#begin").click(function(){
var waterHeight = 2000;
var targetHeight = 3500;
var entities = __this.viewer.entities;
//方式1
__this.floodCal(entities, positions2d, waterHeight, targetHeight);
// 方式2
// __this.floodParse(scene, positions2d, waterHeight, targetHeight);
handlerPolygon && handlerPolygon.clear();
});
$("#clear").click(function(){
__this.viewer.entities.removeAll();
handlerPolygon && handlerPolygon.clear();
});
$("#loadingbar").remove();
$("#toolbar").show();
},
methods: {
addLayers: function(viewer){
var __this = this;
// 添加影像数据
var layer = viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
url : URL_CONFIG.SiChuan_IMG
}));
// 设置相机视图
viewer.scene.camera.setView({
destination : new Cesium.Cartesian3(-1206939.1925299785, 5337998.241228442, 3286279.2424502545),
orientation : {
heading : 1.4059101895600987,
pitch : -0.20917672793046682,
roll : 2.708944180085382e-13
}
});
},
measureArea: function(handlerArea, viewer){
var clampMode = 0; // 空间模式
var positions = null;
// handlerArea = new Cesium.MeasureHandler(viewer, Cesium.MeasureMode.Area, clampMode);
handlerArea.measureEvt.addEventListener(function(result){
var mj = Number(result.area);
var area = mj > 1000000 ? (mj/1000000).toFixed(2) + "km²" : mj.toFixed(2) + "㎡"
handlerArea.areaLabel.text = "面积:" + area;
});
handlerArea.activeEvt.addEventListener(function(isActive){
if(isActive === true){
viewer.enableCursorStyle = false;
viewer._element.style.cursor = "";
$("body").removeClass("measureCur").addClass("measureCur");
}else{
viewer.enableCursorStyle = true;
$("body").removeClass("measureCur");
}
});
},
initHyp: function(){
var hyp = new Cesium.HypsometricSetting();
//设置显示模式
hyp.DisplayMode = Cesium.HypsometricSettingEnum.DisplayMode.FACE;
//设置线颜色为红色
hyp._lineColor = new Cesium.Color(1.0, 0.0, 0.0, 1.0);
//设置最大/最小可见高度
hyp.MinVisibleValue = 0;
//设置颜色表的最大/最小key值,表示高度
hyp.ColorTableMinKey = 1;
hyp.ColorTableMaxKey = 9000;
//新建颜色表
var colorTable = new Cesium.ColorTable();
var height = 1;
//每隔200m向颜色表插入一个随机色
for(var i = 0; i<90; i++){
height += 200;
colorTable.insert(height, getRandomColor());
}
//返回随机颜色
function getRandomColor(){
return new Cesium.Color(Math.random(), Math.random(), Math.random());
}
hyp.ColorTable = colorTable;
hyp.Opacity = 0.8;
//等高线间隔为200m
hyp.LineInterval = 200.0;
return hyp;
},
floodCal: function(entities, positions2d, waterHeight, targetHeight){
let entity = entities.add({
polygon : {
hierarchy : new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(positions2d)),
perPositionHeight: true,
extrudedHeight: new Cesium.CallbackProperty(function(){
waterHeight+=20;
if(waterHeight>targetHeight){
waterHeight=targetHeight;//给个最大值
}
return waterHeight
}, false),
material: new Cesium.ImageMaterialProperty({
image: './images/waterNormals.jpg',
repeat : new Cesium.Cartesian2(1, 1),
transparent: true
})
}
});
},
floodParse: function(scene, positions2d, waterHeight, targetHeight){
var River1=new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry :new Cesium.PolygonGeometry({
polygonHierarchy : new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(positions2d)),
extrudedHeight: targetHeight,
height: waterHeight,
vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT
})
}),
appearance : new Cesium.EllipsoidSurfaceAppearance({
aboveGround : true,
material: new Cesium.Material({
fabric : {
type : 'Water',
uniforms : {
normalMap:'./images/waterNormals.jpg',
frequency: 100.0,
animationSpeed: 0.01,
amplitude: 10.0
}
}
})
}),
show : true
});
scene.primitives.add(River1);
}
}
};
</script>
<style>
.cesium-infoBox-visible {
transform: translate(0,0);
visibility: hidden;
opacity: 1;
transition: opacity 0.2s ease-out,transform 0.2s ease-out;
}
.tool-bar {
position: absolute;
left: 10px;
top: 20px;
z-index: 10000;
padding: 2px;
}
.param-container .param-item {
margin: 5px;
overflow: hidden;
}
</style>