Change of API.
This commit is contained in:
commit
91c9cb2114
58
Algorithms/ObjectToBase64.h
Normal file
58
Algorithms/ObjectToBase64.h
Normal 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_ */
|
@ -21,10 +21,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#ifndef JSON_DESCRIPTOR_H_
|
#ifndef JSON_DESCRIPTOR_H_
|
||||||
#define JSON_DESCRIPTOR_H_
|
#define JSON_DESCRIPTOR_H_
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "BaseDescriptor.h"
|
#include "BaseDescriptor.h"
|
||||||
#include "DescriptionFactory.h"
|
#include "DescriptionFactory.h"
|
||||||
|
#include "../Algorithms/ObjectToBase64.h"
|
||||||
#include "../DataStructures/SegmentInformation.h"
|
#include "../DataStructures/SegmentInformation.h"
|
||||||
#include "../DataStructures/TurnInstructions.h"
|
#include "../DataStructures/TurnInstructions.h"
|
||||||
#include "../Util/Azimuth.h"
|
#include "../Util/Azimuth.h"
|
||||||
@ -173,14 +174,17 @@ public:
|
|||||||
reply.content += ", \"hint_array\": [";
|
reply.content += ", \"hint_array\": [";
|
||||||
|
|
||||||
for(unsigned i = 0; i < rawRoute.segmentEndCoordinates.size(); ++i) {
|
for(unsigned i = 0; i < rawRoute.segmentEndCoordinates.size(); ++i) {
|
||||||
unsigned hint = ((rawRoute.segmentEndCoordinates[i].startPhantom.edgeBasedNode << 1) + rawRoute.segmentEndCoordinates[i].startPhantom.isBidirected());
|
std::string hint;
|
||||||
intToString(hint, tmp);
|
reply.content += "\"";
|
||||||
reply.content += tmp;
|
EncodeObjectToBase64(rawRoute.segmentEndCoordinates[i].startPhantom, hint);
|
||||||
reply.content += ", ";
|
reply.content += hint;
|
||||||
|
reply.content += "\", ";
|
||||||
}
|
}
|
||||||
intToString(((rawRoute.segmentEndCoordinates.back().targetPhantom.edgeBasedNode << 1)+ rawRoute.segmentEndCoordinates.back().targetPhantom.isBidirected()), tmp);
|
std::string hint;
|
||||||
reply.content += tmp;
|
EncodeObjectToBase64(rawRoute.segmentEndCoordinates.back().targetPhantom, hint);
|
||||||
reply.content += "]";
|
reply.content += "\"";
|
||||||
|
reply.content += hint;
|
||||||
|
reply.content += "\"]";
|
||||||
reply.content += "},";
|
reply.content += "},";
|
||||||
reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.3)\"";
|
reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.3)\"";
|
||||||
reply.content += "}";
|
reply.content += "}";
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
//======================
|
//======================
|
||||||
// OBJECTS
|
// OBJECTS
|
||||||
//Map
|
//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_ROUTING_URL = 'http://routingdemo.geofabrik.de/route-via/';
|
||||||
var HOST_WEBSITE = 'http://map.project-osrm.org/';//location.host
|
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)';
|
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++) {
|
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;
|
script.src +='&z='+this.map.getZoom()+'&output=json&jsonp='+callBackFunction+instructions;
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
}
|
}
|
||||||
@ -139,10 +140,11 @@ function showResultsRoute(response) {
|
|||||||
routelink += '\');" value="Get Link"></div>';
|
routelink += '\');" value="Get Link"></div>';
|
||||||
|
|
||||||
//Link for the GPX Download
|
//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++) {
|
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>)';;
|
gpxLink += '&output=gpx">Get GPX File</a>)';;
|
||||||
|
|
||||||
//Show Route Summary
|
//Show Route Summary
|
||||||
|
@ -240,20 +240,21 @@ function computeViaRoute(pixel, isTemporary, skipViaPointsIndex) {
|
|||||||
var coordinate = map.getLonLatFromPixel(pixel);
|
var coordinate = map.getLonLatFromPixel(pixel);
|
||||||
var via = coordinate.transform(EPSG_900913, EPSG_4326);
|
var via = coordinate.transform(EPSG_900913, EPSG_4326);
|
||||||
var viaNodeInserted = false;
|
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';
|
newURL += '&geomformat=cmp';
|
||||||
for(var i = 0; i < viaPointsVector.length; i++) {
|
for(var i = 0; i < viaPointsVector.length; i++) {
|
||||||
if(i == nearestSegmentIndex) { //insert new via node here
|
if(i == nearestSegmentIndex) { //insert new via node here
|
||||||
newURL += '&via=' + via.lat + ',' + via.lon;
|
newURL += '&loc=' + via.lat + ',' + via.lon;
|
||||||
viaNodeInserted = true;
|
viaNodeInserted = true;
|
||||||
}
|
}
|
||||||
if(skipViaPointsIndex == i)
|
if(skipViaPointsIndex == i)
|
||||||
continue;
|
continue;
|
||||||
newURL += '&via=' + viaPointsVector[i][0] + ',' + viaPointsVector[i][1];
|
newURL += '&loc=' + viaPointsVector[i][0] + ',' + viaPointsVector[i][1];
|
||||||
}
|
}
|
||||||
if(false == viaNodeInserted) {
|
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();
|
newURL += '&output=json' + '&z=' + this.map.getZoom();
|
||||||
if(!isTemporary) {
|
if(!isTemporary) {
|
||||||
newURL += '&instructions=true&jsonp=showResultsRoute';
|
newURL += '&instructions=true&jsonp=showResultsRoute';
|
||||||
|
@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../DataStructures/HashTable.h"
|
#include "../DataStructures/HashTable.h"
|
||||||
|
|
||||||
struct RouteParameters {
|
struct RouteParameters {
|
||||||
std::vector<unsigned> hints;
|
std::vector<std::string> hints;
|
||||||
std::vector<std::string> parameters;
|
std::vector<std::string> parameters;
|
||||||
std::vector<std::string> viaPoints;
|
std::vector<std::string> viaPoints;
|
||||||
HashTable<std::string, std::string> options;
|
HashTable<std::string, std::string> options;
|
||||||
|
@ -85,13 +85,7 @@ public:
|
|||||||
}
|
}
|
||||||
} else if("hint" == p) {
|
} else if("hint" == p) {
|
||||||
routeParameters.hints.resize(routeParameters.viaPoints.size(), 0);
|
routeParameters.hints.resize(routeParameters.viaPoints.size(), 0);
|
||||||
if(routeParameters.hints.size()) {
|
routeParameters.hints.back() = o;
|
||||||
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;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
routeParameters.options.Set(p, o);
|
routeParameters.options.Set(p, o);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user