Show
Ignore:
Timestamp:
12/06/07 21:51:12 (13 months ago)
Author:
gyuque
Message:

lang/actionscript/swfgmap: implemented rotation

Location:
lang/actionscript/swfgmap/trunk
Files:
1 added
9 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/swfgmap/trunk/TestApp.as

    r2650 r2665  
    55        import gyuque.gmap.*; 
    66        import gyuque.gmap.ui.Spinner; 
     7        import mx.events.SliderEvent; 
    78 
    89        public class TestApp extends GMapView 
    910        { 
     11                private var mSpnr:Spinner; 
    1012                public function TestApp() 
    1113                { 
     
    2022                         
    2123                        var vp:GMapViewport = new GMapViewport(36.09992, 139.65497, 640, 480, 15); 
    22                          
    23                          
    24                         var T:Matrix = new Matrix(); 
    25                         T.rotate(0.9); 
    26                         vp.setTransform(T); 
    2724                        setViewport(vp); 
    2825 
    2926                        var spnr:Spinner = new Spinner(64); 
    3027                        addChild(spnr); 
     28                        spnr.addEventListener(SliderEvent.THUMB_DRAG , onSpinner); 
     29                         
    3130                        spnr.x = 8; 
    3231                        spnr.y = 8; 
     32                        mSpnr = spnr; 
     33                } 
     34                 
     35                protected function onSpinner(e:SliderEvent):void 
     36                { 
     37                        mCurrentViewport.setNewRotation(mSpnr.value); 
     38                        fireViewportChange(); 
    3339                } 
    3440        } 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/GMapCalc.as

    r2452 r2665  
    5252                        return Math.pow(2, zoom+8);              
    5353                } 
     54 
     55                public static function calcMapTileCols(zoom:int):int 
     56                { 
     57                        return Math.pow(2, zoom);                
     58                } 
    5459                 
    5560                public static function calcTileData(x:Number, y:Number, zoom:int, layer:int):Object 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/GMapView.as

    r2650 r2665  
    1717                private var mBaseSprite:Sprite; 
    1818                private var mSuperLayer:LayerManager; 
    19                 private var mCurrentViewport:GMapViewport; 
     19                protected var mCurrentViewport:GMapViewport; 
    2020                 
    2121                public function GMapView(options:*) 
     
    3939                                fmtDebugOut = new TextFormat(); 
    4040                                fmtDebugOut.size = 9; 
    41                                 txDebugOut.height = height; 
     41                                txDebugOut.y = 90; 
     42                                txDebugOut.height = height-90; 
    4243                                txDebugOut.width = 600; 
    4344                        } 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/GMapViewport.as

    r2637 r2665  
    6565                        mInvViewToScreen = M.clone(); 
    6666                        mInvViewToScreen.invert(); 
     67                } 
     68                 
     69                public function setNewRotation(r:Number):void 
     70                { 
     71                        var T:Matrix = new Matrix(); 
     72                        T.rotate(r); 
     73                        setTransform(T);                         
    6774                } 
    6875                 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/LayerManager.as

    r2528 r2665  
    77                 
    88                private var mLayers:Array = new Array(); 
    9                 private var mPanPos:Point = new Point(); 
    109                 
    1110                public function LayerManager(c:DisplayObjectContainer) 
     
    5453                        M.tx = v.width  * 0.5; 
    5554                        M.ty = v.height * 0.5; 
    56                         if (refreshAll) 
    57                         { 
    58                                 mPanPos.x = 0; 
    59                                 mPanPos.y = 0; 
    60                         } 
    61                         else 
    62                         { 
    63                                 mPanPos.x += mLastDX; 
    64                                 mPanPos.y += mLastDY; 
    65                         } 
    66                         M.tx -= mPanPos.x; 
    67                         M.ty -= mPanPos.y; 
    6855                         
    6956                        transform.matrix = M; 
     
    7259                public function getCurrentPanning(out:Point):void 
    7360                { 
    74                         mViewport.transformVectorScreenToView(mPanPos.x, mPanPos.y, out); 
     61                        out.x = 0; 
     62                        out.y = 0; 
     63                        //mViewport.transformVectorScreenToView(mPanPos.x, mPanPos.y, out); 
    7564                } 
    7665        } 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/googlemaps/GMapMapLayer.as

    r2637 r2665  
    2828                         
    2929                        var g:Graphics = graphics; 
    30  
     30/* 
    3131                        g.beginFill(0xf5f0e9); 
    3232                        g.drawRect(-384, -128, 768, 256); 
     
    3737                        g.drawRect(-128, -128, 256, 256); 
    3838                        g.endFill(); 
    39                          
     39*/                       
    4040                        _I=I++; 
    4141                } 
     
    5757                        mViewport = v;           
    5858                        mVPobs.currentViewport = mViewport; 
     59                         
     60                        if (e.screenDX || e.screenDY) 
     61                        { 
     62                                var p:Point = new Point(); 
     63                                mViewport.transformVectorScreenToView(e.screenDX, e.screenDY, p); 
     64                                x -= p.x; 
     65                                y -= p.y; 
     66                        } 
    5967                } 
    6068 
     
    9098                public function loadTile(tx:int, ty:int):void 
    9199                { 
    92                         var tile:GMapMapTile = new GMapMapTile(tx, ty, GMapCalc.calcMapsZoomIndex(mViewport.zoom)); 
     100                        var tile:GMapMapTile = new GMapMapTile(tx, ty, mViewport.zoom); 
    93101                        tile.addEventListener(IOErrorEvent.IO_ERROR, onIOError); 
    94102//mVPobs.dout.puts(tile.url); 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/googlemaps/GMapMapTile.as

    r2528 r2665  
    44        import flash.events.*; 
    55        import flash.net.URLRequest; 
     6        import gyuque.gmap.GMapCalc; 
    67         
    78        public class GMapMapTile extends Loader 
    89        { 
    9                 public var mTileURL:String; 
     10                public var mTileURL:String = null; 
    1011                public function GMapMapTile(tx:int, ty:int, z:int) 
    1112                { 
     13                        var cols:int = GMapCalc.calcMapTileCols(z); 
     14                        if (ty < 0 || ty >= cols) 
     15                                return; 
     16                        if (tx < 0) 
     17                                tx += cols * 100; 
     18                         
    1219                        var server_index:int = tx%4; 
    13                         mTileURL = "http://mt"+server_index+".google.com/mt?n=404&v=ap.63&x="+tx+"&y="+ty+"&zoom="+z; 
     20                        tx %= cols; 
     21                        ty %= cols; 
     22                        mTileURL = "http://mt"+server_index+".google.com/mt?n=404&v=ap.63&x="+tx+"&y="+ty+"&zoom="+GMapCalc.calcMapsZoomIndex(z); 
    1423                } 
    1524                 
     
    2130                public function loadTile():Loader 
    2231                { 
     32                        if (!mTileURL) 
     33                                return this; 
     34                         
    2335                        var req:URLRequest = new URLRequest(mTileURL); 
    2436                        load(req); 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/ui/Spinner.as

    r2650 r2665  
    22{ 
    33        import flash.display.*; 
     4        import flash.events.*; 
    45        import flash.geom.Matrix; 
     6        import mx.events.SliderEvent; 
    57         
    68        public class Spinner extends Sprite 
     
    810                private var mSize:int; 
    911                private var mBaseRing:Sprite; 
     12                private var mCursor:Sprite; 
    1013                 
    1114                private var mRGradColors:Array; 
     
    1316                private var mRGradRatios:Array; 
    1417                private var mRGradMatrix:Matrix; 
     18                 
     19                private var mValue:Number; 
     20                 
     21                private var mDrag:DragData = new DragData(); 
    1522                 
    1623                public function Spinner(sz:int) 
     
    2027                        mRGradRatios = [150, 180 , 200, 255]; 
    2128                        mRGradMatrix = new Matrix(); 
    22                         mRGradMatrix.createGradientBox(sz*1.05, sz*1.05, 0, -sz*0.05, -sz*0.05); 
     29                        mRGradMatrix.createGradientBox(sz*1.05, sz*1.05, 0, -sz*0.06, -sz*0.06); 
    2330                         
    2431                        mSize = sz; 
    2532                        mBaseRing = new Sprite(); 
    26                         drawBaseRing(mBaseRing.graphics); 
     33                        mCursor = new Sprite(); 
     34                        drawBaseRing(mBaseRing.graphics, mCursor.graphics, graphics); 
     35                        mBaseRing.addChild(mCursor); 
     36                        mCursor.x = sz/2; 
     37                        mCursor.y = sz/2; 
     38                        mCursor.mouseEnabled = false; 
    2739                         
    2840                        addChild(mBaseRing); 
     41                         
     42                        mBaseRing.addEventListener(MouseEvent.MOUSE_MOVE , onRingMouseMove); 
     43                        mBaseRing.addEventListener(MouseEvent.MOUSE_DOWN , onRingMouseDown); 
     44                        mBaseRing.addEventListener(MouseEvent.MOUSE_UP   , onRingMouseUp); 
     45                        mBaseRing.addEventListener(MouseEvent.MOUSE_OUT  , onRingMouseOut); 
     46                         
     47                        mValue = 0; 
    2948                } 
    3049                 
    31                 private function drawBaseRing(g:Graphics):void 
     50                protected function onRingMouseMove(e:MouseEvent):void 
     51                { 
     52                        e.stopPropagation(); 
     53                         
     54                        if (mDrag.dragging) { 
     55                                mDrag.update(e.localX - mSize/2, e.localY - mSize/2); 
     56                                 
     57                                mValue += mDrag.dRad; 
     58                                var se:SliderEvent = new SliderEvent(SliderEvent.THUMB_DRAG, false, false, -1, mValue); 
     59                                dispatchEvent(se); 
     60                                updateCursor(mValue); 
     61                        } 
     62                } 
     63                 
     64                public function set value(v:Number):void 
     65                { 
     66                        mValue = v; 
     67                        updateCursor(mValue); 
     68                } 
     69 
     70                public function get value():Number 
     71                { 
     72                        return mValue; 
     73                } 
     74                 
     75                protected function updateCursor(r:Number):void 
     76                { 
     77                        mCursor.rotation = r * 180 / Math.PI; 
     78                } 
     79 
     80                protected function onRingMouseDown(e:MouseEvent):void 
     81                { 
     82                        e.stopPropagation(); 
     83                         
     84                        mDrag.dragging = true; 
     85                        mDrag.update(e.localX - mSize/2, e.localY - mSize/2); 
     86                } 
     87                 
     88                protected function onRingMouseUp(e:MouseEvent):void 
     89                { 
     90                        e.stopPropagation(); 
     91 
     92                        mDrag.dragging = false; 
     93                } 
     94 
     95                protected function onRingMouseOut(e:MouseEvent):void 
     96                { 
     97                        e.stopPropagation(); 
     98 
     99                        mDrag.dragging = false; 
     100                } 
     101                 
     102                private function drawBaseRing(g:Graphics, c_g:Graphics, sh_g:Graphics):void 
    32103                { 
    33104                        var c:int = mSize/2; 
    34105 
    35                         g.beginFill(0, 0.2); 
    36                         g.lineStyle(1, 0xcccccc, 0.1); 
    37                         g.drawCircle(c+1, c+2, mSize/2); 
    38                         g.drawCircle(c+1, c+2, mSize/3.3); 
    39                         g.endFill(); 
     106                        sh_g.beginFill(0, 0.1); 
     107                        sh_g.lineStyle(1, 0, 0.1); 
     108                        sh_g.drawCircle(c+1, c+2, mSize/2); 
     109                        sh_g.drawCircle(c+1, c+2, mSize/3.6); 
     110                        sh_g.endFill(); 
    40111                         
    41112                        g.beginGradientFill(GradientType.RADIAL, mRGradColors, mRGradAlphas, mRGradRatios, mRGradMatrix); 
    42                         g.lineStyle(1, 0xcccccc); 
     113                        g.lineStyle(1, 0x999999); 
    43114                        g.drawCircle(c, c, mSize/2); 
    44                         g.drawCircle(c, c, mSize/3.3); 
     115                        g.drawCircle(c, c, mSize/3.6); 
    45116                        g.endFill(); 
     117 
     118                        for (var i:int = 0;i < 3;i++) 
     119                        { 
     120                                if (!i) { 
     121                                        c_g.beginFill(0, 0.2); 
     122                                        c_g.lineStyle(2, 0xcccccc, 0.4); 
     123                                } else { 
     124                                        c_g.beginFill(0xffffff, 0.26); 
     125                                        c_g.lineStyle(); 
     126                                } 
     127                                 
     128                                c_g.moveTo(0         , -mSize*0.44 ); 
     129                                c_g.lineTo( mSize*0.07,-mSize*0.44 + mSize*0.06); 
     130                                c_g.lineTo(-mSize*0.07,-mSize*0.44 + mSize*0.06); 
     131                                c_g.endFill(); 
     132                        } 
     133                 
    46134                } 
    47135        } 
    48136} 
     137 
     138class DragData 
     139{ 
     140        public var dragging:Boolean = false; 
     141        public var prevAngle:Number; 
     142        public var dRad:Number; 
     143        public var prevRad:Number; 
     144        public function update(x:Number, y:Number):void { 
     145                var r:Number = Math.atan2(y, x); 
     146                dRad = r - prevRad; 
     147                prevRad = r; 
     148        } 
     149} 
  • lang/actionscript/swfgmap/trunk/testapp.html

    r2454 r2665  
    55        <head> 
    66                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    7                 <title>TestApp</title> 
     7                <title>回るGoogle Maps</title> 
    88                <script src="http://maps.google.com/maps?file=api&amp;v=2"></script> 
    99                <script src="./helper-js/getTileVer.js"></script>