private static async void BusStopsChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { var mapControl = dependencyObject as MapControl; if (args.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 = args.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)); } } } }
public async Task Load(int segmentAttemptId) { SegmentAttempt = await Context.Services.GetSegmentAttempt(segmentAttemptId); MapViewModel = new MapControlViewModel( Context, SegmentAttempt.FormattedTime, PolyUtils.GetMapLocations(SegmentAttempt.Locations, SegmentAttempt.Jumps)); OnPropertyChanged(nameof(MapViewModel)); }
public async Task Load(int id) { Ride = await Context.Services.GetRide(id); MapViewModel = new MapControlViewModel( Context, Ride.DisplayName, PolyUtils.GetMapLocations(Ride.Locations, Ride.Jumps)); OnPropertyChanged(nameof(MapViewModel)); }
public async Task Load(int id) { Segment = await Context.Services.GetSegment(id); MapViewModel = new MapControlViewModel( Context, Segment.Name, PolyUtils.GetMapLocations(Segment.Locations), showRideFeatures: false); OnPropertyChanged(nameof(MapViewModel)); }
private void Application_Startup(Object sender, StartupEventArgs e) { model = new FlightSimulatorModel(new MyTelnetClient()); flightSimulatorViewModel = new FlightSimulatorViewModel(model); manualControlsViewModel = new ManualControlsViewModel(model); dashboardViewModel = new DashboardViewModel(model); mapControlViewModel = new MapControlViewModel(model); Window mainWindow = new MainWindow(); mainWindow.Show(); }
/// <summary> /// Fire the view models' event. /// </summary> private void OnPointerPressed(object sender, PointerRoutedEventArgs e) { if (this.viewModel != null) { // Find the Map control that we're parented to: MapControl mapControl = ControlUtilities.GetParent <MapControl>(this.Parent); if (mapControl != null) { MapControlViewModel mapControlViewModel = mapControl.DataContext as MapControlViewModel; if (mapControlViewModel != null) { mapControlViewModel.SelectStop(this.viewModel); } } } }
/// <summary> /// Fire the view models' event. /// </summary> private void OnTap(object sender, GestureEventArgs e) { FrameworkElement element = sender as FrameworkElement; if (this.viewModel != null && element != null) { // Find the Map control that we're parented to: MapControl mapControl = ControlUtilities.GetParent <MapControl>(element.Parent); if (mapControl != null) { MapControlViewModel mapControlViewModel = mapControl.DataContext as MapControlViewModel; if (mapControlViewModel != null) { mapControlViewModel.SelectStop(this.viewModel); } } } }
public CreateSegmentScreenViewModel(MainContext context, RideDto ride) : base(context) { segment = new SegmentDto(); Ride = ride; count = 1; displayText = "Tap on the map to set a start point"; MapViewModel = new MapControlViewModel( context, Ride?.DisplayName ?? "Map", ride != null ? PolyUtils.GetMapLocations(Ride.Locations, Ride.Jumps) : new List <MapLocation>(), isReadOnly: false, showRideFeatures: false, goToMapPageOnClick: false, mapType: MapType.Satellite, canChangeMapType: true); MapViewModel.MapTapped += MapViewModel_MapTapped; }
public MapControl(UITile[,] map) { InitializeComponent(); _tiles = new TileStatus[map.GetLength(0), map.GetLength(1)]; _vm = new MapControlViewModel(); DataContext = _vm; _vm.TileBitmap = new WriteableBitmap(BitmapHelper.CreateBitmap(map, TileHelper.UI_MAP_TILE_PIXELSIZE)); for (int x = 0; x < map.GetLength(0); x++) { for (int y = 0; y < map.GetLength(1); y++) { _tiles[x, y] = new TileStatus(x, y) { Tile = map[x, y] }; } } //Set the startup size of the grid. This should be immediately overwritten by the SizeChanged event firing, but this ensures we have a valid startup configuration. MapGrid.Width = map.GetLength(0) * TileHelper.UI_MAP_TILE_PIXELSIZE; MapGrid.Height = map.GetLength(1) * TileHelper.UI_MAP_TILE_PIXELSIZE; _tileWidth = TileHelper.UI_MAP_TILE_PIXELSIZE; //When the control is resized, resize the internal grid to fill the available space without stretching. SizeChanged += (sender, args) => { double widthMult = args.NewSize.Width / map.GetLength(0); double heightMult = args.NewSize.Height / map.GetLength(1); double mult = Math.Min(widthMult, heightMult); var width = (int)Math.Floor(map.GetLength(0) * mult); var height = (int)Math.Floor(map.GetLength(1) * mult); MapGrid.Width = width; MapGrid.Height = height; _tileWidth = mult; }; }
public AddNode(MapControlViewModel mapVm, NodesViewModel nodeVm, Action <object> endAction = null) => (MapViewModel, NodesViewModel, this.endAction) = (mapVm, nodeVm, endAction);