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
            }));
        }
        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
            }));
        }
Пример #3
0
        private void UpdateSelectedLine(LineSearchElementViewModel element)
        {
            MapLines.Clear();
            MapPlaces.Clear();

            if (element == null)
            {
                return;
            }

            List <ColoredMapLinePoint> linePoints = element
                                                    .BackingLine
                                                    .Points
                                                    .Select(x => new ColoredMapLinePoint(
                                                                BasicGeopositionExtensions.Create(0.0, x.Longitude, x.Latitude),
                                                                HslColors.GetModeColor(element.BackingLine.TransitMode)))
                                                    .ToList();

            var mapLine = new ColoredMapLine(linePoints);

            MapLines.Clear();
            MapLines.AddRange(new List <ColoredMapLine> {
                mapLine
            });

            List <IMapPoi> stops = new List <IMapPoi>();

            foreach (var stop in element.BackingLine.Stops)
            {
                stops.Add(new BasicMapPoi {
                    Coords = stop.Coords, Name = stop.Name
                });
            }
            MapPlaces.AddRange(stops);

            _messenger.Send(new MessageTypes.SearchLineSelectionChanged());
        }