Technology

Bing Maps Silverlight - smooth zoom skydive animation

Anthony Marshall
Anthony Marshall
11 Oct 2012
blog post featured image

In 2010 Austrian skydiver Felix Baumgartner teamed up with scientists and Red Bull to form the Red Bull Stratos; a project that aims to see Baumgartner free fall from a height of 120 000 feet; the edge of space; to the surface of planet Earth.

Have you ever wondered what this would feel like ? On Sunday Baumgartner will be making his leap, travelling the 23 miles at eye-watering super-sonic speeds, in his attempt to be the first human to break the sound barrier.

[https://www.telegraph.co.uk/science/space/9600661/Felix-Baumgartner-to-make-space-jump-attempt-on-Sunday.html]

If  this isn't something you personally fancy, you could always gain a similar experience by using the Silverlight Bing Maps Control; not quite as glamorous, but, equally not as uncomfortable.

Two years ago when the project was announced we developed a Silverlight application and map that starts zoomed out from your landing point and then smoothly animates the ZoomLevel parameter to mimic ‘plummeting’ to earth.

Read the previous blog post below to find out how we did this, and to take a look at the animation we generated...

... The problem is that the default map animation moves too quickly and you cannot animate the Map controls ZoomLevel property yourself from a Storyboard, as Storyboard animations only operate on DependencyProperties.

ZoomLevel is not the only value that developers have needed to animate in past that has not been a DependencyProperty. The solution is to set the Storyboard animation to target your own class member as a DependencyProperty which in turn can modify your intended object member.

Code Snippet
  1. <Storyboard x:Name="ZoomIn">
  2. <DoubleAnimation x:Name="ZoomLevel"
  3. Storyboard.TargetName="MainMap"
  4. From="3.0"
  5. To="5.0"
  6. Duration="0:0:9" />
  7. </Storyboard>
Within your Silverlight control constructor.
Code Snippet
  1. Storyboard.SetTargetProperty(ZoomLevel,
  2. new PropertyPath(
  3. Attachments.MapZoomLevelProperty
  4. )
  5. );
Handy Attachments utility class
Code Snippet
  1. public partial class Attachments
  2. {
  3. // Map Zoom level property
  4. public static readonly DependencyProperty
  5. MapZoomLevelProperty =
  6. DependencyProperty.RegisterAttached("MapZoomLevel",
  7. typeof(double), typeof(Attachments),
  8. new PropertyMetadata(
  9. new PropertyChangedCallback(OnMapZoomLevelChanged)));
  10. public static void SetMapZoomLevel(DependencyObject o,
  11. double value)
  12. {
  13. o.SetValue(MapZoomLevelProperty, value);
  14. }
  15. public static double GetMapZoomLevel(DependencyObject o)
  16. {
  17. return (double)o.GetValue(MapZoomLevelProperty);
  18. }
  19. private static void OnMapZoomLevelChanged(DependencyObject d,
  20. DependencyPropertyChangedEventArgs e)
  21. {
  22. double z = (double)((Map)d).ZoomLevel;
  23. z = (double)e.NewValue;
  24. ((Map)d).ZoomLevel = z;
  25. }
  26. }
Most of this was gleaned from [https://www.conceptdevelopment.net/Silverlight/VEMap05/] and [https://bryantlikes.com/archive/2009/03/23/animation-hack-using-attached-properties-in-silverlight.aspx]

Just to make things a little more realistic the Map object centre Location property can be animated to provide wind shear.Instead of animating the Latitude and Longitude separately a Point based DependencyProperty can be created.

Code Snippet
  1. <Storyboard x:Name="CenterMap">
  2. <PointAnimation
  3. x:Name="CenterPoint"
  4. Storyboard.TargetName="MainMap"
  5. From="5.0,50.0"
  6. To="-8.0,56.0"
  7. Duration="0:0:14" />
  8. </Storyboard>
Within your Silverlight control constructor.
Code Snippet
  1. Storyboard.SetTargetProperty(CenterPoint,
  2. new PropertyPath(
  3. Attachments.MapCenterPositionProperty
  4. )
  5. );
New property for the Attachments utility class
Code Snippet
  1. // Map Center Position Property as a Point
  2. public static readonly DependencyProperty
  3. MapCenterPositionProperty =
  4. DependencyProperty.RegisterAttached(
  5. "MapCenterPosition",
  6. typeof(Point),
  7. typeof(Attachments),
  8. new PropertyMetadata(
  9. new PropertyChangedCallback(
  10. OnMapCenterPositionChanged)));
  11. public static void SetMapCenterPosition(
  12. DependencyObject o, Point value)
  13. {
  14. o.SetValue(MapCenterPositionProperty, value);
  15. }
  16. public static Point GetMapCenterPosition(
  17. DependencyObject o)
  18. {
  19. return (Point)o.GetValue(MapCenterPositionProperty);
  20. }
  21. private static void OnMapCenterPositionChanged(
  22. DependencyObject d,
  23. DependencyPropertyChangedEventArgs e)
  24. {
  25. Location l = (Location)((Map)d).GetValue(
  26. Map.CenterProperty);
  27. Point p = new Point(l.Latitude, l.Longitude);
  28. p = (Point)e.NewValue;
  29. double z = (double)((Map)d).ZoomLevel;
  30. // Y is Latitude, X is Longitude
  31. ((Map)d).SetView(new Location(p.Y, p.X), z);
  32. }
Now clip the Map to a circle and animate the containers Angle with a regular DoubleAnimation to create a truly sickening spiralling to the ground experience.

skydive2 skydive3

The smooth zooming and panning was used to great effect to navigate around the South Africa world cup football stadiums in time with HD video in our World Cup map https://www.theworldcupmap.com

start skydive demo download SkyDive project

Close chatbot
Open chatbot
Open chatbot