Skip to content

Commit

Permalink
fix for #657: Now route can be show at Gmap
Browse files Browse the repository at this point in the history
  • Loading branch information
kojoty committed Jul 24, 2016
1 parent 7aebd86 commit 88e4858
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
6 changes: 6 additions & 0 deletions lib/class.polylineEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function __construct($numLevels = 18, $zoomFactor = 2, $verySmall = 0.000
*/
public function encode($points)
{
$dists = [];
$absMaxDist=0;
if (count($points) > 2) {
$stack[] = array(0, count($points) - 1);
while (count($stack) > 0) {
Expand Down Expand Up @@ -126,6 +128,8 @@ private function encodeSignedNumber($num)

private function createEncodings($points, $dists)
{
$plat=0; $plng=0;
$encoded_points="";
for ($i = 0; $i < count($points); $i++) {
if (isset($dists[$i]) || $i == 0 || $i == count($points) - 1) {
$point = $points[$i];
Expand All @@ -145,6 +149,7 @@ private function createEncodings($points, $dists)

private function encodeLevels($points, $dists, $absMaxDist)
{
$encoded_levels = "";
if ($this->forceEndpoints) {
$encoded_levels .= $this->encodeNumber($this->numLevels - 1);
} else {
Expand All @@ -165,6 +170,7 @@ private function encodeLevels($points, $dists, $absMaxDist)

private function encodeNumber($num)
{
$encodeString = "";
while ($num >= 0x20) {
$nextValue = (0x20 | ($num & 0x1f)) + 63;
$encodeString .= chr($nextValue);
Expand Down
2 changes: 1 addition & 1 deletion myroutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

if ( $routes_record = XDb::xFetchArray($route_rs) ) {

$routes .= '<div class="headitems">';
$routes = '<div class="headitems">';
$routes .= '<div style="width:80px;" class="myr">' . tr('route_name') . '</div><div class="ver">&nbsp;</div><div style="width:295px;" class="myr">&nbsp;' . tr('route_desc') . '</div><div class="ver">&nbsp;</div><div style="width:60px;" class="myr">&nbsp;' . tr('radius') . '</div><div class="ver">&nbsp;</div><div style="width:60px;" class="myr">&nbsp;' . tr('length') . '</div><div class="ver">&nbsp;</div><div style="width:70px;" class="myr">&nbsp;' . tr('caches') . '</div><div class="ver">&nbsp;</div><div style="width:50px;" class="myr">' . tr('edit') . '</div><div class="ver">&nbsp;</div><div style="width:20px;" class="myr">&nbsp;' . tr('delete') . '</div></div>';

do{
Expand Down
20 changes: 11 additions & 9 deletions myroutes_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

// Read file KML with route, load in the KML file through the my_routes page, and run that KML file through GPSBABEL which has a tool interpolate data points in the route.
if (!$error) {
exec("/usr/local/bin/gpsbabel -i kml -f " . $upload_filename . " -x interpolate,distance=0.25k -o kml -F " . $upload_filename . "");
exec("/usr/bin/gpsbabel -i kml -f " . $upload_filename . " -x interpolate,distance=0.25k -o kml -F " . $upload_filename . "");
$xml = simplexml_load_file($upload_filename);

// get length route
Expand Down Expand Up @@ -84,7 +84,8 @@
// end of read
//we get the point data in to an array called $points:

if (!$error) {
if (!$error && isset($coords)) {

for ($i = 0; $i < count($coords) - 1; $i = $i + 2) {
$points[] = array("lon" => $coords[$i], "lat" => $coords[$i + 1]);
if (($coords[$i] + 0 == 0) OR ( $coords[$i + 1] + 0 == 0)) {
Expand All @@ -95,14 +96,15 @@
}
// add it to the route_points database:
$point_num = 0;
foreach ($points as $point) {
$point_num++;
$result = XDb::xSql(
"INSERT into route_points (route_id,point_nr,lat,lon)
VALUES (?,?,?,?)",
$route_id, $point_num, $point["lat"], $point["lon"]);
if(isset($points)){
foreach ($points as $point) {
$point_num++;
$result = XDb::xSql(
"INSERT into route_points (route_id,point_nr,lat,lon)
VALUES (?,?,?,?)",
$route_id, $point_num, $point["lat"], $point["lon"]);
}
}

tpl_redirect('myroutes.php');
exit;
} //end submit
Expand Down
2 changes: 1 addition & 1 deletion myroutes_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
$upload_filename = $_FILES['file']['tmp_name'];
// Read file KML with route
if (!$error) {
exec("/usr/local/bin/gpsbabel -i kml -f " . $upload_filename . " -x interpolate,distance=0.25k -o kml -F " . $upload_filename . "");
exec("/usr/bin/gpsbabel -i kml -f " . $upload_filename . " -x interpolate,distance=0.25k -o kml -F " . $upload_filename . "");
$xml = simplexml_load_file($upload_filename);

// get length route
Expand Down
2 changes: 1 addition & 1 deletion myroutes_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ function set_route_options($route_id, $options)
if (isset($_POST['submit_map'])) {
$y = $r['longitude'];
$x = $r['latitude'];
$point.=sprintf("addMarker(%s,%s,'%s',%s,'%s','%s','%s',%s);\n", $x, $y, getSmallCacheIcon($r['icon_large']), $r[cacheid], addslashes($r[cachename]), $r[wp_oc], addslashes($r[username]), $r[topratings]);
$point.=sprintf("addMarker(%s,%s,'%s',%s,'%s','%s','%s',%s);\n", $x, $y, getSmallCacheIcon($r['icon_large']), $r['cacheid'], addslashes($r['cachename']), $r['wp_oc'], addslashes($r['username']), $r['topratings']);
tpl_set_var('points', $point);
} else {

Expand Down
2 changes: 2 additions & 0 deletions tpl/stdstyle/myroutes_result_map.tpl.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use Utils\Database\XDb;

global $rootpath;
require_once('./lib/common.inc.php');
require_once('./lib/class.polylineEncoder.php');
Expand Down

0 comments on commit 88e4858

Please sign in to comment.