Select to view content in your preferred language

WPF Toolkit 2.0 - Overview map error

1305
11
02-14-2011 09:26 AM
JoshuaCorcoran
Emerging Contributor
I have created a WPF Window. If I place the OverviewMap Control in the new window and load the application it freezes at the place where you set the Layer property. If I pull the overview map out of the new window and place it on the form with the map it works perfectly. Is this an known error and is there a work around?
0 Kudos
11 Replies
JenniferNery
Esri Regular Contributor
I'm not sure I know how to replicate the issue so you have two different windows, one with your map and one with OverviewMap? How does OverviewMap set its Map property?

I suspect the problem here is with
<esri:OverviewMap x:Name="MyOverviewMap"  Map="{Binding ElementName=MyMap}">


Element binding will not work if MyMap exists in a different window. For the window that will hold OverviewMap control, you may need to create a Map DependencyProperty for the OverviewMap control to use.
0 Kudos
JoshuaCorcoran
Emerging Contributor
I have created a WPF Window. If I place the OverviewMap Control in the new window and load the application it freezes at the place where you set the Layer property. If I pull the overview map out of the new window and place it on the form with the map it works perfectly. Is this an known error and is there a work around?


I created a new WPF Application. You get the standard MainWindow.xaml. I placed a map control on this main page. I then created a new WPF Window. Right click on Project -> New Item -> Window (WPF) called it frmOverview. In the xaml of the new window I added

<esri:OverviewMap x:Name="ovmap" Margin="5"/>

In the code behind for that page I added the following:

public partial class frmOverviewMap: Window
{
   public Map Map { get; set;}
   public Layer Layer { get; set;}

   private void Window_Loaded(object sender, RoutedEventArgs e)
  {
     this.ovmap.Map = this.Map;
     this.ovmap.Layer = this.Layer;
  }
}

My implementation for the main form is as follows:


private void Window_Loaded(object sender, RoutedEventArgs e)
  {
    var newLayer = new ArcGISTiledMapService();
    newLayer.Url = ""<SOME URL>";
    newlayer.ID = "<SOME ID>";

    var newForm = new frmOverviewMap();
    newForm.Map = this.map;
    newForm.Layer = newLayer;
    newform.Topmost = true;
    newform.Show();     
  }

After the layer intalizes the whole app freezes.
0 Kudos
JoshuaCorcoran
Emerging Contributor
I'm not sure I know how to replicate the issue so you have two different windows, one with your map and one with OverviewMap? How does OverviewMap set its Map property? 

I suspect the problem here is with 
<esri:OverviewMap x:Name="MyOverviewMap"  Map="{Binding ElementName=MyMap}">


Element binding will not work if MyMap exists in a different window. For the window that will hold OverviewMap control, you may need to create a Map DependencyProperty for the OverviewMap control to use.


Please see sample code above.
0 Kudos
JenniferNery
Esri Regular Contributor
Map and Layer property in your code use DependencyProperty that sets Map and Layer of the OverviewMap contro? (similar to code below)

I do not get error when I have the following code in OtherWindow.xaml.cs
public Map Map
{
 get { return (Map)GetValue(MapProperty); }
 set { SetValue(MapProperty, value); }
}
 
public static readonly DependencyProperty MapProperty = DependencyProperty.Register("Map", typeof(Map), typeof(OtherWindow), new PropertyMetadata(OnMapPropertyChanged));
  
private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
 OtherWindow ow = d as OtherWindow;
 if (ow != null && e.NewValue is Map)
  ow.MyOverviewMap.Map = e.NewValue as Map;
}
  
public Layer Layer
{
 get { return (Layer)GetValue(LayerProperty); }
 set { SetValue(LayerProperty, value); }
}

public static readonly DependencyProperty LayerProperty = DependencyProperty.Register("Layer", typeof(Layer), typeof(OtherWindow), new PropertyMetadata(OnLayerPropertyChanged));
private static void OnLayerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
 OtherWindow ow = d as OtherWindow;
 if (ow != null && e.NewValue is Layer)
  ow.MyOverviewMap.Layer = e.NewValue as Layer;
}


