Exemplo n.º 1
0
        void RscGetRoutingCompleted(object sender, GetRoutingCompletedEventArgs e)
        {
            if (e.Result.Count() == 0)
            {
                Dtimer.Stop();
                timer.Stop();
                Ltimer.Stop();
                return;
            }
            carloc.Clear();
            _cari = 0;
            var lineLayer = MyMap.Layers["MyLineLayer"] as GraphicsLayer;

            if (lineLayer != null) lineLayer.ClearGraphics();
            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[] { ',' });
                    int beginNode = int.Parse(strArray[3]);
                    if (i==0)
                    {
                        otmpFirstArrays = strArrayPoints;
                    }

                    if ((strArray2.Length == 1) && (strArray2[0].Length > 1))
                    {
                        //面
                    }
                    else
                    {
                        var locations = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                        CustomMapPoint location2;
                        CustomMapPoint locPoint;
                        if (strArray2[0].Equals(strArray2[strArray2.Length - 1]))
                        {

                        }
                        else
                        {
                            var polyline = new ESRI.ArcGIS.Client.Geometry.Polyline();

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

                            }

                            //添加坐标到小车轨迹
                            if (fcarloc.Count>0)
                            {
                                //取出轨迹数据的第一个点
                                var floc1 = new CustomMapPoint(double.Parse(otmpFirstArrays[0].Split(new char[] { ' ' })[1]),
                                                        double.Parse(otmpFirstArrays[0].Split(new char[] { ' ' })[0]));

                                var ffloc1 = fcarloc.ElementAt(0);

                                var loc1 = new CustomMapPoint(double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[1]),
                                                        double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[0]));
                                var loc2 = new CustomMapPoint(double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[1]),
                                                        double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[0]));
                                CustomMapPoint oPoint = GetCarByName("car", MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Geometry as CustomMapPoint;

                                if (i==0)
                                {
                                    //当前车辆不在在轨迹上
                                    if (!IsInLine(oPoint, otmpFirstArrays))
                                    {

                                        //调节车辆最后所在轨迹段顺序
                                        if (!Isclost(ffloc1, loc1, 0.0001) && !Isclost(ffloc1, loc2, 0.0001))
                                        {
                                            for (index = 0; index < fcarloc.Count - 1; index++)
                                            {
                                                var tmoloc = fcarloc.ElementAt(index);

                                                carloc.Add(tmoloc);

                                            }

                                        }
                                        else
                                        {

                                            for (index = fcarloc.Count - 1; index >= 0; index--)
                                            {
                                                var tmoloc1 = fcarloc.ElementAt(index);
                                                carloc.Add(tmoloc1);
                                            }

                                        }
                                    }

                                }

                                if (i == 1)
                                {
                                    //调节第一段轨迹段顺序
                                    if (!Isclost(floc1, loc1, 0.00001) && !Isclost(floc1, loc2, 0.00001))
                                    {

                                        for (index = 0; index < otmpFirstArrays.Length - 1; index++)
                                        {
                                            var tmoloc =
                                                new CustomMapPoint(
                                                    double.Parse(otmpFirstArrays[index].Split(new char[] {' '})[1]),
                                                    double.Parse(otmpFirstArrays[index].Split(new char[] {' '})[0]))
                                                    {Node = beginNode};
                                            carloc.Add(tmoloc);

                                        }

                                    }
                                    else
                                    {

                                        for (index = otmpFirstArrays.Length - 1; index >= 0; index--)
                                        {
                                            var tmoloc1 =
                                                new CustomMapPoint(
                                                    double.Parse(otmpFirstArrays[index].Split(new char[] {' '})[1]),
                                                    double.Parse(otmpFirstArrays[index].Split(new char[] {' '})[0]))
                                                    {Node = beginNode};
                                            carloc.Add(tmoloc1);
                                        }
                                    }

                                    OrderPoints(strArrayPoints, carloc.ElementAt(carloc.Count - 1), loc1, loc2, beginNode);
                                }

                                if(i>1)
                                {
                                    OrderPoints(strArrayPoints, carloc.ElementAt(carloc.Count - 1), loc1, loc2, beginNode);
                                }

                            }
                            polyline.Paths.Add(locations);
                            if (lineLayer != null)
                                lineLayer.Graphics.Add(new Graphic()
                                {
                                    Geometry = polyline,
                                    Symbol = DefaultLineSymbol
                                });
                        }
                    }

                }

            }
            CustomMapPoint c = GetCarByName("car", MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Geometry as CustomMapPoint;
                for (int i = 0; i < carloc.Count-1; i++)
                {
                    var item = carloc.ElementAt(i);
                    if (Isclost(c, item, 0.0001))
                    {

                        for (int y = 0; y < i + 2; y++)
                        {
                            if (carloc.Count > y + 1)
                            {
                                carloc.RemoveAt(0);
                            }
                        }

                    }
                }

            _isgetlocing = false;
            timer.Begin();
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        void RscGetRoutingCompleted(object sender, GetRoutingCompletedEventArgs e)
        {
            if (e.Result.Count() == 0)
            {
                Dtimer.Stop();
                timer.Stop();
                Ltimer.Stop();
                return;
            }
            carloc.Clear();
            _cari = 0;
            var lineLayer = MyMap.Layers["MyLineLayer"] as GraphicsLayer;

            if (lineLayer != null)
            {
                lineLayer.ClearGraphics();
            }
            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[] { ',' });
                    int      beginNode      = int.Parse(strArray[3]);
                    if (i == 0)
                    {
                        otmpFirstArrays = strArrayPoints;
                    }

                    if ((strArray2.Length == 1) && (strArray2[0].Length > 1))
                    {
                        //面
                    }
                    else
                    {
                        var            locations = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                        CustomMapPoint location2;
                        CustomMapPoint locPoint;
                        if (strArray2[0].Equals(strArray2[strArray2.Length - 1]))
                        {
                        }
                        else
                        {
                            var polyline = new ESRI.ArcGIS.Client.Geometry.Polyline();


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

                            //添加坐标到小车轨迹
                            if (fcarloc.Count > 0)
                            {
                                //取出轨迹数据的第一个点
                                var floc1 = new CustomMapPoint(double.Parse(otmpFirstArrays[0].Split(new char[] { ' ' })[1]),
                                                               double.Parse(otmpFirstArrays[0].Split(new char[] { ' ' })[0]));

                                var ffloc1 = fcarloc.ElementAt(0);

                                var loc1 = new CustomMapPoint(double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[1]),
                                                              double.Parse(strArrayPoints[0].Split(new char[] { ' ' })[0]));
                                var loc2 = new CustomMapPoint(double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[1]),
                                                              double.Parse(strArrayPoints[strArrayPoints.Length - 1].Split(new char[] { ' ' })[0]));
                                CustomMapPoint oPoint = GetCarByName("car", MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Geometry as CustomMapPoint;


                                if (i == 0)
                                {
                                    //当前车辆不在在轨迹上
                                    if (!IsInLine(oPoint, otmpFirstArrays))
                                    {
                                        //调节车辆最后所在轨迹段顺序
                                        if (!Isclost(ffloc1, loc1, 0.0001) && !Isclost(ffloc1, loc2, 0.0001))
                                        {
                                            for (index = 0; index < fcarloc.Count - 1; index++)
                                            {
                                                var tmoloc = fcarloc.ElementAt(index);

                                                carloc.Add(tmoloc);
                                            }
                                        }
                                        else
                                        {
                                            for (index = fcarloc.Count - 1; index >= 0; index--)
                                            {
                                                var tmoloc1 = fcarloc.ElementAt(index);
                                                carloc.Add(tmoloc1);
                                            }
                                        }
                                    }
                                }


                                if (i == 1)
                                {
                                    //调节第一段轨迹段顺序
                                    if (!Isclost(floc1, loc1, 0.00001) && !Isclost(floc1, loc2, 0.00001))
                                    {
                                        for (index = 0; index < otmpFirstArrays.Length - 1; index++)
                                        {
                                            var tmoloc =
                                                new CustomMapPoint(
                                                    double.Parse(otmpFirstArrays[index].Split(new char[] { ' ' })[1]),
                                                    double.Parse(otmpFirstArrays[index].Split(new char[] { ' ' })[0]))
                                            {
                                                Node = beginNode
                                            };
                                            carloc.Add(tmoloc);
                                        }
                                    }
                                    else
                                    {
                                        for (index = otmpFirstArrays.Length - 1; index >= 0; index--)
                                        {
                                            var tmoloc1 =
                                                new CustomMapPoint(
                                                    double.Parse(otmpFirstArrays[index].Split(new char[] { ' ' })[1]),
                                                    double.Parse(otmpFirstArrays[index].Split(new char[] { ' ' })[0]))
                                            {
                                                Node = beginNode
                                            };
                                            carloc.Add(tmoloc1);
                                        }
                                    }

                                    OrderPoints(strArrayPoints, carloc.ElementAt(carloc.Count - 1), loc1, loc2, beginNode);
                                }


                                if (i > 1)
                                {
                                    OrderPoints(strArrayPoints, carloc.ElementAt(carloc.Count - 1), loc1, loc2, beginNode);
                                }
                            }
                            polyline.Paths.Add(locations);
                            if (lineLayer != null)
                            {
                                lineLayer.Graphics.Add(new Graphic()
                                {
                                    Geometry = polyline,
                                    Symbol   = DefaultLineSymbol
                                });
                            }
                        }
                    }
                }
            }
            CustomMapPoint c = GetCarByName("car", MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Geometry as CustomMapPoint;

            for (int i = 0; i < carloc.Count - 1; i++)
            {
                var item = carloc.ElementAt(i);
                if (Isclost(c, item, 0.0001))
                {
                    for (int y = 0; y < i + 2; y++)
                    {
                        if (carloc.Count > y + 1)
                        {
                            carloc.RemoveAt(0);
                        }
                    }
                }
            }

            _isgetlocing = false;
            timer.Begin();
        }