Exemple #1
0
        private void DrawPolygonOnBingMap(List <Node> route, Color color)
        {
            MapPolyline polygon = new MapPolyline();

            polygon.Fill            = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent);
            polygon.Stroke          = new System.Windows.Media.SolidColorBrush(color);
            polygon.StrokeThickness = 5;
            polygon.Opacity         = 0.7;
            LocationCollection path = new LocationCollection();

            for (int i = 0; i < route.Count - 2; i++)
            {
                if (alg.NodeDistancesDisjkstry[route.ElementAt(i).Position, route.ElementAt(i + 1).Position] == 0)
                {
                    Dijkstry    di           = new Dijkstry(incidenceList);
                    int[]       pathSD       = di.GetPath(route.ElementAt(i).Position, route.ElementAt(i + 1).Position);
                    List <Node> dijkstryPath = new List <Node>();
                    if (pathSD != null)
                    {
                        //convert from int[] to List<Node>
                        foreach (var p in pathSD)
                        {
                            foreach (var n in alg.NodesList)
                            {
                                if (n.Position == p)
                                {
                                    dijkstryPath.Add(n);
                                    break;
                                }
                            }
                        }

                        foreach (var p in dijkstryPath)
                        {
                            path.Add(new Location(p.Y, p.X));
                        }
                    }
                }
                else
                {
                    path.Add(new Location(route.ElementAt(i).Y, route.ElementAt(i).X));
                }
            }
            foreach (var node in route)
            {
                path.Add(new Location(node.Y, node.X));
            }
            path.Add(path.ElementAt(0)); //i do punktu poczatkowego
            polygon.Locations = path;
            bingMap.Children.Add(polygon);
        }
