Tuesday, 10 July 2007

Synchronized dragging: Silverlight and Live Maps/Virtual Earth

Further to this post on Synchronizing Live Maps & Silverlight canvas, you can now pan by dragging rather than just using the rather clumsy up/down/left/right links: both the Silverlight Canvas containing the animation AND the underlying Microsoft Live Maps can be dragged (together)!

You can try out the demo of a Silverlight & Live Maps overlay with synchronized dragging to pan (it's not yet integrated into RaceReplay.net).

It was a relatively simple implementation of the sample code provided by then Silverlight Mouse Support documentation on MSDN. As with most Silverlight stuff, you can just View Source to see how it works...

Look out MapCruncher (joking!)

UPDATE: zooming now works too. When 'implementing' the Mouse Support example, I blindly copied
    canvasT.X = canvasPixel.x;
canvasT.Y = canvasPixel.y;
into onMouseUp(), forgetting that I was also updating
        sender["Canvas.Left"] += currX - beginX;
sender["Canvas.Top"] += currY - beginY;
in onMouseMove(). Oops. Better to update that same property and avoid applying the 'transformation' twice...
    sender["Canvas.Left"] = canvasPixel.x;
sender["Canvas.Top"] = canvasPixel.y;
Also added a new cursor to indicate the map is 'draggable' - unfortunately Silverlight has a limited set of cursors to choose from, so the hand-pointing is used rather than open-hand.

No comments:

Post a Comment