Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | 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>.'; |
38 | 38 | } |
39 | 39 | else { |
40 | | - define( 'Maps_VERSION', '0.7.3 alpha' ); |
| 40 | + define( 'Maps_VERSION', '0.7.3 a2' ); |
41 | 41 | |
42 | 42 | // The different coordinate notations. |
43 | 43 | define( 'Maps_COORDS_FLOAT', 'float' ); |
— | — | @@ -61,9 +61,11 @@ |
62 | 62 | $wgAutoloadClasses['MapsGeoFunctions'] = $incDir . 'Maps_GeoFunctions.php'; |
63 | 63 | $wgAutoloadClasses['MapsGeocoders'] = $incDir . 'Maps_Geocoders.php'; |
64 | 64 | $wgAutoloadClasses['MapsGeocoder'] = $incDir . 'Maps_Geocoder.php'; |
| 65 | + $wgAutoloadClasses['MapsKMLFormatter'] = $incDir . 'Maps_KMLFormatter.php'; |
65 | 66 | $wgAutoloadClasses['MapsLayer'] = $incDir . 'Maps_Layer.php'; |
66 | 67 | $wgAutoloadClasses['MapsLayerPage'] = $incDir . 'Maps_LayerPage.php'; |
67 | 68 | $wgAutoloadClasses['MapsLayers'] = $incDir . 'Maps_Layers.php'; |
| 69 | + $wgAutoloadClasses['MapsLocation'] = $incDir . 'Maps_Location.php'; |
68 | 70 | $wgAutoloadClasses['iMappingFeature'] = $incDir . 'iMappingFeature.php'; |
69 | 71 | $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php'; |
70 | 72 | $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 |
1 | 157 | + native |
Index: trunk/extensions/Maps/includes/Maps_Location.php |
— | — | @@ -197,6 +197,20 @@ |
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
| 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 | + /** |
201 | 215 | * Returns the locations coordinates formatted in the specified notation. |
202 | 216 | * |
203 | 217 | * @since 0.7.1 |
— | — | @@ -286,7 +300,7 @@ |
287 | 301 | * @return string |
288 | 302 | */ |
289 | 303 | public function getTitle() { |
290 | | - return $tis->title; |
| 304 | + return $this->title; |
291 | 305 | } |
292 | 306 | |
293 | 307 | /** |
— | — | @@ -297,7 +311,7 @@ |
298 | 312 | * @return string |
299 | 313 | */ |
300 | 314 | public function getText() { |
301 | | - return $tis->text; |
| 315 | + return $this->text; |
302 | 316 | } |
303 | 317 | |
304 | 318 | /** |
— | — | @@ -308,7 +322,7 @@ |
309 | 323 | * @return string |
310 | 324 | */ |
311 | 325 | public function getIcon() { |
312 | | - return $tis->icon; |
313 | | - } |
| 326 | + return $this->icon; |
| 327 | + } |
314 | 328 | |
315 | 329 | } |