التكبير/التصغير والتحريك في GMap.net
-
14-11-2019 - |
سؤال
أحاول أن أجعل GMap.Net تم تمكين التحكم في اللمس المتعدد باستخدام أحداث WPF المضمنة ولكني لم أنجح.
لقد وجدت سلسلة من المقالات حول اللمس المتعدد مثل هذا و هذا واحد.في كل منهم، ManipulationContainer
عبارة عن لوحة قماشية وعناصر تحكم منقولة موضوعة عليها، ولكن في مشكلة GMap ManipulationContainer
يكون GMapControl
وليس هناك سيطرة عليه.كيف يمكنني استخدام 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">
وتزويد الأساليب المناسبة في Code Behind (مسروقة بلا خجل ومقتبسة من هذا.) تجول 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;
}