Changeset 179

Show
Ignore:
Timestamp:
03/18/07 19:31:26 (2 years ago)
Author:
darren
Message:

added masking to yahoo clips
changed TileGrid.tileHeight/tileWidth to a public constant
changed LoadMovieThrottledRequest? to fire complete event on Init instead of Complete

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/as2/lib/com/modestmaps/core/Tile.as

    r177 r179  
    133133        if(!grid.paintingAllowed()) 
    134134            return; 
    135  
    136         DispatchableInterface(grid.mapProvider).addEventObserver( this, AbstractMapProvider.EVENT_PAINT_COMPLETE, "onPaintComplete" ); 
    137  
     135                 
    138136        // cancel existing call, if any... 
    139137        if(__paintCall) 
     
    155153         
    156154        // set up the proper clip to paint here 
     155                DispatchableInterface(grid.mapProvider).addEventObserver( this, AbstractMapProvider.EVENT_PAINT_COMPLETE, "onPaintComplete" ); 
    157156         
    158157        var clipId : Number = this.getNextHighestDepth(); 
     
    182181                { 
    183182                        dcCoord = Coordinate( __displayClips[i].coord ); 
     183                                                 
    184184                        if ( dcCoord.equalTo( this.coord ) ) 
    185185                                        break; 
     
    192192                } 
    193193                 
    194               dispatchEvent( EVENT_PAINT_COMPLETE ); 
     194                      dispatchEvent( EVENT_PAINT_COMPLETE ); 
    195195        }        
    196196    }    
  • trunk/as2/lib/com/modestmaps/core/TileGrid.as

    r177 r179  
    1919class com.modestmaps.core.TileGrid extends MovieClip 
    2020{ 
     21    // Real maps use 256. 
     22    public static var TILE_WIDTH : Number = 256; 
     23    public static var TILE_HEIGHT : Number = 256; 
     24 
    2125    private var map:Map; 
    2226 
     
    3640    private var __overlappingMarkers:Object; 
    3741 
    38     // Real maps use 256. 
    39     public var tileWidth:Number = 256; 
    40     public var tileHeight:Number = 256; 
    41      
    4242    // Allow (true) or prevent (false) tiles to paint themselves. 
    4343    private var __paintingAllowed:Boolean; 
     
    131131        {  
    132132            grid: this,  
    133             width: tileWidth,  
    134             height: tileHeight
     133            width: TILE_WIDTH,  
     134            height: TILE_HEIGHT
    135135            coord: coord 
    136136        }; 
     
    164164        {  
    165165            grid: this,  
    166             width: tileWidth,  
    167             height: tileHeight
     166            width: TILE_WIDTH,  
     167            height: TILE_HEIGHT
    168168            coord: initTileCoord 
    169169        }; 
     
    354354             
    355355        } else { 
    356             point.x += tileWidth * (coord.column - tile.coord.column); 
     356            point.x += TILE_WIDTH * (coord.column - tile.coord.column); 
    357357         
    358358        } 
     
    362362             
    363363        } else { 
    364             point.y += tileHeight * (coord.row - tile.coord.row); 
     364            point.y += TILE_HEIGHT * (coord.row - tile.coord.row); 
    365365 
    366366        } 
     
    408408         
    409409        // distance in tile widths from reference tile to point 
    410         var xTiles:Number = (point.x - tile._x) / tileWidth
    411         var yTiles:Number = (point.y - tile._y) / tileHeight
     410        var xTiles:Number = (point.x - tile._x) / TILE_WIDTH
     411        var yTiles:Number = (point.y - tile._y) / TILE_HEIGHT
    412412 
    413413        // distance in rows & columns at maximum zoom 
     
    660660        var wellHeight:Number = (100 / well._yscale) * height; 
    661661 
    662         var targetCols:Number = Math.ceil(wellWidth  / tileWidth)  + 1 + 2 * tileBuffer; 
    663         var targetRows:Number = Math.ceil(wellHeight / tileHeight) + 1 + 2 * tileBuffer; 
     662        var targetCols:Number = Math.ceil(wellWidth  / TILE_WIDTH)  + 1 + 2 * tileBuffer; 
     663        var targetRows:Number = Math.ceil(wellHeight / TILE_HEIGHT) + 1 + 2 * tileBuffer; 
    664664 
    665665        // grid can't drop below 1 x 1 
     
    748748             
    749749            for(var i:Number = 1; i < active.length; i += 1) { 
    750                 active[i]._x = active[0]._x + (active[i].coord.column - active[0].coord.column) * tileWidth
    751                 active[i]._y = active[0]._y + (active[i].coord.row    - active[0].coord.row)    * tileHeight
     750                active[i]._x = active[0]._x + (active[i].coord.column - active[0].coord.column) * TILE_WIDTH
     751                active[i]._y = active[0]._y + (active[i].coord.row    - active[0].coord.row)    * TILE_HEIGHT
    752752             
    753753                //log(active[i].toString()+' at '+active[i]._x+', '+active[i]._y+' vs. '+active[0].toString()); 
     
    842842                newTile.coord = newTile.coord.down(); 
    843843 
    844             newTile._x = referenceTile._x + (xOffset * tileWidth / 2); 
    845             newTile._y = referenceTile._y + (yOffset * tileHeight / 2); 
     844            newTile._x = referenceTile._x + (xOffset * TILE_WIDTH / 2); 
     845            newTile._y = referenceTile._y + (yOffset * TILE_HEIGHT / 2); 
    846846 
    847847            newTile._xscale = newTile._yscale = referenceTile._xscale / 2; 
     
    923923        well.globalToLocal(point); // all tiles are attached to well 
    924924         
    925         var xMin:Number = point.x - (1 + tileBuffer) * tileWidth
    926         var yMin:Number = point.y - (1 + tileBuffer) * tileHeight
     925        var xMin:Number = point.x - (1 + tileBuffer) * TILE_WIDTH
     926        var yMin:Number = point.y - (1 + tileBuffer) * TILE_HEIGHT
    927927         
    928928        point = new Point(width, height); 
     
    930930        well.globalToLocal(point); // all tiles are attached to well 
    931931         
    932         var xMax:Number = point.x + (0 + tileBuffer) * tileWidth
    933         var yMax:Number = point.y + (0 + tileBuffer) * tileHeight
     932        var xMax:Number = point.x + (0 + tileBuffer) * TILE_WIDTH
     933        var yMax:Number = point.y + (0 + tileBuffer) * TILE_HEIGHT
    934934         
    935935        for(var i:Number = 0; i < active.length; i += 1) { 
     
    944944                // too far up 
    945945                tile.panDown(rows); 
    946                 tile._y += rows * tileHeight
     946                tile._y += rows * TILE_HEIGHT
    947947                touched = true; 
    948948 
    949949            } else if(tile._y > yMax) { 
    950950                // too far down 
    951                 if((tile._y - rows * tileHeight) > yMin) { 
     951                if((tile._y - rows * TILE_HEIGHT) > yMin) { 
    952952                    // moving up wouldn't put us too far 
    953953                    tile.panUp(rows); 
    954                     tile._y -= rows * tileHeight
     954                    tile._y -= rows * TILE_HEIGHT
    955955                    touched = true; 
    956956                } 
     
    960960                // too far left 
    961961                tile.panRight(columns); 
    962                 tile._x += columns * tileWidth
     962                tile._x += columns * TILE_WIDTH
    963963                touched = true; 
    964964 
    965965            } else if(tile._x > xMax) { 
    966966                // too far right 
    967                 if((tile._x - columns * tileWidth) > xMin) { 
     967                if((tile._x - columns * TILE_WIDTH) > xMin) { 
    968968                    // moving left wouldn't put us too far 
    969969                    tile.panLeft(columns); 
    970                     tile._x -= columns * tileWidth
     970                    tile._x -= columns * TILE_WIDTH
    971971                    touched = true; 
    972972                } 
     
    10181018            newTileParams = {grid:  lastTile.grid,  coord:  lastTile.coord.down(), 
    10191019                             _x:    lastTile._x,    _y:     lastTile._y + lastTile.height, 
    1020                              width: tileWidth,      height: tileHeight}; 
     1020                             width: TILE_WIDTH,      height: TILE_HEIGHT}; 
    10211021 
    10221022            createTile(newTileParams); 
     
    10581058            newTileParams = {grid:  lastTile.grid,                  coord:  lastTile.coord.right(), 
    10591059                             _x:    lastTile._x + lastTile.width,   _y:     lastTile._y, 
    1060                              width: tileWidth,                      height: tileHeight}; 
     1060                             width: TILE_WIDTH,                     height: TILE_HEIGHT}; 
    10611061 
    10621062            createTile(newTileParams); 
  • trunk/as2/lib/com/modestmaps/io/LoadMovieThrottledRequest.as

    r177 r179  
    6161        // Event Handlers 
    6262         
    63         private function onLoadComplete( clip : MovieClip, httpStatus : Number ) : Void 
     63        private function onLoadInit( clip : MovieClip, httpStatus : Number ) : Void 
    6464        { 
    6565                dispatchEvent( ThrottledRequest.EVENT_RESPONSE_COMPLETE, clip, url ); 
  • trunk/as2/lib/com/modestmaps/Map.as

    r177 r179  
    126126 
    127127        // initial tile position, assuming centered tile well in grid 
    128         var initX:Number = (initTileCoord.column - centerCoord.column) * grid.tileWidth
    129         var initY:Number = (initTileCoord.row - centerCoord.row) * grid.tileHeight
     128        var initX:Number = (initTileCoord.column - centerCoord.column) * TileGrid.TILE_WIDTH
     129        var initY:Number = (initTileCoord.row - centerCoord.row) * TileGrid.TILE_HEIGHT
    130130        var initPoint:Point = new Point(Math.round(initX), Math.round(initY)); 
    131131         
     
    157157 
    158158        // multiplication factor between horizontal span and map width 
    159         var hFactor:Number = (BR.column - TL.column) / (__width / grid.tileWidth); 
     159        var hFactor:Number = (BR.column - TL.column) / (__width / TileGrid.TILE_WIDTH); 
    160160         
    161161        // multiplication factor expressed as base-2 logarithm, for zoom difference 
     
    166166         
    167167        // multiplication factor between vertical span and map height 
    168         var vFactor:Number = (BR.row - TL.row) / (__height / grid.tileHeight); 
     168        var vFactor:Number = (BR.row - TL.row) / (__height / TileGrid.TILE_HEIGHT); 
    169169         
    170170        // multiplication factor expressed as base-2 logarithm, for zoom difference 
  • trunk/as2/lib/com/modestmaps/mapproviders/AbstractMapProvider.as

    r176 r179  
    8888        private function raisePaintComplete( clip : MovieClip, coord : Coordinate ) : Void 
    8989        { 
    90                 dispatchEvent( EVENT_PAINT_COMPLETE, clip, coord ); 
     90                dispatchEvent( AbstractMapProvider.EVENT_PAINT_COMPLETE, clip, coord ); 
    9191        } 
    9292     
  • trunk/as2/lib/com/modestmaps/mapproviders/yahoo/AbstractYahooMapProvider.as

    r177 r179  
    11import com.modestmaps.core.Coordinate; 
     2import com.modestmaps.core.TileGrid; 
    23import com.modestmaps.geo.MercatorProjection; 
    34import com.modestmaps.geo.Transformation; 
     
    2425        } 
    2526 
     27        /** 
     28         * Yahoo clips are 258x258 to deal with Flash pixel fudge, we mask and offset them by 
     29         * one pixel so they show up correctly. 
     30         */ 
     31        public function paint( clip : MovieClip, coord : Coordinate ) : Void  
     32        { 
     33                super.paint( clip, coord ); 
     34 
     35            clip.image._x = clip.image._y = -1; 
     36                createMask( clip );              
     37        } 
     38 
     39 
    2640    public function sourceCoordinate(coord:Coordinate):Coordinate 
    2741    { 
     
    3347        return new Coordinate(coord.row, wrappedColumn, coord.zoom); 
    3448    } 
     49     
     50    private function createMask( clip : MovieClip ) : Void 
     51    { 
     52            var mask : MovieClip = clip.createEmptyMovieClip( "mask", clip.getNextHighestDepth() ); 
     53            with ( mask ) 
     54            { 
     55                moveTo(0, 0); 
     56                //lineStyle( 1, 0x000000 ); 
     57                beginFill(0x000000, 100); 
     58                lineTo(0, TileGrid.TILE_HEIGHT); 
     59                lineTo(TileGrid.TILE_WIDTH, TileGrid.TILE_HEIGHT); 
     60                lineTo(TileGrid.TILE_WIDTH, 0); 
     61                lineTo(0, 0); 
     62                endFill(0, 0); 
     63            } 
     64            clip.setMask( mask );        
     65    } 
    3566} 
  • trunk/as2/lib/com/modestmaps/mapproviders/yahoo/YahooHybridMapProvider.as

    r176 r179  
    1818        } 
    1919         
     20        /** 
     21         * Yahoo clips are 258x258 to deal with Flash pixel fudge, we mask and offset them by 
     22         * one pixel so they show up correctly. 
     23         */ 
    2024        public function paint( clip : MovieClip, coord : Coordinate ) : Void  
    2125        { 
     
    3539                request.send(); 
    3640                 
    37                 //createLabel( clip, coord.toString() ); 
     41                clip.bg._x = clip.bg._y = -1; 
     42                clip.overlay._x = clip.overlay._y = -1; 
     43 
     44                createMask( clip );              
    3845        }        
    3946 
     
    5966        }        
    6067 
     68        private function isClipLoaded( clip : MovieClip ) : Boolean 
     69        { 
     70                return ( clip.getBytesTotal() > 0 && clip.getBytesLoaded() == clip.getBytesTotal() ); 
     71        } 
     72 
    6173        // Event Handlers 
    6274         
    6375        private function onResponseComplete( clip : MovieClip, coordinate : Coordinate ) : Void 
    6476        { 
    65                 if ( clip.bg._loaded && clip.overlay._loaded ) 
     77                // HAKT 
     78                var bgClip : MovieClip = clip._parent.bg; 
     79                var overlayClip : MovieClip = clip._parent.overlay; 
     80                 
     81                if ( isClipLoaded( bgClip ) && isClipLoaded( overlayClip ) ) 
     82                { 
    6683                        raisePaintComplete( clip._parent, coordinate ); 
     84                } 
    6785        } 
    6886}