Created
December 28, 2018 04:58
-
-
Save Iyemon-018/2d7619744fd6bd1130a28e4b2ec47343 to your computer and use it in GitHub Desktop.
MapControl に関するコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace XamlIslands.Wpf | |
{ | |
using System; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using System.Windows.Controls; | |
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT; | |
/// <summary> | |
/// MainWindow.xaml の相互作用ロジック | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
private bool _isLoadedMap; | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
private async void MapControl_OnLoaded(object sender, RoutedEventArgs e) | |
{ | |
BasicGeoposition cityPosition = new BasicGeoposition {Latitude = 34.702476, Longitude = 135.495946}; | |
Geopoint cityCenter = new Geopoint(cityPosition); | |
while (!_isLoadedMap) | |
{ | |
// animation が設定されていると座標移動に時間がかかる。 | |
// 初期座標を設定するならMapAnimationKind.None がよさげ。 | |
bool result = await MapControl.TrySetViewAsync(center: cityCenter, zoomLevel: 14, heading: 0 | |
, desiredPitch: 0, animation: MapAnimationKind.None); | |
if (!result) | |
{ | |
// 1回では初期座標の設定が失敗する可能性が高い。 | |
// 成功するまで間隔おいて再チャレンジする。 | |
await Task.Delay(TimeSpan.FromMilliseconds(500)); | |
continue; | |
} | |
_isLoadedMap = true; | |
} | |
ZoomSlider.Value = 14; | |
} | |
private async void ZoomSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) | |
{ | |
await MapControl.TryZoomToAsync((double) (sender as Slider)?.Value); | |
} | |
private async void RotateSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) | |
{ | |
if (!_isLoadedMap) | |
{ | |
return; | |
} | |
await MapControl.TryRotateToAsync(RotateSlider.Value); | |
} | |
private async void TiltSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) | |
{ | |
if (!_isLoadedMap) | |
{ | |
return; | |
} | |
await MapControl.TryTiltToAsync(TiltSlider.Value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment