Exemplo n.º 1
0
        void LaunchTask()
        {
            if (textBox.Text.Length > 5)
            {
                string searchString = textBox.Text.Trim();

                if (!string.Equals(_lastCheck, searchString, StringComparison.InvariantCultureIgnoreCase))
                {
                    _lastCheck = searchString;

                    if (null != _executeTask)
                    {
                        _executeTask.Cancel();
                        _executeTask = null;
                    }

                    listBox.Visibility      = System.Windows.Visibility.Collapsed;
                    loadingLabel.Visibility = System.Windows.Visibility.Visible;
                    loadingLabel.Text       = "Loading Results...";

                    _executeTask = new AsyncTask(this.Dispatcher, () => WaitXSeconds(1), (ex) => GetMatchingAddress(ex));
                    _executeTask.Execute();
                }
            }
        }
Exemplo n.º 2
0
        private void Route_Click(object sender, RoutedEventArgs e)
        {
            LayoutRoot.RowDefinitions[1].Height = new GridLength(LayoutRoot.RowDefinitions[1].MinHeight);

            /*
             * RouteServiceClient client = new RouteServiceClient("BasicHttpBinding_IRouteService");
             * RouteRequest request = new RouteRequest();
             * request.Waypoints = new List<Waypoint>();
             * request.Waypoints.Add(new Waypoint());
             * request.Waypoints.Add(new Waypoint());
             *
             * request.Credentials = new Credentials();
             * request.Credentials.ApplicationId = BingMapsApiKey;
             * request.Waypoints[0].Location = new Location();
             * request.Waypoints[1].Location = new Location();
             *
             * request.Waypoints[0].Location.Latitude = DataContextManager.SelectedCommute.StartPoint.Location.Latitude;
             * request.Waypoints[0].Location.Longitude = DataContextManager.SelectedCommute.StartPoint.Location.Longitude;
             * request.Waypoints[1].Location.Latitude = DataContextManager.SelectedCommute.EndPoint.Location.Latitude;
             * request.Waypoints[1].Location.Longitude = DataContextManager.SelectedCommute.EndPoint.Location.Longitude;
             *
             * // Only accept results with high confidence.
             * request.Options = new RouteOptions();
             * request.Options.RoutePathType = RoutePathType.Points;
             *
             * client.CalculateRouteCompleted += new EventHandler<CalculateRouteCompletedEventArgs>(client_CalculateRouteCompleted);
             * client.CalculateRouteAsync(request);
             */

            AsyncTask.Execute(this.Dispatcher, delegate()
            {
                _loadedRoute = Utils.RefreshRoute(DataContextManager.SelectedCommute.StartPoint, DataContextManager.SelectedCommute.EndPoint, DataContextManager.SelectedRoute, false);
            }, (ex) => RouteComplete(ex));
        }
Exemplo n.º 3
0
        private void CustomPhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            _splashPopup.Child = null;
            this.RootElement.Children.Add(splashImage);
            _splashPopup.IsOpen = false;
            if (null != this.MainElement)
            {
                this.MainElement.Visibility = System.Windows.Visibility.Visible;
            }

            this.Loaded -= new RoutedEventHandler(CustomPhoneApplicationPage_Loaded);
            AsyncTask.Execute(this.Dispatcher, () => HandleAsyncLoad(), (ex) => HandleAsyncLoadComplete(ex));
        }
