Esempio n. 1
0
        public GPSPoint Play(GPSPoint _GpsPoint = null, string _roadName = "")
        {
            RoadInfo riTemp = null;

            if (_GpsPoint == null)
            {
                if (_roadName == "")
                {
                    riTemp = this.RoadList[0];
                }
                else
                {
                    riTemp = RoadList.Find(_ri => { return(_ri.RoadName == _roadName); });
                }
                if (riTemp == null)
                {
                    if (pointRinger != null)
                    {
                        pointRinger(null);
                    }
                    return(null);
                }
                if (RoadSelectRinger != null)
                {
                    RoadSelectRinger(riTemp.NextRoadNameList);
                }
                return(riTemp.PointList[0]);
            }

            RoadInfo ri = RoadList.First(_ri => { return(_ri.RoadName == _GpsPoint.RoadName); });

            if (ri != null)
            {
                if (_GpsPoint.IndexInList < ri.PointList.Count - 1)
                {
                    var point = ri.PointList.First(_point => _point.IndexInList == (_GpsPoint.IndexInList + 1));

                    if (this.pointRinger != null)
                    {
                        this.pointRinger(point);
                    }
                    return(point);
                }
                else
                {
                    if (ri.NextRoadNameList.Contains(this.NextRoadName))
                    {
                        return(Play(null, this.NextRoadName));
                    }
                    else
                    {
                        //往下没路了,提醒结束
                        if (ri.NextRoadNameList.Count <= 0)
                        {
                            if (pointRinger != null)
                            {
                                pointRinger(null);
                            }
                            return(null);
                        }
                        else
                        {
                            //第一条路
                            return(Play(null, ri.NextRoadNameList[0]));
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 2
0
        public void startRunning()
        {
            //string serializedRoute = "[{\"RoadName\":\"road1\",\"PointList\":[{\"Lat\":1.1,\"Lng\":2.1,\"IndexInList\":0,\"RoadName\":\"road1\"},{\"Lat\":1.2,\"Lng\":2.2,\"IndexInList\":1,\"RoadName\":\"road1\"},{\"Lat\":1.3,\"Lng\":2.3,\"IndexInList\":2,\"RoadName\":\"road1\"}],\"NextRoadNameList\":[\"road2\"]},{\"RoadName\":\"road2\",\"PointList\":[{\"Lat\":2.1,\"Lng\":3.1,\"IndexInList\":0,\"RoadName\":\"road2\"},{\"Lat\":2.2,\"Lng\":3.2,\"IndexInList\":1,\"RoadName\":\"road2\"},{\"Lat\":2.3,\"Lng\":3.3,\"IndexInList\":2,\"RoadName\":\"road2\"}],\"NextRoadNameList\":[\"road3\",\"road4\"]},{\"RoadName\":\"road3\",\"PointList\":[{\"Lat\":3.1,\"Lng\":4.1,\"IndexInList\":0,\"RoadName\":\"road3\"},{\"Lat\":3.2,\"Lng\":4.2,\"IndexInList\":1,\"RoadName\":\"road3\"},{\"Lat\":3.3,\"Lng\":4.3,\"IndexInList\":2,\"RoadName\":\"road3\"}],\"NextRoadNameList\":[]},{\"RoadName\":\"road4\",\"PointList\":[{\"Lat\":4.1,\"Lng\":5.1,\"IndexInList\":0,\"RoadName\":\"road4\"},{\"Lat\":4.2,\"Lng\":5.2,\"IndexInList\":1,\"RoadName\":\"road4\"},{\"Lat\":4.3,\"Lng\":5.3,\"IndexInList\":2,\"RoadName\":\"road4\"}],\"NextRoadNameList\":[]}]";
            string serializedRoute = "[";

            serializedRoute += "{\"RoadName\":\"朝阳北路\",\"NextRoadNameList\":[\"未知道路1\",\"未知道路2\"],\"PointList\":[{\"Lat\":4827494.140625,\"Lng\":12983712.890625,\"RoadName\":\"朝阳北路\",\"IndexInList\":0},{\"Lat\":4827500,\"Lng\":12983710.9375,\"RoadName\":\"朝阳北路\",\"IndexInList\":1},{\"Lat\":4827507.8125,\"Lng\":12983207.03125,\"RoadName\":\"朝阳北路\",\"IndexInList\":2},{\"Lat\":4827511.71875,\"Lng\":12982789.0625,\"RoadName\":\"朝阳北路\",\"IndexInList\":3},{\"Lat\":4827488.28125,\"Lng\":12982417.96875,\"RoadName\":\"朝阳北路\",\"IndexInList\":4},{\"Lat\":4827406.25,\"Lng\":12982019.53125,\"RoadName\":\"朝阳北路\",\"IndexInList\":5},{\"Lat\":4827265.625,\"Lng\":12981437.5,\"RoadName\":\"朝阳北路\",\"IndexInList\":6},{\"Lat\":4827179.6875,\"Lng\":12981144.53125,\"RoadName\":\"朝阳北路\",\"IndexInList\":7}]}";
            serializedRoute += "]";
            List <RoadInfo> roads = (List <RoadInfo>)Newtonsoft.Json.JsonConvert.DeserializeObject <List <RoadInfo> >(serializedRoute);
            Action <string, string, string> actringer = (_roadName, _lat, _lng) =>
            {
                this.lblCurrentRoad.Text = (string)_roadName;

                this.lblLat.Text = _lat;
                this.lblLng.Text = _lng;
            };
            //添加运行到关键点的事件响应
            Action <GPSPoint> ringer = _point =>
            {
                if (_point != null)
                {
                    this.currentRoadName = _point.RoadName;
                    this.Invoke(actringer, _point.RoadName, _point.Lat.ToString(), _point.Lng.ToString());

                    Debug.WriteLine(_point.FormatPointString());
                }
                else
                {
                    this.timer.Enabled = false;
                    postjson(0, 0, "end");
                    this.btnRestart.Enabled = true;

                    Debug.WriteLine("simulation end !");
                }
            };
            Action <List <string> > actRoadSelectRinger = (_roadList) =>
            {
                this.btnRoad1.Text = "";
                this.btnRoad2.Text = "";
                if (_roadList.Count > 0)
                {
                    this.btnRoad1.Text = _roadList[0];
                }
                if (_roadList.Count > 1)
                {
                    this.btnRoad2.Text = _roadList[1];
                }
            };
            //添加当该条路线有继续运行的路时的事件响应
            Action <List <string> > RoadSelectRinger = _list =>
            {
                Debug.WriteLine("选择下一条路线:");
                //打印出可以选择的道路
                foreach (string s in _list)
                {
                    Debug.WriteLine("next road => " + s);
                }

                this.Invoke(actRoadSelectRinger, _list);
            };

            player = RoadPlayer.InitializeRoadPlayer(roads, ringer, RoadSelectRinger);

            pointTemp = player.Play();
            ringer(pointTemp);

            this.timer.Enabled = true;
        }
Esempio n. 3
0
 public void AddPoint(GPSPoint _point)
 {
     _point.IndexInList = this.PointList.Count;
     _point.RoadName    = this.RoadName;
     PointList.Add(_point);
 }