Google
Official Google Earth Download Site

Google Earth Community System Reliability: HIGH

Archive >> Places (read only)

SidneyWinstonSmythe
Tourist


Reged: 07/20/05
Posts: 61
Loc: London, UK
Re: Big Ben feed
      09/19/05 01:40 AM

Thanks, it's very nice to be appreciated. The model is not complicated, in fact if you look at the KML you'll see three things: -
  • Polygons for the grey (Westminster) tower.
  • Coloured polygons sampled from a jpeg to make a crude picture of a clock face.
  • A dynamic link to the PHP below, which generates the KML for the clock hands on request.
Even the PHP is not too onerous once you look at the part of it that actually does the work.

Thanks - Sid

Code:

<?php
//---------------------------------------------------------
/** Clock class Definition
*/
class AnalogueClock {
var $dFaceLon, $dFaceLat, $dFaceAlt;
var $dHourX, $dHourY;
var $dMinuteX, $dMinuteY;
var $dSecondX, $dSecondY;

var $dHourSize, $dMinuteSize, $dSecondSize;

var $sKml;
var $secondsFrac;
var $minutesFrac;
var $hoursFrac;

//---------------------------------------------------------
/**
*/
function AnalogueClock(){
$this->dFaceLon = 0.1;
$this->dFaceLat = 51.0;
$this->dFaceAlt = 20.0;
$this->dHourSize = 10.0;
$this->dMinuteSize = 10.0;
$this->dSecondSize = 10.0;

$this->sKml = "";
$this->sKml .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$this->sKml .= "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n";
$this->sKml .= "<Folder>\n";
$this->sKml .= "<name>Kreation</name>\n";
$this->sKml .= "<open>1</open>\n";

$timeNow = getdate();
$secondsNow = $timeNow[seconds];
$minutesNow = $timeNow[minutes];
$hoursNow = $timeNow[hours];

if( $hoursNow > 12 )
$hoursNow -= 12;

$this->dSecondsFrac = $secondsNow/60.0;
$this->dMinutesFrac = ((60*$minutesNow) + $secondsNow) / 3600;
$this->dHoursFrac = ((3600*$hoursNow) + (60*$minutesNow) + $secondsNow) / 43200;
}

//---------------------------------------------------------
/** Writes a bit of KML to close the XML
*/
function termKml(){
$this->sKml .= "</Folder>\n</kml>\n";
}

//---------------------------------------------------------
/** Creates KML for a hand - called for each of the hands
*/
function generateHandKml($sPlaceName, $sCol, $dHandSize, $dRadians){
$degreesPerMetre=8.98293242838607E-06;
$dAngle = (3.14159/2)-$dRadians;
$dHoriz = 1.5*$dHandSize * cos($dAngle);
$dVert = $dHandSize * sin($dAngle);

$dHandAlt = $dVert + $this->dFaceAlt;
$dHandLon = $this->dFaceLon + ($dHoriz * $degreesPerMetre);
$dHandLat = $this->dFaceLat;

$this->sKml .= "<Placemark>\n";
$this->sKml .= "<name>" . $sPlaceName . "</name>\n";
$this->sKml .= "<Style>\n";
$this->sKml .= "<LineStyle>\n";
$this->sKml .= "<color>" . $sCol . "</color>\n";
$this->sKml .= "<width>50</width>\n";
$this->sKml .= "</LineStyle>\n";
$this->sKml .= "</Style>\n";
$this->sKml .= "<MultiGeometry>\n<Polygon>\n<tessellate>1</tessellate>\n";
$this->sKml .= "<altitudeMode>relativeToGround</altitudeMode>\n<outerBoundaryIs>\n<LinearRing>\n<coordinates>\n";
$this->sKml .= $this->dFaceLon . "," . $this->dFaceLat . "," . $this->dFaceAlt . " \n";
$this->sKml .= $dHandLon . "," . $dHandLat . "," . $dHandAlt . " \n";
$this->sKml .= "</coordinates>\n</LinearRing>\n</outerBoundaryIs>\n</Polygon>\n</MultiGeometry>\n</Placemark>\n";

}

//---------------------------------------------------------
/** Simple conversion of a 0-1 value to radians
*/
function convertToRadians( $angle){
return 2.0*3.14159 *($angle);
}

}

