Click or drag to resize
GraphicsOverlay Class
A collection of vector graphics for overlaying on the map
Inheritance Hierarchy

Namespace: Esri.ArcGISRuntime.Controls
Assembly: Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 10.2.7.0 (10.2.7.1234)
Syntax
[ContentPropertyAttribute("Graphics")]
public sealed class GraphicsOverlay : DependencyObject, 
	INotifyPropertyChanged

The GraphicsOverlay type exposes the following members.

Constructors
  NameDescription
Public methodGraphicsOverlay
Initializes a new instance of the GraphicsOverlay class.
Top
Methods
  NameDescription
Public methodCheckAccess
Determines whether the calling thread has access to this DispatcherObject.
(Inherited from DispatcherObject.)
Public methodClearSelection
Unselects all graphics in the layer
Public methodClearValue(DependencyProperty)
Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier.
(Inherited from DependencyObject.)
Public methodClearValue(DependencyPropertyKey)
Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey.
(Inherited from DependencyObject.)
Public methodCoerceValue
Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.
(Inherited from DependencyObject.)
Public methodEquals
Determines whether a provided DependencyObject is equivalent to the current DependencyObject.
(Inherited from DependencyObject.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Gets a hash code for this DependencyObject.
(Inherited from DependencyObject.)
Public methodGetLocalValueEnumerator
Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.
(Inherited from DependencyObject.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetValue
Returns the current effective value of a dependency property on this instance of a DependencyObject.
(Inherited from DependencyObject.)
Public methodHitTestAsync(ViewBase, Point)
Performs a Hit Test against the GraphicsOverlay at the given screen point, relative to the upper left of the map.
Public methodHitTestAsync(ViewBase, Point, Int32)
Performs a Hit Test against the GraphicsOverlay at the given screen point, relative to the upper left of the map.
Public methodHitTestAsync(ViewBase, Rect, Int32)
Performs a Hit Test against the GraphicsOverlay at the given intersecting rectangle, relative to the upper left of the map.
Public methodInvalidateProperty
Re-evaluates the effective value for the specified dependency property
(Inherited from DependencyObject.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnPropertyChanged
Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. The specific dependency property that changed is reported in the event data.
(Inherited from DependencyObject.)
Public methodReadLocalValue
Returns the local value of a dependency property, if it exists.
(Inherited from DependencyObject.)
Public methodSetCurrentValue
Sets the value of a dependency property without changing its value source.
(Inherited from DependencyObject.)
Public methodSetValue(DependencyProperty, Object)
Sets the local value of a dependency property, specified by its dependency property identifier.
(Inherited from DependencyObject.)
Public methodSetValue(DependencyPropertyKey, Object)
Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.
(Inherited from DependencyObject.)
Protected methodShouldSerializeProperty
Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.
(Inherited from DependencyObject.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodVerifyAccess
Enforces that the calling thread has access to this DispatcherObject.
(Inherited from DispatcherObject.)
Top
Fields
  NameDescription
Public fieldStatic memberGraphicsSourceProperty
Identifies the GraphicsSource dependency property.
Public fieldStatic memberIsVisibleProperty
Identifies the IsVisible Dependency Property
Public fieldStatic memberMaxScaleProperty
Identifies the MaxScale Dependency Property
Public fieldStatic memberMinScaleProperty
Identifies the MinScale Dependency Property
Public fieldStatic memberOpacityProperty
Identifies the Opacity Dependency Property
Public fieldStatic memberRendererProperty
Identifies the Renderer Dependency Property
Public fieldStatic memberScenePropertiesProperty
The scene properties dependency property
Public fieldStatic memberSelectionColorProperty
Identifies the SelectionColor Dependency Property
Top
Properties
  NameDescription
Public propertyDependencyObjectType
Gets the DependencyObjectType that wraps the CLR type of this instance. 
(Inherited from DependencyObject.)
Public propertyDispatcher
Gets the Dispatcher this DispatcherObject is associated with.
(Inherited from DispatcherObject.)
Public propertyGraphics
Gets or sets the graphics collection.
Public propertyGraphicsSource
Gets or sets a collection used to contain the graphics of the GraphicsOverlay.
Public propertyID
Gets or sets an ID associated with this overlay.
Public propertyIsSealed
Gets a value that indicates whether this instance is currently sealed (read-only).
(Inherited from DependencyObject.)
Public propertyIsVisible
Gets or sets the overlay visibility.
Public propertyLabeling
Gets or sets the LabelProperties which is used to enable labeling of a GraphicsLayer.
Public propertyMaxScale
Gets or sets the maximum scale to display this layer at. A small number allows the map to display the layer when zooming further in.
Public propertyMinScale
Gets or sets the minimum scale to render this layer at. A large number allows the map to display the layer when zooming further out.
Public propertyOpacity
Gets or sets the opacity. Must be a value between 0 and 1.
Public propertyRenderer
Gets or sets the renderer used for generating symbols.
Public propertyRenderingMode
Gets or sets a value indicating which rendering mode to use
Public propertySceneProperties
Gets or sets the scene properties associated with this overlay.
Public propertySelectedGraphics
Gets the selected graphics.
Public propertySelectionColor
Gets or sets the color for selected graphics.
Top
Events
  NameDescription
Public eventPropertyChanged
Occurs when a property changed.
Top
Remarks

GraphicsOverlays allow you to associate a collection of Graphic elements with the MapView. Graphics have geometry and attributes that are stored in memory, and therefore must be built programmatically and are not persisted. A GraphicsOverlay always displays on top of all layers in the map, but below any map overlay elements. It displays over any Map you put in the map view and will automatically adjust if the spatial reference changes. While able to display more elements than a map overlay, because they are stored in memory graphics overlays are designed to display a moderate number of features that belong more with your application rather than with a particular map. Graphics are best suited for displaying map information that is specific to the current user session or things that need to be displayed temporarily. Showing query results or buffer polygons on the map are examples suited to using a GraphicsOverlay.

NOTE: Because they are not in the map, graphics in overlays will not appear in a map's legend or be displayed when the map is printed.

Examples

Demonstrates using the Query.FindTask operation to return county features in an ArcGIS Server map service and display the features found as Graphics in a GraphicsOverlay. The user can perform a MapViewTapped on the Graphics to perform a GraphicsOverlay.HitTestAsync to select features and display attribute information.

Performing a GraphicsOverlay.HitTestAsync on Graphic in a GraphicsOverlay.

XAML
<Window x:Class="GraphicsOverlay.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="600" Width="800"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">

    <Grid x:Name="LayoutRoot">

        <!-- Create a simple polygon fill renderer with a solid tan fill. The outline of the polygon is black. -->
        <Grid.Resources>
            <esri:SimpleRenderer x:Key="mySimpleRenderer">
                <esri:SimpleRenderer.Symbol>
                    <esri:SimpleFillSymbol Color="BurlyWood"  Style="Solid">
                        <esri:SimpleFillSymbol.Outline>
                            <esri:SimpleLineSymbol Color="Black" Width="1" Style="Solid"/>
                        </esri:SimpleFillSymbol.Outline>
                    </esri:SimpleFillSymbol>
                </esri:SimpleRenderer.Symbol>
            </esri:SimpleRenderer>
        </Grid.Resources>

        <StackPanel x:Name="StackPanel1" Orientation="Vertical">

            <!-- Add a TextBlock to hold the instructions on how to use the sample code. -->
            <TextBlock Height="52" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="782" 
                   TextWrapping="Wrap" />

            <!-- Add a MapView. -->
            <esri:MapView x:Name="MapView1" Height="517" MapViewTapped="MapView1_MapViewTapped">

                <!-- Add a Map. -->
                <esri:Map x:Name="Map1">

                    <!-- Add a backdrop ArcGISTiledMapServiceLayer. -->
                    <esri:ArcGISTiledMapServiceLayer ID="myArcGISTiledMapServiceLayer" 
                      ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer" />

                </esri:Map>

                <!-- Add a MapView.GraphicsOverlays collection. -->
                <esri:MapView.GraphicsOverlays>

                    <!-- Add a GraphicsOverlay to hold Graphics added via code behind from a FindTask operation. Set the Renderer to draw the polygon graphics. -->
                    <esri:GraphicsOverlay Renderer="{StaticResource mySimpleRenderer}"/>

                </esri:MapView.GraphicsOverlays>

            </esri:MapView>
        </StackPanel>

    </Grid>

</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "GraphicsOverlay.MainWindow" to be just "MainWindow".

namespace GraphicsOverlay
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // Add the instructions on how to use this example code to the TextBlock.
            TextBlock1.Text = "When the application loads, a Query.FindTask will occur to obtain the Features for counties in Minnesota. " + 
                "Graphics will be added to a GraphicsOverlay which is displayed on top of the Map. Tap on a county and it will be be selected " + 
                "and attributes for the Graphic will be displayed in a Message Box.";

            // Set the initial extent of the Map to the Minnesota.
            Esri.ArcGISRuntime.Geometry.SpatialReference mySpatialReference = new Esri.ArcGISRuntime.Geometry.SpatialReference(102100);
            Esri.ArcGISRuntime.Geometry.Geometry myGeometry = new Esri.ArcGISRuntime.Geometry.Envelope(-11260915, 5266673, -9622263, 6368165, mySpatialReference);
            MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myGeometry);

            // Call an asynchronous subroutine to initialize obtaining Features from a map service via a Query.FindTask and display the Features
            // in a GraphicsOverlay.
            Init();
        }

        public async void Init()
        {
            // Create a Uri that points to the public ESRI ArcGIS Server map service with the 'Find' operation supported.
            System.Uri myUri = new System.Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer");

            // Create a new FindParamaters which hold the instructions of how the Query.FindTask will operate.
            Esri.ArcGISRuntime.Tasks.Query.FindParameters myFindParameters = new Esri.ArcGISRuntime.Tasks.Query.FindParameters();

            // Set the FindParameters text to search for. This is a mandatory Property that must be set!
            myFindParameters.SearchText = "Minnesota";

            // Define the layers in the ArcGIS Server map service for which the Query.FindTask will execute on. This is a mandatory Property that must be set!
            System.Collections.Generic.List<int> myLayerIds = new System.Collections.Generic.List<int>();
            myLayerIds.Add(3); // We will find records in the Counties layer.
            myFindParameters.LayerIDs = myLayerIds;

            // Define the attribute fields in the layer for which the we will attempt to find the SearchText. If the FindParameters.SearchFields
            // is not specified, then all of the attributes fields in the layer will be searched for the SearchText.
            System.Collections.Generic.List<string> mySearchFields = new System.Collections.Generic.List<string>();
            mySearchFields.Add("state_name");
            myFindParameters.SearchFields = mySearchFields;

            // Create a new FindTask using the ArcGIS Server map service.
            Esri.ArcGISRuntime.Tasks.Query.FindTask myFindTask = new Esri.ArcGISRuntime.Tasks.Query.FindTask(myUri);

            // Perform the Query.FindTask search. 
            Esri.ArcGISRuntime.Tasks.Query.FindResult myFindResult = await myFindTask.ExecuteAsync(myFindParameters);

            // Get the results from the FindResult object.
            System.Collections.Generic.IReadOnlyList<Esri.ArcGISRuntime.Tasks.Query.FindItem> myFindItems = myFindResult.Results;

            // Get the GraphicsOverlay by its index position in the GraphicsOverlays collection.
            Esri.ArcGISRuntime.Controls.GraphicsOverlay myGraphicsOverlay = MapView1.GraphicsOverlays[0];

            // Loop through the records found.
            foreach (Esri.ArcGISRuntime.Tasks.Query.FindItem oneFindItem in myFindItems)
            {
                // Create a new Graphic based on the returned results of the  Query.FindTask search. 
                Esri.ArcGISRuntime.Layers.Graphic myGraphic = new Esri.ArcGISRuntime.Layers.Graphic();
                myGraphic.Geometry = oneFindItem.Feature.Geometry;

                // Get the attributes (i.e. field name and value) for each FindItem (aka. record).
                System.Collections.Generic.IDictionary<string, object> myAttributes = oneFindItem.Feature.Attributes;

                // Add all of the attributes from the Feature to the Graphic.
                foreach (var oneAttribute in myAttributes)
                {
                    myGraphic.Attributes.Add(oneAttribute.Key, oneAttribute.Value);
                }

                // Add the Graphic to the GraphicsOverlay.
                myGraphicsOverlay.Graphics.Add(myGraphic);

                // Note: The symbology of Graphics in the GraphicsOverlay was defined in the XAML.
            }
        }

        private async void MapView1_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e)
        {
            // Get the GraphicsOverlay by its index position in the GraphicsOverlays collection.
            Esri.ArcGISRuntime.Controls.GraphicsOverlay myGraphicsOverlay = MapView1.GraphicsOverlays[0];

            // Clear out any prior selected Graphics in the GraphicsOverlay.
            myGraphicsOverlay.ClearSelection();

            // Get a single Graphic from the GraphicsOverlay based upon a user mouse-click/tap on the MapView.
            Esri.ArcGISRuntime.Layers.Graphic myGraphic = await myGraphicsOverlay.HitTestAsync(MapView1, e.Position);

            // Only select a Graphic and display it's attribute information if we have a valid HitTestAsync result.
            if (myGraphic != null)
            {
                // Select the Graphic in the GraphicsOverlay.
                myGraphic.IsSelected = true;

                // Get the attributes (i.e. field name and value) that were added to the Graphic in the Init subroutine.
                System.Collections.Generic.IDictionary<string, object> myAttributes = myGraphic.Attributes;

                // Create a StringBuilder to hold the attribute field names and values to display to the user.
                System.Text.StringBuilder myStringBuilder = new System.Text.StringBuilder();

                // Add all of the attribute field names and values to the StringBuider.
                foreach (var oneAttribute in myAttributes)
                {
                    myStringBuilder.AppendLine(oneAttribute.Key.ToString() + ": " + oneAttribute.Value.ToString());
                }

                // Display the attributes to the user for the Graphic they selected.
                System.Windows.MessageBox.Show(myStringBuilder.ToString());
            }
        }    

    }
}
See Also
Supported Platforms
This type is supported on the following ArcGIS Runtime .NET SDK platforms:
Windows Desktop
Windows Phone
Windows Store
Additional Examples
Hyperlink to ExampleDescription
GraphicsOverlayDemonstrates using the Query.FindTask operation to return county features in an ArcGIS Server map service and display the features found as Graphics in a GraphicsOverlay. The user can perform a MapViewTapped on the Graphics to perform a GraphicsOverlay.HitTestAsync to select features and display attribute information.