Show
Ignore:
Timestamp:
12/05/07 20:32:14 (13 months ago)
Author:
gyuque
Message:

lang/actionscript/swfgmap: loading additional tiles and unloading.

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

Legend:

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

    r2485 r2496  
    2121                         
    2222                        var T:Matrix = new Matrix(); 
    23                         T.rotate(0.2); 
     23                        T.rotate(0.9); 
    2424                        vp.setTransform(T); 
    2525                        setViewport(vp); 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/GMapView.as

    r2485 r2496  
    7474                protected function addGoogleMapLayer():Boolean 
    7575                { 
    76                         var lyr:GMapMapLayer = new GMapMapLayer(this); 
     76                        var lyr:GMapMapLayer = new GMapMapLayer(this, mSuperLayer); 
    7777                        lyr.debug_out = this; 
    7878                        mSuperLayer.push(lyr); 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/GridHash.as

    r2454 r2496  
    44        { 
    55                private var mHash:Object; 
     6                private var mItCursor:int; 
     7                 
    68                public function GridHash() 
    79                { 
     
    1416                } 
    1517                 
    16                 public function poke(x:int, y:int, dat:int):void 
     18                public function poke(x:int, y:int, dat:*):void 
    1719                { 
    1820                        mHash[makeKey(x, y)] = dat; 
    1921                } 
    2022 
    21                 public function peek(x:int, y:int):int 
     23                public function peek(x:int, y:int):Object 
    2224                { 
    2325                        return mHash[makeKey(x, y)] || 0; 
     
    2830                        mHash = {}; 
    2931                } 
     32                 
     33                public function map(proc:Function, _this:Object):void 
     34                { 
     35                        for each(var v:int in mHash) 
     36                                proc.apply(_this, [v]); 
     37                } 
    3038        } 
    3139} 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/IMeshMap.as

    r2485 r2496  
    33        import flash.geom.Point; 
    44         
    5         public interface IMeshMap 
     5        public interface IMeshMap extends IPanningLayer 
    66        { 
    7                 function getCurrentPanning(out:Point)  :void; 
    87                function get centerTileX()             :int; 
    98                function get centerTileY()             :int; 
    10                 function resetPanning(tx:int, ty:int)  :void; 
     9                function resetOffset(tx:int, ty:int)  :void; 
    1110                function setTileOffset(ox:int, oy:int) :void; 
    1211                function loadTile(tx:int, ty:int)      :void; 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/Layer.as

    r2413 r2496  
    1212                protected var mLastDX:Number; 
    1313                protected var mLastDY:Number; 
     14                protected var mParent:Layer; 
    1415                 
    15                 public function Layer(eventSrc:EventDispatcher) 
     16                public function Layer(eventSrc:EventDispatcher, parent:Layer) 
    1617                { 
    1718                        eventSrc.addEventListener(GMapViewEvent.VIEWPORT_CHANGED, onViewportChanged); 
     19                        mParent = parent; 
    1820                } 
    1921                 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/LayerManager.as

    r2485 r2496  
    11package gyuque.gmap 
    22{ 
    3         public class LayerManager extends Layer 
     3        public class LayerManager extends Layer implements IPanningLayer 
    44        { 
    55                import flash.display.*; 
    6                 import flash.geom.Matrix; 
     6                import flash.geom.*; 
    77                 
    88                private var mLayers:Array = new Array(); 
     9                private var mPanPos:Point = new Point(); 
    910                 
    1011                public function LayerManager(c:DisplayObjectContainer) 
    1112                { 
    12                         super(c); 
     13                        super(c, null); 
    1314                } 
    1415                 
     
    2728                        M.ty = transform.matrix.ty; 
    2829                         
     30                        M.tx = v.width  * 0.5; 
     31                        M.ty = v.height * 0.5; 
    2932                        if (refreshAll) 
    3033                        { 
    31                                 M.tx = v.width  * 0.5; 
    32                                 M.ty = v.height * 0.5; 
     34                                 
     35                                mPanPos.x = 0; 
     36                                mPanPos.y = 0; 
    3337                        } 
    3438                        else 
    3539                        { 
    36                                 M.tx += mLastDX; 
    37                                 M.ty += mLastDY; 
     40                                mPanPos.x += mLastDX; 
     41                                mPanPos.y += mLastDY; 
    3842                        } 
     43                        M.tx += mPanPos.x; 
     44                        M.ty += mPanPos.y; 
     45                         
    3946                        transform.matrix = M; 
     47                } 
     48                 
     49                public function getCurrentPanning(out:Point):void 
     50                { 
     51                        mViewport.transformVectorScreenToView(mPanPos.x, mPanPos.y, out); 
    4052                } 
    4153        } 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/ViewportUpdater.as

    r2485 r2496  
    1515                private var mReqQueue:XYQueue; 
    1616                private var mUpdateTimer:Timer; 
     17 
     18                private var mLoadedTiles:XYQueue; 
    1719                 
    1820                public function ViewportUpdater(listener:IMeshMap) 
     
    2123                        mGHash = new GridHash(); 
    2224                        mReqQueue = new XYQueue(); 
    23                          
    24                         mUpdateTimer = new Timer(100);  
     25                        mLoadedTiles = new XYQueue(); 
     26                         
     27                        mUpdateTimer = new Timer(80);  
    2528                        mUpdateTimer.addEventListener(TimerEvent.TIMER, onTimer); 
    2629                        mUpdateTimer.start(); 
     
    3538                                if (prev == null) 
    3639                                        refresh(); 
     40                                else 
     41                                        update(); 
    3742                        } 
    3843                } 
     
    4045                private function onTimer(e:Event):void 
    4146                { 
    42                         if (mReqQueue.empty) 
    43                                 return; 
    44                                  
    45                         var j:Object = {}; 
    46                         mReqQueue.consume(j); 
    47                         switch(j.v) 
    48                         { 
    49                         case 1: // load 
    50                                 checkAndLoad(j.x, j.y); 
    51                                 break; 
     47                        update(); 
     48                                 
     49                        for (var i:int = 0;i < 2;i++) 
     50                        { 
     51                                if (mReqQueue.empty) 
     52                                        return; 
     53dout.puts("tiles:"+ mLoadedTiles.length +"  queue:"+mReqQueue.length); 
     54                                 
     55                                var j:Object = {}; 
     56                                mReqQueue.consume(j); 
     57                                switch(j.v) 
     58                                { 
     59                                case 1: // load 
     60                                        checkAndLoad(j.x, j.y); 
     61                                        break; 
     62                                case 2: // load 
     63                                        checkAndUnload(j.x, j.y); 
     64                                        break; 
     65                                } 
    5266                        } 
    5367                } 
     
    7993                                if (nest == 0) 
    8094                                { 
    81                                         if (isTileVisible(x, y) != T_INVISIBLE) 
     95                                        if (isTileVisible(x, y) == T_VISIBLE) 
    8296                                        { 
    8397                                                retval = true; 
     
    89103                        } 
    90104                         
    91                          
    92                          
    93105                        return retval; 
    94106                } 
    95107                 
     108                private function isGoneOut(tx:int, ty:int):Boolean 
     109                { 
     110                        return (isTileVisible(tx, ty) == T_INVISIBLE); 
     111                } 
     112                 
    96113                private function checkAndLoad(tx:int, ty:int):void 
    97114                { 
    98115                        if (mGHash.peek(tx, ty)) 
     116                        { 
    99117                                mListener.loadTile(tx, ty); 
    100                 } 
    101                  
     118                                mLoadedTiles.push(tx, ty, 1); 
     119                        } 
     120                } 
     121 
     122                private function checkAndUnload(tx:int, ty:int):void 
     123                { 
     124                        if (!mGHash.peek(tx, ty)) 
     125                                mListener.unloadTile(tx, ty); 
     126                } 
     127 
    102128                private function addLoadJob(tx:int, ty:int):void 
    103129                { 
     
    106132                                mGHash.poke(tx, ty, 1); 
    107133                                mReqQueue.push(tx, ty, 1); 
    108  
    109                                 dout.puts((tx-29095)+", "+(ty-12855)); 
    110                         } 
     134                        } 
     135                } 
     136 
     137                private function addUnloadJob(tx:int, ty:int):void 
     138                { 
     139                        if (mGHash.peek(tx, ty)) 
     140                        { 
     141                                mGHash.poke(tx, ty, 0); 
     142                                mReqQueue.push(tx, ty, 2); 
     143                        } 
     144                } 
     145                 
     146                private function update():void 
     147                { 
     148         
     149                        var j:Object = {}; 
     150                        var nextArr:XYQueue = new XYQueue(); 
     151                        var len:int = mLoadedTiles.length; 
     152 
     153                        for (;!mLoadedTiles.empty;) 
     154                        { 
     155                                mLoadedTiles.consume(j); 
     156                                if (isGoneOut(j.x, j.y)) 
     157                                        addUnloadJob(j.x, j.y); 
     158                                else 
     159                                { 
     160                                        nextArr.push(j.x, j.y, j.v); 
     161                                        spread(j.x, j.y, 0); 
     162                                } 
     163                        } 
     164                         
     165                        mLoadedTiles = nextArr; 
    111166                } 
    112167                 
     
    116171                        var tiledata:Object = GMapCalc.calcTileData(v.centerNX, v.centerNY, v.zoom, 0); 
    117172 
    118                         mListener.resetPanning(tiledata.tile_index.x, tiledata.tile_index.y); 
     173                        mListener.resetOffset(tiledata.tile_index.x, tiledata.tile_index.y); 
    119174                        mListener.setTileOffset(tiledata.offset.x, tiledata.offset.y); 
    120175                         
     
    142197                        mCurViewport.transformVectorViewToScreen(bx, by, p); 
    143198                         
    144                         var padding:Number = GMapCalc.TILE_SIZE*0.7; 
     199                        var padding:Number = GMapCalc.TILE_SIZE*1.2; 
    145200                        for (var i:int = 0;i < 2;i++) { 
    146201                        if (p.x >= (-mCurViewport.width*0.5 - padding) && p.y >= (-mCurViewport.height*0.5 - padding) && p.x < (mCurViewport.width*0.5 + padding) && p.y < (mCurViewport.height*0.5 + padding)) 
     
    171226        } 
    172227         
     228        public function get length():int 
     229        { 
     230                return Xs.length; 
     231        } 
     232 
     233        public function at(out:Object, i:int):void 
     234        { 
     235                out.x = Xs[i]; 
     236                out.y = Ys[i]; 
     237                out.v = Vs[i]; 
     238        } 
     239         
    173240        public function get empty():Boolean 
    174241        { 
  • lang/actionscript/swfgmap/trunk/gyuque/gmap/googlemaps/GMapMapLayer.as

    r2485 r2496  
    1212                protected var mCenterTX:int; 
    1313                protected var mCenterTY:int; 
     14                protected var mLoadedTiles:GridHash = new GridHash(); 
    1415                 
    1516                public function set debug_out(d:IDebugOut):void 
     
    1819                } 
    1920                 
    20                 public function GMapMapLayer(eventSrc:EventDispatcher) 
     21                public function GMapMapLayer(eventSrc:EventDispatcher, parent:Layer) 
    2122                { 
    22                         super(eventSrc); 
     23                        super(eventSrc, parent); 
    2324                        mVPobs = new ViewportUpdater(this); 
    2425                         
     
    6061                        tile.x = -c + otx*GMapCalc.TILE_SIZE; 
    6162                        tile.y = -c + oty*GMapCalc.TILE_SIZE; 
     63                         
     64                        mLoadedTiles.poke(tx, ty, tile); 
    6265                } 
    6366                 
    6467                public function unloadTile(tx:int, ty:int):void 
    6568                { 
     69                        var o:Object = mLoadedTiles.peek(tx, ty); 
     70                        if (o) 
     71                        { 
     72                                removeChild( DisplayObject(o) ); 
     73                        } 
    6674                } 
    6775                 
    68                 public function resetPanning(tx:int, ty:int):void 
     76                public function resetOffset(tx:int, ty:int):void 
    6977                { 
    7078                        mCenterTX = tx; 
     
    7482                public function getCurrentPanning(out:Point):void 
    7583                { 
    76                         out.x = x; 
    77                         out.y = y; 
     84                        if (parent && parent is IPanningLayer) 
     85                        { 
     86                                IPanningLayer(parent).getCurrentPanning(out); 
     87                        } 
     88                        else 
     89                        { 
     90                                out.x = 0; 
     91                                out.y = 0; 
     92                        } 
     93 
     94                        out.x += x; 
     95                        out.y += y; 
     96                         
    7897                } 
    7998