Creating a graphics layer

In the ArcGIS Runtime SDK for Windows Phone, graphics layers allow you to dynamically display graphics on a map. A graphics layer can, for example, be used to hold polygons drawn by a user or display features that satisfy a user-defined query. In the following image, a graphics layer is used to show states that have a population density of more than 200 per square mile:

Graphics layer

When you create a Windows Phone mapping application, you'll usually declare graphics layers in XAML. When specifying graphics layers in this way, you'll add a GraphicsLayer element inside a Map element. Be sure to specify the graphics layer below any base layers so that the graphics will display above those layers when you run the application. For more information, see Adding layers.

Adding a graphics layer

To add a graphics layer to your ArcGIS Runtime SDK for Windows Phone application, take the following steps:

  1. Create an ArcGIS Runtime SDK for Windows Phone application with a map as described in Creating a map. Your ContentPanel XAML should look as follows:
    <Grid x:Name="ContentPanel" Grid.Row="1">
        <esri:Map x:Name="MyMap" Extent="-120, 20, -100, 40">
            <esri:Map.Layers>
                <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                    Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer">
                </esri:ArcGISTiledMapServiceLayer>
            </esri:Map.Layers>
        </esri:Map>
    </Grid>
    
  2. Add a reference to the System.Runtime.Serialization assembly to your project.
  3. In the map's XAML element, declare a GraphicsLayer. Be sure to put it below the map service layer.
    <esri:Map x:Name="MyMap" Extent="-120, 20, -100, 40">
            <esri:Map.Layers>
                <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                    Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer">
                </esri:ArcGISTiledMapServiceLayer>
                <esri:GraphicsLayer />
            </esri:Map.Layers>
        </esri:Map>
    
  4. When you declare a graphics layer, you must give it an ID. You'll use this ID in your application's .NET code (that is, code-behind) to get a reference to the layer. The following code assigns the GraphicsLayer an ID of MyGraphicsLayer:
    <esri:GraphicsLayer ID="MyGraphicsLayer"/>
    
6/21/2013