Select to view content in your preferred language

How do I bind to a list of features in a map layer?

625
3
11-01-2010 11:11 AM
BenjaminGeiger
Emerging Contributor
I'm attempting to allow my users to select a specific feature from a list, and have my app zoom to that feature. (These are polygon features.)

The problem is retrieving the list of features. Since the layer I'm using to display these features has three different source services (one each for elementary, middle, and high schools), I need to have the list reflect the currently loaded source service. I can't seem to bind to the layer itself.

Am I going about this the wrong way?
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
In this code snippet MyMap is the name of my map, Area is the ID of my FeatureLayer of interest. What you display in the DataTemplate is up to you, in this case, I am displaying one of the attributes where field name is symbolname. The highlighted text in red is what you might need.

<ComboBox ItemsSource="{Binding ElementName=MyMap, Path=Layers[Area].Graphics}">
 <ComboBox.ItemTemplate>
  <DataTemplate>
   <TextBlock Text="{Binding Attributes[symbolname]}"/>
  </DataTemplate>
 </ComboBox.ItemTemplate>
</ComboBox>
0 Kudos
BenjaminGeiger
Emerging Contributor
That works so far, thanks.

Now the problem I'm running into is switching source data for a feature layer. Apparently it can't be done, and the solution you posted only works in a feature layer.

Should I just load all three sets of source data into different layers, and choose which to bind to somehow?
0 Kudos
JenniferNery
Esri Regular Contributor
Graphics is also a property of GraphicsLayer. If later you will not need to distinguish between your different sources you can perform query on all three sources Where "1=1" to return all features and OutFields="*" to return all fields, and add then the featureset.Features to a single GraphicsLayer. You can then bind your ItemSource to the Graphics property of this specific GraphicsLayer.

If you will use separate FeatureLayers, then yes you will need another element that will hold a list of the FeatureLayers. You also need to update the element binding in the ComboBox ItemSource, since it will be based on the SelectedItem.
0 Kudos