public NavigationVM(ViewModelBase favVM_) { FromToggle = true; Pins = new ObservableCollection <Pushpin>(); FavVM = favVM_ as FavouritesVM; ToAddressessSearch = new MixedSearch(); ToAddressessSearch.OnSelectedAction += ToAddressessSearch_OnSelectedAction; FromAddressessSearch = new MixedSearch(); FromAddressessSearch.OnSelectedAction += FromAddressessSearch_OnSelectedAction; MainMap = new MapVM(); FindRouteCommand = new Command(arg => FindRoute()); CenterOnRouteCommand = new Command(arg => CenterOnRoute(arg)); CenterOnUserLocationCommand = new Command(arg => CenterOnUserLocation(arg)); SwapAddressesCommand = new Command(arg => SwapAddresses()); SearchLocationEnterClick = new Command(arg => FindRoute()); MapDoubleClickCommand = new Command(arg => MapDoubleClick(arg)); FromAddressessSearch.StoredLocations = FavVM.Locations; ToAddressessSearch.StoredLocations = FavVM.Locations; FavVM.PropertyChanged += (s, e) => { if (e.PropertyName == "Locations") { if (FavVM.Locations.Count > 0) { MainMap.Center = MapVM.GetLocation(FavVM.Locations.First().Address); } else { MainMap.Center = new Location(52.0, 19.0); MainMap.ZoomLevel = 5; } } }; }
private void CenterOnUserLocation(object sender) { if (sender is UserLocation ul) { MainMap.Center = MapVM.GetLocation(ul.Address); //TODO W zależności od ul.Address.Type można dostosować zoom } }
private void CenterOnUserLocation(object arg) { if (arg is UserLocation ul) { FavMap.Center = MapVM.GetLocation(ul.Address); //TODO W zależności od ul.Address.Type można dostosować zoom } }
private void ToAddressessSearch_OnSelectedAction(object sender, System.EventArgs e) { if (sender is MixedSearch ms) { if (!double.IsNaN(ms.SelectedLocation?.Address.Lat ?? double.NaN)) { var pin = Pins.FirstOrDefault(p => (string)p.Content == "Do"); if (pin != null) { if (Math.Abs(pin.Location.Latitude - ms.SelectedLocation.Address.Lat) > 1 && Math.Abs(pin.Location.Longitude - ms.SelectedLocation.Address.Lon) > 1) { MainMap.Center = MapVM.GetLocation(ms.SelectedLocation.Address); } Pushpin newPin = new Pushpin() { Content = "Do", Location = MapVM.GetLocation(ms.SelectedLocation.Address) }; if (pin != null) { Pins.Remove(pin); } Pins.Add(newPin); } else { Pushpin newPin = new Pushpin() { Content = "Do", Location = MapVM.GetLocation(ms.SelectedLocation.Address) }; if (pin != null) { Pins.Remove(pin); } Pins.Add(newPin); MainMap.Center = MapVM.GetLocation(ms.SelectedLocation.Address); } } } }
private void LoadData() { Task.Run(async() => { System.Windows.Application.Current.Dispatcher.Invoke(() => MainVM.Loading = true); return(await Client.GetMyAddresses()); }).ContinueWith(task => { Locations.Clear(); Locations.AddRange(task.Result); if (Locations.Count > 0) { FavMap.Center = MapVM.GetLocation(Locations.First().Address); } else { FavMap.Center = new Location(52.0, 19.0); FavMap.ZoomLevel = 5; } OnPropertyChanged(nameof(Locations)); MainVM.Loading = false; }, TaskScheduler.FromCurrentSynchronizationContext()); }