Creating a map

When adding a Map control to your WPF application, your code will always contain the following two parts:

How to create a map with a Local Map document layer

The following steps assume you have created a WPF application in Visual Studio and are working in the XAML view of the main page of your application.

  1. Add a reference to ESRI.ArcGIS.Client.dll and ESRI.ArcGIS.Client.Local.dll in your application.
  2. In XAML, add an Extensible Markup Language (XML) namespace that references the ArcGIS schema.

    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
    

  3. Add the Map control element to a container element in the page. In the following example, the container is a Grid. Use the ESRI.ArcGIS.Client namespace identifier "esri" to define the namespace that contains the Map control. Give the Map control a unique name using the x:Name attribute.

    <Grid x:Name="LayoutRoot" Background="White">        
            <esri:Map x:Name="MyMap" >
            </esri:Map>        
    </Grid>
    

  4. Add a local map document layer to the map. The source property is the ArcGISLocalDynamicMapServiceLayer class, which has a Path property. The supported source is an ArcGIS Map Package (.mpk) that can be authored in ArcMap.

    <esri:Map x:Name="MyMap" >
        <esri:ArcGISLocalDynamicMapServiceLayer ID="Local Data" Path="C:\Data\World.mpk" />
    esri:Map>
    

  5. Define a startup extent for the map. Use attribute syntax to define the Extent property on the map. The attribute value is a comma-delimited set of four numbers specifying the min x, min y, max x, and max y values.

    <esri:Map x:Name="MyMap" Extent="-120, 20, -100, 40" >
    

  6. Compile and run your application.

How to create a map with an ArcGIS for Server hosted layer

The following steps assume you have created a WPF application in Visual Studio and are working in the XAML view of the main page of your application.

  1. Add a reference to ESRI.ArcGIS.Client.dll.
  2. In XAML, add an XML namespace that references the ArcGIS schema for WPF.
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
    
  3. Add the Map control element to a container element in the page. In the following example, the container is a Grid. Use the ESRI.ArcGIS.Client namespace identifier "esri" to define the namespace that contains the Map control. Give the Map control a unique name using the x:Name attribute.

    <Grid x:Name="LayoutRoot" Background="White">        
            <esri:Map x:Name="MyMap" >
            </esri:Map>        
    </Grid>
    

  4. Add an ArcGIS for Server tiled map service layer to the map. The map contains a collection of layers referenced by the Layers property. In XAML, you can modify the contents of the Layers property using property element syntax. This means you can specify the property name as an child element (for example, Map.Layers) and include the appropriate contents. In this case, the appropriate content is an ArcGISTileMapServiceLayer element that enables you to reference an ArcGIS for Server cached map service. Define the uniform resource locator (URL) to the map service endpoint and include a unique ID for the layer.

    TipTip:

    Specifying the Layers property inside the Map tag is optional.

    <esri:Map x:Name="MyMap" >
        <esri:Map.Layers>
             <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
                   Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
        </esri:Map.Layers>
    </esri:Map>
    
  5. Define a startup extent for the map. Use attribute syntax to define the Extent property on the map. The attribute value is a comma-delimited set of four numbers specifying the min x, min y, max x, and max y values.
    <esri:Map x:Name="MyMap" Extent="-120, 20, -100, 40" >
    
  6. Compile and run your application.
1/27/2015