Skip to content

Instantly share code, notes, and snippets.

@monschine
Forked from mavisland/panokml.php
Created July 20, 2017 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monschine/2817f8231312361fd5c8da6a73cd9e14 to your computer and use it in GitHub Desktop.
Save monschine/2817f8231312361fd5c8da6a73cd9e14 to your computer and use it in GitHub Desktop.
pano.kml
<?php
function WriteHeader() {
header('Content-Type: application/vnd.google-earth.kml+xml');
header('Content-Disposition: attachment;filename="pano.kml"');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n";
echo "<Folder>\n";
echo "\t<name>pano</name>\n";
echo "\t<open>1</open>\n";
}
function WriteFooter() {
echo "</Folder>\n";
echo "</kml>";
}
function WritePoint($i, $rayon, $angle) {
// $lat = $_POST['lat'];
// $lon = $_POST['lon'];
$latdeg = $_POST['latdeg'];
$latmin = $_POST['latmin'];
$latsec = $_POST['latsec'];
$londeg = $_POST['londeg'];
$lonmin = $_POST['lonmin'];
$lonsec = $_POST['lonsec'];
$lat = $latdeg + $latmin/60.0 + $latsec/3600.0;
$lon = $londeg + $lonmin/60.0 + $lonsec/3600.0;
$alt = $_POST['alt'];
$dlat = ($rayon * cos($angle)) * (90.0 / 10000.0);
$dlon = ($rayon * sin($angle)) * (90.0 / (10000.0 * cos(deg2rad($lat))));
$newlat = $lat + $dlat;
$newlon = $lon + $dlon;
$range = sqrt( $rayon * $rayon *1000.0*1000.0 + $alt * $alt );
$tilt = rad2deg( atan($rayon * 1000.0 / $alt) );
$heading = rad2deg( $angle );
echo "\t<Placemark>\n";
echo "\t\t<name>".$i."</name>\n";
echo "\t\t<LookAt>\n";
echo "\t\t\t<longitude>".$newlon."</longitude>\n";
echo "\t\t\t<latitude>".$newlat."</latitude>\n";
echo "\t\t\t<altitude>0</altitude>\n";
echo "\t\t\t<range>".$range."</range>\n";
echo "\t\t\t<tilt>".$tilt."</tilt>\n";
echo "\t\t\t<heading>".$heading."</heading>\n";
echo "\t\t\t<altitudeMode>absolute</altitudeMode>\n";
echo "\t\t</LookAt>\n";
echo "\t</Placemark>\n";
}
function WriteCircle($rayon, $n) {
echo "<Folder>\n";
echo "\t<name>circle ".$rayon."</name>\n";
echo "\t<open>1</open>\n";
for ($i = 0;$i < $n;$i++) {
$angle = $i * (2.0*pi())/$n;
WritePoint($i + 1, $rayon, $angle);
}
echo "</Folder>\n";
}
//if (isset($_POST['lat'])) {
if (isset($_POST['latdeg'])) {
// $lat = $_POST['lat'];
// $lon = $_POST['lon'];
$latdeg = $_POST['latdeg'];
$latmin = $_POST['latmin'];
$latsec = $_POST['latsec'];
$londeg = $_POST['londeg'];
$lonmin = $_POST['lonmin'];
$lonsec = $_POST['lonsec'];
$lat = $latdeg + $latmin/60.0 + $latsec/3600.0;
$lon = $londeg + $lonmin/60.0 + $lonsec/3600.0;
$alt = $_POST['alt'];
$f = $alt / 4000.0;
$circles[0][0] = 0;
$circles[0][1] = 1;
$circles[1][0] = $f * 2.5;
$circles[1][1] = 6;
$circles[2][0] = $f * 5.0;
$circles[2][1] = 10;
$circles[3][0] = $f * 10.0;
$circles[3][1] = 12;
$circles[4][0] = $f * 50.0;
$circles[4][1] = 12;
WriteHeader();
for ($i=0;$i < 5 ;$i++) {
WriteCircle($circles[$i][0], $circles[$i][1]);
}
WriteFooter();
$latdeg = 0;
$latmin = 0;
$latsec = 0;
$londeg = 0;
$lonmin = 0;
$lonsec = 0;
$alt = 0;
} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="content-type">
<title></title>
</head>
<body>
<form method="post" action="panokml.php" name="formkml">
Lat :&nbsp;<input size="3" name="latdeg" value="37">&nbsp;<input size="2" name="latmin" value="33">&nbsp;<input size="5" name="latsec" value="04.82">N<br>
Lon :&nbsp;<input size="3" name="londeg" value="126">&nbsp;<input size="2" name="lonmin" value="59">&nbsp;<input size="5" name="lonsec" value="16.50">E<br>
Alt :&nbsp;<input size="10" name="alt" value="500"> m<br>
<input type="submit"><br>
</form>
<a href="panokml.phps">Source code</a>
</body>
</html>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment