CartoType's graphics acceleration system gives you a smooth, fast, fluid user experience, with no delays when panning or zooming the map. Drawing speeds of up to 30 frames per second are supported.
What can I do with graphics acceleration?
You can do everything you do already (and more: you can use smooth animations for zooming, panning and rotation). The standard CartoType API is available, and you can use the same map data (CTM1 files) and style sheets that the standard version of CartoType uses. And unlike some mapping frameworks, which require you to use the Web Mercator projection, CartoType GL allows you to use any projection.
How it works
CartoType's graphics-accelerated rendering system uses two things to give you that extra speed. Multi-threading uses several processor cores at once to fetch the map data. The Open GL ES graphics language gives access to the GPU (graphics processing unit) on the device. All modern mobile and desktop platforms now support graphics acceleration.
Graphics-accelerated rendering is available now as an integral part of the CartoType SDK, for iOS, Android, Windows (desktop), .NET for Windows, and Linux. Evaluation SDKs are available for all those platforms. It is also supported on Qt for Windows, Mac OS and Linux.
How to use graphics acceleration
To use graphics acceleration for rendering, you should first create a framework object (e.g., CFramework on C++, Framework on Android, CartoTypeFramework on iOS, etc.) then create a map renderer object (CMapRenderer on C++, MapRenderer on .NET, MapRenderer on Android, CartoTypeMapRenderer on iOS), passing your framework to it.
On Windows and .NET: pass the handle of the window into which the map is to be drawn to the map renderer's constructor. This is the m_hWnd data member on MFC in Windows, and the Handle property in .NET. You don't need to make any explicit drawing calls: the map is drawn automatically at 25 frames per second by the map renderer object.
On other platforms: call the map renderer's Draw function when you need to redraw the map. You can call it continuously if you like, or call it only when you know the map needs to be redrawn.
On Android there is a higher-level class, MapView: it creates a map renderer and draws the map as needed, and also provides panning and pinch zooming.
In the iOS demo program TestGL there is a higher-level CartoTypeMapView class which creates the map renderer and draws the map as needed.
You can use the same maps with graphics-accelerated rendering as with standard CartoType. All projections are supported. Some tile-based systems require the map to use the Web Mercator projection; CartoType GL imposes no such restriction. When loading multiple maps into a framework to be rendered using graphics acceleration you should load all the maps before creating the map renderer, unless you know that the new maps will not change the overall bounds.
The graphics-accelerated rendering systsme supports standard CartoType style sheets. It supports all graphic features except bridge graphics (faint lines beside bridges). 3D buildings have better support than in standard CartoType. OpenStreetMap colors and roof shapes are used.
You can set perspective mode in the usual way from the standard API.
Calling arbitrary functions on your framework object
You can call any function in the standard API quite freely during graphics accelerated drawing. For example, you can
- set the map position using degrees of latitude and longitude
- insert pushpins
- search for a place
- calculate and display a route
The only thing you shouldn't do is delete your framework object, in languages such as C++ which allow that.
Here's how to use CartoType GL on Android. In your main activity class, add instance variables for the framework and view:
private Framework m_framework;
private MapView m_view;
In your onCreate function, create the framework object and the view, and make the view the content view:
m_framework = new Framework(my_map,my_style,my_font);
m_view = new MapView(this,framework);
The MapView class handles panning and pinch zooming; you can subclass it to provide more complex interactions.
You will to install the library libGLESv2 and link your program to it.
On iOS you need to add the OpenGLES framework to your project, otherwise you'll get link errors for the OpenGL functions used by CartoType. To do this in Xcode, select your project in the left column, select the app under 'TARGETS', then click on 'Build Phases, then add OpenGLES.framework in the 'Link Binaries with Libraries' section. You should also add the GLKit framework so that you can use Apple's GLKView and GLKViewController classes, which make using OpenGL ES much easier.
You should create your CartoTypeMapRenderer object in the thread which has the EGL context, otherwise shader compilation will fail. The simplest way to do that is to create the CartoTypeMapRenderer object in the first call to drawRect in your view class. Here is the Objective C source code for a simple view class which does that:
/** A view class for drawing maps using graphics acceleration. */
@interface CartoTypeMapView: GLKView
/** Sets the CartoTypeFramework to be drawn. */
/** Draws the current CartoTypeFramework. */
// instance variables
m_framework = aFramework;
m_map_renderer = nil;
if (m_map_renderer == nil && m_framework != nil)
m_map_renderer = [[CartoTypeMapRenderer alloc] init:m_framework];
You will need to link to OpenGLES libraries and/or DLLs. If you are using the Angle OpenGL ES library (recommended) you need to link to angle_common.lib, angle_util.lib, sample_util.lib, libEGL.lib, and libGLESv2.lib, and to ensure that the Angle DLLs are available in the search path (the PATH environment variable) when your executable is run, for example by executing the command 'PATH=C:\angle\build\Release_x64;%PATH%' beforehand.
You should add a data member to your view window to hold a CMapRenderer object:
and initialise it in your OnInitialUpdate function like this:
after you have created your CFramework object (iFramework in this example).
There is no need to draw the map manually. The CMapRenderer object draws the map automatically at 25 frames per second, taking account of any changes you make to the map, such as panning, zooming, creating routes, etc.
C# notes (using the .NET SDK)
You will need to ensure that the OpenGL DLLs, libEGL.dll and libGLESv2.dll, are available in the search path (the PATH environment variable) when your executable is run, for example by executing the command 'PATH=C:\angle\build\Release_x64;%PATH%' beforehand. These DLLs are supplied with the .NET SDK, in the same directories as the .NET CartoType wrapper DLLs (CartoTypeDemo\vs2017\bin\x64\Release and CartoTypeDemo\vs2017\bin\x64\Debug).
You should add a data member to your Form (window) to hold a MapRenderer object:
private CartoType.MapRenderer m_map_renderer;
and initialise it in your Form constructor:
m_map_renderer = new CartoType.MapRenderer(m_framework, Handle);
after you have created your Framework object (m_framework in this example).
There is no need to draw the map manually. The MapRenderer object draws the map automatically at 25 frames per second, taking account of any changes you make to the map, such as panning, zooming, creating routes, etc.