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.

mapsv2

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 ^-^

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s