管理 KML 线串属性

Managing a KML Linestring properties

我正在绘制 LineString。出于某种原因,我似乎没有影响 LineStyle。我的代码看起来与许多示例相同,但无论我在 LineStyle 中放置什么颜色或宽度,它总是显示为蓝色粗线。

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>Qtr Min Grid Maker</name>
    <LookAt>
      <longitude>-121.5</longitude>
      <latitude>38</latitude>
      <altitude>0</altitude>
      <range>740933.8825924395</range>
      <tilt>0</tilt>
      <heading>0</heading>
    </LookAt>
    <Folder>
      <name>Grids</name>
  <Style id="linestyle1">
    <LineStyle>
      <color>7f0000ff</color>
      <width>1</width>
      <gx:labelVisibility>1</gx:labelVisibility>
    </LineStyle>
  </Style>   
      <Placemark>
        <name>QTR</name>
        <visibility>0</visibility>
        <open>1</open>
        <styleUrl>#linestyle1</styleUrl>
        <LineString>
  <coordinates>
-124.75,40,0 
-124.5,40,0 
-124.25,40,0 
-124,40,0 
-123.75,40,0 
-123.5,40,0 
-123.25,40,0 
-123,40,0 
  </coordinates>
  </LineString>
  </Placemark>
  </Folder>
  </Document>
</kml>

如果我将共享样式移动到顶层(在 <Document> 标签内),它对我有用:

example

来自the documentation(见<StyleSelector>的描述):

A style defined within a Feature is called an "inline style" and applies only to the Feature that contains it. A style defined as the child of a <Document> is called a "shared style." A shared style must have an id defined for it. This id is referenced by one or more Features within the <Document>.

你的既不是 <Document> 的 child 也不属于 <Placemark>

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
  <Style id="linestyle1">
    <LineStyle>
      <color>7f0000ff</color>
      <width>1</width>
      <gx:labelVisibility>1</gx:labelVisibility>
    </LineStyle>
  </Style>   
    <name>Qtr Min Grid Maker</name>
    <LookAt>
      <longitude>-121.5</longitude>
      <latitude>38</latitude>
      <altitude>0</altitude>
      <range>740933.8825924395</range>
      <tilt>0</tilt>
      <heading>0</heading>
    </LookAt>
    <Folder>
      <name>Grids</name>
      <Placemark>
        <name>QTR</name>
        <visibility>0</visibility>
        <open>1</open>
        <styleUrl>#linestyle1</styleUrl>
        <LineString>
  <coordinates>
-124.75,40,0 
-124.5,40,0 
-124.25,40,0 
-124,40,0 
-123.75,40,0 
-123.5,40,0 
-123.25,40,0 
-123,40,0 
  </coordinates>
  </LineString>
  </Placemark>
  </Folder>
  </Document>
</kml>