This commit is contained in:
bastianonm 2011-12-15 19:00:25 +00:00
parent d233e13e83
commit 07afbd92bb
4 changed files with 291 additions and 99 deletions

View File

@ -14,9 +14,11 @@ var loc = loc_en;
function wpgpxmaps(targhetId,mapType,mapData,graphData) function wpgpxmaps(targhetId,mapType,mapData,graphData)
{ {
var el = document.getElementById(targhetId);
var el_map = el.childNodes[0]; var el = document.getElementById("wpgpxmaps_" + targhetId);
var el_chart = el.childNodes[1]; var el_map = document.getElementById("map_" + targhetId);
var el_chart = document.getElementById("chart_" + targhetId);
switch (mapType) switch (mapType)
{ {
case 'TERRAIN': { mapType = google.maps.MapTypeId.TERRAIN; break;} case 'TERRAIN': { mapType = google.maps.MapTypeId.TERRAIN; break;}

View File

@ -59,7 +59,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
jQuery(document).ready(function () { jQuery(document).ready(function () {
var m_'.$r.' = ['.$points_maps.']; var m_'.$r.' = ['.$points_maps.'];
var c_'.$r.' = ['.$points_graph.']; var c_'.$r.' = ['.$points_graph.'];
wpgpxmaps("wpgpxmaps_'.$r.'",\''.$t.'\',m_'.$r.',c_'.$r.'); wpgpxmaps("'.$r.'",\''.$t.'\',m_'.$r.',c_'.$r.');
}); });
</script>'; </script>';

View File

@ -1,96 +1,96 @@
<?php <?php
function getPoints($gpxPath,$gpxOffset = 10) function getPoints($gpxPath,$gpxOffset = 10)
{ {
$points = array(); $points = array();
$dist=0; $dist=0;
$lastLat=0; $lastLat=0;
$lastLon=0; $lastLon=0;
$lastEle=0; $lastEle=0;
$lastOffset=0; $lastOffset=0;
//Default Offset = 10 mt //Default Offset = 10 mt
if (!($gpxOffset > 0)) if (!($gpxOffset > 0))
{ {
$gpxOffset = 10; $gpxOffset = 10;
} }
$realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/')).$gpxPath; $realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/')).$gpxPath;
if (file_exists($realGpxPath)) if (file_exists($realGpxPath))
{ {
$gpx = simplexml_load_file($realGpxPath); $gpx = simplexml_load_file($realGpxPath);
$gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0'); $gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0');
$gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); $gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1');
foreach($gpx->xpath('//trkpt | //10:trkpt | //11:trkpt') as $trkpt){ foreach($gpx->xpath('//trkpt | //10:trkpt | //11:trkpt') as $trkpt){
$lat = $trkpt['lat']; $lat = $trkpt['lat'];
$lon = $trkpt['lon']; $lon = $trkpt['lon'];
$ele = $trkpt->ele; $ele = $trkpt->ele;
if ($lastLat == 0 && $lastLon == 0) if ($lastLat == 0 && $lastLon == 0)
{ {
//Base Case //Base Case
array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1)));
$lastLat=$lat; $lastLat=$lat;
$lastLon=$lon; $lastLon=$lon;
$lastEle=$ele; $lastEle=$ele;
} }
else else
{ {
//Normal Case //Normal Case
$offset = calculateDistance($lat, $lon, $ele,$lastLat, $lastLon, $lastEle); $offset = calculateDistance($lat, $lon, $ele,$lastLat, $lastLon, $lastEle);
$dist = $dist + $offset; $dist = $dist + $offset;
if (((float) $offset + (float) $lastOffset) > $gpxOffset) if (((float) $offset + (float) $lastOffset) > $gpxOffset)
{ {
//Bigger Offset -> write coordinate //Bigger Offset -> write coordinate
$lastOffset=0; $lastOffset=0;
array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1)));
} }
else else
{ {
//Smoller Offset -> continue.. //Smoller Offset -> continue..
$lastOffset= (float) $lastOffset + (float) $offset ; $lastOffset= (float) $lastOffset + (float) $offset ;
} }
} }
$lastLat=$lat; $lastLat=$lat;
$lastLon=$lon; $lastLon=$lon;
$lastEle=$ele; $lastEle=$ele;
} }
} }
else else
{ {
array_push($points, array((float)0,(float)0,(float)0,(float)0)); array_push($points, array((float)0,(float)0,(float)0,(float)0));
} }
// riduco l'array a circa 200 punti per non appensantire la pagina(mappa e grafico)! // riduco l'array a circa 200 punti per non appensantire la pagina(mappa e grafico)!
$count=sizeof($points); $count=sizeof($points);
if ($count>200) if ($count>200)
{ {
$f = round($count/200); $f = round($count/200);
if ($f>1) if ($f>1)
for($i=$count;$i>0;$i--) for($i=$count;$i>0;$i--)
if ($i % $f != 0) if ($i % $f != 0)
unset($points[$i]); unset($points[$i]);
} }
return $points; return $points;
} }
function toRadians($degrees) function toRadians($degrees)
{ {
return $degrees * 3.1415926535897932385 / 180; return $degrees * 3.1415926535897932385 / 180;
} }
function calculateDistance($lat1,$lon1,$ele1,$lat2,$lon2,$ele2) function calculateDistance($lat1,$lon1,$ele1,$lat2,$lon2,$ele2)
{ {
//Distance in meters //Distance in meters
$dLat = toRadians((float) $lat2 - (float) $lat1); $dLat = toRadians((float) $lat2 - (float) $lat1);
$dLng = toRadians((float) $lon2 - (float) $lon1); $dLng = toRadians((float) $lon2 - (float) $lon1);
$a = (float) ( sin($dLat / 2) * sin($dLat / 2)) + (float) ( cos( toRadians($lat1)) * cos( toRadians($lat2)) * sin($dLng / 2) * sin($dLng / 2) ); $a = (float) ( sin($dLat / 2) * sin($dLat / 2)) + (float) ( cos( toRadians($lat1)) * cos( toRadians($lat2)) * sin($dLng / 2) * sin($dLng / 2) );
$dist = 2 * 3958.75 * atan2(sqrt($a), sqrt(1 - (float) $a)); $dist = 2 * 3958.75 * atan2(sqrt($a), sqrt(1 - (float) $a));
return sqrt(pow($dist * 1609.00, 2) + pow((float) $lat1 - (float)$lat2, 2)); return sqrt(pow($dist * 1609.00, 2) + pow((float) $lat1 - (float)$lat2, 2));
} }
?> ?>

