2011-11-17 12:56:45 -05:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2011-11-17 12:56:45 -05:00
|
|
|
|
|
|
|
#ifndef GPX_DESCRIPTOR_H_
|
|
|
|
#define GPX_DESCRIPTOR_H_
|
|
|
|
|
|
|
|
#include "BaseDescriptor.h"
|
|
|
|
|
2013-06-26 19:48:22 -04:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2013-06-24 14:12:25 -04:00
|
|
|
class GPXDescriptor : public BaseDescriptor{
|
2011-11-17 12:56:45 -05:00
|
|
|
private:
|
|
|
|
_DescriptorConfig config;
|
2013-08-14 07:12:28 -04:00
|
|
|
FixedPointCoordinate current;
|
2011-11-17 12:56:45 -05:00
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
public:
|
|
|
|
void SetConfig(const _DescriptorConfig& c) { config = c; }
|
2013-06-24 14:12:25 -04:00
|
|
|
void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngine &sEngine) {
|
2011-11-17 12:56:45 -05:00
|
|
|
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
2012-08-13 10:42:55 -04:00
|
|
|
reply.content += "<gpx creator=\"OSRM Routing Engine\" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" "
|
2011-11-17 12:56:45 -05:00
|
|
|
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
|
|
|
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
|
|
|
|
"\">";
|
2013-02-12 04:57:33 -05:00
|
|
|
reply.content += "<metadata><copyright author=\"Project OSRM\"><license>Data (c) OpenStreetMap contributors (ODbL)</license></copyright></metadata>";
|
2011-11-17 12:56:45 -05:00
|
|
|
reply.content += "<rte>";
|
2012-06-20 07:10:38 -04:00
|
|
|
if(rawRoute.lengthOfShortestPath != INT_MAX && rawRoute.computedShortestPath.size()) {
|
2011-11-17 12:56:45 -05:00
|
|
|
convertInternalLatLonToString(phantomNodes.startPhantom.location.lat, tmp);
|
|
|
|
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
|
|
|
convertInternalLatLonToString(phantomNodes.startPhantom.location.lon, tmp);
|
|
|
|
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
|
|
|
|
2013-01-06 06:59:36 -05:00
|
|
|
BOOST_FOREACH(const _PathData & pathData, rawRoute.computedShortestPath) {
|
2011-12-20 12:45:48 -05:00
|
|
|
sEngine.GetCoordinatesForNodeID(pathData.node, current);
|
2011-11-17 12:56:45 -05:00
|
|
|
|
2011-12-20 12:45:48 -05:00
|
|
|
convertInternalLatLonToString(current.lat, tmp);
|
|
|
|
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
|
|
|
convertInternalLatLonToString(current.lon, tmp);
|
|
|
|
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
2011-11-17 12:56:45 -05:00
|
|
|
}
|
|
|
|
convertInternalLatLonToString(phantomNodes.targetPhantom.location.lat, tmp);
|
|
|
|
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
|
|
|
convertInternalLatLonToString(phantomNodes.targetPhantom.location.lon, tmp);
|
|
|
|
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
|
|
|
}
|
|
|
|
reply.content += "</rte></gpx>";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif /* GPX_DESCRIPTOR_H_ */
|