Adding airport locations to VirtualEarth, Part 2
I went to Remix today and found out that the well regarded VirtualEarth brand is now known as ‘Bing Maps‘. I prefer Virtual Earth, but Microsoft were right to bring all their online services together as Bing, if only for the fact it makes it easier to explain.
Yesterday I added 6,000 pushpins to a layer on top of my map. This seemed to be way too much for Silverlight, and performance suffered.
I didn’t actually require every single airport code in the world, and I found this list of 1900 codes from this website. There was no location data, but I was able to filter my origional list of 6,000 against it with good success. The smaller list was clearer and performance much improved.
I also added some extra data as a tooltip with each pushpin, such as the Airport name, code and associated city.

Creating a tooltip is really easy. First I defined a really simple control to display these vales:
<UserControl
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
x:Class="FlightTracks.Controls.AirportTooltip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="125" Height="50">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock Text="{Binding Code}"></TextBlock>
<TextBlock Text="{Binding City}"></TextBlock>
</StackPanel>
</Grid>
</UserControl>
I then bound it to each ‘Airport’ object I had, and then made it part of the Tooltips content. Finally I set the tooltip to the pushpin image:
private Image CreateImage(BitmapImage bmp, Airport airport)
{
// Picture of pushpin
Image image = new Image();
image.Source = bmp;
image.Opacity = 0.8;
image.Stretch = Stretch.None;
// Content of Tooltip
Controls.AirportTooltip at = new Controls.AirportTooltip();
at.DataContext = airport;
// Tooltip
ToolTip toolTip = new ToolTip();
toolTip.Content = at;
// Add tooltip to Image
ToolTipService.SetToolTip(image, toolTip);
return image;
}
It is a pity I only get an hour or so to play with this each night! When I finished I’ll release the code on Codeplex and write a large article about all the steps ^-^