Change of API.

This commit is contained in:
DennisOSRM 2012-03-05 17:42:35 +01:00
commit 91c9cb2114
6 changed files with 84 additions and 25 deletions

View File

@ -0,0 +1,58 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef OBJECTTOBASE64_H_
#define OBJECTTOBASE64_H_
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/foreach.hpp>
#include <algorithm>
#include <string>
#include "../Util/StringUtil.h"
typedef
boost::archive::iterators::base64_from_binary<
boost::archive::iterators::transform_width<string::const_iterator, 6, 8>
> base64_t;
typedef
boost::archive::iterators::transform_width<
boost::archive::iterators::binary_from_base64<string::const_iterator>, 8, 6
> binary_t;
template<class ToEncodeT>
static void EncodeObjectToBase64(const ToEncodeT & object, std::string& encoded) {
assert(0 == encoded.length());
char * pointerToOriginalObject = (char *)&object;
encoded = std::string(base64_t(pointerToOriginalObject), base64_t(pointerToOriginalObject+sizeof(ToEncodeT)));
}
template<class ToEncodeT>
static void DecodeObjectFraBase64(ToEncodeT & object, const std::string& encoded) {
char * pointerToDecodedObject = (char *)&object;
std::string dec(binary_t(encoded.begin()), binary_t(encoded.begin() + encoded.length() - 1));
std::copy ( dec.begin(), dec.end(), pointerToDecodedObject );
}
#endif /* OBJECTTOBASE64_H_ */

View File

@ -21,10 +21,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef JSON_DESCRIPTOR_H_
#define JSON_DESCRIPTOR_H_
#include <boost/foreach.hpp>
#include <algorithm>
#include "BaseDescriptor.h"
#include "DescriptionFactory.h"
#include "../Algorithms/ObjectToBase64.h"
#include "../DataStructures/SegmentInformation.h"
#include "../DataStructures/TurnInstructions.h"
#include "../Util/Azimuth.h"
@ -173,14 +174,17 @@ public:
reply.content += ", \"hint_array\": [";
for(unsigned i = 0; i < rawRoute.segmentEndCoordinates.size(); ++i) {
unsigned hint = ((rawRoute.segmentEndCoordinates[i].startPhantom.edgeBasedNode << 1) + rawRoute.segmentEndCoordinates[i].startPhantom.isBidirected());
intToString(hint, tmp);
reply.content += tmp;
reply.content += ", ";
std::string hint;
reply.content += "\"";
EncodeObjectToBase64(rawRoute.segmentEndCoordinates[i].startPhantom, hint);
reply.content += hint;
reply.content += "\", ";
}
intToString(((rawRoute.segmentEndCoordinates.back().targetPhantom.edgeBasedNode << 1)+ rawRoute.segmentEndCoordinates.back().targetPhantom.isBidirected()), tmp);
reply.content += tmp;
reply.content += "]";
std::string hint;
EncodeObjectToBase64(rawRoute.segmentEndCoordinates.back().targetPhantom, hint);
reply.content += "\"";
reply.content += hint;
reply.content += "\"]";
reply.content += "},";
reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.3)\"";
reply.content += "}";

View File

