【问题标题】:Windows 10 UWP MapControl moved eventWindows 10 UWP MapControl 移动事件
【发布时间】:2015-08-24 20:50:48
【问题描述】:

当用户手动移动地图时,我想评估一些标准,并在完成后选择做一些事情。我似乎找不到合适的 MapControl event 来解决这个问题。

我尝试过使用CenterChanged,但它会在地图移动时不断触发并降低性能。

我可以使用哪个MapControl 事件来了解用户何时完成移动地图?

【问题讨论】:

  • 您可以使用 ManipulationCompleted 事件。否则,典型的方法是在 CenterChanged 处理程序中停止和重新启动计时器,并在计时器的 Tick 处理程序中进行最终处理。
  • 感谢您的评论。我之前尝试过使用 ManipulationCompleted 但该事件永远不会触发。你有计时器方法的例子吗?
  • 您必须将 ManipulationMode 设置为 None 或 System 以外的值,例如对所有。见here
  • 我也看到了。没有任何区别。该事件永远不会触发。
  • 我记得在 WP 中的一些内容,我会看看

标签: xaml uwp bing-maps uwp-maps


【解决方案1】:

我知道我已经晚了大约一年,但万一有人遇到这个问题......我很确定正确的方法是听LoadingStatusChanged 事件,然后采取当你回来时采取行动MapLoadingStatus.Loaded

public void LoadingStatusChangedEventHandler(MapControl sender, Object o)
{
    if (sender.LoadingStatus == MapLoadingStatus.Loaded)
    {
        // The map has stopped moving and finished rendering
        DoSomething();
    }
}

我知道该活动的文档不是很好,但this code sample 有更多信息,您可以在git repo 上找到更多信息。

【讨论】:

  • 这是最好的解决方案。正是我需要的。感谢分享。
【解决方案2】:

我最终使用计时器每秒检查一次地图中心并相应地更新我的视图模型。对我来说,这感觉像是一个 hack,但它比使用 CenterChanged 性能要好得多。 DispatchTimer 用于允许计时器在 UI 线程上运行,因此它可以访问 MapControl

DispatcherTimer mapCenterTimer = new DispatcherTimer();
mapCenterTimer.Tick += (object sender, object e) =>
{
  ViewModel.MapCenter = MyMapControl.Center;
};
mapCenterTimer.Interval = new TimeSpan(0, 0, 1); // fire every second
mapCenterTimer.Start();

如果 MapControl 为我们这些想要在用户完成移动地图时采取行动的人公开某种 ManualMoveComplete 事件,那肯定会很好。我在 uservoice 上创建了一个请求:https://binglistens.uservoice.com/forums/283355-ideas/suggestions/9494889-add-a-centermanuallychanged-event-to-mapcontrol

【讨论】:

    【解决方案3】:

    我同意你的观点,我更喜欢某种延迟事件,我也更喜欢详细的控件,而是自己过滤事件。从您的解决方案中,不是每秒触发一个定期计时器,而是在事件触发时重新启动它。当事件停止触发时,计时器将计时,您将获得最终值:

    DispatcherTimer mapCenterTimer = new DispatcherTimer();
    mapCenterTimer.Tick += (object sender, object e) =>
    {
      mapCenterTimer.Stop();
      ViewModel.MapCenter = MyMapControl.Center;
    };
    mapCenterTimer.Interval = TimeSpan.FromMilliseconds(500); // map idle for .5 seconds
    MyMapControl.CenterChanged += (map, args) => { mapCenterTimer.Stop(); mapCenterTimer.Start(); };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      • 2016-01-24
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多