Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimating a marker pin on Bing Maps for Metro apps
    primarykey
    data
    text
    <p>I have a Bing Map control and I want to animate the location of a pin drawn on the map.</p> <p>Ideally I'd want to write code like this: </p> <pre class="lang-cs prettyprint-override"><code>// Image myPin = some Image on the map layer; var sb = new Storyboard(); var duration = DurationHelper.FromTimeSpan(System.TimeSpan.FromMilliseconds(1000)); sb.Duration = duration; LocationAnimation ani = new LocationAnimation(); ani.To = new Location(33.3, 11.1); // destination lat, lng ani.Duration = duration; sb.Children.Add(ani); Storyboard.SetTarget(ani, myPin); Storyboard.SetTargetProperty(ani, "MapLayer.Position"); Resources.Add("moveMyPin", sb); sb.Begin(); </code></pre> <p>Of course there is no <code>LocationAnimation</code> class in the framework. There are a couple similar: <code>PointAnimation</code> works with the <code>Point</code> type, while <code>DoubleAnimation</code> works with individual <code>double</code> values.</p> <p>I assumed I have to implement my <code>Timeline</code>-derived class but the documentation I found so far is not helpful in this regard and I don't know where to start.</p> <p>How to animate a property for which there is no *Animation class ready? Am I missing something?</p> <p><strong>Update</strong>: I <em>think</em> I can do something like</p> <pre class="lang-cs prettyprint-override"><code>// let aniX and aniY be two DoubleAnimation objects StoryBoard.SetTargetProperty(aniX, "(MapLayer.Position).Latitude") StoryBoard.SetTargetProperty(aniY, "(MapLayer.Position).Longitude") </code></pre> <p>but now I have another problem as I don't see how to animate the attached property and always get an exception like "Cannot resolve TargetProperty (MapLayer.Position).Latitude on specified object."</p> <p>So I guess the question now becomes: <em>how to specify a property path for an attached property?</em></p> <p><strong>Further update</strong>: I may be on a wrong lead with the "SetTargetProperty" thing as that would make a <em>dependent animation</em> (see link in comments). Could there be a better way to animate a marker pin to a coordinate destination?</p> <p><strong>Update 3</strong>: as Jared pointed out I could try to animate <code>RenderTransform</code>, or use a transition to achieve my result. I had already gone this way and it doesn't seem to be my solution. This is what I found out:</p> <ul> <li>Using <code>RepositionThemeAnimation</code>, it seems I have to give the new pixel position of the pin. This is problematic for a couple reasons: first, I know the lat/lng destination of the pin, but would have to work out the projection (as far as I can tell there is no public interface to work with projection). Secondly the projection itself can change as the map zooms/pans. The pixel destination at the time of the end of the animation could not be the same as the initial pixel destination. In my scenario it's a major problem as it's very likely the map is moving while the animation is occurring.</li> <li>Using <code>RepositionThemeTransition</code> all the weird pixel/projection problems went away. It's the only way so far I was able to see the animation I expected. I just set the transition and set the new lat/lng position of the tag (via MapLayer.SetPosition). It has two major problems though. I can't set the duration (nor the easing functions) for the animation. And most importantly I can see no way to execute code when the pin gets to its final position.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload