introducing &instructions=true/false. Configuration of Descriptor refactored
This commit is contained in:
parent
1cbf2ab0d7
commit
689b447990
@ -31,6 +31,13 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
#include "../Util/StrIngUtil.h"
|
#include "../Util/StrIngUtil.h"
|
||||||
|
|
||||||
|
struct DescriptorConfig {
|
||||||
|
DescriptorConfig() : instructions(true), geometry(true), z(18) {}
|
||||||
|
bool instructions;
|
||||||
|
bool geometry;
|
||||||
|
unsigned short z;
|
||||||
|
};
|
||||||
|
|
||||||
template<class SearchEngineT>
|
template<class SearchEngineT>
|
||||||
class BaseDescriptor {
|
class BaseDescriptor {
|
||||||
public:
|
public:
|
||||||
@ -38,7 +45,7 @@ public:
|
|||||||
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
|
||||||
virtual ~BaseDescriptor() { }
|
virtual ~BaseDescriptor() { }
|
||||||
virtual void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) = 0;
|
virtual void Run(http::Reply& reply, std::vector< _PathData > * path, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) = 0;
|
||||||
virtual void SetZoom(const unsigned short z) = 0;
|
virtual void SetConfig(const DescriptorConfig config) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,18 +23,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef JSONDESCRIPTOR_H_
|
#ifndef JSONDESCRIPTOR_H_
|
||||||
#define JSONDESCRIPTOR_H_
|
#define JSONDESCRIPTOR_H_
|
||||||
|
|
||||||
static double areaThresholds[19] = { 5000, 5000, 5000, 5000, 5000, 2500, 2000, 1500, 800, 400, 250, 150, 100, 75, 25, 20, 10, 5 };
|
static double areaThresholds[19] = { 5000, 5000, 5000, 5000, 5000, 2500, 2000, 1500, 800, 400, 250, 150, 100, 75, 25, 20, 10, 5, 0 };
|
||||||
|
|
||||||
template<class SearchEngineT, bool GeometryOn = true, bool InstructionsOn = true>
|
template<class SearchEngineT>
|
||||||
class JSONDescriptor : public BaseDescriptor<SearchEngineT> {
|
class JSONDescriptor : public BaseDescriptor<SearchEngineT> {
|
||||||
private:
|
private:
|
||||||
short zoom;
|
DescriptorConfig config;
|
||||||
public:
|
public:
|
||||||
JSONDescriptor() : zoom(18) {}
|
JSONDescriptor() {}
|
||||||
void SetZoom(const unsigned short z) {
|
void SetConfig(const DescriptorConfig c) {
|
||||||
if(z > 19)
|
config = c;
|
||||||
zoom = 19;
|
|
||||||
zoom = z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@ -148,7 +146,7 @@ public:
|
|||||||
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
|
double angle = GetAngleBetweenTwoEdges(startOfSegment, current, next);
|
||||||
double area = fabs(0.5*( startOfSegment.lon*(current.lat - next.lat) + current.lon*(next.lat - startOfSegment.lat) + next.lon*(startOfSegment.lat - current.lat) ) );
|
double area = fabs(0.5*( startOfSegment.lon*(current.lat - next.lat) + current.lon*(next.lat - startOfSegment.lat) + next.lon*(startOfSegment.lat - current.lat) ) );
|
||||||
// std::cout << "Area for: " << area << std::endl;
|
// std::cout << "Area for: " << area << std::endl;
|
||||||
if(area > areaThresholds[zoom] || 19 == zoom) {
|
if(area > areaThresholds[config.z] || 19 == config.z) {
|
||||||
painted++;
|
painted++;
|
||||||
convertLatLon(current.lat, tmp);
|
convertLatLon(current.lat, tmp);
|
||||||
routeGeometryString += "[";
|
routeGeometryString += "[";
|
||||||
@ -171,7 +169,7 @@ public:
|
|||||||
routeInstructionString += ",enter motorway and ";
|
routeInstructionString += ",enter motorway and ";
|
||||||
if(type != 0 && prevType == 0 )
|
if(type != 0 && prevType == 0 )
|
||||||
routeInstructionString += ",leave motorway and ";
|
routeInstructionString += ",leave motorway and ";
|
||||||
routeInstructionString += " on ";
|
routeInstructionString += "\", \"";
|
||||||
if(nameID != 0)
|
if(nameID != 0)
|
||||||
routeInstructionString += sEngine->GetEscapedNameForNameID(nameID);
|
routeInstructionString += sEngine->GetEscapedNameForNameID(nameID);
|
||||||
routeInstructionString += "\",";
|
routeInstructionString += "\",";
|
||||||
@ -236,7 +234,7 @@ public:
|
|||||||
nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
type = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
type = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
durationOfInstruction += sEngine->GetWeightForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
durationOfInstruction += sEngine->GetWeightForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
routeInstructionString += " at ";
|
routeInstructionString += "\", \"";
|
||||||
routeInstructionString += sEngine->GetEscapedNameForNameID(nameID);
|
routeInstructionString += sEngine->GetEscapedNameForNameID(nameID);
|
||||||
routeInstructionString += "\",";
|
routeInstructionString += "\",";
|
||||||
distanceOfInstruction = ApproximateDistance(previous.lat, previous.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon) + tempDist;
|
distanceOfInstruction = ApproximateDistance(previous.lat, previous.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon) + tempDist;
|
||||||
@ -282,7 +280,6 @@ public:
|
|||||||
routeSummaryString += "\"total_distance\":";
|
routeSummaryString += "\"total_distance\":";
|
||||||
routeSummaryString += s.str();
|
routeSummaryString += s.str();
|
||||||
|
|
||||||
|
|
||||||
routeSummaryString += ",\"total_time\":";
|
routeSummaryString += ",\"total_time\":";
|
||||||
//give travel time in minutes
|
//give travel time in minutes
|
||||||
int travelTime = distance;
|
int travelTime = distance;
|
||||||
@ -308,12 +305,12 @@ public:
|
|||||||
reply.content += routeSummaryString;
|
reply.content += routeSummaryString;
|
||||||
reply.content += "},";
|
reply.content += "},";
|
||||||
reply.content += "\"route_geometry\": [";
|
reply.content += "\"route_geometry\": [";
|
||||||
if(GeometryOn) {
|
if(config.geometry) {
|
||||||
reply.content += routeGeometryString;
|
reply.content += routeGeometryString;
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content += "],";
|
||||||
reply.content += "\"route_instructions\": [";
|
reply.content += "\"route_instructions\": [";
|
||||||
if(GeometryOn || InstructionsOn) {
|
if(config.geometry || config.instructions) {
|
||||||
reply.content += routeInstructionString;
|
reply.content += routeInstructionString;
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content += "],";
|
||||||
|
@ -21,10 +21,14 @@ 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, bool Geometry = true>
|
#include "BaseDescriptor.h"
|
||||||
|
|
||||||
|
template<class SearchEngineT>
|
||||||
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
|
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
|
||||||
|
private:
|
||||||
|
DescriptorConfig config;
|
||||||
public:
|
public:
|
||||||
void SetZoom(const unsigned short z) { }
|
void SetConfig(const DescriptorConfig c) { config = c; }
|
||||||
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) {
|
||||||
string tmp;
|
string tmp;
|
||||||
string lineString;
|
string lineString;
|
||||||
@ -38,9 +42,9 @@ public:
|
|||||||
|
|
||||||
if(distance != UINT_MAX) {
|
if(distance != UINT_MAX) {
|
||||||
unsigned streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
|
unsigned streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
|
||||||
startName = sEngine->GetNameForNameID(streetID);
|
startName = sEngine->GetEscapedNameForNameID(streetID);
|
||||||
streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
targetName = sEngine->GetNameForNameID(streetID);
|
targetName = sEngine->GetEscapedNameForNameID(streetID);
|
||||||
|
|
||||||
reply.content += ("\t<Placemark>\n");
|
reply.content += ("\t<Placemark>\n");
|
||||||
reply.content += ("\t\t<name><![CDATA[Start from ");
|
reply.content += ("\t\t<name><![CDATA[Start from ");
|
||||||
@ -130,7 +134,7 @@ public:
|
|||||||
//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->GetEscapedNameForNameID(nameID);
|
||||||
/*
|
/*
|
||||||
reply.content += " (type: ";
|
reply.content += " (type: ";
|
||||||
numberString << type;
|
numberString << type;
|
||||||
@ -186,7 +190,7 @@ public:
|
|||||||
nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
type = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
type = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
|
||||||
reply.content += "follow road ";
|
reply.content += "follow road ";
|
||||||
reply.content += sEngine->GetNameForNameID(nameID);
|
reply.content += sEngine->GetEscapedNameForNameID(nameID);
|
||||||
// reply.content += " (type: ";
|
// reply.content += " (type: ";
|
||||||
// numberString << type;
|
// numberString << type;
|
||||||
// reply.content += numberString.str();
|
// reply.content += numberString.str();
|
||||||
@ -218,7 +222,7 @@ public:
|
|||||||
lineString += ",";
|
lineString += ",";
|
||||||
convertLatLon(phantomNodes->targetCoord.lat, tmp);
|
convertLatLon(phantomNodes->targetCoord.lat, tmp);
|
||||||
lineString += tmp;
|
lineString += tmp;
|
||||||
if(!Geometry){
|
if(!config.geometry){
|
||||||
|
|
||||||
reply.content = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
reply.content = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||||
reply.content += ("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
|
reply.content += ("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
|
||||||
@ -250,7 +254,7 @@ public:
|
|||||||
reply.content += " minutes)]]>"
|
reply.content += " minutes)]]>"
|
||||||
"</description>\n";
|
"</description>\n";
|
||||||
|
|
||||||
if(Geometry) {
|
if(config.geometry) {
|
||||||
|
|
||||||
reply.content += "\t\t<GeometryCollection>\n"
|
reply.content += "\t\t<GeometryCollection>\n"
|
||||||
"\t\t\t<LineString>\n"
|
"\t\t\t<LineString>\n"
|
||||||
|
@ -132,6 +132,7 @@ public:
|
|||||||
reply.content += JSONParameter;
|
reply.content += JSONParameter;
|
||||||
reply.content += "(\n";
|
reply.content += "(\n";
|
||||||
}
|
}
|
||||||
|
DescriptorConfig descriptorConfig;
|
||||||
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
|
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
|
||||||
unsigned short zoom = 18;
|
unsigned short zoom = 18;
|
||||||
if(routeParameters.options.Find("z") != ""){
|
if(routeParameters.options.Find("z") != ""){
|
||||||
@ -139,31 +140,30 @@ public:
|
|||||||
if(18 < zoom)
|
if(18 < zoom)
|
||||||
zoom = 18;
|
zoom = 18;
|
||||||
}
|
}
|
||||||
//todo: put options in a seperate struct and pass it to the descriptor
|
descriptorConfig.z = zoom;
|
||||||
|
if(routeParameters.options.Find("instructions") == "false") {
|
||||||
|
descriptorConfig.instructions = false;
|
||||||
|
}
|
||||||
|
if(routeParameters.options.Find("geometry") == "false" ) {
|
||||||
|
descriptorConfig.geometry = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
switch(descriptorType){
|
switch(descriptorType){
|
||||||
case 0:
|
case 0:
|
||||||
if(geometry)
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
|
|
||||||
else
|
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if(geometry)
|
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
|
|
||||||
else
|
|
||||||
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(geometry)
|
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
|
|
||||||
else
|
|
||||||
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
desc->SetZoom(zoom);
|
desc->SetConfig(descriptorConfig);
|
||||||
desc->Run(reply, path, phantomNodes, sEngine, distance);
|
desc->Run(reply, path, phantomNodes, sEngine, distance);
|
||||||
if("" != JSONParameter) {
|
if("" != JSONParameter) {
|
||||||
reply.content += ")\n";
|
reply.content += ")\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user