Adding Tile Overlays to the Map
This topic describes how to add image overlays from existing tile sources using the Bing Maps Silverlight Control. It does not describe how to create your own overlays using tools such as MapCruncher. In order to add a tile overlay to a location on your map, you need to:
-
Specify the tile source (TileSource) of the overlay.
-
Define the area of coverage where the tile source is valid.
-
Create a tile map layer (MapTileLayer) in which to add the tile source.
The following example retrieves image data from the specified tile source, and displays images from the tile source that fall within the specified LocationRect. The LocationRectTileSource object defines the bounding rectangle as well as the valid zoom levels for the tile overlays. Tile overlays that fall outside the bounding rectangle or zoom range do not show up on the map.
After you define the valid coverage area for the tile overlays, add the tile source to a MapTileLayer. The map tile layer is then added to a MapLayer and the tile overlay shows up on the map. This particular example retrieves a terrain overlay for the specified area on the map.
The terrain tile overlay added to the map
<UserControl x:Class="SilverlightTest1.TileOverlay" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:m="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl" Width="1024" Height="768"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="35" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="100" /> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Button x:Name="btnAddTileLayer" Click="btnAddTileLayer_Click" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="0"> <TextBlock x:Name="txtButton">Add Tile Layer</TextBlock> </Button> <Button x:Name="btnRemoveTileLayer" Click="btnRemoveTileLayer_Click" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="0"> <TextBlock x:Name="txtButton2">Remove Tile Layer</TextBlock> </Button> <m:Map x:Name="MapTileOverlay" CredentialsProvider="your key" Mode="Road" Center="48.03,-122.4" ZoomLevel="10" Grid.ColumnSpan="2" Grid.Column="0" Grid.Row="1" /> </Grid> </UserControl>