让线路在Google地球上运行

时间:2012-11-19 23:18:07

标签: kml google-earth

所以我一直在筛选GE的文档,并找到了如何使用LineStyle和LineString来设置样式并显示一条线,但实际上我实际上无法使它工作。这是我的KML:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"><Document><Style id="thisStyle">
<LineStyle>
<color>500078F0</color>
<colorMode>Normal</colorMode>
<width>5</width>
</LineStyle>
</Style>
<Placemark>
<name>502-2012-11-19 05:27:03</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0513,42.0894,247</coordinates>
</Point>
</Placemark>
<Placemark>
<name>502-2012-11-19 05:26:46</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0517,42.0886,287</coordinates>
</Point>
</Placemark>
....
<Placemark>
<name>525-2012-11-19 04:38:25</name>
<description>Speed:0</description>
<Point>
<coordinates>-76.0512,42.0894,178</coordinates>
</Point>
</Placemark>
<styleUrl>#thisStyle</styleUrl>
<LineString>
<tessellate>1</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
-76.0513,42.0894,247 
-76.0517,42.0886,287 
....
-76.0512,42.0894,178 
</coordinates></LineString></Document></kml>

注意:上面出现“......”的地方大约有50多个坐标集,为了简洁起见我删除了它们,但由于所有坐标都是由脚本生成的,如果一个有效,我知道它们都会。任何人都可以在正确的方向上推动我,为什么我的地标都出现了,但没有线?

2 个答案:

答案 0 :(得分:1)

LineString元素仅在地标内(或地标内的MultiGeometry)内有效:

<Placemark>
  <LineString>
    <tessellate>1</tessellate>
    <altitudeMode>clampToGround</altitudeMode>
    <coordinates>
      -76.0513,42.0894,247 
      -76.0517,42.0886,287 
      -76.0512,42.0894,178 
    </coordinates>
  </LineString>
</Placemark>

答案 1 :(得分:1)

您必须在地标中内联Style或使用 styleUrl 元素在地标中引用该样式。

您示例中的最后一个地标需要像这样重写:

<Placemark>
    <name>525-2012-11-19 04:38:25</name>
    <description>Speed:0</description>
    <styleUrl>#thisStyle</styleUrl>
    <LineString>
        <tessellate>1</tessellate>
        <altitudeMode>clampToGround</altitudeMode>
        <coordinates>
            -76.0513,42.0894,247 
            -76.0517,42.0886,287
             ...
            -76.0512,42.0894,178 
        </coordinates>
    </LineString>
</Placemark>

如果您的KML没有正确查看,那么通常有助于验证KML。您可以使用KML Validator