Skip to content
Snippets Groups Projects
Commit 61df9482 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Änderungen bei der Neuberechnung der Route

Wenn man von der Route abweicht, wird nun versucht die aktuelle Fahrtrichtung in die neue Route einzubeziehen.
Grund ist ganz einfach, dass man im Auto nicht jederzeit wenden kann.
parent 824b000e
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,7 @@ public function routingOverviewGeoJson($vehicle, $points)
return $response;
}
public function routingGeoJson($vehicle, $points, $hints = "")
public function routingGeoJson($vehicle, $points, $bearingStartPoint = "")
{
// This is the function to calculate the Route from $from to $to with the given vehicle
$port = 0;
......@@ -90,9 +90,20 @@ public function routingGeoJson($vehicle, $points, $hints = "")
$port = 5000;
}
$url = "http://maps.metager.de:$port/route/v1/$vehicle/$points?steps=true&geometries=geojson&overview=full&annotations=true";
if ($hints !== "") {
$url .= "&hints=$hints";
# Maybe we need to add Bearings:
if ($bearingStartPoint !== "") {
$bearing = $bearingStartPoint . ",90";
# We got the starting Bearing submitted but we need to add bearings for the rest of the points, too
$remainingPoints = sizeof(explode(";", $points)) - 1;
for ($i = $remainingPoints; $i > 0; $i--) {
# For each remaining Point we are gonna add a bearing of 0 with a range of 180°
# Hopefully this will nullify the value
$bearing .= ";0,180";
}
$url .= "&bearings=" . $bearing;
}
$cacheHash = md5($url);
if (Cache::has($cacheHash)) {
$result = Cache::get($cacheHash);
......
......@@ -2786,7 +2786,18 @@ function startLocationFollowing() {
}
});
pointString = pointString.replace(/;$/, '');
var url = '/route/find/' + vehicle + '/' + pointString;
// Let's check if we can submit a bearing for the starting point to generate a better route
if(drivenRoute.coordinates.length >= 2){
// We can calculate the current bearing. Let's do so:
var bearing = getBearing(drivenRoute.coordinates[drivenRoute.coordinates.length-2], drivenRoute.coordinates[drivenRoute.coordinates.length-1]);
bearing = Math.round(bearing);
url += "/" + bearing;
}
$.getJSON(url, function(response) {
route = response;
startLocationFollowing();
......@@ -2981,7 +2992,11 @@ function getBearing(p1, p2) {
var x = Math.cos(p2r[1]) * Math.sin(p2r[0] - p1r[0]);
var y = Math.cos(p1r[1]) * Math.sin(p2r[1]) - Math.sin(p1r[1]) * Math.cos(p2r[1]) * Math.cos(p2r[0] - p1r[0]);
var bearing = Math.atan2(x, y);
return toDegrees(bearing);
bearing = toDegrees(bearing);
if(bearing < 0){
bearing += 360;
}
return bearing;
}
 
function toRadians(angle) {
......
This diff is collapsed.
......@@ -6,5 +6,5 @@
"js/findRoute.js": "js/findRoute-af66afdfbb.js",
"js/iframeSearch.js": "js/iframeSearch-b031528ebf.js",
"js/mapSearch.js": "js/mapSearch-45bfc7f759.js",
"js/routing.js": "js/routing-03ab4ff6f6.js"
"js/routing.js": "js/routing-eb8054ae29.js"
}
\ No newline at end of file
......@@ -2786,7 +2786,18 @@ function startLocationFollowing() {
}
});
pointString = pointString.replace(/;$/, '');
var url = '/route/find/' + vehicle + '/' + pointString;
// Let's check if we can submit a bearing for the starting point to generate a better route
if(drivenRoute.coordinates.length >= 2){
// We can calculate the current bearing. Let's do so:
var bearing = getBearing(drivenRoute.coordinates[drivenRoute.coordinates.length-2], drivenRoute.coordinates[drivenRoute.coordinates.length-1]);
bearing = Math.round(bearing);
url += "/" + bearing;
}
$.getJSON(url, function(response) {
route = response;
startLocationFollowing();
......@@ -2981,7 +2992,11 @@ function getBearing(p1, p2) {
var x = Math.cos(p2r[1]) * Math.sin(p2r[0] - p1r[0]);
var y = Math.cos(p1r[1]) * Math.sin(p2r[1]) - Math.sin(p1r[1]) * Math.cos(p2r[1]) * Math.cos(p2r[0] - p1r[0]);
var bearing = Math.atan2(x, y);
return toDegrees(bearing);
bearing = toDegrees(bearing);
if(bearing < 0){
bearing += 360;
}
return bearing;
}
 
function toRadians(angle) {
......
This diff is collapsed.
......@@ -289,7 +289,18 @@ function startLocationFollowing() {
}
});
pointString = pointString.replace(/;$/, '');
var url = '/route/find/' + vehicle + '/' + pointString;
// Let's check if we can submit a bearing for the starting point to generate a better route
if(drivenRoute.coordinates.length >= 2){
// We can calculate the current bearing. Let's do so:
var bearing = getBearing(drivenRoute.coordinates[drivenRoute.coordinates.length-2], drivenRoute.coordinates[drivenRoute.coordinates.length-1]);
bearing = Math.round(bearing);
url += "/" + bearing;
}
$.getJSON(url, function(response) {
route = response;
startLocationFollowing();
......@@ -484,7 +495,11 @@ function getBearing(p1, p2) {
var x = Math.cos(p2r[1]) * Math.sin(p2r[0] - p1r[0]);
var y = Math.cos(p1r[1]) * Math.sin(p2r[1]) - Math.sin(p1r[1]) * Math.cos(p2r[1]) * Math.cos(p2r[0] - p1r[0]);
var bearing = Math.atan2(x, y);
return toDegrees(bearing);
bearing = toDegrees(bearing);
if(bearing < 0){
bearing += 360;
}
return bearing;
}
function toRadians(angle) {
......
......@@ -52,7 +52,7 @@ Route::group(['prefix' => 'hilfe'], function () {
Route::group(['prefix' => 'route'], function () {
Route::get('preview/{vehicle}/{points}', 'RoutingController@routingOverviewGeoJson');
Route::get('find/{vehicle}/{points}/{hints?}', 'RoutingController@routingGeoJson');
Route::get('find/{vehicle}/{points}/{startBearing?}', 'RoutingController@routingGeoJson');
Route::get('match/{vehicle}/{points}/{timestamp}/{radiuses}', 'RoutingController@match');
Route::get('start/{vehicle}/{points?}', function ($vehicle, $points = "") {
$waypoints = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment