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.
This commit is contained in:
parent
fb2a414839
commit
90bd34d8ac
@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef JSONDESCRIPTOR_H_
|
#ifndef JSONDESCRIPTOR_H_
|
||||||
#define JSONDESCRIPTOR_H_
|
#define JSONDESCRIPTOR_H_
|
||||||
|
|
||||||
template<class SearchEngineT>
|
template<class SearchEngineT, bool SimplifyRoute = false>
|
||||||
class JSONDescriptor : public BaseDescriptor<SearchEngineT> {
|
class JSONDescriptor : public BaseDescriptor<SearchEngineT> {
|
||||||
public:
|
public:
|
||||||
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
||||||
@ -102,7 +102,7 @@ public:
|
|||||||
position++;
|
position++;
|
||||||
|
|
||||||
_Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon);
|
_Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon);
|
||||||
_Coordinate next, current, lastPlace;
|
_Coordinate next, current, lastPlace, startOfSegment;
|
||||||
stringstream numberString;
|
stringstream numberString;
|
||||||
stringstream intNumberString;
|
stringstream intNumberString;
|
||||||
|
|
||||||
@ -118,14 +118,7 @@ public:
|
|||||||
short prevType = SHRT_MAX;
|
short prevType = SHRT_MAX;
|
||||||
for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) {
|
for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) {
|
||||||
sEngine->getNodeInfo(it->node, current);
|
sEngine->getNodeInfo(it->node, current);
|
||||||
convertLatLon(current.lat, tmp);
|
startOfSegment = previous;
|
||||||
routeGeometryString += " [";
|
|
||||||
routeGeometryString += tmp;
|
|
||||||
routeGeometryString += ", ";
|
|
||||||
convertLatLon(current.lon, tmp);
|
|
||||||
routeGeometryString += tmp;
|
|
||||||
routeGeometryString += "],\n";
|
|
||||||
position++;
|
|
||||||
|
|
||||||
if(it==path->end()-1){
|
if(it==path->end()-1){
|
||||||
next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
||||||
@ -138,7 +131,18 @@ public:
|
|||||||
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node);
|
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node);
|
||||||
durationOfInstruction += sEngine->GetWeightForOriginDestinationNodeID(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) {
|
if(nextID == nameID) {
|
||||||
tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon);
|
tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon);
|
||||||
} else {
|
} else {
|
||||||
@ -182,8 +186,7 @@ public:
|
|||||||
lastPlace = current;
|
lastPlace = current;
|
||||||
routeInstructionString += " [\"";
|
routeInstructionString += " [\"";
|
||||||
|
|
||||||
double angle = GetAngleBetweenTwoEdges(previous, current, next);
|
if(angle > 160 && angle < 200) {
|
||||||
if(angle > 160 && angle < 200) {
|
|
||||||
routeInstructionString += /* " (" << angle << ")*/"Continue";
|
routeInstructionString += /* " (" << angle << ")*/"Continue";
|
||||||
} else if (angle > 290 && angle <= 360) {
|
} else if (angle > 290 && angle <= 360) {
|
||||||
routeInstructionString += /*" (" << angle << ")*/ "Turn sharp left";
|
routeInstructionString += /*" (" << angle << ")*/ "Turn sharp left";
|
||||||
|
@ -21,7 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef KML_DESCRIPTOR_H_
|
#ifndef KML_DESCRIPTOR_H_
|
||||||
#define KML_DESCRIPTOR_H_
|
#define KML_DESCRIPTOR_H_
|
||||||
|
|
||||||
template<class SearchEngineT>
|
template<class SearchEngineT, bool SimplifyRoute = false>
|
||||||
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
|
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
|
||||||
public:
|
public:
|
||||||
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
|
||||||
@ -80,7 +80,7 @@ public:
|
|||||||
|
|
||||||
reply.content += ("\t</Placemark>\n");
|
reply.content += ("\t</Placemark>\n");
|
||||||
_Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon);
|
_Coordinate previous(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon);
|
||||||
_Coordinate next, current, lastPlace;
|
_Coordinate next, current, lastPlace, startOfSegment;
|
||||||
stringstream numberString;
|
stringstream numberString;
|
||||||
|
|
||||||
double tempDist = 0;
|
double tempDist = 0;
|
||||||
@ -96,13 +96,7 @@ public:
|
|||||||
reply.content += "\t<Placemark>\n\t\t<name><![CDATA[";
|
reply.content += "\t<Placemark>\n\t\t<name><![CDATA[";
|
||||||
for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) {
|
for(vector< _PathData >::iterator it = path->begin(); it != path->end(); it++) {
|
||||||
sEngine->getNodeInfo(it->node, current);
|
sEngine->getNodeInfo(it->node, current);
|
||||||
convertLatLon(current.lon, tmp);
|
startOfSegment = previous;
|
||||||
lineString += tmp;
|
|
||||||
lineString += ",";
|
|
||||||
convertLatLon(current.lat, tmp);
|
|
||||||
lineString += tmp;
|
|
||||||
lineString += " ";
|
|
||||||
|
|
||||||
if(it==path->end()-1){
|
if(it==path->end()-1){
|
||||||
next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
next = _Coordinate(phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon);
|
||||||
nextID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
nextID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
@ -113,6 +107,16 @@ public:
|
|||||||
nextType = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(it->node, (it+1)->node);
|
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) {
|
if(nextID == nameID) {
|
||||||
tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon);
|
tempDist += ApproximateDistance(previous.lat, previous.lon, current.lat, current.lon);
|
||||||
@ -122,7 +126,7 @@ public:
|
|||||||
if(type != 0 && prevType == 0 )
|
if(type != 0 && prevType == 0 )
|
||||||
reply.content += "leave motorway and ";
|
reply.content += "leave motorway and ";
|
||||||
|
|
||||||
double angle = GetAngleBetweenTwoEdges(previous, current, next);
|
//double angle = GetAngleBetweenTwoEdges(previous, current, next);
|
||||||
reply.content += "follow road ";
|
reply.content += "follow road ";
|
||||||
if(nameID != 0)
|
if(nameID != 0)
|
||||||
reply.content += sEngine->GetNameForNameID(nameID);
|
reply.content += sEngine->GetNameForNameID(nameID);
|
||||||
|
@ -126,15 +126,26 @@ public:
|
|||||||
reply.content += "(\n";
|
reply.content += "(\n";
|
||||||
}
|
}
|
||||||
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
|
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){
|
switch(descriptorType){
|
||||||
case 0:
|
case 0:
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
if(simplifiedRoute)
|
||||||
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
|
||||||
|
else
|
||||||
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
if(simplifiedRoute)
|
||||||
|
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
|
||||||
|
else
|
||||||
|
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
if(simplifiedRoute)
|
||||||
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true >();
|
||||||
|
else
|
||||||
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false >();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user