aboutsummaryrefslogtreecommitdiffstats
path: root/app/testqt.qml
blob: 52c5a47eb3d07a93933ff430b832f6ae8876670e (plain)
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
/*
 * Copyright (C) 2016 The Qt Company Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import QtQuick 2.6
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
import QtWebSockets 1.0
import QtLocation 5.9
import QtPositioning 5.6

ApplicationWindow {
	id: root
	visible: true
	width: 1080
	height: 1488
	title: qsTr("TestQt")
	
	Map{
		id: map
		property variant pathcounter : 0
		property variant segmentcounter : 0
		property int lastX : -1
		property int lastY : -1
		property int pressX : -1
		property int pressY : -1
		property int jitterThreshold : 30
        anchors.fill: parent
		plugin: Plugin {
			name: "mapbox"
			PluginParameter { name: "mapbox.access_token";
			value: "pk.eyJ1IjoiYWlzaW53ZWkiLCJhIjoiY2pqNWg2cG81MGJoazNxcWhldGZzaDEwYyJ9.imkG45PQUKpgJdhO2OeADQ" }
		}
		center: QtPositioning.coordinate(36.131998,-115.1516808)
		zoomLevel: 14
		property variant modepositionfollowing : false 
		property variant currentpostion : QtPositioning.coordinate(36.131998,-115.1516808)
		
		MapQuickItem {
			id: poiTheQtComapny
			sourceItem: Rectangle { width: 14; height: 14; color: "#e41e25"; border.width: 2; border.color: "white"; smooth: true; radius: 7 }
			coordinate {
				latitude: 36.131998
				longitude: -115.1516808
			}
			opacity: 1.0
			anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2)
		}
		MapQuickItem {
			sourceItem: Text{
				text: "LAS VEGAS CONVENTION CENTER"
				color:"#242424"
				font.bold: true
				styleColor: "#ECECEC"
				style: Text.Outline
			}
			coordinate: poiTheQtComapny.coordinate
			anchorPoint: Qt.point(-poiTheQtComapny.sourceItem.width * 0.5,poiTheQtComapny.sourceItem.height * 1.5)
		}
		MapQuickItem {
			id: marker
			anchorPoint.x: imageMarker.width/2
			anchorPoint.y: imageMarker.height/2
			sourceItem: Image {
				id: imageMarker
				width: 150
				height: 150
				source: "images/car_icon.svg"
			}
			coordinate: map.currentpostion
		}
		
		RouteModel {
			id: routeModel
			plugin : map.plugin
			query:  RouteQuery {
				id: routeQuery
			}
			onStatusChanged: {
				if (status == RouteModel.Ready) {
					switch (count) {
					case 0:
						// technically not an error
					//	map.routeError()
						break
					case 1:
						map.pathcounter = 0
						map.segmentcounter = 0
						// report position on route and 1st instruction
						console.log("1 route found")
						console.log("path: ", get(0).path.length, "segment: ", get(0).segments.length)
						for(var i = 0; i < get(0).path.length; i++){
							console.log("", get(0).path[i])
						}
						console.log("1st instruction: ", get(0).segments[map.segmentcounter].maneuver.instructionText)
						break
					}
				} else if (status == RouteModel.Error) {
				//	map.routeError()
				}
			}
		}
		
		Component {
			id: routeDelegate

			MapRoute {
				id: route
				route: routeData
				line.color: "#4658da"
				line.width: 10
				smooth: true
				opacity: 0.8
			}
		}
		
		MapItemView {
			model: routeModel
			delegate: routeDelegate
			autoFitViewport: true
		}
		
		function calculateMarkerRoute()
		{
			var startCoordinate = QtPositioning.coordinate(36.131998,-115.1516808)	// The Qt Company in Oslo
			
			console.log("calculateMarkerRoute")
			routeQuery.clearWaypoints();
			routeQuery.addWaypoint(startCoordinate)
			routeQuery.addWaypoint(mouseArea.lastCoordinate)
			routeQuery.travelModes = RouteQuery.CarTravel
			routeQuery.routeOptimizations = RouteQuery.FastestRoute
			for (var i=0; i<9; i++) {
				routeQuery.setFeatureWeight(i, 0)
			}
			routeModel.update();
		}
		MouseArea {
			id: mouseArea
			property variant lastCoordinate
			anchors.fill: parent
			acceptedButtons: Qt.LeftButton | Qt.RightButton
			
			onPressed : {
				map.lastX = mouse.x
				map.lastY = mouse.y
				map.pressX = mouse.x
				map.pressY = mouse.y
				lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y))
			}
			
			onPositionChanged: {
				if (mouse.button == Qt.LeftButton) {
					map.lastX = mouse.x
					map.lastY = mouse.y
				}
			}
			
			onPressAndHold:{
				if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold
						&& Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) {
					map.modepositionfollowing = false
				//	arrow.positionTimer.stop();
					map.calculateMarkerRoute();
				}
			}
		}
		gesture.onFlickStarted: {
			map.modepositionfollowing = false
		}
		gesture.onPanStarted: {
			map.modepositionfollowing = false
		}
		
		function updatePositon()
		{
			console.log("updatePositon")
			if(routeModel.status == RouteModel.Ready){
				if(pathcounter < routeModel.get(0).path.length){
					console.log("path: ", pathcounter, "/", routeModel.get(0).path.length, "", routeModel.get(0).path[pathcounter])
					map.currentpostion = routeModel.get(0).path[pathcounter]
					marker.coordinate = map.currentpostion
					if(map.modepositionfollowing == true){
						map.center = map.currentpostion
					}
					// report a new instruction if current position matches with the head position of the segment
					if(segmentcounter < routeModel.get(0).segments.length){
						if(routeModel.get(0).path[pathcounter] == routeModel.get(0).segments[segmentcounter].path[0]){
							console.log("new segment: ", segmentcounter, "/", routeModel.get(0).segments.length)
							console.log("instruction: ", routeModel.get(0).segments[segmentcounter].maneuver.instructionText)
							segmentcounter++
						}
					}
					pathcounter++
				}else{
					pathcounter = 0
					segmentcounter = 0
					map.currentpostion = QtPositioning.coordinate(36.131998,-115.1516808)
					marker.coordinate = map.currentpostion
					if(map.modepositionfollowing == true){
						map.center = map.currentpostion
					}
				}
			}else{
				pathcounter = 0
				segmentcounter = 0
			}
		}
	}
	
	// use external nmea data to simulate current position
//	PositionSource {
//		id: src
//		updateInterval: 500
//		active: true
//		nmeaSource: "images/nmea.txt"
//		
//		onPositionChanged: {
//			var coord = src.position.coordinate;
//			console.log("Coordinate: ", src.position.coordinate);
//			map.currentpostion = src.position.coordinate;
//		}
//	}
	
	Item {
		id: present_position
		x: 942
		y: 1328
		
		Button {
			id: btn_present_position
			width: 100
			height: 100
			
			function present_position_clicked() {
				map.modepositionfollowing = true
				map.center = map.currentpostion
			}
			onClicked: { present_position_clicked() }
			
			Image {
				id: image_present_position
				width: 92
				height: 92
				anchors.verticalCenter: parent.verticalCenter
				anchors.horizontalCenter: parent.horizontalCenter
				source: "images/thum500_t002_0_ip_0175.jpg"
			}
		}
	}
	Item {
		id: arrow
		x: 940
		y: 20
		
		Timer {
			id: positionTimer
			interval: 250; running: false; repeat: true
			onTriggered: map.updatePositon()
		}
		
		Button {
			id: btn_arrow
			width: 100
			height: 100
			
			function arrow_clicked() {
				if(positionTimer.running == false){
					map.modepositionfollowing = true
					positionTimer.start();
				}else{
					map.modepositionfollowing = false
					positionTimer.stop();
				}
			}
			
			onClicked: { arrow_clicked() }
			
			Image {
				id: image_arrow
				width: 92
				height: 92
				anchors.verticalCenter: parent.verticalCenter
				anchors.horizontalCenter: parent.horizontalCenter
				source: "images/SW_Patern_1.bmp"
			}
		}
	}
	
	BtnMapDirection {
		id: btn_map_direction
		x: 15
		y: 20
	}
	BtnShrink {
		id: btn_shrink
		x: 23
		y:1200
	}
	BtnEnlarge {
		id: btn_enlarge
		x: 23
		y: 1330
	}
	ImgDestinationDirection {
		id: img_destination_direction
		x: 120
		y: 20
	}
	ProgressNextCross {
		id: progress_next_cross
		x: 225
		y: 20
	}
}