ArcGIS API for Silverlight - Library Reference
Document Class
Members  Example  See Also  Send comments on this topic
ESRI.ArcGIS.Client.WebMap Namespace : Document Class

Class for generating a map based on the ArcGIS Geowarehouse web map document.

Object Model

Document Class

Syntax

Visual Basic (Declaration) 
Public NotInheritable Class Document 
C# 
public sealed class Document 

Remarks

General Remarks

The WebMap.Document class uses an asynchronous programming model to get web map documents from ArcGIS Online or an ArcGIS Portal server. Details the components of a web map document can be found in the concepts document Introduction to web maps.

Use the WebMap.Document.GetMapAsync(String,Object) Method to obtain web map documents when you know the ItemID string (looks like a GUID) that was created in ArcGIS Online or ArcGIS Portal.

The WebMap.Document.GetMapCompleted Event is fired as a result of the using the WebMap.Document.GetMapAsync(String,Object) Method. Use the return parameter WebMap.GetMapCompletedEventArgs in the WebMap.Document.GetMapCompleted Event to obtain Map, WebMap, SpatialReference and other information useful for displaying and interrogating in your client application.

NOTE: If it is desired to add Layers from the returned web map document in the WebMap.Document.GetMapCompleted into an existing Map Contol in you client application, do not forget to clear out all of the Layers in the WebMap.Document.GetMapCompleted.Map.Layers collection before attempting to add Layers to the Map Control in the application. A Layer can only be added to a single Map object! Because a Map object is returned from the web map document via the GeMapCompletedEventArgs parameter, you already have the Layers in that Map. You must clear out all of the Layers in the web map document so that the Layers can be added to the Map Control your the application or else an exception error will be thrown.

Editable FeatureLayers in web map documents

