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.

Notice that 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, either through 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.

To instantiate a MapView from a URL of a WebMap, you can do it either through the layerout xml or through Java code. When the WebMap has Bing map layers, you need to provide application ID to access the Bing map.

XML usage:

 
 <!-- MapView that will fill your device screen with the "mspservice" hosted on ArcGIS Online. -->
 <com.esri.android.map.MapView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent"
      appId="the id...."
      url="http://webmap/mapservice with a Bing map layer/"/>
 
 
Java usage:
 
 MapView mv = new MapView(this,"http://webmap/mapservice with a Bing map layer", null, null, "your appId here");
 setContentView(mv);
 

When instantiating the MapView, as done in the Java usage example shown previously, 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 initialize. 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 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(View source, STATUS status) {
         if (OnStatusChangedListener.STATUS.INITIALIZED == status && source == map) {
           Log.d("Test", "resolution:" + map.getResolution());
         }
       }
     });
   }
 
 
 
When initialize a MapView, the OnStatusChangedListener notifies you the status changes from both the MapView and Layers. You need to use the source of the event to distinguish them. When the initialization is failed, you can use the getError() to get the error details.

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

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, WebMap webmap, String bingMapsAppId, OnMapEventListener listener)
The constructor is used if you are instantiating the MapView using a WebMap.
MapView(Context context, WebMap webmap, BaseMap basemap, String bingMapsAppId, OnMapEventListener listener)
Instantiates an object of MapView from a webmap.
Public Methods
int addLayer(Layer layer, int index)
Adds the child Layer at the given index.
int addLayer(Layer layer)
Adds the child Layer.
void addLayers(Layer[] layerArray)
Adds the Layer array.
void centerAt(Point centerPt, boolean animated)
If the MapView is initialized, centers the map at the given point.
Bitmap createSymbolImage(Symbol symbol, Geometry geometry, int width, int height, int color)
Returns a swatch image of the given geometry rendered with the specified symbol.
Bitmap[] createSymbolImages(Symbol[] symbol, Geometry[] geometry, int width, int height, int color)
Returns a swatch image array of for the given geometries rendered with the symbols.
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 extent.
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.
LocationService getLocationService()
Returns the unique instance of the location service.
Envelope getMapBoundaryExtent()
Returns the boundary extent of the map.
double getMaxResolution()
Gets the maximum resolution of the MapView.
double getMinResolution()
Gets the minimum resolution of the map.
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 map rotation angle(in degree).
double getScale()
A convenience method for obtaining the current map scale .
SpatialReference getSpatialReference()
Returns the spatial coordinate system being used by the MapView.
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.
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(int index)
Removes a child layer at the given index.
void removeLayer(Layer layer)
Removes the child Layer from the parent MapView.
void restoreState(String state)
Restores the center and resolution of the MapView from the given String that is typically setup in an Activity's onPause() method (see MapView's retainMapInfo() method for details).
String retainState()
The MapView's state should be persisted using a String object.
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 into the given geometry so that geometry fits the bounds of the map.
void setExtent(Geometry geometry)
This method will zoom map into the given geometry and use its bound as current map extent.
void setMapBackground(int bkColor, int gridColor, float gridSize, float gridLineSize)
Sets the map background with color and grid.
void setMaxResolution(double maxResolution)
Sets the maximum resolution of the MapView.
void setMinResolution(double minResolution)
Sets the minimum resolution of the map.
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, Point centerPt, boolean animated)
The method will rotate the map in the given angle(in degree) and re-center the map at a map point(x and y in map unit); if the given angle number is positive, map will rotate anti-clockwise.
void setRotationAngle(double degree)
The method will rotate the map in the given angle(in degree) at a screen point(x and y in pixel); if the given angle number is positive, map will rotate anti-clockwise.
void setRotationAngle(double degree, float pivotX, float pivotY)
The method will rotate the map in the given angle(in degree) at a screen point(x and y in pixel); if the given angle number is positive, map will rotate anti-clockwise.
void setScale(double scale)
A convenience method for setting the map scale .
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.
void zoomout()
Zooms out one level from current map resolution.
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.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewGroup.OnHierarchyChangeListener
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

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 The Context the view is running in, through which it can access the current theme, resources, and so on.
attrs The attributes of the XML tag used to inflate the MapView.
defStyle 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 The Context the view is running in, through which it can access the current theme, resources and so on.
attrs 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 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 The Context the view is running in, through which it can access the current theme, resources, , and so on.
spatialreference the spatial reference to initialize the map with.
extent 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 The Context the view is running in, through which it can access the current theme, resources, , and so on.
url the URL of the WebMap
user the name of the user who can access the WebMap. Set to null if the WebMap doesn't need to sign in.
passwd 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 The Context the view is running in, through which it can access the current theme, resources, , and so on.
url the URL of the WebMap
user the name of the user who can access the WebMap. Set to null if the WebMap doesn't need to sign in.
passwd the password of the user. Set to null if the WebMap doesn't need to sign in.
bingMapsAppId 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 The Context the view is running in, through which it can access the current theme, resources, , and so on.
url the URL of the WebMap
user the name of the user who can access the WebMap. Set to null if the WebMap doesn't need to sign in.
passwd the password of the user. Set to null if the WebMap doesn't need to sign in.
bingMapsAppId if the WebMap is using Bing map, you need to provide the application id to access the map.
listener the listener

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

