File indexing completed on 2024-07-07 03:44:51

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #include <QApplication>
0007 
0008 #include <marble/MarbleWidget.h>
0009 #include <marble/MarbleModel.h>
0010 #include <marble/RouteRequest.h>
0011 #include <marble/RoutingManager.h>
0012 
0013 using namespace Marble;
0014 
0015 int main(int argc, char** argv)
0016 {
0017     QApplication app(argc,argv);
0018 
0019     // Create a Marble QWidget without a parent
0020     MarbleWidget *mapWidget = new MarbleWidget();
0021 
0022     // Load the OpenStreetMap map
0023     mapWidget->setMapThemeId(QStringLiteral("earth/openstreetmap/openstreetmap.dgml"));
0024     mapWidget->setProjection( Mercator );
0025 
0026     // Access the shared route request (start, destination and parameters)
0027     RoutingManager* manager = mapWidget->model()->routingManager();
0028     RouteRequest* request = manager->routeRequest();
0029 
0030     // Use default routing settings for cars
0031     request->setRoutingProfile( manager->defaultProfile( RoutingProfile::Motorcar ) );
0032 
0033     // Set start and destination
0034     request->append( GeoDataCoordinates( 8.38942, 48.99738, 0.0, GeoDataCoordinates::Degree ) );
0035     request->append( GeoDataCoordinates( 8.42002, 49.0058, 0.0, GeoDataCoordinates::Degree ) );
0036 
0037     // Calculate the route
0038     manager->retrieveRoute();
0039 
0040     // Center the map on the route start point and show it
0041     mapWidget->centerOn( request->at( 0 ) );
0042     mapWidget->setDistance( 0.75 );
0043     mapWidget->show();
0044 
0045     return app.exec();
0046 }