Map in Tab

Mar 10, 2009 at 8:57 PM

In my application the Map is inside a TabControl - adapting the prototype's Page.xaml:

 

 

 

<swc:TabControl SelectionChanged="TabControl_SelectionChanged" SelectedIndex="0" Grid.Column="0" Grid.Row="0">
    <swc:TabItem Header="Tab1">
       
<TextBlock>Some text on tab 1</TextBlock>
   
</swc:TabItem>
   
<swc:TabItem Header="Map">
       
<Canvas>
           
<!-- Map Control -->
           
<DeepEarth:Map x:Name="map" Margin="0,0,0,0" Style="{StaticResource PrototypeMapStyle}">

 

etc

 


Code behind:

private void ResetMap()
{
    map.SetViewCenter(
new Point(-95.5, 40.5), 4); // attempt to show USA
}

 

 

private void TabControl_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
   
if (e.AddedItems.Count == 0) return;
   
TabItem tabItem = e.AddedItems[0] as TabItem;
   
switch (tabItem.Header.ToString())
    {
       
case "Map":
             ResetMap();
            
break;
    }
}


When I start the application and click the Map tab, the application hangs.
Yet, I seem to do a benign thing: put a map in a TabControl. I am confused.

Mar 12, 2009 at 3:53 AM
Maybe same issue as http://deepearth.codeplex.com/Thread/View.aspx?ThreadId=48721 (also not answered yet)?
Mar 12, 2009 at 2:12 PM
I can assure you that simply placing the map inside a tab control does work. We've been doing it from an early version of DeepEarth and, in order to reproduce a bug for RoadWarrior, I added a tab control to the prototype and the map works fine.

So I suspect something with your code. Without digging too deeply, you should be careful about calling SetViewCenter without verifying if the map has been loaded first. You should only reset the map view in the MapLoaded event if the map has not yet been loaded.

Richard
Mar 12, 2009 at 5:22 PM
I am sorry I do not get it. Must be something really stupid.

All I do is get the Jan 31 source, add a reference to System.Windows.Controls, and add to Prototype\DeepEarthPrototype\Page.xaml:

...

xmlns:swc="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"

...

<Grid x:Name="LayoutRoot" >
   
<swc:TabControl>
       
<swc:TabItem Header="Tab1">
           
<TextBlock>Some text on tab 1</TextBlock>
       
</swc:TabItem>
       
<swc:TabItem Header="Map">
           
<Canvas>

                  <!-- Existing Map Controls here -->

 

             </Canvas>
       
</swc:TabItem>
   
</swc:TabControl>
</Grid>

 

Hit F5 and click the Map tab. Set a breakpoint on line 112 of \DeepEarth\DeepEarth\Layers\TileSource.cs and it looks like it is loading all tiles on all zoom levels which takes quite a while.

(So you get this also without using SetViewCenter(). By the way, are you sure about the "not" in your last sentence ("if the map has not yet been loaded")? I see several comments in the code suggesting some things won't work till after the map has been loaded and I assume the map is loaded in the handler of the map's Loaded event.)

Mar 12, 2009 at 7:45 PM
Correct, you need to wait until the MapLoaded event has fired to set the view.

Try the following modification to Page.xaml: http://deepearth.codeplex.com/WorkItem/View.aspx?WorkItemId=3726

The only difference is I used a Grid instead of a Canvas to hold the map controls in the tab. I tried it again and have no issues with the prototype.

Richard
Mar 12, 2009 at 9:06 PM
Correct. Thank you!