private async void SearchStopsAsync(string searchText) { if (String.IsNullOrWhiteSpace(searchText)) { StopsResultList.Clear(); MapPlaces.Clear(); return; } if (_tokenSource != null && !_tokenSource.IsCancellationRequested) { _tokenSource.Cancel(); } _tokenSource = new CancellationTokenSource(); IsOverviewLoading = true; ApiResult <IEnumerable <TransitStop> > response = await _networkService.GetStopsAsync(searchText, _tokenSource.Token); IsOverviewLoading = false; if (response.IsFailure) { // TODO: Show error in list StopsResultList.Clear(); MapPlaces.Clear(); return; } if (_tokenSource.Token.IsCancellationRequested) { // TODO: Show error in list StopsResultList.Clear(); MapPlaces.Clear(); return; } // We explicitly enumerate the list into memory here, otherwise Guid.NewGuid() gets called every time we enumerate the list, // making it impossible to link a Map POI to a list element. List <TransitStop> stops = response.Result.ToList(); StopsResultList = new ObservableCollection <StopSearchElementViewModel>( stops.Select(x => new StopSearchElementViewModel(x, _messenger))); MapPlaces.Clear(); MapPlaces.AddRange(stops.Select(x => new BasicMapPoi { Coords = x.Coords, Name = x.NameAndCode, Id = x.Id })); }
public void SetMapSelectedPlace(IEnumerable <Guid> obj) { Guid?nullableId = obj?.FirstOrDefault(); if (nullableId != null) { Guid clickedId = nullableId.Value; StopSearchElementViewModel matchingStop = StopsResultList.FirstOrDefault(x => x.BackingStop.Id == clickedId); if (matchingStop != null) { if (_currentState == StopSearchState.Details) { SwitchToDetailedView(new MessageTypes.ViewStopDetails(matchingStop)); } else { SelectedStop = matchingStop; } } } }
private async Task UpdateNearbyPlaces(Geocircle circle, CancellationToken token) { ApiResult <IEnumerable <TransitStop> > response = await _networkService.GetStopsByBoundingRadius( (float)circle.Center.Latitude, (float)circle.Center.Longitude, (int)circle.Radius, token ); if (response.IsFailure) { // TODO: Show error in list StopsResultList.Clear(); MapPlaces.Clear(); return; } if (token.IsCancellationRequested) { // TODO: show error in list StopsResultList.Clear(); MapPlaces.Clear(); return; } // We explicitly enumerate the list into memory here, otherwise Guid.NewGuid() gets called every time we enumerate the list, // making it impossible to link a Map POI to a list element. List <TransitStop> stops = response.Result.ToList(); StopsResultList = new ObservableCollection <StopSearchElementViewModel>( stops.Select(x => new StopSearchElementViewModel(x, _messenger))); MapPlaces.Clear(); MapPlaces.AddRange(stops.Select(x => new BasicMapPoi { Coords = x.Coords, Name = x.NameAndCode, Id = x.Id })); }