远-方的博客

KMZ文件学习

什么是KMZ文件?

 

一个KMZ文件 由一个主KML文件和0至多个支持文件组成,并使用ZIP压缩格式打包压成一个文件,

称之为 an archive。当KMZ文件被解压后,主kml文件和它的支持文件被分离,返回它们的原始格

式和目录结构,依据KML文件的内容,压缩率一般为10:1。

Google Earth和Google Maps能够直接读取KML和KMZ文件,也能够保存为KMZ文件,默认情况下,主

KML文件被命名为 doc.kml。

说明:为了说明的清楚,本文档对KMZ文件中的主KML文件名称定为doc.kml.这个主KML文件也可以

有任意的其他名称,只要它是kml的扩展名,并且仅有一个KML文件即可。

如果你的doc.kml文件大于10Kb,或者doc.kml文件引用了其他文件(images, sound files,

models, textures),那么你应该建立一个KMZ文件。

 

推荐的目录结构:

 

这段为KML/KMZ文件的创建者们提供一些推荐方案,

The example used in this section is from the Jimmy Buffett website, which uses the KML format to show planned concert tours and related highlights on Google Earth.

""


 

Download the KMZ file that contains this tour. (Used by permission.)

一般来说,这些是指导而不是规则,但是如果你按以下指导去做的话,将会减少很多不必要的麻烦:

  • 创建一个目录来存放你的KMZ文件. 用一个描述性的文字来命名它 (for example, buffetthawaiitour).
  • 把默认的KML文件(doc.kml或你自定的其他名称)放在该目录下(不要放到它的子目录中).且仅可以有一个 .kml file. (当 Google Earth 打开一个 KMZ file, 它扫描文件, 在列表中查找第一个 .kml file, 如果这个文件中还有其他.kml文件的话,它将忽略第一个kml后的所有 .kml files. 如果 the archive 中包括了多个 .kml files, 你将不能确定哪一个kml文件会被首先发瑞,因此,你还是仅有一个KML文件比较好.)
  • 该主目录中包括一个或多个子目录以存放 images, models, textures, sound files, 或者其他 doc.kml file中引用的其他资源.这个目录的复杂程度取决于你引用的支持文件的数量.
  • 使用相对目录引用. See References to External Files for more details.
  • 在KMZ文件中及任何子目录中都不能再使用 .kmz 扩展名.

       

      例子: here is the file structure of the KMZ file for the Jimmy Buffett tour:

      ""

       

      由于只有5个支持文件, 它们都存放到一个 files 子目录中. If you load the file into Google Earth and then copy and paste it into a text browser, you'll see that all of the <href> elements use relative references to these supporting files (which represent icons, a screen overlay, and the sound file for the tour).

      Here is the KML code for one of the icon references:

      <IconStyle>
        <scale>1.1</scale>
        <Icon>
          <href>files/icon_surfing.png</href>
        </Icon>
      </IconStyle>
      

      Here is the KML code for the reference to the sound file:

      <gx:SoundCue>
        <href>files/Margaritaville.mp3</href>
      </gx:SoundCue>
      

      引用外部文件

      The doc.kml file 通常包括一些其他文件的链接—images, icons, models, textures, and sound files. 对这些文件的引用使用 href 属性 (or sometimes, the <href> element), which can be found in the following KML elements:

      这些外部链接可以是绝对的或相对的引用,就象下列章节描述的那样. 它们能够在同一个KMZ文件中引用文件, 或者是包含在其他 KMZ files中的或者是存储在 web上的什么地方的文件. With the exception of the <sourceHref> element in <Model>, relative references are always resolved in relation to the doc.kml file, as explained in the section Resolving Relative References.

      Absolute vs. Relative References

      Absolute references contain the full URL for the linked file. They are useful for files posted on a central server and are unambiguous. However, if you use absolute references to local files, the links will break when the files are moved to a new system. Relative references avoid this problem.

      Here is an example of an absolute reference to a file stored on a central server:

      <Icon>
        <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
      </Icon>
      

      Resolving Relative References

      In general, relative references are resolved in relation to the doc.kml file. Any relative URL is resolved against the directory that contains this file, which is considered the root of the KMZ file. In the Hawaiian tour example, the base URL is similar to the following (depending on where you download the KMZ file):

      buffetthawaiitour.kmz

      If you wanted to refer to a file located in a different KMZ file (for example, to images/jimmyphoto.jpg contained in margaritavillealbum.kmz, you would use the ".." notation to go up one level in the directory structure, which would take you out of the current KMZ file (buffetthawaiitour.kmz):

      <href>../margaritavillealbum.kmz/images/jimmyphoto.jpg"</href>

      Note: The rules for resolving relative references in a KMZ archive are based on the RFC 3986 Section 5 standard for resolving web URLs. The base URL is determined by the location of the doc.kml file, and all relative URLs are resolved in relation to that base URL.

      The Exception: <sourceHref> in <Model>

      The <Model> element contains a <Link> element that specifies a COLLADA file to load into Google Earth. COLLADA files specify 3D objects and have a .dae file extension. The <Model> element also contains an <Alias> element, that contains a mapping between the <targetHref> (the texture file to be fetched by Google Earth) and the <sourceHref> (the path specified for the texture file in the COLLADA .dae file). If the <sourceHref> element contains a relative path, Google Earth interprets this path as relative to the .dae file that references it (not relative to the doc.kml file as in all other cases). For example:

      <Model>
      .
      .
      .
        <Link>
          <href>MackyBldg.kmz/files/CU Macky.dae</href>
        </Link>
        <ResourceMap>
          <Alias>
            <sourceHref>../files/StairsnoCulling.jpg</sourceHref>
            <targetHref>../files/StairsnoCulling.jpg</targetHref>
          </Alias>
          <Alias>
            <sourceHref>../files/sideturretnoCulling.jpg</sourceHref>
            <targetHref>../files/sideturretnoCulling.jpg</targetHref>
      	</Alias>
      .
      .
      .
      </Model>
      

      Creating the KMZ Archive

      Use Windows Explorer or the Mac Finder to create a Zip archive. Select the contents of the folder that contains the doc.kml file and related resources and choose an option such as "WinZip > Add to Zip file ...." The Java JAR library also has a Zip library for programmatically creating and extracting a Zip archive, and Linux has command line versions of zip and unzip.

      Note: When you are creating the Zip archive, be sure to select the contents of the folder containing the doc.kml file, not the folder itself.

      After you create the archive, change the .zip file extension to .kmz. To extract the files from the archive, change the .kmz file extension back to .zip and use the Zip utility to unzip the archive.

      Google Earth and KMZ Archives

      Use of the <iframe> Element

      Within KML <description> balloons, most HTML elements are treated in Google Earth just as they're treated in standard web browsers. An <iframe> within a description balloon, however, is treated as straight HTML, which means that special KML features are not recognized. For example, an <iframe> cannot display KMZ resources, and local anchor links, such as <a href="#my feature;flyto">, are not recognized. The <src> element within an <iframe> element cannot point to a local file on disk, nor can it point to a file inside a KMZ file; it must point to a URL on the Internet that a browser can visit.

 

posted on 2009-12-15 22:26  远-方  阅读(2317)  评论(0编辑  收藏  举报

导航