Question

I have just started to learn how to manipulate the KML files. here is a problem that I do not know how to overcome.... I created a polygon and added a description to be shown as a balloon, but it appears as soon as Google Earth starts working before the polygon can be seen. what I want is to show the balloon from a specific distance where the polygon appears(for example in the range distance of LookAt element). anybody knows how to manage that? my code follows:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" mlns: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">
    <LookAt>
    <longitude>17.99514610290434</longitude>
    <latitude>59.36293893395309</latitude>
    <altitude>0</altitude>
    <range>597.51212259908</range>
    <tilt>52.34415598649959</tilt>
    <heading>105.3974737169693</heading>

</LookAt>
<Placemark>
    <name>Stadium</name>

    <description>
        <![CDATA[
        this is <b><i>Råsunda soccer stadium</i></b>
        ]]>
    </description>
        <gx:balloonVisibility>1</gx:balloonVisibility>


        <styleUrl>#msn_ylw-pushpin</styleUrl>
    <Polygon>
        <extrude>1</extrude>
        <tessellate>1</tessellate>
        <altitudeMode>absolute</altitudeMode>
        <outerBoundaryIs>
            <LinearRing>
                <coordinates>
                    17.99514610290434,59.36293893395309,100 17.99651951950199,59.36209399425741,100 17.99752330705672,59.36252751885282,100 17.99613146514916,59.36335387902954,100 17.99514610290434,59.36293893395309,100 
                </coordinates>
            </LinearRing>
        </outerBoundaryIs>
    </Polygon>
</Placemark>
</Document>
</kml>
Was it helpful?

Solution

Normally you can skip rendering the polygon until you get "close" enough to it as defined by a Region element which is determined by calculating when a given area maps to a min or max # of pixels.

Also, the <gx:balloonVisibility> tag forces the description balloon to appear when the KML is loaded regardless of whether Region is active. Adding a Region direct in the KML still shows the popup balloon.

To do what you want to do, you must wrap the KML file with a second KML file with a NetworkLink with a Region that loads the seconds KML only when the region is active (aka close enough) at which time the description is displayed along with the polygon.

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>

  <LookAt>
        <longitude>17.99514610290434</longitude>
        <latitude>59.36293893395309</latitude>
        <altitude>0</altitude>
        <heading>105.3974737169693</heading>
        <tilt>52.34415598649959</tilt>
        <range>597.51212259908</range>
    </LookAt>

  <NetworkLink>
    <Region>
        <LatLonAltBox>
          <north>59.363792</north>
          <south>59.361556</south>
          <east>17.998029</east>
          <west>17.994443</west>
        </LatLonAltBox>
        <Lod>
          <minLodPixels>128</minLodPixels>
          <maxLodPixels>-1</maxLodPixels>
        </Lod>
      </Region>

      <Link>
        <href>target.kml</href>
      </Link>     
  </NetworkLink>

 </Document>

</kml>

And target.kml file contains the original KML you gave:

<?xml version="1.0" encoding="ISO-8859-1"?>
<kml xmlns="http://www.opengis.net/kml/2.2">    
 <Placemark>
    <name>Stadium</name>
    ...
 </Placemark>    
</kml>

You can change the distance the feature + balloon appears by adjusting the minLodPixels value and/or the size of the region. At present the feature will display when the region defined by area surrounding the polygon is at least 128 pixels on the screen. Change to 32 or 64 and/or make the region area larger to make it appear quicker.

Note Google Earth client doesn't give you a tool to edit or even see the Region bounding boxes on the map so debugging this is tricky. You can paste your KML into this tool to generate KML making the Region bounding area visible. This helps to debug Regions more easily.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top