Exemplo n.º 4
0
        void PerformRouting(bool setViewPort)
        {
            _setViewPort = setViewPort;

            AsyncTask.Execute(this.Dispatcher, delegate()
            {
                _loadedRoute = Utils.RefreshRoute(DataContextManager.SelectedCommute.StartPoint, DataContextManager.SelectedCommute.EndPoint, DataContextManager.SelectedRoute, false);

                /*
                 * RouteServiceClient client = new RouteServiceClient("BasicHttpBinding_IRouteService");
                 * RouteRequest request = new RouteRequest();
                 * request.Waypoints = new List<Waypoint>();
                 * request.Waypoints.Add(new Waypoint());
                 *
                 * request.Credentials = new Credentials();
                 * request.Credentials.ApplicationId = BingMapsApiKey;
                 * request.Waypoints[0].Location = new Location();
                 *
                 * request.Waypoints[0].Location.Latitude = DataContextManager.SelectedCommute.StartPoint.Location.Latitude;
                 * request.Waypoints[0].Location.Longitude = DataContextManager.SelectedCommute.StartPoint.Location.Longitude;
                 *
                 * foreach (MobileSrc.Commuter.Shared.RouteLocation wayPoint in DataContextManager.SelectedRoute.WayPoints)
                 * {
                 *  request.Waypoints.Add(new Waypoint());
                 *  request.Waypoints[request.Waypoints.Count - 1].Location = new Location();
                 *  request.Waypoints[request.Waypoints.Count - 1].Location.Latitude = wayPoint.Location.Latitude;
                 *  request.Waypoints[request.Waypoints.Count - 1].Location.Longitude = wayPoint.Location.Longitude;
                 * }
                 *
                 * request.Waypoints.Add(new Waypoint());
                 * request.Waypoints[request.Waypoints.Count - 1].Location = new Location();
                 * request.Waypoints[request.Waypoints.Count - 1].Location.Latitude = DataContextManager.SelectedCommute.EndPoint.Location.Latitude;
                 * request.Waypoints[request.Waypoints.Count - 1].Location.Longitude = DataContextManager.SelectedCommute.EndPoint.Location.Longitude;
                 *
                 * // Only accept results with high confidence.
                 * request.Options = new RouteOptions();
                 * request.Options.RoutePathType = RoutePathType.Points;
                 * request.Options.TrafficUsage = TrafficUsage.TrafficBasedTime;
                 */
            },
                              (ex) => RouteComplete(ex)
                              );
        }
        void AddRoutes()
        {
            pushpinCanvas.Children.Clear();
            _routeLayer.Children.Clear();

            _finalRect = null;

            for (int i = 0; i < this.Source.Routes.Count; ++i)
            {
                Microsoft.Phone.Controls.Maps.MapPolyline line = new Microsoft.Phone.Controls.Maps.MapPolyline();
                line.Locations = new Microsoft.Phone.Controls.Maps.LocationCollection();
                Random rng = new Random();

                if (this.Source.Routes[i].RoutePoints.Count > 0)
                {
                    double maxLat = this.Source.Routes[i].RoutePoints[0].Latitude;
                    double minLat = this.Source.Routes[i].RoutePoints[0].Latitude;
                    double maxLon = this.Source.Routes[i].RoutePoints[0].Longitude;
                    double minLon = this.Source.Routes[i].RoutePoints[0].Longitude;

                    foreach (MobileSrc.Commuter.Shared.GpsLocation location in this.Source.Routes[i].RoutePoints)
                    {
                        line.Locations.Add(new System.Device.Location.GeoCoordinate(location.Latitude, location.Longitude, location.Altitude));

                        maxLat = Math.Max(maxLat, location.Latitude);
                        minLat = Math.Min(minLat, location.Latitude);
                        maxLon = Math.Max(maxLon, location.Longitude);
                        minLon = Math.Min(minLon, location.Longitude);
                    }

                    Color color = RouteColors[i % RouteColors.Count()];

                    line.Opacity = 0.65;
                    line.StrokeThickness = 5;
                    line.Visibility = System.Windows.Visibility.Visible;
                    line.Stroke = new System.Windows.Media.SolidColorBrush(color);
                    _routeLayer.Children.Add(line);
                    Microsoft.Phone.Controls.Maps.LocationRect rect = new Microsoft.Phone.Controls.Maps.LocationRect(maxLat, minLon, minLat, maxLon);

                    if (null == _finalRect)
                    {
                        _finalRect = rect;
                    }
                    else
                    {
                        _finalRect.West = Math.Min(_finalRect.West, rect.West);
                        _finalRect.North = Math.Max(_finalRect.North, rect.North);

                        _finalRect.East = Math.Max(_finalRect.East, rect.East);
                        _finalRect.South = Math.Min(_finalRect.South, rect.South);
                    }
                }
            }

            if (null != _finalRect)
            {
                AsyncTask executeTask = new AsyncTask(this.Dispatcher, () => WaitForStopDownloading(), (ex) => WaitForStopDownloadingComplete(ex));
                executeTask.Execute();
            }

            for (int i = 0; i < this.Source.Routes.Count; ++i)
            {
                if (this.Source.Routes[i].RoutePoints.Count > 0)
                {
                    Color color = RouteColors[i % RouteColors.Count()];

                    Microsoft.Phone.Controls.Maps.Pushpin pushPin = new Microsoft.Phone.Controls.Maps.Pushpin();
                    pushPin.Background = new SolidColorBrush(color);
                    pushPin.Content = this.Source.Routes[i].Name;

                    MobileSrc.Commuter.Shared.GpsLocation prevPushpinLoc = this.Source.Routes[i].RoutePoints[this.Source.Routes[i].RoutePoints.Count / 2 - 5];
                    MobileSrc.Commuter.Shared.GpsLocation pushpinLoc = this.Source.Routes[i].RoutePoints[this.Source.Routes[i].RoutePoints.Count / 2];
                    pushPin.Location = new System.Device.Location.GeoCoordinate(pushpinLoc.Latitude, pushpinLoc.Longitude);

                    string name = this.Source.Routes[i].Name;

                    Border border = new Border();
                    border.BorderBrush = new SolidColorBrush(Colors.Orange);
                    border.BorderThickness = new Thickness(0);
                    border.Background = new SolidColorBrush(Colors.White);
                    border.Width = 21;
                    border.Height = 21;
                    border.Opacity = .5;
                    border.CornerRadius = new CornerRadius(10.5);

                    pushPin.Opacity = .60;

                    Button tooltipBorder = new Button();
                    tooltipBorder.Style = (Style)LayoutRoot.Resources["PhoneTransparentButton"];
                    tooltipBorder.DataContext = this.Source.Routes[i];
                    tooltipBorder.Background = new SolidColorBrush(color);
                    tooltipBorder.FontSize = 16;
                    tooltipBorder.Foreground = new SolidColorBrush(Colors.White);
                    tooltipBorder.Content = name;
                    tooltipBorder.Padding = new Thickness(5);
                    tooltipBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    tooltipBorder.Margin = new Thickness(4);
                    tooltipBorder.BorderBrush = new SolidColorBrush(Colors.White);
                    tooltipBorder.BorderThickness = new Thickness(2);

                    pushpinCanvas.Children.Add(tooltipBorder);
                }
            }
        }
