Search code examples
google-earth

Interactive google earth building


I'm wondering is it possible to create building on google earth; that exchanges information with my web server. So I can change it's let's say wall colour from web server, or serves sends every minute new values. Thanks


Solution

  • Yes, you can create a 3d object and load it into google earth and then adjust its properties. One way to do this would be to use a NetWorkLink file that loads the model data you require. You can set a NetWorkLink to refresh based on various criteria and you can specify a CGI script in the herf attribute. A pesudo example would work like this.

    1) a network link defined in kml

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
        <NetworkLink>
          <refreshVisibility>0</refreshVisibility>
          <flyToView>1</flyToView>
          <Link>
            <refreshInterval>2</refreshInterval>
            <viewRefreshMode>onStop</viewRefreshMode>
            <viewRefreshTime>1</viewRefreshTime>
            <href>http://yourserver.com/cgi-bin/loadbuilding.php</href>
          </Link>
        </NetworkLink>
    </kml>
    

    2) the cgi script specified in the herf

      <?php
       // some logic to select a particular kmz file etc
       $fullPath = "path to your file";
    
       if ($fd = fopen ($fullPath, "r")) {
         header("Content-type: application/octet-stream");
         header("Content-Disposition: filename=building.kmz");
         header("Content-Type: application/vnd.google-earth.kml+xml\n");
         while(!feof($fd)) {
           $buffer = fread($fd, 2048);
           echo $buffer;
         }
         fclose ($fd);
         exit;
        }
      ?>