Starting with ArcGIS Online and ArcGIS Portal version 1.7, it is possible to enable and disable the editing of individual operational FeatureLayers (see the conceptual document Disable editing. This new functionality in web maps can override the behavior of a FeatureLayer that had editing capabilities specifically enabled in ArcGIS Server. In other words, the base FeatureLayer that has editing enabled by default in ArcGIS Server can be overridden so that editing is disabled when within a web map. The following section provides an example with a more in-depth discussion on the subject:

Assume that a FeatureLayer in ArcGIS Server had the following Url: http://sampleserver6.arcgisonline.com/arcgis/rest/services/Military/FeatureServer/2. When you scroll to the bottom of the ArcGIS REST Services Directory page you will see that editing Capabilities have been enabled (Create, Delete, Update, Uploads, and Editing); additionally the Capabilities of Query is enabled as well. See the following screen shot:

Reviewing the 'Capabilities' of a FeatureLayer.

Now imagine that you are authoring a web map document (in ArcGIS Online or ArcGIS Portal) that contains this editable FeatureLayer. You can override the behavior of the operational FeatureLayer in the web map document to disable editing by clicking on arrow button next to the FeatureLayer name and then click Disable Editing in the context menus. See the following screen shot:

Turning off editing of an operational FeatureLayer in ArcGIS Online or ArcGIS Portal.

You can verify that the editing capabilities have been removed for the operational FeatureLayer in the web map document by issuing the following Url syntax in the address bar of a web browser: http://www.MyArcGISPortal.com/sharing/content/items/15f150f6cced4311bfaefab29a413bbc/data?f=pjson (NOTE: this is a fictitious example Url; you would need to create your own web map in ArcGIS Online or ArcGIS Portal), which will result in the following JSON text in the screen shot:

Looking at the 'Capabilities' of an operational Featurelayer in a web map's JSON.

Note: Notice how for the operational FeatureLayer in the JSON text of the web map document that only the capability of 'Query' has been preserved.

Conversely, if you are authoring a web map document (in ArcGIS Online or ArcGIS Portal) that contains the same editable FeatureLayer, you can keep the default behavior of the operational FeatureLayer in the web map document to enable editing by clicking on arrow button next to the FeatureLayer name and then click Enable Editing in the context menus. See the following screen shot:

Turning on editing of an operational FeatureLayer in ArcGIS Online or ArcGIS Portal.

And you can verify that the editing capabilities remain for the FeatureLayer in the web map document by issuing the same Url syntax in the address bar of a web browser: http://devext.arcgis.com/sharing/content/items/15f150f6cced4311bfaefab29a413bbc/data?f=pjson (NOTE: this is a fictitious example Url; you would need to create your own web map in ArcGIS Online or ArcGIS Portal), which will result in JSON text similar to the following screen shot:

Looking at the 'Capabilities' of an operational Featurelayer in a web map's JSON.

NOTE: Notice that because editing has been enabled for the operational FeatureLayer in the web map (which is the default behavior for the FeatureLayer in ArcGIS Server), that Capabilities section is NOT displayed in the JSON syntax for the FeatureLayer. This means that the full default behavior of the FeatureLayer passes through in the web map (meaning full editing capabilities are enabled + Query).

Of course, as a developer you can also use the programmatic Property of FeatureLayer.IsReadOnly to determine if the operational FeatureLayer is editable. You can obtain valid results from the FeatureLayer.IsReadOnly Property in the FeatureLayer.Initialized Event or anytime after this Event fires. One common programming practice is to dynamically wire-up the FeatureLayer.Initialzied Event when cycling through the Map.Layers Property in the WebMap.GetMapCompletedEventArgs parameter of the WebMap.Document.GetMapCompleted Event.

For a more granular interrogation of the editable characteristics of an individual Graphic in the operational FeatureLayer, you could use the FeatureLayer.Graphics Property to get a GraphicCollection to find a particular Graphic and then determine its atomic level editable characteristics using FeatureLayer Methods like:

NOTE: You cannot access Graphics from the operational FeatureLayer returned from a web map document until the operational FeatureLayer.UpdateCompleted Event has fired. Remember that the FeatureLayer.UpdateCompleted Event occurs after the operational FeatureLayer.Initialized Event occurs.

See the code example in this document for an example of programatically discovering the capabilities of an operational FeatureLayer in a web map document.

Example

How to use:

Use ArcGIS Online or ArcGIS Portal to create a web map document that contains and operational FeatureLayer. Experiment by creating one web map document with an operational FeatureLayer that has editing enabled and another web map document with an operational FeatureLayer that does NOT have editing enabled. Copy the web map ID into the textbox and click the button to see the results in the textbox. If the web map has an operational FeatureLayer that is editable, additonal functionlaity is added so that the user can click on Graphics in the returned operational FeatureLayer to obtain more details on the editing abilities.

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Interrogating an operational FeatureLayer in a web map to determine whether it is editable.

XAMLCopy Code
<Grid x:Name="LayoutRoot" >
  
  <!-- Add a Map Control to the application. -->
  <esri:Map x:Name="Map1" WrapAround="True" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,238,0,0" Height="350" Width="415" />
  
  <!-- 
  Have the user enter a web map document ID with an operational FeatureLayer for testing.
  IMPORTANT: The web map document ID supplied in this example is fictitious. You will need to create your own web map 
  document using ArcGIS Online or ArcGIS Portal and copy the ID in the TextBox_WebMapID.Text Property!
  -->
  <sdk:Label Height="20" HorizontalAlignment="Left" Margin="0,214,0,0" Name="Label1" VerticalAlignment="Top" Width="120" 
  Content="Enter a web map ID:"/>
  <TextBox Height="23" HorizontalAlignment="Left" Margin="121,209,0,0" Name="TextBox_WebMapID" VerticalAlignment="Top" Width="294"
  Text="2c9171b7bddd4c999778df8e19cdc525" />
  
  <!-- 
  Add a Button that will allow retrieve the web map document and display it in the Map1 Control. The Click Event is wired-up 
  for code-behind. 
  -->
  <Button Name="Button1" Height="23" HorizontalAlignment="Left" Margin="421,209,0,0"  VerticalAlignment="Top" Width="285" 
  Content="Add a WebMap with an operational FeatureLayer" Click="Button1_Click" />
  
  <!-- TextBox to display information about the operational FeatureLayers added to the Map. -->
  <TextBox Height="350" HorizontalAlignment="Left" Margin="421,238,0,0" Name="TextBox1" VerticalAlignment="Top" Width="285" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="132" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="788" TextWrapping="Wrap" 
   Text="Use ArcGIS Online or ArcGIS Portal to create a web map document that contains and operational FeatureLayer. Experiment 
   by creating one web map document with an operational FeatureLayer that has editing enabled and another web map document 
   with an operational FeatureLayer that does NOT have editing enabled. Copy the web map ID into the textbox and click 
   the button to see the results in the textbox. If the web map has an operational FeatureLayer that is editable, additonal 
   functionlaity is added so that the user can click on Graphics in the returned operational FeatureLayer to obtain more 
   details on the editing abilities." />
  
</Grid>
C#Copy Code
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Create a new WebMap.Document.
  ESRI.ArcGIS.Client.WebMap.Document myWebMap = new ESRI.ArcGIS.Client.WebMap.Document();
  
  // If you are NOT using Esri's public ArcGIS Online services to host your web map document and you have your own 
  // ArcGIS Portal server, then uncomment the next line of code and enter the correct WebMap.Document.ServerBaseUrl.
  //myWebMap.ServerBaseUrl = "http://www.MyArcGISPortal.com/sharing/rest/content"; 
  
  // Wire up the WebMap.Document.GetMapCompleted Event handler. 
  myWebMap.GetMapCompleted += myWebMap_GetMapCompleted;
  
  // Call the WebMap.Document.GetMapAsync Method (using the web map ID as the input parameter) which will cause an
  // Asynchronous call to an ArcGIS Online/Portal server and return the results in the WebMap.Document.GeMapCompleted Event.
  myWebMap.GetMapAsync(TextBox_WebMapID.Text);
}
            
