Changeset 634

Show
Ignore:
Timestamp:
07/24/08 12:43:20 (1 month ago)
Author:
allens
Message:

Added normalize() method for keeping Location objects within bounds. Note: This method returns a new Location instance.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/tom-tweenlite/lib/com/modestmaps/geo/Location.as

    r595 r634  
    3131            } 
    3232 
     33        /** 
     34         * This function normalizes latitude and longitude values to a sensible range 
     35         * (±84°N, ±180°E), and returns a new Location instance. 
     36         */ 
     37        public function normalize():Location 
     38        { 
     39            var loc:Location = clone(); 
     40            loc.lat = Math.max(-84, Math.min(84, loc.lat)); 
     41            while (loc.lon > 180) loc.lon -= 360; 
     42            while (loc.lon < -180) loc.lon += 360; 
     43            return loc; 
     44        } 
     45 
    3346            public function toString(precision:int=5):String 
    3447            { 
    3548                return [lat.toFixed(precision), lon.toFixed(precision)].join(','); 
    3649            } 
    37  
    3850        } 
    3951}