public final class MapboxMap extends Object
MapboxMap
object directly, rather,
you must obtain one from the getMapAsync() method on a MapFragment or MapView that you have
added to your application.
Note: Similar to a View object, a MapboxMap should only be read and modified from the main thread.
Modifier and Type | Class and Description |
---|---|
static interface |
MapboxMap.CancelableCallback
Interface definition for a callback to be invoked when a task is complete or cancelled.
|
static interface |
MapboxMap.InfoWindowAdapter
Interface definition for a callback to be invoked when an info window will be shown.
|
static class |
MapboxMap.MarkerViewAdapter<U extends MarkerView>
Interface definition for a callback to be invoked when an MarkerView will be shown.
|
static interface |
MapboxMap.OnCameraChangeListener
Deprecated.
Replaced by
MapboxMap.OnCameraMoveStartedListener , MapboxMap.OnCameraMoveListener and
MapboxMap.OnCameraIdleListener . The order in which the deprecated onCameraChange method will be called in
relation to the methods in the new camera change listeners is undefined. |
static interface |
MapboxMap.OnCameraIdleListener
Interface definition for a callback to be invoked for when camera movement has ended.
|
static interface |
MapboxMap.OnCameraMoveCanceledListener
Interface definition for a callback to be invoked for when the camera's motion has been stopped or when the camera
starts moving for a new reason.
|
static interface |
MapboxMap.OnCameraMoveListener
Interface definition for a callback to be invoked for when the camera changes position.
|
static interface |
MapboxMap.OnCameraMoveStartedListener
Interface definition for a callback to be invoked for when the camera motion starts.
|
static interface |
MapboxMap.OnFlingListener
Interface definition for a callback to be invoked when the map is flinged.
|
static interface |
MapboxMap.OnFpsChangedListener
Interface definition for a callback to be invoked when a frame is rendered to the map view.
|
static interface |
MapboxMap.OnInfoWindowClickListener
Interface definition for a callback to be invoked when the user clicks on an info window.
|
static interface |
MapboxMap.OnInfoWindowCloseListener
Interface definition for a callback to be invoked when a marker's info window is closed.
|
static interface |
MapboxMap.OnInfoWindowLongClickListener
Interface definition for a callback to be invoked when the user long presses on a marker's info window.
|
static interface |
MapboxMap.OnMapClickListener
Interface definition for a callback to be invoked when the user clicks on the map view.
|
static interface |
MapboxMap.OnMapLongClickListener
Interface definition for a callback to be invoked when the user long clicks on the map view.
|
static interface |
MapboxMap.OnMarkerClickListener
Interface definition for a callback to be invoked when the user clicks on a marker.
|
static interface |
MapboxMap.OnMarkerViewClickListener
Interface definition for a callback to be invoked when the user clicks on a MarkerView.
|
static interface |
MapboxMap.OnMyBearingTrackingModeChangeListener
Interface definition for a callback to be invoked when the the My Location tracking mode changes.
|
static interface |
MapboxMap.OnMyLocationChangeListener
Interface definition for a callback to be invoked when the the My Location view changes location.
|
static interface |
MapboxMap.OnMyLocationTrackingModeChangeListener
Interface definition for a callback to be invoked when the the My Location tracking mode changes.
|
static interface |
MapboxMap.OnPolygonClickListener
Interface definition for a callback to be invoked when the user clicks on a polygon.
|
static interface |
MapboxMap.OnPolylineClickListener
Interface definition for a callback to be invoked when the user clicks on a polyline.
|
static interface |
MapboxMap.OnScrollListener
Interface definition for a callback to be invoked when the map is scrolled.
|
static interface |
MapboxMap.OnStyleLoadedListener
Interface definition for a callback to be invoked when the style has finished loading.
|
static interface |
MapboxMap.SnapshotReadyCallback
Interface definition for a callback to be invoked when the snapshot has been taken.
|
Modifier and Type | Method and Description |
---|---|
void |
addImage(String name,
Bitmap image)
Adds an image to be used in the map's style
|
void |
addLayer(Layer layer)
Adds the layer to the map.
|
void |
addLayerAbove(Layer layer,
String above)
Adds the layer to the map.
|
void |
addLayerAt(Layer layer,
int index)
Adds the layer to the map at the specified index.
|
void |
addLayerBelow(Layer layer,
String below)
Adds the layer to the map.
|
Marker |
addMarker(BaseMarkerOptions markerOptions)
Adds a marker to this map.
|
MarkerView |
addMarker(BaseMarkerViewOptions markerOptions)
Adds a marker to this map.
|
MarkerView |
addMarker(BaseMarkerViewOptions markerOptions,
MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener)
Adds a marker to this map.
|
Marker |
addMarker(MarkerOptions markerOptions)
Adds a marker to this map.
|
List<Marker> |
addMarkers(List<? extends BaseMarkerOptions> markerOptionsList)
Adds multiple markers to this map.
|
List<MarkerView> |
addMarkerViews(List<? extends BaseMarkerViewOptions> markerViewOptions)
Adds multiple markersViews to this map.
|
Polygon |
addPolygon(PolygonOptions polygonOptions)
Adds a polygon to this map.
|
List<Polygon> |
addPolygons(List<PolygonOptions> polygonOptionsList)
Adds multiple polygons to this map.
|
Polyline |
addPolyline(PolylineOptions polylineOptions)
Adds a polyline to this map.
|
List<Polyline> |
addPolylines(List<PolylineOptions> polylineOptionsList)
Adds multiple polylines to this map.
|
void |
addSource(Source source)
Adds the source to the map.
|
void |
animateCamera(CameraUpdate update)
Animate the camera to a new location defined within
CameraUpdate using a transition
animation that evokes powered flight. |
void |
animateCamera(CameraUpdate update,
int durationMs)
Animate the camera to a new location defined within
CameraUpdate using a transition
animation that evokes powered flight. |
void |
animateCamera(CameraUpdate update,
int durationMs,
MapboxMap.CancelableCallback callback)
Animate the camera to a new location defined within
CameraUpdate using a transition
animation that evokes powered flight. |
void |
animateCamera(CameraUpdate update,
MapboxMap.CancelableCallback callback)
Animate the camera to a new location defined within
CameraUpdate using a transition
animation that evokes powered flight. |
void |
cancelTransitions()
Cancels ongoing animations.
|
void |
clear()
Removes all markers, polylines, polygons, overlays, etc from the map.
|
void |
cycleDebugOptions()
Cycles through the map debug options.
|
void |
deselectMarker(Marker marker)
Deselects a currently selected marker.
|
void |
deselectMarkers()
Deselects any currently selected marker.
|
void |
easeCamera(CameraUpdate update)
Gradually move the camera by the default duration, zoom will not be affected unless specified
within
CameraUpdate . |
void |
easeCamera(CameraUpdate update,
int durationMs)
Gradually move the camera by a specified duration in milliseconds, zoom will not be affected
unless specified within
CameraUpdate . |
void |
easeCamera(CameraUpdate update,
int durationMs,
boolean easingInterpolator)
Gradually move the camera by a specified duration in milliseconds, zoom will not be affected
unless specified within
CameraUpdate . |
void |
easeCamera(CameraUpdate update,
int durationMs,
boolean easingInterpolator,
MapboxMap.CancelableCallback callback)
Gradually move the camera by a specified duration in milliseconds, zoom will not be affected
unless specified within
CameraUpdate . |
void |
easeCamera(CameraUpdate update,
int durationMs,
boolean easingInterpolator,
MapboxMap.CancelableCallback callback,
boolean isDismissable)
Gradually move the camera by a specified duration in milliseconds, zoom will not be affected
unless specified within
CameraUpdate . |
void |
easeCamera(CameraUpdate update,
int durationMs,
MapboxMap.CancelableCallback callback)
Gradually move the camera by a specified duration in milliseconds, zoom will not be affected
unless specified within
CameraUpdate . |
Annotation |
getAnnotation(long id)
Return a annotation based on its id.
|
List<Annotation> |
getAnnotations()
Returns a list of all the annotations on the map.
|
CameraPosition |
getCameraForLatLngBounds(LatLngBounds latLngBounds,
int[] padding)
Get a camera position that fits a provided bounds and padding.
|
CameraPosition |
getCameraPosition()
Gets the current position of the camera.
|
float |
getHeight()
Returns the measured height of the Map.
|
MapboxMap.InfoWindowAdapter |
getInfoWindowAdapter()
Gets the callback to be invoked when an info window will be shown.
|
Layer |
getLayer(String layerId)
Get the layer by id
|
<T extends Layer> |
getLayerAs(String layerId)
Tries to cast the Layer to T, returns null if it's another type.
|
List<Layer> |
getLayers()
Retrieve all the layers in the style
|
Light |
getLight()
Get the global light source used to change lighting conditions on extruded fill layers.
|
List<Marker> |
getMarkers()
Returns a list of all the markers on the map.
|
MarkerViewManager |
getMarkerViewManager()
Get the MarkerViewManager associated to the MapView.
|
List<MarkerView> |
getMarkerViewsInRect(RectF rect)
Returns markerViews found inside of a rectangle on this map.
|
double |
getMaxZoomLevel()
Gets the maximum zoom level the map can be displayed at.
|
double |
getMinZoomLevel()
Gets the maximum zoom level the map can be displayed at.
|
Location |
getMyLocation()
Returns the currently displayed user location, or null if there is no location data available.
|
MyLocationViewSettings |
getMyLocationViewSettings()
Gets the settings of the user location for the map.
|
MapboxMap.OnInfoWindowClickListener |
getOnInfoWindowClickListener()
Return the InfoWindow click listener
|
MapboxMap.OnInfoWindowCloseListener |
getOnInfoWindowCloseListener()
Return the InfoWindow close listener
|
MapboxMap.OnInfoWindowLongClickListener |
getOnInfoWindowLongClickListener()
Return the InfoWindow long click listener
|
int[] |
getPadding()
Returns the current configured content padding on map view.
|
List<Polygon> |
getPolygons()
Returns a list of all the polygons on the map.
|
List<Polyline> |
getPolylines()
Returns a list of all the polylines on the map.
|
Projection |
getProjection()
Get the Projection object that you can use to convert between screen coordinates and latitude/longitude
coordinates.
|
List<Marker> |
getSelectedMarkers()
Gets the currently selected marker.
|
Source |
getSource(String sourceId)
Retrieve a source by id
|
<T extends Source> |
getSourceAs(String sourceId)
Tries to cast the Source to T, returns null if it's another type.
|
List<Source> |
getSources()
Retrieve all the sources in the style
|
String |
getStyleUrl()
Returns the map style currently displayed in the map view.
|
TrackingSettings |
getTrackingSettings()
Gets the tracking interface settings for the map.
|
long |
getTransitionDelay()
Get the animation delay for style changes.
|
long |
getTransitionDuration()
Get the animation duration for style changes.
|
UiSettings |
getUiSettings()
Gets the user interface settings for the map.
|
float |
getWidth()
Returns the measured width of the Map.
|
boolean |
isAllowConcurrentMultipleOpenInfoWindows()
Returns whether the map allows concurrent multiple infowindows to be shown.
|
boolean |
isDebugActive()
Returns whether the map debug information is currently shown.
|
boolean |
isMyLocationEnabled()
Returns the status of the my-location layer.
|
void |
moveCamera(CameraUpdate update)
Repositions the camera according to the instructions defined in the update.
|
void |
moveCamera(CameraUpdate update,
MapboxMap.CancelableCallback callback)
Repositions the camera according to the instructions defined in the update.
|
List<com.mapbox.services.commons.geojson.Feature> |
queryRenderedFeatures(PointF coordinates,
Filter.Statement filter,
String... layerIds)
Queries the map for rendered features
|
List<com.mapbox.services.commons.geojson.Feature> |
queryRenderedFeatures(PointF coordinates,
String... layerIds)
Queries the map for rendered features
|
List<com.mapbox.services.commons.geojson.Feature> |
queryRenderedFeatures(RectF coordinates,
Filter.Statement filter,
String... layerIds)
Queries the map for rendered features
|
List<com.mapbox.services.commons.geojson.Feature> |
queryRenderedFeatures(RectF coordinates,
String... layerIds)
Queries the map for rendered features
|
void |
removeAnnotation(Annotation annotation)
Removes an annotation from the map.
|
void |
removeAnnotation(long id)
Removes an annotation from the map
|
void |
removeAnnotations()
Removes all annotations from the map.
|
void |
removeAnnotations(List<? extends Annotation> annotationList)
Removes multiple annotations from the map.
|
void |
removeImage(String name)
Removes an image from the map's style
|
Layer |
removeLayer(Layer layer)
Removes the layer.
|
Layer |
removeLayer(String layerId)
Removes the layer.
|
Layer |
removeLayerAt(int index)
Removes the layer.
|
void |
removeMarker(Marker marker)
Convenience method for removing a Marker from the map.
|
void |
removePolygon(Polygon polygon)
Convenience method for removing a Polygon from the map.
|
void |
removePolyline(Polyline polyline)
Convenience method for removing a Polyline from the map.
|
Source |
removeSource(Source source)
Removes the source, preserving the reverence for re-use
|
Source |
removeSource(String sourceId)
Removes the source.
|
void |
resetNorth()
Resets the map view to face north.
|
void |
selectMarker(Marker marker)
Selects a marker.
|
void |
setAllowConcurrentMultipleOpenInfoWindows(boolean allow)
Changes whether the map allows concurrent multiple infowindows to be shown.
|
void |
setCameraPosition(CameraPosition cameraPosition)
Repositions the camera according to the cameraPosition.
|
void |
setDebugActive(boolean debugActive)
Changes whether the map debug information is shown.
|
void |
setFocalBearing(double bearing,
float focalX,
float focalY,
long duration)
Transform the map bearing given a bearing, focal point coordinates, and a duration.
|
void |
setInfoWindowAdapter(MapboxMap.InfoWindowAdapter infoWindowAdapter)
Sets a custom renderer for the contents of info window.
|
void |
setLatLngBoundsForCameraTarget(LatLngBounds latLngBounds)
Sets a LatLngBounds that constraints map transformations to this bounds.
|
void |
setLocationSource(com.mapbox.services.android.telemetry.location.LocationEngine locationSource)
Replaces the location source of the my-location layer.
|
void |
setMaxZoomPreference(double maxZoom)
Sets the maximum zoom level the map can be displayed at.
|
void |
setMinZoomPreference(double minZoom)
Sets the minimum zoom level the map can be displayed at.
|
void |
setMyLocationEnabled(boolean enabled)
Enables or disables the my-location layer.
|
void |
setOnCameraChangeListener(MapboxMap.OnCameraChangeListener listener)
Deprecated.
|
void |
setOnCameraIdleListener(MapboxMap.OnCameraIdleListener listener)
Sets a callback that is invoked when camera movement has ended.
|
void |
setOnCameraMoveCancelListener(MapboxMap.OnCameraMoveCanceledListener listener)
Sets a callback that is invoked when camera movement was cancelled.
|
void |
setOnCameraMoveListener(MapboxMap.OnCameraMoveListener listener)
Sets a callback that is invoked when camera position changes.
|
void |
setOnCameraMoveStartedListener(MapboxMap.OnCameraMoveStartedListener listener)
Sets a callback that is invoked when camera movement has started.
|
void |
setOnFlingListener(MapboxMap.OnFlingListener listener)
Sets a callback that's invoked when the map is flinged.
|
void |
setOnFpsChangedListener(MapboxMap.OnFpsChangedListener listener)
Sets a callback that's invoked on every frame rendered to the map view.
|
void |
setOnInfoWindowClickListener(MapboxMap.OnInfoWindowClickListener listener)
Sets a callback that's invoked when the user clicks on an info window.
|
void |
setOnInfoWindowCloseListener(MapboxMap.OnInfoWindowCloseListener listener)
Set an callback to be invoked when an InfoWindow closes.
|
void |
setOnInfoWindowLongClickListener(MapboxMap.OnInfoWindowLongClickListener listener)
Sets a callback that's invoked when a marker's info window is long pressed.
|
void |
setOnMapClickListener(MapboxMap.OnMapClickListener listener)
Sets a callback that's invoked when the user clicks on the map view.
|
void |
setOnMapLongClickListener(MapboxMap.OnMapLongClickListener listener)
Sets a callback that's invoked when the user long clicks on the map view.
|
void |
setOnMarkerClickListener(MapboxMap.OnMarkerClickListener listener)
Sets a callback that's invoked when the user clicks on a marker.
|
void |
setOnMyBearingTrackingModeChangeListener(MapboxMap.OnMyBearingTrackingModeChangeListener listener)
Sets a callback that's invoked when the bearing tracking mode changes.
|
void |
setOnMyLocationChangeListener(MapboxMap.OnMyLocationChangeListener listener)
Sets a callback that's invoked when the the My Location view
(which signifies the user's location) changes location.
|
void |
setOnMyLocationTrackingModeChangeListener(MapboxMap.OnMyLocationTrackingModeChangeListener listener)
Sets a callback that's invoked when the location tracking mode changes.
|
void |
setOnPolygonClickListener(MapboxMap.OnPolygonClickListener listener)
Sets a callback that's invoked when the user clicks on a polygon.
|
void |
setOnPolylineClickListener(MapboxMap.OnPolylineClickListener listener)
Sets a callback that's invoked when the user clicks on a polyline.
|
void |
setOnScrollListener(MapboxMap.OnScrollListener listener)
Sets a callback that's invoked when the map is scrolled.
|
void |
setPadding(int left,
int top,
int right,
int bottom)
Sets the distance from the edges of the map view’s frame to the edges of the map
view’s logical viewport.
|
void |
setStyle(String style)
Loads a new map style from the specified bundled style.
|
void |
setStyle(String style,
MapboxMap.OnStyleLoadedListener callback)
Loads a new map style from the specified bundled style.
|
void |
setStyleUrl(String url)
Loads a new map style asynchronous from the specified URL.
|
void |
setStyleUrl(String url,
MapboxMap.OnStyleLoadedListener callback)
Loads a new map style asynchronous from the specified URL.
|
void |
setTransitionDelay(long delayMs)
Set the animation delay for style changes.
|
void |
setTransitionDuration(long durationMs)
Set the animation duration for style changes.
|
void |
snapshot(MapboxMap.SnapshotReadyCallback callback)
Takes a snapshot of the map.
|
void |
updateMarker(Marker updatedMarker)
Updates a marker on this map.
|
void |
updatePolygon(Polygon polygon)
Update a polygon on this map.
|
void |
updatePolyline(Polyline polyline)
Update a polyline on this map.
|
@UiThread public long getTransitionDuration()
Get the animation duration for style changes.
The default value is zero, so any changes take effect without animation.@UiThread public void setTransitionDuration(long durationMs)
durationMs
- Duration in milliseconds@UiThread public long getTransitionDelay()
Get the animation delay for style changes.
The default value is zero, so any changes begin to animate immediately.@UiThread public void setTransitionDelay(long delayMs)
delayMs
- Delay in milliseconds@UiThread public List<Layer> getLayers()
@Nullable @UiThread public Layer getLayer(@NonNull String layerId)
layerId
- the layer's id@Nullable @UiThread public <T extends Layer> T getLayerAs(@NonNull String layerId)
T
- the generic attribute of a LayerlayerId
- the layer id used to look up a layer@UiThread public void addLayer(@NonNull Layer layer)
layer
- the layer to add@UiThread public void addLayerBelow(@NonNull Layer layer, @NonNull String below)
layer
- the layer to addbelow
- the layer id to add this layer before@UiThread public void addLayerAbove(@NonNull Layer layer, @NonNull String above)
layer
- the layer to addabove
- the layer id to add this layer above@UiThread public void addLayerAt(@NonNull Layer layer, int index)
layer
- the layer to addindex
- the index to insert the layer at@UiThread @Nullable public Layer removeLayer(@NonNull String layerId)
layerId
- the layer to remove@UiThread @Nullable public Layer removeLayer(@NonNull Layer layer)
layer
- the layer to remove@UiThread @Nullable public Layer removeLayerAt(int index)
index
- the layer index@UiThread public List<Source> getSources()
@Nullable @UiThread public Source getSource(@NonNull String sourceId)
sourceId
- the source's id@Nullable @UiThread public <T extends Source> T getSourceAs(@NonNull String sourceId)
T
- the generic type of a SourcesourceId
- the id used to look up a layer@UiThread public void addSource(@NonNull Source source)
source
- the source to add@UiThread @Nullable public Source removeSource(@NonNull String sourceId)
sourceId
- the source to remove@UiThread @Nullable public Source removeSource(@NonNull Source source)
source
- the source to remove@UiThread public void addImage(@NonNull String name, @NonNull Bitmap image)
name
- the name of the imageimage
- the pre-multiplied Bitmap@UiThread public void removeImage(String name)
name
- the name of the image to remove@UiThread public void setMinZoomPreference(double minZoom)
Sets the minimum zoom level the map can be displayed at.
minZoom
- The new minimum zoom level.@UiThread public double getMinZoomLevel()
Gets the maximum zoom level the map can be displayed at.
@UiThread public void setMaxZoomPreference(double maxZoom)
Sets the maximum zoom level the map can be displayed at.
maxZoom
- The new maximum zoom level.@UiThread public double getMaxZoomLevel()
Gets the maximum zoom level the map can be displayed at.
public UiSettings getUiSettings()
public TrackingSettings getTrackingSettings()
public MyLocationViewSettings getMyLocationViewSettings()
public Projection getProjection()
@Nullable public Light getLight()
public void cancelTransitions()
This invokes the MapboxMap.CancelableCallback
for ongoing camera updates.
public final CameraPosition getCameraPosition()
public void setCameraPosition(@NonNull CameraPosition cameraPosition)
cameraPosition
- the camera position to set@UiThread public final void moveCamera(CameraUpdate update)
update
- The change that should be applied to the camera.@UiThread public final void moveCamera(CameraUpdate update, MapboxMap.CancelableCallback callback)
update
- The change that should be applied to the cameracallback
- the callback to be invoked when an animation finishes or is canceled@UiThread public final void easeCamera(CameraUpdate update)
CameraUpdate
. If getCameraPosition()
is called during the animation,
it will return the current location of the camera in flight.update
- The change that should be applied to the camera.for a set of updates.
@UiThread public final void easeCamera(CameraUpdate update, int durationMs)
CameraUpdate
. If getCameraPosition()
is called
during the animation, it will return the current location of the camera in flight.update
- The change that should be applied to the camera.durationMs
- The duration of the animation in milliseconds. This must be strictly
positive, otherwise an IllegalArgumentException will be thrown.for a set of updates.
@UiThread public final void easeCamera(CameraUpdate update, int durationMs, MapboxMap.CancelableCallback callback)
CameraUpdate
. A callback can be used to be notified when
easing the camera stops. If getCameraPosition()
is called during the animation, it
will return the current location of the camera in flight.
Note that this will cancel location tracking mode if enabled.
update
- The change that should be applied to the camera.durationMs
- The duration of the animation in milliseconds. This must be strictly
positive, otherwise an IllegalArgumentException will be thrown.callback
- An optional callback to be notified from the main thread when the animation
stops. If the animation stops due to its natural completion, the callback
will be notified with onFinish(). If the animation stops due to interruption
by a later camera movement or a user gesture, onCancel() will be called.
Do not update or ease the camera from within onCancel().for a set of updates.
@UiThread public final void easeCamera(CameraUpdate update, int durationMs, boolean easingInterpolator)
CameraUpdate
. A callback can be used to be notified when
easing the camera stops. If getCameraPosition()
is called during the animation, it
will return the current location of the camera in flight.
Note that this will cancel location tracking mode if enabled.
update
- The change that should be applied to the camera.durationMs
- The duration of the animation in milliseconds. This must be strictly
positive, otherwise an IllegalArgumentException will be thrown.easingInterpolator
- True for easing interpolator, false for linear.@UiThread public final void easeCamera(CameraUpdate update, int durationMs, boolean easingInterpolator, MapboxMap.CancelableCallback callback)
CameraUpdate
. A callback can be used to be notified when
easing the camera stops. If getCameraPosition()
is called during the animation, it
will return the current location of the camera in flight.
Note that this will cancel location tracking mode if enabled. You can change this behaviour by calling
TrackingSettings.setDismissLocationTrackingOnGesture(boolean)
with false before
invoking this method and calling it with true in the MapboxMap.CancelableCallback.onFinish()
.
update
- The change that should be applied to the camera.durationMs
- The duration of the animation in milliseconds. This must be strictly
positive, otherwise an IllegalArgumentException will be thrown.easingInterpolator
- True for easing interpolator, false for linear.callback
- An optional callback to be notified from the main thread when the animation
stops. If the animation stops due to its natural completion, the callback
will be notified with onFinish(). If the animation stops due to interruption
by a later camera movement or a user gesture, onCancel() will be called.
Do not update or ease the camera from within onCancel().@UiThread public final void easeCamera(CameraUpdate update, int durationMs, boolean easingInterpolator, MapboxMap.CancelableCallback callback, boolean isDismissable)
CameraUpdate
. A callback can be used to be notified when
easing the camera stops. If getCameraPosition()
is called during the animation, it
will return the current location of the camera in flight.
Note that this will cancel location tracking mode if enabled. You can change this behaviour by calling
TrackingSettings.setDismissLocationTrackingOnGesture(boolean)
with false before
invoking this method and calling it with true in the MapboxMap.CancelableCallback.onFinish()
.
update
- The change that should be applied to the camera.durationMs
- The duration of the animation in milliseconds. This must be strictly
positive, otherwise an IllegalArgumentException will be thrown.easingInterpolator
- True for easing interpolator, false for linear.callback
- An optional callback to be notified from the main thread when the animation
stops. If the animation stops due to its natural completion, the callback
will be notified with onFinish(). If the animation stops due to interruption
by a later camera movement or a user gesture, onCancel() will be called.
Do not update or ease the camera from within onCancel().isDismissable
- true will allow animated camera changes dismiss a tracking mode.@UiThread public final void animateCamera(CameraUpdate update)
CameraUpdate
using a transition
animation that evokes powered flight. The animation will last the default amount of time.
During the animation, a call to getCameraPosition()
returns an intermediate location
of the camera in flight.update
- The change that should be applied to the camera.for a set of updates.
@UiThread public final void animateCamera(CameraUpdate update, MapboxMap.CancelableCallback callback)
CameraUpdate
using a transition
animation that evokes powered flight. The animation will last the default amount of time. A
callback can be used to be notified when animating the camera stops. During the animation, a
call to getCameraPosition()
returns an intermediate location of the camera in flight.update
- The change that should be applied to the camera.callback
- The callback to invoke from the main thread when the animation stops. If the
animation completes normally, onFinish() is called; otherwise, onCancel() is
called. Do not update or animate the camera from within onCancel().for a set of updates.
@UiThread public final void animateCamera(CameraUpdate update, int durationMs)
CameraUpdate
using a transition
animation that evokes powered flight. The animation will last a specified amount of time
given in milliseconds. During the animation, a call to getCameraPosition()
returns
an intermediate location of the camera in flight.update
- The change that should be applied to the camera.durationMs
- The duration of the animation in milliseconds. This must be strictly
positive, otherwise an IllegalArgumentException will be thrown.for a set of updates.
@UiThread public final void animateCamera(CameraUpdate update, int durationMs, MapboxMap.CancelableCallback callback)
CameraUpdate
using a transition
animation that evokes powered flight. The animation will last a specified amount of time
given in milliseconds. A callback can be used to be notified when animating the camera stops.
During the animation, a call to getCameraPosition()
returns an intermediate location
of the camera in flight.update
- The change that should be applied to the camera.durationMs
- The duration of the animation in milliseconds. This must be strictly
positive, otherwise an IllegalArgumentException will be thrown.callback
- An optional callback to be notified from the main thread when the animation
stops. If the animation stops due to its natural completion, the callback
will be notified with onFinish(). If the animation stops due to interruption
by a later camera movement or a user gesture, onCancel() will be called.
Do not update or animate the camera from within onCancel(). If a callback
isn't required, leave it as null.for a set of updates.
public void resetNorth()
public void setFocalBearing(double bearing, float focalX, float focalY, long duration)
bearing
- The bearing of the Map to be transformed tofocalX
- The x coordinate of the focal pointfocalY
- The y coordinate of the focal pointduration
- The duration of the transformationpublic float getHeight()
public float getWidth()
@UiThread public boolean isDebugActive()
@UiThread public void setDebugActive(boolean debugActive)
Changes whether the map debug information is shown.
The default value is false.debugActive
- If true, map debug information is shown.@UiThread public void cycleDebugOptions()
Cycles through the map debug options.
The value of isDebugActive reflects whether there are any map debug options enabled or disabled.isDebugActive()
@UiThread public void setStyleUrl(@NonNull String url)
Loads a new map style asynchronous from the specified URL.
url
can take the following forms:
Style.*
: load one of the bundled styles in Style
.mapbox://styles/<user>/<style>
:
loads the style from a Mapbox account.
user
is your username. style
is the ID of your custom
style created in Mapbox Studio.http://...
or https://...
:
loads the style over the Internet from any web server.asset://...
:
loads the style from the APK assets/
directory.
This is used to load a style bundled with your app.null
: loads the default Style.MAPBOX_STREETS
style.
This method is asynchronous and will return before the style finishes loading.
If you wish to wait for the map to finish loading, listen for the MapView.DID_FINISH_LOADING_MAP
event
or use the setStyleUrl(String, OnStyleLoadedListener)
method instead.
MapView.DID_FAIL_LOADING_MAP
event will be
emitted.url
- The URL of the map styleStyle
@UiThread public void setStyleUrl(@NonNull String url, @Nullable MapboxMap.OnStyleLoadedListener callback)
Loads a new map style asynchronous from the specified URL.
url
can take the following forms:
Style.*
: load one of the bundled styles in Style
.mapbox://styles/<user>/<style>
:
loads the style from a Mapbox account.
user
is your username. style
is the ID of your custom
style created in Mapbox Studio.http://...
or https://...
:
loads the style over the Internet from any web server.asset://...
:
loads the style from the APK assets/
directory.
This is used to load a style bundled with your app.null
: loads the default Style.MAPBOX_STREETS
style.
If the style fails to load or an invalid style URL is set, the map view will become blank.
An error message will be logged in the Android logcat and MapView.DID_FAIL_LOADING_MAP
event will be
emitted.
url
- The URL of the map stylecallback
- The callback that is invoked when the style has loaded.Style
@UiThread public void setStyle(String style)
Loads a new map style from the specified bundled style.
This method is asynchronous and will return before the style finishes loading.
If you wish to wait for the map to finish loading, listen for the MapView.DID_FINISH_LOADING_MAP
event
or use the setStyle(String, OnStyleLoadedListener)
method instead.
MapView.DID_FAIL_LOADING_MAP
event will be
sent.style
- The bundled style.Style
@UiThread public void setStyle(String style, @Nullable MapboxMap.OnStyleLoadedListener callback)
Loads a new map style from the specified bundled style.
If the style fails to load or an invalid style URL is set, the map view will become blank. An error message will be logged in the Android logcat andMapView.DID_FAIL_LOADING_MAP
event will be
sent.style
- The bundled style.callback
- The callback to be invoked when the style has finished loadingStyle
@UiThread @Nullable public String getStyleUrl()
@UiThread @NonNull public Marker addMarker(@NonNull MarkerOptions markerOptions)
Adds a marker to this map.
The marker's icon is rendered on the map at the locationMarker.position
.
If Marker.title
is defined, the map shows an info box with the marker's title and snippet.markerOptions
- A marker options object that defines how to render the markerMarker
that was added to the map@UiThread @NonNull public Marker addMarker(@NonNull BaseMarkerOptions markerOptions)
Adds a marker to this map.
The marker's icon is rendered on the map at the locationMarker.position
.
If Marker.title
is defined, the map shows an info box with the marker's title and snippet.markerOptions
- A marker options object that defines how to render the markerMarker
that was added to the map@UiThread @NonNull public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions)
Adds a marker to this map.
The marker's icon is rendered on the map at the locationMarker.position
.
If Marker.title
is defined, the map shows an info box with the marker's title and snippet.markerOptions
- A marker options object that defines how to render the markerMarker
that was added to the map@UiThread @NonNull public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions, MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener)
Adds a marker to this map.
The marker's icon is rendered on the map at the locationMarker.position
.
If Marker.title
is defined, the map shows an info box with the marker's title and snippet.markerOptions
- A marker options object that defines how to render the markeronMarkerViewAddedListener
- Callback invoked when the View has been added to the mapMarker
that was added to the map@UiThread @NonNull public List<MarkerView> addMarkerViews(@NonNull List<? extends BaseMarkerViewOptions> markerViewOptions)
The marker's icon is rendered on the map at the location Marker.position
.
If Marker.title
is defined, the map shows an info box with the marker's title and snippet.
markerViewOptions
- A list of markerView options objects that defines how to render the markersMarkerView
s that were added to the map@UiThread @NonNull public List<MarkerView> getMarkerViewsInRect(@NonNull RectF rect)
rect
- the rectangular area on the map to query for markerViews@UiThread @NonNull public List<Marker> addMarkers(@NonNull List<? extends BaseMarkerOptions> markerOptionsList)
Adds multiple markers to this map.
The marker's icon is rendered on the map at the locationMarker.position
.
If Marker.title
is defined, the map shows an info box with the marker's title and snippet.markerOptionsList
- A list of marker options objects that defines how to render the markersMarker
s that were added to the map@UiThread public void updateMarker(@NonNull Marker updatedMarker)
Updates a marker on this map. Does nothing if the marker isn't already added.
updatedMarker
- An updated marker object@UiThread @NonNull public Polyline addPolyline(@NonNull PolylineOptions polylineOptions)
polylineOptions
- A polyline options object that defines how to render the polylinePolyine
that was added to the map@UiThread @NonNull public List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList)
polylineOptionsList
- A list of polyline options objects that defines how to render the polylines.Polyline
s that were added to the map.@UiThread public void updatePolyline(Polyline polyline)
polyline
- An updated polyline object.@UiThread @NonNull public Polygon addPolygon(@NonNull PolygonOptions polygonOptions)
polygonOptions
- A polygon options object that defines how to render the polygon.Polygon
that was added to the map.@UiThread @NonNull public List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList)
polygonOptionsList
- A list of polygon options objects that defines how to render the polygonsPolygon
s that were added to the map@UiThread public void updatePolygon(Polygon polygon)
polygon
- An updated polygon object@UiThread public void removeMarker(@NonNull Marker marker)
Convenience method for removing a Marker from the map.
Calls removeAnnotation() internally.marker
- Marker to remove@UiThread public void removePolyline(@NonNull Polyline polyline)
Convenience method for removing a Polyline from the map.
Calls removeAnnotation() internally.polyline
- Polyline to remove@UiThread public void removePolygon(@NonNull Polygon polygon)
Convenience method for removing a Polygon from the map.
Calls removeAnnotation() internally.polygon
- Polygon to remove@UiThread public void removeAnnotation(@NonNull Annotation annotation)
annotation
- The annotation object to remove.@UiThread public void removeAnnotation(long id)
id
- The identifier associated to the annotation to be removed@UiThread public void removeAnnotations(@NonNull List<? extends Annotation> annotationList)
annotationList
- A list of annotation objects to remove.@UiThread public void removeAnnotations()
@UiThread public void clear()
@Nullable public Annotation getAnnotation(long id)
id
- the id used to look up an annotation@NonNull public List<Annotation> getAnnotations()
@NonNull public List<Marker> getMarkers()
@NonNull public List<Polygon> getPolygons()
@NonNull public List<Polyline> getPolylines()
@UiThread public void setOnMarkerClickListener(@Nullable MapboxMap.OnMarkerClickListener listener)
listener
- The callback that's invoked when the user clicks on a marker.
To unset the callback, use null.@UiThread public void setOnPolygonClickListener(@Nullable MapboxMap.OnPolygonClickListener listener)
listener
- The callback that's invoked when the user clicks on a polygon.
To unset the callback, use null.@UiThread public void setOnPolylineClickListener(@Nullable MapboxMap.OnPolylineClickListener listener)
listener
- The callback that's invoked when the user clicks on a polyline.
To unset the callback, use null.@UiThread public void selectMarker(@NonNull Marker marker)
Selects a marker. The selected marker will have it's info window opened. Any other open info windows will be closed unless isAllowConcurrentMultipleOpenInfoWindows() is true.
Selecting an already selected marker will have no effect.marker
- The marker to select.@UiThread public void deselectMarkers()
@UiThread public void deselectMarker(@NonNull Marker marker)
marker
- the marker to deselect@UiThread public List<Marker> getSelectedMarkers()
public MarkerViewManager getMarkerViewManager()
@UiThread public void setInfoWindowAdapter(@Nullable MapboxMap.InfoWindowAdapter infoWindowAdapter)
Sets a custom renderer for the contents of info window.
When set your callback is invoked when an info window is about to be shown. By returning a customView
, the default info window will be replaced.infoWindowAdapter
- The callback to be invoked when an info window will be shown.
To unset the callback, use null.@UiThread @Nullable public MapboxMap.InfoWindowAdapter getInfoWindowAdapter()
@UiThread public void setAllowConcurrentMultipleOpenInfoWindows(boolean allow)
allow
- If true, map allows concurrent multiple infowindows to be shown.@UiThread public boolean isAllowConcurrentMultipleOpenInfoWindows()
public void setLatLngBoundsForCameraTarget(@Nullable LatLngBounds latLngBounds)
Set to null to clear current bounds, newly set bounds will override previously set bounds.
latLngBounds
- the bounds to constrain the map withpublic CameraPosition getCameraForLatLngBounds(@Nullable LatLngBounds latLngBounds, int[] padding)
latLngBounds
- the bounds to constrain the map withpadding
- the padding to apply to the boundspublic void setPadding(int left, int top, int right, int bottom)
Sets the distance from the edges of the map view’s frame to the edges of the map view’s logical viewport.
When the value of this property is equal to {0,0,0,0}, viewport properties such as `centerCoordinate` assume a viewport that matches the map view’s frame. Otherwise, those properties are inset, excluding part of the frame from the viewport. For instance, if the only the top edge is inset, the map center is effectively shifted downward.
left
- The left margin in pixels.top
- The top margin in pixels.right
- The right margin in pixels.bottom
- The bottom margin in pixels.public int[] getPadding()
@UiThread @Deprecated public void setOnCameraChangeListener(@Nullable MapboxMap.OnCameraChangeListener listener)
listener
- The callback that's invoked on every camera change position.
To unset the callback, use null.@UiThread public void setOnCameraIdleListener(@Nullable MapboxMap.OnCameraIdleListener listener)
listener
- the listener to notify@UiThread public void setOnCameraMoveCancelListener(@Nullable MapboxMap.OnCameraMoveCanceledListener listener)
listener
- the listener to notify@UiThread public void setOnCameraMoveStartedListener(@Nullable MapboxMap.OnCameraMoveStartedListener listener)
listener
- the listener to notify@UiThread public void setOnCameraMoveListener(@Nullable MapboxMap.OnCameraMoveListener listener)
listener
- the listener to notify@UiThread public void setOnFpsChangedListener(@Nullable MapboxMap.OnFpsChangedListener listener)
listener
- The callback that's invoked on every frame rendered to the map view.
To unset the callback, use null.@UiThread public void setOnScrollListener(@Nullable MapboxMap.OnScrollListener listener)
listener
- The callback that's invoked when the map is scrolled.
To unset the callback, use null.@UiThread public void setOnFlingListener(@Nullable MapboxMap.OnFlingListener listener)
listener
- The callback that's invoked when the map is flinged.
To unset the callback, use null.@UiThread public void setOnMapClickListener(@Nullable MapboxMap.OnMapClickListener listener)
listener
- The callback that's invoked when the user clicks on the map view.
To unset the callback, use null.@UiThread public void setOnMapLongClickListener(@Nullable MapboxMap.OnMapLongClickListener listener)
listener
- The callback that's invoked when the user long clicks on the map view.
To unset the callback, use null.@UiThread public void setOnInfoWindowClickListener(@Nullable MapboxMap.OnInfoWindowClickListener listener)
listener
- The callback that's invoked when the user clicks on an info window.
To unset the callback, use null.@UiThread public MapboxMap.OnInfoWindowClickListener getOnInfoWindowClickListener()
@UiThread public void setOnInfoWindowLongClickListener(@Nullable MapboxMap.OnInfoWindowLongClickListener listener)
listener
- The callback that's invoked when a marker's info window is long pressed. To unset the callback,
use null.public MapboxMap.OnInfoWindowLongClickListener getOnInfoWindowLongClickListener()
public void setOnInfoWindowCloseListener(@Nullable MapboxMap.OnInfoWindowCloseListener listener)
listener
- callback invoked when an InfoWindow closes@UiThread public MapboxMap.OnInfoWindowCloseListener getOnInfoWindowCloseListener()
@UiThread public boolean isMyLocationEnabled()
@UiThread public void setMyLocationEnabled(boolean enabled)
Enables or disables the my-location layer. While enabled, the my-location layer continuously draws an indication of a user's current location and bearing.
In order to use the my-location layer feature you need to request permission for either android.Manifest.permission#ACCESS_COARSE_LOCATION or android.Manifest.permission#ACCESS_FINE_LOCATION.enabled
- True to enable; false to disable.@UiThread @Nullable public Location getMyLocation()
@UiThread public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener listener)
listener
- The callback that's invoked when the user clicks on a marker.
To unset the callback, use null.@UiThread public void setLocationSource(@Nullable com.mapbox.services.android.telemetry.location.LocationEngine locationSource)
locationSource
- A LocationEngine
location source to use in the my-location layer.@UiThread public void setOnMyLocationTrackingModeChangeListener(@Nullable MapboxMap.OnMyLocationTrackingModeChangeListener listener)
listener
- The callback that's invoked when the location tracking mode changes.
To unset the callback, use null.@UiThread public void setOnMyBearingTrackingModeChangeListener(@Nullable MapboxMap.OnMyBearingTrackingModeChangeListener listener)
listener
- The callback that's invoked when the bearing tracking mode changes.
To unset the callback, use null.@UiThread public void snapshot(@NonNull MapboxMap.SnapshotReadyCallback callback)
callback
- Callback method invoked when the snapshot is taken.@UiThread @NonNull public List<com.mapbox.services.commons.geojson.Feature> queryRenderedFeatures(@NonNull PointF coordinates, @Nullable String... layerIds)
coordinates
- the point to querylayerIds
- optionally - only query these layers@UiThread @NonNull public List<com.mapbox.services.commons.geojson.Feature> queryRenderedFeatures(@NonNull PointF coordinates, @Nullable Filter.Statement filter, @Nullable String... layerIds)
coordinates
- the point to queryfilter
- filters the returned featureslayerIds
- optionally - only query these layers@UiThread @NonNull public List<com.mapbox.services.commons.geojson.Feature> queryRenderedFeatures(@NonNull RectF coordinates, @Nullable String... layerIds)
coordinates
- the box to querylayerIds
- optionally - only query these layers@UiThread @NonNull public List<com.mapbox.services.commons.geojson.Feature> queryRenderedFeatures(@NonNull RectF coordinates, @Nullable Filter.Statement filter, @Nullable String... layerIds)
coordinates
- the box to queryfilter
- filters the returned featureslayerIds
- optionally - only query these layers© 2015–2017 Mapbox. All rights reserved.