2013-08-28 73 views
1

我有一個問題,指的是在BalloonStyle教程在KML documentiation的名字: BalloonStyle DocumentationKML文件顯示實體的置換

這個KML文件播放各地:

<kml xmlns="http://www.opengis.net/kml/2.2"> 
<Document> 
    <name>ExtendedData+SchemaData</name> 
    <open>1</open>  
    <!-- Create a balloon template referring to the user-defined type --> 
    <Style id="trailhead-balloon-template">  
    <BalloonStyle>  
     <text> 
     <![CDATA[   
      <h2>My favorite trails!</h2>   
      <br/><br/>   
      The $[TrailHeadType/TrailHeadName/displayName] is <i>$[TrailHeadType/TrailHeadName]</i>.   
      The trail is $[TrailHeadType/TrailLength] miles.   <br/>   
      The climb is $[TrailHeadType/ElevationGain] meters.   <br/><br/>  
     ]]> 
     </text>  
    </BalloonStyle> 
    </Style>  

    <!-- Declare the type "TrailHeadType" with 3 fields --> 
    <Schema name="TrailHeadType" id="TrailHeadTypeId">  
    <SimpleField type="string" name="TrailHeadName">  
     <displayName><![CDATA[<b>Trail Head Name</b>]]></displayName>  
    </SimpleField>  
    <SimpleField type="double" name="TrailLength">  
     <displayName><![CDATA[<i>The length in miles</i>]]></displayName>  
    </SimpleField>  
    <SimpleField type="int" name="ElevationGain">  
     <displayName><![CDATA[<i>change in altitude</i>]]></displayName>  
    </SimpleField> 
    </Schema>  

    <!-- Instantiate some Placemarks extended with TrailHeadType fields -->  
    <Placemark>  
    <name>Easy trail</name>  
    <styleUrl>#trailhead-balloon-template</styleUrl>  
    <ExtendedData>  
     <SchemaData schemaUrl="#TrailHeadTypeId">   
     <SimpleData name="TrailHeadName">Pi in the sky</SimpleData>   
     <SimpleData name="TrailLength">3.14159</SimpleData>   
     <SimpleData name="ElevationGain">10</SimpleData>  
     </SchemaData>  
    </ExtendedData>  
    <Point>  
     <coordinates>-122.000,37.002</coordinates>  
    </Point> 
    </Placemark>  
    <Placemark>  
    <name>Difficult trail</name>  
    <styleUrl>#trailhead-balloon-template</styleUrl>  
    <ExtendedData> 
     <SchemaData schemaUrl="#TrailHeadTypeId">   
     <SimpleData name="TrailHeadName">Mount Everest</SimpleData>   
     <SimpleData name="TrailLength">347.45</SimpleData>   
     <SimpleData name="ElevationGain">10000</SimpleData>  
     </SchemaData>  
    </ExtendedData>  
    <Point>  
     <coordinates>-121.998,37.0078</coordinates>  
    </Point> 
    </Placemark> 
</Document> 
</kml> 

當您移除其中一個SimpleData元素,Google地球會從氣球模板中顯示實體替換。例如,您將刪除線<SimpleData name="ElevationGain">10000</SimpleData> 它顯示在氣球中,如「爬升是$ [TrailHeadType/ElevationGain]米」。這看起來不太好。

任何想法如何告訴谷歌地球,它應該不顯示從氣球線,如果有一個缺少SimpleData?

由於提前

回答

0

我不認爲 *你可以做你問這裏是什麼 - 即這個樣式的文本中應用條件邏輯。過去我有類似的要求(我的一些地標中缺少某些數據),並且在生成KML時,我最終針對每種可能的缺失信息方案應用了不同的樣式。

這感覺都非常笨重,如果你有一個或多個項目丟失而其他人存在的情況很多,它可能很快就會變得一團糟。

*很想錯。

UPDATE

只是看着我這個代碼,實際上我最後決定將所有的文字在我的模式中的標領域,並打印出空節點時,我沒有數據 - 也少優雅,但最終並不需要額外的款式。根據您的例子是這樣的:

<BalloonStyle>  
    <text> 
    <![CDATA[   
     <h2>My favorite trails!</h2>   
     $[TrailHeadType/TrailHeadName/displayName] 
     $[TrailHeadType/TrailLengthBalloonText]    
     $[TrailHeadType/ElevationGainBalloonText]    
    ]]> 
    </text>  
</BalloonStyle> 

<Placemark>  
<name>Difficult trail</name>  
<styleUrl>#trailhead-balloon-template</styleUrl>  
<ExtendedData> 
    <SchemaData schemaUrl="#TrailHeadTypeId">   
    <SimpleData name="TrailHeadName">Mount Everest</SimpleData>   
    <SimpleData name="TrailLength">347.45</SimpleData>   
    <SimpleData name="ElevationGain">10000</SimpleData> 

    <SimpleData name="TrailHeadNameBalloonText"><![CDATA[The trail name is Mount Everest</br>]]></SimpleData>   
    <SimpleData name="TrailLengthBalloonText"><![CDATA[The trail is 347.45 miles.</br>]]></SimpleData>   
    <SimpleData name="ElevationGainBalloonText"><![CDATA[The climb is 10000 meters.</br>]]></SimpleData> 
    </SchemaData>  
</ExtendedData>  
<Point>  
    <coordinates>-121.998,37.0078</coordinates>  
</Point> 
</Placemark> 

然後,當你沒有數據你離開這個項目空白:

<Placemark>  
<name>Difficult trail</name>  
<styleUrl>#trailhead-balloon-template</styleUrl>  
<ExtendedData> 
    <SchemaData schemaUrl="#TrailHeadTypeId">   
    <SimpleData name="TrailHeadName">Mount Everest</SimpleData>   
    <SimpleData name="TrailLength">347.45</SimpleData>   
    <SimpleData name="ElevationGain">10000</SimpleData> 

    <SimpleData name="TrailHeadNameBalloonText"><![CDATA[The trail name is Mount Everest</br>]]></SimpleData>   
    <SimpleData name="TrailLengthBalloonText"></SimpleData>   
    <SimpleData name="ElevationGainBalloonText"></SimpleData> 
    </SchemaData>  
</ExtendedData>  
<Point>  
    <coordinates>-121.998,37.0078</coordinates>  
</Point> 
</Placemark> 
+0

感謝這個答案...;) – berkley

0

正如我的數據經常變化不知何故,我現在提供了一個XML文件鏈接到一個css文件並將其嵌入到描述中的iframe中。對於脫機使用,創建一個kmz並將xml和css放入它。

對於一個小教程看看這裏: http://www.w3schools.com/xml/xml_display.asp

在KML,它看起來如下:

<description> 
    <![CDATA[ 
     <iframe src="http://www.w3schools.com/xml/cd_catalog_with_css.xml"></iframe> 
    ]]> 
</description>