Beispiel #1
0
 /// <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>
 /// 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>
        /// Returns a list of suggestions for the user the OBA list of routes.
        /// </summary>
        public async Task <IEnumerable <string> > GetSuggestionsAsync(string query, OneBusAway.Model.Point userLocation)
        {
            var obaDataAccess   = ObaDataAccess.Create();
            var listOfAllRoutes = await obaDataAccess.GetAllRoutesForCurrentRegionAsync();

            return(from result in listOfAllRoutes
                   where (result.ShortName != null && result.ShortName.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1) ||
                   (result.Description != null && result.Description.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1)
                   select string.Format(CultureInfo.CurrentCulture, "BUS {0}", result.ShortName));
        }
        /// <summary>
        /// Called when the user selects a location as the search result. Show all of the routes that are near this stop.
        /// </summary>
        /// <param name="sender">SearchResultsControlViewModel</param>
        /// <param name="e">SearchLocationResultViewModel</param>
        private async void OnSearchResultsControlViewModelLocationSelected(object sender, LocationSelectedEventArgs e)
        {
            this.MapControlViewModel.BusStops = null;
            this.MapControlViewModel.Shapes   = null;

            var point = new OneBusAway.Model.Point(e.Location.Point.Coordinates[0], e.Location.Point.Coordinates[1]);

            this.MapControlViewModel.UserLocation = point;
            this.MapControlViewModel.MapView      = new MapView(point, Constants.ZoomedInMapZoom, true);

            // Find all the bus stops at this location and then show the routes for this address:
            await this.MapControlViewModel.RefreshStopsForLocationAsync();

            // Find all of the unique routes for this location:
            await this.SearchResultsControlViewModel.SelectSpecificRoutesAsync((from stop in this.MapControlViewModel.BusStops
                                                                                from route in stop.Routes
                                                                                select route.Id).Distinct());
        }
        /// <summary>
        /// Searches all agencies for all bus numbers.
        /// </summary>
        public async Task SearchAsync(string query, OneBusAway.Model.Point userLocation)
        {
            this.NoSearchResultsText = string.Format(CultureInfo.CurrentCulture, "SEARCHING FOR '{0}'", query);

            try
            {
                if (string.IsNullOrEmpty(query))
                {
                    this.SearchResults.Clear();
                    this.BingMapsSearchResults = null;
                }
                else
                {
                    // If the user selected a suggestion, then that means they want a specific bus:
                    if (query.StartsWith("BUS", StringComparison.OrdinalIgnoreCase))
                    {
                        await DisplayAndSelectSpecificRouteAsync(query.Substring(3).Trim());
                    }
                    else
                    {
                        var listOfAllRoutes = await this.LoadAllRoutesAsync();

                        // Let's filter the results!

                        var newItems = (from result in listOfAllRoutes
                                        where (result.ShortName != null && result.ShortName.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1) ||
                                        (result.Description != null && result.Description.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1)
                                        select new SearchRouteResultViewModel(result));

                        await this.uiHelper.BatchAddItemsAsync(this.searchResults, newItems);

                        var bingMapResults = await BingMapsServiceHelper.GetLocationByQuery(query, Utilities.Confidence.Medium, userLocation);

                        this.BingMapsSearchResults = (from result in bingMapResults
                                                      select new SearchLocationResultViewModel(result)).ToArray();
                    }
                }
            }
            catch
            {
            }

            this.NoSearchResultsText = "NO RESULTS";
        }
