Class MapScene
Class MapScene
- java.lang.Object
-
- com.here.NativeBase
-
- com.here.sdk.mapview.MapScene
-
public final class MapScene extends NativeBase
Represents a map scene and exposes the functionality to manipulate its content.
Map schemes
The content of the displayed map and how it looks is specified by a
MapSchemewhich is set when loading a scene withloadScene(MapScheme, MapScene.LoadSceneCallback). It is also possible to load your own custom map scheme from a file bundled with your application. Supported file formats are:- JSON (file extension '.json'; e.g. 'my_custom_style.json')
- ZIP archive (file extension '.zip'; e.g. 'my_custom_style.zip'), with the following archive structure:
- root folder: any, not empty (e.g. 'my_custom_style')
- JSON configuration: '
/style.json' - custom assets folder: '
/assets'
Map features
Different map schemes offer different sets of features, for example showing traffic or 3D buildings. Some features have multiple modes of operation, but most have only one.
getSupportedFeatures()can be used to check what features and modes are supported for the current scene. Features can be enabled usingenableFeatures(java.util.Map<java.lang.String, java.lang.String>)and disabled withdisableFeatures(java.util.List<java.lang.String>). Checking which features are currently enabled can be done usinggetActiveFeatures(). For convenience,MapFeaturesandMapFeatureModeshold constants for feature and mode names.Since version 4.15.0, map features cannot be controlled using
setLayerVisibility(java.lang.String, com.here.sdk.mapview.VisibilityState), sincesetLayerVisibility(java.lang.String, com.here.sdk.mapview.VisibilityState)controls only visibility of the layers which are corresponding to the features enabled either byenableFeatures(java.util.Map<java.lang.String, java.lang.String>)or enabled by default for the scene.Map layers
A map scheme is organized in layers, which can be controlled using
setLayerVisibility(java.lang.String, com.here.sdk.mapview.VisibilityState). It's possible to change the visibility state of any map layer as long as the name is known.Layer visibility settings persist between scene reloading.
User content
User generated content can be visualised on the map using
MapPolyline,MapPolygon,MapMarker,MapMarkerCluster,MapArrow,MapMarker3DandMapImageOverlay(collectively referred to as "map items"). Those can be added to and removed from the scene by respective add and remove methods. The render order of the map items is according to the list above. The order of objects within the same type can be controlled using thesetDrawOrder()method of each object.Be careful when adding a very large number of map items as this can have a negative impact on the performance of the app. 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 usingMapCamera.getBoundingBox()(it may be extended) and then use the methodGeoBox.contains(GeoCoordinates)in combination withMapCamera.State.distanceToTargetInMetersto determine which map items 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 Modifier and Type Class Description static interfaceMapScene.LoadSceneCallbackCalled on the main thread afterloadScene()method finishes loading the scene.static classMapScene.MapPickFilterFilter for the map content to be picked.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMapArrow(MapArrow mapArrow)Adds a map arrow to this map scene.voidaddMapImageOverlay(MapImageOverlay overlay)Adds a map image overlay to this map scene.voidaddMapMarker(MapMarker marker)Adds a map marker to this map scene.voidaddMapMarker3d(MapMarker3D marker)Adds a 3D map marker to this map scene.voidaddMapMarkerCluster(MapMarkerCluster cluster)Adds a map marker cluster to the map.voidaddMapMarkers(java.util.List<MapMarker> markers)Adds multiple map markers to this map scene.voidaddMapPolygon(MapPolygon mapPolygon)Adds a map polygon to this map scene.voidaddMapPolyline(MapPolyline mapPolyline)Adds a map polyline to this map scene.voidaddMapPolylines(java.util.List<MapPolyline> mapPolylines)Adds map polylines to this map scene.voiddisableFeatures(java.util.List<java.lang.String> features)Disables specified map features.voidenableFeatures(java.util.Map<java.lang.String,java.lang.String> features)Enables specified map features.java.util.Map<java.lang.String,java.lang.String>getActiveFeatures()Gets map features that are currently active.MapSceneLightsgetLights()Gets a MapSceneLights instance that controls lights present in the scene.java.util.Map<java.lang.String,java.util.List<java.lang.String>>getSupportedFeatures()Gets features and all of their modes supported by the currently loaded scene configuration.voidloadScene(MapSceneLoadOptions options, MapScene.LoadSceneCallback callback)Asynchronously loads a map scene using MapSceneLoadOptions.voidloadScene(MapScheme mapScheme, MapScene.LoadSceneCallback callback)Asynchronously loads a map scene described by a specified map scheme.voidloadScene(java.lang.String configurationFile, MapScene.LoadSceneCallback callback)Asynchronously loads a map scene described by a specified file in one of the supported formats.voidloadScene(java.lang.String configurationFile, WatermarkStyle watermarkStyle, MapScene.LoadSceneCallback callback)Asynchronously loads a map scene described by a specified file in one of the supported formats.voidreloadScene()Asynchronously reloads the current map scene from file.voidremoveMapArrow(MapArrow mapArrow)Removes a map arrow from this map scene.voidremoveMapImageOverlay(MapImageOverlay overlay)Removes a map image overlay from this map scene.voidremoveMapMarker(MapMarker marker)Removes a map marker from this map scene.voidremoveMapMarker3d(MapMarker3D marker)Removes a 3D map marker from this map scene.voidremoveMapMarkerCluster(MapMarkerCluster cluster)Removes a map marker cluster from the map.voidremoveMapMarkers(java.util.List<MapMarker> markers)Removes multiple map markers from this map scene.voidremoveMapPolygon(MapPolygon mapPolygon)Removes a map polygon from this map scene.voidremoveMapPolyline(MapPolyline mapPolyline)Removes a map polyline from this map scene.voidremoveMapPolylines(java.util.List<MapPolyline> mapPolylines)Removes map polylines from this map scene.voidsetLayerVisibility(java.lang.String layerName, VisibilityState visibility)Immediately changes the visibility of a specified map layer.
-
-
-
Method Detail
-
loadScene
public void loadScene(@NonNull MapScheme mapScheme, @Nullable MapScene.LoadSceneCallback callback)Asynchronously loads a map scene described by a specified map scheme. Any previous map scene config will be replaced. The loaded scene is cached and so any changes made to the scene files on disk might not get reflected on a successive call to this function. Instead the reloadScene API can handle such use-cases to force-update the scene.
Map features enabled or disabled using
enableFeatures(java.util.Map<java.lang.String, java.lang.String>)anddisableFeatures(java.util.List<java.lang.String>)will be reset to defaults for the new scene configuration.The callback is called on the main thread. When recreating an activity following a device rotation, it is not necessary to call this method a second time. The map scheme that was loaded when the map view was initially created will continue to be used.
- Parameters:
mapScheme-Map scheme.
callback-Optional callback that will receive the result of this operation.
-
loadScene
public void loadScene(@NonNull java.lang.String configurationFile, @Nullable MapScene.LoadSceneCallback callback)Asynchronously loads a map scene described by a specified file in one of the supported formats. Any previous map scene config will be replaced.
When loading the same file again, consider to call
reloadScene()instead.Map features enabled or disabled using
enableFeatures(java.util.Map<java.lang.String, java.lang.String>)anddisableFeatures(java.util.List<java.lang.String>)will be reset to defaults for the new scene configuration.The callback is called on the main thread. When recreating an activity following a device rotation, it is not necessary to call this method a second time. The map scheme that was loaded when the map view was initially created will continue to be used.
- Parameters:
configurationFile-Map scheme configuration file. It must contain the whole scene configuration. In case it contains references to other files, they have to be reachable under the paths specified in the main configuration file.
callback-Optional callback that will receive the result of this operation.
-
loadScene
public void loadScene(@NonNull java.lang.String configurationFile, @NonNull WatermarkStyle watermarkStyle, @Nullable MapScene.LoadSceneCallback callback)Asynchronously loads a map scene described by a specified file in one of the supported formats. The style of the HERE watermark matching the map scheme is specified. Any previous map scene config will be replaced.
When loading the same file again, consider to call
reloadScene()instead.Map features enabled or disabled using
enableFeatures(java.util.Map<java.lang.String, java.lang.String>)anddisableFeatures(java.util.List<java.lang.String>)will be reset to defaults for the new scene configuration.The callback is called on the main thread. When recreating an activity following a device rotation, it is not necessary to call this method a second time. The map scheme that was loaded when the map view was initially created will continue to be used.
- Parameters:
configurationFile-Map scheme configuration file. It must contain the whole scene configuration. In case it contains references to other files, they have to be reachable under the paths specified in the main configuration file.
watermarkStyle-The style for the HERE watermark, see
WatermarkStyle.callback-Optional callback that will receive the result of this operation.
-
loadScene
public void loadScene(@NonNull MapSceneLoadOptions options, @Nullable MapScene.LoadSceneCallback callback)Asynchronously loads a map scene using MapSceneLoadOptions.
This is an unified API that supports loading from either a map scheme or configuration file, with optional feature and watermark configuration. It's more efficient to load the scene with this function by specifying the list of enabled features and disabled features, compared to loading the scene first and enabling or disabling map features in the scene loading callback function.
Configuration defaults are used for features that are not part of the enabled features or disabled features parameters. When a feature is in both the enabled and disabled lists, the feature is considered as requested to be enabled. If the same feature is present multiple times in the enabled list with different modes, then the feature is considered as requested to be enabled, but with an unspecified mode (any of the many specified in the enabled list).
Any previous map scene config will be replaced. The callback is called on the main thread.
When recreating an activity following a device rotation, it is not necessary to call this method a second time. The map scheme that was loaded when the map view was initially created will continue to be used.
Note: This is a beta release of this feature, so there could be a few bugs and unexpected behaviors. Related APIs may change for new releases without a deprecation process.
- Parameters:
options-Scene configuration options created using MapSceneLoadOptionsBuilder.
callback-Optional callback that will receive the result of this operation.
-
addMapPolyline
public void addMapPolyline(@NonNull MapPolyline mapPolyline)Adds a map polyline to this map scene.
- Parameters:
mapPolyline-The map polyline to be added to this map scene.
-
addMapPolylines
public void addMapPolylines(@NonNull java.util.List<MapPolyline> mapPolylines)Adds map polylines to this map scene.
Note: Due to technical limitations using the MapPolyline API to add a very large number of polylines (especially 1000+ also depending on their complexity) is not recommended. Adding this many polylines has a negative impact on the performance leading to stuttering of the app and lower frame rates. To work around this limitation add only map items which are in the current camera viewport. A guide on how to achieve this can be found towards the end of the
MapSceneclass doc.- Parameters:
mapPolylines-The map polylines to be added to this map scene.
-
removeMapPolyline
public void removeMapPolyline(@NonNull MapPolyline mapPolyline)Removes a map polyline from this map scene.
- Parameters:
mapPolyline-The map polyline to be removed from this map scene.
-
removeMapPolylines
public void removeMapPolylines(@NonNull java.util.List<MapPolyline> mapPolylines)Removes map polylines from this map scene.
- Parameters:
mapPolylines-The map polylines to be removed from this map scene.
-
addMapArrow
public void addMapArrow(@NonNull MapArrow mapArrow)Adds a map arrow to this map scene.
Note: Due to technical limitations using the MapArrow API to add a very large number of arrows (especially 1000+ also depending on their complexity) is not recommended. Adding this many arrows has a negative impact on the performance leading to stuttering of the app and lower frame rates. To work around this limitation add only map items which are in the current camera viewport. A guide on how to achieve this can be found towards the end of the
MapSceneclass doc.- Parameters:
mapArrow-The map arrow to be added to this map scene.
-
removeMapArrow
public void removeMapArrow(@NonNull MapArrow mapArrow)Removes a map arrow from this map scene.
- Parameters:
mapArrow-The map arrow to be removed from this map scene.
-
addMapMarker
public void addMapMarker(@NonNull MapMarker marker)Adds a map marker to this map scene. Adding the same marker instance multiple times has no effect. Adding a marker that is already part of a map marker cluster has no effect.
- Parameters:
marker-The marker to be added to this map scene.
-
addMapMarkers
public void addMapMarkers(@NonNull java.util.List<MapMarker> markers)Adds multiple map markers to this map scene. Adding the same marker instances multiple times has no effect. Adding markers that are already part of a map marker cluster has no effect.
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 add only map items which are in the current camera viewport. A guide on how to achieve this can be found towards the end of the
MapSceneclass doc.- Parameters:
markers-The list of markers to be added to this map scene.
-
removeMapMarker
public void removeMapMarker(@NonNull MapMarker marker)Removes a map marker from this map scene. Removing a marker instance that is not a part of this scene or belongs to a marker cluster has no effect.
- Parameters:
marker-The marker to be removed from this map scene.
-
removeMapMarkers
public void removeMapMarkers(@NonNull java.util.List<MapMarker> markers)Removes multiple map markers from this map scene. Removing marker instances that are not a part of this scene or belong to a marker cluster has no effect.
- Parameters:
markers-The list of markers to be removed from this map scene.
-
addMapMarkerCluster
public void addMapMarkerCluster(@NonNull MapMarkerCluster cluster)Adds a map marker cluster to the map. Either the contained individual map markers or the cluster markers will be displayed. Adding the same map marker cluster instance multiple times has no effect.
- Parameters:
cluster-The marker cluster to be added to this map scene.
-
removeMapMarkerCluster
public void removeMapMarkerCluster(@NonNull MapMarkerCluster cluster)Removes a map marker cluster from the map. Removing a map marker cluster that is not on this scene has no effect.
- Parameters:
cluster-The marker cluster to be removed from this map scene.
-
addMapMarker3d
public void addMapMarker3d(@NonNull MapMarker3D marker)Adds a 3D map marker to this map scene. Does nothing if the marker instance was already added to the scene.
Note: Due to technical limitations using the MapMarker3D API to add a very large number of 3D markers (especially 500+ also depending on the complexity of the 3D object) is not recommended. Adding this many 3D markers has a negative impact on the performance leading to stuttering of the app and lower frame rates. To work around this limitation add only map items which are in the current camera viewport. A guide on how to achieve this can be found towards the end of the
MapSceneclass doc.- Parameters:
marker-The marker to be added to this map scene.
-
removeMapMarker3d
public void removeMapMarker3d(@NonNull MapMarker3D marker)Removes a 3D map marker from this map scene. Removing a marker instance that is not on this scene has no effect.
- Parameters:
marker-The marker to be removed from this map scene.
-
addMapPolygon
public void addMapPolygon(@NonNull MapPolygon mapPolygon)Adds a map polygon to this map scene.
Note: Due to technical limitations using the MapPolygon API to add a very large number of polygons (especially 1000+ also depending on their complexity) is not recommended. Adding this many polygons has a negative impact on the performance leading to stuttering of the app and lower frame rates. To work around this limitation add only map items which are in the current camera viewport. A guide on how to achieve this can be found towards the end of the
MapSceneclass doc.- Parameters:
mapPolygon-The map polygon to be added to this map scene.
-
removeMapPolygon
public void removeMapPolygon(@NonNull MapPolygon mapPolygon)Removes a map polygon from this map scene.
- Parameters:
mapPolygon-The map polygon to be removed from this map scene.
-
addMapImageOverlay
public void addMapImageOverlay(@NonNull MapImageOverlay overlay)Adds a map image overlay to this map scene. Adding the same overlay instance multiple times has no effect.
- Parameters:
overlay-The overlay to be added to this map scene.
-
removeMapImageOverlay
public void removeMapImageOverlay(@NonNull MapImageOverlay overlay)Removes a map image overlay from this map scene. Removing an overlay instance that is not part of this scene has no effect.
- Parameters:
overlay-The overlay to be removed from this map scene.
-
setLayerVisibility
public void setLayerVisibility(@NonNull java.lang.String layerName, @NonNull VisibilityState visibility)Immediately changes the visibility of a specified map layer.
- Parameters:
layerName-The name of the map layer to be changed.
visibility-The new visibility state of the layer.
-
getActiveFeatures
@NonNull public java.util.Map<java.lang.String,java.lang.String> getActiveFeatures()
Gets map features that are currently active. Active features are features that are either enabled via a call to
enableFeatures(java.util.Map<java.lang.String, java.lang.String>)or that are enabled by default in the scene.The key to the resulting map is the name of the feature and the value is the active mode.
Result is empty if scene has not been loaded.
- Returns:
The map of active features.
-
getSupportedFeatures
@NonNull public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getSupportedFeatures()
Gets features and all of their modes supported by the currently loaded scene configuration.
The key to the resulting map is the name of the feature and the value is a list of modes for that feature.
Result is empty if scene has not been loaded.
- Returns:
The map of supported features and all their modes.
-
enableFeatures
public void enableFeatures(@NonNull java.util.Map<java.lang.String,java.lang.String> features)Enables specified map features. Those will become active after next map redraw, meaning that
getActiveFeatures()will return updated list of active features only after the redraw happens.Does not affect features that were not specified. Unsupported features are ignored.
May cause the current map configuration to be reloaded.
See
MapFeaturesfor feature names andMapFeatureModesfor feature mode names.- Parameters:
features-The list of features to enable, key is the name of the feature (see
MapFeatures), value specifies its mode (seeMapFeatureModes).
-
disableFeatures
public void disableFeatures(@NonNull java.util.List<java.lang.String> features)Disables specified map features. Those will become inactive after next map redraw, meaning that
getActiveFeatures()will return updated list of active features only after the redraw happens.Does not affect features that were not specified. Unsupported features are ignored.
May cause the current map configuration to be reloaded.
See
MapFeaturesfor feature names.- Parameters:
features-The names of features to disable (see
MapFeatures).
-
reloadScene
public void reloadScene()
Asynchronously reloads the current map scene from file. This skips any cached data used internally and reloads the scene including any changes made to the (custom) map styles in JSON.
MapFeaturesettings will be preserved.Internal optimization checks will be skipped to ensure all custom style changes are loaded. Therefore, calling this method may take slightly longer than calling one of the
loadScene(..)overloads.
-
getLights
@NonNull public MapSceneLights getLights()
Gets a MapSceneLights instance that controls lights present in the scene.
Note: This is a beta release of this feature, so there could be a few bugs and unexpected behaviors. Related APIs may change for new releases without a deprecation process.
Provides access to a MapSceneLights instance that controls the lights in the scene.
The behavior of the returned MapSceneLights instance depends on the state of the scene:
- If the scene is not loaded, the returned MapSceneLights instance will not contain any light settings, as lights are not loaded without a scene.
- If the scene is loaded, the returned MapSceneLights instance reflects the current light settings of the loaded scene.
Scene Change Behavior:
- If the scene changes, the MapSceneLights instance will be updated to reflect the light settings of the new scene.
- Any user-defined settings to MapSceneLights will be overridden by the new scene's light settings when the scene changes.
Error Handling:
- If the scene is loaded and the loaded scene does not utilize or specify light settings:
- If the lights are not present, the error callback may return a NO_LIGHTS state.
- Returns:
Controls lights present in the scene.
-
-