2012-02-29 192 views
3

我试图让GMap.Net控制多点触控启用,使用WPF内置事件,但我没有成功。缩放和平移在GMap.net

我发现了一系列有关多点触控的文章,如thisthis之一。在所有这些中,ManipulationContainer是放置在其上的画布和可移动控件,但是在GMap问题ManipulationContainer中是GMapControl,并且不能控制它。我如何使用e.ManipulationDelta数据进行缩放和移动?

GMapControl有一个Zoom财产,通过增加或减少它,你可以放大或缩小。

回答

3

快速查看代码显示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; 
}