示例#1
0
        public void RemovePinMenuItem_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine($"Removing pin");
            var control = sender as Control;
            var pin     = control.DataContext as Pushpin;

            //remove the pushpin location from the route and redraw the route.
            int locIndex = route.IndexOf(pin.Location);

            if (locIndex < 0)
            {
                throw new Exception("can't find the location index for the removed pin location");
            }
            route.RemoveAt(locIndex);


            DrawWayPoints();
        }
示例#2
0
        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();
        }