Example #1
0
        private void MenuFileTrajetImport_Click(object sender, RoutedEventArgs e)//IMPORTE UNE POLYLINE D'UN FICHIER CSV
        {
            string filename = "";

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.DefaultExt = ".csv";
            dlg.Filter     = "CSV Files (*.csv)|*.csv";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                filename = dlg.FileName;

                using (TextFieldParser parser = new TextFieldParser(@filename))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(";");

                    POI poi = new POI();
                    MyCartographyObjects.Polyline line = new MyCartographyObjects.Polyline();
                    List <Coordonnees>            c    = new List <Coordonnees>();
                    LocationCollection            loc  = new LocationCollection();

                    while (!parser.EndOfData)
                    {
                        string[] fields = parser.ReadFields();

                        for (int i = 2; i <= fields.Length; i += 3)
                        {
                            poi = new POI(fields[i], Double.Parse(fields[i - 2]), Double.Parse(fields[i - 1]));

                            Pushpin pin = new Pushpin();
                            pin.Location = new Location(Double.Parse(fields[i - 2]), Double.Parse(fields[i - 1]));

                            if (String.IsNullOrEmpty(poi.Description))
                            {
                                c.Add(new Coordonnees(poi.Latitude, poi.Longitude));
                                loc.Add(new Location(poi.Latitude, poi.Longitude));
                            }
                            else
                            {
                                _myMapData.ObservableCollection.Add(poi);
                            }
                            i += 3;
                        }
                    }

                    if (loc.Count() > 0)
                    {
                        line = new MyCartographyObjects.Polyline(c, LineP);
                        foreach (var point in line.coord)
                        {
                            AddPushPin(point);
                        }
                        DrawLine(line.coord, line.Id, line.Colrs);

                        _myMapData.ObservableCollection.Add(line);
                    }
                }
            }
            listBox.Items.Refresh();
        }
Example #2
0
        private void Trajet_Import_Click(object sender, RoutedEventArgs e)
        {
            string filename = "";

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.DefaultExt = ".csv";
            dlg.Filter     = "CSV Files (*.csv)|*.csv";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                filename = dlg.FileName;

                using (TextFieldParser parser = new TextFieldParser(@filename))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(";");

                    POI                poi  = new POI();
                    Polyline           line = new Polyline();
                    List <Coordonnees> c    = new List <Coordonnees>();

                    while (!parser.EndOfData)
                    {
                        string[] fields = parser.ReadFields();

                        for (int i = 2; i <= fields.Length; i += 3)
                        {
                            poi = new POI(fields[i], Double.Parse(fields[i - 1]), Double.Parse(fields[i - 2]));

                            Pushpin pin = new Pushpin();
                            pin.Location = new Location(Double.Parse(fields[i - 2]), Double.Parse(fields[i - 1]));

                            if (String.IsNullOrEmpty(poi.Description))
                            {
                                c.Add(new Coordonnees(poi.X, poi.Y));
                                loc.Add(new Location(poi.Y, poi.X));
                                nbItems++;
                            }
                            else
                            {
                                myMap.Children.Add(pin);
                                userData.Add(poi);
                                listBox.Items.Add(poi.Description);
                                nbPoi++;
                            }

                            i += 3;
                        }
                    }

                    if (loc.Count() > 0)
                    {
                        line = new Polyline(c, Colors.Black, 1);

                        MapPolyline mapPolyline = new MapPolyline
                        {
                            Locations           = loc,
                            Stroke              = new SolidColorBrush(Colors.Black),
                            SnapsToDevicePixels = true
                        };

                        loc = new LocationCollection();
                        myMap.Children.Add(mapPolyline);

                        userData.Add(line);
                        listBox.Items.Add("Polyline" + nbItems);
                    }
                }
            }
        }