Search code examples
google-mapslinekmlgoogle-earthregion

Line label not displayed when using Region on kml file for GE


I have a kml file base on the on the tutorials presented by Google Earth developer website and by this link. My goal is to draw a line which is contained within a region (fades as I zoom out from it) and that is able to display the label name along the line trajectory.

enter image description here

Instead of the question mark I would like to have the name of such line.

So far I have implemented this lines of code:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
   <name>KmlFile</name>
   <Placemark>
      <name>SFO to LAX</name>
      <Style id="line_label">
      <LabelStyle>
         <scale>10</scale>
      </LabelStyle>
      <LineStyle>
          <color>ff00ffff</color>
          <width>5</width>
          <gx:labelVisibility>1</gx:labelVisibility>
      </LineStyle>
      </Style>
      <LineString>
         <tessellate>1</tessellate>
         <coordinates>
         -118.40897,33.943492,0 -122.383103,37.617112,0 
         </coordinates>
      </LineString>
      <Region> 
      <LatLonAltBox>
         <north>37.617112</north>
         <south>33.943492</south>
         <east>-118.40897</east> 
         <west>-122.383103</west> 
         <minAltitude>0</minAltitude>
         <maxAltitude>200000</maxAltitude>
         <altitudeMode>clampToGround</altitudeMode>
         </LatLonAltBox>
      <Lod>
         <minLodPixels>1024</minLodPixels>
         <minFadeExtent>1024</minFadeExtent>
      </Lod>
   </Region> 
</Placemark>
   <Placemark>
   <name>BOH to MAH</name>
   <Style id="line_label">
      <LabelStyle>
        <scale>1.3</scale>
      </LabelStyle>
      <LineStyle>
         <color>ff00ffff</color>
         <width>5</width>
         <gx:labelVisibility>1</gx:labelVisibility>
      </LineStyle>
   </Style>
   <LineString>
      <tessellate>1</tessellate>
      <coordinates>
      -117.40897,34.943492,0 -121.383103,38.617112,0 
   </coordinates>
   </LineString>
  </Placemark>
</Document>
</kml>

Can you please suggest me a way to achieve my goal?


Solution

  • Apparently adding the Region to the Placemark doesn't correctly enable the labelVisibility mode in the line style when the feature becomes active. This is a bug in Google Earth. LabelVisibility works only if you don't use a Region.

    You can get around this, by adding a Point within a MultiGeometry to the placemark to active with Region. Having a point enables the label to be displayed and the label is displayed at the location of the point.

    <Placemark>
          <name>SFO to LAX</name>
          <Style>
            <IconStyle>
                <Icon/>
            </IconStyle>
            <LabelStyle>
                 <scale>1.3</scale>
            </LabelStyle>
            <LineStyle>
              <color>ff00ffff</color>
              <width>5</width>
              <gx:labelVisibility>1</gx:labelVisibility>            
            </LineStyle>
          </Style>
    
          <Region> 
           ...
          </Region> 
    
       <MultiGeometry>
         <Point>
             <coordinates>-119.884604,35.349412</coordinates>
         </Point>
         <LineString>
             <tessellate>1</tessellate>
             <coordinates>
             -118.40897,33.943492 -122.383103,37.617112
             </coordinates>
            </LineString>
        </MultiGeometry>   
    </Placemark>