private void myWebMap_GetMapCompleted(object sender, ESRI.ArcGIS.Client.WebMap.GetMapCompletedEventArgs e)
{
  if (e.Error == null)
  {
    // No Error occurred in processing the web map document.
    
    // Set the Map.Extent to the GeMapCompletedEventArgs.Map.Extent from the returned web map document. 
    Map1.Extent = e.Map.Extent;
    
    // Create a new LayerCollection object.
    ESRI.ArcGIS.Client.LayerCollection myLayerCollection = new ESRI.ArcGIS.Client.LayerCollection();
    
    // Loop through all of the Layer's in the GeMapCompletedEventArgs.Map.Layers from the returned web map document.
    foreach (ESRI.ArcGIS.Client.Layer layer in e.Map.Layers)
    {
      // In this code example we particularly interested in operational FeatureLayers that are in the web map document.
      if (layer is ESRI.ArcGIS.Client.FeatureLayer)
      {
        // Get the operational FeatureLayer from the LayerCollection.
        ESRI.ArcGIS.Client.FeatureLayer myOperationalFeatureLayer = layer as ESRI.ArcGIS.Client.FeatureLayer;
        
        // Just in case there are any MapTips defined, set them to Nothing/null. This will avoid the MapTip from appearing
        // when we are trying to do a left mouse button down click on a Graphic to get more information about it's 
        // editable capabilities.
        myOperationalFeatureLayer.MapTip = null;
        
        // Wire up the operational FeatureLayer.Initialized Event.
        myOperationalFeatureLayer.Initialized += myFeatureLayer_Initialized;
      }
      // Add the Layer to the LayerCollection (can be any type; not just an operational FeatureLayer) .
      myLayerCollection.Add(layer);
    }
    // IMPORTANT: A Layer can only be added to a single Map object! Because a Map object is returned from the web map document 
    // via the GeMapCompletedEventArgs parameter, we already have the desired Layers in that Map. We need to clear out all of 
    // the Layers in the web map document so that the Layers can be added to the Map1 Control that was defined in XAML.
    e.Map.Layers.Clear();
    
    // Set the Map.Layers Property to that of what was returned from the web map document.
    Map1.Layers = myLayerCollection;
  }
  else
  {
    // There was a problem with the web map document. Display the error message to the user.
    MessageBox.Show(e.Error.ToString());
  }
}
            
private void myFeatureLayer_Initialized(object sender, EventArgs e)
{
  // Get the operational FeatureLayer from the FeatureLayer.Initialized sender parameter.
  ESRI.ArcGIS.Client.FeatureLayer myOperationalFeatureLayer = (ESRI.ArcGIS.Client.FeatureLayer)sender;
  
  // Determine if we have any editable operational FeatureLayer.
  bool myFeatureLayerIsReadOnly = myOperationalFeatureLayer.IsReadOnly;
  
  // Create a new StringBuilder container.
  System.Text.StringBuilder returnString = new System.Text.StringBuilder();
  
  // Add information to the user about the editablity of the operational FeatureLayer to the StringBuilder object.
  returnString.Append("The operational FeatureLayer" + Environment.NewLine);
  returnString.Append(myOperationalFeatureLayer.DisplayName + " IsReadOnly: " + myFeatureLayerIsReadOnly.ToString() + Environment.NewLine);
  
  if (myFeatureLayerIsReadOnly == false)
  {
    // We have an operational FeatureLayer that has editing capabilities enabled.
    
    // Wire up the operational FeatureLayer.MouseLeftButtonDown Event handler so that we can click on Graphics in the 
    // operational FeatureLayer to find out more information on exactly what editable properties are available.
    myOperationalFeatureLayer.MouseLeftButtonDown += myOperationalFeatureLayer_MouseLeftButtonDown;
    
    // Inform the user that they can click with the mouse cursor on a Graphic to get more details. 
    returnString.Append("Click on a Graphic to see more details." + Environment.NewLine);
  }
  // Display information about the operational FeatureLayer to the user.
  TextBox1.Text = TextBox1.Text + Environment.NewLine + returnString.ToString();
}
            
