繁体   English   中英

在 GMap.net 中缩放和平移

[英]Zoom and Pan in GMap.net

我正在尝试使用 WPF 内置事件启用GMap.Net控件多点触控,但我没有成功。

我找到了一系列关于像这样这样的多点触控的文章。 在所有这些中, ManipulationContainer是一个画布和放置在其上的可移动控件,但在 GMap 问题中ManipulationContainerGMapControl并且无法对其进行控制。 我如何使用e.ManipulationDelta数据进行缩放和移动?

GMapControl有一个Zoom属性,通过增加或减少它,您可以放大或缩小。

快速查看代码会发现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">

并在代码隐藏中提供适当的方法(无耻地窃取并改编自此 MSDN 演练):

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM