contourAnalysis.html
12.4 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>等高线分析</title>
<script src="/static/js/jquery-3.4.1.min.js"></script>
<script src="/static/js/JavaScript.js"></script>
<script src="/static/js/popupJS.js"></script>
<script src="/static/js/layui/layui.js"></script>
<link rel="stylesheet" href="/static/js/layui/css/layui.css">
<link rel="stylesheet" href="/static/css/analysis.css">
<style>
/* 更改下拉框的样式 */
.layui-form-select .layui-input {
height: 30px;
padding-top: 2px;
}
.layui-form-select dl dd {
height: 30px;
color: black;
}
.layui-select-title {
padding-top: 1px;
}
.layui-form-select dl dd.layui-this {
background-color: #071424;
color: #fff;
}
/* 输入框的样式 */
.layui-input {
height: 30px;
}
.layui-input-block {
margin-left: 110px;
padding-top: 4px;
margin-right: 40px;
}
/* 颜色选择器样式 */
.colorselect {
float: left;
height: 40px;
margin-left: 0px;
}
/* 绘制按钮的样式 */
.tiaojian .search-btn {
width: 100px;
}
</style>
</head>
<body marginwidth="0" marginheight="0">
<div id="mainDiv" class="dialog tiaojian">
<h1 class="title" onmousedown="MouseDown(event)" onmouseup="MouseUp(event)" onmouseout="MouseUp(event)">
等高线分析<i class="guanbibtn" onclick="Close()">X</i>
</h1>
<form class="main layui-form" ref="contour" action="" label-width="70px" label-position="left"
lay-filter="example">
<div class="filter">
<h1 class="filter-title">参数设置</h1>
<div class="box">
<div class="layui-form-item">
<label class="layui-form-label">线不透明度</label>
<div class="layui-input-block">
<input type="text" name="lineOpacity" lay-verify="number" autocomplete="off" value="1.0"
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">显示样式</label>
<div class="layui-input-block">
<select name="showStyle" lay-filter="aihao">
<option value="0" selected>等高线</option>
<option value="1">分层设色图</option>
<option value="2">等高线和分层设色图</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">等高线颜色</label>
<div class="layui-input-block colorselect">
<div id="test3" name="contourColor" style="height: 38px;"></div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">等高距</label>
<div class="layui-input-block">
<input type="text" name="interval" lay-verify="title" autocomplete="off" value="100"
class="layui-input">
</div>
</div>
</div>
<div style="padding:0px 50px;">
<button type="button" class="search-btn" id="btnAnalysis" onclick="DrawRect()">绘制范围</button>
<button type="button" class="search-btn" id="clearAnalysis"
onclick="ClearContourEvent()">清除绘制</button>
</div>
</div>
</form>
</div>
</body>
<script>
layui.use(['form', 'colorpicker'], function () {
var $ = layui.jquery,
colorpicker = layui.colorpicker;
var form = layui.form;
form.render('select');
form.on('select(layer)', function (data) {
//layerChange(data.value);
form.render('select');
});
form.on('select(attrName)', function (data) {
//atteNameChange(data.value);
form.render('select');
});
// colorpicker.render({
// elem: '#test3'
// , color: 'rgb(68,66,66)'
// , format: 'hex' //默认为 hex
// });
colorpicker.render({
elem: '#test3'
, color: 'rgb(7, 155, 140)'
, format: 'hex'
, predefine: true
, alpha: false
, done: function (color) {
// //$('#test-all-input').val(color); //向隐藏域赋值
// layer.tips('给指定隐藏域设置了颜色值:' + color, this.elem);
// color || this.change(color); //清空时执行 change
console.log("颜色" + color);
mapColor = color;//mapColor在下面的script中定义
}
// , change: function (color) {
// //给当前页面头部和左侧设置主题色
// console.log(color);
// // $('.header-demo,.layui-side .layui-nav').css('background-color', color);
// }
});
});
// $("#btnAnalysis").on('click', function () {
// //表单取值
// var form = layui.form;
// var co = layui.colorpicker;
// var data = form.val('example');
// console.log("线不透明度:" + data.lineOpacity);
// console.log("显示样式:" + data.showStyle);
// console.log("等高距:" + data.interval);
// });
</script>
<script>
var terrainRctg = null;
var _Position = null;
var contourMapList = [];
var mapColor = "#079b8c";
function DrawRect() {
terrainRctg = null;
_Position = null;
var SGWorld = CreateSGObj();
try {
SGWorld.AttachEvent("OnLButtonClicked", DrawRectLButtonEvent);
SGWorld.AttachEvent("OnFrame", DrawRectFrameEvent);
SGWorld.Window.SetInputMode(1, "", true);
} catch (e) {
alert(e.message);
}
}
function DrawRectLButtonEvent(Flags, X, Y) {
var SGWorld = new CreateSGObj();
if (null == _Position) {
if (terrainRctg != null) {
SGWorld.ProjectTree.DeleteItem(terrainRctg.ID);
terrainRctg = null;
}
//将屏幕的像素坐标转化为三位中的世界坐标
var wpi = SGWorld.Window.PixelToWorld(X, Y, -1);//最后一个可以设置点击的对象是什么类型的 -1为默认值
if (null == wpi) {
return false;
}
_Position = wpi.Position;
_Position.Yaw = SGWorld.Navigate.GetPosition(3).Yaw;
} else {
//第二次点击结束绘制
FinishedEdit();
}
return false;
}
//绘制矩形点下第一个点,然后移动的事件
function DrawRectFrameEvent() {
if (_Position == null) return;
var SGWorld = CreateSGObj();
var mi = SGWorld.Window.GetMouseInfo();
var position = SGWorld.Window.PixelToWorld(mi.X, mi.Y, -1).Position;
var length = _Position.DistanceTo(position);
var angle = GetAngle(position);
var width = Math.sin(angle) * length; /*这里矩形的宽就得到了*/
var poi1 = _Position.Move(width * -1, _Position.Yaw, 0); /*两个对角点沿摄像机方向延伸一个宽度*/
var poi2 = position.Move(width, _Position.Yaw, 0);
var array = new Array(_Position.X, _Position.Y, 1,
poi1.X, poi1.Y, 1,
position.X, position.Y, 1,
poi2.X, poi2.Y, 1);
var cRing = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry(array);
var cPolygonGeometry = SGWorld.Creator.GeometryCreator.CreatePolygonGeometry(cRing, null);
if (terrainRctg == null) {
var nLineColor = 0xFF00FF00;
var nFillColor = 0xBB00FFFF;
var eAltitudeTypeCode = 0;
terrainRctg = SGWorld.Creator.CreatePolygon(cPolygonGeometry, nLineColor, nFillColor, eAltitudeTypeCode, "", "选中区域");
}
else {
terrainRctg.Geometry = cPolygonGeometry;
}
}
function FinishedEdit() {
_Position = null;
var SGWorld = new CreateSGObj();
//获取矩形的左上角和右下角的值
var points = terrainRctg.Geometry.Rings.Item(0).Points,
pos0,
pos1,
pos2,
pos3,
aveYaw,
rectHeight,
rectWidth;
//获取绘制的矩形的四个点坐标,转换为位置
pos0 = SGWorld.Creator.CreatePosition(
points.Item(0).X,
points.Item(0).Y,
points.Item(0).Z
);
pos1 = SGWorld.Creator.CreatePosition(
points.Item(1).X,
points.Item(1).Y,
points.Item(1).Z
);
pos2 = SGWorld.Creator.CreatePosition(
points.Item(2).X,
points.Item(2).Y,
points.Item(2).Z
);
pos3 = SGWorld.Creator.CreatePosition(
points.Item(3).X,
points.Item(3).Y,
points.Item(3).Z
);
//通过四个点位置,计算矩形的Yaw平均值
aveYaw =
(pos1.AimTo(pos2).Yaw +
180 +
pos2.AimTo(pos1).Yaw +
pos3.AimTo(pos0).Yaw +
pos0.AimTo(pos3).Yaw +
180) /
4.0;
rectHeight = pos3.DistanceTo(pos0); //获取绘制的矩形的高度
rectWidth = pos1.DistanceTo(pos0); //获取绘制的矩形的宽度
var data = layui.form.val('example');
let cmType = data.showStyle,
contourMap = SGWorld.Analysis.CreateContourMap(
0,
0,
0,
0,
cmType,
"",
"",
""
); //创建一个等高线图
//设置等高线图的位置、偏航角、高度、宽度、等高距、等高线颜色、等高线不透明度
contourMap.Position = terrainRctg.Position;
contourMap.Position.Yaw = aveYaw;
contourMap.Depth = rectHeight;
contourMap.Width = rectWidth;
contourMap.ContourLinesInterval = parseFloat(data.interval);
contourMap.ContourLinesColor.FromHTMLColor(mapColor);
contourMap.ContourLinesColor.SetAlpha(parseFloat(data.lineOpacity));
SGWorld.ProjectTree.DeleteItem(terrainRctg.ID); //删除绘制的矩形,只保留形成的等高线图
terrainRctg = null;
contourMapList.push(contourMap.ID); //向临时对象数组中添加临时对象的ID
//完成后的鼠标变化与监听
//SGWorld.ProjectTree.DeleteItem(terrainRctg.ID);
if (terrainRctg != null)
terrainRctg = null;
if (_Position != null)
_Position = null;
SGWorld.DetachEvent("OnLButtonClicked", DrawRectLButtonEvent);
SGWorld.DetachEvent("OnFrame", DrawRectFrameEvent);
SGWorld.Window.SetInputMode(0, "", true);
}
function GetAngle(Poi) {
var SGWorld = new CreateSGObj();
var includeAngle = SGWorld.CoordServices.GetAimingAngles(_Position, Poi);
var angle = includeAngle.Yaw - 90 - _Position.Yaw;
return (angle / 180 * 3.14);
}
//清除生成的矩形等高线分析相关内容
function ClearContourEvent() {
var SGWorld = new CreateSGObj();
for (var i = 0; i < contourMapList.length; i++) {
SGWorld.ProjectTree.DeleteItem(contourMapList[i]);
}
contourMapList.length = 0;
//SGWorld.ProjectTree.DeleteItem(terrainRctg.ID);
//if (terrainRctg != null)
// terrainRctg = null;
//if (_Position != null)
// _Position = null;
//SGWorld.DetachEvent("OnLButtonClicked", DrawRectLButtonEvent);
//SGWorld.DetachEvent("OnFrame", DrawRectFrameEvent);
//SGWorld.Window.SetInputMode(0, "", true);
}
</script>
</html>