X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/mediawiki_extensions/wrmap.git/blobdiff_plain/139b5bd439c7c771dad8c8a1ab1c776edf536122..527e5780153d4792e6bd680be38576b95f3e0b5f:/wrmap.body.php diff --git a/wrmap.body.php b/wrmap.body.php index afd1a9e..60fbf18 100644 --- a/wrmap.body.php +++ b/wrmap.body.php @@ -1,139 +1,51 @@ 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; - } - +class WrMap { /// 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; - if (isset($args['lon'])) $longitude = floatval($args['lon']); else $longitude = 11.404655; + public static function render($content, $args, $parser, $frame) { + // Get center and zoom level from $args + 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; + $res = $dbr->select(array('wrsledruncache', 'wrreportcache'), array('wrsledruncache.page_title', 'position_latitude', 'position_longitude', 'date_report', '`condition`'), array('show_in_overview', 'not under_construction'), __METHOD__, array(), array('wrreportcache' => array('left outer join', 'wrsledruncache.page_id=wrreportcache.page_id'))); + $sledruns = array(); + while ($sledrun = $dbr->fetchRow($res)) $sledruns[] = $sledrun; $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,$longitude&zoom=$zoom&size=${staticSizeX}x$staticSizeY&key=$this->apiKey"; - $staticMarkers = array(); - foreach ($sleddingRoutes as $s) { - $lat = $s['position_latitude']; - $lon = $s['position_longitude']; - $staticMarkers[] = sprintf('%.3f,%.3f,bluer', $lat, $lon); - } - if (count($staticMarkers) > 0) $staticLink .= '&markers=' . implode('|', $staticMarkers); - - // Create
element where the map is placed in - $mapName = 'wrgmap' . $this->mapsCount; - $output .= ''; + $parserOutput = $parser->getOutput(); + $parserOutput->addHeadItem('', 'googlemaps'); + $parserOutput->addModules('ext.wrmap'); - // Return output - $output .= '\n"; - $output .= '\n"; - - return wrCommonReplaceByMarker($output, 'wrmap'); - } - - // returns a string that creates a map object called 'map' - 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" . - "\tmap.setCenter(new GLatLng($latitude, $longitude), $zoom);\n" . - "\tmap.setMapType(G_PHYSICAL_MAP);\n" . - "\tmap.enableScrollWheelZoom();\n"; + $output .= "
\n"; + + return $output; } - // returns a string with a add marker javascript call - private function addJsMarker($latitude, $longitude, $pageTitle) { - return "\tmap.addOverlay(wrCreateMarker($latitude, $longitude, \"" . htmlspecialchars(addslashes($pageTitle)) . "\", wrSleddingIcon));\n"; - } - }