//Ajouter un item private void AddItem(Location pinLocation) { if (POI_Box.IsSelected == true) { //La position du pin sur la carte Pushpin pin = new Pushpin(); POI TmpPoi = new POI(pinLocation.Latitude, pinLocation.Longitude, ""); OptPOI text = new OptPOI(TmpPoi); text.ShowDialog(); //bloque la page pin.Tag = TmpPoi; pinLocation.Latitude = TmpPoi.Latitude; pinLocation.Longitude = TmpPoi.Longitude; pin.Location = pinLocation; //Ajoute le pin a la carte map.Children.Add(pin); //Ajoute à la liste User.Liste.Add(TmpPoi); StatBar.Text = "POI added"; //Affichage dans la StatusBar } if (Polyline_Box.IsSelected == true) { if (ListeTmp == null) { ListeTmp = new List <Coordonnees>(); PolylineTpm = new MapPolyline { Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue), StrokeThickness = 3, Opacity = 1, Locations = new LocationCollection() }; map.Children.Add(PolylineTpm); } ListeTmp.Add(new Coordonnees(pinLocation.Latitude, pinLocation.Longitude)); PolylineTpm.Locations.Add(new Location(pinLocation.Latitude, pinLocation.Longitude)); if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { Polyline TmpPolyline = new Polyline { Coordonnees = ListeTmp }; OptPolyline text = new OptPolyline(TmpPolyline); text.ShowDialog(); //bloque la page //Ajoute à la liste PolylineTpm.StrokeThickness = TmpPolyline.Epaisseur; User.Liste.Add(TmpPolyline); map.Children.Remove(PolylineTpm); PolylineTpm.Stroke = new System.Windows.Media.SolidColorBrush(TmpPolyline.Couleur); map.Children.Add(PolylineTpm); PolylineTpm = null; ListeTmp = null; } StatBar.Text = "Polyline added"; //Affichage dans la StatusBar } if (Polygone_Box.IsSelected == true) { if (ListeTmp == null) { ListeTmp = new List <Coordonnees>(); PolygonTpm = new MapPolygon { Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.LightBlue), Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue), StrokeThickness = 3, Opacity = 0.6, Locations = new LocationCollection() }; map.Children.Add(PolygonTpm); } ListeTmp.Add(new Coordonnees(pinLocation.Latitude, pinLocation.Longitude)); PolygonTpm.Locations.Add(new Location(pinLocation.Latitude, pinLocation.Longitude)); if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { Polygon TmpPolygon = new Polygon { Coordonnees = ListeTmp }; OptPolygon text = new OptPolygon(TmpPolygon); text.ShowDialog(); //bloque la page //Ajoute à la liste User.Liste.Add(TmpPolygon); map.Children.Remove(PolygonTpm); PolygonTpm.Fill = new System.Windows.Media.SolidColorBrush(TmpPolygon.CouleurRemplissage); PolygonTpm.Stroke = new System.Windows.Media.SolidColorBrush(TmpPolygon.CouleurContour); PolygonTpm.Opacity = TmpPolygon.Opacite; map.Children.Add(PolygonTpm); PolygonTpm = null; ListeTmp = null; } StatBar.Text = "Polygon added"; //Affichage dans la StatusBar } }
//Fonction pour importer les Polygons d'un ficher .CSV private void Polygon_Import_Button(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog { InitialDirectory = "c:\\", Filter = "csv files (*.csv)|*.csv" }; if (openFileDialog.ShowDialog() == true) { try { using (StreamReader sr = new StreamReader(openFileDialog.FileName)) { string line = ""; while ((line = sr.ReadLine()) != null) { string[] list = Regex.Split(line, @";+"); //C'est que c'est un POI donc ajout du POI if (list[2] != String.Empty) { Pushpin pin = new Pushpin(); Location pinLocation = new Location(); POI TmpPoi = new POI(Convert.ToDouble(list[0]), Convert.ToDouble(list[1]), list[2]); pin.Tag = TmpPoi; pinLocation.Latitude = TmpPoi.Latitude; pinLocation.Longitude = TmpPoi.Longitude; pin.Location = pinLocation; //Ajoute le pin a la carte map.Children.Add(pin); //Ajoute à la liste User.Liste.Add(TmpPoi); } if (ListeTmp == null) { ListeTmp = new List <Coordonnees>(); PolygonTpm = new MapPolygon { Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.LightBlue), Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue), StrokeThickness = 3, Opacity = 0.6, Locations = new LocationCollection() }; } ListeTmp.Add(new Coordonnees(Convert.ToDouble(list[0]), Convert.ToDouble(list[1]))); PolygonTpm.Locations.Add(new Location(Convert.ToDouble(list[0]), Convert.ToDouble(list[1]))); } Polygon TmpPolygon = new Polygon { Coordonnees = ListeTmp }; TmpPolygon.Description = openFileDialog.SafeFileName; //Ajoute à la liste User.Liste.Add(TmpPolygon); map.Children.Add(PolygonTpm); PolygonTpm = null; ListeTmp = null; } StatBar.Text = "Path imported"; //Affichage dans la StatusBar } catch (Exception) { ErrorWindow error = new ErrorWindow("The file could not be read"); error.ShowDialog(); //bloque la page } } }