Zoom et panoramique dans GMap.net
-
14-11-2019 - |
Question
j'essaie de faire GMap.Net contrôle multitouch activé, en utilisant les événements intégrés WPF, mais je n'ai pas réussi.
J'ai trouvé une série d'articles sur le multitouch comme ce et ce un.Dans chacun d'eux, ManipulationContainer
est un canevas et des contrôles mobiles placés dessus, mais dans un problème GMap ManipulationContainer
est GMapControl
et il n'y a aucun contrôle dessus.comment puis-je utiliser e.ManipulationDelta
données à zoomer et à déplacer ?
Le GMapControl
a un Zoom
propriété qui en l'augmentant ou en la diminuant, vous pouvez zoomer ou dézoomer.
La solution
Un rapide coup d'œil au code montre que le GMapControl
est un ItemsContainer
.
Vous devriez pouvoir relooker le ItemsPanel
modèle et fournir le IsManipulationEnabled
propriété là-bas :
<g:GMapControl x:Name="Map" ...>
<g:GMapControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas IsManipulationEnabled="True" />
</ItemsPanelTemplate>
</g:GMapControl.ItemsPanel>
<!-- ... -->
À ce stade, vous devez câbler le Window
:
<Window ...
ManipulationStarting="Window_ManipulationStarting"
ManipulationDelta="Window_ManipulationDelta"
ManipulationInertiaStarting="Window_InertiaStarting">
Et fournissez les méthodes appropriées dans le Code Behind (volé sans vergogne et adapté de ce Procédure pas à pas 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;
}