Exemplo n.º 6
0
        void LaunchTask()
        {
            if (textBox.Text.Length > 5)
            {
                string searchString = textBox.Text.Trim();

                if (!string.Equals(_lastCheck, searchString, StringComparison.InvariantCultureIgnoreCase))
                {
                    _lastCheck = searchString;

                    if (null != _executeTask)
                    {
                        _executeTask.Cancel();
                        _executeTask = null;
                    }

                    listBox.Visibility = System.Windows.Visibility.Collapsed;
                    loadingLabel.Visibility = System.Windows.Visibility.Visible;
                    loadingLabel.Text = "Loading Results...";

                    _executeTask = new AsyncTask(this.Dispatcher, () => WaitXSeconds(1), (ex) => GetMatchingAddress(ex));
                    _executeTask.Execute();
                }
            }
        }
        void AddRoutes()
        {
            pushpinCanvas.Children.Clear();
            _routeLayer.Children.Clear();

            _finalRect = null;

            for (int i = 0; i < this.Source.Routes.Count; ++i)
            {
                Microsoft.Phone.Controls.Maps.MapPolyline line = new Microsoft.Phone.Controls.Maps.MapPolyline();
                line.Locations = new Microsoft.Phone.Controls.Maps.LocationCollection();
                Random rng = new Random();

                if (this.Source.Routes[i].RoutePoints.Count > 0)
                {
                    double maxLat = this.Source.Routes[i].RoutePoints[0].Latitude;
                    double minLat = this.Source.Routes[i].RoutePoints[0].Latitude;
                    double maxLon = this.Source.Routes[i].RoutePoints[0].Longitude;
                    double minLon = this.Source.Routes[i].RoutePoints[0].Longitude;

                    foreach (MobileSrc.Commuter.Shared.GpsLocation location in this.Source.Routes[i].RoutePoints)
                    {
                        line.Locations.Add(new System.Device.Location.GeoCoordinate(location.Latitude, location.Longitude, location.Altitude));

                        maxLat = Math.Max(maxLat, location.Latitude);
                        minLat = Math.Min(minLat, location.Latitude);
                        maxLon = Math.Max(maxLon, location.Longitude);
                        minLon = Math.Min(minLon, location.Longitude);
                    }

                    Color color = RouteColors[i % RouteColors.Count()];

                    line.Opacity         = 0.65;
                    line.StrokeThickness = 5;
                    line.Visibility      = System.Windows.Visibility.Visible;
                    line.Stroke          = new System.Windows.Media.SolidColorBrush(color);
                    _routeLayer.Children.Add(line);
                    Microsoft.Phone.Controls.Maps.LocationRect rect = new Microsoft.Phone.Controls.Maps.LocationRect(maxLat, minLon, minLat, maxLon);

                    if (null == _finalRect)
                    {
                        _finalRect = rect;
                    }
                    else
                    {
                        _finalRect.West  = Math.Min(_finalRect.West, rect.West);
                        _finalRect.North = Math.Max(_finalRect.North, rect.North);

                        _finalRect.East  = Math.Max(_finalRect.East, rect.East);
                        _finalRect.South = Math.Min(_finalRect.South, rect.South);
                    }
                }
            }

            if (null != _finalRect)
            {
                AsyncTask executeTask = new AsyncTask(this.Dispatcher, () => WaitForStopDownloading(), (ex) => WaitForStopDownloadingComplete(ex));
                executeTask.Execute();
            }

            for (int i = 0; i < this.Source.Routes.Count; ++i)
            {
                if (this.Source.Routes[i].RoutePoints.Count > 0)
                {
                    Color color = RouteColors[i % RouteColors.Count()];

                    Microsoft.Phone.Controls.Maps.Pushpin pushPin = new Microsoft.Phone.Controls.Maps.Pushpin();
                    pushPin.Background = new SolidColorBrush(color);
                    pushPin.Content    = this.Source.Routes[i].Name;

                    MobileSrc.Commuter.Shared.GpsLocation prevPushpinLoc = this.Source.Routes[i].RoutePoints[this.Source.Routes[i].RoutePoints.Count / 2 - 5];
                    MobileSrc.Commuter.Shared.GpsLocation pushpinLoc     = this.Source.Routes[i].RoutePoints[this.Source.Routes[i].RoutePoints.Count / 2];
                    pushPin.Location = new System.Device.Location.GeoCoordinate(pushpinLoc.Latitude, pushpinLoc.Longitude);

                    string name = this.Source.Routes[i].Name;

                    Border border = new Border();
                    border.BorderBrush     = new SolidColorBrush(Colors.Orange);
                    border.BorderThickness = new Thickness(0);
                    border.Background      = new SolidColorBrush(Colors.White);
                    border.Width           = 21;
                    border.Height          = 21;
                    border.Opacity         = .5;
                    border.CornerRadius    = new CornerRadius(10.5);

                    pushPin.Opacity = .60;

                    Button tooltipBorder = new Button();
                    tooltipBorder.Style               = (Style)LayoutRoot.Resources["PhoneTransparentButton"];
                    tooltipBorder.DataContext         = this.Source.Routes[i];
                    tooltipBorder.Background          = new SolidColorBrush(color);
                    tooltipBorder.FontSize            = 16;
                    tooltipBorder.Foreground          = new SolidColorBrush(Colors.White);
                    tooltipBorder.Content             = name;
                    tooltipBorder.Padding             = new Thickness(5);
                    tooltipBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    tooltipBorder.Margin              = new Thickness(4);
                    tooltipBorder.BorderBrush         = new SolidColorBrush(Colors.White);
                    tooltipBorder.BorderThickness     = new Thickness(2);

                    pushpinCanvas.Children.Add(tooltipBorder);
                }
            }
        }