Beispiel #6
0
        /// <summary>
        /// Finds the users location asynchronously using the Geolocator.
        /// </summary>
        public async Task FindUserLocationAsync()
        {
            // If we already have a location, don't get it again:
            if (this.UserLocation == null)
            {
                try
                {
                    var position = await ServiceRepository.GeoLocationService.FindUserLocationAsync();

                    this.UserLocation = new Point(position.Latitude, position.Longitude);
                    this.MapView      = new MapView(this.UserLocation, Constants.ZoomedInMapZoom);
                }
                catch
                {
                    // geolocator failed for some other reason.
                    // [Ghulam] Apparently on server 2102 GetGeopositionAsync throws FileNotFoundException.
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Finds the users location asynchronously using the Geolocator.
        /// </summary>
        public async Task <bool> TryFindUserLocationAsync()
        {
            try
            {
                var position = await ServiceRepository.GeoLocationService.FindUserLocationAsync();

                this.UserLocation = new Point(position.Latitude, position.Longitude);
                this.MapView      = new MapView(this.UserLocation, Constants.ZoomedInMapZoom, true);
                return(true);
            }
            catch (UnauthorizedAccessException)
            {
                return(false);
            }
            catch (Exception)
            {
                // geolocator failed for some other reason.
                // [Ghulam] Apparently on server 2102 GetGeopositionAsync throws FileNotFoundException.
                return(false);
            }
        }
        /// <summary>
        /// Finds the users location asynchronously using the Geolocator.
        /// </summary>
        public async Task<bool> TryFindUserLocationAsync()
        {
            try
            {
                Geolocator geolocator = new Geolocator();
                var position = await geolocator.GetGeopositionAsync();

                this.UserLocation = new Point(position.Coordinate.Point.Position.Latitude, position.Coordinate.Point.Position.Longitude); ;
                this.MapView = new MapView(this.UserLocation, this.MapView.ZoomLevel, true);
                return true;
            }
            catch (UnauthorizedAccessException)
            {
                return false;
            }
            catch (Exception)
            {
                // geolocator failed for some other reason.
                // [Ghulam] Apparently on server 2102 GetGeopositionAsync throws FileNotFoundException.
                return false;
            }
        }
        /// <summary>
        /// Finds the users location asynchronously using the Geolocator.
        /// </summary>
        public async Task FindUserLocationAsync()
        {
            // If we already have a location, don't get it again:
            if (this.UserLocation == null)
            {
                this.UserLocation = MapView.Current.MapCenter;
                this.MapView = new MapView(this.UserLocation, ViewModelConstants.DefaultMapZoom);

                try
                {
                    Geolocator geolocator = new Geolocator();
                    var position = await geolocator.GetGeopositionAsync();

                    this.UserLocation = new Point(position.Coordinate.Point.Position.Latitude, position.Coordinate.Point.Position.Longitude); ;
                    this.MapView = new MapView(this.UserLocation, ViewModelConstants.ZoomedInMapZoom);
                }
                catch
                {
                    // geolocator failed for some other reason.
                    // [Ghulam] Apparently on server 2102 GetGeopositionAsync throws FileNotFoundException.
                }
            }
        }
 /// <summary>
 /// This method is called when the geo location service has a new lat / lon for us.
 /// </summary>
 public void OnUserLocationChanged(Point newLocation)
 {
     this.UserLocation = newLocation;
 }
        /// <summary>
        /// Finds the users location asynchronously using the Geolocator.
        /// </summary>
        public async Task<bool> TryFindUserLocationAsync()
        {
            try
            {
                var position = await ServiceRepository.GeoLocationService.FindUserLocationAsync();

                this.UserLocation = new Point(position.Latitude, position.Longitude);
                this.MapView = new MapView(this.UserLocation, Constants.ZoomedInMapZoom, true);                
                return true;
            }
            catch (UnauthorizedAccessException)
            {
                return false;
            }
            catch (Exception)
            {
                // geolocator failed for some other reason.
                // [Ghulam] Apparently on server 2102 GetGeopositionAsync throws FileNotFoundException.
                return false;
            }
        }
 /// <summary>
 /// Finds the users location asynchronously using the Geolocator.
 /// </summary>
 public async Task FindUserLocationAsync()
 {
     // If we already have a location, don't get it again:
     if (this.UserLocation == null)
     {
         try
         {
             var position = await ServiceRepository.GeoLocationService.FindUserLocationAsync();
             this.UserLocation = new Point(position.Latitude, position.Longitude);
             this.MapView = new MapView(this.UserLocation, Constants.ZoomedInMapZoom);
         }
         catch
         {
             // geolocator failed for some other reason.
             // [Ghulam] Apparently on server 2102 GetGeopositionAsync throws FileNotFoundException.
         }
     }
 }
Beispiel #13
0
 /// <summary>
 /// This method is called when the geo location service has a new lat / lon for us.
 /// </summary>
 public void OnUserLocationChanged(Point newLocation)
 {
     this.UserLocation = newLocation;
 }
        /// <summary>
        /// Called when the user selects a location as the search result. Show all of the routes that are near this stop.
        /// </summary>
        /// <param name="sender">SearchResultsControlViewModel</param>
        /// <param name="e">SearchLocationResultViewModel</param>
        private async void OnSearchResultsControlViewModelLocationSelected(object sender, LocationSelectedEventArgs e)
        {
            this.MapControlViewModel.BusStops = null;
            this.MapControlViewModel.Shapes = null;
            
            var point = new OneBusAway.Model.Point(e.Location.Point.Coordinates[0], e.Location.Point.Coordinates[1]);
            this.MapControlViewModel.UserLocation = point;
            this.MapControlViewModel.MapView = new MapView(point, ViewModelConstants.ZoomedInMapZoom, true);            

            // Find all the bus stops at this location and then show the routes for this address:
            await this.MapControlViewModel.RefreshStopsForLocationAsync();

            // Find all of the unique routes for this location:
            await this.SearchResultsControlViewModel.SelectSpecificRoutesAsync((from stop in this.MapControlViewModel.BusStops
                                                                                from route in stop.Routes
                                                                                select route.Id).Distinct());
        }