Select to view content in your preferred language

Change Map at runtime

1201
8
08-11-2010 06:52 PM
xariaD
by
Occasional Contributor
I have to change the entire map upon some event.
Eg If checkbox 1 is checked load map1; when checkbox2 is checked load map2.
But I want to have the same events on feature layer of both maps, and same Maptips.
I think converting the MapTip to user control will be a good idea, but how do I change the map?

Both maps essentially have same attributes.
0 Kudos
8 Replies
JenniferNery
Esri Regular Contributor
You can create two maps with layer events using the same event handlers in code and add/remove to your grid based on the CheckBox IsChecked property. Or you can define your maps in XAML and then bind each map's Visibility property to the CheckBox IsChecked, at which case you will need to write your own Converter.

Jennifer
0 Kudos
xariaD
by
Occasional Contributor
Or you can define your maps in XAML and then bind each map's Visibility property to the CheckBox IsChecked, at which case you will need to write your own Converter.

Jennifer


What kind of converter, and for what? Could you please elaborate.
Thanks
0 Kudos
xariaD
by
Occasional Contributor
Is it possible to change the Dynamic layer and feature layer only?

If I define two maps then they'll have different "Name" and my code will be in mess.
Can I not just change the url for ArcGISDynamic Layer and Feature Layer???
0 Kudos
JenniferNery
Esri Regular Contributor
Sure you can add/remove layer from your Map layers in code-behind, that will work too with minimal effort.

If you will change visibility using CheckBox. You will have something like this:

Visibility="{Binding IsChecked, ElementName=checkBox, Converter={StaticResource BooleanToVisibilityConverter}}"


public class BooleanToVisibilityConverter : IValueConverter {

    public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) {
      if (targetType == typeof(Visibility) && value !=null) {
        var visible = System.Convert.ToBoolean(value, culture);
        return visible ? Visibility.Visible : Visibility.Collapsed;
      }
      throw new InvalidOperationException("Converter can only convert to value of type Visibility.");
    }

    public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture) {
      throw new InvalidOperationException("Converter cannot convert back.");
    }
}

Jennifer
0 Kudos
xariaD
by
Occasional Contributor
I cannot see the map after I add the layers until i click on the Full extent button on the navigation.
😞
0 Kudos
JenniferNery
Esri Regular Contributor
Which approach did you use? You can check that all layers have initialized. If you are creating the layers in code, be sure to call layer.Initialize(), subscribe to Initialized event too.

Jennifer
0 Kudos
xariaD
by
Occasional Contributor
Well, Finally I had to resort to defining two maps and hiding one .
No issues now.
Thanks for your help.
0 Kudos
deleted-user-ATjHIWsdQYmT
Deactivated User
Jennifer,

What do I have to add to my XAML in order to expose the converter class as a static resource?
0 Kudos