@ -29,7 +29,7 @@
//======================
// OBJECTS
//Map
var HOST_ROUTING_URL = 'http://141.3.24.68:5000/viaroute';
var HOST_ROUTING_URL = 'http://localhost:5000/viaroute';
//var HOST_ROUTING_URL = 'http://routingdemo.geofabrik.de/route-via/';
var HOST_WEBSITE = 'http://map.project-osrm.org/';//location.host
@ -79,10 +79,11 @@ function routing(isDragRoute){
document.getElementById('information').innerHTML = '<p class="infoHL">Release mouse button to get Route Information!</p>(If no Route Summary is diplayed, press the Route!-button)';
}
script.src = HOST_ROUTING_URL + "?start="+from.lat + ',' + from.lon + '&dest=' + to.lat + ',' + to.lon;
script.src = HOST_ROUTING_URL + "?loc="+from.lat + ',' + from.lon;
for(var i = 0; i < viaPointsVector.length; i++) {
script.src += ('&via=' + viaPointsVector[i][0] + ',' + viaPointsVector[i][1]);
script.src += ('&loc=' + viaPointsVector[i][0] + ',' + viaPointsVector[i][1]);
}
script.src += '&loc=' + to.lat + ',' + to.lon;
script.src +='&z='+this.map.getZoom()+'&output=json&jsonp='+callBackFunction+instructions;
document.body.appendChild(script);
}
@ -139,10 +140,11 @@ function showResultsRoute(response) {
routelink += '\');" value="Get Link"></div>';
//Link for the GPX Download
var gpxLink = '(<a href="'+HOST_ROUTING_URL+'?start='+from.lat.toFixed(6)+','+from.lon.toFixed(6)+'&dest='+to.lat.toFixed(6)+','+to.lon.toFixed(6)+'&z='+this.map.getZoom();
var gpxLink = '(<a href="'+HOST_ROUTING_URL+'?loc='+from.lat.toFixed(6)+','+from.lon.toFixed(6);
for(i = 0; i < viaPointsVector.length; i++) {
gpxLink += "&via=" + viaPointsVector[i][0] + "," + viaPointsVector[i][1];
gpxLink += "&loc=" + viaPointsVector[i][0] + "," + viaPointsVector[i][1];
}
gpxLink += '&loc='+to.lat.toFixed(6)+','+to.lon.toFixed(6)+'&z='+this.map.getZoom()
gpxLink += '&output=gpx">Get GPX File</a>)';;
       //Show Route Summary

View File

@ -240,20 +240,21 @@ function computeViaRoute(pixel, isTemporary, skipViaPointsIndex) {
var coordinate = map.getLonLatFromPixel(pixel);
var via = coordinate.transform(EPSG_900913, EPSG_4326);
var viaNodeInserted = false;
var newURL = HOST_ROUTING_URL + "?start="+from.lat + ',' + from.lon + '&dest=' + to.lat + ',' + to.lon;
var newURL = HOST_ROUTING_URL + "?loc="+from.lat + ',' + from.lon;
newURL += '&geomformat=cmp';
for(var i = 0; i < viaPointsVector.length; i++) {
if(i == nearestSegmentIndex) { //insert new via node here
newURL += '&via=' + via.lat + ',' + via.lon;
newURL += '&loc=' + via.lat + ',' + via.lon;
viaNodeInserted = true;
}
if(skipViaPointsIndex == i)
continue;
newURL += '&via=' + viaPointsVector[i][0] + ',' + viaPointsVector[i][1];
newURL += '&loc=' + viaPointsVector[i][0] + ',' + viaPointsVector[i][1];
}
if(false == viaNodeInserted) {
newURL += '&via=' + via.lat + ',' + via.lon;
newURL += '&loc=' + via.lat + ',' + via.lon;
}
newURL += '&loc=' + to.lat + ',' + to.lon;
newURL += '&output=json' + '&z=' + this.map.getZoom();
if(!isTemporary) {
newURL += '&instructions=true&jsonp=showResultsRoute';

View File

@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../DataStructures/HashTable.h"
struct RouteParameters {
std::vector<unsigned> hints;
std::vector<std::string> hints;
std::vector<std::string> parameters;
std::vector<std::string> viaPoints;
HashTable<std::string, std::string> options;

View File

@ -85,13 +85,7 @@ public:
}
} else if("hint" == p) {
routeParameters.hints.resize(routeParameters.viaPoints.size(), 0);
if(routeParameters.hints.size()) {
unsigned hint = 0;
try {
hint = 10*boost::lexical_cast<int>(o);
} catch(boost::bad_lexical_cast &) { /* do nothing since hint is initialized to 0 */}
routeParameters.hints.back() = hint;
}
routeParameters.hints.back() = o;
} else {
routeParameters.options.Set(p, o);
}