Select to view content in your preferred language

Legend of maps

998
7
05-15-2012 12:29 PM
YassineEL_JADIDI
Deactivated User
Hello,
i want to have a legend of two maps with radiobutton.
explaining : i want to have a legend with RadioButtons..when i click on first radiobutton, i should have a map(map1), and when i clicked in the another radiobutton, i should have another map (map2).
any help about this please !
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
If you want Legend control to switch Map through RadioButton.Click, you can use RadioButton.Tag to store the element and implement its Click event.

You can do something like this:
XAML
  <StackPanel VerticalAlignment="Top" HorizontalAlignment="Center">
   <RadioButton x:Name="Rb" Content="Test" Tag="{Binding ElementName=MyMap}" Click="RadioButton_Click"/>
   <RadioButton x:Name="Rb2" Content="Test" Tag="{Binding ElementName=MyMap2}" Click="RadioButton_Click"/>
  </StackPanel>


Assuming you've given your Legend control a name (i.e. x:Name="MyLegend")
Code-behind
  private void RadioButton_Click(object sender, RoutedEventArgs e)
  {
   var rb = sender as RadioButton;
   if (rb.IsChecked.HasValue && rb.IsChecked.Value)
    MyLegend.Map = rb.Tag as Map;
  }
0 Kudos
YassineEL_JADIDI
Deactivated User
thank you jennifer for your replies.
i tried your solution but it didnt work.i want when i click in the radiobutton of map1....the map1 appear..and if i want the map2..i click in the other radiobutton.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
i tried your solution but it didnt work.i want when i click in the radiobutton of map1....the map1 appear..and if i want the map2..i click in the other radiobutton.


Do do you mean by 'the map1 appears'? appears in the legend (with 2 maps on the screen) or just toggled on/off with only one map visible at a time?

In the second case, you have just to create 2 maps and toggle the visibilities on/off depending on the radio button.
0 Kudos
YassineEL_JADIDI
Deactivated User
i mean when i click on the radiobutton of "map1", the map1 appear ine the screen with his legend, and when i click on radiobutton of map2, the map2 appear with his legend.
i wish i explained well what i want !!
0 Kudos
DominiqueBroux
Esri Frequent Contributor
i mean when i click on the radiobutton of "map1", the map1 appear ine the screen with his legend, and when i click on radiobutton of map2, the map2 appear with his legend.
i wish i explained well what i want !!

So why not just define 2 maps and 2 legends with only one map and one legend visible at a time (radio button toggling visibility of these elements) ?
0 Kudos
YassineEL_JADIDI
Deactivated User
how can i do that ??
how can the radiobutton click toggle the visibility of a map ?? can you help me with the code please ?
0 Kudos
ChristopherHill
Deactivated User
Here is a simple example of how to do what you are asking using 2 maps and 2 Legends.

<Grid x:Name="LayoutRoot" Background="White">
        <esri:Map x:Name="Map1" Extent="-20037507.0671618,-20037507.0671618,20037507.0671618,20037507.0671619">
            <esri:ArcGISTiledMapServiceLayer ID="basemap" DisplayName="Base Map 1" Url="http://services.arcgisonline.com/arcgis/rest/services/world_topo_map/MapServer" />
            <esri:FeatureLayer ID="points" DisplayName="Incident Points" Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/0" DisableClientCaching="True"/>
        </esri:Map>

        <esri:Map x:Name="Map2" Extent="-20037507.0671618,-20037507.0671618,20037507.0671618,20037507.0671619" Visibility="Collapsed">
            <esri:ArcGISTiledMapServiceLayer ID="basemap" DisplayName="Base Map 2" Url="http://services.arcgisonline.com/arcgis/rest/services/world_topo_map/MapServer" />
            <esri:FeatureLayer ID="lines" DisplayName="Incident Lines" Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/1" DisableClientCaching="True"/>
            <esri:FeatureLayer ID="polygons" DisplayName="Incident Polygons" Url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/operations/FeatureServer/2" DisableClientCaching="True"/>
        </esri:Map>
        
        <Grid VerticalAlignment="Bottom" HorizontalAlignment="Right">
            <esri:Legend x:Name="Legend1" Map="{Binding ElementName=Map1}" LayerIDs="points" />
            <esri:Legend x:Name="Legend2" Map="{Binding ElementName=Map2}" LayerIDs="lines,polygons" Visibility="Collapsed" />
        </Grid>
        
        <StackPanel VerticalAlignment="Top" HorizontalAlignment="Right" Margin="10">
            <RadioButton GroupName="MapSwitcher" Tag="1" Content="Display Map 1" IsChecked="True" Click="RadioButton_Click" />
            <RadioButton GroupName="MapSwitcher" Tag="2" Content="Display Map 2" IsChecked="False" Click="RadioButton_Click" />
        </StackPanel>
    </Grid>


private void RadioButton_Click(object sender, RoutedEventArgs e)
{
 string tag = (sender as RadioButton).Tag as string;
 switch (tag)
 {
  case "1":
   Map1.Visibility = Visibility.Visible;
   Legend1.Visibility = Visibility.Visible;   
                                          Map2.Visibility = Visibility.Collapsed;
   Legend2.Visibility = Visibility.Collapsed;
   break;
  case "2":
   Map2.Visibility = Visibility.Visible;
   Legend2.Visibility = Visibility.Visible;
   Map1.Visibility = Visibility.Collapsed;
   Legend1.Visibility = Visibility.Collapsed;
                break;
  }   
 }
}


This should give you the functionality you are looking for and you can then change it to meet your needs.
0 Kudos