flash on 2012-7-18
♥0 |
Line 27 |
Modified 2012-07-18 16:52:40 |
MIT License
archived:2017-03-20 05:46:22
ActionScript3 source code
/**
* Copyright Gleb.Panteleew ( http://wonderfl.net/user/Gleb.Panteleew )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/8pHj
*/
package {
import flash.text.TextField;
import flash.geom.Point;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var tf:TextField = new TextField()
tf.height = 500;
tf.width = 500;
tf.appendText(worldToTilePos(46.555,38.5235,11));
addChild(tf);
}
public function worldToTilePos(lon:Number, lat:Number, zoom:int){
var p:Point = new Point();
p.x = ((lon + 180.0) / 360.0 * (1 << zoom));
p.y = ((1.0 - Math.log(Math.tan(lat * Math.PI / 180.0) + 1.0 / Math.cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * (1 << zoom));
return p;
}
public function tileToWorldPos(tile_x:Number, tile_y:Number, zoom:int) {
var p:Point = new Point();
var n:Number = Math.PI - ((2.0 * Math.PI * tile_y) / Math.pow(2.0, zoom));
p.x = ((tile_x / Math.pow(2.0, zoom) * 360.0) - 180.0);
p.y = (180.0 / Math.PI * Math.atan(Math.sin(n)));
return p;
}
}
}