Skip to content

Multi Map View

Show multiple map views.

Multi_Map View - cpp example screenshot

Setup

First, get an API key token, see the Getting Started guide.

Prerequisites

It is required that you complete the Environment Setup - CPP Examples guide before starting this guide.

Setting your API key token

To set your API key token, define it like this:

#define API_TOKEN "YOUR_API_KEY_TOKEN"

replacing YOUR_API_KEY_TOKEN with your actual API key token text, within the quotes.

This can be done in the main() function, before the following line:

#if defined(API_TOKEN)

or outside the main() function, further up, or in a header file.

Although it is also possible to define your API key token as the text value of the GEM_TOKEN environment variable, this is not recommended, as it is not secure.

Use case

Present more than one interactive map view, functioning independent of each other.

How to use the sample

When you open the sample, you’ll be viewing the scene from above. The scene will be displayed in two views. For highlight purposes a different style is set to the 2nd view, if available.

How it works

  1. Create an instance of Environment and set your API key token:

1int main( int argc, char** argv )
2{
3   std::string projectApiToken = "";
4#define API_TOKEN "YOUR_API_KEY_TOKEN"
5#if defined(API_TOKEN)
6   projectApiToken = std::string( API_TOKEN );
7#endif
8   // Sdk objects can be created & used below this line
9   Environment::SdkSession session(projectApiToken, { argc > 1 ? argv[1] : "" });
  1. The SDK is initialized with your API key token string and the log file path, where to write the application logs. Note that the log file path is not initialized by default, the empty string above, after the API key token, which means that no logs are written. The log file path is initialized with the first command line argument, if any. Create a gem::MapView interactive map object, using an OpenGL context for 3D graphics, the SDK environment created above, and a touch event listener for interactive user touch and mouse input, such as pan and zoom.

1// Create an interactive map view
2CTouchEventListener pTouchEventListener;
3gem::StrongPointer<gem::Screen> screen = gem::Screen::produce(session.produceOpenGLContext(
4   Environment::WindowFrameworks::Available, "MultiMapView", &pTouchEventListener));
  1. To display multiple independently functioning interactive map views, a gem::Screen is produced, above, to which multiple gem::MapView instances are added, each centered on a different location, and rendered using a different map style:

 1// Map view in left viewport half
 2gem::StrongPointer<gem::MapView> mapView1 = gem::MapView::produce(screen, gem::RectF(0.f, 0.f, 0.5f, 1.0f));
 3// Map view in lower right viewport
 4gem::StrongPointer<gem::MapView> mapView2 = gem::MapView::produce(screen, gem::RectF(0.5f, 0.f, 1.0f, 0.5f));
 5// Map view in upper right viewport
 6gem::StrongPointer<gem::MapView> mapView3 = gem::MapView::produce(screen, gem::RectF(0.5f, 0.5f, 1.f, 1.f));
 7
 8mapView2->centerOnCoordinates({ 48.8613, 2.33387 }, 72);
 9mapView3->centerOnCoordinates({ 48.5213, 7.7377 }, 72);
10
11// Set a different map style in each mapView to differentiate them
12auto styleList = gem::ContentStore().getLocalContentList(gem::EContentType::CT_ViewStyleLowRes);
13
14if (styleList.size() > 1)
15   mapView1->preferences().setMapStyle(styleList.at(1));
16if (styleList.size() > 3)
17   mapView2->preferences().setMapStyle(styleList.at(3));
18if (styleList.size() > 4)
19   mapView3->preferences().setMapStyle(styleList.at(4));
  1. Use the special provided macro to keep the interactive map and wait until the user closes the window.

1   WAIT_UNTIL_WINDOW_CLOSE();
2   return 0;
3}

C++ Examples

Maps SDK for C++ Examples can be downloaded or cloned with Git