2011-11-17 12:56:45 -05:00
|
|
|
/*
|
|
|
|
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 GPX_DESCRIPTOR_H_
|
|
|
|
#define GPX_DESCRIPTOR_H_
|
|
|
|
|
|
|
|
#include "BaseDescriptor.h"
|
|
|
|
|
2013-06-26 19:48:22 -04:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2013-09-19 12:54:30 -04:00
|
|
|
template<class DataFacadeT>
|
|
|
|
class GPXDescriptor : public BaseDescriptor<DataFacadeT> {
|
2011-11-17 12:56:45 -05:00
|
|
|
private:
|
2013-09-19 16:10:49 -04:00
|
|
|
DescriptorConfig config;
|
2013-08-14 07:12:28 -04:00
|
|
|
FixedPointCoordinate current;
|
2011-11-17 12:56:45 -05:00
|
|
|
|
|
|
|
std::string tmp;
|
|
|
|
public:
|
2013-09-19 16:28:02 -04:00
|
|
|
void SetConfig(const DescriptorConfig & c) { config = c; }
|
2013-09-19 12:54:30 -04:00
|
|
|
|
|
|
|
//TODO: reorder parameters
|
|
|
|
void Run(
|
|
|
|
http::Reply & reply,
|
|
|
|
const RawRouteData &rawRoute,
|
|
|
|
PhantomNodes &phantomNodes,
|
|
|
|
const DataFacadeT * facade
|
|
|
|
) {
|
2011-11-17 12:56:45 -05:00
|
|
|
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
2013-09-19 12:54:30 -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-09-19 12:54:30 -04: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>";
|
2013-09-19 12:54:30 -04:00
|
|
|
bool found_route = (rawRoute.lengthOfShortestPath != INT_MAX) &&
|
|
|
|
(rawRoute.computedShortestPath.size() );
|
|
|
|
if( found_route ) {
|
|
|
|
convertInternalLatLonToString(
|
|
|
|
phantomNodes.startPhantom.location.lat,
|
|
|
|
tmp
|
|
|
|
);
|
2011-11-17 12:56:45 -05:00
|
|
|
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
2013-09-19 12:54:30 -04:00
|
|
|
convertInternalLatLonToString(
|
|
|
|
phantomNodes.startPhantom.location.lon,
|
|
|
|
tmp
|
|
|
|
);
|
2011-11-17 12:56:45 -05:00
|
|
|
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
|
|
|
|
2013-09-19 12:54:30 -04:00
|
|
|
BOOST_FOREACH(
|
|
|
|
const _PathData & pathData,
|
|
|
|
rawRoute.computedShortestPath
|
|
|
|
) {
|
|
|
|
current = facade->GetCoordinateOfNode(pathData.node);
|
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
|
|
|
}
|
2013-09-19 12:54:30 -04:00
|
|
|
convertInternalLatLonToString(
|
|
|
|
phantomNodes.targetPhantom.location.lat,
|
|
|
|
tmp
|
|
|
|
);
|
2011-11-17 12:56:45 -05:00
|
|
|
reply.content += "<rtept lat=\"" + tmp + "\" ";
|
2013-09-19 12:54:30 -04:00
|
|
|
convertInternalLatLonToString(
|
|
|
|
phantomNodes.targetPhantom.location.lon,
|
|
|
|
tmp
|
|
|
|
);
|
2011-11-17 12:56:45 -05:00
|
|
|
reply.content += "lon=\"" + tmp + "\"></rtept>";
|
|
|
|
}
|
|
|
|
reply.content += "</rte></gpx>";
|
|
|
|
}
|
|
|
|
};
|
2013-09-19 12:54:30 -04:00
|
|
|
#endif // GPX_DESCRIPTOR_H_
|