190
wp-gpx-maps_admin.php Normal file
View File

@ -0,0 +1,190 @@
<?php
function WP_GPX_Maps_html_page() {
$realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/'))."/wp-content/uploads/gpx";
$gpxRegEx = '/.gpx$/';
?>
<div>
<h2>WP GPX Settings</h2>
<?php
if(file_exists($realGpxPath) && is_dir($realGpxPath))
{
//dir exsist!
}
else
{
if (!@mkdir($dir)) {
echo '<div class="error" style="padding:10px">
Can\'t create <b>'.$realGpxPath.'</b> folder. Please create it and make it writable!<br />
If not, you will must update the file manually!
</div>';
}
}
?>
<div style="padding:10px 10px 30px 10px;">
<b>The fastest way to use this plugin:</b> upload the file using the uploader below, than put this
shotcode: <b>[sgpx gpx="/wp-content/uploads/gpx/&lt gpx file name &gt"]</b> in the pages/posts.
</div>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options') ?>
<table width="100%">
<tr valign="top">
<th width="200" scope="row">Maps Width:</th>
<td>
<input name="wpgpxmaps_width" type="text" id="wpgpxmaps_width" value="<?php echo get_option('wpgpxmaps_width'); ?>" style="width:50px;" />
</td>
</tr>
<tr valign="top">
<th width="200" scope="row">Maps Height:</th>
<td>
<input name="wpgpxmaps_height" type="text" id="wpgpxmaps_height" value="<?php echo get_option('wpgpxmaps_height'); ?>" style="width:50px;" />
</td>
</tr>
<tr>
<th width="200" scope="row">Default Map Type:</th>
<td>
<?php
$t = get_option('wpgpxmaps_map_type');
if (!($t))
$t = 'HYBRID';
?>
<input type="radio" name="wpgpxmaps_map_type" value="HYBRID" <?php if ($t == 'HYBRID') echo 'checked'; ?> > This map type displays a transparent layer of major streets on satellite images.<br />
<input type="radio" name="wpgpxmaps_map_type" value="ROADMAP" <?php if ($t == 'ROADMAP') echo 'checked'; ?>> This map type displays a normal street map.<br />
<input type="radio" name="wpgpxmaps_map_type" value="SATELLITE" <?php if ($t == 'SATELLITE') echo 'checked'; ?>> This map type displays satellite images.<br />
<input type="radio" name="wpgpxmaps_map_type" value="TERRAIN" <?php if ($t == 'TERRAIN') echo 'checked'; ?>> This map type displays maps with physical features such as terrain and vegetation.<br />
</td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input name="page_options" type="hidden" value="wpgpxmaps_map_type,wpgpxmaps_height,wpgpxmaps_width" />
<p>
<input type="submit" value="<?php _e('Save Changes') ?>" />
</p>
</form>
<?php
if ( isset($_POST['delete']) )
{
$del = $_POST['delete'];
if (preg_match($gpxRegEx, $del ) && file_exists($realGpxPath ."/". $del))
{
unlink($realGpxPath ."/". $del);
}
}
if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) { ?>
<div class="tablenav top">
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" onchange="this.parentNode.submit()" />
<?php
if ( isset($_FILES['uploadedfile']) )
{
$target_path = $realGpxPath ."/". basename( $_FILES['uploadedfile']['name']);
if (preg_match($gpxRegEx,$target_path ))
{
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
else
{
echo "file not supported!";
}
}
?>
</form>
</div>
<table cellspacing="0" class="wp-list-table widefat plugins">
<thead>
<tr>
<th style="" class="manage-column" id="name" scope="col">File</th>
<th style="" class="manage-column" id="name" scope="col">Last modified</th>
<th style="" class="manage-column" id="name" scope="col">File size (Byte)</th>
</tr>
</thead>
<tfoot>
<tr>
<th style="" class="manage-column" id="name" scope="col">File</th>
<th style="" class="manage-column" id="name" scope="col">Last modified</th>
<th style="" class="manage-column" id="name" scope="col">File size (Byte)</th>
</tr>
</tfoot>
<tbody id="the-list">
<?php
while (false !== ($entry = readdir($handle))) {
if (preg_match($gpxRegEx,$entry ))
{
$file = $realGpxPath . "/" . $entry;
?>
<tr class="active" id="akismet">
<td class="plugin-title">
<strong><?php echo $entry; ?></strong>
<div class="row-actions-visible">
<a href="#" onclick="delgpx('<?php echo $entry ?>'); return false;">Delete</a>
|
<a href="../wp-content/uploads/gpx/<?php echo $entry?>">Download</a>
</div>
</td>
<td class="column-description desc">
<div class="plugin-description">
<p><?php echo date ("F d Y H:i:s.", filemtime( $file ) ) ?></p>
</div>
</td>
<td class="column-description desc">
<div class="plugin-description">
<p><?php echo number_format ( filesize( $file ) , 0, '.', ',' ) ?></p>
</div>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
closedir($handle);
} ?>
</div>
<script type="text/javascript">
function delgpx(file)
{
if (confirm('Delte this file: ' + file + '?'))
{
document.formdelgpx.delete.value = file;
document.formdelgpx.submit();
}
}
</script>
<form method="post" name="formdelgpx" style="display:none;">
<input type="hidden" name="delete" />
</form>
<?php
}
?>