]> ToastFreeware Gitweb - philipp/winterrodeln/mediawiki_extensions/wrmap.git/blobdiff - wrmap.body.php
Both, wrmap and wrgmap tags are parsed now.
[philipp/winterrodeln/mediawiki_extensions/wrmap.git] / wrmap.body.php
index 60fbf18295f739d3bbaa5ae0adc7a4e70b549370..c4e3d9e7b219e45ee11ce4320e037cc7a08db456 100644 (file)
@@ -1,19 +1,29 @@
 <?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);
@@ -28,7 +38,9 @@ class WrMap {
                
                // 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'];
@@ -48,5 +60,13 @@ class WrMap {
 
 }
 
+// <wrmap> tag
+class WrMap extends WrBaseMap {
+}
+
+
+// <wrgmap> tag
+class WrGMap extends WrBaseMap {
+}
 
 ?>