Customizing the XamMap MapNavigationPane Control Template

[Infragistics] Mihail Mateev / Tuesday, August 17, 2010

XamMap control is a powerful component for the visualization of geographic data.
Often users want to change the style of components and in particular the style of MapNavigationPane.
Many people want to have navigation on the map similar to the Bing Maps or other applications.
This article demonstrates how to do custom style in MapNavigationPane XamMap:

Bing Maps navigation pane

This article demonstrates how to change the style of MapNavigationPane changing some settings and
restyling the control, using the main template parts

Requirements:

Software:

  • Visual Studio 2010
  • Microsoft Expression Blend 4
  • Infragistics XamMap component:

For Silverlight Demo:

  • NetAdvantage for Silverlight Data Visualization 2010 vol.2

http://ko.infragistics.com/dotnet/netadvantage/silverlight/data-visualization.aspx#Downloads

For WPF Demo:

  • NetAdvantage for Silverlight Data Visualization 2010 vol.2

http://ko.infragistics.com/dotnet/netadvantage/wpf/data-visualizationdownloads.aspx#Downloads

Sample data:

Steps to reproduce:

For Silverlight Demo:

  1. Create a Silverlight application with WEB site (with Expression Blend 4.0 ).
  2. Change a MapNavigationPane settings.
  3. Retemplate a MapNavigationPane control.
  4. Run the sample application

  • Create a Silverlight application with WEB site (with Expression Blend 4.0 ).

Start Microsoft Expression Blend 4 and create a new Silverlight Application + Website

Add a XamMap control with a MapNavigationPane inside it:

<ig:MapNavigationPane Name="navPane" Margin="0"

HorizontalAlignment="Center" VerticalAlignment="Bottom" Orientation="Horizontal"/>

Rebuild a solution.

Create a folder , named ShapeFIles in the ClienBin folder of the WEB Project.

Add a shapefiles in this folder.

Add a MapLayer, named World with a ShapeFileReader, that uses a data from shapefile with world countries:

  

<ig:XamMap Margin="30" d:LayoutOverrides="Width, Height">

        <ig:MapNavigationPane Name="navPane" Width="100" Height="300" Margin="0,60,0,0"

        HorizontalAlignment="Left" VerticalAlignment="Top"/>

        <ig:XamMap.Layers>

            <ig:MapLayer

                   Name="World" Brushes="#4C2C42C0 #4C218B93 #4CDC1C1C #4C3D7835 #4C701B51"

                   FillMode="Choropleth">

                    <ig:MapLayer.Reader>

                        <ig:ShapeFileReader Uri="ShapeFiles\Cntry00\Cntry00"

                           DataMapping="Name=CNTRY_NAME; Value=POP_CNTRY; Caption=CNTRY_NAME; ToolTip=CNTRY_NAME" />

                    </ig:MapLayer.Reader>

                    <ig:MapLayer.ValueScale>

                        <ig:LinearScale IsAutoRange="True"/>

                    </ig:MapLayer.ValueScale>

                </ig:MapLayer>

        </ig:XamMap.Layers>                   

</ig:XamMap>

 

Rebuild and Run the sample application.

  • Change a MapNavigationPane settings.

Change MapNavigationPane.Orientation property to Horizontal, VerticalPosition to Bottom,
HorizontalPosition to Center and remove Width, Height and Margin settings:

 

Run the sample application:

<ig:MapNavigationPane Name="navPane" Margin="0"

HorizontalAlignment="Center" VerticalAlignment="Bottom" Orientation="Horizontal" Style="{StaticResource MapNavigationPaneCustomStyle}"/>

  • Retemplate a MapNavigationPane control.

 

Edit a copy of the current MapNavigationPane style, named MapNavigationPaneCustomStyle

 

Retemplate a MapNavigationPane control.

There are two main parts in the MapNavigationPane control template:

HorizontalRoot from type FrameworkElement, used when the orientation is horizontal and
VerticalRoot from type FrameworkElement, used whenthe orientation is vertical .

By default HorizontalRoot and VerticalRoot are from type Grid:

 

There are several additional template parts inside a HorizontalRoot and a VerticalRoot elements:

