Index: trunk/extensions/Maps/includes/services/GoogleMaps/Maps_GoogleMaps.php |
— | — | @@ -120,6 +120,17 @@ |
121 | 121 | global $egMapsGoogleMapsZoom; |
122 | 122 | return $egMapsGoogleMapsZoom; |
123 | 123 | } |
| 124 | + |
| 125 | + /** |
| 126 | + * Returns all possible values for the overlays parameter. |
| 127 | + * |
| 128 | + * @since 0.7.1 |
| 129 | + * |
| 130 | + * @return array |
| 131 | + */ |
| 132 | + public function getOverlayNames() { |
| 133 | + return array_keys( self::$overlayData ); |
| 134 | + } |
124 | 135 | |
125 | 136 | /** |
126 | 137 | * @see MapsMappingService::getMapId |
Index: trunk/extensions/Maps/includes/Maps_CoordinateParser.php |
— | — | @@ -45,6 +45,14 @@ |
46 | 46 | * @return array of float or false |
47 | 47 | */ |
48 | 48 | public static function parseCoordinates( $coordinates ) { |
| 49 | + if ( $coordinates === false ) { |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + if ( is_array( $coordinates ) ) { |
| 54 | + $coordinates = implode( self::$separators[0], $coordinates ); |
| 55 | + } |
| 56 | + |
49 | 57 | // Handle i18n notations. |
50 | 58 | $coordinates = self::handleI18nLabels( $coordinates ); |
51 | 59 | |
Index: trunk/extensions/Maps/includes/Maps_Location.php |
— | — | @@ -0,0 +1,215 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class describing a single location (geographical point). |
| 6 | + * |
| 7 | + * @since 0.7.1 |
| 8 | + * |
| 9 | + * @file Maps_Location.php |
| 10 | + * @ingroup Maps |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw |
| 13 | + */ |
| 14 | +class MapsLocation { |
| 15 | + |
| 16 | + /** |
| 17 | + * @since 0.7.1 |
| 18 | + * |
| 19 | + * @var string |
| 20 | + */ |
| 21 | + protected $address; |
| 22 | + |
| 23 | + /** |
| 24 | + * @since 0.7.1 |
| 25 | + * |
| 26 | + * @var float |
| 27 | + */ |
| 28 | + protected $latitude; |
| 29 | + |
| 30 | + /** |
| 31 | + * @since 0.7.1 |
| 32 | + * |
| 33 | + * @var float |
| 34 | + */ |
| 35 | + protected $longitude; |
| 36 | + |
| 37 | + |
| 38 | + /** |
| 39 | + * @since 0.7.1 |
| 40 | + * |
| 41 | + * @var boolean |
| 42 | + */ |
| 43 | + protected $isValid = false; |
| 44 | + |
| 45 | + |
| 46 | + /** |
| 47 | + * @since 0.7.1 |
| 48 | + * |
| 49 | + * @var string Element of the Maps_COORDS_ enum |
| 50 | + */ |
| 51 | + protected $format; |
| 52 | + |
| 53 | + /** |
| 54 | + * @since 0.7.1 |
| 55 | + * |
| 56 | + * @var boolean |
| 57 | + */ |
| 58 | + protected $directional; |
| 59 | + |
| 60 | + /** |
| 61 | + * @since 0.7.1 |
| 62 | + * |
| 63 | + * @var string |
| 64 | + */ |
| 65 | + protected $separator; |
| 66 | + |
| 67 | + |
| 68 | + /** |
| 69 | + * Constructor. |
| 70 | + * |
| 71 | + * @since 0.7.1 |
| 72 | + */ |
| 73 | + public function construct( $coordsOrAddress = null, $format = Maps_COORDS_FLOAT, $directional = false, $separator = ',' ) { |
| 74 | + $this->format = $format; |
| 75 | + $this->directional = $directional; |
| 76 | + $this->separator = $separator; |
| 77 | + |
| 78 | + if ( !is_null( $coordsOrAddress ) ) { |
| 79 | + if ( MapsCoordinateParser::areCoordinates( $coordsOrAddress ) ) { |
| 80 | + $this->setCoordinates( $coordsOrAddress ); |
| 81 | + } |
| 82 | + else { |
| 83 | + $this->setAddress( $coordsOrAddress ); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Sets the location to a set of coordinates. You can provide a string |
| 90 | + * of raw coordinates, an array with lat and lon values and false. |
| 91 | + * |
| 92 | + * @since 0.7.1 |
| 93 | + * |
| 94 | + * @param mixed $coordinates |
| 95 | + * |
| 96 | + * @return boolean Success indicator |
| 97 | + */ |
| 98 | + public function setCoordinates( $coordinates ) { |
| 99 | + $coordSet = MapsCoordinateParser::parseCoordinates( $coordinates ); |
| 100 | + $this->isValid = $coordSet !== false; |
| 101 | + |
| 102 | + $this->latitude = $coordSet['lat']; |
| 103 | + $this->longitude = $coordSet['lon']; |
| 104 | + |
| 105 | + return $this->isValid; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Sets the location to an address. |
| 110 | + * |
| 111 | + * @since 0.7.1 |
| 112 | + * |
| 113 | + * @param string $address |
| 114 | + * @param boolean $asActualLocation When set to false, the location is not changed, only the address string is. |
| 115 | + * |
| 116 | + * @return boolean Success indicator |
| 117 | + */ |
| 118 | + public function setAddress( $address, $asActualLocation = true ) { |
| 119 | + if ( $asActualLocation ) { |
| 120 | + $this->setCoordinates( MapsGeocoder::geocode( $address ) ); |
| 121 | + } |
| 122 | + |
| 123 | + $this->address = $address; |
| 124 | + |
| 125 | + return $this->isValid; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Returns if the location is valid. |
| 130 | + * |
| 131 | + * @since 0.7.1 |
| 132 | + * |
| 133 | + * @return boolean |
| 134 | + */ |
| 135 | + public function isValid() { |
| 136 | + return $this->isValid; |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * Returns the locations latitude. |
| 141 | + * |
| 142 | + * @since 0.7.1 |
| 143 | + * |
| 144 | + * @return float |
| 145 | + */ |
| 146 | + public function getLatitude() { |
| 147 | + if ( !$this->isValid() ) { |
| 148 | + throw new Exception( 'Attempt to get the latitude of an invalid location' ); |
| 149 | + } |
| 150 | + return $this->latitude; |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Returns the locations longitude. |
| 155 | + * |
| 156 | + * @since 0.7.1 |
| 157 | + * |
| 158 | + * @return float |
| 159 | + */ |
| 160 | + public function getLongitude() { |
| 161 | + if ( !$this->isValid() ) { |
| 162 | + throw new Exception( 'Attempt to get the longitude of an invalid location' ); |
| 163 | + } |
| 164 | + return $this->longitude; |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Returns the locations coordinates formatted in the specified notation. |
| 169 | + * |
| 170 | + * @since 0.7.1 |
| 171 | + * |
| 172 | + * @param string $format Element of the Maps_COORDS_ enum |
| 173 | + * @param boolean $directional |
| 174 | + * @param string $separator |
| 175 | + * |
| 176 | + * @return string |
| 177 | + */ |
| 178 | + public function getCoordinates( $format = null, $directional = null, $separator = null ) { |
| 179 | + if ( !$this->isValid() ) { |
| 180 | + throw new Exception( 'Attempt to get the coordinates for an invalid location' ); |
| 181 | + } |
| 182 | + return MapsCoordinateParser::formatCoordinates( |
| 183 | + array( 'lat' => $this->latitude, 'lon' => $this->longitude ), |
| 184 | + is_null( $format ) ? $this->format : $format, |
| 185 | + is_null( $directional ) ? $this->directional : $directional, |
| 186 | + is_null( $separator ) ? $this->separator : $separator |
| 187 | + ); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * Returns the address corresponding to this location. |
| 192 | + * If there is none, and empty sting is returned. |
| 193 | + * |
| 194 | + * @since 0.7.1 |
| 195 | + * |
| 196 | + * @param boolean $geocodeIfEmpty |
| 197 | + * |
| 198 | + * @return string |
| 199 | + */ |
| 200 | + public function getAddress( $geocodeIfEmpty = true ) { |
| 201 | + if ( !$this->isValid() ) { |
| 202 | + throw new Exception( 'Attempt to get the address of an invalid location' ); |
| 203 | + } |
| 204 | + |
| 205 | + if ( is_null( $this->address ) ) { |
| 206 | + if ( $geocodeIfEmpty ) { |
| 207 | + // TODO: attempt to reverse-geocode |
| 208 | + } |
| 209 | + |
| 210 | + $this->address = ''; |
| 211 | + } |
| 212 | + |
| 213 | + return $this->address; |
| 214 | + } |
| 215 | + |
| 216 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/includes/Maps_Location.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 217 | + native |