r77163 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77162‎ | r77163 | r77164 >
Date:15:52, 23 November 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.7.3 - added KML formatter class
Modified paths:
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_KMLFormatter.php (added) (history)
  • /trunk/extensions/Maps/includes/Maps_Location.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.php
@@ -36,7 +36,7 @@
3737 echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.';
3838 }
3939 else {
40 - define( 'Maps_VERSION', '0.7.3 alpha' );
 40+ define( 'Maps_VERSION', '0.7.3 a2' );
4141
4242 // The different coordinate notations.
4343 define( 'Maps_COORDS_FLOAT', 'float' );
@@ -61,9 +61,11 @@
6262 $wgAutoloadClasses['MapsGeoFunctions'] = $incDir . 'Maps_GeoFunctions.php';
6363 $wgAutoloadClasses['MapsGeocoders'] = $incDir . 'Maps_Geocoders.php';
6464 $wgAutoloadClasses['MapsGeocoder'] = $incDir . 'Maps_Geocoder.php';
 65+ $wgAutoloadClasses['MapsKMLFormatter'] = $incDir . 'Maps_KMLFormatter.php';
6566 $wgAutoloadClasses['MapsLayer'] = $incDir . 'Maps_Layer.php';
6667 $wgAutoloadClasses['MapsLayerPage'] = $incDir . 'Maps_LayerPage.php';
6768 $wgAutoloadClasses['MapsLayers'] = $incDir . 'Maps_Layers.php';
 69+ $wgAutoloadClasses['MapsLocation'] = $incDir . 'Maps_Location.php';
6870 $wgAutoloadClasses['iMappingFeature'] = $incDir . 'iMappingFeature.php';
6971 $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php';
7072 $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php';
Index: trunk/extensions/Maps/includes/Maps_KMLFormatter.php
@@ -0,0 +1,155 @@
 2+<?php
 3+
 4+/**
 5+ * Class to format geographical data to KML.
 6+ *
 7+ * @since 0.7.3
 8+ *
 9+ * @file Maps_KMLFormatter.php
 10+ * @ingroup Maps
 11+ *
 12+ * @author Jeroen De Dauw
 13+ */
 14+class MapsKMLFormatter {
 15+
 16+ /**
 17+ * @since 0.7.3
 18+ *
 19+ * @var array of MapsLocation
 20+ */
 21+ protected $placemarks;
 22+
 23+ public function __construct() {
 24+ $this->clearElements();
 25+ }
 26+
 27+ /**
 28+ * Builds and returns KML representing the set geographical objects.
 29+ *
 30+ * @since 0.7.3
 31+ *
 32+ * @return string
 33+ */
 34+ public function getKML() {
 35+ $elements = $this->getKMLElements();
 36+
 37+ // http://earth.google.com/kml/2.2
 38+ return <<<EOT
 39+<?xml version="1.0" encoding="UTF-8"?>
 40+<kml xmlns="http://www.opengis.net/kml/2.2">
 41+ <Document>
 42+ $elements
 43+ </Document>
 44+</kml>
 45+EOT;
 46+ }
 47+
 48+ /**
 49+ * Adds a single placemark.
 50+ *
 51+ * @since 0.7.3
 52+ *
 53+ * @param MapsLocation $placemark
 54+ */
 55+ public function addPlacemark( MapsLocation $placemark ) {
 56+ $this->placemarks[] = $placemark;
 57+ }
 58+
 59+ /**
 60+ * Adds a multiple placemarks.
 61+ *
 62+ * @since 0.7.3
 63+ *
 64+ * @param array of MapsLocation $placemark
 65+ */
 66+ public function addPlacemarks( array $placemarks ) {
 67+ foreach ( $placemarks as $placemark ) {
 68+ $this->addPlacemark( $placemark );
 69+ }
 70+ }
 71+
 72+ /**
 73+ * Clears all set geographical objects.
 74+ *
 75+ * @since 0.7.3
 76+ */
 77+ public function clearElements() {
 78+ $this->clearPlacemarks();
 79+ }
 80+
 81+ /**
 82+ * Clears all set placemarks.
 83+ *
 84+ * @since 0.7.3
 85+ */
 86+ public function clearPlacemarks() {
 87+ $this->placemarks = array();
 88+ }
 89+
 90+ /**
 91+ * Returns the KML for all set geographical objects.
 92+ *
 93+ * @since 0.7.3
 94+ *
 95+ * @return string
 96+ */
 97+ protected function getKMLElements() {
 98+ $elements = array();
 99+
 100+ $elements = array_merge( $elements, $this->getPlacemarks() );
 101+
 102+ return implode( "\n", $elements );
 103+ }
 104+
 105+ /**
 106+ * Returns KML for all set placemarks in a list, where each element is
 107+ * a KML node representing a placemark.
 108+ *
 109+ * @since 0.7.3
 110+ *
 111+ * @return array
 112+ */
 113+ protected function getPlacemarks() {
 114+ $placemarks = array();
 115+
 116+ foreach ( $this->placemarks as $location ) {
 117+ $placemarks[] = $this->getKMLForLocation( $location );
 118+ }
 119+
 120+ return $placemarks;
 121+ }
 122+
 123+ /**
 124+ * Returns the KML representing the provided location.
 125+ *
 126+ * @since 0.7.3
 127+ *
 128+ * @param MapsLocation $location
 129+ *
 130+ * @return string
 131+ */
 132+ protected function getKMLForLocation( MapsLocation $location ) {
 133+ $name = Xml::element( 'name', array(), $location->getTitle() );
 134+
 135+ $description = '<description><![CDATA[ ' . $location->getText() . ']]></description>';
 136+
 137+ // lon,lat[,alt]
 138+ $coordinates = Xml::element(
 139+ 'coordinates',
 140+ array(),
 141+ $location->getLongitude() . ',' . $location->getLatitude() . ',' . $location->getAltitude()
 142+ );
 143+
 144+ return <<<EOT
 145+ <Placemark>
 146+ $name
 147+ $description
 148+ <Point>
 149+ $coordinates
 150+ </Point>
 151+ </Placemark>
 152+
 153+EOT;
 154+ }
 155+
 156+}
\ No newline at end of file
Property changes on: trunk/extensions/Maps/includes/Maps_KMLFormatter.php
___________________________________________________________________
Added: svn:eol-style
1157 + native
Index: trunk/extensions/Maps/includes/Maps_Location.php
@@ -197,6 +197,20 @@
198198 }
199199
200200 /**
 201+ * Returns the locations altitude.
 202+ *
 203+ * @since 0.7.3
 204+ *
 205+ * @return float
 206+ */
 207+ public function getAltitude() {
 208+ if ( !$this->isValid() ) {
 209+ throw new Exception( 'Attempt to get the altitude of an invalid location' );
 210+ }
 211+ return $this->altitude;
 212+ }
 213+
 214+ /**
201215 * Returns the locations coordinates formatted in the specified notation.
202216 *
203217 * @since 0.7.1
@@ -286,7 +300,7 @@
287301 * @return string
288302 */
289303 public function getTitle() {
290 - return $tis->title;
 304+ return $this->title;
291305 }
292306
293307 /**
@@ -297,7 +311,7 @@
298312 * @return string
299313 */
300314 public function getText() {
301 - return $tis->text;
 315+ return $this->text;
302316 }
303317
304318 /**
@@ -308,7 +322,7 @@
309323 * @return string
310324 */
311325 public function getIcon() {
312 - return $tis->icon;
313 - }
 326+ return $this->icon;
 327+ }
314328
315329 }

Status & tagging log