Save all Marker-Position

Topics: Etc...
Mar 1, 2012 at 12:45 PM

Hello @all,

 

i can add some markers an then generate a Polygon.

Now i want to save the polygonPoints as txt with Xml.Serialization. I can save 2 points start and end like this that works:

            saveFileDialog1.ShowDialog();
            string filename = saveFileDialog1.FileName;
            TextWriter tx = new StreamWriter(filename);
            XmlSerializer sw = new XmlSerializer(typeof(PointLatLng));
            sw.Serialize(tx, start);
            sw.Serialize(tx, end);
            tx.Close();

 

But how i can do it with the polygonPoints? i think i need a counter?

thanks at alll :)

 

Coordinator
Mar 1, 2012 at 12:57 PM

sw.Serialize(tx, p1);
sw.Serialize(tx, p2);
sw.Serialize(tx, p3);
sw.Serialize(tx, p4);
sw.Serialize(tx, p5);
sw.Serialize(tx, p6);
sw.Serialize(tx, pN);

;}

Mar 6, 2012 at 9:32 AM

Really?

i think that is a difficult path, what happend, if i have millions of polygonPoints?

Coordinator
Mar 6, 2012 at 9:39 AM

what if sun explode?

Mar 6, 2012 at 9:40 AM

@hakan80 - put all to some kind of list - List<type> myList, then use method Add - and some part of my code:

  public static void setDataToXML<T>(T data, string fileName)
        {

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                TextWriter textWriter = new StreamWriter(@fileName);
                serializer.Serialize(textWriter, data);
                textWriter.Close();
            }
            catch (UnauthorizedAccessException)
            {
                    MessageBoxResult result = MessageBox.Show("Aplication can not write profile file. Check if there is\n enough space on disk.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                
            }
        }

Mar 13, 2012 at 10:06 AM

thxxx it was very easy :)

Mar 21, 2012 at 8:42 AM
Edited Mar 21, 2012 at 8:45 AM

hello, me again :)

points save is done, now i want to load this xml-file.

Loading my test.txt file with XmlTextReader, but how can i set the potins as new PointLatLng(lat, lng)?

my code:

XmlTextReader xtr = new XmlTextReader("test.txt");

            while (xtr.Read())
            {
                if (xtr.NodeType == XmlNodeType.Element)
                {                                
                        if (xtr.Name == "Lat")
                        {
                            xtr.Read();
                            textBox3.Text += xtr.Value;
                            textBox3.Text += "\r\n";
                        }

                        if (xtr.Name == "Lng")
                        {
                            xtr.Read();
                            textBox4.Text += xtr.Value;
                        }

--> now i can see the points Lat and Lng  on each textbox.

Mar 21, 2012 at 11:40 AM

In the same way as writen to file. It will return specified by you structure of data.

  public static T getDataFromXML<T>(string fileName)
        {
            T temp = default(T);

            XmlSerializer serializer = new XmlSerializer(typeof(T));


            try
            {
                TextReader textReader = new StreamReader(@fileName);

                temp = (T)serializer.Deserialize(textReader);

                textReader.Close();


            }
            catch (FileNotFoundException)
            {

                MessageBoxResult result = MessageBox.Show("Description file " + fileName + " doesn't exist", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

            }

            catch (DirectoryNotFoundException e)
            {

                MessageBoxResult result = MessageBox.Show("Directory not found." + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

            }

            return temp;
              
        }

Mar 22, 2012 at 9:31 AM
Edited Mar 22, 2012 at 10:43 AM

thxx for help :)

with  this code i can add a polygon from my xml-file,

GMapPolygon P = new GMapPolygon(temp, "test");
  polygons.Polygons.Add(P);

but i want to add also my marker for each points  how can i change my List in each point?

i think with index of list: temp[1].Lat.ToString();??

Mar 22, 2012 at 12:14 PM

problem ist solved, with index was the right answer :)

thxx again to radioman and herbatnic

Coordinator
Mar 22, 2012 at 12:36 PM

..i was lazy on this, cheers! ;}