[Marble-commits] KDE/kdeedu/marble/src/plugins/runner/monav
Dennis Nienhüser
earthwings at gentoo.org
Fri Oct 1 23:28:59 CEST 2010
SVN commit 1181723 by nienhueser:
Implement reverse geocoding using monav and the usual trivial route request approach.
M +1 -1 MonavPlugin.cpp
M +47 -13 MonavRunner.cpp
M +3 -0 MonavRunner.h
--- trunk/KDE/kdeedu/marble/src/plugins/runner/monav/MonavPlugin.cpp #1181722:1181723
@@ -107,7 +107,7 @@
// Check installation
d->m_mapDir = QDir( MarbleDirs::localPath() + "/maps/earth/monav/" );
bool haveMap = QFileInfo( d->m_mapDir, "plugins.ini" ).exists();
- setCapabilities( haveMap ? Routing : None );
+ setCapabilities( haveMap ? Routing | ReverseGeocoding : None );
}
MonavPlugin::~MonavPlugin()
--- trunk/KDE/kdeedu/marble/src/plugins/runner/monav/MonavRunner.cpp #1181722:1181723
@@ -33,6 +33,8 @@
MonavRunnerPrivate();
+ bool retrieveData( RouteRequest *route, RoutingDaemonResult* result ) const;
+
GeoDataLineString* retrieveRoute( RouteRequest *route, QVector<GeoDataPlacemark*> *instructions ) const;
GeoDataDocument* createDocument( GeoDataLineString* geometry, const QVector<GeoDataPlacemark*> &instructions ) const;
@@ -44,10 +46,8 @@
// nothing to do
}
-GeoDataLineString* MonavRunnerPrivate::retrieveRoute( RouteRequest *route, QVector<GeoDataPlacemark*> *instructions ) const
+bool MonavRunnerPrivate::retrieveData( RouteRequest *route, RoutingDaemonResult* reply ) const
{
- GeoDataLineString* geometry = new GeoDataLineString;
-
QLocalSocket socket;
socket.connectToServer( "MoNavD" );
if ( socket.waitForConnected() ) {
@@ -69,22 +69,42 @@
command.post( &socket );
socket.flush();
- RoutingDaemonResult reply;
- if ( reply.read( &socket ) ) {
- switch ( reply.type ) {
+ if ( reply->read( &socket ) ) {
+ switch ( reply->type ) {
case RoutingDaemonResult::LoadFailed:
mDebug() << "failed to load monav map from " << m_mapDir.absolutePath();
+ return false;
break;
case RoutingDaemonResult::RouteFailed:
mDebug() << "failed to retrieve route from monav daemon";
+ return false;
break;
case RoutingDaemonResult::TypeLookupFailed:
mDebug() << "failed to lookup type from monav daemon";
+ return false;
break;
case RoutingDaemonResult::NameLookupFailed:
mDebug() << "failed to lookup name from monav daemon";
+ return false;
break;
case RoutingDaemonResult::Success:
+ return true;
+ }
+ } else {
+ mDebug() << "Failed to read reply";
+ }
+ } else {
+ mDebug() << "No connection to MoNavD";
+ }
+
+ return false;
+}
+
+GeoDataLineString* MonavRunnerPrivate::retrieveRoute( RouteRequest *route, QVector<GeoDataPlacemark*> *instructions ) const
+{
+ GeoDataLineString* geometry = new GeoDataLineString;
+ RoutingDaemonResult reply;
+ if ( retrieveData( route, &reply ) ) {
/** @todo: make use of reply.seconds, the estimated travel time */
for ( int i = 0; i < reply.pathNodes.size(); ++i ) {
qreal lon = reply.pathNodes[i].longitude;
@@ -127,14 +147,7 @@
placemark->setGeometry( geometry );
instructions->push_back( placemark );
}
- break;
}
- } else {
- mDebug() << "Failed to read reply";
- }
- } else {
- mDebug() << "No connection to MoNavD";
- }
return geometry;
}
@@ -192,6 +205,27 @@
emit routeCalculated( result );
}
+void MonavRunner::reverseGeocoding( const GeoDataCoordinates &coordinates )
+{
+ GeoDataPlacemark placemark;
+ placemark.setCoordinate( GeoDataPoint( coordinates ) );
+
+ RouteRequest route;
+ route.append( coordinates );
+ route.append( coordinates );
+ RoutingDaemonResult reply;
+
+ if ( d->retrieveData( &route, &reply ) && !reply.pathEdges.isEmpty() ) {
+ QString road = reply.nameStrings[reply.pathEdges[0].name];
+ placemark.setAddress( road );
+ GeoDataExtendedData extendedData;
+ extendedData.addValue( GeoDataData( "road", road ) );
+ placemark.setExtendedData( extendedData );
+ }
+
+ emit reverseGeocodingFinished( coordinates, placemark );
+}
+
} // namespace Marble
#include "MonavRunner.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/runner/monav/MonavRunner.h #1181722:1181723
@@ -35,6 +35,9 @@
// Overriding MarbleAbstractRunner
virtual void retrieveRoute( RouteRequest *request );
+ // Overriding MarbleAbstractRunner
+ void reverseGeocoding( const GeoDataCoordinates &coordinates );
+
private:
MonavRunnerPrivate* const d;
};
More information about the Marble-commits
mailing list