/// Die Naviser Hütte
/// </googlemap>
function wrmapParserHook($input, $args, $parser) {
- $output = '<googlemap version="0.9" lat="47.452237" lon="11.208801" type="terrain" zoom="9">'; // TODO: Varable coordinates
+ $debug = (isset($args['debug']));
+
+ $output = '';
$lines = explode("\n", $input);
+ $latitudes = array();
+ $longitudes = array();
foreach ($lines as $line) {
try {
$l = trim($line);
if (count($columns) != 3) throw new Exception(sprintf(utf8_encode('Die Anzahl der Spalten ist nicht 3 sondern %d'), count($columns)));
$columns = list($type, $geo, $name) = $columns;
list($latitude, $longitude) = wrGeoStringToGeo($geo);
+ $latitudes[] = $latitude;
+ $longitudes[] = $longitude;
$output .= sprintf("%F, %F, %s\n", $latitude, $longitude, htmlspecialchars($name));
} catch (Exception $e) {
return sprintf(utf8_encode('Ungültige Zeile in der Koordinatenliste: <em>%s</em>. %s'), htmlspecialchars($line), htmlspecialchars($e->getMessage()));
}
}
- $output = $output .= "</googlemap>\n";
+ if (count($latitudes) == 0) return utf8_encode('Keine Koordinaten eingetragen');
+ $minLatitude = min($latitudes);
+ $centerLat = $minLatitude + (max($latitudes) - $minLatitude) / 2;
+ $minLongitude = min($longitudes);
+ $centerLon = $minLongitude + (max($longitudes) - $minLongitude) / 2;
+
+ // TODO: Varable zoom level
+ $output = '<googlemap version="0.9" lat="' . $centerLat . '" lon="' . $centerLon . '" type="terrain" zoom="9">'. "\n" . $output . "</googlemap>\n";
+
+ if ($debug) return $output = "<pre><nowiki>$output</nowiki></pre>";
+
/*
global $wgTitle, $wgUser;
$parser = new Parser();
$result = $parser->parse($output, $wgTitle, $parserOptions); // TODO: Make this call less complicated
return $result->getText();
*/
- $result = $parser->recursiveTagParse($output); // TODO: Maybe this is already the solution?
- return $result;
+
+ $output = $parser->recursiveTagParse($output); // TODO: Maybe this is already the solution?
+
+ return $output;
}