The constructor is used if you are instantiating the 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 The Context the view is running in, through which it can access the current theme, resources, , and so on.
webmap the WebMap
bingMapsAppId if the WebMap is using Bing map, you need to provide the application id to access the map.
listener when fail to load the WebMap, the user can feedback on how to handle the failure. You can set to null to follow the default loading behavior.

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

Instantiates an object of MapView from a webmap. The MapView contains the operational layers from the given webmap and the basemap layers from the give basemap.

Parameters
context The Context the view is running in, through which it can access the current theme, resources, , and so on.
webmap the MapView retrieves operations layers from the given webmap here.
basemap the MapView retrieves basemap layers from the given basemap here.
bingMapsAppId if the WebMap is using Bing map, you need to provide the application id to access the map.
listener when fail to load the WebMap, the user can feedback on how to handle the failure. You can set to null to follow the default loading behavior.

Public Methods

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 one of the concrete sub-classes of the Layer class (e.g. ArcGISDynamicMapServiceLayer, and so on).
index the index position of the Layer.
Returns
  • a positive integer if the layer is added to the map successfully.

public int addLayer (Layer layer)

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

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

public void addLayers (Layer[] layerArray)

Adds the Layer array.

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

public void centerAt (Point centerPt, boolean animated)

If the MapView is initialized, centers the map at the given point.

Parameters
centerPt 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. The isLoaded() method can be used to determine if the MapView has been initialized. See isLoaded() method description for details.
animated boolean to decide if animation is needed.

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

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

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

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

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

Parameters
symbol a symbol array
geometry a geometry array
width the width of the swatch in pixels.
height the height of the swatch in pixels.
color the background color in ARGB format.
Returns
  • a Bitmap array

public void enableWrapAround (boolean enable)

Enable or disable the map wrap around feature. The following 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.

Parameters
enable boolean

public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

public Callout getCallout ()

Returns a callout window.

Returns
  • 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
  • the center

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

Creates a drawing cache of the map in the given extent.

Parameters
x the x of the left-upper corner of the cache image in screen coordinates
y the y of the left-upper corner of the cache image in screen coordinates
w the width of the cache in pixles
h the height of the cache in pixles
Returns
  • the drawing map cache

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
  • 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

public Layer getLayer (int index)

Gets a layer at the given index.

Parameters
index the index position of the Layer.
Returns
  • Layer object.

public Layer getLayerByID (long layerID)

Gets a layer by its ID.

Parameters
layerID an unique long integer.
Returns
  • Layer object.
See Also

public Layer getLayerByURL (String url)

Gets a layer by its service URL.

Parameters
url service URL.
Returns
  • 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
  • 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 LocationService getLocationService ()

Returns the unique instance of the location service.

Returns
  • the location service

public Envelope getMapBoundaryExtent ()

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 or null if the map is not initialized.

public double getMaxResolution ()

Gets the maximum resolution of the MapView.

Returns
  • Returns the maxResolution.

public double getMinResolution ()

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

Returns
  • Returns the minResolution.

public OnLongPressListener getOnLongPressListener ()

Gets the OnLongPressListener of the MapView.

Returns
  • Returns the OnLongPressListener.

public OnPanListener getOnPanListener ()

Gets the OnPanListener of the MapView.

Returns
  • Returns the OnPanListener.

public OnPinchListener getOnPinchListener ()

Gets the OnPinchListener of the MapView.

Returns
  • Returns the OnPinchListener.

public OnSingleTapListener getOnSingleTapListener ()

Gets the onSingleTapListener of the MapView.

Returns
  • Returns the onSingleTapListener.

public OnStatusChangedListener getOnStatusChangedListener ()

Gets the OnStatusChangedListener of the MapView.

Returns
  • Returns the OnStatusChangedListener.

public OnZoomListener getOnZoomListener ()

Gets the OnZoomListener of the MapView.

Returns
  • Returns the OnZoomListener.

public double getResolution ()

Returns the resolution of the MapView.

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

public double getRotationAngle ()

Returns the current map rotation angle(in degree).

Returns
  • rotated angle.

public double getScale ()

A convenience method for obtaining the current map scale .

Returns
  • 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
  • If the MapView is not initialized, then null is returned.

public boolean isAllowRotationByPinch ()

Returns true if the rotation by pinch is allowed.

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

public boolean isLoaded ()

Returns true if the MapView is initialized.

Returns
  • true, if checks if is loaded

public boolean isRecycled ()

Returns true if the MapView has been recycled.

Returns
  • true if the MapView has been recycled.

public void onChildViewAdded (View parent, View child)

public void onChildViewRemoved (View parent, View child)

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.

public void removeLayer (int index)

