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 LayerView as its child. In general, the MapView is the parent of all LayerView 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 LayerView. 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 "World Street Map" 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">
    <com.esri.android.map.ags.ArcGISTiledMapServiceLayer
      url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
 </com.esri.android.map.MapView> 
 
 
Java usage:
 //ArcGISTiledMapServiceLayer class is used to define the LayerView that is added to the 
 //MapView object. 
 MapView mv = new MapView(this);
 mv.addLayer(new ArcGISTiledMapServiceLayer(this,
     "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.

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) {
           Log.d("Test", "resolution:" + map.getResolution());
         }
       }
     });
   }
 
 
 
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
static long CONTEXT_TILE_CACHE_SIZE
          Defines the disk space (in KB) for tile cache on the internal directory.
static String EXTERNAL_CACHE_DIR_NAME
          Defines the name of the directory for tile caching on the external storage (e.g.
static boolean EXTERNAL_TILE_CACHE_ENABLED
          Enables the external storage for tile caching.
static long EXTERNAL_TILE_CACHE_SIZE
          Defines the disk space (in KB) for tile cache on the external storage (e.g.
static int TILE_FILE_KB_SIZE
          Defines the average size (in KB) of a cached tile.
 
Fields inherited from class android.view.ViewGroup
CLIP_TO_PADDING_MASK, 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, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, KEEP_SCREEN_ON, NO_ID, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET
 
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, String url, String user, String passwd)
          The constructor is used if you are instantiating the MapView using the URL of a WebMap.
 
Method Summary
 void addLayer(LayerView<?> layer)
          Adds the child LayerView to the parent, MapView.
 void addLayer(LayerView<?> layer, int index)
          Adds the child LayerView at the given index supplied in the method call.
 void addLayers(LayerView<?>[] layerArray)
          Adds the LayerView array to the parent MapView.
 void centerAt(Point centerPt)
          If the MapView is initialized, then the centerPt is used to reposition the MapView to make this point the center of the device's display.
 android.view.ViewGroup.LayoutParams generateLayoutParams(android.util.AttributeSet attrs)
           
 Callout getCallout()
          Returns the unique instance of the callout window
 Point getCenter()
          Returns the center of the MapView as an ArcGIS geometry Point.
 Envelope getExtent()
          Returns an extent representing the maximum extent of data, which is currently visible on the device that is showing the map.
 LayerView<?> getLayerById(int resourceId)
          Gets a layer by its resource id.
 LayerView<?>[] getLayers()
          Returns all child LayerViews that are added to the MapView.
 LocationService getLocationService()
          Returns the unique instance of the location service
 OnMapExtentChangedListener getOnExtentChangedListener()
          Gets the onExtentChangedListener of the MapView.
 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.
 SpatialReference getSpatialReference()
          Returns the spatial coordinate system being used by the MapView.
 boolean isLoaded()
          Returns true if the MapView is initialized.
 void onChildViewAdded(android.view.View parent, android.view.View child)
           
 void onChildViewRemoved(android.view.View parent, android.view.View child)
           
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)
           
 void removeAll()
          Removes all child views from the MapView map view.
 void removeLayer(int index)
          Removes a child layer at the index position passed into the method.
 void removeLayerById(int resourceId)
          Removes a layer by its resource id.
 void reorderLayer(int resourceId, int index)
          Changes the index position of the layer with the resource id supplied in the method.
 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 setExtent(Envelope extent)
          If the MapView is initialized, then the extent of the map that is displayed on the device will change to the extent that is supplied in this method call.
 void setOnExtentChangedListener(OnMapExtentChangedListener onExtentChangedListener)
          Sets the onExtentChangedListener of the MapView.
 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.
 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 zoomin()
          Zooms In one level from current map resolution.
 void zoomout()
          Zooms Out one level from current map resolution.
 void zoomTo(Envelope extent)
          Changes the map bounds to the given extent if the MapView is initialized.
 void zoomTo(Point centerPt, float factor)
          If the MapView is initialized, then the extent of the map that is displayed on the device will center itself at the point and re-factor based on the supplied parameters in the method call.
 
