Calculate Route Multi View¶
Calculate two routes and add them in two separate views.

Use case¶
Calculate routes and display them in separate views.
How to use the sample¶
First, get an API key token, see the Getting Started guide.
Download the Maps & Navigation SDK for C++ archive file for Linux or WindowsWhen you open the sample, you’ll be viewing the scene from above. The screen will be split into two identical views. From each view a fly will be performed to a different calculated route.
How it works¶
Create an instance of
Environment
and set your API key token:
1Environment& env = Environment::GetInstance();
2
3//
4// Project API token available at:
5// https://developer.magiclane.com/api/projects
6//
7std::string projectApiToken = ""; //YOUR_TOKEN
The SDK is initialized with your API key token string and the log file path, where to write the application logs. Note that
logFilePath
is not initialized by default, which means that no logs are written. The logFilePath is initialized with the first command line argument, if any.
1std::string logFilePath;
2if ( argc > 1 )
3 logFilePath = std::string(argv[1]);
4
5env.InitSDK( projectApiToken, logFilePath.c_str() );
Create two
MapViewListener
objects, oneOpenGLContext
, oneScreen
and twoMapView
objects.
1MapViewListenerImpl mapViewListener1;
2MapViewListenerImpl mapViewListener2;
3
4auto oglContext = env.ProduceOpenGLContext("calculateRouteMultiView");
5gem::StrongPointer<gem::Screen> screen = gem::Screen::produce(oglContext, gem::RR_Automatic);
6gem::StrongPointer<gem::MapView> mapView1 = gem::MapView::produce(screen, gem::RectF(0.f, 0.f, 0.5f, 1.f), &mapViewListener1);
7gem::StrongPointer<gem::MapView> mapView2 = gem::MapView::produce(screen, gem::RectF(0.5f, 0.f, 1.f, 1.f), &mapViewListener2);
8
9auto ret = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &mapViewListener1), 15000);
10auto ret2 = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &mapViewListener2), 15000);
Create a
RouteList
, aProgressListener
, aLandmarkList
with twoLandmarks
in it and aRoutePreferences
object.
1gem::RouteList routes1, routes2;
2{
3 ProgressListener calculateRouteListener;
4 gem::LandmarkList waypoints;
5 waypoints.push_back(gem::Landmark("San Francisco", { 37.77903, -122.41991 }));
6 waypoints.push_back(gem::Landmark("San Jose", { 37.33619, -121.89058 }));
7 gem::RoutePreferences preferences;
Call the
RoutingService
usingRouteList
,LandmarkList
,RoutePreferences
and the progress listener. Wait up to 15 seconds (15000 milliseconds) for the route computation to complete.
1 gem::RoutingService().calculateRoute(routes1, waypoints, preferences, &calculateRouteListener);
2 auto ret = WAIT_UNTIL(std::bind(&ProgressListener::IsFinished, &calculateRouteListener), 15000);
3}
Perform steps 4 and 5 for the 2nd
MapView
.
1{
2 ProgressListener calculateRouteListener;
3 gem::LandmarkList waypoints;
4 waypoints.push_back(gem::Landmark("London", { 51.516128, -0.142828 }));
5 waypoints.push_back(gem::Landmark("Paris", { 48.848462, 2.327315 }));
6 gem::RoutePreferences preferences;
7 gem::RoutingService().calculateRoute(routes2, waypoints, preferences, &calculateRouteListener);
8 auto ret = WAIT_UNTIL(std::bind(&ProgressListener::IsFinished, &calculateRouteListener), 15000);
9}
Once the route calculation operations complete, if the resulting route list contains at least one route for each of the 2 calculated route collections, add the first calculated route (at index 0) of each collection to their corresponding view
MapViewPreferences
routes collection. Instruct bothMapView
objects to center on the first route of its route collection.
1if (routes1.size() > 0 && routes2.size() > 0)
2{
3 mapView1->preferences().routes().add(routes1[0], true);
4 mapView1->centerOnRoute(routes1[0], gem::Rect(), gem::Animation(gem::AnimationLinear, gem::ProgressListener(), 2000));
5 ret = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &mapViewListener1), 15000);
6
7 mapView2->preferences().routes().add(routes2[0], true);
8 mapView2->centerOnRoute(routes2[0], gem::Rect(), gem::Animation(gem::AnimationLinear, gem::ProgressListener(), 2000));
9 ret = WAIT_UNTIL(std::bind(&MapViewListenerImpl::IsFinished, &mapViewListener2), 15000);
10}
11WAIT_UNTIL_WINDOW_CLOSE();