MapMarker (API Reference)
Class MapMarker
MapMarker is used to draw images on the map, for example to mark a specific location.
By default, the marker is centered on the given geographic coordinates.
Markers keep their size regardless of the current zoom level of the map view.
The image to be displayed is represented by MapImage object. For performance reasons,
it is highly recommended to reuse a single instance of the image when creating multiple
identical markers.
To display the map marker, it needs to be added to the scene using MapScene.addMapMarker(com.here.sdk.mapview.MapMarker).
To stop displaying it, remove it from the scene using MapScene.removeMapMarker(com.here.sdk.mapview.MapMarker).
The display of a map marker is only guaranteed in case its origin is within the viewport. At the moment, this is a known limitation that mostly affects map markers which are visually large and cover a sizeable part of the viewport.
Note:
Due to technical limitations using the MapMarkers API to add a very large number of markers
(several thousands, especially 10000+) is not recommended. Adding this many markers will have a
negative impact on the performance leading to stuttering of the app and lower frame rates.
To work around this limitation the following approach can be used:
Register to map camera updates using MapCamera.addListener(com.here.sdk.mapview.MapCameraListener). Query the bounding box of the
camera viewport using MapCamera.getBoundingBox() (it may be extended)
and then use the method GeoBox.contains(GeoCoordinates) in combination with
MapCamera.State.distanceToTargetInMeters to determine which MapMarkers are actually visible
to the user in the current camera viewport and thus need to be added to the map.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionMapMarker(GeoCoordinates coordinates, MapImage image) Creates an instance of a marker at given coordinates, represented by specified image.MapMarker(GeoCoordinates coordinates, MapImage image, Anchor2D anchor) Creates an instance of a marker at given coordinates, represented by specified image, with anchor point specifying how the image is positioned relative to the marker's coordinates.MapMarker(GeoCoordinates coordinates, MapImage image, String text) Creates aMapMarkerinstance at given coordinates with specified image and text and a default text style. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancelAnimation(MapMarkerAnimation animation) Cancels single ongoing animation.Gets current anchor point for the marker image.Gets the point on the map where the marker is drawn.intGets draw order of this marker relative to other markers.Gets the current duration of a fade-in effect on marker addition to a scene or a fade-out effect on marker removal from a scene.getImage()Gets currently used map image.Gets the Metadata instance attached to this marker.doubleGets the current opacity of the marker image.getText()Gets the text drawn on the map by theMapMarker.Gets a copy of theTextStylecurrently in use by theMapMarker.Gets the list of visibility ranges.booleanReturnstrueif the marker allows overlap with other markers,falseotherwise.booleanReturnstrueif the marker allows text to be hidden,falseotherwise.voidSets anchor point of the marker image which specifies the position offset relative to the marker's coordinates.voidsetCoordinates(GeoCoordinates value) Sets the point on the map where the marker is drawn.voidsetDrawOrder(int value) Sets draw order of this marker relative to other markers.voidsetFadeDuration(Duration value) Sets duration of a fade-in effect on marker addition to a scene or a fade-out effect on marker removal from a scene.voidSets map image used to represent the marker on screen.voidsetMetadata(Metadata value) Sets the Metadata instance attached to this marker.voidsetOpacity(double value) Sets the opacity of the marker image.voidsetOverlapAllowed(boolean value) Sets whether the marker is allowed to overlap with other markers.voidSets the text to be drawn on the map by theMapMarker.voidsetTextOptional(boolean value) Sets whether the marker is allowed to appear without text.voidsetTextStyle(MapMarker.TextStyle value) Sets theTextStyleto be used by theMapMarker.voidsetVisibilityRanges(List<MapMeasureRange> value) Sets visibility ranges for this map marker.voidstartAnimation(MapMarkerAnimation animation, AnimationListener animationListener) Starts animation of this map marker according to providedMapMarkerAnimation.
-
Constructor Details
-
MapMarker
Creates an instance of a marker at given coordinates, represented by specified image.
The altitude component of the coordinates is ignored.
- Parameters:
coordinates-The marker's geographical coordinates.
image-The image to draw on the map.
-
MapMarker
public MapMarker(@NonNull GeoCoordinates coordinates, @NonNull MapImage image, @NonNull String text) Creates a
MapMarkerinstance at given coordinates with specified image and text and a default text style.The altitude component of the coordinates is ignored.
- Parameters:
coordinates-The marker's geographical coordinates.
image-The image to draw on the map.
text-The text to draw on the map.
-
MapMarker
public MapMarker(@NonNull GeoCoordinates coordinates, @NonNull MapImage image, @NonNull Anchor2D anchor) Creates an instance of a marker at given coordinates, represented by specified image, with anchor point specifying how the image is positioned relative to the marker's coordinates.
The anchor is a way of specifying position offset relative to image's dimensions on the screen. For example, (0, 0) places the top-left corner of the image at the marker's coordinates. (1, 1) would place the bottom-right corner of the image at the marker's coordinates. (0.5, 0.5) which is the default value would center the image at the marker's coordinates. Values outside the 0..1 range are also allowed, for example (0.5, 2) would display the image centered horizontally with its bottom edge above the marker's coordinates at the distance in pixels that is equal to the height of the image.
- Parameters:
coordinates-The marker's geographical coordinates.
image-The image to draw on the map.
anchor-The anchor point for the marker image which specifies the position offset relative to the marker's coordinates.
-
-
Method Details
-
startAnimation
public void startAnimation(@NonNull MapMarkerAnimation animation, @Nullable AnimationListener animationListener) Starts animation of this map marker according to provided
MapMarkerAnimation.The
MapMarkerAnimationmay be shared between multiple instances ofMapMarker.Starting animation on one map marker does not influence any ongoing animations on other map markers. Any ongoing animation of this marker instance will get cancelled.
- Parameters:
animation-The animation to start, may be used for multiple different map markers.
animationListener-The listener to receive notifications about animation start, completion or cancellation.
-
cancelAnimation
Cancels single ongoing animation.
Does nothing if animation was not started for this map marker.
Does not cancel other animations if the same
MapMarkerAnimationobject was applied to multipleMapMarkers.- Parameters:
animation-The animation to cancel.
-
getCoordinates
Gets the point on the map where the marker is drawn.
- Returns:
The point on the map where the map marker is drawn.
-
setCoordinates
Sets the point on the map where the marker is drawn. The altitude component of the coordinates is ignored.
- Parameters:
value-The point on the map where the map marker is drawn.
-
getMetadata
Gets the Metadata instance attached to this marker. This will be
nullif nothing has been attached before.- Returns:
The Metadata instance attached to this marker, see
Metadata.
-
setMetadata
Sets the Metadata instance attached to this marker.
- Parameters:
value-The Metadata instance attached to this marker, see
Metadata.
-
isOverlapAllowed
public boolean isOverlapAllowed()Returns
trueif the marker allows overlap with other markers,falseotherwise. Defaults totrue.- Returns:
Determines whether or not the marker can overlap other markers.
-
setOverlapAllowed
public void setOverlapAllowed(boolean value) Sets whether the marker is allowed to overlap with other markers.
If
false, it will disappear the moment it overlaps another marker that has a higher visibility priority. A marker that allows overlap will always be drawn. Among markers that don't allow overlap, the one with the highest draw order has priority. Marker that is hidden due to overlapping with other markers is not pickable.- Parameters:
value-Determines whether or not the marker can overlap other markers.
-
isTextOptional
public boolean isTextOptional()Returns
trueif the marker allows text to be hidden,falseotherwise. Defaults tofalse.- Returns:
Determines if the marker can be displayed with icon and without text.
-
setTextOptional
public void setTextOptional(boolean value) Sets whether the marker is allowed to appear without text.
Controls whenever
MapMarkercan be shown as icon only whenisOverlapAllowed()isfalse, has no effect otherwise. Iffalsethen theMapMarkerwill not appear when icon or text are blocked by other labels. Iftrue, icon will appear even if the text part is blocked by other labels.- Parameters:
value-Determines if the marker can be displayed with icon and without text.
-
getDrawOrder
public int getDrawOrder()Gets draw order of this marker relative to other markers. The default value is 0.
- Returns:
The draw order of this marker relative to other markers.
-
setDrawOrder
public void setDrawOrder(int value) Sets draw order of this marker relative to other markers.
Markers with higher draw order value are drawn on top of markers with lower draw order. In case multiple markers have the same draw order value then the order in which they were added to the scene matters. Last added marker is drawn on top.
Allowed range is [0, 1023]. Values outside this range will be clamped. The default value is 0.
- Parameters:
value-The draw order of this marker relative to other markers.
-
getImage
Gets currently used map image.
- Returns:
Image representing the marker on the screen.
-
setImage
Sets map image used to represent the marker on screen.
- Parameters:
value-Image representing the marker on the screen.
-
getAnchor
Gets current anchor point for the marker image.
- Returns:
The anchor point for the marker image which specifies the position offset relative to the marker's coordinates.
-
setAnchor
Sets anchor point of the marker image which specifies the position offset relative to the marker's coordinates.
For example, (0, 0) places the top-left corner of the image at the marker's coordinates. (1, 1) would place the bottom-right corner of the image at the marker's coordinates. (0.5, 0.5) which is the default value would center the image at the marker's coordinates. Values outside the 0..1 range are also allowed, for example (0.5, 2) would display the image centered horizontally with its bottom edge above the marker's coordinates at the distance in pixels that is equal to the height of the image.
- Parameters:
value-The anchor point for the marker image which specifies the position offset relative to the marker's coordinates.
-
getOpacity
public double getOpacity()Gets the current opacity of the marker image. Value is in the range of [0.0, 1.0]. Default value is 1.0.
- Returns:
Opacity, the factor applied to the alpha channel of the marker image.
-
setOpacity
public void setOpacity(double value) Sets the opacity of the marker image.
Provided value is clamped to the range of [0.0, 1.0]. Default value is 1.0, which means marker is displayed with the default opacity of the image.
Markers with opacity value set to 0.0 are still on the map and are considered for picking.
- Parameters:
value-Opacity, the factor applied to the alpha channel of the marker image.
-
getFadeDuration
Gets the current duration of a fade-in effect on marker addition to a scene or a fade-out effect on marker removal from a scene.
- Returns:
Duration of a fade-in effect on marker addition to a scene or a fade-out effect on marker removal from a scene.
-
setFadeDuration
Sets duration of a fade-in effect on marker addition to a scene or a fade-out effect on marker removal from a scene.
Provided value is clamped in range [0.0, 10.0] seconds. Default value is 0 seconds which means the effect is disabled and marker is added/removed immediately without any animation. Fade-in effect is also applied when marker leaves and then re-enters screen area.
Change to this property is made asynchronously and is not guaranteed to take effect on the next rendered frame. In particular, changing fade duration and removing the marker immediately after may result in the new value being ignored for this removal.
- Parameters:
value-Duration of a fade-in effect on marker addition to a scene or a fade-out effect on marker removal from a scene.
-
getText
Gets the text drawn on the map by the
MapMarker.- Returns:
The text to be drawn on the map along with the image of the
MapMarker.
-
setText
Sets the text to be drawn on the map by the
MapMarker.- Parameters:
value-The text to be drawn on the map along with the image of the
MapMarker.
-
getTextStyle
Gets a copy of the
TextStylecurrently in use by theMapMarker.- Returns:
The
TextStyleapplied to the text of theMapMarker.
-
setTextStyle
Sets the
TextStyleto be used by theMapMarker.- Parameters:
value-The
TextStyleapplied to the text of theMapMarker.
-
getVisibilityRanges
Gets the list of visibility ranges. The map marker is visible only inside these map measure ranges. When empty (the default), the map marker is visible without map measure restrictions.
- Returns:
The list of visibility ranges. The map marker is visible only inside these map measure ranges.
-
setVisibilityRanges
Sets visibility ranges for this map marker.
A range is half open - [minimumZoomLevel, maximumZoomLevel), the given maximum value is not contained in the range. The map marker is visible only inside these map measure ranges.
When empty (the default), the map marker is visible without map measure restrictions. Only
MapMeasureRange(s) ofMapMeasure.Kind.ZOOM_LEVELtype are supported.MapMeasureRange(s) of other unsupported types will be ignored.- Parameters:
value-The list of visibility ranges. The map marker is visible only inside these map measure ranges.
-