Methods inherited from class android.view.ViewGroup
addFocusables, addFocusables, addStatesFromChildren, addTouchables, addView, addView, addView, addView, addView, addViewInLayout, addViewInLayout, attachLayoutAnimationParameters, attachViewToParent, bringChildToFront, canAnimate, checkLayoutParams, childDrawableStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, debug, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDraw, dispatchFreezeSelfOnly, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetPressed, dispatchSetSelected, dispatchThawSelfOnly, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, drawableStateChanged, drawChild, findFocus, fitSystemWindows, focusableViewAvailable, focusSearch, gatherTransparentRegion, generateDefaultLayoutParams, generateLayoutParams, getChildAt, getChildCount, getChildDrawingOrder, getChildMeasureSpec, getChildStaticTransformation, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getPersistentDrawingCache, hasFocus, hasFocusable, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isChildrenDrawingOrderEnabled, isChildrenDrawnWithCacheEnabled, measureChild, measureChildren, measureChildWithMargins, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onAnimationEnd, onAnimationStart, onCreateDrawableState, onInterceptTouchEvent, onRequestFocusInDescendants, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeDetachedView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestTransparentRegion, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setChildrenDrawingCacheEnabled, setChildrenDrawingOrderEnabled, setChildrenDrawnWithCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setOnHierarchyChangeListener, setPadding, setPersistentDrawingCache, setStaticTransformationsEnabled, showContextMenuForChild, startLayoutAnimation, updateViewLayout
 
Methods inherited from class android.view.View
awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, cancelLongPress, checkInputConnectionProxy, clearAnimation, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, destroyDrawingCache, draw, findViewById, findViewWithTag, focusSearch, forceLayout, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getKeepScreenOn, getKeyDispatcherState, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTag, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPaddingOffsetRequired, isPressed, isSaveEnabled, isScrollbarFadingEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAttachedToWindow, onCheckIsTextEditor, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDetachedFromWindow, onDisplayHint, onDraw, onDrawScrollBars, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onRestoreInstanceState, onSaveInstanceState, onScrollChanged, onSetAlpha, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, onWindowVisibilityChanged, 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, setMeasuredDimension, 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, verifyDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface android.view.ViewParent
createContextMenu, getParent, isLayoutRequested, requestLayout
 

Field Detail

EXTERNAL_TILE_CACHE_SIZE

public static long EXTERNAL_TILE_CACHE_SIZE
Defines the disk space (in KB) for tile cache on the external storage (e.g. sdcard). The default size is 50,000KB. The disk space must be larger than 500KB. The larger the size, generally the better the performance you get.


EXTERNAL_TILE_CACHE_ENABLED

public static boolean EXTERNAL_TILE_CACHE_ENABLED
Enables the external storage for tile caching. It is enabled by default. When set to false, the internal cache will be enabled; however, the internal storage is generally much smaller and therefore can cache less tiles.


EXTERNAL_CACHE_DIR_NAME

public static String EXTERNAL_CACHE_DIR_NAME
Defines the name of the directory for tile caching on the external storage (e.g. sdcard). The default directory name is "ArcGIS".


CONTEXT_TILE_CACHE_SIZE

public static long CONTEXT_TILE_CACHE_SIZE
Defines the disk space (in KB) for tile cache on the internal directory. The default size is 5,000KB. The disk space must be larger than 50KB; The larger the size, generally the better the performance you get.


TILE_FILE_KB_SIZE

public static int TILE_FILE_KB_SIZE
Defines the average size (in KB) of a cached tile. The value is used to calculate the number of tiles to cache. The number of tiles = (EXTERNAL_TILE_CACHE_SIZE / TILE_FILE_KB_SIZE) or ( CONTEXT_TILE_CACHE_SIZE / TILE_FILE_KB_SIZE) The default value is 50 (KB).

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

onChildViewRemoved

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

onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)
Overrides:
onMeasure in class android.view.View

onLayout

protected void onLayout(boolean changed,
                        int l,
                        int t,
                        int r,
                        int b)
Specified by:
onLayout in class android.view.ViewGroup

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.


onSizeChanged

protected void onSizeChanged(int w,
                             int h,
                             int oldw,
                             int oldh)
Overrides:
onSizeChanged in class android.view.View

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.

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.

