Search code examples
kmlgoogle-earth

Google earth kml refresh causes placemark's description bubble to close


My KML file is:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
    <Document>
      <NetworkLink>
        <Link>
          <href>http://localhost/test.php</href>
          <refreshMode>onInterval</refreshMode>
          <refreshInterval>1</refreshInterval>
        </Link>
      </NetworkLink>
    </Document>
</kml>

Localhost/test.php returns:

<Document>
  <Placemark>
    <name>Testing</name>
    <description>
      Test
    </description>
    <Point>
      <altitudeMode>absolute</altitudeMode>
      <coordinates>0,0,0</coordinates>
    </Point>
  </Placemark>
</Document>

When you click on the icon, it opens the ballon that says "test", then after one second, when the kml is refreshed, the balloon closes, how can I fix this?


Solution

  • In order to have the balloon open, just add an <open>1</open> tag to the placemark

    <Document>
      <Placemark>
        <name>Testing</name>
        <open>1</open>
        <description>
          Test
        </description>
        <Point>
          <altitudeMode>absolute</altitudeMode>
          <coordinates>0,0,0</coordinates>
        </Point>
      </Placemark>
    </Document>
    

    However, this means the placemark will ALWAYS be open (balloon showing) when the link is refreshed.

    If you want to refresh the kml and leave the balloon open or closed depending on it's current state, then you need to look into the UPDATE command instead, and use it to update only certain parts of the currently loaded KML, rather than replacing (reloading) the whole KML.

    So it really comes down to, why are you Refreshing the KML in the first place??

    EDIT: To answer question in comments

    Use the CHANGE feature of the UPDATE

    <Update> 
        <targetHref>http://www.domain.com/file.kml</targetHref> 
        <Change> 
          <Point targetId="point123"> 
            <coordinates>-95.48,40.43,0</coordinates>
          </Point> 
        </Change> 
      </Update> 
    

    That will change the coordinates of a placemark with an id of point123 that was loaded in the kml mentioned as the targetHref (which was loaded via a NetworkLink)