public class

MapView

extends ViewGroup
implements ViewGroup.OnHierarchyChangeListener
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ com.esri.android.map.MapView

Class Overview

The MapView is the main mapping component of the ArcGIS API for Android. It represents an Android View that will display a map with a set of service layers. The MapView can be navigated using a device's touch screen. By default the MapView will respond to the following gestures:

  • The single finger, double tap and pinch-out gestures will zoom into the map.
  • The double finger, single tap and pinch-in gestures will zoom out of the map.
  • The single finger drag and single flick gestures will pan the map.
  • The double-tap-then-drag gesture will allow continual zooming in/out of the map. (Note, only vertical movement of the finger will trigger zooming - upwards to zoom out, downwards to zoom in. Horizontal movement is ignored).

The MapView inherits directly from Android's ViewGroup. Therefore, the MapView class inherits all the methods and properties from the ViewGroup and is very similar to working with other Android views. To make the MapView functional, it must have at least one Layer as its child. In general, the MapView is the parent of all Layer children.

The following are examples of how you might work with the MapView. The code will add a map service from ArcGIS Online using map services that have been cached. When working with cached map services the ArcGISTiledMapServiceLayer class must be used, which is a type of Layer. There are two approaches you can take when initializing your MapView; create it in a layout's XML or through Java source code. This example code shows you how to connect to ArcGIS Online, but you can easily update the code to point to your own ArcGIS Server REST end points.

XML usage:

 
 <!-- MapView that will fill your device screen with the "Washington, DC" hosted on ArcGIS.com. -->
 <com.esri.android.map.MapView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent"
 url="http://www.arcgis.com/home/webmap/viewer.html?webmap=e229d715f7ca4fa980308549fb288165"/>
 
 
Java usage:
 //ArcGISTiledMapServiceLayer class is used to define the Layer that is added to the 
 //MapView object. 
 MapView mv = new MapView(this);
 mv.addLayer(new ArcGISTiledMapServiceLayer(
     "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"));
 setContentView(mv);
 

The first layer that is added to the MapView using either approach presented previously will defines its initial extent, resolution, and spatial reference for the entire map. To change any of these attributes, use the corresponding setter methods; otherwise the MapView will maintain these initial values during the lifetime of the object.

A simplified use of instantiating a MapView with a defined basemap, zoomlevel, and center uses the MapOptions class. A typical use of this workflow is defined below:

Java usage:
 MapOptions topo = new MapOptions(MapType.TOPO, 23, -110, 9);
 MapView mapView = new MapView(this, topo);
 

You can now easily switch basemaps using the setMapOptions(MapOptions.MapType) method using the new MapOptions class:

Java usage:
 MapOptions streets = new MapOptions(MapType.STREETS);
 mapView.setMapOptions(streets);
 

Since the streets MapOptions class did not set a specific zoom level or center the map extent from the previous Basemap will be honored. If you want to explicitly set the zoom level or center of the Map when switching basemaps you need to provide those in the MapOptions constructor.

The examples above introduced the MapOptions class usage in Java. However, instead of using Java in your activity, you can assign MapOptions to your MapView in the XML Layout using the mapoptions attribute. For Example:

XML Usage
 
 <!-- MapView with MapOptions settings for Topo basemap,
         zoom level, and centered in Costa Mesa, CA. -->
 <com.esri.android.map.MapView
 android:id="@+id/map"
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent"
 mapoptions.MapType="topo"
 mapoptions.ZoomLevel="13"
 mapoptions.center="33.666354, -117.903557"/>
 
 
Java usage:
 // Retrieve the MapView, Basemap, ZoomLevel, and Center from XML layout
 MapView mMapView = (MapView) findViewById(R.id.map);
 

When instantiating the MapView, as shown in any of the Java usage examples above, you cannot assume that the object is initialized immediately due to the normal life cycle of an Activity. For instance, when you initialize the MapView and attempt to get the resolution immediately after you call the constructor, nothing will happen because the MapView will not have completely initialized. This will happen if you attempt to call the following methods of the MapView immediately after constructing your object:

The proper way to write code to perform actions after the map is initialized is to do the following:

 
 
 public class MapViewCenterAt extends Activity {
   MapView map;
 
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.mapviewcenterat);
     map = (MapView) findViewById(R.id.map);
 
     // the right way to get map resolution
     map.setOnStatusChangedListener(new OnStatusChangedListener() {
       private static final long serialVersionUID = 1L;
 
       public void onStatusChanged(Object source, STATUS status) {
         if (OnStatusChangedListener.STATUS.INITIALIZED == status && source == map) {
           Log.i("Test", "resolution:" + map.getResolution());
         }
       }
     });
   }
 
 
 
When initializing a MapView, the OnStatusChangedListener notifies you of the status changes from both the MapView and Layers. You need to use the source of the event to distinguish them. When initialization has failed, you can use the getError() to get the error details.

Also, you can check the map view status using this method: isLoaded()

By default, methods that navigate the map (for example setExtent(Geometry), setScale(double), and centerAt(Point, boolean)) animate the map from the existing state to the new state. Some methods have overloads to control whether or not animation is used. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series. If a Callout is visible, it will be temporarily hidden during animation.

See also:

Summary

