Select to view content in your preferred language

Toggling Identify function

1405
6
12-10-2010 04:10 AM
BrianPangtay
Regular Contributor
The sample code for the Identify function is always on.

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify

by hardwiring the event: MouseClick on the Map object to code behind that handles the Identify results.

What is the recommended method to change the code to allow the user to toggle the Identify functionality?

Thanks for your help.
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
In this sample application, the identify functionality is binded to the visibility of the identify windows (i.e. the identify functionality is off when the window is closed and the functionality is on when the window is open).

View it live.

Note that it's not a recommended approach, just my 2 cts.
0 Kudos
BrianPangtay
Regular Contributor
I've been trying to implement just the Identify functionality of the sample code into my application. I'm having difficulty adding the ToVisibilityConverter function which is the key to toggling the Identify action.

In MainPage.xaml, I have:

       
    <UserControl.Resources>
        <DropShadowEffect x:Name="dropShadow" BlurRadius="10" ShadowDepth="10" Direction="-45" Color="Black" Opacity="0.5" />
        <local:ToVisibilityConverter x:Key="ToVisibility" />
    </UserControl.Resources>

 <!-- Identify Window -->
        <local:WindowPanel x:Name="IdentifyPanel" Width="260" Height="364"  Effect="{StaticResource dropShadow}"
                              Background="{StaticResource CommonBackgroundBrush}"
                              Visibility="{Binding ElementName=Identify, Path=IsActive, Mode=TwoWay, Converter={StaticResource ToVisibility}}"
                              VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" HorizontalAlignment="Left" VerticalAlignment="Top"
                              Margin="30,200,0,0"
                              BorderBrush="{StaticResource CommonBorderBrush}" >
            <local:Identify x:Name="Identify" Map="{Binding ElementName=Map}" IsActive="False"/>
            <local:WindowPanel.ContentTitle>
                <StackPanel Orientation="Horizontal">
                    <Image Source="Images/IdentifyTool.png" 
                           HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill" 
                           Width="20" Height="20" Margin="5,2,0,0" />
                    <TextBlock Foreground="White" FontSize="12" 
                               Text="Identify" TextWrapping="NoWrap" Height="Auto" 
                               HorizontalAlignment="Left" Margin="5,3,0,0" />
                </StackPanel>
            </local:WindowPanel.ContentTitle>
        </local:WindowPanel>


In MainPage.xaml.cs, I've added the following:


 #region ToVisibilityConverter
 public sealed class ToVisibilityConverter : IValueConverter
 {
  // Methods
  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
   bool flag = false;
   if (value is bool)
   {
    flag = (bool)value;
   }
   else if (value is bool?)
   {
    bool? nullable = (bool?)value;
    flag = nullable.HasValue ? nullable.Value : false;
   }
   else if (value is int)
   {
    flag = ((int)value != 0);
   }
   else if (value is double)
   {
    flag = ((double)value != 0);
   }
   return (flag ? Visibility.Visible : Visibility.Collapsed);
  }

  public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  {
   return ((value is Visibility) && (((Visibility)value) == Visibility.Visible));
  }
 } 
 #endregion


However, when I build the solution, it says that I don't have the ToVisibilityConverter defined. VS IDE Intellisense doesn't show that method for my application namespace. What am I missing?
0 Kudos
JenniferNery
Esri Regular Contributor
Hmm that is difficult to check with the code you provided. Did you define XAML namespace for local properly? Does that namespace match the namespace where your converter reside?

For example, the following code:
xmlns:esriConverters="clr-namespace:ESRI.ArcGIS.Client.ValueConverters;assembly=ESRI.ArcGIS.Client">
<UserControl.Resources>
 <esriConverters:DictionaryConverter x:Key="DictConvert" />
</UserControl.Resources>
<Grid>
 <Ellipse Fill="{Binding Path=Attributes, Converter={StaticResource DictConvert}, ConverterParameter=Color, Mode=OneWay}"/>
</Grid> 


namespace ESRI.ArcGIS.Client.ValueConverters
{
 [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)] public sealed class DictionaryConverter : IValueConverter
 {


EditorBrowsable property documentation: http://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsablestate(v=VS.95).aspx
0 Kudos
BrianPangtay
Regular Contributor
I found my problem. I just needed to move the function outside of MainPage code.

Thanks for your help.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Wonderful 🙂
0 Kudos
BrianPangtay
Regular Contributor
There is a fix required to display the selected feature from the list of identified features when multiple features overlap on the same point. I had to add a ClearGraphics to remove previous selected feature graphics so the selected feature could be seen.

  private void _featureSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
   DataItem item = (DataItem)_featureSelector.SelectedItem;
            if (item != null)
            {
                _graphicsLayer.ClearGraphics();
                CreateGraphic(item);
            }
  }
0 Kudos