Removes a child layer at the given index. See the addLayer(Layer, int) method for details on the index.

Parameters
index the index position of the Layer.

public void removeLayer (Layer layer)

Removes the child Layer from the parent MapView.

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

public void restoreState (String state)

Restores the center and resolution of the MapView from the given String that is typically setup in an Activity's onPause() method (see MapView's retainMapInfo() method for details). Use the SharedPReferences object to retrieve the preferences, which includes the center of the map and current the map resolution and pass that object into this method to restore the MapView's state. Typically, this method should be called when an Activity containing the MapView moves into the onResume state in the Activity's life cycle.

 // 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", ""));
 }
 
See the HelloWorld sample for more details.

Parameters
state the state

public String retainState ()

The MapView's state should be persisted using a String object. When calling this method , the center of the map and the current map resolution are returned as a String. Typically, this method should be called when an Activity containing the MapView moves into the onPause state in the Activity's life cycle.

The following example code illustrates the purpose of this method:

 
 // 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();
 
See the HelloWorld sample for more details.

Returns
  • the string

public void setAllowRotationByPinch (boolean allowRotationByPinch)

Allows/disallow pinch to rotate.

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

public void setEsriLogoVisible (boolean visible)

Turns on or off the ESRI logo.

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

public void setExtent (Geometry geometry, int padding)

Zooms into the given geometry so that geometry fits the bounds 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.

Parameters
geometry Geometry object(Point, Polygon, Polyline or Envelope);
padding non-negative integer (in pixel)

public void setExtent (Geometry geometry)

This method will zoom map into the given geometry and use its bound as current map extent. Internally it calls setExtent(Geometry, int) method with padding zero.

Parameters
geometry Geometry object(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 background color packed as ints.
gridColor grid color packed as ints.
gridSize the size of grid.
gridLineSize the line size of grid

public void setMaxResolution (double maxResolution)

Sets the maximum resolution of the MapView.

Parameters
maxResolution The maxResolution to set.

public void setMinResolution (double minResolution)

Sets the minimum resolution of the map.

Parameters
minResolution The minResolution to set.

public void setOnLongPressListener (OnLongPressListener onLongPressListener)

Sets the OnLongPressListener of the MapView.

Parameters
onLongPressListener The OnLongPressListener to set.

public void setOnPanListener (OnPanListener onPanListener)

Sets the OnPanListener of the MapView.

Parameters
onPanListener The OnPanListener to set.

public void setOnPinchListener (OnPinchListener onPinchListener)

Sets the onPinchListener of the MapView.

Parameters
onPinchListener The onPinchListener to set.

public void setOnSingleTapListener (OnSingleTapListener onSingleTapListener)

Sets the onSingleTapListener of the MapView.

Parameters
onSingleTapListener The onSingleTapListener to set.

public void setOnStatusChangedListener (OnStatusChangedListener onStatusChangedListener)

Sets the OnStatusChangedListener of the MapView.

Parameters
onStatusChangedListener The OnStatusChangedListener to set.

public void setOnZoomListener (OnZoomListener onZoomListener)

Sets the OnZoomListener of the MapView.

Parameters
onZoomListener The OnZoomListener to set.

public void setResolution (double res)

Sets the resolution of the MapView.

Parameters
res a valid double number

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

The method will rotate the map in the given angle(in degree) and re-center the map at a map point(x and y in map unit); if the given angle number is positive, map will rotate anti-clockwise. Otherwise it will rotate clockwise.

Parameters
degree double number (in degree)
centerPt 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. The isLoaded() method can be used to determine if the MapView has been initialized. See isLoaded() method description for details.
animated boolean to decide if animation is needed.

public void setRotationAngle (double degree)

The method will rotate the map in the given angle(in degree) at a screen point(x and y in pixel); if the given angle number is positive, map will rotate anti-clockwise. Otherwise it will rotate clockwise.

Parameters
degree double number (in degree)

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

The method will rotate the map in the given angle(in degree) at a screen point(x and y in pixel); if the given angle number is positive, map will rotate anti-clockwise. Otherwise it will rotate clockwise.

Parameters
degree double number (in degree)
pivotX a float number (in pixel)
pivotY a float number (in pixel)

public void setScale (double scale)

A convenience method for setting the map scale .

Parameters
scale double value

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 the x coordinate of the device's screen point in pixels.
screeny the y coordinate of the device's screen point in pixels.
Returns
  • 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 the ArcGIS geometry Point given in screen coordinates.
Returns
  • 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 the ArcGIS geometry Point that has a spatial coordinate system defined equivalent to that of the MapView's.
Returns
  • 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.

Parameters
centerPt 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 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.

Parameters
centerPt a Point object
res a double number

public void zoomToScale (Point centerPt, double scale)

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

Parameters
centerPt a Point object
scale a double number

public void zoomin ()

Zooms in one level from current map resolution.

public void zoomout ()

Zooms out one level from current map resolution.

Protected Methods

protected void finalize ()

Throws
Throwable

protected void onDetachedFromWindow ()

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

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

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