Select to view content in your preferred language

Attribute Editing for multiple layers

1224
13
10-29-2010 06:23 AM
WilliamDonahue
Emerging Contributor
I was wondering if it was possible to use one attribute editor for multuiple layers. It would streamline my application stream and reduce the file size.
0 Kudos
13 Replies
AliMirzabeigi
Emerging Contributor
An alternative would be to use a ComboBox bound to the layers collection in your map and binding the FeatureLayer property of the FeatureDataForm to the selected layer (SelectedItem) in your ComboBox. Depending on your application logic you would then need to set the GraphicSource property of the FeatureDataForm accordingly.
0 Kudos
WilliamDonahue
Emerging Contributor
I have minimal programing experience with the online APIs. I just started 2 weeks ago. I have been following the online samples. Would it be possible for you to clarify how to use the combo box to make the Graphics changes?
0 Kudos
AliMirzabeigi
Emerging Contributor
Here is a simple example...
Assume you have the following layers in your UserControl:
<esri:Map x:Name="MyMap">
<esri:ArcGISTiledMapServiceLayer ID="BaseLayer" 
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
<esri:FeatureLayer ID="Fire" OutFields="*" DisableClientCaching="True" AutoSave="False" MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp"
                Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0" />
<esri:FeatureLayer ID="HomelandSecurity" OutFields="*" DisableClientCaching="True" AutoSave="False" MouseLeftButtonUp="FeatureLayer_MouseLeftButtonUp"
                Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer..." />
</esri:Map>
I added a StackPanel containing my ComboBox and a FeatureDataForm for attribute editing. The GraphicSource property of the FeatureDataForm has set to the selected graphic of the feature layers:
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Select Layer" />
<ComboBox x:Name="cboLayers" Margin="3,0,0,0">
<ComboBoxItem Content="Fire" DataContext="{Binding Path=Layers[1], ElementName=MyMap}" />
<ComboBoxItem Content="HomelandSecurity" DataContext="{Binding Path=Layers[2], ElementName=MyMap}" />
</ComboBox>
</StackPanel>
<esri:FeatureDataForm x:Name="MyFeatureDataForm" Width="400" Height="400" 
                                  FeatureLayer="{Binding Path=SelectedItem.DataContext, ElementName=cboLayers}" 
                                  GraphicSource="{Binding Path=SelectedItem.DataContext.SelectedGraphics[0], ElementName=cboLayers}" />
</StackPanel>
And here is the MouseLeftButtonUp event handler of both FeatureLayers:
private void FeatureLayer_MouseLeftButtonUp(object sender, ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs e)
        {
            FeatureLayer featureLayer = sender as FeatureLayer;
            for (int i = 0; i < featureLayer.SelectionCount; i++)
                featureLayer.SelectedGraphics.ToList().UnSelect();
            e.Graphic.Select();
        }


Hope this helps.
0 Kudos
JenniferNery
Esri Regular Contributor
Another way is to have all the FeatureLayer subscribe to MouseLeftButtonDown event and update your FeatureDataForm's FeatureLayer and GraphicSource in the eventhandler:
 private void FeatureLayer_MouseLeftButtonDown(object sender, ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs e)
 {
  this.MyFeatureDataForm.FeatureLayer = sender as FeatureLayer;
  this.MyFeatureDataForm.GraphicSource = e.Graphic;
 }


If you are going to use Ali's suggestion, your ComboBox ItemSource need to bind to a list of FeatureLayer and your FeatureDataForm's FeatureLayer need to bind to the SelectedItem of your ComboBox. How you choose the Graphic, is up to your application's logic.
0 Kudos
WilliamDonahue
Emerging Contributor
Jen,

If i wanted to have it show a selection color for only the selected item how would i do that.

I when i change feature layers say from points to lines there are both a line and a point highlighted.

Thanks for the help so far.
0 Kudos
JenniferNery
Esri Regular Contributor
You can iterate through the layers' Graphics and mark every selected graphic (Selected = false). You can subscribe to PropertyChanged event on all FeatureLayers. The property you need to check for is either "SelectedGraphics" or "SelectionCount".  When either of these two property changes, you can check whether this is the layer you want the graphic to be selected, if not then be sure to unselect the graphic.
0 Kudos
WilliamDonahue
Emerging Contributor
Is that a for loop that seaches through the entire Feature layer or is it more like a clear selection command?
0 Kudos
JenniferNery
Esri Regular Contributor
It is a foreach loop.
foreach (Graphic item in layer.Graphics)
   item.Selected = false;


You can also use the Editor's ClearSelection command as in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerSelection
0 Kudos
WilliamDonahue
Emerging Contributor
I would perfer not to have my users need to click clear selection before each selection. I tried working with the code you provided and realized i am missing something. Below is my attached code
   private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e)
        {   
   foreach (Graphic item in Map.Graphics)
      item.Selected = false;
   
   
            this.Attributes.FeatureLayer = sender as FeatureLayer;
   this.Attributes.GraphicSource = e.Graphic;
   this.Attachments.GraphicSource = e.Graphic;
   this.Attachments.FeatureLayer = sender as FeatureLayer;
   
   FeatureLayer featureLayer = sender as FeatureLayer;


What i don't really understand is what to put in the position before the .graphics, I keep getting errors returned.
0 Kudos