2

我正在编写一个 C# 程序,使用http://www.icsharpcode.net/opensource/sharpziplib/ 将包含 KML 文件和图标的 KMZ 文件压缩为 zip 文件。

我的尝试:

  1. 在 Google 地球中打开 KMZ 文件后,现在会显示图标。
  2. 然后我将 KMZ 转换为 zip 文件,以便检查其内容。
  3. 我将图标重命名为不同的名称,然后恢复为原始名称。
  4. 然后我将其改回 KMZ 文件并在 Google 地球中打开,图标显示正常。

关于我在压缩过程中做错了什么会导致图标最初不显示的任何想法?

4

1 回答 1

3

让使用CSharpZipLib创建的 KMZ 文件与 Google 地球一起正常工作的一个技巧是关闭与 Google 地球不兼容的 Zip64 模式。

要使 KMZ 文件在 Google 地球和其他地球浏览器中可互操作,它必须使用“传统”压缩方法(例如 deflate)与 ZIP 2.0 兼容,并且不能使用 Zip64 等扩展名。KML Errata中提到了这个问题。

这是用于创建 KMZ 文件的 C# 代码片段:

using (FileStream fileStream = File.Create(ZipFilePath)) // Zip File Path (String Type)
{
    using (ZipOutputStream zipOutputStream = new ZipOutputStream(fileStream))
    {
        // following line must be present for KMZ file to work in Google Earth
        zipOutputStream.UseZip64 = UseZip64.Off;

        // now normally create the zip file as you normally would 
        // add root KML as first entry
        ZipEntry zipEntry = new ZipEntry("doc.kml");
        zipOutputStream.PutNextEntry(zipEntry);  
        //build you binary array from FileSystem or from memory... 
        zipOutputStream.write(/*binary array*/); 
        zipOutputStream.CloseEntry();
        // next add referenced file entries (e.g. icons, etc.)
        // ...
        //don't forget to clean your resources and finish the outputStream
        zipOutputStream.Finish();
        zipOutputStream.Close();
    }
}
于 2014-03-26T13:21:33.877 回答