private void myOperationalFeatureLayer_MouseLeftButtonDown(object sender, ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs e)
{
  // Get the operational FeatureLayer from the FeatureLayer.MouseLeftButtonDown sender parameter.
  ESRI.ArcGIS.Client.FeatureLayer myOperationalFeatureLayer = (ESRI.ArcGIS.Client.FeatureLayer)sender;
  
  // Get a specific Graphic from the operational FeatureLayer.MouseLeftButtonDown e parameter.
  ESRI.ArcGIS.Client.Graphic myGraphic = e.Graphic;
  
  // Create a new StringBuilder container.
  System.Text.StringBuilder returnString = new System.Text.StringBuilder();
  
  // Add information to the user about the editablity of the user clicked Graphic in the operational FeatureLayer to the StringBuilder object.
  returnString.Append("Graphic.IsAttachmentAllowed: " + myOperationalFeatureLayer.IsAddAttachmentAllowed(myGraphic).ToString() + Environment.NewLine);
  returnString.Append("Graphic.IsDeleteAllowed: " + myOperationalFeatureLayer.IsDeleteAllowed(myGraphic).ToString() + Environment.NewLine);
  returnString.Append("Graphic.IsDeleteAttachmentAllowed: " + myOperationalFeatureLayer.IsDeleteAttachmentAllowed(myGraphic).ToString() + Environment.NewLine);
  returnString.Append("Graphic.IsGeometryUpdateAllowed: " + myOperationalFeatureLayer.IsGeometryUpdateAllowed(myGraphic).ToString() + Environment.NewLine);
  returnString.Append("Graphic.IsUpdateAllowed: " + myOperationalFeatureLayer.IsUpdateAllowed(myGraphic).ToString() + Environment.NewLine);
  
  // Display information about the user clicked Graphic in the operational FeatureLayer to the user.
  TextBox1.Text = TextBox1.Text + Environment.NewLine + returnString.ToString();
}
VB.NETCopy Code
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Create a new WebMap.Document.
  Dim myWebMap As ESRI.ArcGIS.Client.WebMap.Document = New ESRI.ArcGIS.Client.WebMap.Document
  
  ' If you are NOT using Esri's public ArcGIS Online services to host your web map document and you have your own 
  ' ArcGIS Portal server, then uncomment the next line of code and enter the correct WebMap.Document.ServerBaseUrl.
  'myWebMap.ServerBaseUrl = "http://www.MyArcGISPortal.com/sharing/rest/content" 
  
  ' Wire up the WebMap.Document.GetMapCompleted Event handler. 
  AddHandler myWebMap.GetMapCompleted, AddressOf myWebMap_GetMapCompleted
  
  ' Call the WebMap.Document.GetMapAsync Method (using the web map ID as the input parameter) which will cause an
  ' Asynchronous call to an ArcGIS Online/Portal server and return the results in the WebMap.Document.GeMapCompleted Event.
  myWebMap.GetMapAsync(TextBox_WebMapID.Text)
  
End Sub
            
Private Sub myWebMap_GetMapCompleted(sender As Object, e As ESRI.ArcGIS.Client.WebMap.GetMapCompletedEventArgs)
  
  If e.Error Is Nothing Then
    
    ' No Error occurred in processing the web map document.
    
    ' Set the Map.Extent to the GeMapCompletedEventArgs.Map.Extent from the returned web map document. 
    Map1.Extent = e.Map.Extent
    
    ' Create a new LayerCollection object.
    Dim myLayerCollection As ESRI.ArcGIS.Client.LayerCollection = New ESRI.ArcGIS.Client.LayerCollection()
    
    ' Loop through all of the Layer's in the GeMapCompletedEventArgs.Map.Layers from the returned web map document.
    For Each layer As ESRI.ArcGIS.Client.Layer In e.Map.Layers
      
      ' In this code example we particularly interested in operational FeatureLayers that are in the web map document.
      If TypeOf layer Is ESRI.ArcGIS.Client.FeatureLayer Then
        
        ' Get the operational FeatureLayer from the LayerCollection.
        Dim myOperationalFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = TryCast(layer, ESRI.ArcGIS.Client.FeatureLayer)
        
        ' Just in case there are any MapTips defined, set them to Nothing/null. This will avoid the MapTip from appearing
        ' when we are trying to do a left mouse button down click on a Graphic to get more information about it's 
        ' editable capabilities.
        myOperationalFeatureLayer.MapTip = Nothing
        
        ' Wire up the operational FeatureLayer.Initialized Event.
        AddHandler myOperationalFeatureLayer.Initialized, AddressOf myFeatureLayer_Initialized
        
      End If
      
      ' Add the Layer to the LayerCollection (can be any type; not just an operational FeatureLayer) .
      myLayerCollection.Add(layer)
      
    Next layer
    
    ' IMPORTANT: A Layer can only be added to a single Map object! Because a Map object is returned from the web map document 
    ' via the GeMapCompletedEventArgs parameter, we already have the desired Layers in that Map. We need to clear out all of 
    ' the Layers in the web map document so that the Layers can be added to the Map1 Control that was defined in XAML.
    e.Map.Layers.Clear()
    
    ' Set the Map.Layers Property to that of what was returned from the web map document.
    Map1.Layers = myLayerCollection
    
  Else
    
    ' There was a problem with the web map document. Display the error message to the user.
    MessageBox.Show(e.Error.ToString)
    
  End If
  
