function display($tpl = null)
    {
        $app = JFactory::getApplication();
        $params = $app->getParams();
        $dispatcher = JDispatcher::getInstance();
        $model = $this->getModel('walkdetails');
        $controller = JControllerLegacy::getInstance('SWG_WalkLibrary');
        // Get some data from the models
        $state = $this->get('State');
        $this->walk = $this->get('Walk');
        $this->walkInstances = $this->walk->getInstances();
        // Get some permissions info
        $this->canAdd = $controller->canAdd();
        $this->canEdit = $controller->canEdit($this->walk);
        // Check for errors.
        if (count($errors = $this->get('Errors'))) {
            JError::raiseError(500, implode('<br />', $errors));
            return false;
        }
        // Load the map JS
        $document = JFactory::getDocument();
        JHtml::_('behavior.framework', true);
        $document->addScript('/libraries/openlayers/OpenLayers.js');
        $document->addScript('/swg/js/maps.js');
        $start = new Waypoint();
        $start->osRef = getOSRefFromSixFigureReference($this->walk->startGridRef);
        $end = new Waypoint();
        $end->osRef = getOSRefFromSixFigureReference($this->walk->endGridRef);
        // Create the map
        $document->addScriptDeclaration(<<<MAP
window.addEvent("domready", function() {
\tvar map = new SWGMap('map');
\tvar walk = map.addWalk({$this->walk->id});
\tmap.addLoadedHandler(function()
\t{
\t\tvar route = new Route();
\t\troute.load("walk", walk.id, 10, walk);
\t\t//walk.loadRoute(map); // TODO: Should only load the most specific Route. Implement in other mapping pages. Detach route loading logic from walk object.
\t});
});
MAP
);
        // Display the view
        parent::display($tpl);
    }
    </p>
    
    <h2>Convert Six-Figure OS Grid Reference String to an OSRef Object</h2>
    
    <p>
      To convert a string representing a six-figure OSGB grid reference:

      <pre>$os6 = "TG514131";
echo "Six figure string: " . $os6 . "&lt;br /&gt;";
$os6x = getOSRefFromSixFigureReference($os6);
echo "Converted to OS Grid Ref: " . $os6x->toString() . " - " . $os6x->toSixFigureString();</pre>    
      
      <?php 
$os6 = "TG514131";
echo "Six figure string: " . $os6 . "<br />";
$os6x = getOSRefFromSixFigureReference($os6);
echo "Converted to OS Grid Ref: " . $os6x->toString() . " - " . $os6x->toSixFigureString();
?>
    </p>

    <h2>Convert UTM Reference to Latitude/Longitude</h2>

    <p>
      <pre>$utm1 = new UTMRef(456463.99, 3335334.05, "E", 12);
echo "UTM Reference: " . $utm1->toString() . "&lt;br /&gt;";
$ll3 = $utm1->toLatLng();
echo "Converted to Lat/Long: " . $ll3->toString();</pre>

      <?php 
