From 90bd34d8ac47b39780c566973d6649bae6c6e71c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 19 Apr 2011 16:03:48 +0000 Subject: [PATCH] Support for additional parameter '&simplified=yes' that outputs a simplified geometry that does not depict all of the small road segments but omits some. Usually, this is not visible to the user. --- Plugins/JSONDescriptor.h | 29 ++++++++++++++++------------- Plugins/KMLDescriptor.h | 24 ++++++++++++++---------- Plugins/RoutePlugin.h | 17 ++++++++++++++--- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/Plugins/JSONDescriptor.h b/Plugins/JSONDescriptor.h index 7d197dc3c..d0e2ec025 100644 --- a/Plugins/JSONDescriptor.h +++ b/Plugins/JSONDescriptor.h @@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef JSONDESCRIPTOR_H_ #define JSONDESCRIPTOR_H_ -template +template class JSONDescriptor : public BaseDescriptor { public: void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) { @@ -102,7 +102,7 @@ public: position++; _Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon); - _Coordinate next, current, lastPlace; + _Coordinate next, current, lastPlace, startOfSegment; stringstream numberString; stringstream intNumberString; @@ -118,14 +118,7 @@ public: short prevType = SHRT_MAX; for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) { sEngine->getNodeInfo(it->node, current); - convertLatLon(current.lat, tmp); - routeGeometryString += " ["; - routeGeometryString += tmp; - routeGeometryString += ", "; - convertLatLon(current.lon, tmp); - routeGeometryString += tmp; - routeGeometryString += "],\n"; - position++; + startOfSegment = previous; if(it==path->end()-1){ next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon); @@ -138,7 +131,18 @@ public: nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node); durationOfInstruction += sEngine->GetWeightForOriginDestinationNodeID(it->node, (it+1)->node); } - + double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next); + if(178 > angle || 182 < angle || false == SimplifyRoute) { + convertLatLon(current.lat, tmp); + routeGeometryString += " ["; + routeGeometryString += tmp; + routeGeometryString += ", "; + convertLatLon(current.lon, tmp); + routeGeometryString += tmp; + routeGeometryString += "],\n"; + position++; + startOfSegment = current; + } if(nextID == nameID) { tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon); } else { @@ -182,8 +186,7 @@ public: lastPlace = current; routeInstructionString += " [\""; - double angle = GetAngleBetweenTwoEdges(previous, current, next); - if(angle > 160 && angle < 200) { + if(angle > 160 && angle < 200) { routeInstructionString += /* " (" << angle << ")*/"Continue"; } else if (angle > 290 && angle <= 360) { routeInstructionString += /*" (" << angle << ")*/ "Turn sharp left"; diff --git a/Plugins/KMLDescriptor.h b/Plugins/KMLDescriptor.h index 7e93fbcbe..9c2694526 100644 --- a/Plugins/KMLDescriptor.h +++ b/Plugins/KMLDescriptor.h @@ -21,7 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef KML_DESCRIPTOR_H_ #define KML_DESCRIPTOR_H_ -template +template class KMLDescriptor : public BaseDescriptor{ public: void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) { @@ -80,7 +80,7 @@ public: reply.content += ("\t\n"); _Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon); - _Coordinate next, current, lastPlace; + _Coordinate next, current, lastPlace, startOfSegment; stringstream numberString; double tempDist = 0; @@ -96,13 +96,7 @@ public: reply.content += "\t\n\t\t::iterator it = path->begin(); it != path->end(); it++) { sEngine->getNodeInfo(it->node, current); - convertLatLon(current.lon, tmp); - lineString += tmp; - lineString += ","; - convertLatLon(current.lat, tmp); - lineString += tmp; - lineString += " "; - + startOfSegment = previous; if(it==path->end()-1){ next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon); nextID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2); @@ -113,6 +107,16 @@ public: nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node); } + double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next); + if(178 > angle || 182 < angle || false == SimplifyRoute) { + convertLatLon(current.lon, tmp); + lineString += tmp; + lineString += ","; + convertLatLon(current.lat, tmp); + lineString += tmp; + lineString += " "; + startOfSegment = current; + } if(nextID == nameID) { tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon); @@ -122,7 +126,7 @@ public: if(type != 0 && prevType == 0 ) reply.content += "leave motorway and "; - double angle = GetAngleBetweenTwoEdges(previous, current, next); + //double angle = GetAngleBetweenTwoEdges(previous, current, next); reply.content += "follow road "; if(nameID != 0) reply.content += sEngine->GetNameForNameID(nameID); diff --git a/Plugins/RoutePlugin.h b/Plugins/RoutePlugin.h index 250a696aa..c97ffc631 100644 --- a/Plugins/RoutePlugin.h +++ b/Plugins/RoutePlugin.h @@ -126,15 +126,26 @@ public: reply.content += "(\n"; } unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")]; + const bool simplifiedRoute = (routeParameters.options.Find("simplified") == "yes"); + //todo: put options in a seperate struct and pass it to the descriptor switch(descriptorType){ case 0: - desc = new KMLDescriptor > >(); + if(simplifiedRoute) + desc = new KMLDescriptor >, true >(); + else + desc = new KMLDescriptor >, false >(); break; case 1: - desc = new JSONDescriptor > >(); + if(simplifiedRoute) + desc = new JSONDescriptor >, true >(); + else + desc = new JSONDescriptor >, false >(); break; default: - desc = new KMLDescriptor > >(); + if(simplifiedRoute) + desc = new KMLDescriptor >, true >(); + else + desc = new KMLDescriptor >, false >(); break; }