//---------------------------------------------------------
/** Actual generation of KML
*/

// Set the mime-type to "google earth"
header('Content-type: application/vnd.google-earth.kml+xml');

// Create an instance of a clock
$clock = new AnalogueClock;

// Work out the rotation of each of the hands
$seconds = $clock->convertToRadians( $clock->dSecondsFrac );
$minutes = $clock->convertToRadians( $clock->dMinutesFrac );
$hours = $clock->convertToRadians( $clock->dHoursFrac );

// Generate KML for each hand
$clock->generateHandKml("Hour Hand","#ffff0000", $clock->dHourSize, $hours);
$clock->generateHandKml("Minute Hand","#ff00ff00", $clock->dMinuteSize, $minutes);
$clock->generateHandKml("Second Hand","#ff0000ff", $clock->dSecondSize, $seconds);

// Actually write the KML out and finish
echo "$clock->sKml";
$clock->sKml="";
$clock->termKml();
echo "$clock->sKml";
?>




Post Extras Print Post   Remind Me!     Report this Post


Entire topic
Subject Posted by Posted on
* Big Ben feed SidneyWinstonSmythe 07/29/05 01:16 PM
. * * Re: Big Ben feed WherethehellamI   11/15/05 12:01 PM
. * * Re: Limited Time Only - Big Ben feed Mike_in_Florida   07/30/05 06:30 AM
. * * Re: Limited Time Only - Big Ben feed Sirous_Nekooei   07/30/05 02:44 AM
. * * Re: Limited Time Only - Big Ben feed SidneyWinstonSmythe   07/31/05 02:17 PM
. * * Re: Limited Time Only - Big Ben feed dulceModerator   07/31/05 02:47 PM
. * * Big Ben feed SidneyWinstonSmythe   08/24/05 12:07 PM
. * * Re: Big Ben feed jayhasbi   09/16/05 07:28 AM
. * * Re: Big Ben feed Frank4   09/16/05 09:09 PM
. * * Re: Big Ben feed SidneyWinstonSmythe   09/19/05 01:40 AM
. * * Re: Big Ben feed echodawg   11/15/05 12:49 PM
. * * Re: Big Ben feed SidneyWinstonSmythe   11/15/05 03:22 PM
. * * Re: Big Ben feed echodawg   11/15/05 05:46 PM
. * * Re: Big Ben feed SidneyWinstonSmythe   11/16/05 12:25 AM
. * * Re: Big Ben feed Sanga   10/31/06 09:40 AM
. * * Re: Big Ben feed philverneyAdministrator   11/01/06 02:04 PM
. * * Re: Big Ben feed derekins   09/15/05 04:13 PM
. * * Re: Limited Time Only - Big Ben feed SidneyWinstonSmythe   07/30/05 02:58 AM
. * * Re: Limited Time Only - Big Ben feed SidneyWinstonSmythe   07/29/05 01:48 PM
. * * Re: Limited Time Only - Big Ben feed ExFiler   07/29/05 01:44 PM
. * * Re: Limited Time Only - Big Ben feed reeperbahn   09/20/05 12:53 AM
. * * Re: Limited Time Only - Big Ben feed SidneyWinstonSmythe   09/20/05 01:51 AM
. * * Re: Limited Time Only - Big Ben feed mdrogerson   10/28/05 08:06 AM
. * * Re: Limited Time Only - Big Ben feed SidneyWinstonSmythe   10/31/05 02:00 AM
. * * Re: Limited Time Only - Big Ben feed FrankB   11/02/05 11:56 AM


Extra information
0 registered and 6 anonymous users are browsing this forum.

Moderator:  Hill, Jumble, Kempster, jeffryv, mcshea98, esterrett, dulce, NormB, Frank_McVey, TheLedge, BeadieJay, Cyclonic, no_stranger, LuciaM, tekgergedan, toponym2006, Noisette, danescombe, Michal_Drewniak, mutex, marinerfan, Delta102, bebop, MarkAubin 



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating: ****
Thread views: 22409

Rate this thread

Jump to

earth.google.com    bbs.keyhole.com

*
UBB.threads™ 6.5.1.1