[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
MapView(Context context, AttributeSet attrs, int defStyle)
Inflate the MapView object from XML and apply a class-specific base style.
MapView(Context context, AttributeSet attrs)
This constructor is called when the MapView object is being inflated from XML.
MapView(Context context)
The constructor is used if you are instantiating the MapView using Java code (see the class description for an example of this usage).
MapView(Context context, SpatialReference spatialreference, Envelope extent)
The constructor is used if you are instantiating the MapView using Java code (see the class description for an example of this usage).
MapView(Context context, String url, String user, String passwd)
The constructor is used if you are instantiating the MapView using the URL of a WebMap.
MapView(Context context, String url, String user, String passwd, String bingMapsAppId)
The constructor is used if you are instantiating the MapView using the URL of a WebMap.
MapView(Context context, String url, String user, String passwd, String bingMapsAppId, OnMapEventListener listener)
The constructor is used if you are instantiating the MapView using the URL of a WebMap.
MapView(Context context, String url, UserCredentials credentials, String bingMapsAppId, OnMapEventListener listener)
The constructor is used if you are instantiating the MapView using the URL of a WebMap.
MapView(Context context, WebMap webmap, String bingMapsAppId, OnMapEventListener listener)
Instantiates a MapView using a WebMap.
MapView(Context context, WebMap webmap, BaseMap basemap, String bingMapsAppId, OnMapEventListener listener)
Instantiates a MapView using a WebMap.
MapView(Context context, WebMap webmap, List<Layer> baseLayers, List<Layer> referenceLayers, String bingMapsAppId, OnMapEventListener listener)
Instantiates a MapView from a WebMap.
MapView(Context context, MapOptions options)
The constructor is used if you are instantiating the MapView using the given options including basemap, zoom leven and map center.
Public Methods
int addLayer(Layer layer)
Adds the child Layer.
int addLayer(Layer layer, int index)
Adds the child Layer at the given index.
void addLayers(Layer[] layerArray)
Adds the Layer array.
void centerAndZoom(double lat, double lon, float levelOrFactor)
If the MapView is initialized, centers the map at the given latitude and longitude and zoom the map based on the given factor.
void centerAt(Point centerPt, boolean animated)
If the MapView is initialized, centers the map at the given point; optionally, the change is animated.
void centerAt(double lat, double lon, boolean animated)
If the MapView is initialized, centers the map at the given latitude and longitude; optionally, the change is animated.
Bitmap createSymbolImage(Symbol symbol, Geometry geometry, int width, int height, int color)
This method is deprecated. at 10.2.2 use getLegendImage(Symbol, Geometry, int, int, int) instead.
Bitmap[] createSymbolImages(Symbol[] symbol, Geometry[] geometry, int width, int height, int color)
This method is deprecated. at 10.2.2 use getLegendImages(Symbol[], Geometry[], int, int, int) instead.
void enableWrapAround(boolean enable)
Enable or disable the map wrap around feature.
ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
Callout getCallout()
Returns a callout window.
Point getCenter()
Returns the center of the MapView as an ArcGIS geometry Point.
Bitmap getDrawingMapCache(float x, float y, int w, int h)
Creates a drawing cache of the map in the given screen coordinates.
Polygon getExtent()
Returns a polygon comprising of four corners of map in map coordinates.
Grid getGrid()
Returns the Grid instance of the map which allows for the type and visibility of the grid to be controlled.
Layer getLayer(int index)
Gets a layer at the given index.
Layer getLayerByID(long layerID)
Gets a layer by its ID.
Layer getLayerByURL(String url)
Gets a layer by its service URL.
Layer[] getLayers()
Returns all child Layers that are added to the MapView.
LocationDisplayManager getLocationDisplayManager()
Envelope getMapBoundaryExtent()
This method is deprecated. in 10.2.2, use getMaxExtent() instead
Envelope getMaxExtent()
Returns the max extent of the map.
double getMaxResolution()
This method is deprecated. at 10.2.2 please use getMinScale()
double getMaxScale()
Returns maximum scale.
double getMinResolution()
This method is deprecated. 10.2.2 please use getMaxScale()
double getMinScale()
Returns the minimum scale.
OnLongPressListener getOnLongPressListener()
Gets the OnLongPressListener of the MapView.
OnPanListener getOnPanListener()
Gets the OnPanListener of the MapView.
OnPinchListener getOnPinchListener()
Gets the OnPinchListener of the MapView.
OnSingleTapListener getOnSingleTapListener()
Gets the onSingleTapListener of the MapView.
OnStatusChangedListener getOnStatusChangedListener()
Gets the OnStatusChangedListener of the MapView.
OnZoomListener getOnZoomListener()
Gets the OnZoomListener of the MapView.
double getResolution()
Returns the resolution of the MapView.
double getRotationAngle()
Returns the current rotation angle of the map in degrees counter-clockwise.
double getScale()
A convenience method for obtaining the current map scale .
SpatialReference getSpatialReference()
Returns the spatial coordinate system being used by the MapView.
boolean isAllowOneFingerZoom()
Returns true if one-finger zooming is allowed.
boolean isAllowRotationByPinch()
Returns true if the rotation by pinch is allowed.
boolean isLoaded()
Returns true if the MapView is initialized.
boolean isRecycled()
Returns true if the MapView has been recycled.
boolean isShowMagnifierOnLongPress()
This method checks whether the map will show the magnifier when the user performs a tap and hold gesture on the map.
void onChildViewAdded(View parent, View child)
void onChildViewRemoved(View parent, View child)
void pause()
Pauses the map.
void recycle()
Releases the resources referenced by the MapView so that they can be recycled.
void removeAll()
Removes all child layers from the map.
void removeLayer(Layer layer)
Removes the child Layer from the parent MapView.
void removeLayer(int index)
Removes a child layer at the given index.
void restoreState(String state)
Restores the center and resolution, and the LocationDisplayManager state (whether it was active and whether or not to autopan) from the given state String into the MapView.
String retainState()
Saves the coordinates of the center of the map, the current map resolution, and the LocationDisplayManager state (whether it was active and whether or not to autopan) as a String.
void setAllowMagnifierToPanMap(boolean allow)
Flag to indicate if the map should pan when the magnifier gets near the edge of the map's bounds.
void setAllowOneFingerZoom(boolean allowOneFingerZoom)
Allows/disallows one-finger zooming.
void setAllowRotationByPinch(boolean allowRotationByPinch)
Allows/disallow pinch to rotate.
void setEsriLogoVisible(boolean visible)
Turns on or off the ESRI logo.
void setExtent(Geometry geometry, int padding)
Zooms the map to the given geometry, so that geometry fits within the bounds of the map with the specified padding between the geometry and edge of the map.
void setExtent(Geometry geometry, int padding, boolean animated)
Zooms the map to the given geometry, so that geometry fits within the bounds of the map with the specified padding between the geometry and edge of the map; optionally, the change is animated.
void setExtent(Geometry geometry)
Zooms the map to the given geometry so that geometry fits within the bounds of the map.
void setMapBackground(int bkColor, int gridColor, float gridSize, float gridLineSize)
Sets the map background with color and grid.
boolean setMapOptions(MapOptions options)
Switches basemap by the given options.
void setMaxExtent(Envelope env)
Sets the boundary extent of the map.
void setMaxResolution(double maxResolution)
This method is deprecated. at 10.2.2 please use setMinScale(double)
void setMaxScale(double maxScale)
Sets the maximum scale to which the map can be zoomed in.
void setMinResolution(double minResolution)
This method is deprecated. at 10.2.2, please use setMaxScale(double)
void setMinScale(double minScale)
Set the minimum scale to which the map can be zoomed out.
void setOnLongPressListener(OnLongPressListener onLongPressListener)
Sets the OnLongPressListener of the MapView.
void setOnPanListener(OnPanListener onPanListener)
Sets the OnPanListener of the MapView.
void setOnPinchListener(OnPinchListener onPinchListener)
Sets the onPinchListener of the MapView.
void setOnSingleTapListener(OnSingleTapListener onSingleTapListener)
Sets the onSingleTapListener of the MapView.
void setOnStatusChangedListener(OnStatusChangedListener onStatusChangedListener)
Sets the OnStatusChangedListener of the MapView.
void setOnZoomListener(OnZoomListener onZoomListener)
Sets the OnZoomListener of the MapView.
void setResolution(double res)
Sets the resolution of the MapView.
void setRotationAngle(double degree, float pivotX, float pivotY)
Rotates the map to the given angle in degrees, pivoting the rotation around a given point on the screen.
void setRotationAngle(double degree, boolean animated)
Rotates the map to the given angle in degrees; optionally, the change is animated.
void setRotationAngle(double degree, Point centerPt, boolean animated)
Rotates the map to the given angle in degrees and re-centers the map at the specified map coordinates; optionally, the change is animated.
void setRotationAngle(double degree)
Rotates the map to the given angle in degrees; if the specified angle is positive, rotation is counter-clockwise, if negative then rotation is clockwise.
void setScale(double scale, boolean animated)
Sets the map scale; optionally, the change is animated.
void setScale(double scale)
Sets the map scale.
void setShowMagnifierOnLongPress(boolean showMagnifier)
Sets a flag that defines whether or not the map should show the magnifier when the user performs a long press gesture on the map.
Future<Boolean> switchBaseMap(BaseMap basemap, Portal portal, OnBaseMapSwitchListener listener)
Replaces the basemap layers of this MapView if it was created from a WebMap, otherwise just adds the new basemap layers at the bottom or top of the existing MapView layers, depending on whether they are base or reference layers.
Point toMapPoint(float screenx, float screeny)
A convenience method that will convert a device's screen coordinates to an ArcGIS geometry Point that has the same spatial coordinate system as the MapView's.
Point toMapPoint(Point src)
A convenience method that will convert a device's screen coordinates into an ArcGIS geometry Point that has the same spatial coordinate system as the MapView's.
Point toScreenPoint(Point src)
A convenience method that will convert an ArcGIS geometry Point from the MapView's spatial coordinate system into the device's screen coordinates.
void unpause()
Unpauses the map.
void zoomTo(Point centerPt, float factor)
If the MapView is initialized, zooms the map by a factor to the given center point.
void zoomToResolution(Point centerPt, double res)
Centers the map on the given point and zoom into the given resolution level.
void zoomToScale(Point centerPt, double scale)
Centers the map on the given point and zoom into the given scale level.
void zoomin()
Zooms in one level from current map resolution; the map animates to the new resolution.
void zoomin(boolean animated)
Zooms in one level from current map resolution; optionally, the change is animated.
void zoomout()
Zooms out one level from current map resolution; the map animates to the new resolution.
void zoomout(boolean animated)
Zooms out one level from current map resolution; optionally, the change is animated.
Protected Methods
void finalize()
void onDetachedFromWindow()
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onSizeChanged(int w, int h, int oldw, int oldh)
[Expand]
Inherited Methods
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface android.view.ViewGroup.OnHierarchyChangeListener

Public Constructors

public MapView (Context context, AttributeSet attrs, int defStyle)

Inflate the MapView object from XML and apply a class-specific base style. This constructor of MapView allows subclasses to use their own base style when they are being inflated.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, and so on.
attrs AttributeSet: The attributes of the XML tag used to inflate the MapView.
defStyle int: the default style to apply to this view. If the value 0 is supplied, then no style will be applied (beyond what is included in the theme). This may either be an attribute resource, whose value will be retrieved from the current theme, or an explicit style resource.

public MapView (Context context, AttributeSet attrs)

This constructor is called when the MapView object is being inflated from XML. Attributes that are specified in the XML are used to help inflate this object. This constructor, by default, uses a style of 0. This implies that the only attribute values that are applied are those in Android's Context's Theme and the given attributes stipulated in the XML. The inherited method, onFinishInflate(), is called after all the children have been added.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources and so on.
attrs AttributeSet: The attributes of the XML tag used to inflate the MapView.

public MapView (Context context)

The constructor is used if you are instantiating the MapView using Java code (see the class description for an example of this usage).

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, , and so on.

public MapView (Context context, SpatialReference spatialreference, Envelope extent)

The constructor is used if you are instantiating the MapView using Java code (see the class description for an example of this usage).

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, , and so on.
spatialreference SpatialReference: the spatial reference to initialize the map with.
extent Envelope: the initial map extent to display.

public MapView (Context context, String url, String user, String passwd)

The constructor is used if you are instantiating the MapView using the URL of a WebMap. If you need to add a layer above such a MapView, you should invoke addLayer(Layer) in an OnStatusChangedListener.

Java code sample to add a GraphicsLayer on top of the WebMap:

 
 MapView mv = new MapView(this, "http://www.arcgis.com/home/item.html?id=12345", "myname", "mypassword");
 setContentView(mv);
 
 mv.setOnStatusChangedListener(new OnStatusChangedListener() {
   private static final long serialVersionUID = 1L;
 
   public void onStatusChanged(View source, STATUS status) {
     if (status == STATUS.INITIALIZED) {
 
       // add a graphics layer
       mv.addLayer(new GraphicsLayer(this, new SimpleRenderer(new SimpleMarkerSymbol(Color.RED, 20, STYLE.DIAMOND)),
           null, null));
     }
   }
 });
 
 

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, , and so on.
url String: the URL of the WebMap
user String: the name of the user who can access the WebMap. Set to null if the WebMap doesn't need to sign in.
passwd String: the password of the user. Set to null if the WebMap doesn't need to sign in.

public MapView (Context context, String url, String user, String passwd, String bingMapsAppId)

The constructor is used if you are instantiating the MapView using the URL of a WebMap. If you need to add a layer above such a MapView, you should invoke addLayer(Layer) in an OnStatusChangedListener.

Java code sample to add a GraphicsLayer on top of the WebMap:

 
 MapView mv = new MapView(this, "http://www.arcgis.com/home/item.html?id=12345", "myname", "mypassword");
 setContentView(mv);
 
 mv.setOnStatusChangedListener(new OnStatusChangedListener() {
   private static final long serialVersionUID = 1L;
 
   public void onStatusChanged(View source, STATUS status) {
     if (status == STATUS.INITIALIZED) {
 
       // add a graphics layer
       mv.addLayer(new GraphicsLayer(this, new SimpleRenderer(new SimpleMarkerSymbol(Color.RED, 20, STYLE.DIAMOND)),
           null, null));
     }
   }
 });
 
 

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, , and so on.
url String: the URL of the WebMap
user String: the name of the user who can access the WebMap. Set to null if the WebMap doesn't need to sign in.
passwd String: the password of the user. Set to null if the WebMap doesn't need to sign in.
bingMapsAppId String: if the WebMap is using Bing map, you need to provide the application id to access the map.

public MapView (Context context, String url, String user, String passwd, String bingMapsAppId, OnMapEventListener listener)

The constructor is used if you are instantiating the MapView using the URL of a WebMap. If you need to add a layer above such a MapView, you should invoke addLayer(Layer) in an OnStatusChangedListener.

Java code sample to add a GraphicsLayer on top of the WebMap:

 
 MapView mv = new MapView(this, "http://www.arcgis.com/home/item.html?id=12345", "myname", "mypassword");
 setContentView(mv);
 
 mv.setOnStatusChangedListener(new OnStatusChangedListener() {
   private static final long serialVersionUID = 1L;
 
   public void onStatusChanged(View source, STATUS status) {
     if (status == STATUS.INITIALIZED) {
 
       // add a graphics layer
       mv.addLayer(new GraphicsLayer(this, new SimpleRenderer(new SimpleMarkerSymbol(Color.RED, 20, STYLE.DIAMOND)),
           null, null));
     }
   }
 });
 
 

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, , and so on.
url String: the URL of the WebMap
user String: the name of the user who can access the WebMap. Set to null if the WebMap doesn't need to sign in.
passwd String: the password of the user. Set to null if the WebMap doesn't need to sign in.
bingMapsAppId String: if the WebMap is using Bing map, you need to provide the application id to access the map.
listener OnMapEventListener: the listener

public MapView (Context context, String url, UserCredentials credentials, String bingMapsAppId, OnMapEventListener listener)

The constructor is used if you are instantiating the MapView using the URL of a WebMap.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, , and so on.
url String: the URL of the WebMap
credentials UserCredentials: the credentials of the user who can access the WebMap. Set to null if the WebMap doesn't need to sign in.
bingMapsAppId String: if the WebMap is using Bing map, you need to provide the application id to access the map.
listener OnMapEventListener: the listener

public MapView (Context context, WebMap webmap, String bingMapsAppId, OnMapEventListener listener)

Instantiates a MapView using a WebMap. If you need to add a layer above such a MapView, you should invoke addLayer(Layer) in an OnStatusChangedListener.

Java code sample to add a GraphicsLayer on top of the WebMap:

 
 MapView mv = new MapView(this, webmap, null, null);
 setContentView(mv);
 
 mv.setOnStatusChangedListener(new OnStatusChangedListener() {
   private static final long serialVersionUID = 1L;
 
   public void onStatusChanged(View source, STATUS status) {
     if (status == STATUS.INITIALIZED) {
 
       // add a graphics layer
       mv.addLayer(new GraphicsLayer(this, new SimpleRenderer(new SimpleMarkerSymbol(Color.RED, 20, STYLE.DIAMOND)),
           null, null));
     }
   }
 });
 
 

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources etc.
webmap WebMap: the WebMap that provides the layers for the MapView.
bingMapsAppId String: if the WebMap is using Bing map, you need to provide the application id to access the map.
listener OnMapEventListener: when failed to load the WebMap, the user can feedback on how to handle the failure. Can be set to null to follow the default loading behavior.
Throws
IllegalArgumentException if the webmap argument is null.

public MapView (Context context, WebMap webmap, BaseMap basemap, String bingMapsAppId, OnMapEventListener listener)

Instantiates a MapView using a WebMap. The MapView contains the operational layers from the given WebMap and the basemap layers from the given BaseMap.

Parameters
context Context: the Context the view is running in, through which it can access the current theme, resources etc.
webmap WebMap: the WebMap that provides the operational layers for the MapView.
basemap BaseMap: the BaseMap that provides the basemap layers for the MapView.
bingMapsAppId String: if the WebMap is using Bing map, you need to provide the application id to access the map.
listener OnMapEventListener: when failed to load the WebMap, the user can feedback on how to handle the failure. Can be set to null to follow the default loading behavior.
Throws
IllegalArgumentException if the webmap argument is null.

public MapView (Context context, WebMap webmap, List<Layer> baseLayers, List<Layer> referenceLayers, String bingMapsAppId, OnMapEventListener listener)

Instantiates a MapView from a WebMap. The MapView contains the operational layers from the given WebMap and the basemap layers from the lists of baseLayers and referenceLayers.

Parameters
context Context: the Context the view is running in, through which it can access the current theme, resources etc.
webmap WebMap: the WebMap that provides the operational layers for the MapView.
baseLayers List: the base layers which are added to the MapView before the operational layers, thus drawn below the operational layers.
referenceLayers List: the layers that are part of the basemap but drawn on top of the operational layers.
bingMapsAppId String: if the WebMap is using Bing map, you need to provide the application id to access the map.
listener OnMapEventListener: when failed to load the WebMap, the user can feedback on how to handle the failure. Can be set to null to follow the default loading behavior.
Throws
IllegalArgumentException if the webmap argument is null.

public MapView (Context context, MapOptions options)

The constructor is used if you are instantiating the MapView using the given options including basemap, zoom leven and map center.

Parameters
context Context
options MapOptions: the given options.

Public Methods

public int addLayer (Layer layer)

Adds the child Layer. The new layer is placed on top of the map.

Parameters
layer Layer: one of the concrete sub-classes of the Layer class (e.g. ArcGISDynamicMapServiceLayer, and so on).
Returns
int a positive integer if the layer is added to the map successfully.

public int addLayer (Layer layer, int index)

Adds the child Layer at the given index.

The index position is zero-based, meaning that a value of 0 represents the first Layer to be drawn by the MapView.

An index number out of current index range is not allowed. For instance, if you have 3 layers with index 0, 1, and 2, then you cannot add the next Layer with an index position of 3.

Parameters
layer Layer: one of the concrete sub-classes of the Layer class (e.g. ArcGISDynamicMapServiceLayer, and so on).
index int: the index position of the Layer.
Returns
int a positive integer if the layer is added to the map successfully.

public void addLayers (Layer[] layerArray)

Adds the Layer array.

Parameters
layerArray Layer: a set of the concrete sub-classes of the Layer classes (e.g. ArcGISDynamicMapServiceLayer, and so on).

public void centerAndZoom (double lat, double lon, float levelOrFactor)

If the MapView is initialized, centers the map at the given latitude and longitude and zoom the map based on the given factor.

Since 10.2.2, the map animates to the new center and scale; alternatively use an overload of centerAt(Point, boolean) or setScale(double, boolean) with an animated parameter to control whether or not to animate the change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
lat double: latitude of the new center of the MapView.
lon double: longitude of the new center of the MapView.
levelOrFactor float: When using an ArcGISTiledMapServiceLayer as basemap, the map is zoomed to the level specified. Otherwise the map is zoomed in or out by the specified factor. For example, use 0.5 to zoom in twice as far and 2.0 to zoom out twice as far. When levelOrFactor is less than or equal to 0, nothing happens.

public void centerAt (Point centerPt, boolean animated)

If the MapView is initialized, centers the map at the given point; optionally, the change is animated.

Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
centerPt Point: the new center point of the MapView in map coordinates. Must have the same spatial reference as the MapView; see the getSpatialReference() method.
animated boolean: indicates if the map should animate to the new center

public void centerAt (double lat, double lon, boolean animated)

If the MapView is initialized, centers the map at the given latitude and longitude; optionally, the change is animated.

Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
lat double: latitude of the new center of the MapView
lon double: longitude of the new center of the MapView
animated boolean: indicates if the map should animate to the new center

public Bitmap createSymbolImage (Symbol symbol, Geometry geometry, int width, int height, int color)

This method is deprecated.
at 10.2.2 use getLegendImage(Symbol, Geometry, int, int, int) instead.

Returns a swatch image of the given geometry rendered with the specified symbol.

Parameters
symbol Symbol: to render the geometry with.
geometry Geometry: the geometry to render in the swatch.
width int: the width of the swatch in pixels.
height int: the height of the swatch in pixels.
color int: the background color in ARGB format.
Returns
Bitmap the swatch Bitmap or null.

public Bitmap[] createSymbolImages (Symbol[] symbol, Geometry[] geometry, int width, int height, int color)

This method is deprecated.
at 10.2.2 use getLegendImages(Symbol[], Geometry[], int, int, int) instead.

Returns a swatch image array of for the given geometries rendered with the symbols.

Parameters
symbol Symbol: a symbol array
geometry Geometry: a geometry array
width int: the width of the swatch in pixels.
height int: the height of the swatch in pixels.
color int: the background color in ARGB format.
Returns
Bitmap[] a Bitmap array

public void enableWrapAround (boolean enable)

Enable or disable the map wrap around feature. The following requirements must be satisfied before enabling wrap around: (1)The map's full envelope must cover the entire world; (2)The map's spatial reference must either be WGS84(WKID=4326) or Web Mercator(WKID=102113, 102100, or 3857) (3)Dynamic layers must be based on map services from ArcGIS Server 10.0 or higher.

If using wrap around maps, geometries created from the map (for example, from toMapPoint(Point), toMapPoint(float, float), getCenter() or getExtent()) may have coordinates outside the domain of the spatial reference of the map. Before using these geometries to perform spatial queries, address finding, or as feature geometries in a geodatabase, these geometries should be normalized to lie within the spatial reference domain. You can normalize geometries using the normalizeCentralMeridian(Geometry, SpatialReference) method.

Parameters
enable boolean: boolean

public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

Parameters
attrs AttributeSet
Returns
ViewGroup.LayoutParams

public Callout getCallout ()

Returns a callout window.

Returns
Callout the callout window

public Point getCenter ()

Returns the center of the MapView as an ArcGIS geometry Point. Use this Point object to obtain (x, y) coordinates, or spatial reference, and so on.

Returns
Point the center

public Bitmap getDrawingMapCache (float x, float y, int w, int h)

Creates a drawing cache of the map in the given screen coordinates. It may return null object if the coordinate is not correct.

Parameters
x float: the x of the left-upper corner of the cache image in screen coordinates
y float: the y of the left-upper corner of the cache image in screen coordinates
w int: the width of the cache in pixles
h int: the height of the cache in pixles
Returns
Bitmap the drawing map cache or null when one of the parameters is invalid

public Polygon getExtent ()

Returns a polygon comprising of four corners of map in map coordinates. The first vertex in polygon represents top-left corner. The second vertex represents top-right corner. The third vertex represents bottom-right corner. The fourth vertex represents bottom-left corner.

Returns
Polygon a Polygon object or null if map is not initialized.

public Grid getGrid ()

Returns the Grid instance of the map which allows for the type and visibility of the grid to be controlled.

Returns
Grid the map Grid

public Layer getLayer (int index)

Gets a layer at the given index.

Parameters
index int: the index position of the Layer.
Returns
Layer Layer object.

public Layer getLayerByID (long layerID)

Gets a layer by its ID.

Parameters
layerID long: an unique long integer.
Returns
Layer Layer object.

See also:

public Layer getLayerByURL (String url)

Gets a layer by its service URL.

Parameters
url String: service URL.
Returns
Layer Layer object.

public Layer[] getLayers ()

Returns all child Layers that are added to the MapView. The Layer array will be a zero based array, meaning Layer[0] will give you the first Layer that is drawn by the MapView.

Returns
Layer[] If the MapView has no child Layers, then an array with no elements will be returned. A MapView with no children is meaningless, ideally you will have at least one Layer child.

public LocationDisplayManager getLocationDisplayManager ()

Returns the LocationDisplayManager.

Returns
LocationDisplayManager the location display manager

public Envelope getMapBoundaryExtent ()

This method is deprecated.
in 10.2.2, use getMaxExtent() instead

Returns the boundary extent of the map. The boundary extent imposes an restriction on the viewable area of the map. The center of the map can not go beyond boundary extent when you navigate the map.

Returns
Envelope envelope or null if the map is not initialized.

public Envelope getMaxExtent ()

Returns the max extent of the map. The max extent imposes an restriction on the viewable area of the map. The center of the map can not go beyond boundary extent when you navigate the map.

Returns
Envelope envelope or null if the map is not initialized.

public double getMaxResolution ()

This method is deprecated.
at 10.2.2 please use getMinScale()

Gets the maximum resolution of the MapView.

Returns
double Returns the maxResolution.

public double getMaxScale ()

Returns maximum scale.

Returns
double a double value

public double getMinResolution ()

This method is deprecated.
10.2.2 please use getMaxScale()

Gets the minimum resolution of the map. The map can not zoom beyond the resolution range determined by minimum resolution and maximum resolution.

Returns
double Returns the minResolution.

public double getMinScale ()

Returns the minimum scale.

Returns
double a double value

public OnLongPressListener getOnLongPressListener ()

Gets the OnLongPressListener of the MapView.

Returns
OnLongPressListener Returns the OnLongPressListener.

public OnPanListener getOnPanListener ()

Gets the OnPanListener of the MapView.

Returns
OnPanListener Returns the OnPanListener.

public OnPinchListener getOnPinchListener ()

Gets the OnPinchListener of the MapView.

Returns
OnPinchListener Returns the OnPinchListener.

public OnSingleTapListener getOnSingleTapListener ()

Gets the onSingleTapListener of the MapView.

Returns
OnSingleTapListener Returns the onSingleTapListener.

public OnStatusChangedListener getOnStatusChangedListener ()

Gets the OnStatusChangedListener of the MapView.

Returns
OnStatusChangedListener Returns the OnStatusChangedListener.

public OnZoomListener getOnZoomListener ()

Gets the OnZoomListener of the MapView.

Returns
OnZoomListener Returns the OnZoomListener.

public double getResolution ()

Returns the resolution of the MapView.

Returns
double If the MapView is not initialized, then Double.NaN is returned.

public double getRotationAngle ()

Returns the current rotation angle of the map in degrees counter-clockwise.

Returns
double rotation angle in degrees

public double getScale ()

A convenience method for obtaining the current map scale .

Returns
double double the current map scale. Returns 0 if no base layer is set.

public SpatialReference getSpatialReference ()

Returns the spatial coordinate system being used by the MapView.

Returns
SpatialReference If the MapView is not initialized, then null is returned.

public boolean isAllowOneFingerZoom ()

Returns true if one-finger zooming is allowed. This gesture is triggered by holding the second tap of a one-finger double tap, and then dragging the finger up or down. Dragging down will zoom in, and dragging up will zoom out. Zooming may be stopped by either returning the finger near its original position, or by lifting the finger up.

Returns
boolean true if one-finger zooming is allowed (default: true)

public boolean isAllowRotationByPinch ()

Returns true if the rotation by pinch is allowed.

Returns
boolean true, if checks if is allow rotation by pinch

public boolean isLoaded ()

Returns true if the MapView is initialized.

Returns
boolean true, if checks if is loaded

public boolean isRecycled ()

Returns true if the MapView has been recycled.

Returns
boolean true if the MapView has been recycled.

public boolean isShowMagnifierOnLongPress ()

This method checks whether the map will show the magnifier when the user performs a tap and hold gesture on the map.

Returns
boolean true if magnifier should be shown on tap and hold gesture

public void onChildViewAdded (View parent, View child)

Parameters
parent View
child View

public void onChildViewRemoved (View parent, View child)

Parameters
parent View
child View

public void pause ()

Pauses the map. Threads related to map rendering will hang until unpause is called. It is recommended that you call this method when your Activity goes to background(usually in Activity.onPause()) since map will burn less battery when it pauses.

public void recycle ()

Releases the resources referenced by the MapView so that they can be recycled.

public void removeAll ()

Removes all child layers from the map. The native layer resources will also be recycled for each layer that is no longer referenced. If this happens, those layers cannot be added back to the MapView.

public void removeLayer (Layer layer)

Removes the child Layer from the parent MapView. The native layer resources will also be recycled if the layer is no longer referenced. If this happens, the layer cannot be added back to the MapView.

Parameters
layer Layer: one of the concrete sub-classes of the MapLayer class (e.g. ArcGISDynamicMapServiceLayer, and so on).

public void removeLayer (int index)

Removes a child layer at the given index. See the addLayer(Layer, int) method for details on the index. The native layer resources will also be recycled if the layer is no longer referenced. If this happens, the layer cannot be added back to the MapView.

Parameters
index int: the index position of the Layer.

public void restoreState (String state)

Restores the center and resolution, and the LocationDisplayManager state (whether it was active and whether or not to autopan) from the given state String into the MapView. The state string passed to this method should be the result of a call to the retainState() method. Typically, the restoreState method should be called when an Activity containing the MapView moves into the onResume state in the Activity's life cycle. Note that as the state string contains coordinates, the restoreState and retainState methods are expected to be called on MapViews that have the same spatial reference.

Unlike many other methods that change the extent of the map, restoreState does not animate the map to the specified state.

The following example code shows how to use a SharedPreferences object to retrieve a state string saved in a preferences file, and pass the result to this method to restore the state of the MapView.

 // The onResume() method is being overridden for an Activity
 // The map object is of type MapView
 protected void onResume() {
   super.onResume();
   SharedPreferences prefs = getPreferences(0);
   map.restoreState(prefs.getString("my map state", ""));
 }
 

Parameters
state String: a String containing the map state saved from the retainState() method

public String retainState ()

Saves the coordinates of the center of the map, the current map resolution, and the LocationDisplayManager state (whether it was active and whether or not to autopan) as a String. Typically, the retainState method should be called when an Activity containing the MapView moves into the onPause state in the Activity's life cycle, with a corresponding call to the restoreState(String) method in the Activity's onResume method to restore the saved state. Note that as the state string contains coordinates, the restoreState and retainState methods are expected to be called on MapViews that have the same spatial reference.

The following example code shows how to use a SharedPreferences object to save a state string in a preferences file.

 // The onPause() method is being overridden for an Activity
 // The map object is of type MapView
 super.onPause();
 SharedPreferences.Editor editor = getPreferences(0).edit();
 editor.putString("my map status", map.retainState());
 editor.commit();
 

Returns
String a map state String

public void setAllowMagnifierToPanMap (boolean allow)

Flag to indicate if the map should pan when the magnifier gets near the edge of the map's bounds. The default is false.

Parameters
allow boolean: boolean

public void setAllowOneFingerZoom (boolean allowOneFingerZoom)

Allows/disallows one-finger zooming. This gesture is triggered by holding the second tap of a one-finger double tap, and then dragging the finger up or down. Dragging down will zoom in, and dragging up will zoom out. Zooming may be stopped by either returning the finger near its original position, or by lifting the finger up.

Parameters
allowOneFingerZoom boolean: flag for allowing one-finger zoom (default: true)

public void setAllowRotationByPinch (boolean allowRotationByPinch)

Allows/disallow pinch to rotate.

Parameters
allowRotationByPinch boolean: flag for allowing rotation by pinch (default: true)

public void setEsriLogoVisible (boolean visible)

Turns on or off the ESRI logo.

Parameters
visible boolean: true to turn on the Esri logo on the map.

public void setExtent (Geometry geometry, int padding)

Zooms the map to the given geometry, so that geometry fits within the bounds of the map with the specified padding between the geometry and edge of the map.

If padding is bigger than zero, a space between map bounds and geometry will be added so that the geometry does not touch any edge of the map. If geometry type is point, map will center at the given point and padding is ignored.

Since 10.2.2, the map animates to the new extent; alternatively use the setExtent(Geometry, int, boolean) overload to control whether or not to animate the extent change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
geometry Geometry: Geometry object to zoom to (Point, Polygon, Polyline or Envelope)
padding int: non-negative integer in DP (density independent pixels)

public void setExtent (Geometry geometry, int padding, boolean animated)

Zooms the map to the given geometry, so that geometry fits within the bounds of the map with the specified padding between the geometry and edge of the map; optionally, the change is animated.

If padding is bigger than zero, a space between map bounds and geometry will be added so that the geometry does not touch any edge of the map. If geometry type is point, map will center at the given point and padding is ignored.

Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
geometry Geometry: Geometry object to zoom to (Point, Polygon, Polyline or Envelope)
padding int: non-negative integer in DP (density independent pixels)
animated boolean: indicates if the map should animate to the new extent

public void setExtent (Geometry geometry)

Zooms the map to the given geometry so that geometry fits within the bounds of the map. Equivalent to setExtent(Geometry, int) method with a padding value of zero.

Since 10.2.2, the map animates to the new extent; alternatively use the setExtent(Geometry, int, boolean) overload to control whether or not to animate the extent change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
geometry Geometry: Geometry object to zoom to (Point, Polygon, Polyline or Envelope)

public void setMapBackground (int bkColor, int gridColor, float gridSize, float gridLineSize)

Sets the map background with color and grid.

Parameters
bkColor int: background color packed as ints.
gridColor int: grid color packed as ints.
gridSize float: the size of grid.
gridLineSize float: the line size of grid

public boolean setMapOptions (MapOptions options)

Switches basemap by the given options. If the map is instantiated using a MapOptions and the spatial reference of the current basemap is the same as the given basemap's, the given basemap is replaced of the current one.

Parameters
options MapOptions: the given options of the map.
Returns
boolean

public void setMaxExtent (Envelope env)

Sets the boundary extent of the map. The boundary extent imposes an restriction on the viewable area of the map. The center of the map can not go beyond boundary extent when you navigate the map.

Parameters
env Envelope

public void setMaxResolution (double maxResolution)

This method is deprecated.
at 10.2.2 please use setMinScale(double)

Sets the maximum resolution of the MapView.

Parameters
maxResolution double: The maxResolution to set.

public void setMaxScale (double maxScale)

Sets the maximum scale to which the map can be zoomed in. For example, if the map is set with maximum scale 1000, the map will be stopped from zooming in further than the scale 1:1000.

Parameters
maxScale double: positive non-zero double value

public void setMinResolution (double minResolution)

This method is deprecated.
at 10.2.2, please use setMaxScale(double)

Sets the minimum resolution of the map.

Parameters
minResolution double: The minResolution to set.

public void setMinScale (double minScale)

Set the minimum scale to which the map can be zoomed out. For example, if the map is set with minimum scale 1000000, the map will be stopped from zooming out further than the scale 1:1000000.

Parameters
minScale double: positive non-zero double value

public void setOnLongPressListener (OnLongPressListener onLongPressListener)

Sets the OnLongPressListener of the MapView.

Parameters
onLongPressListener OnLongPressListener: The OnLongPressListener to set.

public void setOnPanListener (OnPanListener onPanListener)

Sets the OnPanListener of the MapView.

Parameters
onPanListener OnPanListener: The OnPanListener to set.

public void setOnPinchListener (OnPinchListener onPinchListener)

Sets the onPinchListener of the MapView.

Parameters
onPinchListener OnPinchListener: The onPinchListener to set.

public void setOnSingleTapListener (OnSingleTapListener onSingleTapListener)

Sets the onSingleTapListener of the MapView.

Parameters
onSingleTapListener OnSingleTapListener: The onSingleTapListener to set.

public void setOnStatusChangedListener (OnStatusChangedListener onStatusChangedListener)

Sets the OnStatusChangedListener of the MapView.

Parameters
onStatusChangedListener OnStatusChangedListener: The OnStatusChangedListener to set.

public void setOnZoomListener (OnZoomListener onZoomListener)

Sets the OnZoomListener of the MapView.

Parameters
onZoomListener OnZoomListener: The OnZoomListener to set.

public void setResolution (double res)

Sets the resolution of the MapView.

Since 10.2.2, the map animates to the new resolution; alternatively use the setScale(double, boolean) method to zoom to a specific scale and also control whether or not to animate the change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
res double: a valid double number

public void setRotationAngle (double degree, float pivotX, float pivotY)

Rotates the map to the given angle in degrees, pivoting the rotation around a given point on the screen. If the specified angle is positive, rotation is counter-clockwise, if negative then rotation is clockwise.

Since 10.2.2, the map animates to the new rotation angle; alternatively use an overload of setRotationAngle with an animated parameter, for example setRotationAngle(double, boolean) or setRotationAngle(double, Point, boolean) to control whether or not to animate the change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
degree double: rotation angle in degrees
pivotX float: x-axis screen coordinate of the pivot point, in pixels
pivotY float: y-axis screen coordinate of the pivot point, in pixels

public void setRotationAngle (double degree, boolean animated)

Rotates the map to the given angle in degrees; optionally, the change is animated. If the specified angle is positive, rotation is counter-clockwise, if negative then rotation is clockwise.

Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
degree double: rotation angle in degrees
animated boolean: indicates if the map should animate to the new rotation angle

public void setRotationAngle (double degree, Point centerPt, boolean animated)

Rotates the map to the given angle in degrees and re-centers the map at the specified map coordinates; optionally, the change is animated. If the specified angle is positive, rotation is counter-clockwise, if negative then rotation is clockwise.

Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
degree double: rotation angle in degrees
centerPt Point: the new center point of the MapView in map coordinates. Must have the same spatial reference as the MapView; see the getSpatialReference() method.
animated boolean: indicates if the map should animate to the new rotation angle

public void setRotationAngle (double degree)

Rotates the map to the given angle in degrees; if the specified angle is positive, rotation is counter-clockwise, if negative then rotation is clockwise.

Since 10.2.2, the map animates to the new rotation angle; alternatively use the setRotationAngle(double, boolean) overload to control whether or not to animate the map rotation. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
degree double: rotation angle in degrees

public void setScale (double scale, boolean animated)

Sets the map scale; optionally, the change is animated.

Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
scale double: the scale the map should be displayed at
animated boolean: indicates if the map should animate to the new scale

public void setScale (double scale)

Sets the map scale.

Since 10.2.2, the map animates to the new scale; alternatively use the setScale(double, boolean) overload to control whether or not to animate the scale change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
scale double: the scale the map should be displayed at

public void setShowMagnifierOnLongPress (boolean showMagnifier)

Sets a flag that defines whether or not the map should show the magnifier when the user performs a long press gesture on the map. Default is false. If setting to true, use onLongPressUp(MotionEvent) instead of {#link OnLongPressListener#onLongPress}.

Parameters
showMagnifier boolean: pass true if the magnifier should be shown on long press

public Future<Boolean> switchBaseMap (BaseMap basemap, Portal portal, OnBaseMapSwitchListener listener)

Replaces the basemap layers of this MapView if it was created from a WebMap, otherwise just adds the new basemap layers at the bottom or top of the existing MapView layers, depending on whether they are base or reference layers. The following conditions have to be true for the basemap switch to succeed:

When switching basemaps, the delegate methods regarding layer loading are called (see OnStatusChangedListener and OnBaseMapSwitchListener). For example if a basemap layer fails to load it will call onWebMapLoadError(MapView, WebMap, WebMapLayer, Layer, Throwable, UserCredentials) and the user can feedback on how to handle the failure. Once the webmap has tried to load all the basemap layers and added them to the map then the onBaseMapSwitchCompleted(BaseMap, Throwable) method is called.

Parameters
basemap BaseMap: a BaseMap providing the new basemap layers.
portal Portal: a portal instance used to authenticate federated basemap service layers, can be null.
listener OnBaseMapSwitchListener: a class that implements OnBaseMapSwitchListener, that recieves callbacks for the operation. Use the onWebMapLoadError(MapView, WebMap, WebMapLayer, Layer, Throwable, UserCredentials) callback to control some aspects of how layer loading failure is handled. The onBaseMapSwitchCompleted(BaseMap, Throwable) method is called when the basemap switch operation is finished. This argument can be null.
Returns
Future<Boolean> A Future that allows cancellation of the async request as well as retrieving a boolean that indicates success or failure.
Throws
IllegalStateException if the MapView has not been initialized yet when calling this method.

public Point toMapPoint (float screenx, float screeny)

A convenience method that will convert a device's screen coordinates to an ArcGIS geometry Point that has the same spatial coordinate system as the MapView's.

Parameters
screenx float: the x coordinate of the device's screen point in pixels.
screeny float: the y coordinate of the device's screen point in pixels.
Returns
Point the ArcGIS geometry Point that has a spatial coordinate system defined equivalent to that of the MapView's.

public Point toMapPoint (Point src)

A convenience method that will convert a device's screen coordinates into an ArcGIS geometry Point that has the same spatial coordinate system as the MapView's.

Parameters
src Point: the ArcGIS geometry Point given in screen coordinates.
Returns
Point the ArcGIS geometry Point that has a spatial coordinate system defined equivalent to that of the MapView's.

public Point toScreenPoint (Point src)

A convenience method that will convert an ArcGIS geometry Point from the MapView's spatial coordinate system into the device's screen coordinates. The return value is an ArcGIS geometry Point to make it easier for you to supply the Point as input for other methods in the ArcGIS API for Android.

Parameters
src Point: the ArcGIS geometry Point that has a spatial coordinate system defined equivalent to that of the MapView's.
Returns
Point the ArcGIS geometry Point given in screen coordinates.

public void unpause ()

Unpauses the map. Threads related to map rendering resume running. If you call pause when your Activity goes to background, you must call this method when your Activitiy is brought to front(usually in Activity.onResume()).

public void zoomTo (Point centerPt, float factor)

If the MapView is initialized, zooms the map by a factor to the given center point.

Since 10.2.2, the map animates to the new center and scale; alternatively use the centerAt(Point, boolean) and setScale(double, boolean) methods to zoom to a specific center point and scale and also control whether or not to animate the change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
centerPt Point: a point representing the new center of the MapView. The point object must be defined to have the same spatial coordinate system of the MapView. The spatial coordinate system can be obtained using the getSpatialReference() method.
factor float: represents a factor that is used to calculate and apply a new resolution to the MapView. The new resolution is equal to the current resolution divided by the factor supplied in the method call (new resolution = current resolution / factor).

public void zoomToResolution (Point centerPt, double res)

Centers the map on the given point and zoom into the given resolution level.

Since 10.2.2, the map animates to the new center and resolution; alternatively use the centerAt(Point, boolean) and setScale(double, boolean) methods to zoom to a specific center point and scale and also control whether or not to animate the change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
centerPt Point: a Point object
res double: a double number

public void zoomToScale (Point centerPt, double scale)

Centers the map on the given point and zoom into the given scale level.

Since 10.2.2, the map animates to the new center and scale; alternatively use the centerAt(Point, boolean) and setScale(double, boolean) methods to zoom to a specific center point and scale and also control whether or not to animate the change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
centerPt Point: a Point object
scale double: a double number

public void zoomin ()

Zooms in one level from current map resolution; the map animates to the new resolution.

Alternatively use the zoomin(boolean) overload to control whether or not to animate the change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

public void zoomin (boolean animated)

Zooms in one level from current map resolution; optionally, the change is animated.

Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
animated boolean: indicates if the map should animate to the new resolution

public void zoomout ()

Zooms out one level from current map resolution; the map animates to the new resolution.

Alternatively use the zoomout(boolean) overload to control whether or not to animate the change. Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

public void zoomout (boolean animated)

Zooms out one level from current map resolution; optionally, the change is animated.

Note that map navigation animation methods are not blocking, and calling another such method before the previous method's animation has completed may have unexpected results. If you need to make a series of navigation calls in quick succession, the recommended approach is to use animation only in the last call in the series.

Parameters
animated boolean: indicates if the map should animate to the new resolution

Protected Methods

protected void finalize ()

Throws
Throwable

protected void onDetachedFromWindow ()

protected void onLayout (boolean changed, int l, int t, int r, int b)

Parameters
changed boolean
l int
t int
r int
b int

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Parameters
widthMeasureSpec int
heightMeasureSpec int

protected void onSizeChanged (int w, int h, int oldw, int oldh)

Parameters
w int
h int
oldw int
oldh int