public final class Map extends Object implements AutoCloseable
LayerList
. For rendering, all data is transformed to a common coordinate reference for display. As a consequence, many different types of data can be visualized at the same time: raster data (imagery and elevation) and vector data (Feature
instances).
The following article shows, among others, how you can add data to the map: Create your first map application
MapNavigator
. If you want to fully customize map navigation, you can set the Camera
directly.
Related articles:
Feature
data, it is possible to query which features are present in a given pixel bounds. Feature
states, such as selection, can be tracked by the Map
's FeatureStateManager
.
Map
and its Map.Renderer
track on which thread they are constructed. This is done so that, in subsequent calls, they can verify that the same threads are used consistently. When an inconsistency is detected, an assertion is triggered. This means that:
Map
, except getRenderer()
must be called on the thread on which the Map
was constructed (the "UI" thread).
Map.Renderer
must be called on the thread on which getRenderer()
was called the first time (the "Render" thread).
Related article: Threading rules for the Map
Map
can be rendered on screens with different DPI's, it is possible to configure:
Map#setDpi
Map#setDisplayScale
Related article: Support high-resolution (HiDPI) displays
Modifier and Type | Class and Description |
---|---|
static class |
Map.Builder |
static class |
Map.FeatureQuery
A query specifies which features you are interested in.
|
static class |
Map.HeightProvider
A height provider based on the map layers order and visibility.
|
static interface |
Map.IRendererCallback
This callback can be used to execute tasks on the render thread right before or right after the
Map is painted by Map.Renderer . |
static class |
Map.LocationMode
Used to determine how the Map::getViewToMapTransformation method determines the point in
Map coordinates that corresponds to a given view location. |
static class |
Map.Renderer
The
Map renderer. |
static class |
Map.ViewMapTransformation
This class allows to transform between view (pixel coordinates on the screen) and map coordinates.
|
Modifier and Type | Method and Description |
---|---|
void |
addRendererCallback(Map.IRendererCallback rendererCallback)
Adds the given callback to the
Map . |
void |
close() |
void |
deliverNotifications()
Delivers any pending notifications.
|
void |
destroy()
Disposes the
Map . |
protected void |
finalize() |
AnimationManager |
getAnimationManager()
Important notice regarding multi-threading:
|
android.graphics.Color |
getBackgroundColor()
Returns the background color of the map.
|
Camera |
getCamera()
Returns the camera that is currently used.
|
IController |
getController()
Returns the current active controller of the map.
|
MouseCursor |
getCursor()
Returns the current cursor of the map.
|
double |
getDisplayScale()
Gets the display scale currently used to render the map.
|
double |
getDpi()
Gets the DPI value used to calculate map scales.
|
GraphicsEffects |
getEffects() |
FeatureStateManager |
getFeatureStateManager()
Returns the
FeatureStateManager that keeps track of the feature state (for example selection) for this map. |
long |
getHeight() |
Map.HeightProvider |
getHeightProvider() |
LayerList |
getLayerList() |
MapNavigator |
getMapNavigator() |
CoordinateReference |
getReference()
Returns the reference of this
Map . |
Map.Renderer |
getRenderer()
|
Map.ViewMapTransformation |
getViewMapTransformation()
Returns a transformation that can transform view coordinates to map coordinates and vice-versa.
|
long |
getWidth() |
boolean |
is3D()
Returns whether this
Map is visualized in 3D. |
static Map.Builder |
newBuilder() |
void |
queryFeatures(Map.FeatureQuery query,
IMapQueryFeaturesCallback callback)
Queries the features under the given pixel bounds, and passes the result to the given callback.
|
void |
removeRendererCallback(Map.IRendererCallback rendererCallback)
Removes the given callback from the
Map . |
void |
resize(long width,
long height)
To be called when the host widget resizes, so that the map can adapt its camera, and graphics related resources.
|
void |
setBackgroundColor(android.graphics.Color color)
Sets the background color of the map.
|
void |
setCamera(Camera camera)
Set the camera that is used by the renderer.
|
void |
setController(IController controller)
Activate a controller, so that it can interact with the map.
|
void |
setCursor(MouseCursor cursor)
Change the map's cursor.
|
void |
setDisplayScale(double displayScale)
Specifies the display scale to allow the renderer to scale the graphics on high DPI displays.
|
void |
setDpi(double dpi)
Sets the DPI value that will be used to calculate map scales.
|
void |
setMapInvalidationCallback(IInvalidationCallback mapInvalidationCallback)
Sets the given
IInvalidationCallback . |
void |
setMouseCursorCallback(IMouseCursorCallback mouseCursorCallback)
Sets the given
IMouseCursorCallback . |
public void close()
close
in interface AutoCloseable
@NotNull public static Map.Builder newBuilder()
public void destroy()
public void setMapInvalidationCallback(@Nullable IInvalidationCallback mapInvalidationCallback)
IInvalidationCallback
.
This callback is called when the map has changed, and needs to be repainted. Can be null
. The callback is owned by the calling code, i.e. typically code that integrates the Map
in a UI framework. Beware that this callback should not call (directly or indirectly) the map (for example Map::paint) because it can be called on any thread.
mapInvalidationCallback
- a callback that is called when the map has changed.@NotNull public Map.Renderer getRenderer()
Renderer
for this Map
.
The Renderer
owns the OpenGL resources related to this Map
. It can only be interacted with while the OpenGL context is current.
public void deliverNotifications()
The map buffers up notifications for delivery to the user on the UI thread. However, as the map does not have a way to schedule any actions on the UI thread, the user himself should call this function on the appropriate thread. For example, this could be done when the UI toolkit or framework indicates that the widget containing this map should be updated.
public void resize(long width, long height)
width
- The new map's width expressed in device independent pixels.height
- The new map's height expressed in device independent pixels.public long getWidth()
Map
in device independent pixelspublic long getHeight()
Map
in device independent pixels@NotNull public LayerList getLayerList()
@NotNull public CoordinateReference getReference()
Map
.
This reference determines how the Map
is visualized. When a projected (2D) reference is used, all data on the map is painted in this reference. When a (3D) geocentric reference is used, the Map
is painted in 3D, and all data is pointed on the globe.
Map
.@NotNull public MapNavigator getMapNavigator()
MapNavigator
instance that can manipulate the Camera
of this mappublic void setCamera(@NotNull Camera camera) throws NullPointerException
This method is only needed when you want to navigate in a different way than using MapNavigator
.
You can call this method on any thread, but its behavior is slightly different:
animation manager
, which performs animation updated on the render thread.
See the threading article for a more detailed explanation on the threading behavior.
camera
- the new camera. Cannot be null
.NullPointerException
- when the camera is null
.@NotNull public Camera getCamera()
You can call this method on any thread.
See also setCamera
for more information.
Warning: this method will return the camera instance that was last used by the map renderer. This means that if you call setCamera
on a different thread than the render thread, a call to getCamera immediately after will not necessarily result in the same camera. See the threading article for a more detailed explanation.
@NotNull public FeatureStateManager getFeatureStateManager()
FeatureStateManager
that keeps track of the feature state (for example selection) for this map.
Apart from inspecting the feature state, you can use the returned object to change the feature state.
FeatureStateManager
that keeps track of the feature state for this map.public void queryFeatures(@NotNull Map.FeatureQuery query, @NotNull IMapQueryFeaturesCallback callback) throws NullPointerException
All visible layers are taken into account. The features are sorted using the following criteria:
3D:
2D:
It is possible that the same feature appears multiple times in the result list, once for each part of the feature. When a feature is for example painted
using 2 draw calls, all 2 parts of the feature can be returned if they are hit. A typical example is a feature is painted using both a geometry on the map and a label. It is up to the caller of this method to filter out duplicate feature hits if needed.
query
- the feature query containing the parameters to use to query the visible featurescallback
- a callback which can handle the result of the query operation. Cannot be null
.NullPointerException
- when the call back is null
.@NotNull public Map.ViewMapTransformation getViewMapTransformation()
public void setBackgroundColor(@NotNull android.graphics.Color color)
color
- the new background color.@NotNull public android.graphics.Color getBackgroundColor()
public void setController(@Nullable IController controller)
When a controller is set, the map will call IController#onActivate
to let the controller know it is activated. The previous controller if present will first receive a call to IController#onDeactivate
.
controller
- The new active controller. If null
is given, that will only deactivate the previous one. Given that, no further interaction will be possible on the map until a controller is set again.@Nullable public IController getController()
No default behavior is
null
if no controller has been set.@NotNull public AnimationManager getAnimationManager()
AnimationManager
from the UI thread.
IAnimation
will be invoked from the render thread. Because of this, animations are for example suitable to animate and update the map's camera
.
See the related article: Threading rules for the Map
AnimationManager
attached to this map.public void setCursor(@NotNull MouseCursor cursor)
Changing the cursor triggers a call to the mouse cursor callback if set.
cursor
- the new cursor.Map#setMouseCursorCallback
@NotNull public MouseCursor getCursor()
The default value is MouseCursor#defaultCursor
.
Map#setCursor
public void setMouseCursorCallback(@Nullable IMouseCursorCallback mouseCursorCallback)
IMouseCursorCallback
.
This callback is called when the map's cursor has changed. Can be null
. The callback is owned by the calling code, i.e. typically code that integrates the Map
in a UI framework. Beware that this callback should not call (directly or indirectly) the map (for example Map::paint) because it can be called on any thread.
mouseCursorCallback
- a callback that is called when the map has changed.public boolean is3D()
Map
is visualized in 3D.
Currently, this will only be true if the map reference
is geocentric.
Having a 2D map limits the navigation, for example the camera can not be tilted and will always be top-down.
Currently, 3D maps always use a perspective camera
and 2D maps always use an orthographic camera
.
Map
is visualized in 3D.public double getDisplayScale()
setDisplayScale
has never been calledpublic void setDisplayScale(double displayScale)
When a feature is scaled by the display scale, it means that pixel distances are scale. For example:
This method must be called every time the display or its display scale changes to ensure proper rendering.
You can call this method on any thread, but its behavior is slightly different:
See the threading article for a more detailed explanation on the threading behavior.
The default is 1.0;
displayScale
- the display scale. A value of 1.0 corresponds with a display scale of 100%.public double getDpi()
public void setDpi(double dpi)
By default, the map uses the default DPI of your platform (96 on Windows/Linux, 72 on MacOS, 160 on Android). The DPI value should be set to the physical DPI value of the display to get accurate results.
You can call this method on any thread, but its behavior is slightly different:
See the threading article for a more detailed explanation on the threading behavior.
dpi
- the dpi valuepublic void addRendererCallback(@NotNull Map.IRendererCallback rendererCallback) throws NullPointerException
Map
.
After calling this method, the Map.Renderer#paint
will start calling the given callback instance.
rendererCallback
- a renderer callback instance. Cannot be null
.NullPointerException
- when the renderer call back is null
.public void removeRendererCallback(@NotNull Map.IRendererCallback rendererCallback) throws NullPointerException
Map
.
After calling this method, the Map.Renderer#paint
will stop calling the given callback instance.
rendererCallback
- a renderer callback instance. Cannot be null
.NullPointerException
- when the renderer call back is null
.@NotNull public GraphicsEffects getEffects()
GraphicsEffects
instance that can apply graphics effects on this map. Have a look at GraphicsEffects
for a list of effects that are available.@NotNull public Map.HeightProvider getHeightProvider()
Map
based height provider.