Select to view content in your preferred language

Identify task layers into separate display boxes

1211
7
Jump to solution
05-23-2012 09:43 AM
TanyaOwens
Frequent Contributor
I am looking to separate out identify task layers into separate display boxes. I have three layers that return results but instead of a combo box drop down selection, I would like the identify results of each layer separated out into individual display boxes. Any direction or guidance would be appreciated. Thanks!
0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor
Are you using FeatureDataGrid? If no and you are using this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify, you can update the IdentifyGrid ScrollViewer by inserting the following code:
      <StackPanel>       <slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False" HeadersVisibility="None"                                Background="White">        <slData:DataGrid.Columns>         <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>         <slData:DataGridTextColumn Binding="{Binding Path=Value}"/>        </slData:DataGrid.Columns>       </slData:DataGrid>        <slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False" HeadersVisibility="None"                                Background="White">         <slData:DataGrid.Columns>          <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>          <slData:DataGridTextColumn Binding="{Binding Path=Value}"/>         </slData:DataGrid.Columns>        </slData:DataGrid>       </StackPanel>


        public void ShowFeatures(List<IdentifyResult> results)         {             _dataItems = new List<DataItem>();              if (results != null && results.Count > 0)             {                 IdentifyComboBox.Items.Clear();                 foreach (IdentifyResult result in results)                 {                     Graphic feature = result.Feature;                     string title = result.Value.ToString() + " (" + result.LayerName + ")";                     _dataItems.Add(new DataItem()                     {                         Title = title,                         Data = feature.Attributes                     });                     IdentifyComboBox.Items.Add(title);       if(result.LayerId == 3)       IdentifyDetailsDataGrid.ItemsSource = feature.Attributes;      else       IdentifyDetailsDataGrid2.ItemsSource = feature.Attributes;                  }                 IdentifyComboBox.SelectedIndex = 0;             }         }


Try this first and you will see that LayerId=3 is always displayed on top data grid. If this works for you, you can clean up other code and remove use of ComboBox. If you are using FeatureDataGrid, you need to put your results in 2 different GraphicsLayer. Same idea, use IdentifyResults.LayerId or LayerName to separate the results.

View solution in original post

0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
In the ExecuteCompleted event handler, you can check for LayerId or LayerName to separate the results:

