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, array('wrmap', 'wrgmap')));
+
+ $parserOutput = $parser->getOutput();
+ $parserOutput->addHeadItem('', 'googlemaps');
+ $parserOutput->addModules('ext.wrmap');
+
+ // append all sledruns as icon
+ $json_features = array();
+ $show_sledruns = ($tagname == 'wrgmap');
+ if ($show_sledruns) {
+ $json_features = array_merge($json_features, sledruns_to_json_features());
+ }
+
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;
- list($latitude, $longitude) = wrGeoStringToGeo($geo);
- $latitudes[] = $latitude;
- $longitudes[] = $longitude;
- $output .= sprintf("%F, %F, %s\n", $latitude, $longitude, htmlspecialchars($name));
+ // map properties
+ $properties = array();
+ if (isset($args['lat'])) $properties['lat'] = (float) $args['lat']; // latitude as float value
+ if (isset($args['lon'])) $properties['lon'] = (float) $args['lon']; // longitude as float value
+ if (isset($args['zoom'])) $properties['zoom'] = (int) $args['zoom']; // zoom as int value
+ if (isset($args['width'])) $properties['width'] = (int) $args['width']; // width as int value
+ if (isset($args['height'])) $properties['height'] = (int) $args['height']; // height as int value
+
+ // append all elements in the XML
+ $json_features = array_merge($json_features, xml_to_json_features('' . $content . ''));
} catch (Exception $e) {
- return sprintf(utf8_encode('Ungültige Zeile in der Koordinatenliste: %s. %s'), htmlspecialchars($line), htmlspecialchars($e->getMessage()));
+ return '' . htmlspecialchars("Fehler beim Parsen der Landkarte: " . $e->getMessage()) . '
';
}
+
+ // create final geojson
+ $json = array(
+ 'type' => 'FeatureCollection',
+ 'features' => $json_features,
+ 'properties' => $properties
+ );
+ $json_string = json_encode($json);
+
+ // Create element where the map is placed in
+ global $wgExtensionAssetsPath;
+ $width_s = (isset($properties['width'])) ? (string) $properties['width'] . 'px' : '100%';
+ $height_s = (isset($properties['height']) ? (string) $properties['height'] : 450) . 'px';
+ $output = "";
+ $output .= "";
+ $output .= "
\n";
+
+ return $output;
}
- 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 = ''. "\n" . $output . "\n";
-
- if ($debug) return $output = "$output
";
-
- /*
- global $wgTitle, $wgUser;
- $parser = new Parser();
- $parserOptions = new ParserOptions();
- $parserOptions->initialiseFromUser($wgUser);
- $result = $parser->parse($output, $wgTitle, $parserOptions); // TODO: Make this call less complicated
- return $result->getText();
- */
-
- $output = $parser->recursiveTagParse($output); // TODO: Maybe this is already the solution?
-
- return $output;
}
+// tag
+class WrMap extends WrBaseMap {
+}
+
+
+// tag
+class WrGMap extends WrBaseMap {
+}
+
?>