End Sub
            
Private Sub myFeatureLayer_Initialized(sender As Object, e As EventArgs)
  
  ' Get the operational FeatureLayer from the FeatureLayer.Initialized sender parameter.
  Dim myOperationalFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = sender
  
  ' Determine if we have any editable operational FeatureLayer.
  Dim myFeatureLayerIsReadOnly As Boolean = myOperationalFeatureLayer.IsReadOnly
  
  ' Create a new StringBuilder container.
  Dim returnString As New System.Text.StringBuilder
  
  ' Add information to the user about the editablity of the operational FeatureLayer to the StringBuilder object.
  returnString.Append("The operational FeatureLayer" + vbCrLf)
  returnString.Append(myOperationalFeatureLayer.DisplayName + " IsReadOnly: " + myFeatureLayerIsReadOnly.ToString + vbCrLf)
  
  If myFeatureLayerIsReadOnly = False Then
    
    ' We have an operational FeatureLayer that has editing capabilities enabled.
    
    ' Wire up the operational FeatureLayer.MouseLeftButtonDown Event handler so that we can click on Graphics in the 
    ' operational FeatureLayer to find out more information on exactly what editable properties are available.
    AddHandler myOperationalFeatureLayer.MouseLeftButtonDown, AddressOf myOperationalFeatureLayer_MouseLeftButtonDown
    
    ' Inform the user that they can click with the mouse cursor on a Graphic to get more details. 
    returnString.Append("Click on a Graphic to see more details." + vbCrLf)
    
  End If
  
  ' Display information about the operational FeatureLayer to the user.
  TextBox1.Text = TextBox1.Text + vbCrLf + returnString.ToString
  
End Sub
            
Private Sub myOperationalFeatureLayer_MouseLeftButtonDown(sender As Object, e As ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs)
  
  ' Get the operational FeatureLayer from the FeatureLayer.MouseLeftButtonDown sender parameter.
  Dim myOperationalFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = sender
  
  ' Get a specific Graphic from the operational FeatureLayer.MouseLeftButtonDown e parameter.
  Dim myGraphic As ESRI.ArcGIS.Client.Graphic = e.Graphic
  
  ' Create a new StringBuilder container.
  Dim returnString As New System.Text.StringBuilder
  
  ' Add information to the user about the editablity of the user clicked Graphic in the operational FeatureLayer to the StringBuilder object.
  returnString.Append("Graphic.IsAttachmentAllowed: " + myOperationalFeatureLayer.IsAddAttachmentAllowed(myGraphic).ToString + vbCrLf)
  returnString.Append("Graphic.IsDeleteAllowed: " + myOperationalFeatureLayer.IsDeleteAllowed(myGraphic).ToString + vbCrLf)
  returnString.Append("Graphic.IsDeleteAttachmentAllowed: " + myOperationalFeatureLayer.IsDeleteAttachmentAllowed(myGraphic).ToString + vbCrLf)
  returnString.Append("Graphic.IsGeometryUpdateAllowed: " + myOperationalFeatureLayer.IsGeometryUpdateAllowed(myGraphic).ToString + vbCrLf)
  returnString.Append("Graphic.IsUpdateAllowed: " + myOperationalFeatureLayer.IsUpdateAllowed(myGraphic).ToString + vbCrLf)
  
  ' Display information about the user clicked Graphic in the operational FeatureLayer to the user.
  TextBox1.Text = TextBox1.Text + vbCrLf + returnString.ToString
  
End Sub

Inheritance Hierarchy

System.Object
   ESRI.ArcGIS.Client.WebMap.Document

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

© ESRI, Inc. All Rights Reserved.