如何使图钉在bingmap wpf的地图上拖动

本文关键字:地图 拖动 wpf bingmap 何使图 | 更新日期: 2023-09-27 18:29:10

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

提前非常感谢

如何使图钉在bingmap wpf的地图上拖动

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;
    }
  }
}