Ejemplo n.º 1
0
        /// <summary>
        /// Returns the KML file at the specified <paramref name="path"/>.
        ///
        /// If the KMZ file's <see cref="KmlDocument.NetworkLink"/> property indicates another KML or KMZ file, that file will be retrieved and returned instead.
        /// </summary>
        /// <param name="path">The path to the file on disk.</param>
        /// <returns>An instance of <see cref="KmlFile"/>.</returns>
        public static KmlFile LoadKml(string path)
        {
            KmlFile kml;

            // Get the KML file from the KMZ file at "path"
            using (KmzFile kmz = OpenRead(path)) {
                kml = kmz.Kml;
            }

            // If the KML file doesn't have a network link, we'll just return it right away
            if (kml.Document.HasNetworkLink == false)
            {
                return(kml);
            }

            // Get the KML or KMZ file specified by the network link
            HttpResponse response = (HttpResponse)HttpUtils.Requests.Get(kml.Document.NetworkLink.Link.Href);

            // Parse the response body
            switch (response.ContentType)
            {
            case KmlConstants.KmlMimeType:
                return(KmlFile.Parse(response.Body));

            case KmlConstants.KmzMimeType:
                using (KmzFile kmz = Parse(response.BinaryBody)) return(kmz.Kml);

            default:
                throw new KmzException("Unknown mime type " + response.ContentType);
            }
        }
Ejemplo n.º 2
0
        private KmlFile LoadKmlFile()
        {
            ZipArchiveEntry entry = Archive.GetEntry("doc.kml");

            if (entry == null)
            {
                throw new KmzException("KMZ file is missing doc.kml entry");
            }

            using (Stream stream = entry.Open()) {
                using (StreamReader reader = new StreamReader(stream)) {
                    return(KmlFile.Parse(reader.ReadToEnd()));
                }
            }
        }