Select to view content in your preferred language

Only display features from layer filter

820
3
03-25-2011 08:58 AM
RobertMueller
Deactivated User
Is it possible with the current API to display only the selected feature from selected layer? I would like to have a combobox with state names (from my current State layer). Upon selection of that state I would like the filter the State Layer for the user selection and display only that feature.
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
I think you can use VisualStateManager to update the symbol to null or transparent color when unselected. You can look at this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SelectGraphics.
0 Kudos
RobertMueller
Deactivated User
I wasn't going that direction, but I think that will work.

My other question is the one I thought was going to be easy for me to figure out. I've created combobox queries similar to the County Query Sample, but I can't seem to to populate the layer names in this combobox. The list box code for this function is simply;

<ListBox x:Name="MyList" ItemsSource="{Binding ElementName=Map, Path=Layers}">

But how do you convert it to this:
<ComboBox x:Name="CountyQueryComboBox" Grid.Row="1" MinWidth="150" SelectionChanged="CountyQueryComboBox_SelectionChanged" Margin="5,1,5,5" >

More so, how do I change the "County Query Sample" code behind to work with this task?
0 Kudos
JenniferNery
Esri Regular Contributor
I was hoping there's a way to create the query in XAML alone but it seems like &apos; for single quote (') is not supported in XAML.

You can try out the following:
 <Grid x:Name="LayoutRoot" Background="White">
  <esri:Map x:Name="MyMap">
   <esri:Map.Extent>
    <esri:Envelope XMin="-178.217598362366" YMin="18.921786345087" XMax="-66.9692709841984" YMax="71.4062353672549">
     <esri:Envelope.SpatialReference>
      <esri:SpatialReference WKID="4269"/>
     </esri:Envelope.SpatialReference>
    </esri:Envelope>
   </esri:Map.Extent>
   <esri:FeatureLayer ID="MyStateLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" OutFields="*"/>
   <esri:FeatureLayer ID="MyCountyLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3" OutFields="*" />
  </esri:Map>
  <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
  <ComboBox x:Name="MyStates" ItemsSource="{Binding ElementName=MyMap, Path=Layers[MyStateLayer].Graphics}" SelectionChanged="ComboBox_SelectionChanged">
   <ComboBox.ItemTemplate>
    <DataTemplate>
      <TextBlock Text="{Binding Attributes[STATE_NAME]}"/>
    </DataTemplate>
   </ComboBox.ItemTemplate>
  </ComboBox>
   <ComboBox x:Name="MyCounties" ItemsSource="{Binding ElementName=MyMap, Path=Layers[MyCountyLayer].Graphics}">
   <ComboBox.ItemTemplate>
    <DataTemplate>
      <TextBlock Text="{Binding Attributes[CNTY_FIPS]}"/>
    </DataTemplate>
   </ComboBox.ItemTemplate>
  </ComboBox>
   <TextBlock Text="{Binding ElementName=MyStates, Path=SelectedItem.Attributes[STATE_NAME], StringFormat='STATE_NAME = &quot;\{0\}&quot;'}"/>
  </StackPanel>
 </Grid>


private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
 var stateName = ((sender as ComboBox).SelectedItem as Graphic).Attributes["STATE_NAME"] as string;
 FeatureLayer countyLayer = this.MyMap.Layers["MyCountyLayer"] as FeatureLayer;
 countyLayer.Where = string.Format("STATE_NAME = '{0}'", stateName);
 countyLayer.Update();
}


There's more than one way to populate your combo box with county based on state selection. The code above is just one sample. You can also use QueryTask and store results in a GraphicsLayer and still bind to the Attributes the same way as I did when working with the FeatureLayers.
0 Kudos