addLayer

public void addLayer(LayerView<?> layer)
Adds the child LayerView to the parent, MapView.

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

addLayers

public void addLayers(LayerView<?>[] layerArray)
Adds the LayerView array to the parent MapView.

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

addLayer

public void addLayer(LayerView<?> layer,
                     int index)
Adds the child LayerView at the given index supplied in the method call.

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

Additionally, the index is sequential. For instance, if you have 3 layers with index 0, 1, and 2, then you cannot add the next LayerView with an index position of 5. In this case you must supply an index position of 3, which is the next integer in sequence.

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

removeLayer

public void removeLayer(int index)
Removes a child layer at the index position passed into the method. See the addLayer(LayerView, int) method for details on the index.

Parameters:
index - the index position of the LayerView.

removeAll

public void removeAll()
Removes all child views from the MapView map view. This includes all ArcGIS API views along with any Android views (Menu, and so on).


removeLayerById

public void removeLayerById(int resourceId)
Removes a layer by its resource id. The resource id is specified as an attribute, android:id, in the associated layout XML.
 
 map.removeLayerById(R.id.baselayer);
 
 

Parameters:
resourceId - the resource id of the layer specified in the associated layout XML that you, the developer, will specify when defining your XML

getLayerById

public LayerView<?> getLayerById(int resourceId)
Gets a layer by its resource id. Returns null if no layer is found by the given id.


getLayers

public LayerView<?>[] getLayers()
Returns all child LayerViews that are added to the MapView. The LayerView array will be a zero based array, meaning LayerView[0] will give you the first LayerView that is drawn by the MapView.

Returns:
If the MapView has no child LayerViews, then an array with no elements will be returned. A MapView with no children is meaningless, ideally you will have at least one LayerView child.

reorderLayer

public void reorderLayer(int resourceId,
                         int index)
Changes the index position of the layer with the resource id supplied in the method. The resouce id is specified as an attribute, android:id, in the associated layout XML. For example, if you have layers with the following ids and index positions (id0, 0), (id1, 1), (id2, 2), (id3, 3), and (id4, 4) and you want to move the layer, (id3, 3) to index position 1, the resulting ids and index positions would be: (id0, 0), (id3, 1), (id1, 2), (id2, 3), and (id4, 4).

Parameters:
resourceId - the resource id of the layer specified in the associated layout XML.
index - the index position you want to move the layer too.

getExtent

public Envelope getExtent()
Returns an extent representing the maximum extent of data, which is currently visible on the device that is showing the map.

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

setExtent

public void setExtent(Envelope extent)
If the MapView is initialized, then the extent of the map that is displayed on the device will change to the extent that is supplied in this method call.

If you pass in an extent that goes outside the boundaries of the device, then the framework will re-draw the map to fit correctly on the device it is being displayed on.

Note: If you attempt to set an extent that is larger or smaller than what the current extent of the device is, the method will take an additional step to correct the aspect ratio of your new extent, which you can get the adjusted Extent by calling getExtent().

Parameters:
extent - the extent 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.

zoomTo

public void zoomTo(Envelope extent)
Changes the map bounds to the given extent if the MapView is initialized.

Parameters:
extent - the extent must in the same coordinates of the map.

zoomTo

public void zoomTo(Point centerPt,
                   float factor)
If the MapView is initialized, then the extent of the map that is displayed on the device will center itself at the point and re-factor based on the supplied parameters in the method call.

Define the center point using ArcGIS geometry's 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)
If the MapView is initialized, then the centerPt is used to reposition the MapView to make this point the center of the device's display.

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.

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 point on the map .
Returns:
the device screen (x, y).

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.

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.

getOnExtentChangedListener

public OnMapExtentChangedListener getOnExtentChangedListener()
Gets the onExtentChangedListener of the MapView.

Returns:
Returns the onExtentChangedListener.

setOnExtentChangedListener

public void setOnExtentChangedListener(OnMapExtentChangedListener onExtentChangedListener)
Sets the onExtentChangedListener of the MapView.

Parameters:
onExtentChangedListener - The onExtentChangedListener 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 the unique instance of the callout window

Returns:
the callout window


Copyright © 2010. All Rights Reserved.