diff options
author | 2018-12-04 16:27:03 +0900 | |
---|---|---|
committer | 2018-12-04 16:27:03 +0900 | |
commit | 5cc96b75fb3c396bd412e762fe3a611bcd8e34c4 (patch) | |
tree | 84a1bcc92117a640eae6814ed190dd5ef19602e4 /app/navigation.qml | |
parent | cf1d48d14028697c8ac9643df5320a4c6852f917 (diff) |
merge githubsandbox/zheng_wenlong/ces2019_vertical
Diffstat (limited to 'app/navigation.qml')
-rwxr-xr-x | app/navigation.qml | 216 |
1 files changed, 109 insertions, 107 deletions
diff --git a/app/navigation.qml b/app/navigation.qml index ffc0ded..10e5966 100755 --- a/app/navigation.qml +++ b/app/navigation.qml @@ -29,21 +29,23 @@ ApplicationWindow { // height: 680 //debug title: qsTr("navigation") - property real car_position_lat: fileOperation.getLatitude() // WestGate as default - property real car_position_lon: fileOperation.getLongitude() + property real car_position_lat: fileOperation.getStartLatitude() + property real car_position_lon: fileOperation.getStartLongitute() property real car_direction: 0 //North - property real car_driving_speed: fileOperation.getSpeed() // set Km/h + property real car_driving_speed: fileOperation.getCarSpeed() // set Km/h property real prev_car_direction: 0 property bool st_heading_up: false property real default_zoom_level : 18 property real default_car_direction : 0 property real car_accumulated_distance : 0 - property real positionTimer_interval : fileOperation.getInterval() // set millisecond + property real positionTimer_interval : fileOperation.getUpdateInterval() // set millisecond property real car_moving_distance : (car_driving_speed / 3.6) / (1000/positionTimer_interval) // Metric unit Map{ id: map property int pathcounter : 0 + property int prevpathcounter : -1 + property real is_rotating: 0 property int segmentcounter : 0 property int waypoint_count: -1 property int lastX : -1 @@ -63,9 +65,9 @@ ApplicationWindow { width: parent.width height: parent.height plugin: Plugin { - name: "mapboxgl" - PluginParameter { name: "mapboxgl.access_token"; - value: fileOperation.getMapAccessToken() } + name: "mapboxgl" + PluginParameter { name: "mapboxgl.access_token"; + value: fileOperation.getMapAccessToken() } } center: QtPositioning.coordinate(car_position_lat, car_position_lon) zoomLevel: default_zoom_level @@ -138,6 +140,7 @@ ApplicationWindow { } MapQuickItem { id: car_position_mapitem + property int isRotating: 0 sourceItem: Image { id: car_position_mapitem_image width: 32 @@ -166,7 +169,12 @@ ApplicationWindow { } ] transitions: Transition { - RotationAnimation { properties: "angle"; easing.type: Easing.InOutQuad } + RotationAnimation { + properties: "angle"; + easing.type: Easing.InOutQuad; + direction: RotationAnimation.Shortest; + duration: 200 + } } } @@ -208,11 +216,12 @@ ApplicationWindow { RouteModel { id: routeModel - plugin: Plugin { - name: "mapbox" - PluginParameter { name: "mapbox.access_token"; - value: fileOperation.getMapAccessToken() } - } + plugin : Plugin { + name: "mapbox" + PluginParameter { name: "mapbox.access_token"; + value: fileOperation.getMapAccessToken() + } + } query: RouteQuery { id: routeQuery } @@ -225,6 +234,8 @@ ApplicationWindow { break case 1: map.pathcounter = 0 + map.prevpathcounter = -1 + map.is_rotating = 0 map.segmentcounter = 0 // console.log("1 route found") // console.log("path: ", get(0).path.length, "segment: ", get(0).segments.length) @@ -233,9 +244,9 @@ ApplicationWindow { // } console.log("1st instruction: ", get(0).segments[map.segmentcounter].maneuver.instructionText) for( var i = 0; i < routeModel.get(0).segments.length; i++){ -// console.log("segments[",i,"].maneuver.direction:" ,routeModel.get(0).segments[i].maneuver.direction) -// console.log("segments[",i,"].maneuver.instructionText:" ,routeModel.get(0).segments[i].maneuver.instructionText) -// console.log("segments[",i,"].maneuver.path[0]:" ,routeModel.get(0).segments[i].path[0].latitude,",",routeModel.get(0).segments[i].path[0].longitude) + console.log("segments[",i,"].maneuver.direction:" ,routeModel.get(0).segments[i].maneuver.direction) + console.log("segments[",i,"].maneuver.instructionText:" ,routeModel.get(0).segments[i].maneuver.instructionText) + console.log("segments[",i,"].maneuver.path[0]:" ,routeModel.get(0).segments[i].path[0].latitude,",",routeModel.get(0).segments[i].path[0].longitude) // markerModel.addMarker(routeModel.get(0).segments[i].path[0]) // for debug } break @@ -255,7 +266,7 @@ ApplicationWindow { line.color: "#4658da" line.width: 10 smooth: true - opacity: 0.8 + opacity: 0.8 } } @@ -338,6 +349,8 @@ ApplicationWindow { } waypoint_count = 0 pathcounter = 0 + prevpathcounter = -1 + is_rotating = 0 segmentcounter = 0 routeModel.update(); markerModel.removeMarker(); @@ -546,7 +559,7 @@ ApplicationWindow { } onPressAndHold:{ - if(btn_guidance.state !== "onGuide") + if((btn_guidance.state !== "onGuide") && (btn_guidance.state !== "Routing")) { if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { @@ -588,74 +601,93 @@ ApplicationWindow { routeModel.get(0).segments[segmentcounter].path[0].latitude, routeModel.get(0).segments[segmentcounter].path[0].longitude); // console.log("next_cross_distance:",next_cross_distance); - // set next coordidnate - if(next_distance < (root.car_moving_distance * 1.5)) - { - map.currentpostion = routeModel.get(0).path[pathcounter] - if(pathcounter != 0){ - car_accumulated_distance += next_distance - } - map.qmlSignalPosInfo(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,car_accumulated_distance) - if(pathcounter < routeModel.get(0).path.length - 1){ - pathcounter++ - } - else + + // car_position_mapitem angle + if(prevpathcounter !== pathcounter) { + root.prev_car_direction = root.car_direction + root.car_direction = next_direction + } + + if(root.st_heading_up) { + // HeadingUp + is_rotating = map.bearing - root.car_direction; + } else { + // NorthUp + is_rotating = root.prev_car_direction - root.car_direction; + } + + if(is_rotating < 0) { + var val = -1; + is_rotating = is_rotating * val; + } + + if(is_rotating < 30) { + // set next coordidnate + if(next_distance < (root.car_moving_distance * 1.5)) { - // Arrive at your destination - btn_guidance.sts_guide = 0 - map.qmlSignalArrvied() - } - }else{ - setNextCoordinate(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,root.car_moving_distance) - if(pathcounter != 0){ - car_accumulated_distance += root.car_moving_distance + map.currentpostion = routeModel.get(0).path[pathcounter] + car_accumulated_distance += next_distance + map.qmlSignalPosInfo(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,car_accumulated_distance) + if(pathcounter < routeModel.get(0).path.length - 1){ + prevpathcounter = pathcounter + pathcounter++ + } + else + { + // Arrive at your destination + btn_guidance.sts_guide = 0 + map.qmlSignalArrvied() + } + }else{ + setNextCoordinate(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,root.car_moving_distance) + if(pathcounter != 0){ + car_accumulated_distance += root.car_moving_distance + } + map.qmlSignalPosInfo(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,car_accumulated_distance) } - map.qmlSignalPosInfo(map.currentpostion.latitude, map.currentpostion.longitude,next_direction,car_accumulated_distance) + // console.log("NextCoordinate:",map.currentpostion.latitude,",",map.currentpostion.longitude) } -// console.log("NextCoordinate:",map.currentpostion.latitude,",",map.currentpostion.longitude) - - // car_position_mapitem angle - root.prev_car_direction = root.car_direction - root.car_direction = next_direction if(btn_present_position.state === "Flowing") { // update map.center map.center = map.currentpostion - - rotateMapSmooth() } - - // report a new instruction if current position matches with the head position of the segment - if(segmentcounter <= routeModel.get(0).segments.length - 1){ - if(next_cross_distance < 2){ -// console.log("new segment instruction: ", routeModel.get(0).segments[segmentcounter].maneuver.instructionText) - progress_next_cross.setProgress(0) - if(segmentcounter < routeModel.get(0).segments.length - 1){ - segmentcounter++ - } - if(segmentcounter === routeModel.get(0).segments.length - 1){ - img_destination_direction.state = "12" - map.removeMapItem(icon_segment_point) + rotateMapSmooth() + + if(is_rotating < 30) { + // report a new instruction if current position matches with the head position of the segment + if(segmentcounter <= routeModel.get(0).segments.length - 1){ + if(next_cross_distance < 2){ + console.log("new segment instruction: ", routeModel.get(0).segments[segmentcounter].maneuver.instructionText) // for segment debug + progress_next_cross.setProgress(0) + if(segmentcounter < routeModel.get(0).segments.length - 1){ + segmentcounter++ + } + if(segmentcounter === routeModel.get(0).segments.length - 1){ + img_destination_direction.state = "12" + map.removeMapItem(icon_segment_point) + }else{ + img_destination_direction.state = routeModel.get(0).segments[segmentcounter].maneuver.direction + icon_segment_point.coordinate = routeModel.get(0).segments[segmentcounter].path[0] + map.addMapItem(icon_segment_point) + // console.log(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) // for guidanceModule debug + // guidanceModule.guidance(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) + } }else{ - img_destination_direction.state = routeModel.get(0).segments[segmentcounter].maneuver.direction - icon_segment_point.coordinate = routeModel.get(0).segments[segmentcounter].path[0] - map.addMapItem(icon_segment_point) - // console.log(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) - // guidanceModule.guidance(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) - } - }else{ - if(next_cross_distance <= 330 && last_segmentcounter != segmentcounter) { - last_segmentcounter = segmentcounter - console.log(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) - guidanceModule.guidance(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) + if(next_cross_distance <= 330 && last_segmentcounter != segmentcounter) { + last_segmentcounter = segmentcounter +// console.log(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) // for guidanceModule debug + guidanceModule.guidance(routeModel.get(0).segments[segmentcounter].maneuver.instructionText) + } + // update progress_next_cross + progress_next_cross.setProgress(next_cross_distance) } - // update progress_next_cross - progress_next_cross.setProgress(next_cross_distance) } } } } + function removePoiIconsSLOT(category_id){ console.log("called removePoiIcons") while(poiArray.length>0) @@ -677,50 +709,19 @@ ApplicationWindow { } function rotateMapSmooth(){ - var prev = root.prev_car_direction - var now = root.car_direction - var diff - if(root.st_heading_up){ - - diff = now - prev - - if ( 180 < diff ){ - diff = diff - 360.0 - } else if ( diff < -180 ){ - diff = diff + 360.0 - } - - //console.log("prev:", prev, ", now:", now, ", diff:", diff) - - if( 0 < diff ){ - rot_anim.direction = RotationAnimation.Clockwise - } else { - rot_anim.direction = RotationAnimation.Counterclockwise - } - map.state = "none" map.state = "smooth_rotate" }else{ - diff = 0 - prev - - if ( 180 < diff ){ - diff = diff - 360.0 - } else if ( diff < -180 ){ - diff = diff + 360.0 - } - - //console.log("prev:", prev, ", now:", now, ", diff:", diff) - if( 0 < diff ){ - rot_anim.direction = RotationAnimation.Clockwise - } else { - rot_anim.direction = RotationAnimation.Counterclockwise - } - map.state = "smooth_rotate_north" } } + function stopMapRotation(){ + map.state = "none" + rot_anim.stop() + } + states: [ State { name: "none" @@ -740,6 +741,7 @@ ApplicationWindow { RotationAnimation { id: rot_anim property: "bearing" + direction: RotationAnimation.Shortest easing.type: Easing.InOutQuad duration: 200 } |