Exemple #1
0
        private static KMLPlacemark ReadPlacemark(XmlReader reader)
        {
            string name        = string.Empty;
            string description = string.Empty;

            KMLPlacemarkItem item = null;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name.ToUpper())
                    {
                    case "NAME":
                    {
                        name = TinyKML.ReadString(reader);
                        break;
                    }

                    case "DESCRIPTION":
                    {
                        description = TinyKML.ReadString(reader);
                        break;
                    }

                    case "POINT":
                    {
                        item = (KMLPoint)TinyKML.ReadPlacemarkItem(reader);

                        if (item != null)
                        {
                            return(new KMLPlacemark(name, description, item));
                        }
                        else
                        {
                            throw new FormatException();
                        }
                    }

                    case "LINESTRING":
                    {
                        item = (KMLLineString)TinyKML.ReadPlacemarkItem(reader);

                        if (item != null)
                        {
                            return(new KMLPlacemark(name, description, item));
                        }
                        else
                        {
                            throw new FormatException();
                        }
                    }
                    }
                }
            }

            throw new FormatException();
        }
Exemple #2
0
        private static KMLPlacemarkItem ReadPlacemarkItem(XmlReader reader)
        {
            bool isExtrude    = false;
            bool isTessallate = true;
            List <KMLLocation> coordinates = null;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name.ToUpper())
                    {
                    case "EXTRUDE":
                    {
                        isExtrude = Convert.ToBoolean(TinyKML.ReadInt(reader));
                        break;
                    }

                    case "TESSALLATE":
                    {
                        isTessallate = Convert.ToBoolean(TinyKML.ReadInt(reader));
                        break;
                    }

                    case "COORDINATES":
                    {
                        coordinates = KMLLocation.Parse(TinyKML.ReadString(reader));

                        if (coordinates == null)
                        {
                            throw new FormatException();
                        }

                        if (coordinates.Count == 1)
                        {
                            return(new KMLPoint(coordinates[0], isExtrude, isTessallate));
                        }
                        else
                        {
                            return(new KMLLineString(isExtrude, isTessallate, coordinates.ToArray()));
                        }
                    }
                    }
                }
            }

            throw new FormatException();
        }
Exemple #3
0
        public static KMLData Read(string fileName)
        {
            KMLData result = new KMLData();

            using (XmlReader reader = XmlReader.Create(fileName))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name.ToUpper())
                        {
                        case "NAME":
                        {
                            result.Name = TinyKML.ReadString(reader);
                            break;
                        }

                        case "DESCRIPTION":
                        {
                            result.Name = TinyKML.ReadString(reader);
                            break;
                        }

                        case "PLACEMARK":
                        {
                            result.Add(TinyKML.ReadPlacemark(reader));
                            break;
                        }
                        }
                    }
                }
            }

            return(result);
        }