com.esri.android.map
Class MapView

java.lang.Object
  extended by android.view.View
      extended by android.view.ViewGroup
          extended by com.esri.android.map.MapView
All Implemented Interfaces:
android.graphics.drawable.Drawable.Callback, android.view.accessibility.AccessibilityEventSource, android.view.KeyEvent.Callback, android.view.ViewGroup.OnHierarchyChangeListener, android.view.ViewManager, android.view.ViewParent

public class MapView
extends android.view.ViewGroup
implements android.view.ViewGroup.OnHierarchyChangeListener

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:

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 OnStatusChangedListener.STATUS.getError() to get the error details.

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

See Also:
OnStatusChangedListener

Nested Class Summary
 
Nested classes/interfaces inherited from class android.view.ViewGroup
android.view.ViewGroup.LayoutParams, android.view.ViewGroup.MarginLayoutParams, android.view.ViewGroup.OnHierarchyChangeListener
 
Nested classes/interfaces inherited from class android.view.View
android.view.View.BaseSavedState, android.view.View.MeasureSpec, android.view.View.OnClickListener, android.view.View.OnCreateContextMenuListener, android.view.View.OnFocusChangeListener, android.view.View.OnKeyListener, android.view.View.OnLongClickListener, android.view.View.OnTouchListener
 
Field Summary
 
Fields inherited from class android.view.ViewGroup
FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE
 
Fields inherited from class android.view.View
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, KEEP_SCREEN_ON, NO_ID, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SOUND_EFFECTS_ENABLED, VISIBLE
 
Constructor Summary
MapView(android.content.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(android.content.Context context, android.util.AttributeSet attrs)
          This constructor is called when the MapView object is being inflated from XML.
MapView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)
          Inflate the MapView object from XML and apply a class-specific base style.
