Visual Basic (Declaration) | |
---|---|
Public ReadOnly Property Items As ObservableCollection(Of IAttribution) |
C# | |
---|---|
public ObservableCollection<IAttribution> Items {get;} |
How to use:
By default three Layers have been added to the Map Control and the Copyright information for those Layers are displayed in the Attribution Control. Click the 'Interrogate Attribution.Items' button to loop through the ObservableCollection(Of IAttribution) object obtained by the Attribution.Items Property to display various information about items in the Control.
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.
XAML | Copy Code |
---|---|
<Grid x:Name="LayoutRoot"> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="65" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="626" TextWrapping="Wrap" Margin="2,2,0,0" Text="By default three Layers have been added to the Map Control and the CopyrightText information for those Layers are displayed in the Attribution Control. Click the 'Interrogate Attribution.Items' button to loop through the ObservableCollection(Of IAttribution) object obtained by the Attribution.Items Property to display various information about items in the Control." /> <!-- Add a Map Control zoomed to a specific Extent. --> <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,105,0,0" Name="Map1" VerticalAlignment="Top" Height="303" Width="600" Extent="-10723833,4627392,-10704398,4644168"> <!-- Add an ArcGISTiledMapServiceLayer. Note: since an ID value is specified the design-time will list the Layer ID in Attribution Control placeholder (Ex: World Imagery attribution.). --> <esri:ArcGISTiledMapServiceLayer ID="World Imagery" Url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/> <!-- Add an ArcGISDynamicMapServiceLayer. Note: since an ID value is specified the design-time will list the Layer ID in Attribution Control placeholder (Ex: World Transportation attribution.). --> <esri:ArcGISDynamicMapServiceLayer ID="World Transportation" Url="http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer" /> <!-- Add a FeatureLayer. Note: since an ID value is specified the design-time will list the Layer ID in Attribution Control placeholder (Ex: Local Rivers attribution.). --> <esri:FeatureLayer ID="Local Rivers" Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/1" AutoSave="False" DisableClientCaching="True" OutFields="*" Mode="OnDemand" /> </esri:Map> <!-- Add an Attribution Control and Bind the Map.Layers to the Attribution.Layers. Change a few visual appearance settings related to the Font for the text that is displayed in the Control. --> <esri:Attribution HorizontalAlignment="Left" VerticalAlignment="Top" Margin="12,420,0,0" Name="Attribution1" Layers="{Binding ElementName=Map1,Path=Layers}" Width="600" Height="48" FontSize="12" FontFamily="Courier New" Foreground="Green" /> <!-- Add a button to dynamically interrogate each IAttribution object in the ObservableCollection using the Attribution.Items Property. Note the Click event handler is wired up to use code-behind. --> <Button Content="Interrogate Attribution.Items" Height="23" HorizontalAlignment="Left" Margin="12,76,0,0" Name="Button_Interrogate_AttributeItems" VerticalAlignment="Top" Width="600" Click="Button_Interrogate_AttributeItems_Click"/> </Grid> |
C# | Copy Code |
---|---|
private void Button_Interrogate_AttributeItems_Click(object sender, System.Windows.RoutedEventArgs e) { // This function loops through all of the ObservabaleCollection<IAttribution> items of the Attribution // Control to display various information in a MessageBox. // Get the ObservabaleCollection<IAttribution> object. Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.IAttribution> theObservableCollectionOfIAttribution = null; theObservableCollectionOfIAttribution = Attribution1.Items; // Get the count of the number of items in the ObservabaleCollection<IAttribution>. int theCount = theObservableCollectionOfIAttribution.Count; // Define a StringBuilder to display information back to the user about the Attribution Control. Text.StringBuilder myStringBuilder = new Text.StringBuilder(); // Add the count of items to the StringBuilder. myStringBuilder.Append("There are " + theCount.ToString() + " Layers in the Attribution Control." + Environment.NewLine); // Loop through each item in the ObservabaleCollection<IAttribution>. foreach (ESRI.ArcGIS.Client.IAttribution oneIAttribution in theObservableCollectionOfIAttribution) { // Define some variables for CopyrightText and Layer.ID information. string theCopyrightText = null; string theLayerID = null; // FYI: The ESRI.ArcGIS.Client.IAttribution object are really various types of Layer objects! // Not every Type of Layer has a .AttributionTemplate Property which is the internal mechanism for // constructing the ESRI.ArcGIS.Client.IAttribution object. Only those Layers which have a // .AttributionTemplate Property will get listed in the ObservabaleCollection<IAttribution> as // a result of the Attribution.Items Property. Some of theses special Types of Layers that have a // .AttributionTemplate Property are used below to obtain the various CopyrightText and Layer.ID // information if (oneIAttribution is ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer) { ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer oneArcGISDynamicMapServiceLayer = null; oneArcGISDynamicMapServiceLayer = oneIAttribution as ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer; theCopyrightText = oneArcGISDynamicMapServiceLayer.CopyrightText; theLayerID = oneArcGISDynamicMapServiceLayer.ID; } else if (oneIAttribution is ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer) { ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer oneArcGISTiledMapServiceLayer = null; oneArcGISTiledMapServiceLayer = oneIAttribution as ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer; theCopyrightText = oneArcGISTiledMapServiceLayer.CopyrightText; theLayerID = oneArcGISTiledMapServiceLayer.ID; } else if (oneIAttribution is ESRI.ArcGIS.Client.FeatureLayer) { ESRI.ArcGIS.Client.FeatureLayer oneFeatureLayer = null; oneFeatureLayer = oneIAttribution as ESRI.ArcGIS.Client.FeatureLayer; ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo oneFeatureLayerInfo = oneFeatureLayer.LayerInfo; theCopyrightText = oneFeatureLayerInfo.CopyrightText; theLayerID = oneFeatureLayer.ID; } // Append the CopyrightText and Layer.ID information about the Layer in the StringBuilder. myStringBuilder.Append(Environment.NewLine); myStringBuilder.Append("Layer: " + theLayerID + " has the CopyrightText: " + theCopyrightText + Environment.NewLine); } // Display the information about the Attribute Control to the user. MessageBox.Show(myStringBuilder.ToString()); } |
VB.NET | Copy Code |
---|---|
Private Sub Button_Interrogate_AttributeItems_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) ' This function loops through all of the ObservabaleCollection(Of IAttribution) items of the Attribution ' Control to display various information in a MessageBox. ' Get the ObservabaleCollection(Of IAttribution) object. Dim theObservableCollectionOfIAttribution As Collections.ObjectModel.ObservableCollection(Of ESRI.ArcGIS.Client.IAttribution) theObservableCollectionOfIAttribution = Attribution1.Items ' Get the count of the number of items in the ObservabaleCollection(Of IAttribution). Dim theCount As Integer = theObservableCollectionOfIAttribution.Count ' Define a StringBuilder to display information back to the user about the Attribution Control. Dim myStringBuilder As New Text.StringBuilder ' Add the count of items to the StringBuilder. myStringBuilder.Append("There are " + theCount.ToString + " Layers in the Attribution Control." + vbCrLf) ' Loop through each item in the ObservabaleCollection(Of IAttribution). For Each oneIAttribution As ESRI.ArcGIS.Client.IAttribution In theObservableCollectionOfIAttribution ' Define some variables for CopyrightText and Layer.ID information. Dim theCopyrightText As String = Nothing Dim theLayerID As String = Nothing ' FYI: The ESRI.ArcGIS.Client.IAttribution object are really various types of Layer objects! ' Not every Type of Layer has a .AttributionTemplate Property which is the internal mechanism for ' constructing the ESRI.ArcGIS.Client.IAttribution object. Only those Layers which have a ' .AttributionTemplate Property will get listed in the ObservabaleCollection(Of IAttribution) as ' a result of the Attribution.Items Property. Some of theses special Types of Layers that have a ' .AttributionTemplate Property are used below to obtain the various CopyrightText and Layer.ID ' information If TypeOf oneIAttribution Is ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer Then Dim oneArcGISDynamicMapServiceLayer As ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer = Nothing oneArcGISDynamicMapServiceLayer = TryCast(oneIAttribution, ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer) theCopyrightText = oneArcGISDynamicMapServiceLayer.CopyrightText theLayerID = oneArcGISDynamicMapServiceLayer.ID ElseIf TypeOf oneIAttribution Is ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer Then Dim oneArcGISTiledMapServiceLayer As ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer = Nothing oneArcGISTiledMapServiceLayer = TryCast(oneIAttribution, ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer) theCopyrightText = oneArcGISTiledMapServiceLayer.CopyrightText theLayerID = oneArcGISTiledMapServiceLayer.ID ElseIf TypeOf oneIAttribution Is ESRI.ArcGIS.Client.FeatureLayer Then Dim oneFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = Nothing oneFeatureLayer = TryCast(oneIAttribution, ESRI.ArcGIS.Client.FeatureLayer) Dim oneFeatureLayerInfo As ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo = oneFeatureLayer.LayerInfo theCopyrightText = oneFeatureLayerInfo.CopyrightText theLayerID = oneFeatureLayer.ID End If ' Append the CopyrightText and Layer.ID information about the Layer in the StringBuilder. myStringBuilder.Append(vbCrLf) myStringBuilder.Append("Layer: " + theLayerID + " has the CopyrightText: " + theCopyrightText + vbCrLf) Next ' Display the information about the Attribute Control to the user. MessageBox.Show(myStringBuilder.ToString) End Sub |
The Attribution Items are the Layers of the Map (or the Layers corresponding to LayerIDs) implementing IAttribution and returning a non null AttributionTemplate.
The Attribution.Items Property returns a Read only ObservableCollection(Of IAttribution) object. You can use the various ObservableCollection Propeties such as .Add, .Clear, .Remove, etc. to manipulate the contents of what is in the Collection. However it should be noted that the Attribution.PropertyChanged and Attribution.Refreshed Events do not fire as a result of adding items to the ObservableCollection. Also, the Map Control does not automatically by adding new items to the ObservableCollection. The correct programming practice to see automatic updates to the Attributon.Items Collection is to add Layers to the Map Control which is bound to the Attribution.Layers. When Binding the Map.Layers to the Attribution.Layers is done any .Add, .Remove, or change to the LayerCollection will result in update to Attribution.Items.
The Attribution Control is comprised of mainly one sub-component, a ContentPresenter, that displays Copyright information for each Layer that has the IAttribution Interface implemented. The implied Binding that occurs in the ControlTemplate Style of the Attribution Control to the ContentPresenter sub-component is to the ESRI.ArcGIS.Client.IAttribution Interface members. The IAttribution Interface adds functionality to some of the Layer objects; which also means that you can cast to these special Layer types. These special Layer Types have an .AttributionTemplate Property. The .AttributionTemplate Property is the internal mechanism for constructing the IAttribution object. Only those Layers which have a .AttributionTemplate Property will get listed in the ObservabaleCollection(Of IAttribution) as a result of using the Attribution.Items Property. The following Layers are those that implement the IAttribution Interface and have an .AttributionTemplate Property:
para>
- ArcGISDynamicMapServiceLayer
- ArcGISImageServiceLayer
- ArcGISTiledMapServiceLayer
- FeatureLayer
- TileLayer
- OpenStreetMapLayer
Note:This also means that you can also use implied Binding in the ControlTemplate Style of the Attribution Control for the various Properties of the special Types of Layers such as: .ID, .Url, .Version, etc.
Both the Attribution.PropertyChanged and Attribution.Refreshed Events fire as a result of the Layers that Implement IAttribution in the LayerCollection being added or removed in the Attribution.Layers Property. Use the Attribution.Refreshed Event if you want to add, delete, or modify the default attribution items given by the framework. Use the Attribution.PropertyChanged Event on property Attribution.Items, if you want to be aware of this change in order to hook up an Event fired by Attribution.Items. Note: The various special Layer types that Implement the IAttribution Interface have Copyright information Properties that are ReadOnly (meaning they can't be changed by the client application) and hence it is impossible force the Attribution.PropertyChanged and Attribution.Refreshed Events to update as a result of trying to modify the Copyright information on the client side.
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family