如何在bing map wpf中使推针在地图上拖动

时间:2012-03-28 11:14:29

标签: c# wpf bing-maps bing-api

我正在研究bingmap wpf。我在鼠标点击事件上创建了图钉。现在我需要使其可拖动并根据图钉位置跟踪坐标。任何人都知道如何使图钉可拖动,以及我们需要在哪个函数中编写代码以便在发布时进行更新。

非常感谢您提前

1 个答案:

答案 0 :(得分:6)

Vector _mouseToMarker;
private bool _dragPin;
public Pushpin SelectedPushpin { get; set; }

void pin_MouseDown(object sender, MouseButtonEventArgs e)
{
  e.Handled = true;
  SelectedPushpin = sender as Pushpin;
  _dragPin = true;
  _mouseToMarker = Point.Subtract(
    map.LocationToViewportPoint(SelectedPushpin.Location), 
    e.GetPosition(map));
}

private void map_MouseMove(object sender, MouseEventArgs e)
{
  if (e.LeftButton == MouseButtonState.Pressed)
  {
    if (_dragPin && SelectedPushpin != null)
    {
      SelectedPushpin.Location = map.ViewportPointToLocation(
        Point.Add(e.GetPosition(map), _mouseToMarker));
      e.Handled = true;
    }
  }
}