在GMap.net中进行缩放和平移

3
我试图让GMap.Net控制多点触控,并使用WPF内置事件,但我没有成功。
我找到了一系列有关多点触控的文章,例如这篇这篇。在所有这些文章中,ManipulationContainer是画布,可移动的控件放置在上面,但在GMap问题中,ManipulationContainerGMapControl,并且对其没有控制。我该如何使用e.ManipulationDelta数据进行缩放和移动? GMapControl有一个Zoom属性,通过增加或减小它,可以进行放大或缩小。
1个回答

3
快速查看代码可以发现,GMapControl是一个ItemsContainer
您应该能够重新定义ItemsPanel模板并在其中提供IsManipulationEnabled属性:
<g:GMapControl x:Name="Map" ...>
   <g:GMapControl.ItemsPanel>
       <ItemsPanelTemplate>
           <Canvas IsManipulationEnabled="True" />
       </ItemsPanelTemplate>
   </g:GMapControl.ItemsPanel>
   <!-- ... -->

此时,您需要连接Window

<Window ...
    ManipulationStarting="Window_ManipulationStarting"
    ManipulationDelta="Window_ManipulationDelta"
    ManipulationInertiaStarting="Window_InertiaStarting">

在Code Behind中提供适当的方法(从这个MSDN Walkthrough无耻地盗用并改编):

void Window_ManipulationStarting(
    object sender, ManipulationStartingEventArgs e)
{
    e.ManipulationContainer = this;
    e.Handled = true;
}

void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    // uses the scaling value to supply the Zoom amount
    this.Map.Zoom = e.DeltaManipulation.Scale.X;
    e.Handled = true;
}

void Window_InertiaStarting(
    object sender, ManipulationInertiaStartingEventArgs e)
{
    // Decrease the velocity of the Rectangle's resizing by 
    // 0.1 inches per second every second.
    // (0.1 inches * 96 pixels per inch / (1000ms^2)
    e.ExpansionBehavior.DesiredDeceleration = 0.1 * 96 / (1000.0 * 1000.0);
    e.Handled = true;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接