Exemple #2
0
        private void DrawRouteOnBingMap(List <Node> route, Color color, bool Dijkstry)
        {
            MapPolyline polygon = new MapPolyline();

            polygon.Fill            = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent);
            polygon.Stroke          = new System.Windows.Media.SolidColorBrush(color);
            polygon.StrokeThickness = 5;
            polygon.Opacity         = 0.7;
            LocationCollection path = new LocationCollection();

            foreach (var node in route)
            {
                path.Add(new Location(node.Y, node.X));
            }
            if (!Dijkstry)
            {
                path.Add(path.ElementAt(0));
            }
            polygon.Locations = path;
            bingMap.Children.Add(polygon);
        }
        public void setRoute(LocationCollection points)
        {
            this.fullRoute = points;

            double north = double.MinValue;
            double west = double.MaxValue;
            double south = double.MaxValue;
            double east = double.MinValue;
            foreach (var location in fullRoute)
            {
                if (north < location.Latitude)
                    north = location.Latitude;
                if (south > location.Latitude)
                    south = location.Latitude;
                if (west > location.Longitude)
                    west = location.Longitude;
                if (east < location.Longitude)
                    east = location.Longitude;
            }

            double diff = (east - west)/5;

            LocationRect initialRect = new LocationRect(north + diff, west - diff, south - diff, east + diff);

            this.OSM_Map.SetView(initialRect);
            this.RoutePushpinLayer.Children.Clear();
            addRoutePushpin(fullRoute.ElementAt(0), "Start");
            addRoutePushpin(fullRoute.ElementAt(fullRoute.Count - 1), "Goal");
            // this.setAndSimplifyRoute();
        }
        void rsc_GetRoutingCompleted(object sender, GetRoutingCompletedEventArgs e)
        {
            carloc.Clear();
            cari = 0;
            MapLayer layer = (MapLayer)this.ctlMap.FindName("routing");

            layer.Children.Clear();
            var builder = new StringBuilder();

            if (e.Error == null)
            {
                Color color = Colors.Blue;
                for (int i = 0; i < e.Result.Count; i++)
                {
                    string[] strArray = e.Result[i].Split(new char[] { ';' });


                    builder.Length = 0;
                    int index = 2;
                    while (index < (strArray.Length - 1))
                    {
                        builder.Append(strArray[index] + ": ");
                        index++;
                    }
                    string[] strArray2      = strArray[strArray.Length - 1].Split(new char[] { ',' });
                    string[] strArrayPoints = strArray[strArray.Length - 2].Split(new char[] { ',' });
                    if ((strArray2.Length == 1) && (strArray2[0].Length > 1))
                    {
                        //Ellipse dependencyObject = new Ellipse();
                        //dependencyObject.Width=10.0;
                        //dependencyObject.Height=(10.0);
                        //dependencyObject.Fill=(new SolidColorBrush(color));
                        //dependencyObject.Opacity=(0.65);
                        //Location location = new Location(double.Parse(strArray2[0].Split(new char[] { ' ' })[0]), double.Parse(strArray2[0].Split(new char[] { ' ' })[1]));
                        //MapLayer.SetPosition(dependencyObject, location);
                        //ToolTipService.SetToolTip(dependencyObject, builder.ToString());
                        //layer.Children.Add(dependencyObject);
                    }
                    else
                    {
                        LocationCollection locations;
                        Location           location2;
                        Location           locPoint;
                        if (strArray2[0].Equals(strArray2[strArray2.Length - 1]))
                        {
                            var polygon = new MapPolygon
                            {
                                Stroke          = new SolidColorBrush(color),
                                StrokeThickness = 2.0,
                                Fill            = new SolidColorBrush(color),
                                Opacity         = 0.75
                            };
                            locations = new LocationCollection();
                            index     = 0;
                            while (index < strArray2.Length)
                            {
                                if (strArray2[index].IndexOf(" ") != -1)
                                {
                                    location2 = new Location(double.Parse(strArray2[index].Split(new char[] { ' ' })[0]), double.Parse(strArray2[index].Split(new char[] { ' ' })[1]));
                                    locations.Add(location2);
                                }
                                index++;
                            }
                            polygon.Locations = locations;
                            ToolTipService.SetToolTip(polygon, builder.ToString());
                            layer.Children.Add(polygon);
                        }
                        else
                        {
                            var polyline = new MapPolyline {
                                Stroke = new SolidColorBrush(color), StrokeThickness = 6.0
                            };
                            var doubles = new DoubleCollection {
                                3.0, 3.0
                            };
                            polyline.StrokeDashArray = doubles;
                            locations = new LocationCollection();

                            for (index = strArray2.Length - 1; index >= 0; index--)
                            {
                                location2 = new Location(double.Parse(strArray2[index].Split(new char[] { ' ' })[0]), double.Parse(strArray2[index].Split(new char[] { ' ' })[1]));

                                locations.Add(location2);
                                if (i == 0)
                                {
                                    carloc.Add(location2);
                                }
                            }



                            //添加坐标到小车轨迹
                            if (i > 0)
                            {
                                Location loc1 = new Location(double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[0]), double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[1]));
                                Location loc2 = new Location(double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[0]), double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[1]));
                                if (IsCloset(carloc.ElementAt(carloc.Count - 1), loc1, loc2))
                                {
                                    for (index = strArrayPoints.Length - 1; index >= 0; index--)
                                    {
                                        var tmoloc1 = new Location(double.Parse(strArrayPoints[index].Split(new char[] { ' ' })[0]), double.Parse(strArrayPoints[index].Split(new char[] { ' ' })[1]));

                                        carloc.Add(tmoloc1);
                                    }
                                }
                                else
                                {
                                    for (index = 0; index < strArrayPoints.Length - 1; index++)
                                    {
                                        var tmoloc = new Location(double.Parse(strArrayPoints[index].Split(new char[] { ' ' })[0]), double.Parse(strArrayPoints[index].Split(new char[] { ' ' })[1]));
                                        carloc.Add(tmoloc);
                                    }
                                }
                            }



                            polyline.Locations = locations;
                            ToolTipService.SetToolTip(polyline, builder.ToString());

                            layer.Children.Add(polyline);
                        }
                    }
                }
            }



            CustomPushpin otmpcp = GetCarByMSID("car", carml);

            for (int i = 0; i < carloc.Count; i++)
            {
                var item = carloc.ElementAt(i);
                if (item.Latitude == otmpcp.Location.Latitude && item.Longitude == otmpcp.Location.Longitude)
                {
                    for (int y = 0; y < i + 1; y++)
                    {
                        if (carloc.Count > y + 1)
                        {
                            carloc.RemoveAt(y);
                        }
                    }
                }
            }
            carloc.RemoveAt(0);
            isgetloc = false;

            timer.Begin();
            //RouteLoadingPanel.Stop();
        }