appendChild($dom->createElementNS('http://earth.google.com/kml/2.1','kml'));
$node_h=$node_h->appendChild($dom->createElement('Document'));
$description="This is a data set"; // May present some meta info on the data set, eg fetched from the database may use all kind of html
$node_h->appendChild($dom->createElement('name',"Dataset"));
$node_h->appendChild($dom->createElement('description'))->appendChild($dom->createCDATASection
($description)); // description of the data set, shows up in the t.o.c. in google earth
$scale=0.25; // size of the markers.
function createstyle($node_h,$id,$color){
global $dom;
global $scale;
$style=$node_h->appendChild($dom->createElement('Style'));
$style->setAttribute("id",$id);
$style=$style->appendChild($dom->createElement('IconStyle'));
$style->appendChild($dom->createElement('scale',$scale));
$style->appendChild($dom->createElement('color',$color));
$style->appendChild($dom->createElement('Icon'))->appendChild($dom->createElement('href','http://sickel.net/images/circle.png')); // a grey circle on a white background. gray gets colored, white is turned into transparent.
}
$opacity='bb'; // will have the same opacity on all symbols
// creates a few styles:
createstyle($node_h,'gr',$opacity."44ff00");
createstyle($node_h,'ye',$opacity."44ffff");
createstyle($node_h,'rd',$opacity."4400ff");
$style=$node_h->appendChild($dom->createElement('Style'));
$style->setAttribute("id","rd");
$style=$style->appendChild($dom->createElement('IconStyle'));
$style->appendChild($dom->createElement('scale',$scale));
$style->appendChild($dom->createElement('color',"aa4400ff"));
$style->appendChild($dom->createElement('Icon'))->appendChild($dom->createElement('href','http://radioecology/images/circle.png'));
//relative
$sql="select lon,lat,value from where "; // must be set up to match whatever is needed.
$sqlh=$dbh->prepare($sql);
$sqlh->execute(); // define parameters to the query here
$error=$sqlh->errorInfo();
if($error[0]!='00000'){
//debug($error);
throw(new Exception($error[2]));}
while($row=$sqlh->fetch(PDO::FETCH_NUM)){
if ($row[0] && $row[1]){
$col=$row[2]>4000?'#ye':'#gr'; // if value < 4000, green, 4000 - 6000 yellow,
$col=$row[2]>6000?'#rd':$col; // > 6000 red. may of cource be changed to whatever is needed
$pm=$node_h->appendChild($dom->createElement('Placemark'));
$pm->appendChild($dom->createElement('description',$row[2])); // shown on click. May contain html, eg a link to further information about the point
$pm->appendChild($dom->createElement('styleUrl',$col));
$pm->appendChild($dom->createElement('Point'))->appendChild($dom->createElement('coordinates',sprintf("%f,%f,0 ",$row[0],$row[1])));
}
}
header("Content-Type: application/vnd-google-earth.kml+xml");
print($dom->saveXML());
?>