http://www.mediawiki.org/wiki/Special:Code/MediaWiki/66298

Revision: 66298
Author:   jeroendedauw
Date:     2010-05-12 21:01:28 +0000 (Wed, 12 May 2010)

Log Message:
-----------
Added support for several distance units

Modified Paths:
--------------
    trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php
    trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php

Removed Paths:
-------------
    trunk/extensions/SemanticMaps/GeoCoords/SM_DistanceValue.php

Modified: trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php
===================================================================
--- trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php 
2010-05-12 21:00:27 UTC (rev 66297)
+++ trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php 
2010-05-12 21:01:28 UTC (rev 66298)
@@ -28,6 +28,28 @@
        public function __construct( SMGeoCoordsValue $dataValue, $radius ) {
                parent::__construct( $dataValue, SM_CMP_NEAR ); 
 
+               // Parse the radius to the actual value and the optional unit.
+               $radius = preg_replace('/\s\s+/', ' ', $radius);
+               $parts = explode( ' ', $radius );
+               $radius = (float)array_shift( $parts );
+               
+               // If there is a unit, find it's ratio and apply it to the 
radius value.
+               if ( count( $parts ) > 0 ) {
+                       $unit = strtolower( implode( ' ', $parts ) );
+                       
+                       $ratio = array(
+                               'km' => 1000,
+                               'mile' => 1609.344,
+                               'miles' => 1609.344,
+                               'nautical mile' => 1852,
+                               'nautical miles' => 1852,
+                       );                      
+                       
+                       if ( array_key_exists( $unit, $ratio ) ) {
+                               $radius = $radius * $ratio[$unit];
+                       }
+               }
+               
                // If the MapsGeoFunctions class is not loaded, we can not 
create the bounding box,
                // so don't add any conditions.
                if ( self::geoFunctionsAreAvailable() ) {
@@ -38,7 +60,7 @@
                                        'lat' => $dbKeys[0],
                                        'lon' => $dbKeys[1]
                                ),
-                               $radius * 1000
+                               $radius
                        );
                }
        }

Deleted: trunk/extensions/SemanticMaps/GeoCoords/SM_DistanceValue.php
===================================================================
--- trunk/extensions/SemanticMaps/GeoCoords/SM_DistanceValue.php        
2010-05-12 21:00:27 UTC (rev 66297)
+++ trunk/extensions/SemanticMaps/GeoCoords/SM_DistanceValue.php        
2010-05-12 21:01:28 UTC (rev 66298)
@@ -1 +0,0 @@
-<?php

Modified: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
===================================================================
--- trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php       
2010-05-12 21:00:27 UTC (rev 66297)
+++ trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php       
2010-05-12 21:01:28 UTC (rev 66298)
@@ -88,7 +88,7 @@
                        $distance = count( $parts ) > 0 ? trim( array_shift( 
$parts ) ) : false;
 
                        if ( $distance !== false ) {
-                               if ( preg_match( '/^\d+(\.\d+)?\)$/', $distance 
) ) {
+                               if ( preg_match( '/^\d+(\.\d+)?(\s.+)\)$/', 
$distance ) ) {
                                        $distance = substr( $distance, 0, -1 );
                                }
                                else {



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to