<?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 {
+}
?>
<?php
-// This extension depends on no other extension.
+/* This extension creates a map using OpenLayers to show sledrun details and sledrun overviews.
+ *
+ * This extension depends on no other extension.
+ *
+ * Definition:
+ * <wrgmap lat="47.267648" lon="11.40465" zoom="10"/>
+ * Shows icons for all sledruns.
+ * lat, lon and zoom are optional.
+ *
+ *
+ *
+ *
+ * <wrmap lat="47.267648" lon="11.40465" zoom="10" width="550" height="400">
+ *
+ * <gasthaus wiki="Rumer Alm (Gasthaus)" name="Rumer Alm">
+ * 47.11 N 12.53 E
+ * </gasthaus>
+ *
+ * <gasthaus name="Enzianhuette">
+ * 47.11 N 12.53 E
+ * </gasthaus>
+ *
+ * <bushaltestelle name="Rum Sanatorium">
+ * 47.11 N 12.53 E
+ * </bushaltestelle>
+ *
+ * <rodelbahn>
+ * 47.11 12.53
+ * 19.33 12.12
+ * </rodelbahn>
+ *
+ * <gehweg>
+ * 23.12 12.12
+ * 12.12 12.12
+ * </gehweg>
+ *
+ * <alternative>
+ * 12.23 32.12
+ * 12.22 12.22
+ * </alternative>
+ *
+ * <lift>
+ * 23.23 23.12
+ * 12.12 12.12
+ * </lift>
+ *
+ * <linie farbe="#232321" dicke="5">
+ * 23.23 23.12
+ * 12.12 12.12
+ * </linie>
+ *
+ * <punkt name="Brunnen">
+ * 23.23 23.12
+ * </punkt>
+ *
+ * </wrmap>
+ * lat, lon and zoom are optional.
+ */
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Winterrodeln Map',
- 'version' => '2.1.1',
+ 'version' => '3.0.0',
'author' =>'Philipp Spitzer',
'url' => 'http://www.winterrodeln.org/trac/wiki/WrMap',
- 'description' => 'This extension creates a map using OpenLayers to show sledruns.'
+ 'description' => 'This extension creates a map using OpenLayers to show sledrun details and sledrun overviews.'
);
function wrMapParserFirstCallInit($parser) {
$parser->setHook('wrgmap', 'WrMap::render');
+ $parser->setHook('wrmap', 'WrMap::render');
return true;
}