4 /// Renders the <wrgmap> tag and the <wrmap> tag.
5 /// This class would be the only class needed but as the function render() toes not provide an argument
6 /// telling which tag name called the function, a trick with two inherited classes has to be used.
7 /// @param $content string - the content of the <wrgmap> tag
8 /// @param $args array - the array of attribute name/value pairs for the tag
9 /// @param $parser Parser - the MW Parser object for the current page
11 /// @return string - the html for rendering the map
12 public static function render($content, $args, $parser, $frame) {
13 // Unfortunately, $tagname is no argument of this function, therefore we have to use a trick with derived classes.
14 $tagname = strtolower(get_called_class()); // either wrmap or wrgmap
15 assert(in_array($tagname, 'wrmap', 'wrgmap'));
17 // Get center and zoom level from $args
18 if (isset($args['lat'])) $latitude = floatval($args['lat']); else $latitude = 47.267648; // latitude as float value
19 if (isset($args['lon'])) $longitude = floatval($args['lon']); else $longitude = 11.404655; // longitude as float value
20 if (isset($args['zoom'])) $zoom = intval($args['zoom']); else $zoom = 10; // Google Zoom Level
21 if (isset($args['width'])) $width = intval($args['width']); else $width = null; // null corresponds to 100%
22 if (isset($args['height'])) $height = intval($args['height']); else $height = 450;
23 $latitude_s = sprintf('%.6F', $latitude);
24 $longitude_s = sprintf('%.6F', $longitude);
25 $width_s = is_null($width) ? '100%' : $width . 'px';
26 $height_s = $height . 'px';
29 $dbr = wfGetDB(DB_SLAVE);
30 $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')));
32 while ($sledrun = $dbr->fetchRow($res)) $sledruns[] = $sledrun;
33 $dbr->freeResult($res);
35 $parserOutput = $parser->getOutput();
36 $parserOutput->addHeadItem('<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.8&sensor=false"></script>', 'googlemaps');
37 $parserOutput->addModules('ext.wrmap');
39 // Create <div/> element where the map is placed in
40 global $wgExtensionAssetsPath;
41 $output = "<div class=\"wrmap\" style=\"width: $width_s; height: $height_s; border-style:none;\" data-center-lon=\"$longitude_s\" data-center-lat=\"$latitude_s\" data-zoom=\"$zoom\" data-img-path=\"$wgExtensionAssetsPath/wrmap/openlayers/img/\">\n";
43 // create layeer showing sledruns as icons (note: why not use WFS?)
44 foreach ($sledruns as $sledrun) {
45 $lat = $sledrun['position_latitude'];
46 $lon = $sledrun['position_longitude'];
47 if (!$lat || !$lon) continue;
48 $title = Title::newFromText($sledrun['page_title']);
49 $title_text = htmlspecialchars($title->getText());
50 $title_url = htmlspecialchars($title->getLocalUrl());
51 $output .= "<p data-lon=\"$lon\" data-lat=\"$lat\" data-title=\"$title_text\" data-url=\"$title_url\" ";
52 if (!is_null($sledrun['date_report'])) $output .= "data-date_report=\"{$sledrun['date_report']}\" ";
53 if (!is_null($sledrun['condition'])) $output .= "data-condition=\"{$sledrun['condition']}\" ";
56 $output .= "</div>\n";
64 class WrMap extends WrBaseMap {
69 class WrGMap extends WrBaseMap {