diff options
Diffstat (limited to 'app/qml')
-rw-r--r-- | app/qml/Main.qml | 163 | ||||
-rw-r--r-- | app/qml/MapWindow.qml | 141 | ||||
-rw-r--r-- | app/qml/TbtBoard.qml | 2 |
3 files changed, 271 insertions, 35 deletions
diff --git a/app/qml/Main.qml b/app/qml/Main.qml index 4139cb9..2162e2e 100644 --- a/app/qml/Main.qml +++ b/app/qml/Main.qml @@ -1,5 +1,7 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 +import QtWebSockets 1.0 +import QtPositioning 5.0 import "qrc:/qml" @@ -11,6 +13,167 @@ ApplicationWindow { width: 640 visible: true + property string tbt_navi_request_str: "" + property string api_str: "naviapi" + property string verb_getrouteinfo: "navicore_getrouteinfo" + property string verb_getallsessions: "navicore_getallsessions" + property string verb_subscribe: "subscribe" + property string verb_unsubscribe: "unsubscribe" + property string event_setdemorouteinfo: "naviapi/navicore_setdemorouteinfo" + property string event_arrivedest: "naviapi/navicore_arrivedest" + property string event_stopdemo: "naviapi/navicore_stopdemo" + property string event_setdestpos: "naviapi/navicore_setdestpos" + property string event_gps: "naviapi/navicore_gps" + property string event_getdestdir: "naviapi/navicore_getdestdir" + property var msgid_enu: { "call":2, "retok":3, "reterr":4, "event":5 } + + WebSocket { + id: websocket + url: bindingAddress + + onStatusChanged: { + if (websocket.status === WebSocket.Error){ + console.log ("Error: " + websocket.errorString) + websocket.active = false + countdown.start() + }else if (websocket.status === WebSocket.Open){ + console.log ("Socket Open") + do_getallsessions() + }else if (websocket.status === WebSocket.Closed){ + console.log ("Socket closed") + } + } + + onTextMessageReceived: { + console.log("tbtnavi:onTextMessageReceived: " + message) + var message_json = JSON.parse(message) + + //analyse the infomation from the naviapi service + if (message_json[0] === msgid_enu.event) + { + //set route infomation during the route demo + if(message_json[2].event === event_setdemorouteinfo) + { + var latitude = message_json[2].data[0].DemoLatitude + var longitude = message_json[2].data[0].DemoLongitude + var distance = message_json[2].data[0].DemoDistance + var direction = message_json[2].data[0].DemoDirection + console.log("tbtnavi: distance = " + distance + "direction = " + direction) + mapwindow.do_setDirection(direction) + mapwindow.do_setNextCrossDistance(distance) + } + //when arrive the destination + else if(message_json[2].event === event_arrivedest) + { + mapwindow.do_arrivedest() + } + //when the demo stopped + else if(message_json[2].event === event_stopdemo) + { + mapwindow.do_stopnavidemo() + mapwindow.do_setCoordinate(35.6673965582,139.7491882778) + mapwindow.startPoint = QtPositioning.coordinate(35.6673965582,139.7491882778); + } + //when add destination + else if(message_json[2].event === event_setdestpos) + { + var allroutes = message_json[2].data[0].AllRoutes + var destlat = message_json[2].data[0].DestinationLatitude + var destlon = message_json[2].data[0].DestinationLongitude + mapwindow.do_setdest(allroutes,destlat,destlon) + } + else if(message_json[2].event === event_gps){ + console.log ("tbt:Receive Event======event_gps") + var lat = message_json[2].data.latitude + var lon = message_json[2].data.longitude + console.log ("tbt:Receive Event lat====== " + lat+" "+"lon======"+lon) + mapwindow.do_setCoordinate(lat,lon) + + } + else if(message_json[2].event === event_getdestdir){ + var state = message_json[2].data.state + mapwindow.do_setTbtState(state) + } + } + else if (message_json[0] === msgid_enu.retok) + { + //when connect successed request the route infomation + if(message_json[2].request.info === verb_getallsessions) + { + do_getrouteinfo() + } + //add destination + else if(message_json[2].request.info === verb_getrouteinfo) + { + var routes = message_json[2].response[0].AllRoutes + var currentlat = message_json[2].response[0].CurrentLatitude + var currentlon = message_json[2].response[0].CurrentLongitude + var destposlat = message_json[2].response[0].DestinationLatitude + var destposlon = message_json[2].response[0].DestinationLongitude + mapwindow.do_addRoutePoint(currentlat,currentlon,destposlat,destposlon,routes) + } + } + else{ + console.log("Raw response: " + message) + } + } + active: false + } + + Timer { + id: countdown + repeat: false + interval: 3000 + triggeredOnStart: false + onTriggered: { + websocket.active = true + } + } + + onVisibleChanged: { + if (visible){ + if (!websocket.active){ + websocket.active = true + } + } + else { + countdown.stop() + if (websocket.active){ + do_unsubscribe("setdemopos") + do_unsubscribe("stopdemo") + do_unsubscribe("arrivedest") + } + } + } + + //make a connect to the naviapi service + function do_getallsessions() { + tbt_navi_request_str = '[' + msgid_enu.call + ',"99999","' + api_str+'/'+verb_getallsessions + '", {} ]' + console.log (tbt_navi_request_str) + websocket.sendTextMessage (tbt_navi_request_str) + } + + //get route information + function do_getrouteinfo() { + tbt_navi_request_str = '[' + msgid_enu.call + ',"99999","' + api_str+'/'+verb_getrouteinfo+ '", {}]' + console.log (tbt_navi_request_str) + websocket.sendTextMessage (tbt_navi_request_str) + } + + //subscribe + function do_subscribe( event ) { + tbt_navi_request_str = '[' + msgid_enu.call + ',"99999","' + api_str+'/'+verb_subscribe + '", {"value":"' + event + '"} ]' + console.log (tbt_navi_request_str) + websocket.sendTextMessage (tbt_navi_request_str) + } + + //unsubscribe + function do_unsubscribe( event ) { + tbt_navi_request_str = '[' + msgid_enu.call + ',"99999","' + api_str+'/'+verb_unsubscribe + '", {"value":"' + event + '"} ]' + console.log (tbt_navi_request_str) + websocket.sendTextMessage (tbt_navi_request_str) + } + Item { anchors.centerIn: parent width: parent.width diff --git a/app/qml/MapWindow.qml b/app/qml/MapWindow.qml index 8a41390..8321515 100644 --- a/app/qml/MapWindow.qml +++ b/app/qml/MapWindow.qml @@ -7,7 +7,7 @@ import com.mapbox.cheap_ruler 1.0 Item { id: mapWindow - property int disOffset: 70 + property int disOffset: fileOperation.getCarSpeed() // set Km/h property real rotateAngle: 0 property var startPoint property var endPoint @@ -29,28 +29,18 @@ Item { name: "mapboxgl" PluginParameter { - name: "mapboxgl.mapping.items.insert_before" - value: "road-label-small" - } - - PluginParameter { name: "mapboxgl.mapping.additional_style_urls" - value: "mapbox://styles/mapbox/streets-v9" + value: fileOperation.getMapStyleUrls() } PluginParameter { name: "mapboxgl.access_token" value: fileOperation.getMapAccessToken() } - - PluginParameter { - name: "mapboxgl.mapping.cache.directory" - value: "/home/0/app-data/navigation/" - } } center: ruler.currentPosition - zoomLevel: 20 + zoomLevel: 18 tilt: 60 gesture.acceptedGestures:MapGestureArea.NoGesture copyrightsVisible: false @@ -166,7 +156,7 @@ Item { CheapRuler { id: ruler - onCurrentDistanceChanged: { + /* onCurrentDistanceChanged: { var total = 0; var i = 0; var alldistance = ruler.distance * 1000; @@ -181,20 +171,21 @@ Item { } //show the tbt board(it will be always show when demo start) - tbt_board.visible = true +// tbt_board.visible = true // Set turn instruction tbt_board.do_setTurnInstructions(routeModel.get(0).segments[i].maneuver.instructionText) - tbt_board.state = routeModel.get(0).segments[i].maneuver.direction +// tbt_board.state = routeModel.get(0).segments[i].maneuver.direction //when goto the last instruction,set the states to "arriveDest" if(i >= (routeModel.get(0).segments.length-1)) { total = alldistance; - tbt_board.state = "arriveDest"; +// tbt_board.state = "arriveDest"; } var dis = (total - ruler.currentDistance).toFixed(1); + console.log("tbtnavi:dis = " + dis) // Set distance tbt_board.do_setDistance(dis) @@ -211,7 +202,7 @@ Item { tbt_board.do_showTbtboard(false) } } - } + }*/ //deleted } } @@ -239,30 +230,91 @@ Item { Component.onCompleted: { //request the route info when map load finish - if (ruler) { - ruler.initRouteInfo(); - ruler.setCurrentPosition(fileOperation.getStartLatitude(), fileOperation.getStartLongitute()); - } - } + console.log("Component.onCompleted") + } //the functions can be called by outside //add route signal function - function do_addRoutePoint(poi_Lat_s, poi_Lon_s, poi_Lat_e, poi_Lon_e) { - //set the startPoint and endPoint - startPoint= QtPositioning.coordinate(poi_Lat_s,poi_Lon_s); - endPoint = QtPositioning.coordinate(poi_Lat_e,poi_Lon_e); + function do_addRoutePoint(poi_Lat_s, poi_Lon_s, poi_Lat_e, poi_Lon_e,routes) { + + var latitude = "" + var longitute = "" + //when current point is null + if((poi_Lat_s === "") + &&(poi_Lon_s === "")) + { + latitude = fileOperation.getStartLatitude() + longitute = fileOperation.getStartLongitute() + } + else + { + latitude = poi_Lat_s + longitute = poi_Lon_s + } + + startPoint= QtPositioning.coordinate( latitude,longitute); startMarker.coordinate = startPoint; - endMarker.coordinate = endPoint; - //update the route view - if (map) { - map.updateRoute(); + + if (ruler) { + console.log ("latitude:"+latitude+" longitute:"+longitute) + ruler.setCurrentCoordinate(latitude,longitute); + if((routes !== 0) + &&(poi_Lat_e !== "") + &&(poi_Lon_e !== "")) + { + endPoint = QtPositioning.coordinate(poi_Lat_e,poi_Lon_e); + endMarker.coordinate = endPoint; + //update the route view + if (map) { + map.updateRoute(); + } + } + window.do_subscribe("gps") + window.do_subscribe("getdestdir") + window.do_subscribe("adddest") + window.do_subscribe("setdemopos") + window.do_subscribe("stopdemo") + window.do_subscribe("arrivedest") } } //set the current position - function do_setCoordinate(latitude,longitude,direction,distance) { - ruler.setCurrentPosition(latitude, longitude); - ruler.setCurrentDistance(distance); + function do_setCoordinate(latitude,longitude) { + ruler.setCurrentCoordinate(latitude, longitude); + } + + function do_setDistance(distance) { + ruler.setCurrentDistance(distance); + } + + function do_setNextCrossDistance(distance) { + var dis = distance; + console.log("tbtnavi:dis = " + dis) + + // Set distance + tbt_board.do_setDistance(dis) + + // Set board status + if((dis < mapWindow.disOffset) && (dis > 2)) + { + //show the tbt board(the big one) + tbt_board.do_showTbtboard(false) + } + else + { + //disvisible the tbt board(the big one) + tbt_board.do_showTbtboard(false) + } + } + + function do_setDirection(direction) { +// ruler.setCurrentDistance(direction); + } + + function do_setTbtState(tbtstate) { + //show the tbt board(it will be always show when demo start) + tbt_board.visible = true; + tbt_board.state = tbtstate; } //stop navidemo signal @@ -280,4 +332,25 @@ Item { //disvisible the tbt board tbt_board.visible = false } + + //set the current position + function do_setdest(allroutes,latitude,longitude) { + if((allroutes !== 0) + &&(latitude !== "") + &&(longitude !== "")) + { + endPoint = QtPositioning.coordinate(latitude,longitude); + endMarker.coordinate = endPoint; + + if (ruler) { + if(allroutes !== 0) + { + //update the route view + if (map) { + map.updateRoute(); + } + } + } + } + } } diff --git a/app/qml/TbtBoard.qml b/app/qml/TbtBoard.qml index cf6f537..738530d 100644 --- a/app/qml/TbtBoard.qml +++ b/app/qml/TbtBoard.qml @@ -93,7 +93,7 @@ Item { // the cases of direction arrow board states: [ State { - name: "arriveDest" //arrive the destination + name: "12" //arrive the destination PropertyChanges { target: turnDirectionBoard; source: "qrc:destination_full.png" } PropertyChanges { target: turnDirection; source: "qrc:destination.png" } }, |