/* Code written and owned by Chris Youderian All code is licensed under the GPLv2. This means that any derivate works that you create using this code must be released under the same license. If you wish to use this code in a product you want to resell, you need to ask for permission. Contact form available at: http://www.flashworldmap.com/contactus.php See original posting at: http://www.flashmap.org/robinson-projection-in-as3-gpl/ */ import flash.geom.*; var long:Number=0; //longitude...x-axis var lat:Number=90; //latitude...y-axis var earth_rad:Number=1; //Replace this number as described in directions // var earth_rad:Number=6378100; //The earth's true radius. //The above is useful to verify code with output at http://spatialreference.org/ref/esri/54030/ ; const AA:Array = [ 0.8487, 0.84751182, 0.84479598, 0.840213, 0.83359314, 0.8257851, 0.814752, 0.80006949, 0.78216192, 0.76060494, 0.73658673, 0.7086645, 0.67777182, 0.64475739, 0.60987582, 0.57134484, 0.52729731, 0.48562614, 0.45167814, ]; const BB:Array = [0, 0.0838426, 0.1676852, 0.2515278, 0.3353704, 0.419213, 0.5030556, 0.5868982, 0.67182264, 0.75336633, 0.83518048, 0.91537187, 0.99339958, 1.06872269, 1.14066505, 1.20841528, 1.27035062, 1.31998003, 1.3523, ]; project(long, lat, new Point()); function project(long:Number, lat:Number, xy:Point):Point { var long_sign:Number = 1; var lat_sign:Number = 1; //deals with negatives if (long<0){long_sign=-1;} if (lat<0){lat_sign=-1;} //deals with negatives long = Math.abs(long); lat = Math.abs(lat); //all calculations positive if (long<0){long_sign=-1;} if (lat<0){lat_sign=-1;} //transform back later var radian:Number = 0.017453293; // pi/180 var low = roundToNearest(5, lat-.0000000001); //want exact numbers to round down if (lat == 0) {low = 0}; //except when at 0 var high = low + 5; var low_index = low/5; //low index used for interpolation var high_index = high/5; //high index used for interpolation var ratio:Number = (lat-low)/5; var pt1:Point = new Point(); //interpolation in one dimension var adj_AA:Number = ((AA[high_index]-AA[low_index])*ratio)+AA[low_index]; var adj_BB:Number = ((BB[high_index]-BB[low_index])*ratio)+BB[low_index]; //Formula from Robinson xy.x = adj_AA * long * radian; xy.x = xy.x*long_sign*earth_rad; xy.y = adj_BB; xy.y = (xy.y*lat_sign*earth_rad); trace(xy); return xy; } function roundToNearest(roundTo:Number, value:Number):Number{ return Math.floor(value/roundTo)*roundTo; //rounds down }