-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathNavigationMapScreen.qml
More file actions
302 lines (251 loc) · 8.38 KB
/
NavigationMapScreen.qml
File metadata and controls
302 lines (251 loc) · 8.38 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
// ******************************************
// ** Map and Route Simulation Page **
// ******************************************
//
// This QML page simulates a map and route functionality using Mapbox and OpenStreetMap. It
// demonstrates the journey from a current location to a destination by animating a car marker
// along the calculated route. The animation includes tilting and rotating the map.
//
// Key Features:
// - Visualization of a map with a route line.
// - Animated car marker to simulate route traversal.
// - Map tilting and rotating animations.
// - GeoModel to find destination coordinates.
// - RouteModel to calculate the route.
//
// This page is intended for demonstration purposes and can be customized to fit your
// application's needs for displaying routes and geolocation data.
//
// ******************************************
import QtQuick 2.9
import QtLocation 5.6
import QtQml 2.3
import QtQuick.Controls 2.5
import QtGraphicalEffects 1.0
import QtPositioning 5.6
import Style 1.0
Page {
id: pageMap
property var currentLoc: QtPositioning.coordinate(28.4595, 77.0266) // current location
property bool isRoutingStart: false
property bool runMapAnimation: false
property bool enableGradient: true
padding: 0
function startAnimation (){
geoModel.update()
}
// Gradient to give fading effect on edges
RadialGradient {
z: 1
visible: enableGradient
anchors.fill: parent
gradient: Gradient {
GradientStop {
position: 0.0
color: "#00000000"
}
GradientStop {
position: 0.72
color: "#000000"
}
}
}
// Main map
Map {
id: map
anchors.fill: parent
copyrightsVisible: false
center: QtPositioning.coordinate(28.4595, 77.0266)
zoomLevel: 13.3
bearing: -80
plugin: Plugin {
name: "mapboxgl"
PluginParameter { name: "mapboxgl.access_token"; value: "pk.eyJ1IjoiaGFzZWVidGFyaXExOTk4IiwiYSI6ImNsbGw4cXQ3YTFsdXkzanBxaG1rZDZrYTgifQ.8M9sbj-GM8oDrhAfCMUasw"}
PluginParameter { name: "mapboxgl.mapping.additional_style_urls"; value: "mapbox://styles/haseebtariq1998/clm1o9olf00rf01qxb3nr9n82"}
}
// Route line, to show route from current location to destination
MapItemView{
id: mapRouteLine
model: routeModel
delegate: Component {
MapRoute{
route: routeData
line.color: "aqua"
line.width: adaptive.width(7)
}
}
}
// Current location marker
MapQuickItem{
id: currentLocationMarker
coordinate: QtPositioning.coordinate(28.4595, 77.0266)
visible: false
z: 1
onCoordinateChanged:
{
if(isRoutingStart)
map.center = coordinate
}
sourceItem: Rectangle{
width: adaptive.width(100) * (map.zoomLevel / 17)
height: adaptive.height(100) * (map.zoomLevel / 17)
color: "transparent"
anchors.centerIn: parent
radius: 180
Image {
id: car
width: adaptive.width(100) * (map.zoomLevel / 17)
height: adaptive.height(100) * (map.zoomLevel / 17)
source: "qrc:/Map/CarMarker.png"
anchors.centerIn: parent
}
}
Behavior on coordinate {
PropertyAnimation {
duration: 5000
}
}
}
// Destination marker
MapQuickItem{
id: destinationMarker
visible: false
z: 1
sourceItem: Rectangle{
width: adaptive.width(50) * (map.zoomLevel / 17)
height: adaptive.height(50) * (map.zoomLevel / 17)
color: "transparent"
anchors.centerIn: parent
radius: 180
AnimatedImage {
width: adaptive.width(50) * (map.zoomLevel / 17)
height: adaptive.height(50) * (map.zoomLevel / 17)
source: "qrc:/animIcons/icons8-destination.gif"
anchors.centerIn: parent
}
}
}
// Departure location marker
MapQuickItem{
id: startMarker
visible: false
z: 1
sourceItem: Rectangle{
width: adaptive.width(50) * (map.zoomLevel / 17)
height: adaptive.height(50) * (map.zoomLevel / 17)
color: "transparent"
anchors.centerIn: parent
radius: 180
Image {
width: adaptive.width(50) * (map.zoomLevel / 17)
height: adaptive.height(50) * (map.zoomLevel / 17)
source: "qrc:/Map/LocationMarker.png"
anchors.centerIn: parent
}
}
}
// Route model to calculate route
RouteModel{
id : routeModel
plugin: geoModel.plugin
query: RouteQuery{
id: routeQuery
}
onRoutesChanged: {
map.center = routeModel.get(0).path[ (routeModel.get(0).path.length/2).toFixed(0) ]
destinationMarker.coordinate = QtPositioning.coordinate(26.2124,78.1772) //routeModel.get(0).path[ routeModel.get(0).path.length -1 ]
startMarker.coordinate = currentLoc
destinationMarker.visible = true
startMarker.visible = true
animationTimer.running = true
}
}
// Timer to start car driving animation
Timer{
id: animationTimer
interval: 3000
onTriggered: {
startMarker.visible = false
currentLocationMarker.visible = true
isRoutingStart = true
simulateDrive.path = routeModel.get(0).path
routeStartAnimation.running = true
simulateDrive.running = true
}
}
// To simulate car driving on route
Timer{
id: simulateDrive
property var path
property int index
interval: 1000
repeat: true
onTriggered: {
if(path.length > index)
{
currentLocationMarker.coordinate = path[index]
index++
}
else{
simulateDrive.stop()
}
}
}
// To find coordinate of destination location
GeocodeModel{
id: geoModel
plugin: Plugin
{
name: "osm"
PluginParameter {
name: "osm.mapping.custom.host"
value: "https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png"
}
}
query: "Gwalior"
onLocationsChanged: {
if(count)
{
routeQuery.addWaypoint(currentLoc)
routeQuery.addWaypoint(get(0).coordinate)
routeModel.update()
}
}
}
}
// Animation to show at start where map tilts and rotates
SequentialAnimation{
id: routeStartAnimation
PropertyAnimation {
id: centeranimation
duration: 1000
target: map
property: "center"
to: currentLoc
}
NumberAnimation{
id: zoomAnimation
target: map
duration: 6000
properties: "zoomLevel"
from: map.zoomLevel
to: 18
}
NumberAnimation{
id: tiltAnimation
target: map
duration: 1000
properties: "tilt"
from: 0
to: map.maximumTilt
}
NumberAnimation{
id: rotationAnimation
target: map
duration: 5000
properties: "bearing"
from: -80
to: 0
}
}
}