in TrafficApp/MainPage.xaml.cs [219:246]
private async Task ResetViewAsync(bool isGeolocatorReady = true)
{
LocationData currentLocation = null;
if (isGeolocatorReady) currentLocation = await this.GetCurrentLocationAsync();
if (currentLocation != null)
{
if (this.MappedLocations.Count > 0 && this.MappedLocations[0].IsCurrentLocation)
{
this.MappedLocations.RemoveAt(0);
}
this.MappedLocations.Insert(0, new LocationData { Position = currentLocation.Position, IsCurrentLocation = true });
}
// Set the current view of the map control.
var positions = this.Locations.Select(loc => loc.Position).ToList();
if (currentLocation != null) positions.Insert(0, currentLocation.Position);
var bounds = GeoboundingBox.TryCompute(positions);
double viewWidth = ApplicationView.GetForCurrentView().VisibleBounds.Width;
var margin = new Thickness((viewWidth >= 500 ? 300 : 10), 10, 10, 10);
bool isSuccessful = await this.InputMap.TrySetViewBoundsAsync(bounds, margin, MapAnimationKind.Default);
if (isSuccessful && positions.Count < 2) this.InputMap.ZoomLevel = 12;
else if (!isSuccessful && positions.Count > 0)
{
this.InputMap.Center = new Geopoint(positions[0]);
this.InputMap.ZoomLevel = 12;
}
if (currentLocation != null) await this.TryUpdateLocationsTravelInfoAsync(this.Locations, currentLocation);
}