예제 #1
0
        private void ListBoxMyPersonalData_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListBox lb       = sender as ListBox;
            int     oldCount = lb.Items.Count;

            if (lb.SelectedItem != null)
            {
                int index = lb.SelectedIndex;
                UpdateStatusBar("Item sélectionné" + index.ToString() + " :) ");
                Console.WriteLine(mP.CartoCollection[index].ToString());
                WindowItemProperty wItem = new WindowItemProperty(index);
                wItem.ShowDialog();

                lb.Items.Refresh();
                RefreshMap();
            }
        }
예제 #2
0
        /// Va gérer les clicks sur la map en fonction du mode dans lequel on se trouve
        private void myMap_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            UpdateStatusBar("MouseLeftButtonDown");
            if (status != null)
            {
                System.Windows.Point mousePosition = e.GetPosition(myMap);
                ICoord     obj;
                bool       trouve = false;
                List <int> index = new List <int>();
                double     distancemin, distanceTmp;

                Location loc = new Location();
                loc = myMap.ViewportPointToLocation(mousePosition);

                int i = 0, distPos = 0;
                ///ISPointClose
                ///On cherche les CartoObj proche
                foreach (ICartoObj cartoObj in mP.CartoCollection)
                {
                    Console.WriteLine("Test : cartoObj = " + cartoObj);
                    Console.WriteLine("location = " + loc.Latitude + " / " + loc.Longitude);
                    if (cartoObj.IsPointClose(loc.Latitude, loc.Longitude, mP.Precision) == true)
                    {
                        Console.WriteLine("IS POINT CLOSE TRUE");
                        trouve = true;
                        index.Add(i);
                        //obj = cartoObj.WhichPointIsClose(e.GetPosition(myMap).X,e.GetPosition(myMap).Y);
                    }
                    i++;
                }

                if (trouve)
                {
                    Console.WriteLine("ON A TROUVE UN POINT PROCHE");
                    ///On va devoir trouver quel CartoObj est le plus proche
                    ICoord[] objtmp = new ICoord[index.Count];

                    i = 0;
                    for (int j = 0; j < index.Count; j++)
                    {
                        objtmp[i] = mP.CartoCollection[index[j]].WhichPointIsClose(loc.Latitude, loc.Longitude);
                        i        += 1;
                    }
                    ///Comparer la distance entre chaque
                    i           = 0;
                    distancemin = -1;

                    foreach (ICoord coord in objtmp)
                    {
                        Console.WriteLine("Comparaison avec le point : " + coord.X + "/" + coord.Y);
                        Console.WriteLine("Point click : " + loc.Latitude + "/" + loc.Longitude);
                        distanceTmp = MathUtil.DistanceDeuxPoints(coord.X, coord.Y, loc.Latitude, loc.Longitude);
                        if (distancemin == -1)
                        {
                            distancemin = distanceTmp;
                            distPos     = i;
                        }
                        if (distancemin > distanceTmp)
                        {
                            distancemin = distanceTmp;
                            distPos     = i;
                        }
                        i += 1;
                    }
                    Console.WriteLine("Point le plus proche : " + objtmp[distPos].X + "/" + objtmp[distPos].Y);
                    ///Arriver ici, nous avons les coordonnées du point le plus proche
                    if (objtmp[distPos] is POI)
                    {
                        if (RBPoi.IsChecked == true)
                        {
                            ///Pas de superposition de pushpin
                            loc = new Location();
                            loc = myMap.ViewportPointToLocation(mousePosition);
                            obj = new POI(loc.Latitude, loc.Longitude);
                        }
                        else
                        {
                            obj = objtmp[distPos];
                            loc = new Location(obj.X, obj.Y);
                        }
                    }
                    else
                    {
                        if (RBPoi.IsChecked == true)
                        {
                            obj = new POI(objtmp[distPos].X, objtmp[distPos].Y);
                        }
                        else
                        {
                            obj = objtmp[distPos];
                        }

                        loc = new Location(obj.X, obj.Y);
                    }
                }
                else
                {
                    Console.WriteLine("ON A PAS TROUVE DE POINT PROCHE");
                    loc = new Location();
                    loc = myMap.ViewportPointToLocation(mousePosition);
                    Console.WriteLine("Loc = " + loc.Latitude + "/ " + loc.Longitude);
                    if (status == "Créer")
                    {
                        if (RBPoi.IsChecked == true)
                        {
                            obj = new POI(loc.Latitude, loc.Longitude);
                        }
                        else
                        {
                            obj = new Coordonnees(loc.Latitude, loc.Longitude);
                        }
                    }
                    else
                    {
                        obj = null; ///Ne plus avoir l'erreur ligne 262 (utilisation d'une variable non assigné)
                    }
                }
                index.Clear();

                Console.WriteLine("Location = ", loc.Longitude + " / " + loc.Latitude);
                switch (status)
                {
                case "Créer":
                {
                    UpdateStatusBar("MouseLeftButtonDownCréer");

                    if (RBPoi.IsChecked == true)
                    {
                        Pushpin pin = new Pushpin();
                        pin.Location = loc;
                        myMap.Children.Add(pin);
                        mP.AddCartObj(obj as POI);
                        Console.WriteLine("Test après add : " + mP.CartoCollection.Last().lCoord.Last());

                        UpdateStatusBar(mP.CartoCollection.Last().ToString());
                        //ListBoxMyPersonalData.Items.Add(new POI(loc.Latitude,loc.Longitude));
                    }
                    if (RBPolyline.IsChecked == true)
                    {
                        if (coordTmp.Count == 0)
                        {
                            maPolyline = new MapPolyline();
                            myMap.Children.Add(maPolyline);
                            locCol = new LocationCollection();
                            maPolyline.Locations       = locCol;
                            maPolyline.StrokeThickness = mP.lineEp;
                            maPolyline.Stroke          = ToBrush(mP.Contour);
                            maPolyline.Opacity         = mP.Opacity;
                        }


                        if (coordTmp.Count > 2)
                        {
                            if ((coordTmp[0].X <= obj.X + mP.Precision && coordTmp[0].X >= obj.X - mP.Precision) && (coordTmp[0].Y <= obj.Y + mP.Precision && coordTmp[0].Y >= obj.Y - mP.Precision))
                            {
                                ///Notre polyline est revenu a son point de départ -> Polygon ?
                                MessageBoxResult res = MessageBox.Show("Voulez-vous en faire un polygon ? ", "Polygon", MessageBoxButton.YesNo);
                                if (res == MessageBoxResult.Yes)
                                {
                                    ///On va enfaire un polygon

                                    maPolygon = new MapPolygon();
                                    myMap.Children.Add(maPolygon);
                                    maPolygon.Locations       = locCol;
                                    maPolygon.StrokeThickness = mP.lineEp;
                                    maPolygon.Stroke          = ToBrush(mP.Contour);
                                    maPolygon.Fill            = ToBrush(mP.Remplissage);
                                    maPolygon.Opacity         = mP.Opacity;
                                    maPolygon.Locations       = maPolyline.Locations;
                                    RBPolygon.IsChecked       = true;
                                    RBPolyline.IsChecked      = false;
                                    ButtonFinirTrace_Click(null, null);

                                    return;
                                }
                            }
                        }
                        maPolyline.Locations.Add(loc);

                        coordTmp.Add(obj);
                    }
                    if (RBPolygon.IsChecked == true)
                    {
                        if (coordTmp.Count == 0)
                        {
                            maPolygon = new MapPolygon();
                            myMap.Children.Add(maPolygon);
                            locCol = new LocationCollection();
                            maPolygon.Locations       = locCol;
                            maPolygon.StrokeThickness = mP.lineEp;
                            maPolygon.Stroke          = ToBrush(mP.Contour);
                            maPolygon.Fill            = ToBrush(mP.Remplissage);
                            maPolygon.Opacity         = mP.Opacity;
                        }
                        coordTmp.Add(obj);

                        maPolygon.Locations.Add(loc);
                    }
                    break;
                }

                case "Supprimer":
                {
                    Console.WriteLine("Supprimer");
                    if (trouve)
                    {
                        bool find = false;
                        int  j = 0, a = 0;

                        ///On sait sur quel point/figure on clique, on doit retrouver la position de chaque
                        while (j < mP.CartoCollection.Count && find == false)
                        {
                            a = 0;
                            while (a < mP.CartoCollection[j].lCoord.Count && find == false)
                            {
                                if (mP.CartoCollection[j].lCoord[a].X == loc.Latitude && mP.CartoCollection[j].lCoord[a].Y == loc.Longitude)
                                {
                                    find = true;
                                }
                                else
                                {
                                    a++;
                                }
                            }
                            if (!find)
                            {
                                j++;
                            }
                        }
                        if (find)
                        {
                            Console.WriteLine("TROUVE");
                            // J contient l'index de la figure contenant le point sélectionné
                            myMap.Children.Remove(myMap.Children[j]);
                            mP.CartoCollection.Remove(mP.CartoCollection[j]);
                            //ListBoxMyPersonalData.Items.Refresh();
                        }
                    }

                    break;
                }

                case "Modifier":
                {
                    ///On va récupérer l'index
                    if (trouve)
                    {
                        bool find = false;
                        int  j = 0, a = 0;
                        while (j < mP.CartoCollection.Count && find == false)
                        {
                            a = 0;
                            while (a < mP.CartoCollection[j].lCoord.Count && find == false)
                            {
                                if (mP.CartoCollection[j].lCoord[a].X == loc.Latitude && mP.CartoCollection[j].lCoord[a].Y == loc.Longitude)
                                {
                                    find = true;
                                }
                                else
                                {
                                    a++;
                                }
                            }
                            if (!find)
                            {
                                j++;
                            }
                        }
                        if (find)
                        {
                            WindowItemProperty wItem = new WindowItemProperty(j);
                            wItem.ShowDialog();

                            ListBoxMyPersonalData.Items.Refresh();
                            RefreshMap();
                        }
                    }


                    break;
                }
                }
            }
        }