introducing &instructions=true/false. Configuration of Descriptor refactored

This commit is contained in:
Dennis Luxen 2011-05-13 09:16:58 +00:00
parent 1cbf2ab0d7
commit 689b447990
4 changed files with 45 additions and 37 deletions

View File

@ -31,6 +31,13 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../DataStructures/HashTable.h"
#include "../Util/StrIngUtil.h"
struct DescriptorConfig {
DescriptorConfig() : instructions(true), geometry(true), z(18) {}
bool instructions;
bool geometry;
unsigned short z;
};
template<class SearchEngineT>
class BaseDescriptor {
public:
@ -38,7 +45,7 @@ public:
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
virtual ~BaseDescriptor() { }
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;
};

View File

@ -23,18 +23,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef 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> {
private:
short zoom;
DescriptorConfig config;
public:
JSONDescriptor() : zoom(18) {}
void SetZoom(const unsigned short z) {
if(z > 19)
zoom = 19;
zoom = z;
JSONDescriptor() {}
void SetConfig(const DescriptorConfig c) {
config = c;
}
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 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;
if(area > areaThresholds[zoom] || 19 == zoom) {
if(area > areaThresholds[config.z] || 19 == config.z) {
painted++;
convertLatLon(current.lat, tmp);
routeGeometryString += "[";
@ -171,7 +169,7 @@ public:
routeInstructionString += ",enter motorway and ";
if(type != 0 && prevType == 0 )
routeInstructionString += ",leave motorway and ";
routeInstructionString += " on ";
routeInstructionString += "\", \"";
if(nameID != 0)
routeInstructionString += sEngine->GetEscapedNameForNameID(nameID);
routeInstructionString += "\",";
@ -236,7 +234,7 @@ public:
nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
type = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
durationOfInstruction += sEngine->GetWeightForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
routeInstructionString += " at ";
routeInstructionString += "\", \"";
routeInstructionString += sEngine->GetEscapedNameForNameID(nameID);
routeInstructionString += "\",";
distanceOfInstruction = ApproximateDistance(previous.lat, previous.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon) + tempDist;
@ -282,7 +280,6 @@ public:
routeSummaryString += "\"total_distance\":";
routeSummaryString += s.str();
routeSummaryString += ",\"total_time\":";
//give travel time in minutes
int travelTime = distance;
@ -308,12 +305,12 @@ public:
reply.content += routeSummaryString;
reply.content += "},";
reply.content += "\"route_geometry\": [";
if(GeometryOn) {
if(config.geometry) {
reply.content += routeGeometryString;
}
reply.content += "],";
reply.content += "\"route_instructions\": [";
if(GeometryOn || InstructionsOn) {
if(config.geometry || config.instructions) {
reply.content += routeInstructionString;
}
reply.content += "],";

View File

@ -21,10 +21,14 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef KML_DESCRIPTOR_H_
#define KML_DESCRIPTOR_H_
template<class SearchEngineT, bool Geometry = true>
#include "BaseDescriptor.h"
template<class SearchEngineT>
class KMLDescriptor : public BaseDescriptor<SearchEngineT>{
private:
DescriptorConfig config;
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) {
string tmp;
string lineString;
@ -38,9 +42,9 @@ public:
if(distance != UINT_MAX) {
unsigned streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startNode1, phantomNodes->startNode2);
startName = sEngine->GetNameForNameID(streetID);
startName = sEngine->GetEscapedNameForNameID(streetID);
streetID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
targetName = sEngine->GetNameForNameID(streetID);
targetName = sEngine->GetEscapedNameForNameID(streetID);
reply.content += ("\t<Placemark>\n");
reply.content += ("\t\t<name><![CDATA[Start from ");
@ -130,7 +134,7 @@ public:
//double angle = GetAngleBetweenTwoEdges(previous, current, next);
reply.content += "follow road ";
if(nameID != 0)
reply.content += sEngine->GetNameForNameID(nameID);
reply.content += sEngine->GetEscapedNameForNameID(nameID);
/*
reply.content += " (type: ";
numberString << type;
@ -186,7 +190,7 @@ public:
nameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
type = sEngine->GetTypeOfEdgeForOriginDestinationNodeID(phantomNodes->targetNode1, phantomNodes->targetNode2);
reply.content += "follow road ";
reply.content += sEngine->GetNameForNameID(nameID);
reply.content += sEngine->GetEscapedNameForNameID(nameID);
// reply.content += " (type: ";
// numberString << type;
// reply.content += numberString.str();
@ -218,7 +222,7 @@ public:
lineString += ",";
convertLatLon(phantomNodes->targetCoord.lat, tmp);
lineString += tmp;
if(!Geometry){
if(!config.geometry){
reply.content = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
reply.content += ("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
@ -250,7 +254,7 @@ public:
reply.content += " minutes)]]>"
"</description>\n";
if(Geometry) {
if(config.geometry) {
reply.content += "\t\t<GeometryCollection>\n"
"\t\t\t<LineString>\n"

View File

@ -132,6 +132,7 @@ public:
reply.content += JSONParameter;
reply.content += "(\n";
}
DescriptorConfig descriptorConfig;
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
unsigned short zoom = 18;
if(routeParameters.options.Find("z") != ""){
@ -139,31 +140,30 @@ public:
if(18 < zoom)
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){
case 0:
if(geometry)
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
else
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
break;
case 1:
if(geometry)
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
else
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
desc = new JSONDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
break;
default:
if(geometry)
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, true>();
else
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> >, false>();
desc = new KMLDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > >();
break;
}
desc->SetZoom(zoom);
desc->SetConfig(descriptorConfig);
desc->Run(reply, path, phantomNodes, sEngine, distance);
if("" != JSONParameter) {
reply.content += ")\n";