<?php
-class WrMap {
- /// Renders the <wrgmap> tag
+class WrBaseMap {
+ /// Renders the <wrgmap> tag and the <wrmap> tag.
+ /// This class would be the only class needed but as the function render() toes not provide an argument
+ /// telling which tag name called the function, a trick with two inherited classes has to be used.
/// @param $content string - the content of the <wrgmap> 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
public static function render($content, $args, $parser, $frame) {
+ // Unfortunately, $tagname is no argument of this function, therefore we have to use a trick with derived classes.
+ $tagname = strtolower(get_called_class()); // either wrmap or wrgmap
+ assert(in_array($tagname, 'wrmap', 'wrgmap'));
+
// 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
+ if (isset($args['width'])) $width = intval($args['width']); else $width = null; // null corresponds to 100%
+ if (isset($args['height'])) $height = intval($args['height']); else $height = 450;
$latitude_s = sprintf('%.6F', $latitude);
$longitude_s = sprintf('%.6F', $longitude);
+ $width_s = is_null($width) ? '100%' : $width . 'px';
+ $height_s = $height . 'px';
// Query database
$dbr = wfGetDB(DB_SLAVE);
// Create <div/> element where the map is placed in
global $wgExtensionAssetsPath;
- $output = "<div class=\"wrmap\" style=\"width: 100%; height: 450px; border-style:none;\" data-center-lon=\"$longitude_s\" data-center-lat=\"$latitude_s\" data-zoom=\"$zoom\" data-img-path=\"$wgExtensionAssetsPath/wrmap/openlayers/img/\">\n";
+ $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";
+
+ // create layeer showing sledruns as icons (note: why not use WFS?)
foreach ($sledruns as $sledrun) {
$lat = $sledrun['position_latitude'];
$lon = $sledrun['position_longitude'];
}
+// <wrmap> tag
+class WrMap extends WrBaseMap {
+}
+
+
+// <wrgmap> tag
+class WrGMap extends WrBaseMap {
+}
?>