HERE Android SDK Developer's Guide

MapOffScreenRenderer

The class MapOffScreenRenderer is a member of com.here.android.mpa.mapping .

Class Summary

public final class MapOffScreenRenderer

   implements com.here.android.mpa.common.OffScreenRenderer

extends java.lang.Object

Map derivation of the OffScreenRenderer.

[For complete information, see the section Class Details]

Constructor Summary

Table 1. Constructors in MapOffScreenRenderer
Constructors

MapOffScreenRenderer (Context ctx)

Constructor of a MapOffScreenRenderer .

Method Summary

Table 2. Methods in MapOffScreenRenderer
Methods

public void addOnMapRenderListener (OnMapRenderListener listener)

Adds a OnMapRenderListener to listen for map render events.

public boolean getBlockingRendering ()

Get whether the offscreen renderer is rendering synchronously.

public void getScreenCapture (OnScreenCaptureListener listener)

Returns the full screen bitmap for the Map .

public void removeOnMapRenderListener (OnMapRenderListener listener)

Removes an existing OnMapRenderListener.

public MapOffScreenRenderer setBlockingRendering (boolean blocking)

Toggle if the offscreen renderer draws synchronously.

public MapOffScreenRenderer setMap (Map map)

Associate the Map with the OffScreen renderer.

public MapOffScreenRenderer setSize (int width, int height)

Set the size of the requested screen surface

public MapOffScreenRenderer setViewRect (ViewRect viewRect)

Set the view rectangle where the map will be drawn.

public void start ()

Starts the offscreen renderer.

public void start (SurfaceHolder renderTarget, SurfaceUpdatedListener listener)

Start the offscreen renderer.

public void stop ()

Stop the offscreen renderer.

Class Details

Map derivation of the OffScreenRenderer. This class as allows users to capture screenshots of a Map with or without the map rendered in an Android android.view.android.view.View.

Here's a short example to capture a screenshot of a Map not rendered in a View :

      OnMapRenderListener listener = new OnMapRenderListener() {
    // ...
    public void onPostDraw(boolean invalidated, long renderTime)
{
      // map has been rendered, now it's OK to get screen
capture!
      renderer.getScreenCapture(...);
    }
    // ...
 } Map map = new Map();
 MapOffScreenRenderer renderer = new MapOffScreenRenderer(ctx);
 renderer.setMap(map);
 renderer.setSize(500, 500);
 renderer.addRenderListener(listener);
 renderer.start();
 // ...
 renderer.stop();
 renderer.removeRenderListener(listener);
 renderer.setMap(null);           

Constructor Details

MapOffScreenRenderer (Context ctx)

Constructor of a MapOffScreenRenderer .

Parameters:

  • ctx

    Context to be used by the MapOffScreenRenderer

Method Details

public void addOnMapRenderListener (OnMapRenderListener listener)

Adds a OnMapRenderListener to listen for map render events. This method is only effective after a Map has been associated with the renderer by calling setMap(Map).

Parameters:

  • listener

    A OnMapRenderListener to add to the MapOffScreenRenderer

See also:

removeOnMapRenderListener(OnMapRenderListener)

public boolean getBlockingRendering ()

Get whether the offscreen renderer is rendering synchronously.

This API only takes effect after setMap(Map) has been called. By default, blocking rendering is disabled.

Returns:

true if rendering synchronously, false otherwise.

public void getScreenCapture (OnScreenCaptureListener listener)

Returns the full screen bitmap for the Map . This method is asynchronous and will invoke a callback once the operation is completed through the OnScreenCaptureListener.

The MapOffScreenRenderer must have been started and the Map rendered in order to create the screen capture. For Map being rendered in a View , users can use the methods getHeight() or getWidth() to verify that the Map has been rendered. Otherwise, users can also utilize the onPostDraw(boolean, long) callback to confirm when the Map has been rendered.

Note that this requires the device to support EGL pBuffer Surfaces. It is recommended to have a size of a power of two. (For example 128x128, 256x256).

Parameters:

  • listener

    A OnScreenCaptureListener to listen for the callback when screen capture is complete.

Throws:

  • IllegalArgumentException

    if listener is null.

See also:

start()

start(SurfaceHolder, SurfaceUpdatedListener)

onPostDraw(boolean, long)

public void removeOnMapRenderListener (OnMapRenderListener listener)

Removes an existing OnMapRenderListener.

Parameters:

  • listener

    A OnMapRenderListener to remove from the MapOffScreenRenderer

public MapOffScreenRenderer setBlockingRendering (boolean blocking)

Toggle if the offscreen renderer draws synchronously. This means it will block waiting for all required data to complete rendering.

This API only takes effect after setMap(Map) has been called.

It is also recommended animations be disabled with the method setFadingAnimations(boolean).

Parameters:

  • blocking

    true if rendering will block, false otherwise. Default is false.

Returns:

This MapOffScreenRenderer object

public MapOffScreenRenderer setMap (Map map)

Associate the Map with the OffScreen renderer.

Make sure to set the map back to null after calling stop() to free up resources properly.

Parameters:

  • map

    Map instance to render in the offscreen renderer.

Returns:

This MapOffScreenRenderer object

public MapOffScreenRenderer setSize (int width, int height)

Set the size of the requested screen surface

Parameters:

  • width

    The screen surface width, in number of pixels

  • height

    The screen surface height, in number of pixels

Returns:

This MapOffScreenRenderer object

Throws:

  • IllegalArgumentException

    if width or length is less than or equal to 0

public MapOffScreenRenderer setViewRect (ViewRect viewRect)

Set the view rectangle where the map will be drawn. This API can only called after the setMap(Map) with a valid Map has been called.

Parameters:

  • viewRect

    Rectangle where the map will be drawn to the view.

Returns:

This MapOffScreenRenderer object

Throws:

  • RuntimeException

    if a map has not been set to the MapOffScreenRenderer.

public void start ()

Starts the offscreen renderer. A new PBuffer based surface will be allocated. Before calling this method, ensure a valid size has been set by calling the method setSize(int, int).

public void start (SurfaceHolder renderTarget, SurfaceUpdatedListener listener)

Start the offscreen renderer. The renderer will be attached to the supplied Surface argument.

Parameters:

  • renderTarget

    Surface to attach to.

  • listener

    Callback when the surface has been updated

public void stop ()

Stop the offscreen renderer. All resource allocated will be released.