2 require_once dirname(__FILE__) . '/../wrgeo/wrgeo.body.php'; # for the function wrGeoGeoStringToGeo
4 function wrMapParserFirstCallInit() {
6 $wgParser->setHook('wrmap', 'wrmapParserHook');
11 /// Format inside <wrmap>...</wrmap> has to be like this:
14 /// Rodelbahn|47.143241 N 11.208959 E|Birgitzer Alm
18 /// The extension produces a format like this:
19 /// <googlemap version="0.9" lat="47.241016" lon="11.56517" zoom="11">
20 /// 47.241731, 11.358994, Birgitzer Alm
21 /// Die Birgitzer Alm ist nett
22 /// 47.17607, 11.542763, Naviser Hütte
25 function wrmapParserHook($input, $args, $parser) {
26 $debug = (isset($args['debug']) && $args['debug'] != '0');
29 $lines = explode("\n", $input);
31 $longitudes = array();
32 foreach ($lines as $line) {
35 if (strlen($l) == 0) continue;
36 $columns = explode('|', $line);
37 if (count($columns) != 3) throw new Exception(sprintf(utf8_encode('Die Anzahl der Spalten ist nicht 3 sondern %d'), count($columns)));
38 $columns = list($type, $geo, $name) = $columns;
39 if (strlen(trim($geo)) == 0) continue;
40 list($latitude, $longitude) = wrGeoStringToGeo($geo);
41 $latitudes[] = $latitude;
42 $longitudes[] = $longitude;
43 $output .= sprintf("%F, %F, %s\n", $latitude, $longitude, htmlspecialchars($name));
44 } catch (Exception $e) {
45 return sprintf(utf8_encode('Ungültige Zeile in der Koordinatenliste: <em>%s</em>. %s'), htmlspecialchars($line), htmlspecialchars($e->getMessage()));
48 if (count($latitudes) == 0) return utf8_encode('Keine Koordinaten eingetragen');
49 $minLatitude = min($latitudes);
50 $centerLat = $minLatitude + (max($latitudes) - $minLatitude) / 2;
51 $minLongitude = min($longitudes);
52 $centerLon = $minLongitude + (max($longitudes) - $minLongitude) / 2;
54 // TODO: Varable zoom level
55 $output = '<googlemap version="0.9" lat="' . $centerLat . '" lon="' . $centerLon . '" type="terrain" zoom="9">'. "\n" . $output . "</googlemap>\n";
57 if ($debug) return "<pre><nowiki>$output</nowiki></pre>\n";
58 return $parser->recursiveTagParse($output);