protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); busArrivalUpdateTimer.Start(); viewModel.RegisterEventHandlers(Dispatcher); UpdateAppBar(true); if (isFiltered == true) { viewModel.LoadArrivalsForStop(viewModel.CurrentViewState.CurrentStop, viewModel.CurrentViewState.CurrentRoute); } else { viewModel.LoadArrivalsForStop(viewModel.CurrentViewState.CurrentStop, null); } // When we enter this page after tombstoning often the location won't be available when the map // data binding queries CurrentLocationSafe. The center doesn't update when the property changes // so we need to explicitly set the center once the location is known. viewModel.LocationTracker.RunWhenLocationKnown(delegate(GeoCoordinate location) { Dispatcher.BeginInvoke(() => { DetailsMap.Center = location; //calculate distance to current stop and zoom map if (viewModel.CurrentViewState.CurrentStop != null) { if (location.IsUnknown || location.Latitude < -90.0 || location.Latitude > 90 || location.Longitude < -180.0 || location.Longitude > 180) { // location is bogus. don't try to set the map view with it. } else { GeoCoordinate stoplocation = new GeoCoordinate(viewModel.CurrentViewState.CurrentStop.coordinate.Latitude, viewModel.CurrentViewState.CurrentStop.coordinate.Longitude); double radius = 2 * location.GetDistanceTo(stoplocation) * 0.009 * 0.001; // convert metres to degrees and double radius = Math.Max(radius, minimumZoomRadius); radius = Math.Min(radius, maximumZoomRadius); DetailsMap.SetView(new LocationRect(location, radius, radius)); } } DetailsMap_MapZoom(this, null); }); } ); }
void FullScreenMapPage_Loaded(object sender, RoutedEventArgs e) { if (viewModel.CurrentViewState.CurrentSearchLocation != null) { // Using mapHasMoved prevents us from relocating the map if the user reloads this // page from the back stack if (mapHasMoved == false) { Dispatcher.BeginInvoke(() => { //DetailsMap.Center = viewModel.CurrentViewState.CurrentSearchLocation.location; DetailsMap.SetView(viewModel.CurrentViewState.CurrentSearchLocation.boundingBox); viewModel.LoadStopsForLocation(viewModel.CurrentViewState.CurrentSearchLocation.location); } ); } } else { viewModel.LocationTracker.RunWhenLocationKnown(delegate(GeoCoordinate location) { Dispatcher.BeginInvoke(() => { // If the user has already moved the map, don't relocate it if (mapHasMoved == false) { DetailsMap.Center = location; } viewModel.LoadStopsForLocation(location); } ); } ); } }