【问题标题】:Variable Substitution in KML Icon ReferenceKML 图标参考中的变量替换
【发布时间】:2014-09-02 18:31:14
【问题描述】:

如何在 kml 图标引用中进行变量替换?我正在使用 Google 地球加载 kml,但在这个简单的示例中我的图片没有出现:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Document>
      <name>TestMap</name>
      <Style id="Icon1">
          <IconStyle>
            <Icon>
              <href>$[url]</href>
            </Icon>
          </IconStyle>
      </Style>
      <Placemark> 
        <name>Hello World</name>
        <styleUrl>#Icon1</styleUrl>
        <ExtendedData>
            <Data name="url"> 
                <value>http://magiccards.info/scans/en/al/232.jpg</value>
            </Data>
        </ExtendedData>
        <Point>
          <coordinates>
            0,0,0
          </coordinates>
        </Point>
      </Placemark>
    </Document>
  </Document>
</kml>

【问题讨论】:

    标签: kml google-earth variable-substitution


    【解决方案1】:

    KML 中扩展数据的变量替换仅适用于描述的上下文,因此您可以通过 description balloon 显示地标的数据 URL。

    <kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>
      <name>Data+BalloonStyle</name>
      <Style id="balloon-style">
        <BalloonStyle>
          <text>
            <![CDATA[
                $[name]<br>
                <img src="$[url]"/>
            ]]>
          </text>
        </BalloonStyle>
      </Style>
      <Placemark>
        <name>Hello World</name>
        <styleUrl>#balloon-style</styleUrl>
        <ExtendedData>
            <Data name="url"> 
                <value>http://magiccards.info/scans/en/al/232.jpg</value>
            </Data>
        </ExtendedData>
        <Point>
          <coordinates>-111.956,33.5043</coordinates>
        </Point>
      </Placemark>
    </Document>
    </kml>
    

    请参阅有关添加自定义数据的相关教程,其中描述了使用 BalloonStyle 元素作为模板
    https://developers.google.com/kml/documentation/extendeddata

    如果您想通过IconStyle 为每个地标显示自定义图标,那么您需要使用适当的 URL 为每个地标定义一个内联样式。

      <Placemark>
        <name>Hello World</name>
        <Style>
          <IconStyle>
            <Icon>
                <href>http://magiccards.info/scans/en/al/232.jpg</href>
            </Icon>
        </IconStyle>
        </Style>
        <Point>
          <coordinates>-111.956,33.5043</coordinates>
        </Point>
      </Placemark>
    

    【讨论】:

    • 我在发布我的问题之前阅读了文档。仅允许在气球中进行变量替换似乎过于受限。我希望有一种方法可以使用替换图标。这似乎是一个基本功能。
    • 实体替换(例如 $[name])仅限于 BalloonStyle 的文本字段或描述元素本身。更通用的替换概念可能有用,但未在 KML 标准中定义。这些功能可以提交给OGC KML Standards Working Group,目前正在完成 KML 2.3。
    猜你喜欢
    • 2021-09-19
    • 2016-05-26
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多