Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MapControl の表示を良い感じにするやつ
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.Map.Loaded += Map_Loaded;
base.OnNavigatedTo(e);
}
private async void Map_Loaded(object sender, RoutedEventArgs e)
{
await ApplyMapView(new[]
{
new Windows.Devices.Geolocation.BasicGeoposition{Latitude = 35.75, Longitude = 139.79 },
new Windows.Devices.Geolocation.BasicGeoposition{Latitude = 35.80, Longitude = 139.81 },
new Windows.Devices.Geolocation.BasicGeoposition{Latitude = 35.81, Longitude = 139.81 },
new Windows.Devices.Geolocation.BasicGeoposition{Latitude = 35.84, Longitude = 139.84 }
});
}
public async Task ApplyMapView(IEnumerable<Windows.Devices.Geolocation.BasicGeoposition> positions)
{
// 与えられた位置情報から北東・南西・中心の位置を割り出す
var boundingBox = Windows.Devices.Geolocation.GeoboundingBox.TryCompute(positions);
// さいしょ
var mapStartPin = new Windows.UI.Xaml.Controls.Maps.MapIcon
{
Location = new Windows.Devices.Geolocation.Geopoint(positions.First()),
NormalizedAnchorPoint = new Point(0.5, 0.5)
};
// おわり
var mapEndPin = new Windows.UI.Xaml.Controls.Maps.MapIcon
{
Location = new Windows.Devices.Geolocation.Geopoint(positions.Last()),
NormalizedAnchorPoint = new Point(0.5, 0.5)
};
// 軌跡
var line = new Windows.UI.Xaml.Controls.Maps.MapPolyline
{
Path = new Windows.Devices.Geolocation.Geopath(positions),
StrokeColor = Colors.Blue,
StrokeThickness = 2,
};
this.Map.MapElements.Add(line);
this.Map.MapElements.Add(mapStartPin);
this.Map.MapElements.Add(mapEndPin);
// 範囲に収める
await this.Map.TrySetViewBoundsAsync(boundingBox, new Thickness(100), Windows.UI.Xaml.Controls.Maps.MapAnimationKind.Default);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment