Class MapSurface
Class MapSurface
- java.lang.Object
-
- com.here.sdk.mapview.MapSurface
-
- All Implemented Interfaces:
MapViewBase
public class MapSurface extends java.lang.Object implements MapViewBase
Provides the ability to render a map into a provided rendering surface. This enables the possibility to render a map into external displays like Android Auto. If you want to use the map for a regular use case please use theMapViewinstead.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMapSurface.RenderListenerListener of MapSurface render events.-
Nested classes/interfaces inherited from interface com.here.sdk.mapview.MapViewBase
MapViewBase.MapPickCallback
-
-
Constructor Summary
Constructors Constructor Description MapSurface()Creates a new instance.MapSurface(android.content.Context context)Creates a new instance.MapSurface(android.content.Context context, MapViewOptions options)Creates a new instance.MapSurface(MapViewOptions options)Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddLifecycleListener(MapViewLifecycleListener lifecycleListener)Adds aMapViewLifecycleListenerto this map view.voidattachSurface(android.content.Context context, android.view.Surface surface, int width, int height)Sets the surface on which the map will be rendered.voidattachSurface(android.content.Context context, android.view.Surface surface, int width, int height, MapSurface.RenderListener renderListener)Sets the surface on which the map will be rendered.voiddestroy()Destroys the map renderer and render surface, making thisMapSurfaceinvalid.voiddestroySurface()Destroys the rendering surface.Point2DgeoToViewCoordinates(GeoCoordinates geoCoordinates)Converts geographical coordinates to view coordinates (in pixels).MapCameragetCamera()Returns the camera control object for the mapintgetFrameRate()Gets maximum render frame rate in frames per second.GesturesgetGestures()Returns the gestures control object.HereMapgetHereMap()Gets the HereMap associated with this map view.MapContextgetMapContext()Gets the map context associated with this map view.MapScenegetMapScene()Gets the map scene associated with this map view.doublegetPixelScale()Gets the pixel scale factor used by this MapView.static ShadowQualitygetShadowQuality()Gets the currently set shadow quality.Size2DgetViewportSize()Returns the viewport size of this MapView in physical pixels.Size2DgetWatermarkSize()Returns the watermark size in physical pixels.booleanisValid()Returns whether thisMapSurfaceis valid.voidonPause()Call this method in the onPause() method of the lifecycle owner.voidonResume()Call this method in the onResume() method of the lifecycle owner.voidpick(MapScene.MapPickFilter filter, Rectangle2D viewArea, MapViewBase.MapPickCallback callback)Returns all map content located inside the specified pick area.voidredraw(java.lang.Runnable redrawFinished)Redraws the map and reports back on completion.voidremoveLifecycleListener(MapViewLifecycleListener lifecycleListener)Removes aMapViewLifecycleListenerfrom this map view.voidsetFrameRate(int value)Sets maximum render frame rate in frames per second.voidsetOnReadyListener(MapView.OnReadyListener readyListener)Sets the OnReadyListener, which will be notified once MapView initialization has been finished.static voidsetShadowQuality(ShadowQuality shadowQuality)Set desired shadow quality for all instances of MapSurface/MapView.voidsetSurface(android.content.Context context, android.view.Surface surface, int width, int height)Deprecated.Will be removed in v4.26.0.voidsetSurface(android.content.Context context, android.view.Surface surface, int width, int height, MapSurface.RenderListener renderListener)Deprecated.Will be removed in v4.26.0.voidsetWatermarkLocation(Anchor2D anchor, Point2D offset)Sets the position of the HERE logo watermark within the map view.voidtakeScreenshot(MapView.TakeScreenshotCallback callback)Asynchronously retrieves screenshot of current map viewGeoCoordinatesviewToGeoCoordinates(Point2D viewCoordinates)Converts view coordinates to geographical coordinates.
-
-
-
Constructor Detail
-
MapSurface
public MapSurface()
Creates a new instance.
-
MapSurface
public MapSurface(MapViewOptions options)
Creates a new instance.- Parameters:
options- The options
-
MapSurface
public MapSurface(android.content.Context context)
Creates a new instance.- Parameters:
context- The Application context
-
MapSurface
public MapSurface(android.content.Context context, MapViewOptions options)Creates a new instance.- Parameters:
options- The optionscontext- The Application context
-
-
Method Detail
-
isValid
public boolean isValid()
Returns whether thisMapSurfaceis valid. An invalidMapSurfaceis non-functional. AMapSurfaceis considered valid only aftersetSurface(Context, Surface, int, int)and beforedestroy()is called.MapSurfaceis also invalidated when theSDKNativeEngineit is using is destroyed.- Specified by:
isValidin interfaceMapViewBase- Returns:
trueif thisMapSurfaceis valid,falseotherwise.
-
destroy
public void destroy()
Destroys the map renderer and render surface, making thisMapSurfaceinvalid. Call this method only when the render surface will no longer be used.isValid()will return @{code false} after this is called. It can be made valid again by setting render surface usingsetSurface(Context, Surface, int, int).
-
setOnReadyListener
public void setOnReadyListener(MapView.OnReadyListener readyListener)
Sets the OnReadyListener, which will be notified once MapView initialization has been finished. It is highly recommended to put code that accesses map view related functionality insideMapView.OnReadyListener.onMapViewReady()instead of directly inActivity'sonResume().- Parameters:
readyListener- The listener to be registered, ornullto unregister any previously register listener.
-
setSurface
public void setSurface(android.content.Context context, android.view.Surface surface, int width, int height)Deprecated.Will be removed in v4.26.0. Please use attachSurface.
Sets the surface on which the map will be rendered. This method needs to be called before any other methods in this class.- Parameters:
context- The Application contextsurface- The surface to render to.width- The width of the render surface in pixels.height- The height of the render surface in pixels.
-
attachSurface
public void attachSurface(android.content.Context context, android.view.Surface surface, int width, int height)Sets the surface on which the map will be rendered. Throws exception if the surface cannot be used by HERESDK.- Parameters:
context- The Application contextsurface- The surface to render to.width- The width of the render surface in pixels.height- The height of the render surface in pixels.- Throws:
java.lang.NullPointerException- if surface is invalid and cannot be used.
-
setSurface
@Deprecated public void setSurface(android.content.Context context, android.view.Surface surface, int width, int height, @NonNull MapSurface.RenderListener renderListener)Deprecated.Will be removed in v4.26.0. Please use attachSurface.
Sets the surface on which the map will be rendered. This method needs to be called before any other methods in this class. Note: This feature is in BETA state and thus there can be bugs and unexpected behavior. Related APIs may change for new releases without a deprecation process.- Parameters:
context- The Application contextsurface- The surface to render to.width- The width of the render surface in pixels.height- The height of the render surface in pixels.renderListener- A listener for render events. The listener will be released oncedestroySurface()gets called.
-
attachSurface
public void attachSurface(android.content.Context context, android.view.Surface surface, int width, int height, @NonNull MapSurface.RenderListener renderListener)Sets the surface on which the map will be rendered. Throws exception if the surface cannot be used by HERESDK. Note: This feature is in BETA state and thus there can be bugs and unexpected behavior. Related APIs may change for new releases without a deprecation process.- Parameters:
context- The Application contextsurface- The surface to render to.width- The width of the render surface in pixels.height- The height of the render surface in pixels.renderListener- A listener for render events. The listener will be released oncedestroySurface()gets called.- Throws:
java.lang.NullPointerException- if surface is invalid and cannot be used.
-
destroySurface
public void destroySurface()
Destroys the rendering surface.
-
redraw
public void redraw(java.lang.Runnable redrawFinished)
Redraws the map and reports back on completion.
- Parameters:
redrawFinished-The runnable to be executed after completion.
-
pick
public void pick(@Nullable MapScene.MapPickFilter filter, @NonNull Rectangle2D viewArea, @NonNull MapViewBase.MapPickCallback callback)Returns all map content located inside the specified pick area. Content to be picked is specified by a pick content filter. The pick area is defined by a rectangle in map view coordinates in pixels, relative to the map view's origin at (0, 0) which indicates the top-left corner of the map view.
- Specified by:
pickin interfaceMapViewBase- Parameters:
filter-Filter for the map content to be picked. When a filter is not set all of the pickable content will be picked.
viewArea-The rectangular pixel area of the view inside which map content will be picked. View area is relative to the map view's origin at (0, 0) at the top-left corner of the map view.
callback-Callback to call with the result. This will be called on a main thread when pick operation completes.
-
geoToViewCoordinates
@Nullable public Point2D geoToViewCoordinates(@NonNull GeoCoordinates geoCoordinates)
Converts geographical coordinates to view coordinates (in pixels).If specified, altitude of the input coordinates is interpreted as altitude above sea level. If not specified, the input coordinates are interpreted as being on ground elevation. The above distinction is only relevant when 3D terrain feature is enabled.
The resulting view coordinates might be outside of current viewport, i.e. result might contain values less than zero or greater than view's dimensions.
If the render surface is not attached, it will return
null.- Specified by:
geoToViewCoordinatesin interfaceMapViewBase- Parameters:
geoCoordinates-Geographical coordinates to convert.
- Returns:
The view coordinates of the specified geographical point or
nullif there is no render surface attached.- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.- See Also:
MapView.OnReadyListener
-
addLifecycleListener
public void addLifecycleListener(@NonNull MapViewLifecycleListener lifecycleListener)Adds a
MapViewLifecycleListenerto this map view. Adding the same object multiple times has no effect.- Specified by:
addLifecycleListenerin interfaceMapViewBase- Parameters:
lifecycleListener-An object to be notified of lifecycle events.
- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
removeLifecycleListener
public void removeLifecycleListener(@NonNull MapViewLifecycleListener lifecycleListener)Removes a
MapViewLifecycleListenerfrom this map view. Trying to remove an object that was not added or was removed before has no effect.- Specified by:
removeLifecycleListenerin interfaceMapViewBase- Parameters:
lifecycleListener-An object to stop being notified of lifecycle events.
- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
onResume
public void onResume()
Call this method in the onResume() method of the lifecycle owner.
-
onPause
public void onPause()
Call this method in the onPause() method of the lifecycle owner.
-
viewToGeoCoordinates
@Nullable public GeoCoordinates viewToGeoCoordinates(@NonNull Point2D viewCoordinates)
Converts view coordinates to geographical coordinates.An optional altitude component of the resulting geographical coordinate is not set.
If the view coordinates specify a point above a horizon, then the result is geographical coordinates of the point on a horizon below the specified view coordinates.
The fog effect is ignored for the calculation, meaning that for the view point within the area covered by the fog, the result is geographical coordinates that would be displayed at the specified point if the fog effect was not applied.
If the render surface is not attached, it will return
null.- Specified by:
viewToGeoCoordinatesin interfaceMapViewBase- Parameters:
viewCoordinates-Point inside the view to convert.
- Returns:
The geographical coordinates under specified view point or
nullif there is no render surface attached.- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.- See Also:
MapView.OnReadyListener
-
getGestures
@NonNull public Gestures getGestures()
Returns the gestures control object. Please note that there is no gesture support for the MapSurface at this point.- Specified by:
getGesturesin interfaceMapViewBase- Returns:
- the
Gesturescontrol object - Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getPixelScale
public double getPixelScale()
Gets the pixel scale factor used by this MapView. It is used to support screen resolution and size independence. This value is a derivative of the device's screen pixel density and is a direct analog of pixel density from DisplayMetrics. It can be used to translate between physical pixels and density independent pixels according to formula:
dp = px / pixel_scale.
- Specified by:
getPixelScalein interfaceMapViewBase- Returns:
- current pixel scale factor, or 0.0 if MapView is not initialized
- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getViewportSize
public Size2D getViewportSize()
Returns the viewport size of this MapView in physical pixels.- Specified by:
getViewportSizein interfaceMapViewBase- Returns:
- The viewport size in physical pixels
- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getFrameRate
public int getFrameRate()
Gets maximum render frame rate in frames per second. The default value is 60 frames per second.- Specified by:
getFrameRatein interfaceMapViewBase- Returns:
- Actual maximal render frame rate
- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
setFrameRate
public void setFrameRate(int value)
Sets maximum render frame rate in frames per second.- Specified by:
setFrameRatein interfaceMapViewBase- Parameters:
value- Maximum render frame rate in frames per second. Setting to 0 disables automatic rendering for this view. Setting negative values has no effect.- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
takeScreenshot
public void takeScreenshot(MapView.TakeScreenshotCallback callback)
Asynchronously retrieves screenshot of current map view- Parameters:
callback- Completion handler called when the screenshot is completed
-
setWatermarkLocation
public void setWatermarkLocation(@NonNull Anchor2D anchor, @NonNull Point2D offset)Sets the position of the HERE logo watermark within the map view. By default, the watermark is aligned to the bottom-right corner of the view: Anchor2D(1.0, 1.0) and Point2D(-watermarkSize.width / 2, -watermarkSize.height / 2). It is recommended to change the default position only if necessary to avoid overlapping UI elements. The watermark should always be fully visible within the view. The anchor point on the watermark is its center (width/2, height/2), around which it will be placed in the map view. For map views smaller than 250 dip in both width and height, the watermark will not be shown.
- Specified by:
setWatermarkLocationin interfaceMapViewBase- Parameters:
anchor-Anchor point in normalized view coordinates [0, 1]. Map view's origin at (0, 0) indicates a top-left corner of the map view. Out of boundary anchor point values will be clamped to the [0, 1] range.
offset-A horizontal and vertical offset (expressed in positive/negative pixel coordinates) that allows shifting the watermark from the anchor point position in one or the other direction. For the quadrant of values expressing visible part of the map view negative offset shifts the watermark to the direction of the origin, positive - away from it. For example, the offset of (-10, 5) will shift the watermark 10px to the left and 5px to the bottom. If specified offset will result in watermark being completely or partially out-of-view the offset will be adjusted internally so that watermark is fully visible. Offset is not being scaled when the map view size changes.
- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getWatermarkSize
@NonNull public Size2D getWatermarkSize()
Returns the watermark size in physical pixels.
- Specified by:
getWatermarkSizein interfaceMapViewBase- Returns:
Provides the size of the watermark in physical pixels.
- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
setShadowQuality
public static void setShadowQuality(ShadowQuality shadowQuality)
Set desired shadow quality for all instances of MapSurface/MapView. The quality controls the size of the shadow maps and the cascade count. The default shadow quality isShadowQuality.MEDIUM. MapSurfaces can request to render shadows by feature. Enabling shadows has a performance impact and should be considered only for devices with sufficient performance. Note: This feature is in beta state and thus there can be bugs and unexpected behavior.- Parameters:
shadowQuality- The shadow quality.- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getShadowQuality
public static ShadowQuality getShadowQuality()
Gets the currently set shadow quality. The default shadow quality isShadowQuality.MEDIUM. Note: This feature is in beta state and thus there can be bugs and unexpected behavior.- Returns:
- The currently set shadow quality.
- Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getCamera
@NonNull public MapCamera getCamera()
Returns the camera control object for the map- Specified by:
getCamerain interfaceMapViewBase- Returns:
- the
MapCameraobject for the map - Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getMapScene
@NonNull public MapScene getMapScene()
Gets the map scene associated with this map view. This can be used to request different map schemes to be displayed in the map view, and to add and remove map items from the map.- Specified by:
getMapScenein interfaceMapViewBase- Returns:
- the
MapSceneassociated with this map view. - Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getMapContext
@NonNull public MapContext getMapContext()
Gets the map context associated with this map view.- Specified by:
getMapContextin interfaceMapViewBase- Returns:
- the
MapContextassociated with this map view. - Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
getHereMap
@NonNull public HereMap getHereMap()
Gets the HereMap associated with this map view.- Specified by:
getHereMapin interfaceMapViewBase- Returns:
- the
HereMapassociated with this map view. - Throws:
java.lang.IllegalStateException- if MapSurface object is not valid.
-
-