global $wgParser;
global $wgGoogleMapsKey;
$wrGoogleMaps = new WrGoogleMaps($wgGoogleMapsKey);
- $wgParser->setHook('wrmap', 'wrmapParserHook');
$wgParser->setHook('wrgmap', array($wrGoogleMaps, 'render'));
return true;
}
}
-/// Format inside <wrmap>...</wrmap> has to be like this:
-///
-/// <wrmap>
-/// Rodelbahn|47.143241 N 11.208959 E|Birgitzer Alm
-/// ...
-/// </wrmap>
-///
-/// The extension produces a format like this:
-/// <googlemap version="0.9" lat="47.241016" lon="11.56517" zoom="11">
-/// 47.241731, 11.358994, Birgitzer Alm
-/// Die Birgitzer Alm ist nett
-/// 47.17607, 11.542763, Naviser Hütte
-/// Die Naviser Hütte
-/// </googlemap>
-function wrmapParserHook($input, $args, $parser) {
- $debug = (isset($args['debug']) && $args['debug'] != '0');
-
- $output = '';
- $lines = explode("\n", $input);
- $latitudes = array();
- $longitudes = array();
- foreach ($lines as $line) {
- try {
- $l = trim($line);
- if (strlen($l) == 0) continue;
- $columns = explode('|', $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;
- if (strlen(trim($geo)) == 0) continue;
- 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()));
- }
- }
- 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 "<pre><nowiki>$output</nowiki></pre>\n";
- return $parser->recursiveTagParse($output);
-}
-
-
?>