Select to view content in your preferred language

ArgumentNullException (center) in Map.zoomAbout() clicking on map with no tile layers

1107
2
03-10-2011 10:47 AM
AndySanford
Emerging Contributor
ArgumentNullException (center) in Map.zoomAbout() clicking on map with no tile layers

We are using the Silverlight API v2.1 with Silverlight 4

If we have a map which currently only contains (empty) graphics layers (no tile layers) and the user clicks on the blank map, you get an ArgumentNullException for the "center" parameter of the Map.zoomAbout() method.

While we have the map defined in xaml, we've removed the ArcGISTiledMapServiceLayer from xaml because we have to wait a while to determine what URL we want to connect the layer to (and it seems you cannot leave the layer's Url property blank or null when specified in xaml.) Once we know the URL, we create the layer in code behind and add it to the map's layers collection. This part works fine; the problem is simply the ArgumentNullException. It seems to be occurring in some MouseLeftButtonUp handler that is internal to the map (that is the method that appears to be calling map.zoomAbout()); we tried adding our own empty left button handler but that didn't fix the problem.

We'd rather not create the map in code behind, as we have a bunch of stuff within the map element. Is there a way to avoid this exception?

Thanks!

0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
Thank you for reporting this.

What you can do to avoid the exception is to prevent a zoom on double-click when map does not contain any layer.

void MyMap_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
 e.Handled = MyMap.Layers.Count == 0;
}
0 Kudos
AndySanford
Emerging Contributor
Hi, Jennifer,

Thanks a bunch, that works!

I also found that I can disable the map (map.IsEnabled = false) to prevent the problem.

Thanks again for your help.

Regards,
-Andy
0 Kudos