Source for file map.php

Documentation is available at map.php

  1. <?php
  2. /**
  3. * Defines a class for viewing the SLOODLE Map module in Moodle.
  4. * Derived from the module view base class.
  5. *
  6. @package sloodle
  7. @copyright Copyright (c) 2008 Sloodle (various contributors)
  8. @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. @contributor Peter R. Bloomfield
  11. */
  12.  
  13. /** The base module view class */
  14. require_once(SLOODLE_DIRROOT.'/view/base/base_view_module.php');
  15. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  16.  
  17.  
  18. /**
  19. * Class for rendering a view of a Map module in Moodle.
  20. @package sloodle
  21. */
  22. {
  23.     /**
  24.     * A SLOODLE map module object to wrap the basic map functionality.
  25.     * @var SloodleModuleMap 
  26.     * @access private
  27.     */
  28.     var $sloodle_map_module = null;
  29.     
  30.     /**
  31.     * Numeric array of locations, obtained from the {@link SloodleModuleMap} object.
  32.     * @var array 
  33.     * @access private
  34.     */
  35.     var $locations = array();
  36.  
  37.     /**
  38.     * Constructor.
  39.     */
  40.     function sloodle_view_map()
  41.     {
  42.     }
  43.  
  44.     /**
  45.     * Processes request data to determine which Map is being accessed.
  46.     */
  47.     function process_request()
  48.     {
  49.         // Process the basic data
  50.         parent::process_request();
  51.         
  52.         // Obtain a map module
  53.         $tempsession new SloodleSession(false);
  54.         $this->sloodle_map_module = sloodle_load_module('map'$tempsession$this->cm->id);
  55.         if (!$this->sloodle_map_moduleerror('Failed to load SLOODLE map module.');
  56.         
  57.         // Get the locations currently on the map
  58.         $this->locations = $this->sloodle_map_module->get_locations();
  59.     }
  60.  
  61.     /**
  62.     * Process any form data which has been submitted.
  63.     */
  64.     function process_form()
  65.     {
  66.     }
  67.  
  68.     /**
  69.     * Print the page header (requires special scripts to be added into the header)
  70.     */
  71.     function print_header()
  72.     {
  73.         global $CFG;
  74.         
  75.         // Get the initial coordinates and zoom values from the map module
  76.         list($initialx$initialy$this->sloodle_map_module->get_initial_coordinates();
  77.         $initialzoom $this->sloodle_map_module->get_initial_zoom();
  78.         // Get the strings for showing/hiding pan and zoom controls
  79.         $showpan 'false'$showzoom 'false';
  80.         if ($this->sloodle_map_module->check_pan_controls()) $showpan 'true';
  81.         if ($this->sloodle_map_module->check_zoom_controls()) $showzoom 'true';
  82.         // Get the string for enabling/disabling map dragging
  83.         $allowdrag '';
  84.         if (!$this->sloodle_map_module->check_allow_drag()) $allowdrag 'mapInstance.disableDragging();';
  85.         
  86.         // Construct code to add the initial markers to the map
  87.         $initialmarkers '';
  88.         foreach ($this->locations as $loc{
  89.             $initialmarkers .= "mapInstance.addMarker(new Marker(yellow_markers, new XYPoint({$loc->globalx}, {$loc->globaly})));\n";
  90.         }
  91.  
  92.         // Construct the JavaScript for our header
  93.         $js = <<<XXXEODXXX
  94. <script src="http://secondlife.com/apps/mapapi/" type="text/javascript"></script>
  95.  
  96. <script type="text/javascript">
  97.  
  98. // Declare our map
  99. var mapInstance;
  100. // Declare a variable to store marker data
  101. var marker;
  102.  
  103. // Declare the yellow dot images
  104. var yellow_dot_image = new Img("{$CFG->wwwroot}/mod/sloodle/map_dot_yellow.gif", 9, 9);
  105. var yellow_icon = new Icon(yellow_dot_image);
  106. var yellow_markers = [yellow_icon, yellow_icon, yellow_icon, yellow_icon, yellow_icon, yellow_icon];
  107.  
  108.  
  109. var dblClick = function(x,y)
  110. {
  111.     try {
  112.  
  113.         // Go to a SLurl of the given location
  114.         gotoSLURL(x, y);
  115.  
  116.     } catch (e) {
  117.         alert('Sorry. The SL map API does not seem to support direct teleporting.');
  118.     }
  119. }
  120.  
  121. var sglClick = function(x,y)
  122. {
  123.     try {
  124.         var elemX = document.getElementById('xcoord');
  125.         var elemY = document.getElementById('ycoord');
  126.  
  127.         elemX.value = x;
  128.         elemY.value = y;
  129.     } catch (e) {
  130.     }
  131. }
  132.  
  133. function sloodle_load_map()
  134. {
  135.  
  136.     try {
  137.         // Create the map and setup the interface settings
  138.         mapInstance = new SLMap(document.getElementById('map-container'), {hasZoomControls: {$showzoom}, hasPanningControls: {$showpan}, doubleClickHandler: dblClick});
  139.         mapInstance.centerAndZoomAtSLCoord(new XYPoint({$initialx},{$initialy}), {$initialzoom});
  140.         {$allowdrag}
  141.  
  142.         // Put markers on each location from the database
  143.         {$initialmarkers}
  144.     
  145.     } catch (e) {
  146.        alert("An error occurred while trying to load the map: " + e.description);
  147.     }
  148. }
  149.  
  150. function showMapWindow(x, y, text)
  151. {
  152.     // Create a map window at the specified position
  153.     try {
  154.         mapInstance.addMapWindow(new MapWindow(text), new XYPoint(x, y));
  155.         mapInstance.panOrRecenterToSLCoord(new XYPoint(x, y), true);
  156.     } catch (e) {
  157.         alert("An error occurred while trying to create a map window: " + e.description);
  158.     }
  159. }
  160.  
  161. </script>
  162. XXXEODXXX;
  163.  
  164.         // Print the header, including our JavaScript
  165.         $editbuttons '';
  166.         if ($this->canedit$editbuttons update_module_button($this->cm->id$this->course->idget_string('modulename','sloodle'));
  167.         $navigation "<a href=\"index.php?id={$this->course->id}\">".get_string('modulenameplural','sloodle')."</a> ->";
  168.         print_header_simple(format_string($this->sloodle->name)"""$navigation ".format_string($this->sloodle->name)""$jstrue""navmenu($this->course$this->cm));
  169.     }
  170.  
  171.     /**
  172.     * Render the view of the Map.
  173.     */
  174.     function render()
  175.     {
  176.         global $CFG;
  177.  
  178.         // Render the map itself
  179.         echo '<p style="text-align:center;">Click and drag the map to pan around.</p>';
  180.         echo '<div id="map-container" style="width:500px; height:500px; margin-left:auto; margin-right:auto;"></div>',"\n";
  181.         echo '<script type="text/javascript">sloodle_load_map();</script>',"\n";
  182.  
  183.         // Render a list of location links below the map, which can be clicked to see data about them
  184.         echo "<div style=\"text-align:center;\"><ol>\n";
  185.         foreach ($this->locations as $loc{
  186.             // Output the location and region name
  187.             echo '<li>'$loc->name" (region: {$loc->region}) \n";
  188.             // Output a button to show it on the map
  189.             $teleportURL "secondlife://{$loc->region}/{$loc->localx}/{$loc->localy}/{$loc->localz}";
  190.             $windowtext "<b>{$loc->name}</b><br/>{$loc->description}<br/><br/><i>[<a href=&quot;{$teleportURL}&quot;>Teleport Now</a>]</i>";
  191.             echo "<input type=\"button\" value=\"Show on map\" onclick=\"showMapWindow({$loc->globalx}, {$loc->globaly}, '{$windowtext}');\" /> \n";
  192.             // Output a link to teleport directly to it
  193.             echo "[<a href=\"{$teleportURL}\">Teleport Now</a>]\n";
  194.             echo "</li>\n";
  195.         }
  196.         echo '</ol></div>';
  197.     }
  198.  
  199. }
  200.  
  201.  
  202. ?>

Documentation generated on Fri, 17 Jul 2009 11:01:50 +0100 by phpDocumentor 1.4.0