$utm1 = new UTMRef(456463.99, 3335334.05, "E", 12);
echo "UTM Reference: " . $utm1->toString() . "<br />";
    function display($tpl = null)
    {
        $app = JFactory::getApplication();
        $params = $app->getParams();
        $dispatcher = JDispatcher::getInstance();
        $model = $this->getModel('uploadtrack');
        // Get some data from the models
        $state = $this->get('State');
        $this->wi = $this->get('WalkInstance');
        $this->form = $this->get('Form');
        // Has the user uploaded a track to preview?
        $this->track = $this->get('CachedTrack');
        $this->gotTrack = !empty($this->track);
        $document = JFactory::getDocument();
        JHtml::_('behavior.framework', true);
        $document->addScript('swg/js/common.js');
        // Prepare any error messages
        // TODO: Find how Joomla handles error messages (and make them look nicer) - maybe just throw exceptions out and have an exception handler that displays a popup
        $errors = $this->getErrors();
        $errJS = "";
        if (!empty($errors)) {
            $errJS = "Popup('Could not upload track', " . implode("<br />", $errors) . ");";
            $document->addScriptDeclaration(<<<ERR
window.addEvent("domready", function() {
\t{$errJS}
});
ERR
);
        }
        // Do we know what walk we're working on?
        if (isset($this->wi)) {
            if ($this->gotTrack) {
                $this->track->setWalk($this->wi);
                $this->wi->setTrack($this->track);
            }
            // Load the map JS
            $document->addScript('libraries/openlayers/OpenLayers.js');
            $document->addScript('swg/js/maps.js');
            $start = new Waypoint();
            $start->osRef = getOSRefFromSixFigureReference($this->wi->startGridRef);
            $end = new Waypoint();
            $end->osRef = getOSRefFromSixFigureReference($this->wi->endGridRef);
            // Create the map
            if ($this->gotTrack) {
                $trackJSON = $this->track->jsonEncode();
                $trackJS = "var route = new Route(wi);\nroute.read(" . $this->track->jsonEncode() . ");\nmap.loadedRoute(route,wi);\n";
            } else {
                $trackJS = "";
            }
            $document->addScriptDeclaration(<<<MAP
window.addEvent("domready", function() {
    var map = new SWGMap('map');
\tvar wi = map.addWalkInstance({$this->wi->id});
\tmap.addLoadedHandler(function(){
\t\t{$trackJS}
\t\tmap.zoomToFit();
\t});
});
MAP
);
        }
        // Display the view
        parent::display($tpl);
    }
 public function __set($name, $value)
 {
     switch ($name) {
         // Strings - just save them (TODO: Safety checks?)
         case "startPlaceName":
         case "endPlaceName":
             $this->{$name} = $value;
             break;
             // Integer
         // Integer
         case "headCount":
         case "distance":
             $this->{$name} = (int) $value;
             break;
             // Booleans
         // Booleans
         case "isLinear":
         case "dogFriendly":
         case "childFriendly":
         case "speedy":
         case "challenge":
             $this->{$name} = (bool) $value;
             break;
             // More specific processing
         // More specific processing
         case "distanceGrade":
             $value = strtoupper($value);
             if (empty($value)) {
                 $this->{$name} = null;
             } else {
                 if ($value == "A" || $value == "B" || $value == "C") {
                     $this->{$name} = $value;
                 } else {
                     throw new UnexpectedValueException("Distance grade must be A, B or C");
                 }
             }
             break;
         case "difficultyGrade":
             $value = (int) $value;
             if (empty($value)) {
                 $this->{$name} = null;
             } else {
                 if ($value == 1 || $value == 2 || $value == 3) {
                     $this->{$name} = $value;
                 } else {
                     throw new UnexpectedValueException("Difficulty grade must be 1, 2 or 3");
                 }
             }
             break;
         case "miles":
             $value = (double) $value;
             if ($value >= 0) {
                 $this->{$name} = $value;
                 $this->distanceGrade = $this->getDistanceGrade($value);
             } else {
                 throw new UnexpectedValueException("Distance must be positive");
             }
             // TODO: Validate >0 when saving
             break;
             // Grid references - start with two letters, then an even number of digits - at least 6
         // Grid references - start with two letters, then an even number of digits - at least 6
         case "startGridRef":
         case "endGridRef":
             $value = strtoupper(str_replace(" ", "", $value));
             if (empty($value)) {
                 $this->{$name} = null;
                 if ($name == "startGridRef") {
                     $this->startLatLng = null;
                 } else {
                     $this->endLatLng = null;
                 }
             } else {
                 if (preg_match("/[A-Z][A-Z]([0-9][0-9]){3,}/", $value)) {
                     $this->{$name} = $value;
                     // Also set the lat/lng
                     $osRef = getOSRefFromSixFigureReference($value);
                     $latLng = $osRef->toLatLng();
                     $latLng->OSGB36ToWGS84();
                     if ($name == "startGridRef") {
                         $this->startLatLng = $latLng;
                     } else {
                         $this->endLatLng = $latLng;
                     }
                 } else {
                     throw new UnexpectedValueException("Grid references must be at least 6-figures, with the grid square letters before (e.g. SK123456)");
                 }
             }
             break;
             // Connected objects
         // Connected objects
         case "leader":
         case "leaderId":
             if (empty($value)) {
                 $this->leader = null;
                 $this->leaderId = null;
             } else {
                 if ($value instanceof Leader) {
                     $this->leader = $value;
                     $this->leaderId = $value->id;
                 } else {
                     if (is_int($value) || ctype_digit($value)) {
                         $this->leaderId = (int) $value;
                         $this->leader = null;
                         // Will be loaded when needed
                     } else {
                         throw new UnexpectedValueException("Leader or Leader ID must be a Leader or an integer");
                     }
                 }
             }
             break;
         case "backmarker":
         case "backmarkerId":
             if (empty($value)) {
                 $this->backmarker = null;
                 $this->backmarkerId = null;
             }
             if ($value instanceof Leader) {
                 $this->backmarker = $value;
                 $this->backmarkerId = $value->id;
             } else {
                 if (is_int($value) || ctype_digit($value)) {
                     $this->backmarkerId = (int) $value;
                     $this->backmarker = null;
                     // Will be loaded when needed
                 } else {
                     throw new UnexpectedValueException("Backmarker or backmarker ID must be a Leader or an integer");
                 }
             }
             break;
         case "meetPoint":
         case "meetPointId":
             if (empty($value)) {
                 $this->meetPoint = null;
                 $this->meetPointId = null;
             } elseif ($value instanceof WalkMeetingPoint) {
                 $this->meetPoint = $value;
                 $this->meetPointId = $value->id;
             } else {
                 if (is_int($value) || ctype_digit($value)) {
                     $this->meetPointId = (int) $value;
                     $this->meetPoint = null;
                 } else {
                     throw new UnexpectedValueException("Meetpoint or MeetPointID must be a WalkMeetingPoint or an integer");
                 }
             }
             if (isset($this->meetPoint) && !empty($this->meetPlaceTime)) {
                 $this->meetPoint->setExtra($this->meetPlaceTime);
             }
             break;
         case "walkid":
             $this->walkid = (int) $value;
             break;
         case "meetPlaceTime":
             $this->meetPlaceTime = $value;
             if (isset($this->meetPoint)) {
                 $this->meetPoint->setExtra($value);
             }
             break;
             // Checks TODO
         // Checks TODO
         case "location":
         case "suggestedBy":
         case "status":
         case "specialTBC":
             $this->{$name} = $value;
             break;
         case "routeVisibility":
             $this->{$name} = (int) $value;
             break;
         default:
             // All others - fall through to Event
             parent::__set($name, $value);
     }
 }
 public function __set($name, $value)
 {
     switch ($name) {
         // Strings - just save them (TODO: Safety checks?)
         case "name":
         case "startPlaceName":
         case "endPlaceName":
         case "description":
         case "information":
             $this->{$name} = $value;
             break;
             // Booleans
         // Booleans
         case "isLinear":
         case "dogFriendly":
         case "transportByCar":
         case "transportPublic":
         case "childFriendly":
             $this->{$name} = (bool) $value;
             break;
             // More specific processing
         // More specific processing
         case "distanceGrade":
             $value = strtoupper($value);
             if ($value == "A" || $value == "B" || $value == "C") {
                 $this->{$name} = $value;
             } else {
                 if (!empty($value)) {
                     throw new UnexpectedValueException("Distance grade must be A, B or C");
                 }
             }
             break;
         case "difficultyGrade":
             $value = (int) $value;
             if ($value == 1 || $value == 2 || $value == 3) {
                 $this->{$name} = $value;
             } else {
                 if (!empty($value)) {
                     throw new UnexpectedValueException("Difficulty grade must be 1, 2 or 3");
                 }
             }
             break;
         case "miles":
             $value = (double) $value;
             if ($value >= 0) {
                 $this->{$name} = $value;
                 $this->distanceGrade = $this->getDistanceGrade($value);
             } else {
                 throw new UnexpectedValueException("Distance must be positive");
             }
             // TODO: Validate >0 when saving
             break;
             // Grid references - start with two letters, then an even number of digits - at least 6
         // Grid references - start with two letters, then an even number of digits - at least 6
         case "startGridRef":
         case "endGridRef":
             $value = str_replace(" ", "", $value);
             if (empty($value)) {
                 break;
             }
             if (preg_match("/[A-Z][A-Z]([0-9][0-9]){3,}/", $value)) {
                 $this->{$name} = $value;
                 // Also set the lat/lng
                 $osRef = getOSRefFromSixFigureReference($value);
                 $latLng = $osRef->toLatLng();
                 $latLng->OSGB36ToWGS84();
                 if ($name == "startGridRef") {
                     $this->startLatLng = $latLng;
                 } else {
                     $this->endLatLng = $latLng;
                 }
             } else {
                 throw new UnexpectedValueException("Grid references must be at least 6-figures, with the grid square letters before (e.g. SK123456)");
             }
             break;
             // Checks TODO
         // Checks TODO
         case "location":
         case "fileLinks":
         case "routeImage":
         case "suggestedBy":
         case "status":
         case "specialTBC":
             $this->{$name} = $value;
             break;
         case "routeVisibility":
             $this->{$name} = (int) $value;
     }
 }
