示例#1
0
        private void MoveByRoute()
        {
            double cAngle = 0;

            // последовательный перебор точек маршрута
            for (int i = 0; i < ePoints.Count; i++)
            {
                var point = ePoints[i];
                // делегат, возвращающий управление в главный поток
                Application.Current.Dispatcher.Invoke(delegate {
                    if (i < ePoints.Count - 10)
                    {
                        var nextPoint = ePoints[i + 10];

                        double latDiff = nextPoint.Lat - point.Lat;
                        double lngDiff = nextPoint.Lng - point.Lng;
                        // вычисление угла направления движения
                        // latDiff и lngDiff - катеты прямоугольного треугольника
                        double angle = Math.Atan2(lngDiff, latDiff) * 180.0 / Math.PI;

                        // установка угла поворота маркера

                        if (Math.Abs(angle - cAngle) > 10) //|| (a - angle < 0))
                        {
                            cAngle = angle;
                            carMarker.Shape.RenderTransform = new RotateTransform(angle, 10, 10);
                        }
                    }
                    gMap.Position = carMarker.Position;
                    // изменение позиции маркера
                    carMarker.Position = point;
                    this.point         = point;

                    if (pass != null)
                    {
                        pass.setPosition(point);
                        pass.humanMarker.Position = point;
                        pass.humanMarker.Shape.RenderTransform = new RotateTransform(cAngle, 16, 16);

                        // FollowtheCar?.Invoke(this, null);
                    }
                });
                // задержка 5 мс
                Thread.Sleep(5);
            }
            // отправка события о прибытии после достижения последней точки маршрута
            if (pass == null)
            {
                Arrived?.Invoke(this, null);
            }
            else
            {
                pass = null;

                FollowtheCar?.Invoke(this, null);
                //newThread.Abort();
            }
        }
示例#2
0
 public void passSeated(object sender, EventArgs e)
 {
     MessageBox.Show("Taxi arrived");
     pass = (CHuman)sender;
     Application.Current.Dispatcher.Invoke(delegate {
         gMap.Markers.Add(moveTo(pass.getDestination()));
     });
     // pass.point=point;
 }
示例#3
0
 public CCar(string title, PointLatLng point, GMapControl map) : base(title)
 {
     this.point = point;
     pass       = null;
     gMap       = map;
 }
示例#4
0
        private void Map_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            buttonDoubleClick = true;
            PointLatLng point = Map.FromLocalToLatLng((int)e.GetPosition(Map).X, (int)e.GetPosition(Map).Y);

            if (objType.SelectedIndex > -1 && createFlag == true)
            {
                if (objType.SelectedIndex == 0 && objTitle.Text.Length > 0)
                {
                    CCar car = new CCar(objTitle.Text, pts[0], Map);
                    objs.Add(car);
                    cars.Add(car);
                    if (human != null)
                    {
                        //car.Arrived += human.CarArrived;
                        //  human.passSeated += car.passSeated;
                        // car.ArrivedtoDestination += human.CarArrivedToDestination;
                        // human.passRise += car.passRise;
                    }
                }
                else if (objType.SelectedIndex == 0 && objTitle.Text.Length == 0)
                {
                    MessageBox.Show("Введите имя машины");
                }
                if (objType.SelectedIndex == 1 && objTitle.Text.Length > 0)
                {
                    human = new CHuman(objTitle.Text, pts[0]);
                    objs.Add(human);
                }
                else if (objType.SelectedIndex == 1 && objTitle.Text.Length == 0)
                {
                    MessageBox.Show("Введите имя человека");
                }
                if (objType.SelectedIndex == 2 && objTitle.Text.Length > 0)
                {
                    if (human != null)
                    {
                        human.moveTo(point);

                        CLocation location = new CLocation(objTitle.Text, pts[0]);
                        objs.Add(location);
                    }
                }
                else if (objType.SelectedIndex == 2 && objTitle.Text.Length == 0)
                {
                    MessageBox.Show("Введите название место прибытия");
                }
                pts.Clear();
                Map.Markers.Clear();
                objTitle.Clear();
                objectList.Items.Clear();
                foreach (CMapObject cm in objs)
                {
                    Map.Markers.Add(cm.getMarker());
                    objectList.Items.Add(cm.getTitle());
                }
                foreach (GMapMarker cm in markerTaxi)
                {
                    Map.Markers.Add(cm);
                }
            }
        }
示例#5
0
 private void button1_Click(object sender, RoutedEventArgs e)//add obj
 {
     try
     {
         if (objType.SelectedIndex > -1 && createFlag == true)
         {
             if (objType.SelectedIndex == 0 && objTitle.Text.Length > 0)
             {
                 CCar car = new CCar(objTitle.Text, pts[0], Map);
                 objs.Add(car);
                 cars.Add(car);
             }
             else if (objType.SelectedIndex == 0 && objTitle.Text.Length == 0)
             {
                 MessageBox.Show("Введите имя машины");
             }
             if (objType.SelectedIndex == 1 && objTitle.Text.Length > 0)
             {
                 human = new CHuman(objTitle.Text, pts[0]);
                 objs.Add(human);
             }
             else if (objType.SelectedIndex == 1 && objTitle.Text.Length == 0)
             {
                 MessageBox.Show("Введите имя человека");
             }
             if (objType.SelectedIndex == 2 && objTitle.Text.Length > 0)
             {
                 CLocation location = new CLocation(objTitle.Text, pts[0]);
                 objs.Add(location);
             }
             else if (objType.SelectedIndex == 2 && objTitle.Text.Length == 0)
             {
                 MessageBox.Show("Введите название место прибытия");
             }
             if (objType.SelectedIndex == 3 && pts.Count > 2 && objTitle.Text.Length > 0)
             {
                 CArea area = new CArea(objTitle.Text, pts);
                 objs.Add(area);
             }
             else if (objType.SelectedIndex == 3 && pts.Count <= 2 && objTitle.Text.Length > 0)
             {
                 MessageBox.Show("Обозначьте площадь не менее из 3 точек");
             }
             if (objType.SelectedIndex == 4 && pts.Count > 1 && objTitle.Text.Length > 0)
             {
                 CRoude roude = new CRoude(objTitle.Text, pts);
                 objs.Add(roude);
             }
             else if (objType.SelectedIndex == 4 && pts.Count <= 1 && objTitle.Text.Length > 0)
             {
                 MessageBox.Show("Введите маршрут не менее из 2 точек");
             }
         }
         else if (objType.SelectedIndex > -1 && !createFlag)
         {
         }
         pts.Clear();
         Map.Markers.Clear();
         objTitle.Clear();
         objectList.Items.Clear();
         foreach (CMapObject cm in objs)
         {
             Map.Markers.Add(cm.getMarker());
             objectList.Items.Add(cm.getTitle());
         }
         foreach (GMapMarker cm in markerTaxi)
         {
             Map.Markers.Add(cm);
         }
     }
     catch
     {
         MessageBox.Show("Выберите место");
     }
 }