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:
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:
- the <a href> element of a <description> (and also <img src> in a <description>)
- <Icon> (as a child of <IconStyle>, <GroundOverlay>, <ScreenOverlay>, <PhotoOverlay>)
- <ItemIcon>
- <Link>
- <gx:SoundCue>
- <targetHref> and <sourceHref> in <Alias>
這些外部鏈接可以是絕對的或相對的引用,就象下列章節描述的那樣. 它們能夠在同一個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.kmzIf 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.
?
轉載于:https://www.cnblogs.com/mylem/archive/2009/12/15/1625121.html
總結
- 上一篇: Django 使用 mysql 数据库连
- 下一篇: 五月28学习笔记