【问题标题】:Bing maps WPF multitouchdemo必应地图 WPF 多点触控演示
【发布时间】:2014-09-06 17:22:20
【问题描述】:

我创建了一个带有 Bing 地图的简单 WPF 应用程序。问题是当我尝试在带有触摸输入的 PC 上运行我的程序时,它变得非常不稳定:当您尝试缩放或平移地图时,它很难滞后。 顺便说一句,相同的应用程序在桌面上正常运行,您只能使用鼠标进行导航。此外,当您在此触摸设备上的浏览器中打开 Bing 地图时,一切正常,所以我认为问题出在代码中,与硬件无关。

我做了一些积极的步骤:现在我在我的代码中处理操作事件(第一次我没有为地图实现任何控制功能,所以每个操作都由默认事件处理程序处理)。它改善了这种情况,当您尝试缩放或平移地图时,地图也不会那么滞后了。

但是我遇到了另一个问题。在应用程序工作流程中,我向地图添加了大约 200 条折线,当它发生时,触摸控制的问题返回并且地图再次变得不稳定。

这是项目中的一些代码:

MainWindow.xaml

<Window x:Class="NYCTraffic.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"

        ManipulationDelta="Window_ManipulationDelta" 

        Title="MainWindow" WindowState="Maximized">
    <Grid>
        <m:Map Name="map" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Row="0"
                   CredentialsProvider="myKey"
                   MouseLeftButtonDown="map_MouseLeftButtonDown" SupportedManipulations="Translate,Scale"
                   IsManipulationEnabled="True" TouchUp="map_TouchUp" AnimationLevel="None"
                   Center="40.714623, -74.006605" ZoomLevel="13" >
        </m:Map>
    </Grid>
</Window>

MainWindow.xaml.cs

public MainWindow()
{
    InitializeComponent();

    map.Focus();
    map.ZoomLevel = DEFAULT_ZOOM;
}

private void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    if (e.Manipulators.Count() == 1)
    {
        long dx = (long)-e.DeltaManipulation.Translation.X;
        long dy = (long)-e.DeltaManipulation.Translation.Y;
        if (Math.Abs(dx) >= SystemParameters.MinimumHorizontalDragDistance ||
            Math.Abs(dy) >= SystemParameters.MinimumVerticalDragDistance)
        {
            var p = map.Center;
            var pLocal = map.LocationToViewportPoint(p);
            pLocal.Offset(dx, dy);
            map.Center = map.ViewportPointToLocation(pLocal);
        }
    }
    else
    {
        map.ZoomLevel = Math.Log(Math.Pow(2, map.ZoomLevel) * e.DeltaManipulation.Scale.Length / Math.Sqrt(2), 2);
    }
    e.Handled = true;
}

这不是程序的全文,但我认为它与我的问题最相关。

那么,有人有什么建议吗?

【问题讨论】:

  • 这是一个已知问题。 WPF 控件是在 Windows 8 之前构建的,旨在与原始 Microsoft Surface 设备(台式计算机)中的触摸传感器配合使用。
  • @rbrundritt 好吧,很伤心 =( 那么,这是否意味着在 WPF 应用程序中没有办法避免这个问题?
  • 我还没有遇到任何人自己设法解决了这个问题。通常他们只是禁用触摸事件。这被记录为要在 WPF 控件中修复的错误。
  • @rbrundritt。不幸的是,我不能让自己禁用触摸事件。在我的应用程序中,我尝试使用另一个地图 (greatmaps.codeplex.com),它有点帮助 - 现在触摸操作看起来几乎不错,但有几个小缺点,所以它不是一个真正的解决方案。

标签: c# wpf bing-maps multi-touch


【解决方案1】:

Bing Maps WPF 地图控件已更新,修复了触摸功能。您可以在此处下载更新的库:http://www.microsoft.com/en-us/download/details.aspx?id=27165

您也可以使用 Nuget 访问地图控件库:https://www.nuget.org/packages/Microsoft.Maps.MapControl.WPF/1.0.0.3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多