-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.qml
241 lines (208 loc) · 6.76 KB
/
main.qml
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
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QmlVlc 0.1
import QtMultimedia 5.0
import QtWebEngine 1.2
import vmf3.demo.metadata 1.0
ApplicationWindow {
visible: true
title: qsTr("VMF-3 Demo Player")
width: 1250
height: 675
property variant paths : [ [], [] ]
property variant legends : [legend0, legend1]
property variant deviceIdLabels: [deviceIdLabel0, deviceIdLabel1]
function initializeMap(coord)
{
var script = "map.setCenter(new google.maps.LatLng(%1,%2));\n";
web.runJavaScript(script.arg(coord.lat).arg(coord.lng));
}
function getRotation(fromPt, toPt)
{
var dx = toPt.x - fromPt.x
var dy = toPt.y - fromPt.y
if (dx == 0 && dy == 0)
return 0;
else if (dx == 0)
return dy > 0 ? 90 : 270;
var rotate = Math.atan2(dy, dx)*180/Math.PI;
return rotate >= 0 ? rotate : rotate + 360;
}
function drawObject(nObject)
{
var script = "drawObject(%1, %2, %3, %4, %5);\n";
var len = paths[nObject].length
if(len > 0)
{
var toPt = paths[nObject][len-1]
var fromPt = toPt;
if(len >= 2)
fromPt = paths[nObject][len-2]
var lat = toPt.latitude
var lng = toPt.longitude
var rotate = getRotation({x: fromPt.latitude, y: fromPt.longitude},
{x: toPt.latitude, y: toPt.longitude})
var colorStr = ""
if(nObject === 0)
colorStr = "'red'"
else
colorStr = "'blue'"
script = script.arg(lat).arg(lng).arg(rotate).arg(colorStr).arg(nObject)
web.runJavaScript(script);
legends[nObject].visible = true
console.debug(script);
}
else
{
hideObject(nObject)
}
}
function hideObject(nObject)
{
legends[nObject].visible = false
web.runJavaScript("removeObject(%1);\n".arg(nObject));
}
function drawRoute(nPath)
{
web.runJavaScript("removePath(%1);\n".arg(nPath))
var len = paths[nPath].length
if(len >= 2)
{
var script = "";
script += "myCoordinates = [\n";
for(var i = 0; i < len; i++)
{
var lat = paths[nPath][i].latitude
var lng = paths[nPath][i].longitude
script += "new google.maps.LatLng(%1 , %2),\n".arg(lat).arg(lng);
}
script += "];\n";
var colorStr = ""
if(nPath === 0)
colorStr = "#FF0000"
else
colorStr = "#0000FF"
script += "myColor = '" + colorStr + "';\n";
script += "nPath = " + nPath + ";\n";
script += "drawRoute(myCoordinates, myColor, nPath);\n";
web.runJavaScript(script);
}
}
function removeRoute(nPath)
{
paths[nPath] = []
web.runJavaScript("removePath(%1);\n".arg(nPath))
}
SplitView {
anchors.fill: parent
orientation: Qt.Horizontal
Layout.minimumWidth: 1000
Layout.minimumHeight: 500
Rectangle {
Layout.minimumWidth: 320
color: "red"
VideoMetaWidget {
anchors.fill: parent
//ip: "192.168.10.190"
ip: "192.168.10.218"
onTrajectoryChanged: {
deviceIdLabels[0].text = deviceId
paths[0] = trajectory
drawRoute(0)
drawObject(0)
}
onStarted: { }
onStopped: {
removeRoute(0); hideObject(0);
}
}
}
Rectangle {
Layout.minimumWidth: 320
color: "blue"
VideoMetaWidget {
anchors.fill: parent
ip: "192.168.10.176"
onTrajectoryChanged: {
deviceIdLabels[1].text = deviceId
paths[1] = trajectory
drawRoute(1)
drawObject(1)
}
onStarted: { }
onStopped: {
removeRoute(1); hideObject(1);
}
}
}
Rectangle {
Layout.fillWidth: true
Layout.minimumWidth: 320
ColumnLayout {
spacing : 2
anchors.fill: parent
Rectangle {
anchors.top : parent.top
anchors.bottom: mapRowLayout.top
anchors.left: parent.left
anchors.right: parent.right
//Layout.fillHeight: true
//Layout.fillWidth: true
//Layout.alignment: Qt.AlignTop
WebEngineView {
id: web
anchors.fill: parent
url: "map.html"
}
}
RowLayout {
id : mapRowLayout
spacing : 2
Layout.alignment: Qt.AlignBottom
Button {
text : "remove routes"
onClicked: {
removeRoute(0); hideObject(0);
removeRoute(1); hideObject(1);
}
}
Rectangle {
//placeholder
Layout.fillWidth: true
}
RowLayout {
id: legend0
visible: false
spacing: 2
Rectangle {
color: "#ff0000"
border.color: "#000000"
width: 20
height: 20
}
Text {
id: deviceIdLabel0
text: "device #0"
}
}
RowLayout {
id: legend1
visible: false
spacing: 2
Rectangle {
color: "#0000ff"
border.color: "#000000"
width: 20
height: 20
}
Text {
id: deviceIdLabel1
text: "device #1"
}
}
}
}
}
}
}