【问题标题】:Zoom and Pan in GMap.netGMap.net 中的缩放和平移
【发布时间】:2012-03-19 03:08:56
【问题描述】:
我正在尝试使用 WPF 内置事件启用 GMap.Net 控件多点触控,但我没有成功。
我发现了一系列关于多点触控的文章,例如 this 和 this one。在所有这些中,ManipulationContainer 是一个画布和放置在其上的可移动控件,但在 GMap 问题中,ManipulationContainer 是GMapControl,并且无法控制它。如何使用e.ManipulationDelta 数据进行缩放和移动?
GMapControl 有一个Zoom 属性,通过增加或减少它,您可以放大或缩小。
【问题讨论】:
标签:
c#
wpf
c#-4.0
multi-touch
gmap.net
【解决方案1】:
快速查看代码显示GMapControl is an 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 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;
}