Inside HorizontalRoot :

  • ButtonBase HorizontalPanWestButton: ButtonBase inheritor, used for pan West.
  • ButtonBase HorizontalPanSouthButton: ButtonBase inheritor, used for pan South.
  • ButtonBase HorizontalPanEastButton: ButtonBase inheritor, used for pan East.
  • ButtonBase HorizontalPanNorthButton: ButtonBase inheritor, used for pan North.
  • ButtonBase HorizontalZoomInButton: ButtonBase inheritor, used for zoom in.
  • ButtonBase HorizontalZoomOutButton: ButtonBase inheritor, used for used for zoom out.
  • ButtonBase HorizontalFitButton: ButtonBase inheritor, used for zoom to fit.
  • ButtonBase HorizontalBackButton: ButtonBase inheritor, uset for zoom back.
  • RangeBase HorizontalZoomRange: RangeBase inheritor that represents current scale, min scale and max scale

Inside VerticalRoot: 

 

  • ButtonBase VerticalPanWestButton: ButtonBase inheritor, used for pan West.
  • ButtonBase VerticalPanSouthButton: ButtonBase inheritor, used for pan South.
  • ButtonBase VerticalPanEastButton: ButtonBase inheritor, used for pan East.
  • ButtonBase VerticalPanNorthButton: ButtonBase inheritor, used for pan North.
  • ButtonBase VerticalZoomInButton: ButtonBase inheritor, used for zoom in.
  • ButtonBase VerticalZoomOutButton: ButtonBase inheritor, used for used for zoom out.
  • ButtonBase VerticalFitButton: ButtonBase inheritor, used for zoom to fit.
  • ButtonBase VerticalBackButton: ButtonBase inheritor, uset for zoom back.
  • RangeBase VerticalZoomRange: RangeBase inheritor that represents current scale, min scale and max scale.

In this demo application are modified only elements for horizontalorientation.

Change the control template in the MapNavigationPaneCustomStyle:

Change the number of columns to 5 in the HorizontalRoot Grid. Edit Rectangle elements,
used to represent the background to cover all columns:

 <Grid x:Name="HorizontalRoot">

    <Grid.ColumnDefinitions>

        <ColumnDefinition Width="auto"/>

        <ColumnDefinition Width="auto"/>                                   

        <ColumnDefinition Width="auto"/>

        <ColumnDefinition Width="auto"/>

        <ColumnDefinition Width="*"/>

    </Grid.ColumnDefinitions>

    <Rectangle Grid.ColumnSpan="5" Grid.Column="0" Fill="White" RadiusY="4" RadiusX="4"/>

    <Rectangle Grid.ColumnSpan="5" Grid.Column="0" Fill="{StaticResource GenericBackgroundGradient}" RadiusY="4" RadiusX="4" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1.3"/>

...

</Grid>

 

Change a Slider with a ProgressBar and add a Button for back navigation:

<Button x:Name="HorizontalZoomOutButton" Grid.Column="1" HorizontalAlignment="Center" Height="20" Style="{StaticResource ZoomOut}" VerticalAlignment="Center" Width="20"/>

<ProgressBar HorizontalAlignment="Left" Grid.Column="5" Visibility="Visible" Margin="0,20,0,20" Foreground="Red" x:Name="HorizontalZoomRange" Width="100" Background="{StaticResource ZoomPaneSliderOuterBevelTopFill}"/>

<Button x:Name="HorizontalZoomInButton" Grid.Column="2" HorizontalAlignment="Center" Height="20" Style="{StaticResource ZoomIn}" VerticalAlignment="Center" Width="20"/>

<Button x:Name="HorizontalBackButton" Grid.Column="3" Content="Back" Width="40" Margin="0,20,0,20" HorizontalAlignment="Right" d:LayoutOverrides="Width"/>

  

  • Run the sample application.

 

  

 A new MapNavigationPane UI.

Run the sample application.

This sample demonstrates the flexibility of MapNavigationPane control inside a XamMap components.
It can give very different components XamMap style, giving it a new interface.

For WPF implementation could be used an article: Using Infragistics XamMap Silverlight/WPF control with SQL Server Spatial


Example application code can be found here: