I'm trying to make GMap.Net control multitouch enabled, using WPF build-in events but i wasn't successful.
I found a series of articles about multitouch like this and this one. In all of them, ManipulationContainer
is a canvas and movable controls placed on it, but in GMap issue ManipulationContainer
is GMapControl
and there is no control over it. how can i use e.ManipulationDelta
data to Zoom and Move?
The GMapControl
has a Zoom
property which by increase or decreasing it, you can zoom in or zoom out.
A quick look at the code shows that the GMapControl
is an ItemsContainer
.
You should be able to restyle the ItemsPanel
template and supply the IsManipulationEnabled
property there:
<g:GMapControl x:Name="Map" ...>
<g:GMapControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas IsManipulationEnabled="True" />
</ItemsPanelTemplate>
</g:GMapControl.ItemsPanel>
<!-- ... -->
At this point you need to wire up the Window
:
<Window ...
ManipulationStarting="Window_ManipulationStarting"
ManipulationDelta="Window_ManipulationDelta"
ManipulationInertiaStarting="Window_InertiaStarting">
And supply the appropriate methods in the Code Behind (shamelessly stolen and adapted from this 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;
}