Пример #1
0
        void RenderRoute()
        {
            layer.Children.Clear();

            Microsoft.Phone.Controls.Maps.MapPolyline line = new Microsoft.Phone.Controls.Maps.MapPolyline();
            line.Locations = new Microsoft.Phone.Controls.Maps.LocationCollection();

            double maxLat = DataContextManager.SelectedRoute.RoutePoints[0].Latitude;
            double minLat = DataContextManager.SelectedRoute.RoutePoints[0].Latitude;
            double maxLon = DataContextManager.SelectedRoute.RoutePoints[0].Longitude;
            double minLon = DataContextManager.SelectedRoute.RoutePoints[0].Longitude;

            foreach (MobileSrc.Commuter.Shared.GpsLocation location in DataContextManager.SelectedRoute.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);
            }
            Microsoft.Phone.Controls.Maps.LocationRect rect = new Microsoft.Phone.Controls.Maps.LocationRect(maxLat, minLon, minLat, maxLon);

            line.Opacity         = 0.65;
            line.StrokeThickness = 5;
            line.Visibility      = System.Windows.Visibility.Visible;
            line.Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue);
            layer.Children.Add(line);

            if (_setViewPort)
            {
                BingMap.SetView(rect);
            }
        }
        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);
                }
            }
        }
 private Microsoft.Phone.Controls.Maps.MapPolyline SetRouteProperties()
 {
     Color routeColor = Colors.Blue;
     SolidColorBrush routeBrush = new SolidColorBrush(routeColor);
     Microsoft.Phone.Controls.Maps.MapPolyline routeLine = new Microsoft.Phone.Controls.Maps.MapPolyline();
     routeLine.Locations = new Microsoft.Phone.Controls.Maps.LocationCollection();
     routeLine.Stroke = routeBrush;
     routeLine.Opacity = 0.65;
     routeLine.StrokeThickness = 5.0;
     return routeLine;
 }
Пример #4
0
        void RenderRoute()
        {
            layer.Children.Clear();

            Microsoft.Phone.Controls.Maps.MapPolyline line = new Microsoft.Phone.Controls.Maps.MapPolyline();
            line.Locations = new Microsoft.Phone.Controls.Maps.LocationCollection();

            double maxLat = DataContextManager.SelectedRoute.RoutePoints[0].Latitude;
            double minLat = DataContextManager.SelectedRoute.RoutePoints[0].Latitude;
            double maxLon = DataContextManager.SelectedRoute.RoutePoints[0].Longitude;
            double minLon = DataContextManager.SelectedRoute.RoutePoints[0].Longitude;

            foreach (MobileSrc.Commuter.Shared.GpsLocation location in DataContextManager.SelectedRoute.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);
            }
            Microsoft.Phone.Controls.Maps.LocationRect rect = new Microsoft.Phone.Controls.Maps.LocationRect(maxLat, minLon, minLat, maxLon);

            line.Opacity = 0.65;
            line.StrokeThickness = 5;
            line.Visibility = System.Windows.Visibility.Visible;
            line.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue);
            layer.Children.Add(line);

            if (_setViewPort)
            {
                BingMap.SetView(rect);
            }
        }
        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);
                }
            }
        }