com.esri.android.map
Class GraphicsLayer

java.lang.Object
  extended by android.view.View
      extended by com.esri.android.map.LayerView<LayerModel>
          extended by com.esri.android.map.GraphicsLayer
All Implemented Interfaces:
android.graphics.drawable.Drawable.Callback, android.view.accessibility.AccessibilityEventSource, android.view.KeyEvent.Callback
Direct Known Subclasses:
ArcGISFeatureLayer

public class GraphicsLayer
extends LayerView<LayerModel>

The GraphicsLayer class represents a layer that contains one or more Graphic features. The map can contains one or more graphics layers.

Note: Notice that the GraphicsLayer class, like all concrete layers, inherits directly from Android's View class. Therefore, the GraphicsLayer class inherits all the methods and properties from the View and is very similar to working with other Android View objects.

The following are examples of how you might work with the GraphicsLayer class. There are two approaches you can take when initializing your object, either through a layout's XML or through Java source code.

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.GraphicsLayer  
      android:id="@+id/graphics"/>
 </com.esri.android.map.MapView> 
 
 
Java usage:
 //GraphicsLayer class is used to define the LayerView that is added to the 
 //MapView object.
 MapView mv = new MapView(this);
 mv.addLayer(new GraphicsLayer(this));
 setContentView(mv);
 


Nested Class Summary
 
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
protected  ConcurrentLinkedQueue<Graphic> graphics
          The graphics that make up the layer.
 
Fields inherited from class com.esri.android.map.LayerView
canvasOffsetX, canvasOffsetY, mapView, model
 
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
GraphicsLayer(android.content.Context context)
          The constructor is used if your are instantiating the GraphicsLayer using Java code (see the class description for an example of this usage).
GraphicsLayer(android.content.Context context, android.util.AttributeSet attrs)
          This constructor is called when the GraphicsLayer object is being inflated from XML.
GraphicsLayer(android.content.Context context, android.util.AttributeSet attrs, int defStyle)
          Inflate the GraphicsLayer object from XML and apply a class-specific base style.
GraphicsLayer(android.content.Context context, Renderer<Graphic> renderer, SpatialReference ref, Envelope extent)
          The constructor is used if your are instantiating the GraphicsLayer using Java code (see the class description for an example of another usage).
 
Method Summary
 void addGraphic(Graphic graphic)
          Adds a graphic element to the layer.
 void addGraphics(Collection<Graphic> array)
          Adds a graphic collection to the layer.
 void addGraphics(Graphic[] array)
          Adds a graphic array to the layer.
 void clear()
          Removes all graphics from the layer.
 boolean contains(Collection<Graphic> array)
          Returns true if the layer contains all of the given graphics.
 boolean contains(Graphic graphic)
          Returns true if the layer contains the given graphic.
 SpatialReference getDefaultSpatialReference()
          If the LayerView is associated with a LayerModel, then the default spatial coordinate system of the layer model is returned.
 Graphic[] getGraphics()
          Returns all the graphics on the layer.
 Graphic[] getGraphics(float x, float y, int tolerance)
           
 Renderer<Graphic> getRenderer()
          Returns the renderer of this layer.
protected  LayerModel initModel()
          This method will instantiate the LayerModel object.
protected  void onDraw(android.graphics.Canvas canvas)
           
 void removeGraphic(Graphic graphic)
          Removes a graphic element from the layer.
 void removeGraphics(Collection<Graphic> array)
          Removes a set of graphic elements from the layer.
 void setRenderer(Renderer<Graphic> renderer)
          Sets the renderer of this layer.
 float toMapUnit(double screen)
          Converts the point from the screen coordinates to the current MapView coordinates.
protected  void update()
          Updates the MapView with images that are retrieved from the LayerView's associated LayerModel object.
 
Methods inherited from class com.esri.android.map.LayerView
cancelPendingTasks, clearCache, getCenter, getExtent, getFullExtent, getModel, getOffset, getOnStatusChangedListener, getResolution, getSpatialReference, getUrl, getUrlHashCode, initLayer, isInitialized, isLongLifeCache, onAnimationEnd, onAnimationStart, onSizeChanged, setLongLifeCache, setOffset, setOnStatusChangedListener, setUrl, toMapPoint, toMapPoint, toScreenPoint, toScreenPoint
 
Methods inherited from class android.view.View
addFocusables, addFocusables, addTouchables, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, cancelLongPress, checkInputConnectionProxy, clearAnimation, clearFocus, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, destroyDrawingCache, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDraw, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetPressed, dispatchSetSelected, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, draw, drawableStateChanged, findFocus, findViewById, findViewWithTag, fitSystemWindows, 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, hasFocus, hasFocusable, 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, onCreateDrawableState, onCreateInputConnection, onDetachedFromWindow, onDisplayHint, onDrawScrollBars, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onLayout, onMeasure, 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, 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, setPadding, 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
 

Field Detail

graphics

protected final ConcurrentLinkedQueue<Graphic> graphics
The graphics that make up the layer.

Constructor Detail

GraphicsLayer