Example #6
0
<?php

// This relies on phpcoord, which can be downloaded from
// http://www.jstott.me.uk/phpcoord/
include '/var/www/qs/phpcoord-2.3.php';
$r = scandir("/home/nick/vmd/tiles");
foreach ($r as $file) {
    if ($file != "." && $file != "..") {
        $gr = getOSRefFromSixFigureReference(substr($file, 0, 2) . $file[2] . "00" . $file[3] . "00");
        $e = $gr->easting / 1000;
        $n = $gr->northing / 1000;
        $im = ImageCreateFromPNG("/home/nick/vmd/tiles/{$file}");
        for ($x = 0; $x < 10; $x++) {
            for ($y = 0; $y < 10; $y++) {
                $e_km = $e + $x;
                $n_km = $n + $y;
                $im2 = ImageCreateTrueColor(400, 400);
                ImageCopy($im2, $im, 0, 0, $x * 400, (9 - $y) * 400, 400, 400);
                if (!file_exists("tilesout/{$e_km}")) {
                    mkdir("tilesout/{$e_km}", 0755);
                }
                $file_out = "tilesout/{$e_km}/{$n_km}.png";
                echo "{$file_out}\n";
                ImagePNG($im2, $file_out);
                ImageDestroy($im2);
            }
        }
        ImageDestroy($im);
    }
}
header("Content-type: application/json");
$scopeSheffield = 1;
$scopeGeneralArea = 2;
if (!empty($_GET['lat']) && !empty($_GET['lon']) || !empty($_GET['east']) && !empty($_GET['north']) || !empty($_GET['gridref'])) {
    $wp = new Waypoint();
    if (!empty($_GET['lat']) && !empty($_GET['lon'])) {
        $wp->latLng = new LatLng((double) $_GET['lat'], (double) $_GET['lon']);
    } else {
        if (!empty($_GET['east']) && !empty($_GET['north'])) {
            $osRef = new OSRef((int) $_GET['east'], (int) $_GET['north']);
            $latLng = $osRef->toLatLng();
            $latLng->OSGB36ToWGS84();
            $wp->latLng = $latLng;
        } else {
            if (!empty($_GET['gridref'])) {
                $osRef = getOSRefFromSixFigureReference($_GET['gridref']);
                $latLng = $osRef->toLatLng();
                $latLng->OSGB36ToWGS84();
                $wp->latLng = $latLng;
            }
        }
    }
    // Now do a reverse geocode & return the result
    $placeName = $wp->reverseGeocode();
    echo json_encode($placeName);
} else {
    if (!empty($_GET['postcode']) || !empty($_GET['search'])) {
        $options = array("format=json", "accept-language=en-gb,en", "countrycodes=gb");
        // 	if (!empty($_GET['scope']))
        // 	{
        // 		if ($_GET['scope'] == $scopeSheffield)