MapView(android.content.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(android.content.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(android.content.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(android.content.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(android.content.Context context, WebMap webmap, String bingMapsAppId, OnMapEventListener listener)
          The constructor is used if you are instantiating the MapView using a WebMap.
 
Method Summary
 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 centerAt(Point centerPt, boolean animated)
          If the MapView is initialized, centers the map at the given point.
 android.view.ViewGroup.LayoutParams generateLayoutParams(android.util.AttributeSet attrs)
           
 Callout getCallout()
          Returns a callout window
 Point getCenter()
          Returns the center of the MapView as an ArcGIS geometry Point.
 android.graphics.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 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(android.view.View parent, android.view.View child)
           
 void onChildViewRemoved(android.view.View parent, android.view.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)
          This method will zoom map into the given geometry and use its bound as current map extent.
 void setExtent(Geometry geometry, int padding)
          Zooms into the given geometry so that geometry fits the bounds of the map.
 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)
          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 zoomin()
          Zooms in one level from current map resolution.
 void zoomout()
          Zooms out one level from current map resolution.
 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.
 
Methods inherited from class android.view.ViewGroup
addFocusables, addFocusables, addStatesFromChildren, addTouchables, addView, addView, addView, addView, addView, bringChildToFront, childDrawableStateChanged, clearChildFocus, clearDisappearingChildren, clearFocus, dispatchConfigurationChanged, dispatchDisplayHint, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchSetSelected, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, findFocus, focusableViewAvailable, focusSearch, gatherTransparentRegion, getChildAt, getChildCount, getChildMeasureSpec, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getPersistentDrawingCache, hasFocus, hasFocusable, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onInterceptTouchEvent, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestTransparentRegion, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setOnHierarchyChangeListener, setPadding, setPersistentDrawingCache, showContextMenuForChild, startLayoutAnimation, updateViewLayout
 
Methods inherited from class android.view.View
bringToFront, buildDrawingCache, buildDrawingCache, cancelLongPress, checkInputConnectionProxy, clearAnimation, computeScroll, createContextMenu, destroyDrawingCache, draw, findViewById, findViewWithTag, focusSearch, forceLayout, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getContentDescription, getContext, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getId, getKeepScreenOn, getKeyDispatcherState, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getTag, getTag, getTop, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, hasWindowFocus, inflate, invalidate, invalidate, invalidate, invalidateDrawable, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPressed, isSaveEnabled, isScrollbarFadingEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, offsetLeftAndRight, offsetTopAndBottom, onCheckIsTextEditor, onCreateInputConnection, onFinishTemporaryDetach, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onWindowFocusChanged, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setClickable, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setKeepScreenOn, setLayoutParams, setLongClickable, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setOnTouchListener, setPressed, setSaveEnabled, setScrollbarFadingEnabled, setScrollBarStyle, setScrollContainer, setSelected, setSoundEffectsEnabled, setTag, setTag, setTouchDelegate, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVisibility, setWillNotCacheDrawing, setWillNotDraw, showContextMenu, startAnimation, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface android.view.ViewParent
createContextMenu, getParent, isLayoutRequested, requestLayout
 

Constructor Detail

MapView

public MapView(android.content.Context context,
               android.util.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.

MapView

public MapView(android.content.Context context,
               android.util.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.

MapView

public MapView(android.content.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.

MapView

public MapView(android.content.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.

MapView

public MapView(android.content.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.

MapView

public MapView(android.content.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.

MapView

public MapView(android.content.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.

MapView

public MapView(android.content.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.
Method Detail

zoomin

public void zoomin()
Zooms in one level from current map resolution.


zoomout

public void zoomout()
Zooms out one level from current map resolution.


generateLayoutParams

public android.view.ViewGroup.LayoutParams generateLayoutParams(android.util.AttributeSet attrs)
Overrides:
generateLayoutParams in class android.view.ViewGroup

onChildViewAdded

public void onChildViewAdded(android.view.View parent,
                             android.view.View child)
Specified by:
onChildViewAdded in interface android.view.ViewGroup.OnHierarchyChangeListener

retainState

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.


restoreState

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.


isAllowRotationByPinch

public boolean isAllowRotationByPinch()
Returns true if the rotation by pinch is allowed.


setAllowRotationByPinch

public void setAllowRotationByPinch(boolean allowRotationByPinch)
Allows/disallow pinch to rotate

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

getCenter

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.


getResolution

public double getResolution()
Returns the resolution of the MapView.

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

setResolution

public void setResolution(double res)
Sets the resolution of the MapView.

Parameters:
res - a valid double number

getSpatialReference

public SpatialReference getSpatialReference()
Returns the spatial coordinate system being used by the MapView.

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

removeLayer

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).

addLayer

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.

addLayers

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).

addLayer

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.

removeLayer

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.

removeAll

public void removeAll()
Removes all child layers from the map.


getLayerByURL

public Layer getLayerByURL(String url)
Gets a layer by its service URL.

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

getLayers

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.

getLayer

public Layer getLayer(int index)
Gets a layer at the given index.

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

setMapBackground

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

getExtent

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.

getMapBoundaryExtent

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.

setExtent

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);

setExtent

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)

zoomTo

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).

centerAt

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.

toScreenPoint

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.

toMapPoint

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.

toMapPoint

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.

getScale

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.

setScale

public void setScale(double scale)
A convenience method for setting the map scale .

Parameters:
scale - double value

getOnZoomListener

public OnZoomListener getOnZoomListener()
Gets the OnZoomListener of the MapView.

Returns:
Returns the OnZoomListener.

setOnZoomListener

public void setOnZoomListener(OnZoomListener onZoomListener)
Sets the OnZoomListener of the MapView.

Parameters:
onZoomListener - The OnZoomListener to set.

getOnPanListener

public OnPanListener getOnPanListener()
Gets the OnPanListener of the MapView.

Returns:
Returns the OnPanListener.

setOnPanListener

public void setOnPanListener(OnPanListener onPanListener)
Sets the OnPanListener of the MapView.

Parameters:
onPanListener - The OnPanListener to set.

getOnLongPressListener

public OnLongPressListener getOnLongPressListener()
Gets the OnLongPressListener of the MapView.

Returns:
Returns the OnLongPressListener.

setOnLongPressListener

public void setOnLongPressListener(OnLongPressListener onLongPressListener)
Sets the OnLongPressListener of the MapView.

Parameters:
onLongPressListener - The OnLongPressListener to set.

getOnPinchListener

public OnPinchListener getOnPinchListener()
Gets the OnPinchListener of the MapView.

Returns:
Returns the OnPinchListener.

setOnPinchListener

public void setOnPinchListener(OnPinchListener onPinchListener)
Sets the onPinchListener of the MapView.

Parameters:
onPinchListener - The onPinchListener to set.

getOnSingleTapListener

public OnSingleTapListener getOnSingleTapListener()
Gets the onSingleTapListener of the MapView.

Returns:
Returns the onSingleTapListener.

setOnSingleTapListener

public void setOnSingleTapListener(OnSingleTapListener onSingleTapListener)
Sets the onSingleTapListener of the MapView.

Parameters:
onSingleTapListener - The onSingleTapListener to set.

getOnStatusChangedListener

public OnStatusChangedListener getOnStatusChangedListener()
Gets the OnStatusChangedListener of the MapView.

Returns:
Returns the OnStatusChangedListener.

setOnStatusChangedListener

public void setOnStatusChangedListener(OnStatusChangedListener onStatusChangedListener)
Sets the OnStatusChangedListener of the MapView.

Parameters:
onStatusChangedListener - The OnStatusChangedListener to set.

isLoaded

public boolean isLoaded()
Returns true if the MapView is initialized.


getLocationService

public LocationService getLocationService()
Returns the unique instance of the location service

Returns:
the location service

getCallout

public Callout getCallout()
Returns a callout window

Returns:
the callout window

recycle

public void recycle()
Releases the resources referenced by the MapView so that they can be recycled.


setRotationAngle

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)

setRotationAngle

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)

getRotationAngle

public double getRotationAngle()
Returns the current map rotation angle(in degree).

Returns:
rotated angle.

pause

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.


unpause

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()).


zoomToScale

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

zoomToResolution

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

onChildViewRemoved

public void onChildViewRemoved(android.view.View parent,
                               android.view.View child)
Specified by:
onChildViewRemoved in interface android.view.ViewGroup.OnHierarchyChangeListener

getMinResolution

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.

setMinResolution

public void setMinResolution(double minResolution)
Sets the minimum resolution of the map.

Parameters:
minResolution - The minResolution to set.

getMaxResolution

public double getMaxResolution()
Gets the maximum resolution of the MapView.

Returns:
Returns the maxResolution.

setMaxResolution

public void setMaxResolution(double maxResolution)
Sets the maximum resolution of the MapView.

Parameters:
maxResolution - The maxResolution to set.

getGrid

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

Returns:
the map Grid

setEsriLogoVisible

public void setEsriLogoVisible(boolean visible)
Turns on or off the ESRI logo.

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

getDrawingMapCache

public android.graphics.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

isRecycled

public boolean isRecycled()
Returns true if the MapView has been recycled.

Returns:
true if the MapView has been recycled.


Copyright © 2012. All Rights Reserved.