public GraphicsLayer(android.content.Context context,
                     android.util.AttributeSet attrs,
                     int defStyle)
Inflate the GraphicsLayer object from XML and apply a class-specific base style. This constructor of the GraphicsLayer allows subclasses to use their own base style when they are being inflated.

This constructor assumes you have another layer as the bottom most layer defined for the MapView. In this instance the GraphicsLayer cannot be the bottom most layer.

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 GraphicsLayer.
defStyle - the 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.

GraphicsLayer

public GraphicsLayer(android.content.Context context,
                     android.util.AttributeSet attrs)
This constructor is called when the GraphicsLayer 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.

This constructor assumes you have another layer as the bottom most layer defined for the MapView. In this instance the GraphicsLayer cannot be the bottom most layer.

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

GraphicsLayer

public GraphicsLayer(android.content.Context context)
The constructor is used if your are instantiating the GraphicsLayer using Java code (see the class description for an example of this usage).

This constructor assumes you have another layer as the bottom most layer defined for the MapView. In this instance the GraphicsLayer cannot be the bottom most layer.

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

GraphicsLayer

public GraphicsLayer(android.content.Context context,
                     Renderer<Graphic> renderer,
                     SpatialReference ref,
                     Envelope extent)
The constructor is used if your are instantiating the GraphicsLayer using Java code (see the class description for an example of another usage). This constructor should only be used if you need to add the GraphicsLayer as your bottom layer of the MapView.

Parameters:
context - The Context the view is running in, through which it can access the current theme, resources, and so on.
renderer - The renderer allows for the symbol of the graphic to be dynamically picked - for example based on attributes or position of the graphic, or based on the scale of the map, or anything else.
ref - the spatial reference of the layer. It must not be null when added as the bottom layer of the MapView.
extent - the full extent of the graphics layer, It must not be null when added as the bottom layer of the MapView.
Method Detail

getDefaultSpatialReference

public SpatialReference getDefaultSpatialReference()
Description copied from class: LayerView
If the LayerView is associated with a LayerModel, then the default spatial coordinate system of the layer model is returned.

Overrides:
getDefaultSpatialReference in class LayerView<LayerModel>

initModel

protected LayerModel initModel()
                        throws Exception
Description copied from class: LayerView
This method will instantiate the LayerModel object.

In a Model-View-Controller architecture, the LayerView represents the View and handles the image rendering related functionality. Each View has an associated Model object that handles fetching map images, calculating map bounds, and so on.

Any class that extends the LayerView class should provide an implementation of a LayerModel class and instantiate that model in this method.

Specified by:
initModel in class LayerView<LayerModel>
Returns:
the LayerModel instance associated with this LayerView.
Throws:
Exception

update

protected void update()
Description copied from class: LayerView
Updates the MapView with images that are retrieved from the LayerView's associated LayerModel object. This method is called when the MapView's extent is changed.

Any class that extends the LayerView class should provide an implementation of this method to retrieve updated an updated map from the map service. The TiledLayer and DynamicLayer subclasses provide default implementation for cached and dynamic map services. If you DO NOT need to support other types of map services, then you should not override this default functionality (it will save you a lot of unnecessary development effort).

Specified by:
update in class LayerView<LayerModel>

onDraw

protected void onDraw(android.graphics.Canvas canvas)
Overrides:
onDraw in class LayerView<LayerModel>

toMapUnit

public float toMapUnit(double screen)
Converts the point from the screen coordinates to the current MapView coordinates.

Parameters:
screen - the distance given in screen coordinates.
Returns:
the distance in map coordinates.

getRenderer

public Renderer<Graphic> getRenderer()
Returns the renderer of this layer. The renderer allows for the symbol of the graphic to be dynamically picked - for example based on attributes or position of the graphic, or based on the scale of the map, or anything else.

Returns:
the renderer or null if not specified.

setRenderer

public void setRenderer(Renderer<Graphic> renderer)
Sets the renderer of this layer. The renderer allows for the symbol of the graphic to be dynamically picked - for example based on attributes or position of the graphic, or based on the scale of the map, or anything else.


addGraphic

public void addGraphic(Graphic graphic)
Adds a graphic element to the layer.


addGraphics

public void addGraphics(Collection<Graphic> array)
Adds a graphic collection to the layer.


addGraphics

public void addGraphics(Graphic[] array)
Adds a graphic array to the layer.


removeGraphic

public void removeGraphic(Graphic graphic)
Removes a graphic element from the layer.


removeGraphics

public void removeGraphics(Collection<Graphic> array)
Removes a set of graphic elements from the layer.


clear

public void clear()
Removes all graphics from the layer.


contains

public boolean contains(Collection<Graphic> array)
Returns true if the layer contains all of the given graphics.


contains

public boolean contains(Graphic graphic)
Returns true if the layer contains the given graphic.


getGraphics

public Graphic[] getGraphics()
Returns all the graphics on the layer.


getGraphics

public Graphic[] getGraphics(float x,
                             float y,
                             int tolerance)


Copyright © 2010. All Rights Reserved.