setHook('wrgmap', array($wrGoogleMaps, 'render')); return true; } // Java script // ----------- // Global JavaScript functions define(WRGMAPJSFUNCTIONS, << //" + name+ "");}); return marker; } //]]> JAVASCRIPT ); /** This class was inpired by the GoogleMaps class of the GoogleMaps extension. */ class WrGoogleMaps { /// the Google API key (obtained from /// http://www.google.com/apis/maps/signup.html) private $apiKey = null; /// How many tags are on the current page? private $mapsCount = 0; /// Constructor function WrGoogleMaps($apiKey) { $this->apiKey = $apiKey; } /// Renders the tag /// @param $content string - the content of the tag /// @param $args array - the array of attribute name/value pairs for the tag /// @param $parser Parser - the MW Parser object for the current page /// /// @return string - the html for rendering the map function render($content, $args, $parser) { ++$this->mapsCount; // Decode data if (isset($args['lat'])) $latitude = floatval($args['lat']); else $latitude = 47.267648; // latitude as float value if (isset($args['lon'])) $longitude = floatval($args['lon']); else $longitude = 11.404655; // longitude as float value if (isset($args['zoom'])) $zoom = intval($args['zoom']); else $zoom = 10; // Google Zoom Level $staticSizeX = 600; $staticSizeY = 450; $latitude_s = sprintf('%.6F', $latitude); $longitude_s = sprintf('%.6F', $longitude); // Query database $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('wrsleddingcache', array('page_title', 'position_latitude', 'position_longitude'), array('show_in_overview', 'not under_construction')); $sleddingRoutes = array(); while ($sleddingRoute = $dbr->fetchRow($res)) $sleddingRoutes[] = $sleddingRoute; $dbr->freeResult($res); // Load Google Maps Script and define functions $output = ''; if ($this->mapsCount == 1) { $output .= '' . "\n"; $output .= WRGMAPJSFUNCTIONS; } // Create static map image link $staticLink = "http://maps.google.com/staticmap?center=$latitude_s,$longitude_s&zoom=$zoom&size=${staticSizeX}x$staticSizeY&key=$this->apiKey"; $staticMarkers = array(); foreach ($sleddingRoutes as $s) { $lat = $s['position_latitude']; // this is a string $lon = $s['position_longitude']; // this is a string $staticMarkers[] = sprintf('%s,%s,bluer', $lat, $lon); } if (count($staticMarkers) > 0) $staticLink .= '&markers=' . implode('|', $staticMarkers); // Create
element where the map is placed in $mapName = 'wrgmap' . $this->mapsCount; $output .= ''; // Return output $output .= '\n"; $output .= '\n"; return wrCommonReplaceByMarker($output, 'wrmap'); } // returns a string that creates a map object called 'map' // $latitude, $longitude and $zoom have to be float/integer values. private function addMap($mapName, $latitude, $longitude, $zoom) { return "\tvar map = new GMap2(document.getElementById('$mapName'), {'mapTypes': [G_NORMAL_MAP, G_HYBRID_MAP, G_PHYSICAL_MAP, G_SATELLITE_MAP]});\n" . "\tmap.addControl(new GLargeMapControl());\n" . "\tmap.addControl(new GMapTypeControl());\n" . "\tmap.addControl(new GScaleControl());\n" . sprintf("\tmap.setCenter(new GLatLng(%.6F, %.6F), %d);\n", $latitude, $longitude, $zoom) . "\tmap.setMapType(G_PHYSICAL_MAP);\n"; // "\tmap.enableScrollWheelZoom();\n"; } // returns a string with a add marker javascript call // $latitude and $longitude are expected as string private function addJsMarker($latitude, $longitude, $pageTitle) { return "\tmap.addOverlay(wrCreateMarker($latitude, $longitude, \"" . htmlspecialchars(addslashes($pageTitle)) . "\", wrSleddingIcon));\n"; } } ?>