forked from Zhang-xie/GUI_SwarmIntelligenceSys
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGUI.html
More file actions
443 lines (407 loc) · 17.3 KB
/
Copy pathGUI.html
File metadata and controls
443 lines (407 loc) · 17.3 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>GUI</title>
<meta charset="UTF-8"/>
<!-- 引入 echarts.js -->
<script src="js/echarts.js"></script>
<script src="js/jquery.min.js"></script>
<!-- <script src="js/jquery-3.3.1.slim.min.js"></script> -->
<!-- <script src="js/bootstrap-3.3.4.js"></script> -->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.flightindicators.js"></script><!-- this is for the dicators to showing the pose -->
<link type="text/css" href="css/header.css" rel="stylesheet" />
<link type="text/css" href="css/control_column.css" rel="stylesheet"/><!-- the style for the left column of the page -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/style.css"><!-- the style for the whole page and the map -->
<link rel="stylesheet" type="text/css" href="css/flightindicators.css" />
<!-- 左边栏的开关按钮 -->
<script type="text/javascript">
// When all the elements in the webpage are ready, this function will be called
// $ represents a selector selecting the elements in the parentheses
// $(.xxx) selects all the elements with class .xxx in css file
// $(#xxx) selects all the elements with id xxx
// $([xx="yy"]) selects all the elements with property naming xx valuing yy
$(document).ready(function () {
var trigger = $('.hamburger');
var overlay = $('.overlay');
var mainCanvas = $('#mainCanvas');
// var mainOpBox = $('#main');
var isClosed = false;
//When the element is clicked, the function will be called
trigger.click(function () {
hamburger_cross();
});
function hamburger_cross() {
if (isClosed == true) {
overlay.hide();
//is-open, is-closed are classes defined in style.css representing the style of the hamburger
trigger.removeClass('is-open'); //Remove the class from the selected elements
trigger.addClass('is-closed'); //Add class to the selected elements
isClosed = false;
} else {
overlay.show();
trigger.removeClass('is-closed');
trigger.addClass('is-open');
isClosed = true;
}
}
// toggleClass switches the class of the selected elements
// If the selected elements have some classes, then delete them and add the new ones
$('[data-toggle="offcanvas"]').click(function() {
$('#wrapper').toggleClass('toggled');
});
});
</script>
<!-- 点击左边栏boardcast按钮,将开始跟新所有车辆的连接信息,同时显示在map -->
<script>
var myChart ; //声明全局使用的chart
var IDforDetails = 0;//存下用户需要知道详细信息的对象的ID,便于更新左边栏的信息框以及姿态显示图标
var options;//姿态显示设置
var flag = 0;//用来标记是显示模式,还是控制模式;0->显示;1->控制
var timer;//用来记录refresh的重复执行
var ids = 0;//用来记录在控制时候选中的个体ID 默认0,代表没有
var totalData;//记录所有ID的数据
//首先获取echarts,然后设定一个鼠标点击的监听,最后设置refresh反复运行,实现对map的刷新
$(document).ready( function(){
myChart = echarts.init(document.getElementById('mainControlMap')); //get echarts
myChart.on('click', function (params) { //监听鼠标点击事件函数
// console.log(params.value[4]);
// console.log(params.value);
IDforDetails = params.value[4];//因为在下面的option中ID存在数组第四个
});
myChart.on('brushselected', function(params){ //触发了框选之后获取已框选的个体的ID
var temp = new Array();
var mainSeries = params.batch[0].selected[0];
for (var i = 0; i < mainSeries.dataIndex.length; i++) {
var rawIndex = mainSeries.dataIndex[i];
temp.push(totalData[rawIndex][4]);
}
ids = temp.join('');
var ele=document.getElementById("choosedId");
ele.value = ids;
});
//点击按钮后,refresh刷新map
$("#boardcast_btn").click(
function(){
if(flag == 0){ //进入显示模式
timer = setInterval(refresh, 300);//执行refresh函数,每30毫秒一次
flag = 1;
}
else { //进入控制模式
clearInterval(timer);//取消重复刷新
$.post("mysql/postCommand.php",{ commandID:0 , start_x:0,start_y:0,start_z:0,end_x:0,end_y:0,end_z:0,IDs:ids},//提交command 0 号指令,该指令表示所有个体停止运动
function(data,status){
});
refresh();//当前所有个体静止所在的位置显示
flag = 0;
}
});
// 设定姿态仪表盘的初始参数
options = {
size : 150, // Sets the size in pixels of the indicator (square)
roll : 0, // Roll angle in degrees for an attitude indicator
pitch : 10, // Pitch angle in degrees for an attitude indicator
heading: 0, // Heading angle in degrees for an heading indicator
vario: 0, // Variometer in 1000 feets/min for the variometer indicator
airspeed: 0, // Air speed in knots for an air speed indicator
altitude: 0, // Altitude in feets for an altimeter indicator
pressure: 1000, // Pressure in hPa for an altimeter indicator
showBox : false, // Sets if the outer squared box is visible or not (true or false)
img_directory : 'img/' // The directory where the images are saved to
};
var indicator_0 = $.flightIndicator('#attitude_0', 'attitude',options);
var indicator_1 = $.flightIndicator('#attitude_1', 'heading',options);
var indicator_2 = $.flightIndicator('#attitude_2', 'variometer',options);
var indicator_3 = $.flightIndicator('#attitude_3', 'airspeed',options);
var indicator_4 = $.flightIndicator('#attitude_4', 'altimeter',options);
});
//refresh函数,访问数据库获取每辆车的最新记录,然后mychart重新setoption,同时,刷新左侧栏的第一个信息框显示
function refresh(){
$.post("mysql/getAll.php",{},
function(data,status){
testJson = eval("(" + data + ")");
var html = '';
for(var i = 0; i < testJson.length; i++)
{
html +='<tr>';
html += '<td>' + testJson[i].ID + '</td>';
html += '<td>' + testJson[i].time + '</td>';
html += '<td><div class="state_color"></td>';
html +='</tr>';
//更新左边栏第二个信息框(details)以及 对应的姿态仪表
if(testJson[i].ID == IDforDetails){
var htmltemp = '';
htmltemp += '<thead><tr><th>ID</th><th id="single_id">'+testJson[i].ID+'</th></tr></thead>';
htmltemp += '<tbody><tr><td>Speed</td><td id="single_speed">'+ testJson[i].speed+'</td></tr>';
htmltemp += '<tr><td>Pitch</td><td id="single_pitch">'+ testJson[i].pitch+'</td></tr>';
htmltemp += '<tr><td>Roll</td><td id="single_roll">'+ testJson[i].roll+'</td></tr>';
htmltemp += '<tr><td>Azimuth</td><td id="single_azimuth">'+ testJson[i].azimuth+'</td></tr>';
htmltemp += '<tr><td>Location</td><td id="single_location">'+ testJson[i].X + ' ' + testJson[i].Y + ' ' + testJson[i].Z + '</td></tr></tbody>';
var ele=document.getElementById("car_details");
ele.innerHTML= htmltemp;
// 设置对应的仪表盘显示
options = {
size : 150, // Sets the size in pixels of the indicator (square)
roll : testJson[i].roll, // Roll angle in degrees for an attitude indicator
pitch : testJson[i].pitch, // Pitch angle in degrees for an attitude indicator
heading: testJson[i].azimuth, // Heading angle in degrees for an heading indicator
vario: 0, // Variometer in 1000 feets/min for the variometer indicator
airspeed: 0, // Air speed in knots for an air speed indicator
altitude: 0, // Altitude in feets for an altimeter indicator
pressure: 1000, // Pressure in hPa for an altimeter indicator
showBox : false, // Sets if the outer squared box is visible or not (true or false)
img_directory : 'img/' // The directory where the images are saved to
};
var indicator_0 = $.flightIndicator('#attitude_0', 'attitude',options);
var indicator_1 = $.flightIndicator('#attitude_1', 'heading',options);
var indicator_2 = $.flightIndicator('#attitude_2', 'variometer',options);
var indicator_3 = $.flightIndicator('#attitude_3', 'airspeed',options);
var indicator_4 = $.flightIndicator('#attitude_4', 'altimeter',options);
}
}
var element=document.getElementById("cars_situation");
element.innerHTML= html;
// 以上更新到侧边栏的车辆信息框中
// 以下为更新map显示
totalData = [];
var totalDataNum = 0;
totalDataNum = testJson.length;
for(var i = 0; i < testJson.length; i++)
{
totalData.push([testJson[i].X, testJson[i].Y, 28, 'rgb(128,128,0)', testJson[i].ID, testJson[i].speed, testJson[i].roll, testJson[i].pitch, testJson[i].azimuth, testJson[i].time]);
};
option = {
animation: true,
tooltip:{
// trigger:'axis'
showDelay: 0,
formatter: function (params) {
if(params.value.length > 1) {
return params.seriesName + '<br/>x: ' + params.value[0] + '<br/>y: ' + params.value[1];
}
},
axisPointer: {
show: true,
type : 'cross',
lineStyle: {
type : 'dashed',
width : 1
}
}
},
xAxis: {
show: true,
type: 'value',
min: 'dataMin',
max: 'dataMax',
splitLine: {
show: true
}
},
yAxis: {
show: true,
type: 'value',
min: 'dataMin',
max: 'dataMax',
splitLine: {
show: true
}
},
dataZoom: [
//Initialize the style of the x and y axises
{
// moveOnMouseMove: false,
type: 'slider',
show: true,
xAxisIndex: [0],
start: 0,
end: 100
},
{
// moveOnMouseMove: false,
type: 'slider',
show: true,
yAxisIndex: [0],
left: '93%',
start: 0,
end: 100
},
//The operation of the mouse wheel
{
moveOnMouseMove: true,
type: 'inside',
xAxisIndex: [0],
start: 1,
end: 35
},
{
moveOnMouseMove: true,
type: 'inside',
yAxisIndex: [0],
start: 29,
end: 36
}
],
brush: {
outOfBrush: {
color: '#abc'//刷选区之外的颜色
},
brushStyle: {
borderWidth: 2,
color: 'rgba(0,0,0,0.2)',
borderColor: 'rgba(0,0,0,0.5)',
},
seriesIndex: [0],//指定哪些 series 可以被刷选,可取值为:'all': 所有 series'Array': series index 列表'number': 某个 series index
throttleType: 'debounce',//以下两项都是用来设定用户选中之后多久响应
throttleDelay: 500,
geoIndex: 0 //设定可以执行刷选的范围
},
series: [
{
name: 'robotVehicle',
type: 'scatter',
itemStyle: {
normal: {
//Set the transparency
opacity: 0.8,
color: 'rgb(128,128,0)'
// color: function (val) {
// return val[3];
// }
},
emphasis: {
color: 'rgb(0,255,0)'
}
},
symbolSize: function (val) {
return val[2];
},
data: totalData,
label: {
show: true,
color: 'rgb(0,0,0)',
position: 'top',
formatter: function(params) {
return params.value[4];
}
}
},
]
};
myChart.setOption(option,true); //chart.setOption(option,notMerge,lazyUpdate);option:图表的配置项和数据 notMerge:可选,是否不跟之前设置的option进行合并,默认为false,即合并。(这里是导致二次渲染不成功的根本)lazyUpdate:可选,在设置完option后是否不立即更新图表,默认为false,即立即更新。
});}
</script>
</head>
<body>
<!--
<div id="modeButton" class="modeButtonDivStyle">
<button id="detailsButton">details</button>
<button id="controlButton">control</button>
</div> thses buttons are used to change the model of the showing window -->
<div id="mainControlMapDiv" >
<div id="mainControlMap" class="controlMapDivStyle"></div>
</div>
<!-- 暂时用来放姿态显示仪表板 -->
<div id="selectedSector" class="selectedSectorStyle">
<div>
<span id="attitude_0" style="float: right;"></span>
</div>
<div>
<span id="attitude_1" style="float: right;"></span>
</div>
<div>
<span id="attitude_2" style="float: right;"></span>
</div>
<div>
<span id="attitude_3" style="float: right;"></span>
</div>
<div>
<span id="attitude_4" style="float: right;"></span>
</div>
</div>
<div id="wrapper" style="z-index: 40;">
<div class="overlay"></div> <!-- the head line bar of the whole page -->
<div class="navbar navbar-inverse navbar-fixed-top" id="sidebar-wrapper" role="navigation"> <!-- the left bar for the details of the cars -->
<div id="cars"> <!-- showing the connect situation of the cars -->
<div class="btn_wrapper">
<button type="button" id="boardcast_btn">boardcast</button> <!-- this button is going to creat a call to check the connection of the cars -->
</div>
<div class="cars_box_wrapper">
<table class="cars_box">
<thead>
<tr>
<th>ID</th>
<th>TIME</th>
<th>STATE</th>
</tr>
</thead>
<tbody id="cars_situation">
</tbody>
</table>
</div>
</div>
<div id="data"> <!-- this block gonna showing the detals of a pecular car which is choosed by the user -->
<table class="data_box" id='car_details'>
<thead>
<tr>
<th>ID</th>
<th id="single_id">01</th>
</tr>
</thead>
<tbody>
<tr>
<td>Speed</td>
<td id="single_speed">000</td>
</tr>
<tr>
<td>Pitch</td>
<td id="single_pitch">000</td>
</tr>
<tr>
<td>Roll</td>
<td id="single_roll">000</td>
</tr>
<tr>
<td>Azimuth</td>
<td id="single_azimuth">000</td>
</tr>
<tr>
<td>Location</td>
<td id="single_location">000</td>
</tr>
</tbody>
</table>
</div>
<div id="realTime"> <!-- shwing some messages that GUI is getting -->
<div id="message_title">Command</div>
<div id="message_body">
<form name="input" action="mysql/postCommand.php" method="post">
CommandID:<select name="commandID">
<option value="1">一号指令</option>
<option value="2">二号指令</option>
<option value="3">三号指令</option>
<option value="4">四号指令</option>
</select><br>
start_x: <input type="text" name="start_x" value="0"><br>
start_y: <input type="text" name="start_y" value="0"><br>
start_z: <input type="text" name="start_z" value="0"><br>
end_x: <input type="text" name="end_x" value="0"><br>
end_y: <input type="text" name="end_y" value="0"><br>
end_z: <input type="text" name="end_z" value="0"><br>
已选: <input type="text" name="IDs" value="111" id="choosedId"><br>
<input type="submit" value="Submit">
</form>
</div>
</div>
</div>
<div id="page-content-wrapper"> <!-- control the visibility of the left bar -->
<button type="button" class="hamburger is-closed animated fadeInLeft" data-toggle="offcanvas">
<span class="hamb-top"></span>
<span class="hamb-middle"></span>
<span class="hamb-bottom"></span>
</button>
</div>
</div>
</body>
</html>