移动目标兵地图Silverlight的结合 [英] Bing map silverlight binding for moving target

查看:155
本文介绍了移动目标兵地图Silverlight的结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要到Bing地图上动态显示汽车点。我可以轻松地绘制多个点作为该项目周围的旅行,但我希望有每辆车围绕一个点移动。

I want to animate a "car" dot on a Bing map. I can easily draw multiple dots as the item travels around, but I want to have a single dot move around per car.

XAML

    <m:Map Name="myMap" Grid.Row="2" MouseClick="myMap_MouseClick" UseInertia="True">
    <m:MapLayer x:Name="carLayer" />
    </m:Map>

有些code:

private void AddCarDot(double latitude, double longitude)
{
    Ellipse point = new Ellipse();
    point.Width = 15;
    point.Height = 15;
    point.Fill = new SolidColorBrush(Colors.Blue);
    point.Opacity = 0.65;
    Location location = new Location(latitude, longitude);
    MapLayer.SetPosition(point, location);
    MapLayer.SetPositionOrigin(point, PositionOrigin.Center);

    carLayer.Children.Add(point);
}

private void cmbCar_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if(cmbCar.SelectedItem != null)
            {
                Binding binding = new Binding("CarLocation");
                binding.Source = cmbCar.SelectedItem;
                binding.Mode = BindingMode.OneWay;
                carLayer.SetBinding(MapLayer.PositionProperty, binding);
            }
        }

该CarLocation是类型所在地的轿车对象的属性。
然而,这并不工作,我不太清楚如何让车来移动地图。有人能指出我朝着正确的方向吗?

The CarLocation is a property on the Car object of type Location. However that does not work and I'm not quite sure how to get the "car" to move around the map. Can someone point me in the right direction?

推荐答案

好你的问题得到那种当cloudly一个神秘的taxiLayer出现正变得泥泞当你想将点就可以了,而不是绑定(我的猜测再度presents汽车)。

Well you're question kind gets cloudly when a mysterious "taxiLayer" appears positively gets muddy when you want set a binding on it instead of the "point" (which I guess represents a car).

需要做些什么是您使用 MapLayer.Position 依赖属性作为附加属性。当的UIElement到这个连接是一个 MapLayer 图层的孩子知道如何布局的。

What needs to happen is you are using the MapLayer.Position dependency property as an attached property. When the UIElement to which this is attached is a child of a MapLayer map layer knows how to layout it.

所以,问题是如何将分配一个绑定到该属性,以便当约束对象的值发生变化的位置被更新。我打算做一个假设在code的前面部分中创建的Elipse可作为现场我去叫。然后,code可能是这个样子: -

So the question is how would assign a binding to this property so that when the value of the bound object changes the position is updated. I'm going to make an assumption the Elipse created in the earlier part of the code is available as field I'll call car. Then the code might look something like this:-

private Elipse AddCarDot(object source)
{
    Ellipse point = new Ellipse();
    point.Width = 15;
    point.Height = 15;
    point.Fill = new SolidColorBrush(Colors.Blue);
    point.Opacity = 0.65;
    MapLayer.SetPositionOrigin(point, PositionOrigin.Center);
    point.SetBinding(MapLayer.PositionProperty, new Binding("CarLocation") {Source = source});
    carLayer.Children.Add(point);
}

private void cmbCar_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if(cmbCar.SelectedItem != null)
    {
        AddCarDot(cmbCar);
    }
}

现在假设你的对象,有一个 CarLocation 财产实施 INotifyPropertyChanged的这样的结合可以提醒当 CarLocation 改变点会适当地移动。

Now assuming you object that has a CarLocation property implement INotifyPropertyChanged so the binding can be alerted when CarLocation changes the dot will move appropriately.

这篇关于移动目标兵地图Silverlight的结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