Creating a graphics layer
In the ArcGIS API for Windows Phone, graphics layers allow you to dynamically display graphics on a Map. A graphics layer could, for example, be used to hold polygons drawn by a user or display features that satisfy a user-defined query. In the image below, a graphics layer is used to show states that have a population density of more than 200 per square mile:
When you create a Windows Phone mapping application, you will usually declare graphics layers in XAML. When specifying graphics layers in this way, you will 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 your application. For more information, see Adding layers.
Adding a graphics layer
To add a graphics layer to your ArcGIS API for Windows Phone application, take the following steps:
- Create an ArcGIS API for Windows Phone application with a Map as described in the topic Creating a map. Your ContentGrid XAML should look as follows:
<Grid x:Name="ContentGrid" 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>
- Add a reference to the System.Runtime.Serialization assembly to your project.
- Inside 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>
- When you declare a GraphicsLayer, you must give it an ID. You will use this ID in your application's .NET code (i.e. code-behind) to get a reference to the layer. The code below assigns the GraphicsLayer an ID of "MyGraphicsLayer."
<esri:GraphicsLayer ID="MyGraphicsLayer"/>