Changeset 41
- Timestamp:
- 01/16/07 19:59:33 (2 years ago)
- Files:
-
- branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/Coordinate.as (copied) (copied from branches/migurski tile zooming/as2/lib/com/modestmaps/core/Coordinate.as)
- branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/mapproviders/AbstractMicrosoftMapProvider.as (modified) (1 diff)
- branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/Tile.as (modified) (12 diffs)
- branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/TileGrid.as (modified) (25 diffs)
- branches/darren mapprovider prototype/as2/lib/SampleClient.as (modified) (3 diffs)
- branches/migurski tile zooming (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/mapproviders/AbstractMicrosoftMapProvider.as
r34 r41 36 36 { 37 37 // 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 ); 40 40 41 var colBinaryString : String = BinaryUtil.convertToBinary( tile.co lumn );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 ); 43 43 44 44 // generate zoom string by combining strings 45 45 var zoomString : String = ""; 46 for ( var i : Number = 0; i < tile. zoom; i++ )46 for ( var i : Number = 0; i < tile.coord.zoom; i++ ) 47 47 { 48 48 zoomString += BinaryUtil.convertToDecimal( rowBinaryString.charAt( i ) + colBinaryString.charAt( i ) ).toString(); branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/Tile.as
r30 r41 2 2 3 3 import com.modestmaps.core.Point; 4 import com.modestmaps.core.Coordinate; 4 5 import com.modestmaps.core.TileGrid; 5 6 … … 9 10 public var grid:TileGrid; 10 11 12 public var coord:Coordinate; 13 14 /* 11 15 public var row:Number = 0; 12 16 public var column:Number = 0; 13 17 public var zoom:Number = 0; 18 */ 14 19 15 20 public var width:Number; … … 37 42 public function zoomOut():Void 38 43 { 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); 42 45 redraw(); 43 46 } … … 45 48 public function zoomInTopLeft():Void 46 49 { 47 zoom -= 1; 48 column *= 2; 49 row *= 2; 50 coord = new Coordinate(coord.row * 2, coord.column * 2, coord.zoom - 1); 50 51 redraw(); 51 52 } … … 53 54 public function zoomInTopRight():Void 54 55 { 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); 59 57 redraw(); 60 58 } … … 62 60 public function zoomInBottomLeft():Void 63 61 { 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); 68 63 redraw(); 69 64 } … … 71 66 public function zoomInBottomRight():Void 72 67 { 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); 78 69 redraw(); 79 70 } … … 81 72 public function panUp(distance:Number):Void 82 73 { 83 row -= (distance ? distance : 1);74 coord = coord.up(distance); 84 75 redraw(); 85 76 } … … 87 78 public function panRight(distance:Number):Void 88 79 { 89 co lumn += (distance ? distance : 1);80 coord = coord.right(distance); 90 81 redraw(); 91 82 } … … 93 84 public function panDown(distance:Number):Void 94 85 { 95 row += (distance ? distance : 1);86 coord = coord.down(distance); 96 87 redraw(); 97 88 } … … 99 90 public function panLeft(distance:Number):Void 100 91 { 101 co lumn -= (distance ? distance : 1);92 coord = coord.left(distance); 102 93 redraw(); 103 94 } … … 105 96 public function toString():String 106 97 { 107 return row + ', ' + column + ' @' + zoom;98 return 'Tile' + coord.toString(); 108 99 } 109 100 branches/darren mapprovider prototype/as2/lib/com/modestmaps/core/TileGrid.as
r36 r41 1 import com.modestmaps.core.Coordinate; 1 2 import com.modestmaps.core.Bounds; 2 3 import com.modestmaps.core.Point; … … 23 24 private var tileHeight:Number = 256; 24 25 26 // the currently-native zoom level 27 private var zoomLevel:Number; 28 25 29 // 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; 30 32 31 33 // Tiles attach to the well. … … 47 49 48 50 // Who do we get our Map graphics from? 51 public var mapProviderType:Number; 49 52 private var __mapProvider : IMapProvider; 50 53 … … 55 58 public function TileGrid() 56 59 { 57 setMapProvider( MapProviders.MICROSOFT_AERIAL);60 setMapProvider(mapProviderType); 58 61 59 62 buildWell(); 60 63 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); 61 69 62 70 // initial tile centers the map on the SF Bay Area … … 67 75 width: tileWidth, 68 76 height: tileHeight, 69 row: 791, 70 column: 328, 71 zoom: 11 77 coord: new Coordinate(791, 328, zoomLevel) 72 78 }; 73 79 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)]; 81 81 82 82 rows = 1; … … 93 93 94 94 log('FUCK YEAH '+width+'x'+height); 95 96 // TODO:97 // Figure out why positionTiles() doesn't seem to work98 // when called from here, even on a delay via the Reactor.99 95 } 100 96 … … 119 115 } 120 116 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 121 141 public function log(msg:String):Void 122 142 { … … 124 144 } 125 145 146 public function clearLog():Void 147 { 148 label.text = ''; 149 } 150 126 151 private function setMapProvider( mapProviderType : Number ) : Void 127 152 { 153 this.mapProviderType = mapProviderType; 128 154 var mapProviderFactory : MapProviderFactory = MapProviderFactory.getInstance(); 129 155 __mapProvider = MapProviderFactory.getInstance().getMapProvider( mapProviderType ); … … 140 166 141 167 /* 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. 145 170 * 146 171 * Respect infinite rows or columns, to bind movement on one (or no) axis. 147 172 */ 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); 153 184 154 185 // store the infinite 155 186 var force:Point = new Point(0, 0); 156 187 157 if(co lumn == Infinity || column == -Infinity) {158 force.x = co lumn;188 if(coord.column == Number.POSITIVE_INFINITY || coord.column == Number.NEGATIVE_INFINITY) { 189 force.x = coord.column; 159 190 160 191 } else { 161 point.x += tileWidth * (co lumn - 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; 167 198 168 199 } else { 169 point.y += tileHeight * ( row - tiles[0].row);200 point.y += tileHeight * (coord.row - tile.coord.row); 170 201 171 202 } … … 182 213 return point; 183 214 } 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 */ 184 244 185 245 /* … … 193 253 // "min" = furthest well position left & up, 194 254 // 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 199 259 // "max" = furthest well position right & down, 200 260 // use the location of the top-left limit 201 max = tilePosition(rowTop, columnLeft, this);261 max = coordinatePoint(topLeftOutLimit, this); 202 262 max.x = well._x - max.x; 203 263 max.y = well._y - max.y; 264 265 log('min/max for drag: '+min+', '+max+' ('+topLeftOutLimit+', '+bottomRightInLimit+')'); 204 266 205 267 // weird negative edge conditions, limit all movement on an axis … … 224 286 // so we'll fudge it with some implausibly large numbers. 225 287 226 var xMin:Number = (bounds.min.x == Infinity)288 var xMin:Number = (bounds.min.x == Number.POSITIVE_INFINITY) 227 289 ? 100000 228 : ((bounds.min.x == -Infinity)290 : ((bounds.min.x == Number.NEGATIVE_INFINITY) 229 291 ? -100000 230 292 : bounds.min.x); 231 293 232 var yMin:Number = (bounds.min.y == Infinity)294 var yMin:Number = (bounds.min.y == Number.POSITIVE_INFINITY) 233 295 ? 100000 234 : ((bounds.min.y == -Infinity)296 : ((bounds.min.y == Number.NEGATIVE_INFINITY) 235 297 ? -100000 236 298 : bounds.min.y); 237 299 238 var xMax:Number = (bounds.max.x == Infinity)300 var xMax:Number = (bounds.max.x == Number.POSITIVE_INFINITY) 239 301 ? 100000 240 : ((bounds.max.x == -Infinity)302 : ((bounds.max.x == Number.NEGATIVE_INFINITY) 241 303 ? -100000 242 304 : bounds.max.x); 243 305 244 var yMax:Number = (bounds.max.y == Infinity)306 var yMax:Number = (bounds.max.y == Number.POSITIVE_INFINITY) 245 307 ? 100000 246 : ((bounds.max.y == -Infinity)308 : ((bounds.max.y == Number.NEGATIVE_INFINITY) 247 309 ? -100000 248 310 : bounds.max.y); … … 263 325 centerWell(true); 264 326 } 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 } 265 357 266 358 /* … … 313 405 private function allocateTiles():Void 314 406 { 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 315 414 // 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); 318 417 319 418 // change column count to match target … … 342 441 /** 343 442 * Adjust position of the well, so it stays in the center. 344 * Optionally, compensate tile positions to prevent visual345 * discontinuity with respect to upper-left hand corner.443 * Optionally, compensate tile positions to prevent 444 * visual discontinuity. 346 445 */ 347 446 private function centerWell(adjustTiles:Boolean):Void … … 351 450 var xAdjustment:Number = well._x - center.x; 352 451 var yAdjustment:Number = well._y - center.y; 353 452 354 453 well._x -= xAdjustment; 355 454 well._y -= yAdjustment; … … 357 456 if(adjustTiles) { 358 457 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; 363 622 } 364 623 … … 427 686 var lastTile:Tile; 428 687 var newTileParams:Object; 429 var newTile:Tile;430 688 431 689 tiles.sort(compareTileRowColumn); … … 435 693 lastTile = tiles[i]; 436 694 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)); 447 700 } 448 701 … … 455 708 private function popTileRow():Void 456 709 { 457 var oldTile:Tile;458 459 710 tiles.sort(compareTileRowColumn); 460 711 461 712 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())); 467 714 } 468 715 … … 477 724 var lastTile:Tile; 478 725 var newTileParams:Object; 479 var newTile:Tile;480 726 481 727 tiles.sort(compareTileColumnRow); … … 485 731 lastTile = tiles[i]; 486 732 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(), 489 734 _x: lastTile._x + lastTile.width, _y: lastTile._y, 490 735 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)); 497 738 } 498 739 … … 505 746 private function popTileColumn():Void 506 747 { 507 var oldTile:Tile;508 509 748 tiles.sort(compareTileColumnRow); 510 749 511 750 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())); 517 752 } 518 753 … … 538 773 private static function compareTileRowColumn(a:Tile, b:Tile):Number 539 774 { 540 if(a. row == b.row) {541 return a.co lumn - b.column;775 if(a.coord.row == b.coord.row) { 776 return a.coord.column - b.coord.column; 542 777 543 778 } else { 544 return a. row - b.row;779 return a.coord.row - b.coord.row; 545 780 546 781 } … … 552 787 private static function compareTileColumnRow(a:Tile, b:Tile):Number 553 788 { 554 if(a.co lumn == b.column) {555 return a. row - b.row;789 if(a.coord.column == b.coord.column) { 790 return a.coord.row - b.coord.row; 556 791 557 792 } else { 558 return a.co lumn - b.column;793 return a.coord.column - b.coord.column; 559 794 560 795 } branches/darren mapprovider prototype/as2/lib/SampleClient.as
r34 r41 3 3 import com.modestmaps.core.TileGrid; 4 4 import com.modestmaps.core.Tile; 5 import com.modestmaps.core.mapproviders.MapProviders; 5 6 6 7 class SampleClient … … 9 10 { 10 11 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})); 12 13 13 14 Stage.scaleMode = 'noScale'; … … 15 16 Stage.addListener(grid); 16 17 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 17 31 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; 18 56 } 19 57