In MainWindow.xaml.cs
private void Window_Loaded(object sender, RoutedEventArgs e)
{
 OtherWindow ow = new OtherWindow()
 {
 Map = this.MyMap,
 Layer = new ArcGISTiledMapServiceLayer()
 {
  Url = (this.MyMap.Layers[0] as ArcGISTiledMapServiceLayer).Url
 }
};
ow.Show();
0 Kudos
JoshuaCorcoran
Emerging Contributor
Jennifer,

Will try that code first thing in the morning, and let you know if it works for me. Thanks.
0 Kudos
JoshuaCorcoran
Emerging Contributor
Map and Layer property in your code use DependencyProperty that sets Map and Layer of the OverviewMap contro? (similar to code below)

I do not get error when I have the following code in OtherWindow.xaml.cs
public Map Map
{
 get { return (Map)GetValue(MapProperty); }
 set { SetValue(MapProperty, value); }
}
 
public static readonly DependencyProperty MapProperty = DependencyProperty.Register("Map", typeof(Map), typeof(OtherWindow), new PropertyMetadata(OnMapPropertyChanged));
  
private static void OnMapPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
 OtherWindow ow = d as OtherWindow;
 if (ow != null && e.NewValue is Map)
  ow.MyOverviewMap.Map = e.NewValue as Map;
}
  
public Layer Layer
{
 get { return (Layer)GetValue(LayerProperty); }
 set { SetValue(LayerProperty, value); }
}

public static readonly DependencyProperty LayerProperty = DependencyProperty.Register("Layer", typeof(Layer), typeof(OtherWindow), new PropertyMetadata(OnLayerPropertyChanged));
private static void OnLayerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
 OtherWindow ow = d as OtherWindow;
 if (ow != null && e.NewValue is Layer)
  ow.MyOverviewMap.Layer = e.NewValue as Layer;
}


In MainWindow.xaml.cs
private void Window_Loaded(object sender, RoutedEventArgs e)
{
 OtherWindow ow = new OtherWindow()
 {
 Map = this.MyMap,
 Layer = new ArcGISTiledMapServiceLayer()
 {
  Url = (this.MyMap.Layers[0] as ArcGISTiledMapServiceLayer).Url
 }
};
ow.Show();


Jennifer,

I tried the code that you supplied. The application no longer freezes up completly but no overview map is diplayed. I just get a blank white window. I put a breakpoint in the application and notice that the Layer supplied is never initalized. Upon calling initalize the application freezes up again. What am I doing wrong here, this seems like such a simple task.
0 Kudos
JenniferNery
Esri Regular Contributor
Can you try to run Fiddler with your application to monitor web requests?

I really could not replicate the issue you are facing with OverviewMap. I modified a copy of this sample in WPF http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#OverviewMap.
. Placing OverviewMap code in another Window with the code I included in my last post.

Did you replace "OtherWindow" with your own class name?

public static readonly DependencyProperty MapProperty = DependencyProperty.Register("Map", typeof(Map), typeof(  OtherWindow), new PropertyMetadata(OnMapPropertyChanged)); 

public static readonly DependencyProperty LayerProperty = DependencyProperty.Register("Layer", typeof(Layer), typeof(  OtherWindow), new PropertyMetadata(OnLayerPropertyChanged)); 


If that still does not work for you, download Toolkit source code from CodePlex http://esrisilverlight.codeplex.com/ and debug through it.
0 Kudos
JoshuaCorcoran
Emerging Contributor
Can you try to run Fiddler with your application to monitor web requests?

I really could not replicate the issue you are facing with OverviewMap. I modified a copy of this sample in WPF  http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#OverviewMap.
. Placing OverviewMap code in another Window with the code I included in my last post.

Did you replace "OtherWindow" with your own class name?


If that still does not work for you, download Toolkit source code from CodePlex http://esrisilverlight.codeplex.com/ and debug through it.


Jennifer,

Could you send me a zip file of the project you tested it with. I can try and run the project from here and see if I get the same error. My email address is: corcoranj.ctr@jdi.socom.mil

Thanks,

Josh
0 Kudos
JenniferNery
Esri Regular Contributor
Sure. I just added it as attachment to this post in case other dev will need to do something similar. Kindly see attached WPF project.
0 Kudos