rectangleQuery.html
11.8 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<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>
<script src="/static/js/eventJS/search.js"></script>
<link rel="stylesheet" href="/static/js/layui/css/layui.css">
<link rel="stylesheet" href="/static/css/search.css">
<style>
.show-tab-title {
width: 480px;
overflow: auto;
overflow-y: hidden;
}
.layui-form {
height: 50px;
font-size: 14px;
}
.layui-form-item {
height: 50px;
}
.layui-input-block {
height: 25px;
font-size: 14px;
width: 170px;
margin-left: 80px;
}
.layui-form-label {
float: left;
padding: 9px 0px;
text-align: center;
}
.tool {
/* float: left; */
left: 20px;
}
.layui-tab-content {
padding: 0px;
}
.layui-form-label,
.layui-tab-title {
color: #FFF;
}
.layui-tab-title .layui-this {
color: aqua;
}
.showdiv {
width: 500px;
height: 320px;
}
.ul {
width: 480px;
}
</style>
</head>
<body marginwidth="0" marginheight="0" onload="init()">
<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="layui-form" action="">
<div class="layui-form-item">
<label class="layui-form-label">图层选择</label>
<div class="layui-input-block">
<select id="layerSelect" name="interest" lay-filter="aihao">
<option value="" selected=""></option>
</select>
</div>
</div>
</form>
<div class="tool">
<i title="开始绘制" onclick="startDrawRect()">开始绘制</i>
</div>
<div class="result layui-tab">
<h1 class="dialog title">属性展示</h1>
<div class="show-tab-title">
<ul class="layui-tab-title">
<!-- <li class="layui-this">网站设置</li> -->
</ul>
</div>
<ul class="ul">
<li class="item">
<span class="name">属性名</span>
<span class="value">属性值</span>
</li>
</ul>
<div class="layui-tab-content">
<!-- <div class="layui-tab-item layui-show">
<div class="showdiv">
<ul class="ul" id="liitems">
<li class="item">
<span class="name">属性名</span>
<span class="value">属性值</span>
</li>
</ul>
</div>
</div> -->
</div>
</div>
</div>
<script>
layui.use(['form', 'element'], function () {
var $ = layui.jquery
, element = layui.element; //Tab的切换功能,切换事件监听等,需要依赖element模块
//触发事件
var active = {
tabAdd: function () {
//新增一个Tab项
element.tabAdd('demo', {
title: '新选项' + (Math.random() * 1000 | 0) //用于演示
, content: '内容' + (Math.random() * 1000 | 0)
, id: new Date().getTime() //实际使用一般是规定好的id,这里以时间戳模拟下
})
}
, tabDelete: function (othis) {
//删除指定Tab项
element.tabDelete('demo', '44'); //删除:“商品管理”
othis.addClass('layui-btn-disabled');
}
, tabChange: function () {
//切换到指定Tab项
element.tabChange('demo', '22'); //切换到:用户管理
}
};
$('.site-demo-active').on('click', function () {
var othis = $(this), type = othis.data('type');
active[type] ? active[type].call(this, othis) : '';
});
//Hash地址的定位
var layid = location.hash.replace(/^#test=/, '');
element.tabChange('test', layid);
element.on('tab(test)', function (elem) {
location.hash = 'test=' + $(this).attr('lay-id');
});
var form = layui.form;
form.render('select');
});
</script>
<script>
function init() {
var sgworld = CreateSGObj();
ScanTree();
for (var index = 0; index < layersList.length; index++) {
var element = layersList[index];
var str = "<option value=" + element.id + ">" + element.name + "</option>";
$("#layerSelect").append(str);
}
}
var position = null;
var terrainRctg = null;
function startDrawRect() {
var sgworld = CreateSGObj();
//添加鼠标左键单击事件
sgworld.AttachEvent("OnLButtonClicked", rectangleQuery);
sgworld.AttachEvent("OnFrame", rectangleQueryFrame);
sgworld.Window.SetInputMode(1, "", true);
}
function rectangleQuery(Flags, X, Y) {
var wpi;
var sgWorld = CreateSGObj();
if (null === position) {
if (null !== terrainRctg) {
sgWorld.ProjectTree.DeleteItem(terrainRctg.ID);
terrainRctg = null;
}
if (!(wpi = sgWorld.Window.PixelToWorld(X, Y, -1))) return false;
position = wpi.Position;
position.Yaw = sgWorld.Navigate.GetPosition(3).Yaw;
return;
}
finishedEdit();
return false;
}
function rectangleQueryFrame() {
// console.log('rectangle');
if (!position) return;
var sgWorld = CreateSGObj();
var mi = sgWorld.Window.GetMouseInfo(),
pos = sgWorld.Window.PixelToWorld(mi.X, mi.Y, -1).Position,
length = position.DistanceTo(pos),
angle = getAngle(pos),
width = Math.sin(angle) * length,
poi1 = position.Move(width * -1, position.Yaw, 0),
poi2 = pos.Move(width, position.Yaw, 0);
let array = new Array(
position.X,
position.Y,
1,
poi1.X,
poi1.Y,
1,
pos.X,
pos.Y,
1,
poi2.X,
poi2.Y,
1
),
cRing = sgWorld.Creator.GeometryCreator.CreateLinearRingGeometry(
array
),
cPolygonGeometry = sgWorld.Creator.GeometryCreator.CreatePolygonGeometry(
cRing,
null
);
if (!terrainRctg) {
var nLineColor = 0xff00ff00,
nFillColor = 0xbb00ffff,
eAltitudeTypeCode = 0;
terrainRctg = sgWorld.Creator.CreatePolygon(
cPolygonGeometry,
nLineColor,
nFillColor,
eAltitudeTypeCode,
"",
"选中区域"
);
return;
}
terrainRctg.Geometry = cPolygonGeometry;
}
function getAngle(Poi) {
var sgWorld = CreateSGObj();
var includeAngle = sgWorld.CoordServices.GetAimingAngles(
position,
Poi
);
var angle = includeAngle.Yaw - 90 - position.Yaw;
return (angle / 180) * 3.14;
}
function finishedEdit() {
position = null;
var sgworld = CreateSGObj();
sgworld.DetachEvent("OnLButtonClicked", rectangleQuery);
sgworld.DetachEvent("OnFrame", rectangleQueryFrame);
sgworld.Window.SetInputMode(0, "", true);
var layerID = $("#layerSelect").val();
ShowSpatialQueryValue(terrainRctg, layerID);
}
//通过传入的图形来进行空间查询(多边形查询的时候有用到)
function ShowSpatialQueryValue(graphic, layerID) {
//创建查询
var SGWorld = CreateSGObj();
var layer = SGWorld.ProjectTree.GetObject(layerID);
$(".layui-tab-title").html("");
$(".layui-tab-content").html("");
//OT_3D_MESH_LAYER = 38 OT_3D_MESH_FEATURE_LAYER = 39
if (layer.ObjectType == 38) {
var featureLayers = layer.FeatureLayers;
for (var x = 0; x < featureLayers.Count; x++) {
var featurelayer = featureLayers.Item(x);
var resFeatures = featurelayer.ExecuteSpatialQuery(graphic.Geometry, 1);
for (var i = 0; i < resFeatures.Count; i++) {
var pIFeature = resFeatures.Item(i);
$(".layui-tab-title").append("<li>" + pIFeature.ID + "</li>");//Tab表的表头
var strAdd = "<div class='layui-tab-item'><div class='showdiv'><ul class='ul' id='liitems'>";
//添加下面的展示面板
for (var j = 0; j < pIFeature.FeatureAttributes.Count; j++) {
var pIFeatureAttribute = pIFeature.FeatureAttributes.Item(j);
strAdd += "<li class='item'><span class='name'>" +
pIFeatureAttribute.Name + "</span><span class='value'>" +
pIFeatureAttribute.Value + "</span></li>";
}
strAdd += "</ul></div></div>";
$(".layui-tab-content").append(strAdd);
}
}
}
//OT_FEATURE_LAYER = 36
else if (layer.ObjectType == 36) {
var resFeatures = layer.ExecuteSpatialQuery(graphic.Geometry, 1);
for (var i = 0; i < resFeatures.Count; i++) {
var pIFeature = resFeatures.Item(i);
$(".layui-tab-title").append("<li>" + pIFeature.ID + "</li>");//Tab表的表头
var strAdd = "<div class='layui-tab-item'><div class='showdiv'><ul class='ul' id='liitems'>";
for (var j = 0; j < pIFeature.FeatureAttributes.Count; j++) {
var pIFeatureAttribute = pIFeature.FeatureAttributes.Item(j);
strAdd += "<li class='item'><span class='name'>" +
pIFeatureAttribute.Name + "</span><span class='value'>" +
pIFeatureAttribute.Value + "</span></li>";
}
strAdd += "</ul></div></div>";
$(".layui-tab-content").append(strAdd);
}
}
$(".layui-tab-title").children(":first").addClass("layui-this");
$(".layui-tab-content").children(":first").addClass("layui-show");
}
</script>
</body>
</html>