if (e.IdentifyResults.Any(r => r.LayerId == 1))
{
 var resultsFrom1 = e.IdentifyResults.Where(r => r.LayerId == 1);
 displayComboBoxFrom1.ItemsSource = resultsFrom1;
}
if (e.IdentifyResults.Any(r => r.LayerId == 2))
{
 var resultsFrom2 = e.IdentifyResults.Where(r => r.LayerId == 2);
 displayComboBoxFrom2.ItemsSource = resultsFrom2;
}
0 Kudos
TanyaOwens
Frequent Contributor
Does that code replace:
            
            if (args.IdentifyResults.Count > 0)
            {
                IdentifyResultsStackPanel.Visibility = Visibility.Visible;

                foreach (IdentifyResult result in args.IdentifyResults)
                {
                    string title = string.Format("{0} ({1})", result.Value.ToString(), result.LayerName);
                    IdentifyComboBox.Items.Add(title);
                }


and I get an error for the displayComboBox - "The name 'displayComboBoxFrom4' does not exist in the current context"; Do I need to add something to my xaml code?
0 Kudos
TanyaOwens
Frequent Contributor
I may be wrong but, after working with this code it appears that it is giving me additional ComboBox displays. I think I would like to get rid of the combo boxes completely and just display the 3 layer feature data in a data grid separated by layer. For example:

Layer 1 Text Title:
Layer 1 Feature data grid

Layer 2 Text Title:
Layer 2 Feature data grid

Any further guidance in achieving this?

-Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
Are you using FeatureDataGrid? If no and you are using this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify, you can update the IdentifyGrid ScrollViewer by inserting the following code:
      <StackPanel>       <slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False" HeadersVisibility="None"                                Background="White">        <slData:DataGrid.Columns>         <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>         <slData:DataGridTextColumn Binding="{Binding Path=Value}"/>        </slData:DataGrid.Columns>       </slData:DataGrid>        <slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False" HeadersVisibility="None"                                Background="White">         <slData:DataGrid.Columns>          <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>          <slData:DataGridTextColumn Binding="{Binding Path=Value}"/>         </slData:DataGrid.Columns>        </slData:DataGrid>       </StackPanel>


        public void ShowFeatures(List<IdentifyResult> results)         {             _dataItems = new List<DataItem>();              if (results != null && results.Count > 0)             {                 IdentifyComboBox.Items.Clear();                 foreach (IdentifyResult result in results)                 {                     Graphic feature = result.Feature;                     string title = result.Value.ToString() + " (" + result.LayerName + ")";                     _dataItems.Add(new DataItem()                     {                         Title = title,                         Data = feature.Attributes                     });                     IdentifyComboBox.Items.Add(title);       if(result.LayerId == 3)       IdentifyDetailsDataGrid.ItemsSource = feature.Attributes;      else       IdentifyDetailsDataGrid2.ItemsSource = feature.Attributes;                  }                 IdentifyComboBox.SelectedIndex = 0;             }         }


Try this first and you will see that LayerId=3 is always displayed on top data grid. If this works for you, you can clean up other code and remove use of ComboBox. If you are using FeatureDataGrid, you need to put your results in 2 different GraphicsLayer. Same idea, use IdentifyResults.LayerId or LayerName to separate the results.
0 Kudos
TanyaOwens
Frequent Contributor
I am not using a featuredatagrid so I was able to modify my code to add in additional data grids. Except I get a error "The property 'Content' is set more than once." I am unsure why.

        <!--IDENTIFY TASK INTERFACE-->
        <StackPanel Margin="10" HorizontalAlignment="Right">
            <Grid>
                <Rectangle Fill="#CC5C90B2" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0,0,0,-25" />
                <TextBlock Text="School Attendance Area:" Foreground="White" FontSize="10" 
        Margin="14,9,6,6" />
                <StackPanel x:Name="IdentifyResultsStackPanel" Margin="15,30,15,10" Visibility="Collapsed">
                    <TextBlock Text="Select a result from the list to display additional info" Foreground="White" 
          FontSize="10" FontStyle="Italic" Margin="0,0,0,5" />
                    <ComboBox x:Name="IdentifyComboBox" SelectionChanged="IdentifyComboBox_SelectionChanged" />
                    <ScrollViewer MaxHeight="340" Margin="0,10,0,0">
                        <slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False"
            HeadersVisibility="None" LoadingRow="IdentifyDetailsDataGrid_LoadingRow">
                            <slData:DataGrid.Columns>
                                <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
                                <slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
                            </slData:DataGrid.Columns>
                        </slData:DataGrid>
                        <slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False"
            HeadersVisibility="None" LoadingRow="IdentifyDetailsDataGrid_LoadingRow">
                            <slData:DataGrid.Columns>
                                <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
                                <slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
                            </slData:DataGrid.Columns>
                        </slData:DataGrid>
                    </ScrollViewer>
                    <ListBox x:Name="MyListBox" Height="200" Width="200" />
                </StackPanel>
            </Grid>
        </StackPanel>
    </Grid>
</UserControl>



But for separating out the data I have more than two layers (right now I have 3) so I am not sure an If/Else statement will be best in this case. I am looking to identify layer 1 into a data grid 1, layer 2 into a data grid 2, and layer 3 into a data grid 3. It seems like it should be easy but because I am new to this, I think I am just missing it. Also I am using the concepts identify task http://help.arcgis.com/en/webapi/silverlight/help/index.html#/Identify_task/01660000001m000000/ so my code looks like this:

        //Displaying Identify Results.
        // Populate ComboBox with the results when Identify is complete.
        private void IdentifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
        {
            IdentifyComboBox.Items.Clear();

            // Check for new results.
            if (args.IdentifyResults.Count > 0)
            {
                // Show ComboBox and attributes DataGrid.
                IdentifyResultsStackPanel.Visibility = Visibility.Visible;

                // Add results to ComboBox.
                foreach (IdentifyResult result in args.IdentifyResults)
                {
                    string title = string.Format("{0} ({1})", result.Value.ToString(), result.LayerName);
                    IdentifyComboBox.Items.Add(title);

                }

                // Workaround for ComboBox bug.
                IdentifyComboBox.UpdateLayout();

                // Store the list of Identify results.
                _lastIdentifyResult = args.IdentifyResults;

                // Initialize ComboBox and fire SelectionChanged.
                IdentifyComboBox.SelectedIndex = 0;
            }
            else
            {
                // Hide ComboBox and attributes DataGrid and notify the user.
                IdentifyResultsStackPanel.Visibility = Visibility.Collapsed;
                MessageBox.Show("No features found");
            }
        }


Additional Info: I also have included into my code the selection of fields to display from these 3 layer:
                var fieldsToDisplay = new List<string>() { "School Name", "Address", "Zip", "Phone", "Website", "School District" };
                var attributesToDisplay = new Dictionary<string, object>();
                foreach (var item in selectedFeature.Attributes)
                    if (fieldsToDisplay.Contains(item.Key))
                        attributesToDisplay[item.Key] = item.Value;
                   IdentifyDetailsDataGrid.ItemsSource = attributesToDisplay;


My Goal is to have the Identify task have no combo box and just 3 display boxes with the attribute info. If there is another way to do that I am willing to go a different direction. Right now when I am looking through the code there are many references to the combo box so I am a little nervous about how to go about creating an identify task without a combo box.
0 Kudos
TanyaOwens
Frequent Contributor
I have changed my code behind to match the sample code http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify. I was able to get my data to separate out into two data grids by using the if else statement. But I am having trouble figuring out how to make a statement to separate out my 3 layers into 3 separate data grids. Also, I need to select specific fields to display from these layers and the following code isn't working for me. I think I might be placing the code incorrectly but everything I try returns and error.

var temp = new Dictionary<string, object>();
var fields = new List<string>() {"field1", "field2"}; //fields to display
foreach(var item in feature.Attributes)
{
     if(fields.Contains(item.Key)) 
          temp[item.Key] = item.Value;
}
//more code goes here
     Data = temp
0 Kudos
TanyaOwens
Frequent Contributor
Never mind, I got it with the following code:

        public void ShowFeatures(List<IdentifyResult> results)
        {
            _dataItems = new List<DataItem>();

            if (results != null && results.Count > 0)
            {
                
                foreach (IdentifyResult result in results)
                {

                    Graphic feature = result.Feature;
                    string title = result.Value.ToString() + " (" + result.LayerName + ")";
                    _dataItems.Add(new DataItem()

                    {

                        Title = title,
                        Data = feature.Attributes

                    });
                    
                    var fieldsToDisplay = new List<string>() { "School Name", "Address", "Zip", "Phone", "Website", "School District" };
                    var attributesToDisplay = new Dictionary<string, object>();
                    foreach (var item in feature.Attributes)
                        if (fieldsToDisplay.Contains(item.Key))
                            attributesToDisplay[item.Key] = item.Value;
                    

                    if (result.LayerId == 4)
                        IdentifyDetailsDataGrid.ItemsSource = feature.Attributes;
                        IdentifyDetailsDataGrid.ItemsSource = attributesToDisplay;
                    if (result.LayerId == 9)
                        IdentifyDetailsDataGrid2.ItemsSource = feature.Attributes;
                        IdentifyDetailsDataGrid2.ItemsSource = attributesToDisplay;  
                    if (result.LayerId == 14)
                        IdentifyDetailsDataGrid3.ItemsSource = feature.Attributes;
                        IdentifyDetailsDataGrid3.ItemsSource = attributesToDisplay;

                }


Now all I need it to set the field attribute of "Website" to be a hyperlink in all three data grids.
0 Kudos