Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php |
— | — | @@ -174,7 +174,7 @@ |
175 | 175 | } |
176 | 176 | } |
177 | 177 | else { // If a centre value is set, geocode when needed and use it. |
178 | | - $this->centre = MapsGeocodeUtils::attemptToGeocode( $this->centre, $this->geoservice, $this->serviceName ); |
| 178 | + $this->centre = MapsGeocoder::attemptToGeocode( $this->centre, $this->geoservice, $this->serviceName ); |
179 | 179 | |
180 | 180 | // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde. |
181 | 181 | if ( $this->centre ) { |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | $this->centre_lon = $egMapsMapLon; |
75 | 75 | } |
76 | 76 | else { // If a centre value is set, geocode when needed and use it. |
77 | | - $this->coordinates = MapsGeocodeUtils::attemptToGeocode( $this->coordinates, $this->geoservice, $this->serviceName ); |
| 77 | + $this->coordinates = MapsGeocoder::attemptToGeocode( $this->coordinates, $this->geoservice, $this->serviceName ); |
78 | 78 | |
79 | 79 | // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde. |
80 | 80 | if ( $this->coordinates ) { |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php |
— | — | @@ -165,7 +165,7 @@ |
166 | 166 | $coordinates = explode( $delimeter, $coordList ); |
167 | 167 | |
168 | 168 | foreach ( $coordinates as $coordinate ) { |
169 | | - if ( MapsGeocodeUtils::isCoordinate( $coordinate ) ) { |
| 169 | + if ( MapsCoordinateParser::areCoordinates( $coordinate ) ) { |
170 | 170 | $validCoordinates[] = $coordinate; |
171 | 171 | } |
172 | 172 | else { |
— | — | @@ -226,7 +226,7 @@ |
227 | 227 | $args[0] = trim( $args[0] ); |
228 | 228 | |
229 | 229 | if ( strlen( $args[0] ) > 0 ) { |
230 | | - $coords = MapsGeocodeUtils::attemptToGeocode( $args[0], $geoservice, $service, $isDefault ); |
| 230 | + $coords = MapsGeocoder::attemptToGeocode( $args[0], $geoservice, $service, $isDefault ); |
231 | 231 | |
232 | 232 | if ( $coords ) { |
233 | 233 | $args[0] = $coords; |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | 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>.'; |
35 | 35 | } |
36 | 36 | else { |
37 | | - define( 'Maps_VERSION', '0.5.5' ); |
| 37 | + define( 'Maps_VERSION', '0.5.6' ); |
38 | 38 | |
39 | 39 | $egMapsScriptPath = ( isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/Maps'; |
40 | 40 | $egMapsDir = dirname( __FILE__ ) . '/'; |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | $wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks'; |
53 | 53 | |
54 | 54 | // Autoload the general classes |
| 55 | + $wgAutoloadClasses['MapsCoordinateParser'] = $egMapsDir . 'Maps_CoordinateParser.php'; |
55 | 56 | $wgAutoloadClasses['MapsMapFeature'] = $egMapsDir . 'Maps_MapFeature.php'; |
56 | 57 | $wgAutoloadClasses['MapsMapper'] = $egMapsDir . 'Maps_Mapper.php'; |
57 | 58 | $wgAutoloadClasses['MapsUtils'] = $egMapsDir . 'Maps_Utils.php'; |
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMCgiBin.php |
— | — | @@ -101,19 +101,26 @@ |
102 | 102 | |
103 | 103 | $center = array( $this->lon, $this->lat ); |
104 | 104 | if ( $this->options['sphericalMercator'] ) { |
105 | | - // Calculate bounds within a spherical mercator projection if that is what the scale is based on |
| 105 | + // Calculate bounds within a spherical mercator projection if that is what the scale is based on. |
106 | 106 | $mercatorCenter = MapsUtils::forwardMercator( $center ); |
107 | | - $mbounds = array( |
108 | | - $mercatorCenter[0] - $w_deg / 2, |
109 | | - $mercatorCenter[1] - $h_deg / 2, |
110 | | - $mercatorCenter[0] + $w_deg / 2, |
111 | | - $mercatorCenter[1] + $h_deg / 2 |
| 107 | + |
| 108 | + $this->bounds = MapsUtils::inverseMercator( |
| 109 | + array( |
| 110 | + $mercatorCenter[0] - $w_deg / 2, |
| 111 | + $mercatorCenter[1] - $h_deg / 2, |
| 112 | + $mercatorCenter[0] + $w_deg / 2, |
| 113 | + $mercatorCenter[1] + $h_deg / 2 |
| 114 | + ) |
112 | 115 | ); |
113 | | - $this->bounds = MapsUtils::inverseMercator( $mbounds ); |
114 | 116 | } |
115 | 117 | else { |
116 | 118 | // Calculate bounds within WGS84 |
117 | | - $this->bounds = array( $center[0] - $w_deg / 2, $center[1] - $h_deg / 2, $center[0] + $w_deg / 2, $center[1] + $h_deg / 2 ); |
| 119 | + $this->bounds = array( |
| 120 | + $center[0] - $w_deg / 2, |
| 121 | + $center[1] - $h_deg / 2, |
| 122 | + $center[0] + $w_deg / 2, |
| 123 | + $center[1] + $h_deg / 2 |
| 124 | + ); |
118 | 125 | } |
119 | 126 | } |
120 | 127 | |
Index: trunk/extensions/Maps/Maps_Utils.php |
— | — | @@ -45,10 +45,10 @@ |
46 | 46 | * @param $deg_coord |
47 | 47 | * @return unknown_type |
48 | 48 | */ |
49 | | - private static function convertCoord( $deg_coord = "" ) { |
| 49 | + private static function convertCoord( $deg_coord = '' ) { |
50 | 50 | if ( preg_match ( '/°/', $deg_coord ) ) { |
51 | 51 | if ( preg_match ( '/"/', $deg_coord ) ) { |
52 | | - return MapsUtils::degree2Decimal ( $deg_coord ); |
| 52 | + return MapsUtils::DMSToDecimal ( $deg_coord ); |
53 | 53 | } else { |
54 | 54 | return MapsUtils::decDegree2Decimal ( $deg_coord ); |
55 | 55 | } |
— | — | @@ -58,23 +58,29 @@ |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * |
| 62 | + * |
62 | 63 | * @param $deg_coord |
63 | 64 | * @return unknown_type |
64 | 65 | */ |
65 | | - private static function degree2Decimal( $deg_coord = "" ) { |
66 | | - $dpos = strpos ( $deg_coord, '°' ); |
67 | | - $mpos = strpos ( $deg_coord, '.' ); |
68 | | - $spos = strpos ( $deg_coord, '"' ); |
69 | | - $mlen = ( ( $mpos - $dpos ) - 1 ); |
70 | | - $slen = ( ( $spos - $mpos ) - 1 ); |
71 | | - $direction = substr ( strrev ( $deg_coord ), 0, 1 ); |
72 | | - $degrees = substr ( $deg_coord, 0, $dpos ); |
73 | | - $minutes = substr ( $deg_coord, $dpos + 1, $mlen ); |
74 | | - $seconds = substr ( $deg_coord, $mpos + 1, $slen ); |
| 66 | + private static function DMSToDecimal( $dmsCoordinates = '' ) { |
| 67 | + $degreePosition = strpos( $dmsCoordinates, '°' ); |
| 68 | + $minutePosition = strpos( $dmsCoordinates, '.' ); |
| 69 | + $secondPosition = strpos( $dmsCoordinates, '"' ); |
| 70 | + |
| 71 | + $minuteLength = $minutePosition - $degreePosition - 1; |
| 72 | + $secondLength = $secondPosition - $minutePosition - 1; |
| 73 | + |
| 74 | + $direction = substr ( strrev ( $dmsCoordinates ), 0, 1 ); |
| 75 | + |
| 76 | + $degrees = substr ( $dmsCoordinates, 0, $dpos ); |
| 77 | + $minutes = substr ( $dmsCoordinates, $dpos + 1, $mlen ); |
| 78 | + $seconds = substr ( $dmsCoordinates, $mpos + 1, $slen ); |
| 79 | + |
75 | 80 | $seconds = ( $seconds / 60 ); |
76 | 81 | $minutes = ( $minutes + $seconds ); |
77 | 82 | $minutes = ( $minutes / 60 ); |
78 | 83 | $decimal = ( $degrees + $minutes ); |
| 84 | + |
79 | 85 | // South latitudes and West longitudes need to return a negative result |
80 | 86 | if ( $direction == "S" || $direction == "W" ) { |
81 | 87 | $decimal *= - 1; |
— | — | @@ -150,7 +156,7 @@ |
151 | 157 | /** |
152 | 158 | * Convert from WGS84 to spherical mercator. |
153 | 159 | */ |
154 | | - public static function forwardMercator( $lonlat ) { |
| 160 | + public static function forwardMercator( array $lonlat ) { |
155 | 161 | for ( $i = 0; $i < count( $lonlat ); $i += 2 ) { |
156 | 162 | /* lon */ |
157 | 163 | $lonlat[$i] = $lonlat[$i] * ( 2 * M_PI * 6378137 / 2.0 ) / 180.0; |
— | — | @@ -165,7 +171,7 @@ |
166 | 172 | /** |
167 | 173 | * Convert from spherical mercator to WGS84. |
168 | 174 | */ |
169 | | - public static function inverseMercator( $lonlat ) { |
| 175 | + public static function inverseMercator( array $lonlat ) { |
170 | 176 | for ( $i = 0; $i < count( $lonlat ); $i += 2 ) { |
171 | 177 | /* lon */ |
172 | 178 | $lonlat[$i] = $lonlat[$i] / ( ( 2 * M_PI * 6378137 / 2.0 ) / 180.0 ); |
Index: trunk/extensions/Maps/Maps_CoordinateParser.php |
— | — | @@ -74,12 +74,10 @@ |
75 | 75 | |
76 | 76 | $coordinates = self::resolveAngles( $coordinates ); |
77 | 77 | |
78 | | - $coordinates = array( |
| 78 | + return array( |
79 | 79 | 'lat' => self::parseCoordinate( $coordinates['lat'], $coordsType ), |
80 | 80 | 'lon' => self::parseCoordinate( $coordinates['lon'], $coordsType ), |
81 | 81 | ); |
82 | | - |
83 | | - return $floatCoordinates; |
84 | 82 | } |
85 | 83 | |
86 | 84 | /** |
— | — | @@ -109,6 +107,25 @@ |
110 | 108 | } |
111 | 109 | } |
112 | 110 | |
| 111 | + /** |
| 112 | + * Returns a boolean indicating if the provided value is a valid set of coordinate. |
| 113 | + * |
| 114 | + * @param string $coordsOrAddress |
| 115 | + * |
| 116 | + * @return boolean |
| 117 | + */ |
| 118 | + public static function areCoordinates( $coordsOrAddress ) { |
| 119 | + return self::getCoordinatesType( $coordsOrAddress ) !== false; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Returns the coordinate parsed in the given notation. |
| 124 | + * |
| 125 | + * @param string $coordinate |
| 126 | + * @param coordinate type $coordType |
| 127 | + * |
| 128 | + * @return string |
| 129 | + */ |
113 | 130 | private static function parseCoordinate( $coordinate, $coordType ) { |
114 | 131 | switch ( $coordType ) { |
115 | 132 | case COORDS_FLOAT: |
Index: trunk/extensions/Maps/Geocoders/Maps_GeocodeUtils.php |
— | — | @@ -1,72 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * MapsGeocodeUtils holds static functions to geocode values when needed. |
6 | | - * |
7 | | - * @file Maps_GeocodeUtils.php |
8 | | - * @ingroup Maps |
9 | | - * |
10 | | - * @author Jeroen De Dauw |
11 | | - */ |
12 | | - |
13 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
14 | | - die( 'Not an entry point.' ); |
15 | | -} |
16 | | - |
17 | | -final class MapsGeocodeUtils { |
18 | | - /** |
19 | | - * This function first determines wether the provided string is a pair or coordinates |
20 | | - * or an address. If it's the later, an attempt to geocode will be made. The function will |
21 | | - * return the coordinates or false, in case a geocoding attempt was made but failed. |
22 | | - * |
23 | | - * @param $coordsOrAddress |
24 | | - * @param $geoservice |
25 | | - * @param $service |
26 | | - * |
27 | | - * @return string or boolean |
28 | | - */ |
29 | | - public static function attemptToGeocode( $coordsOrAddress, $geoservice, $service, $checkForCoords = true ) { |
30 | | - if ( $checkForCoords ) { |
31 | | - if ( MapsGeocodeUtils::isCoordinate( $coordsOrAddress ) ) { |
32 | | - $coords = $coordsOrAddress; |
33 | | - } |
34 | | - else { |
35 | | - $coords = MapsGeocoder::geocodeToString( $coordsOrAddress, $geoservice, $service ); |
36 | | - } |
37 | | - } |
38 | | - else { |
39 | | - $coords = MapsGeocoder::geocodeToString( $coordsOrAddress, $geoservice, $service ); |
40 | | - } |
41 | | - |
42 | | - return $coords; |
43 | | - } |
44 | | - |
45 | | - /** |
46 | | - * Returns a boolean indication if a provided value is a valid coordinate. |
47 | | - * |
48 | | - * @param string $coordsOrAddress |
49 | | - * |
50 | | - * @return boolean |
51 | | - */ |
52 | | - public static function isCoordinate( $coordsOrAddress ) { |
53 | | - $coordRegexes = array( |
54 | | - '/^(-)?\d{1,3}(\.\d{1,20})?,(\s)?(-)?\d{1,3}(\.\d{1,20})?$/', // Floats |
55 | | - '/^(\d{1,3}°)(\d{1,2}(\′|\'))?((\d{1,2}(″|"))?|(\d{1,2}\.\d{1,2}(″|"))?)(N|S)(\s)?(\d{1,3}°)(\d{1,2}(\′|\'))?((\d{1,2}(″|"))?|(\d{1,2}\.\d{1,2}(″|"))?)(E|W)$/', // DMS |
56 | | - '/^(-)?\d{1,3}(|\.\d{1,20})°,(\s)?(-)?(\s)?\d{1,3}(|\.\d{1,20})°$/', // DD |
57 | | - '/^\d{1,3}(|\.\d{1,20})°(\s)?(N|S),(\s)?(\s)?\d{1,3}(|\.\d{1,20})°(\s)(E|W)?$/', // DD (directional) |
58 | | - '/(-)?\d{1,3}°\d{1,3}(\.\d{1,20}\')?,(\s)?(-)?\d{1,3}°\d{1,3}(\.\d{1,20}\')?$/', // DM |
59 | | - ); |
60 | | - |
61 | | - $isCoordinate = false; |
62 | | - |
63 | | - foreach ( $coordRegexes as $coordRegex ) { |
64 | | - if ( preg_match( $coordRegex, trim( $coordsOrAddress ) ) ) { |
65 | | - $isCoordinate = true; |
66 | | - continue; |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - return $isCoordinate; |
71 | | - } |
72 | | - |
73 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Maps/Geocoders/Maps_Geocoders.php |
— | — | @@ -31,7 +31,6 @@ |
32 | 32 | |
33 | 33 | $wgAutoloadClasses['MapsBaseGeocoder'] = $egMapsDir . 'Geocoders/Maps_BaseGeocoder.php'; |
34 | 34 | $wgAutoloadClasses['MapsGeocoder'] = $egMapsDir . 'Geocoders/Maps_Geocoder.php'; |
35 | | - $wgAutoloadClasses['MapsGeocodeUtils'] = $egMapsDir . 'Geocoders/Maps_GeocodeUtils.php'; |
36 | 35 | } |
37 | 36 | |
38 | 37 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/Geocoders/Maps_Geocoder.php |
— | — | @@ -32,6 +32,26 @@ |
33 | 33 | private static $mGeocoderCache = array(); |
34 | 34 | |
35 | 35 | /** |
| 36 | + * This function first determines wether the provided string is a pair or coordinates |
| 37 | + * or an address. If it's the later, an attempt to geocode will be made. The function will |
| 38 | + * return the coordinates or false, in case a geocoding attempt was made but failed. |
| 39 | + * |
| 40 | + * @param string $coordsOrAddress |
| 41 | + * @param string $geoservice |
| 42 | + * @param string $service |
| 43 | + * @param boolean $checkForCoords |
| 44 | + * |
| 45 | + * @return string or boolean |
| 46 | + */ |
| 47 | + public static function attemptToGeocode( $coordsOrAddress, $geoservice, $service, $checkForCoords = true ) { |
| 48 | + if ( $checkForCoords && MapsCoordinateParser::areCoordinates( $coordsOrAddress ) ) { |
| 49 | + return $coordsOrAddress; |
| 50 | + } else { |
| 51 | + return self::geocodeToString( $coordsOrAddress, $geoservice, $service ); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
36 | 56 | * Geocodes an address with the provided geocoding service and returns the result |
37 | 57 | * as a string with the optionally provided format, or false when the geocoding failed. |
38 | 58 | * |