/// <summary> /// Copies data from another map control view model. /// </summary> public void CopyFrom(MapControlViewModel other) { this.userLocation = other.userLocation; this.busStops = other.busStops; this.mapView = other.mapView; this.shapes = other.shapes; this.selectedBusStop = other.selectedBusStop; }
/// <summary> /// Called when a stop is selected. /// </summary> public void SelectStop(BusStopControlViewModel busStopViewModel) { var stopSelected = this.StopSelected; if (stopSelected != null) { this.UnSelectStop(); this.SelectedBusStop = busStopViewModel; this.SelectedBusStop.ZIndex = 100; stopSelected(this, new StopSelectedEventArgs(busStopViewModel.StopName, busStopViewModel.StopId, busStopViewModel.Direction, busStopViewModel.Latitude, busStopViewModel.Longitude)); } }
private static async void BusStopsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var mapControl = d as MapControl; if (e.NewValue == null) { mapControl.displayedBusStopLookup.Clear(); mapControl.map.Children.Clear(); mapControl.map.Children.Add(mapControl.userLocationIcon); MapLayer.SetPosition(mapControl.userLocationIcon, mapControl.userLocation); } else { MapControlViewModel mapControlViewModel = (MapControlViewModel)mapControl.DataContext; var stops = e.NewValue as BusStopList; if (stops.ClearExistingStops) { // If the clear existing stops property is set to true, // then we should clear the existing stops: mapControl.map.Children.Clear(); mapControl.displayedBusStopLookup.Clear(); } foreach (var stop in stops) { // If we're not already displaying this bus stop then add it to the list: if (!mapControl.displayedBusStopLookup.Contains(stop.StopId)) { BusStopControlViewModel busStopControlViewModel = new BusStopControlViewModel(stop); if (mapControlViewModel.SelectedBusStop != null) { busStopControlViewModel.IsSelected = string.Equals(mapControlViewModel.SelectedBusStop.StopId, stop.StopId, StringComparison.OrdinalIgnoreCase); if (busStopControlViewModel.IsSelected) { mapControlViewModel.SelectedBusStop = busStopControlViewModel; } } BusStop busStopIcon = new BusStop(); busStopIcon.ViewModel = busStopControlViewModel; mapControl.map.Children.Add(busStopIcon); // Wait for the UI to idle before we add another bus stop to make the UI more responsive: await mapControl.uiHelper.WaitForIdleAsync(); mapControl.displayedBusStopLookup.Add(stop.StopId); MapLayer.SetPosition(busStopIcon, new Location(stop.Latitude, stop.Longitude)); } } } }
/// <summary> /// Clears the view model when we're unloaded. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnUnloaded(object sender, RoutedEventArgs e) { if (this.viewModel != null) { this.viewModel.PropertyChanged -= OnViewModelPropertyChanged; this.viewModel = null; } }