Changeset 41

Show
Ignore:
Timestamp:
01/16/07 19:59:33 (2 years ago)
Author:
migurski
Message:

Merged branch "migurski tile zooming" into branch "darren mapprovider prototype"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/mapproviders/AbstractMicrosoftMapProvider.as

    r34 r41  
    3636        {                
    3737                // convert row + col to zoom string 
    38                 var rowBinaryString : String = BinaryUtil.convertToBinary( tile.row );                 
    39                 rowBinaryString = rowBinaryString.substring( rowBinaryString.length - tile.zoom ); 
     38                var rowBinaryString : String = BinaryUtil.convertToBinary( tile.coord.row );           
     39                rowBinaryString = rowBinaryString.substring( rowBinaryString.length - tile.coord.zoom ); 
    4040                 
    41                 var colBinaryString : String = BinaryUtil.convertToBinary( tile.column ); 
    42                 colBinaryString = colBinaryString.substring( colBinaryString.length - tile.zoom ); 
     41                var colBinaryString : String = BinaryUtil.convertToBinary( tile.coord.column ); 
     42                colBinaryString = colBinaryString.substring( colBinaryString.length - tile.coord.zoom ); 
    4343 
    4444                // generate zoom string by combining strings 
    4545                var zoomString : String = ""; 
    46                 for ( var i : Number = 0; i < tile.zoom; i++ )  
     46                for ( var i : Number = 0; i < tile.coord.zoom; i++ )  
    4747                { 
    4848                        zoomString += BinaryUtil.convertToDecimal( rowBinaryString.charAt( i ) + colBinaryString.charAt( i ) ).toString(); 
  • branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/Tile.as

    r30 r41  
    22 
    33import com.modestmaps.core.Point; 
     4import com.modestmaps.core.Coordinate; 
    45import com.modestmaps.core.TileGrid; 
    56 
     
    910    public var grid:TileGrid; 
    1011 
     12    public var coord:Coordinate; 
     13     
     14    /* 
    1115    public var row:Number = 0; 
    1216    public var column:Number = 0; 
    1317    public var zoom:Number = 0; 
     18    */ 
    1419 
    1520    public var width:Number; 
     
    3742    public function zoomOut():Void 
    3843    { 
    39         zoom += 1; 
    40         column = Math.floor(column / 2); 
    41         row = Math.floor(row / 2); 
     44        coord = new Coordinate(Math.floor(coord.row / 2), Math.floor(coord.column / 2), coord.zoom + 1); 
    4245        redraw(); 
    4346    } 
     
    4548    public function zoomInTopLeft():Void 
    4649    { 
    47         zoom -= 1; 
    48         column *= 2; 
    49         row *= 2; 
     50        coord = new Coordinate(coord.row * 2, coord.column * 2, coord.zoom - 1); 
    5051        redraw(); 
    5152    } 
     
    5354    public function zoomInTopRight():Void 
    5455    { 
    55         zoom -= 1; 
    56         column *= 2; 
    57         column += 1; 
    58         row *= 2; 
     56        coord = new Coordinate(coord.row * 2, coord.column * 2 + 1, coord.zoom - 1); 
    5957        redraw(); 
    6058    } 
     
    6260    public function zoomInBottomLeft():Void 
    6361    { 
    64         zoom -= 1; 
    65         column *= 2; 
    66         row *= 2; 
    67         row += 1; 
     62        coord = new Coordinate(coord.row * 2 + 1, coord.column * 2, coord.zoom - 1); 
    6863        redraw(); 
    6964    } 
     
    7166    public function zoomInBottomRight():Void 
    7267    { 
    73         zoom -= 1; 
    74         column *= 2; 
    75         column += 1; 
    76         row *= 2; 
    77         row += 1; 
     68        coord = new Coordinate(coord.row * 2 + 1, coord.column * 2 + 1, coord.zoom - 1); 
    7869        redraw(); 
    7970    } 
     
    8172    public function panUp(distance:Number):Void 
    8273    { 
    83         row -= (distance ? distance : 1); 
     74        coord = coord.up(distance); 
    8475        redraw(); 
    8576    } 
     
    8778    public function panRight(distance:Number):Void 
    8879    { 
    89         column += (distance ? distance : 1); 
     80        coord = coord.right(distance); 
    9081        redraw(); 
    9182    } 
     
    9384    public function panDown(distance:Number):Void 
    9485    { 
    95         row += (distance ? distance : 1); 
     86        coord = coord.down(distance); 
    9687        redraw(); 
    9788    } 
     
    9990    public function panLeft(distance:Number):Void 
    10091    { 
    101         column -= (distance ? distance : 1); 
     92        coord = coord.left(distance); 
    10293        redraw(); 
    10394    } 
     
    10596    public function toString():String 
    10697    { 
    107         return row + ', ' + column + ' @' + zoom
     98        return 'Tile' + coord.toString()
    10899    } 
    109100 
  • branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/TileGrid.as

    r36 r41  
     1import com.modestmaps.core.Coordinate; 
    12import com.modestmaps.core.Bounds; 
    23import com.modestmaps.core.Point; 
     
    2324    private var tileHeight:Number = 256; 
    2425     
     26    // the currently-native zoom level 
     27    private var zoomLevel:Number; 
     28     
    2529    // some limits on scrolling distance, initially set to none 
    26     private var rowTop:Number = Number.NEGATIVE_INFINITY; 
    27     private var rowBottom:Number = Number.POSITIVE_INFINITY; 
    28     private var columnLeft:Number = Number.NEGATIVE_INFINITY; 
    29     private var columnRight:Number = Number.POSITIVE_INFINITY; 
     30    private var topLeftOutLimit:Coordinate; 
     31    private var bottomRightInLimit:Coordinate; 
    3032 
    3133    // Tiles attach to the well. 
     
    4749 
    4850    // Who do we get our Map graphics from? 
     51    public var mapProviderType:Number; 
    4952    private var __mapProvider : IMapProvider; 
    5053 
     
    5558    public function TileGrid() 
    5659    { 
    57         setMapProvider( MapProviders.MICROSOFT_AERIAL ); 
     60        setMapProvider(mapProviderType); 
    5861         
    5962        buildWell(); 
    6063        buildMask(); 
     64         
     65        // impose some limits 
     66        zoomLevel = 11; 
     67        topLeftOutLimit = new Coordinate(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, 0); 
     68        bottomRightInLimit = new Coordinate(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Coordinate.MAX_ZOOM); 
    6169         
    6270        // initial tile centers the map on the SF Bay Area 
     
    6775            width: tileWidth,  
    6876            height: tileHeight, 
    69             row: 791,  
    70             column: 328,  
    71             zoom: 11 
     77            coord: new Coordinate(791, 328, zoomLevel) 
    7278        }; 
    7379         
    74         var initialTile : Tile =  
    75             Tile( well.attachMovie( Tile.symbolName, 'tile'+well.getNextHighestDepth(), well.getNextHighestDepth(), initObj )); 
    76          
    77         initialTile.addEventObserver( this, "invalidated", "handleTileInvalidated" );    
    78         initialTile.redraw(); 
    79                  
    80         tiles = [initialTile]; 
     80        tiles = [createTile(initObj)]; 
    8181                                                                   
    8282        rows = 1; 
     
    9393         
    9494        log('FUCK YEAH '+width+'x'+height); 
    95          
    96         // TODO: 
    97         // Figure out why positionTiles() doesn't seem to work 
    98         // when called from here, even on a delay via the Reactor. 
    9995    } 
    10096     
     
    119115    } 
    120116     
     117   /** 
     118    * Create a new tile and return it, but don't add it to tiles array. 
     119    */ 
     120    private function createTile(tileParams:Object):Tile 
     121    { 
     122        var tile:Tile; 
     123 
     124        tile = Tile(well.attachMovie(Tile.symbolName, 'tile'+well.getNextHighestDepth(), well.getNextHighestDepth(), tileParams)); 
     125        tile.addEventObserver(this, "invalidated", "handleTileInvalidated"); 
     126        tile.redraw(); 
     127         
     128        return tile; 
     129    } 
     130     
     131   /** 
     132    * Destroy an old tile, but don't remove it from tiles array. 
     133    */ 
     134    private function destroyTile(tile:Tile):Void 
     135    { 
     136        tile.removeEventObserver(this, "invalidated", "handleTileInvalidated"); 
     137        tile.destroy(); 
     138        tile.removeMovieClip(); 
     139    } 
     140     
    121141    public function log(msg:String):Void 
    122142    { 
     
    124144    } 
    125145     
     146    public function clearLog():Void 
     147    { 
     148        label.text = ''; 
     149    } 
     150     
    126151    private function setMapProvider( mapProviderType : Number ) : Void 
    127152    { 
     153        this.mapProviderType = mapProviderType; 
    128154        var mapProviderFactory : MapProviderFactory = MapProviderFactory.getInstance(); 
    129155        __mapProvider = MapProviderFactory.getInstance().getMapProvider( mapProviderType );  
     
    140166     
    141167   /* 
    142     * Return the x, y position of a tile with the given row and column at the 
    143     * current zoom level (whether it exists on the stage or not) in the context 
    144     * of the given movie clip. 
     168    * Return the point position of a tile with the given coordinate in the 
     169    * context of the given movie clip. 
    145170    * 
    146171    * Respect infinite rows or columns, to bind movement on one (or no) axis. 
    147172    */ 
    148     private function tilePosition(row:Number, column:Number, context:MovieClip):Point 
    149     { 
    150         // get the position of the first tile, an arbitrary 
    151         // choice but known to exist regardless of grid size. 
    152         var point:Point = new Point(tiles[0]._x, tiles[0]._y); 
     173    private function coordinatePoint(coord:Coordinate, context:MovieClip):Point 
     174    { 
     175        // pick a reference tile, an arbitrary choice 
     176        // but known to exist regardless of grid size. 
     177        var tile:Tile = tiles[0]; 
     178     
     179        // get the position of the reference tile. 
     180        var point:Point = new Point(tile._x, tile._y); 
     181         
     182        // make sure coord is using the same zoom level 
     183        coord = coord.zoomTo(tile.coord.zoom); 
    153184         
    154185        // store the infinite 
    155186        var force:Point = new Point(0, 0); 
    156187         
    157         if(column == Infinity || column == -Infinity) { 
    158             force.x = column; 
     188        if(coord.column == Number.POSITIVE_INFINITY || coord.column == Number.NEGATIVE_INFINITY) { 
     189            force.x = coord.column; 
    159190             
    160191        } else { 
    161             point.x += tileWidth * (column - tiles[0].column); 
    162          
    163         } 
    164          
    165         if(row == Infinity || row == -Infinity) { 
    166             force.y = row; 
     192            point.x += tileWidth * (coord.column - tile.coord.column); 
     193         
     194        } 
     195         
     196        if(coord.row == Number.POSITIVE_INFINITY || coord.row == Number.NEGATIVE_INFINITY) { 
     197            force.y = coord.row; 
    167198             
    168199        } else { 
    169             point.y += tileHeight * (row - tiles[0].row); 
     200            point.y += tileHeight * (coord.row - tile.coord.row); 
    170201 
    171202        } 
     
    182213        return point; 
    183214    } 
     215     
     216    /* 
     217    private function pointCoordinate(point:Point):Coordinate 
     218    { 
     219        var tile:Tile; 
     220        var tileCoord:Coordinate; 
     221        var pointCoord:Coordinate; 
     222         
     223        // an arbitrary reference tile, zoomed to the maximum 
     224        tile = tiles[0]; 
     225        tileCoord = new Coordinate(tile.row, tile.column, tile.zoom); 
     226        tileCoord.zoomTo(Coordinate.MAX_ZOOM); 
     227         
     228        // distance in tile widths from reference tile to point 
     229        var xTiles:Number = (point.x - tile._x) / tileWidth; 
     230        var yTiles:Number = (point.y - tile._y) / tileHeight; 
     231         
     232        // distance in rows & columns at maximum zoom 
     233        var xDistance:Number = xTiles * Math.pow(2, (Coordinate.MAX_ZOOM - tile.zoom)); 
     234        var yDistance:Number = yTiles * Math.pow(2, (Coordinate.MAX_ZOOM - tile.zoom)); 
     235         
     236        // new point coordinate reflecting that distance 
     237        pointCoord = new Coordinate(Math.round(tileCoord.row + yDistance), 
     238                                    Math.round(tileCoord.column + xDistance), 
     239                                    tileCoord.zoom); 
     240         
     241        return pointCoord; 
     242    } 
     243    */ 
    184244     
    185245   /* 
     
    193253        // "min" = furthest well position left & up, 
    194254        // use the location of the bottom-right limit 
    195         min = tilePosition(rowBottom, columnRight, this); 
    196         min.x = well._x - min.x + width - tileWidth
    197         min.y = well._y - min.y + height - tileHeight
    198  
     255        min = coordinatePoint(bottomRightInLimit, this); 
     256        min.x = well._x - min.x + width
     257        min.y = well._y - min.y + height
     258         
    199259        // "max" = furthest well position right & down, 
    200260        // use the location of the top-left limit 
    201         max = tilePosition(rowTop, columnLeft, this); 
     261        max = coordinatePoint(topLeftOutLimit, this); 
    202262        max.x = well._x - max.x; 
    203263        max.y = well._y - max.y; 
     264         
     265        log('min/max for drag: '+min+', '+max+' ('+topLeftOutLimit+', '+bottomRightInLimit+')'); 
    204266         
    205267        // weird negative edge conditions, limit all movement on an axis 
     
    224286        // so we'll fudge it with some implausibly large numbers. 
    225287         
    226         var xMin:Number = (bounds.min.x == Infinity
     288        var xMin:Number = (bounds.min.x == Number.POSITIVE_INFINITY
    227289                            ? 100000 
    228                             : ((bounds.min.x == -Infinity
     290                            : ((bounds.min.x == Number.NEGATIVE_INFINITY
    229291                                ? -100000 
    230292                                : bounds.min.x); 
    231293         
    232         var yMin:Number = (bounds.min.y == Infinity
     294        var yMin:Number = (bounds.min.y == Number.POSITIVE_INFINITY
    233295                            ? 100000 
    234                             : ((bounds.min.y == -Infinity
     296                            : ((bounds.min.y == Number.NEGATIVE_INFINITY
    235297                                ? -100000 
    236298                                : bounds.min.y); 
    237299         
    238         var xMax:Number = (bounds.max.x == Infinity
     300        var xMax:Number = (bounds.max.x == Number.POSITIVE_INFINITY
    239301                            ? 100000 
    240                             : ((bounds.max.x == -Infinity
     302                            : ((bounds.max.x == Number.NEGATIVE_INFINITY
    241303                                ? -100000 
    242304                                : bounds.max.x); 
    243305         
    244         var yMax:Number = (bounds.max.y == Infinity
     306        var yMax:Number = (bounds.max.y == Number.POSITIVE_INFINITY
    245307                            ? 100000 
    246                             : ((bounds.max.y == -Infinity
     308                            : ((bounds.max.y == Number.NEGATIVE_INFINITY
    247309                                ? -100000 
    248310                                : bounds.max.y); 
     
    263325        centerWell(true); 
    264326    } 
     327     
     328    public function startZoomIn():Void 
     329    { 
     330        if(zoomLevel >= bottomRightInLimit.zoom && Math.round(well._xscale) >= 100) 
     331            return; 
     332     
     333        well._xscale *= Math.pow(2, .25); 
     334        well._yscale *= Math.pow(2, .25); 
     335         
     336        normalizeWell(); 
     337        allocateTiles(); 
     338        positionTiles(); 
     339         
     340        log('New well scale: '+well._xscale.toString()); 
     341    } 
     342     
     343    public function startZoomOut():Void 
     344    { 
     345        if(zoomLevel <= topLeftOutLimit.zoom && Math.round(well._xscale) <= 100) 
     346            return; 
     347     
     348        well._xscale /= Math.pow(2, .25); 
     349        well._yscale /= Math.pow(2, .25); 
     350         
     351        normalizeWell(); 
     352        allocateTiles(); 
     353        positionTiles(); 
     354         
     355        log('New well scale: '+well._xscale.toString()); 
     356    } 
    265357 
    266358   /* 
     
    313405    private function allocateTiles():Void 
    314406    { 
     407        // internal pixel dimensions of well, compensating for scale 
     408        var wellWidth:Number  = (100 / well._xscale) * width; 
     409        var wellHeight:Number = (100 / well._yscale) * height; 
     410 
     411        var targetCols:Number = Math.ceil(wellWidth  / tileWidth)  + 1 + 2 * tileBuffer; 
     412        var targetRows:Number = Math.ceil(wellHeight / tileHeight) + 1 + 2 * tileBuffer; 
     413 
    315414        // grid can't drop below 1 x 1 
    316         var targetCols:Number = Math.max(1, Math.ceil(width / tileWidth) + 1 + 2 * tileBuffer); 
    317         var targetRows:Number = Math.max(1, Math.ceil(height / tileHeight) + 1 + 2 * tileBuffer); 
     415        targetCols = Math.max(1, targetCols); 
     416        targetRows = Math.max(1, targetRows); 
    318417 
    319418        // change column count to match target 
     
    342441   /** 
    343442    * Adjust position of the well, so it stays in the center. 
    344     * Optionally, compensate tile positions to prevent visual 
    345     * discontinuity with respect to upper-left hand corner
     443    * Optionally, compensate tile positions to prevent 
     444    * visual discontinuity
    346445    */ 
    347446    private function centerWell(adjustTiles:Boolean):Void 
     
    351450        var xAdjustment:Number = well._x - center.x; 
    352451        var yAdjustment:Number = well._y - center.y; 
    353          
     452 
    354453        well._x -= xAdjustment; 
    355454        well._y -= yAdjustment; 
     
    357456        if(adjustTiles) { 
    358457            for(var i:Number = 0; i < tiles.length; i += 1) { 
    359                 tiles[i]._x += xAdjustment; 
    360                 tiles[i]._y += yAdjustment; 
    361             } 
    362         } 
     458                tiles[i]._x += xAdjustment * 100 / well._xscale; 
     459                tiles[i]._y += yAdjustment * 100 / well._xscale; 
     460            } 
     461        } 
     462    } 
     463     
     464   /** 
     465    * Adjust position and scale of the well, so it stays 
     466    * in the center and within reason.  Compensate tile 
     467    * zoom and positions to prevent visual discontinuity. 
     468    */ 
     469    private function normalizeWell():Void 
     470    { 
     471        var zoomAdjust:Number, scaleAdjust:Number; 
     472         
     473        // just in case? 
     474        centerWell(true); 
     475 
     476        if(Math.abs(well._xscale - 100) < 1) { 
     477            // set to 100% if within 99% - 101% 
     478            well._xscale = well._yscale = 100; 
     479             
     480            tiles.sort(compareTileRowColumn); 
     481             
     482            // lock the tiles back to round-pixel positions 
     483            tiles[0]._x = Math.round(tiles[0]._x); 
     484            tiles[0]._y = Math.round(tiles[0]._y); 
     485             
     486            for(var i:Number = 1; i < tiles.length; i += 1) { 
     487                tiles[i]._x = tiles[0]._x + (tiles[i].coord.column - tiles[0].coord.column) * tileWidth; 
     488                tiles[i]._y = tiles[0]._y + (tiles[i].coord.row    - tiles[0].coord.row)    * tileHeight; 
     489             
     490                log(tiles[i].toString()+' at '+tiles[i]._x+', '+tiles[i]._y+' vs. '+tiles[0].toString()); 
     491            } 
     492 
     493        } else if(Math.floor(well._xscale) <= 60 || Math.ceil(well._xscale) >= 165) { 
     494            // split or merge tiles if outside of 60% - 165% 
     495 
     496            // zoom adjust: base-2 logarithm of the scale 
     497            // see http://mathworld.wolfram.com/Logarithm.html (15) 
     498            zoomAdjust = Math.round(Math.log(well._xscale / 100) / Math.log(2)); 
     499            scaleAdjust = Math.pow(2, zoomAdjust); 
     500         
     501            log('This is where we scale the whole well by '+zoomAdjust+' zoom levels: '+(100 / scaleAdjust)+'%'); 
     502 
     503            for(var i:Number = 0; i < zoomAdjust; i += 1) { 
     504                zoomLevel += 1; 
     505                splitTiles(); 
     506            } 
     507                 
     508            for(var i:Number = 0; i > zoomAdjust; i -= 1) { 
     509                zoomLevel -= 1; 
     510                mergeTiles(); 
     511            } 
     512                 
     513            well._xscale /= scaleAdjust; 
     514            well._yscale /= scaleAdjust; 
     515             
     516            for(var i:Number = 0; i < tiles.length; i += 1) { 
     517                tiles[i]._x *= scaleAdjust; 
     518                tiles[i]._y *= scaleAdjust; 
     519 
     520                tiles[i]._xscale *= scaleAdjust; 
     521                tiles[i]._yscale *= scaleAdjust; 
     522            } 
     523         
     524            log('Scaled to '+zoomLevel+', '+well._xscale+'%'); 
     525        } 
     526    } 
     527     
     528   /** 
     529    * Do a 1-to-4 tile split: for every tile in the well, add four 
     530    * new tiles at a higher zoom level, and remove the original. 
     531    * Double the row & column count. 
     532    */ 
     533    private function splitTiles():Void 
     534    { 
     535        var newTiles:/*Tile*/Array = []; 
     536        var oldTile:Tile; 
     537        var newTile:Tile; 
     538        var xOffset:Number, yOffset:Number; 
     539         
     540        while(tiles.length) { 
     541            oldTile = Tile(tiles.pop()); 
     542             
     543            for(var q:Number = 0; q < 4; q += 1) { 
     544                // two-bit value into two one-bit values 
     545                xOffset = q & 1; 
     546                yOffset = (q >> 1) & 1; 
     547                 
     548                newTile = createTile(oldTile); 
     549                newTile.coord = newTile.coord.zoomBy(1); 
     550                 
     551                if(xOffset) 
     552                    newTile.coord = newTile.coord.right(); 
     553                 
     554                if(yOffset) 
     555                    newTile.coord = newTile.coord.down(); 
     556 
     557                newTile._x = oldTile._x + (xOffset * tileWidth / 2); 
     558                newTile._y = oldTile._y + (yOffset * tileHeight / 2); 
     559 
     560                newTile._xscale = newTile._yscale = oldTile._xscale / 2; 
     561                newTiles.push(newTile); 
     562                newTile.redraw(); 
     563            } 
     564 
     565            destroyTile(oldTile); 
     566        } 
     567         
     568        rows *= 2; 
     569        columns *= 2; 
     570         
     571        tiles = newTiles; 
     572    } 
     573     
     574    private function mergeTiles():Void 
     575    { 
     576        var newTiles:/*Tile*/Array = []; 
     577        var oldTile:Tile; 
     578        var newTile:Tile; 
     579        var rowsMerged:Number, columnsMerged:Number; 
     580     
     581        tiles.sort(compareTileRowColumn); 
     582 
     583        if(tiles[0].coord.zoomBy(-1).isRowEdge()) { 
     584            rowsMerged = Math.ceil(rows / 2); 
     585             
     586        } else { 
     587            rowsMerged = Math.floor(rows / 2); 
     588             
     589        } 
     590         
     591        if(tiles[0].coord.zoomBy(-1).isColumnEdge()) { 
     592            columnsMerged = Math.ceil(columns / 2); 
     593             
     594        } else { 
     595            columnsMerged = Math.floor(columns / 2); 
     596             
     597        } 
     598 
     599        while(tiles.length) { 
     600            oldTile = Tile(tiles.pop()); 
     601             
     602            if(oldTile.coord.zoomBy(-1).isEdge()) { 
     603                // we are only interested in tiles that are edges for this zoom 
     604                newTile = createTile(oldTile); 
     605                newTile.coord = newTile.coord.zoomBy(-1); 
     606                 
     607                newTile._x = oldTile._x; 
     608                newTile._y = oldTile._y; 
     609 
     610                newTile._xscale = newTile._yscale = oldTile._xscale * 2; 
     611                newTiles.push(newTile); 
     612                newTile.redraw(); 
     613            } 
     614 
     615            destroyTile(oldTile); 
     616        } 
     617         
     618        rows = rowsMerged; 
     619        columns = columnsMerged; 
     620         
     621        tiles = newTiles; 
    363622    } 
    364623     
     
    427686        var lastTile:Tile; 
    428687        var newTileParams:Object; 
    429         var newTile:Tile; 
    430688         
    431689        tiles.sort(compareTileRowColumn); 
     
    435693            lastTile = tiles[i]; 
    436694         
    437             newTileParams = {grid:  lastTile.grid,      zoom:   lastTile.zoom, 
    438                              row:   lastTile.row + 1,   column: lastTile.column, 
    439                              _x:    lastTile._x,        _y:     lastTile._y + lastTile.height, 
    440                              width: tileWidth,          height: tileHeight}; 
    441              
    442             newTile = Tile(well.attachMovie(Tile.symbolName, 'tile'+well.getNextHighestDepth(), well.getNextHighestDepth(), newTileParams)); 
    443             newTile.addEventObserver( this, "invalidated", "handleTileInvalidated" ); 
    444             newTile.redraw(); 
    445  
    446             tiles.push(newTile); 
     695            newTileParams = {grid:  lastTile.grid,  coord:  lastTile.coord.down(), 
     696                             _x:    lastTile._x,    _y:     lastTile._y + lastTile.height, 
     697                             width: tileWidth,      height: tileHeight}; 
     698 
     699            tiles.push(createTile(newTileParams)); 
    447700        } 
    448701         
     
    455708    private function popTileRow():Void 
    456709    { 
    457         var oldTile:Tile; 
    458          
    459710        tiles.sort(compareTileRowColumn); 
    460711 
    461712        while(tiles.length > columns * (rows - 1)) { 
    462             oldTile = Tile(tiles.pop()); 
    463          
    464             oldTile.removeEventObserver( this, "invalidated", "handleTileInvalidated" ); 
    465             oldTile.destroy(); 
    466             oldTile.removeMovieClip(); 
     713            destroyTile(Tile(tiles.pop())); 
    467714        } 
    468715                                          
     
    477724        var lastTile:Tile; 
    478725        var newTileParams:Object; 
    479         var newTile:Tile; 
    480726         
    481727        tiles.sort(compareTileColumnRow); 
     
    485731            lastTile = tiles[i]; 
    486732         
    487             newTileParams = {grid:  lastTile.grid,                  zoom:   lastTile.zoom, 
    488                              row:   lastTile.row,                   column: lastTile.column + 1, 
     733            newTileParams = {grid:  lastTile.grid,                  coord:  lastTile.coord.right(), 
    489734                             _x:    lastTile._x + lastTile.width,   _y:     lastTile._y, 
    490735                             width: tileWidth,                      height: tileHeight}; 
    491              
    492             newTile = Tile(well.attachMovie(Tile.symbolName, 'tile'+well.getNextHighestDepth(), well.getNextHighestDepth(), newTileParams)); 
    493             newTile.addEventObserver( this, "invalidated", "handleTileInvalidated" );  
    494             newTile.redraw(); 
    495              
    496             tiles.push(newTile); 
     736 
     737            tiles.push(createTile(newTileParams)); 
    497738        } 
    498739         
     
    505746    private function popTileColumn():Void 
    506747    { 
    507         var oldTile:Tile; 
    508          
    509748        tiles.sort(compareTileColumnRow); 
    510749 
    511750        while(tiles.length > rows * (columns - 1)) { 
    512             oldTile = Tile(tiles.pop()); 
    513          
    514             oldTile.removeEventObserver( this, "invalidated", "handleTileInvalidated" ); 
    515             oldTile.destroy(); 
    516             oldTile.removeMovieClip(); 
     751            destroyTile(Tile(tiles.pop())); 
    517752        } 
    518753 
     
    538773    private static function compareTileRowColumn(a:Tile, b:Tile):Number 
    539774    { 
    540         if(a.row == b.row) { 
    541             return a.column - b.column; 
     775        if(a.coord.row == b.coord.row) { 
     776            return a.coord.column - b.coord.column; 
    542777             
    543778        } else { 
    544             return a.row - b.row; 
     779            return a.coord.row - b.coord.row; 
    545780             
    546781        } 
     
    552787    private static function compareTileColumnRow(a:Tile, b:Tile):Number 
    553788    { 
    554         if(a.column == b.column) { 
    555             return a.row - b.row; 
     789        if(a.coord.column == b.coord.column) { 
     790            return a.coord.row - b.coord.row; 
    556791             
    557792        } else { 
    558             return a.column - b.column; 
     793            return a.coord.column - b.coord.column; 
    559794             
    560795        } 
  • branches/darren mapprovider prototype/as2/lib/SampleClient.as

    r34 r41  
    33import com.modestmaps.core.TileGrid; 
    44import com.modestmaps.core.Tile; 
     5import com.modestmaps.core.mapproviders.MapProviders; 
    56 
    67class SampleClient 
     
    910    { 
    1011        var grid:TileGrid = TileGrid(clip.attachMovie(TileGrid.symbolName, 'tile', clip.getNextHighestDepth(), 
    11                                                       {_x: 128, _y: 128, width: Stage.width - 256, height: Stage.height - 256})); 
     12                                                      {mapProviderType: MapProviders.MICROSOFT_AERIAL, _x: 128, _y: 128, width: Stage.width - 256, height: Stage.height - 256})); 
    1213 
    1314        Stage.scaleMode = 'noScale'; 
     
    1516        Stage.addListener(grid); 
    1617         
     18        var plus:MovieClip = makeButton(clip, 'plus', 'zoom in', Delegate.create(grid, grid.startZoomIn)); 
     19        var minus:MovieClip = makeButton(clip, 'minus', 'zoom out', Delegate.create(grid, grid.startZoomOut)); 
     20        var clear:MovieClip = makeButton(clip, 'clear', 'clear log', Delegate.create(grid, grid.clearLog)); 
     21 
     22        plus._x = grid._x; 
     23        plus._y = grid._y - plus['label']._height - 10; 
     24         
     25        minus._x = plus._x + minus['label']._width + 4; 
     26        minus._y = plus._y; 
     27         
     28        clear._x = minus._x + clear['label']._width + 14; 
     29        clear._y = minus._y; 
     30 
    1731        Reactor.run(clip, null, 50); 
     32    } 
     33     
     34    public static function makeButton(clip:MovieClip, name:String, label:String, action:Function):MovieClip 
     35    { 
     36        var button:MovieClip = clip.createEmptyMovieClip(name, clip.getNextHighestDepth()); 
     37         
     38        button.createTextField('label', button.getNextHighestDepth(), 0, 0, 100, 100); 
     39        button['label'].selectable = false; 
     40        button['label'].textColor = 0xFFFFFF; 
     41        button['label'].text = label; 
     42        button['label']._width = button['label'].textWidth + 4; 
     43        button['label']._height = button['label'].textHeight + 2; 
     44         
     45        button.moveTo(0, 0); 
     46        button.beginFill(0x000000, 100); 
     47        button.lineTo(0, button['label']._height); 
     48        button.lineTo(button['label']._width, button['label']._height); 
     49        button.lineTo(button['label']._width, 0); 
     50        button.lineTo(0, 0); 
     51        button.endFill(0, 0); 
     52         
     53        button.onRelease = action; 
     54         
     55        return button; 
    1856    } 
    1957