Changeset 66
- Timestamp:
- 01/22/07 22:38:42 (2 years ago)
- Files:
-
- branches/darren tile painting/as2/lib/com/modestmaps/core/Coordinate.as (modified) (1 diff)
- branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/AbstractMapProvider.as (modified) (4 diffs)
- branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/AbstractMicrosoftMapProvider.as (modified) (2 diffs)
- branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/IMapProvider.as (modified) (1 diff)
- branches/darren tile painting/as2/lib/com/modestmaps/core/TileGrid.as (modified) (16 diffs)
- branches/darren tile painting/as2/lib/com/modestmaps/geo (copied) (copied from branches/migurski geocoding/as2/lib/com/modestmaps/geo)
- branches/darren tile painting/as2/lib/SampleClient.as (modified) (3 diffs)
- branches/darren tile painting/as2/lib/SampleFlashLiteClient.as (modified) (5 diffs)
- branches/migurski geocoding (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/darren tile painting/as2/lib/com/modestmaps/core/Coordinate.as
r61 r66 15 15 { 16 16 return '(' + row + ',' + column + ' @' + zoom + ')'; 17 } 18 19 public function copy():Coordinate 20 { 21 return new Coordinate(row, column, zoom); 17 22 } 18 23 branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/AbstractMapProvider.as
r47 r66 5 5 import com.modestmaps.core.Coordinate; 6 6 import com.modestmaps.events.IDispatchable; 7 7 import com.modestmaps.geo.IProjection; 8 import com.modestmaps.geo.LinearProjection; 9 import com.modestmaps.geo.Transformation; 10 import com.modestmaps.geo.Location; 8 11 9 12 /** … … 17 20 18 21 private var __requestThrottler : RequestThrottler; 22 private var __projection:IProjection; 19 23 20 24 // tracks if we're set up to broadcast events … … 33 37 } 34 38 35 __requestThrottler = RequestThrottler.getInstance(); 39 __requestThrottler = RequestThrottler.getInstance(); 40 41 var t:Transformation = new Transformation(1, 0, 0, 0, 1, 0); 42 __projection = new LinearProjection(Coordinate.MAX_ZOOM, t); 36 43 } 37 44 … … 82 89 super.dispatchEvent( eventObj ); 83 90 } 91 92 /* 93 * Return projected and transformed coordinate for a location. 94 */ 95 public function locationCoordinate(location:Location):Coordinate 96 { 97 return __projection.locationCoordinate(location); 98 } 99 100 /* 101 * Return untransformed and unprojected location for a coordinate. 102 */ 103 public function coordinateLocation(coordinate:Coordinate):Location 104 { 105 return __projection.coordinateLocation(coordinate); 106 } 84 107 } branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/AbstractMicrosoftMapProvider.as
r63 r66 4 4 import com.modestmaps.io.LoadMovieThrottledRequest; 5 5 import mx.utils.Delegate; 6 import com.modestmaps.geo.MercatorProjection; 7 import com.modestmaps.geo.Transformation; 6 8 7 9 /** … … 17 19 { 18 20 super(); 21 22 // see: http://track.stamen.com/modestmap/wiki/TileCoordinateComparisons#TileGeolocations 23 var t:Transformation = new Transformation(1.068070779e7, 0, 3.355443185e7, 24 0, -1.068070890e7, 3.355443057e7); 25 26 __projection = new MercatorProjection(26, t); 19 27 } 20 28 branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/IMapProvider.as
r44 r66 3 3 */ 4 4 import com.modestmaps.core.Coordinate; 5 import com.modestmaps.geo.Location; 5 6 6 7 interface com.modestmaps.core.mapproviders.IMapProvider 7 8 { 8 9 public function paint( clip : MovieClip, coord : Coordinate ) : Void; 10 11 /* 12 * Return projected and transformed coordinate for a location. 13 */ 14 public function locationCoordinate(location:Location):Coordinate; 15 16 /* 17 * Return untransformed and unprojected location for a coordinate. 18 */ 19 public function coordinateLocation(coordinate:Coordinate):Location; 9 20 } branches/darren tile painting/as2/lib/com/modestmaps/core/TileGrid.as
r65 r66 4 4 import com.modestmaps.core.Tile; 5 5 import com.modestmaps.core.mapproviders.IMapProvider; 6 import com.modestmaps.core.mapproviders.MapProviderFactory;7 import com.modestmaps.core.mapproviders.MapProviders;8 6 9 7 import mx.utils.Delegate; … … 50 48 51 49 // Who do we get our Map graphics from? 52 public var mapProviderType:Number; 53 public var mapProvider : IMapProvider; 50 public var mapProvider:IMapProvider; 54 51 55 52 public static var symbolName:String = '__Packages.com.modestmaps.core.TileGrid'; … … 59 56 public function TileGrid() 60 57 { 61 setMapProvider(mapProviderType);62 63 58 this.createEmptyMovieClip( "labelContainer", getNextHighestDepth() ); 64 59 labelContainer.createTextField('label', 1, 10, 10, width-20, height-20); … … 110 105 well.onRelease = Delegate.create(this, this.stopWellDrag); 111 106 well.onReleaseOutside = Delegate.create(this, this.stopWellDrag); 107 108 /* 109 // So the log is visible... 110 var c:Color = new Color(well); 111 var t:Object = c.getTransform(); 112 t.ra = 20; 113 t.rb = 204; 114 t.ga = 20; 115 t.gb = 204; 116 t.ba = 20; 117 t.bb = 204; 118 c.setTransform(t); 119 */ 112 120 } 113 121 … … 154 162 { 155 163 label.text = ''; 156 }157 158 private function setMapProvider( mapProviderType : Number ) : Void159 {160 this.mapProviderType = mapProviderType;161 var mapProviderFactory : MapProviderFactory = MapProviderFactory.getInstance();162 mapProvider = MapProviderFactory.getInstance().getMapProvider( mapProviderType );163 164 } 164 165 … … 221 222 } 222 223 223 /*224 224 private function pointCoordinate(point:Point):Coordinate 225 225 { … … 230 230 // an arbitrary reference tile, zoomed to the maximum 231 231 tile = tiles[0]; 232 tileCoord = new Coordinate(tile.row, tile.column, tile.zoom);233 tileCoord .zoomTo(Coordinate.MAX_ZOOM);232 tileCoord = tile.coord.copy(); 233 tileCoord = tileCoord.zoomTo(Coordinate.MAX_ZOOM); 234 234 235 235 // distance in tile widths from reference tile to point 236 236 var xTiles:Number = (point.x - tile._x) / tileWidth; 237 237 var yTiles:Number = (point.y - tile._y) / tileHeight; 238 238 239 239 // distance in rows & columns at maximum zoom 240 var xDistance:Number = xTiles * Math.pow(2, (Coordinate.MAX_ZOOM - tile. zoom));241 var yDistance:Number = yTiles * Math.pow(2, (Coordinate.MAX_ZOOM - tile. zoom));240 var xDistance:Number = xTiles * Math.pow(2, (Coordinate.MAX_ZOOM - tile.coord.zoom)); 241 var yDistance:Number = yTiles * Math.pow(2, (Coordinate.MAX_ZOOM - tile.coord.zoom)); 242 242 243 243 // new point coordinate reflecting that distance … … 246 246 tileCoord.zoom); 247 247 248 return pointCoord; 249 } 250 */ 248 return pointCoord.zoomTo(tile.coord.zoom); 249 } 250 251 public function topLeftCoordinate():Coordinate 252 { 253 var point:Point = new Point(0, 0); 254 255 localToGlobal(point); 256 well.globalToLocal(point); 257 258 return pointCoordinate(point); 259 } 260 261 public function bottomRightCoordinate():Coordinate 262 { 263 var point:Point = new Point(width, height); 264 265 localToGlobal(point); 266 well.globalToLocal(point); 267 268 return pointCoordinate(point); 269 } 251 270 252 271 /* … … 333 352 } 334 353 335 public function startZoomIn():Void354 public function zoomIn(amount:Number):Void 336 355 { 337 356 if(zoomLevel >= bottomRightInLimit.zoom && Math.round(well._xscale) >= 100) 338 357 return; 339 358 340 well._xscale *= Math.pow(2, .25);341 well._yscale *= Math.pow(2, .25);359 well._xscale *= Math.pow(2, amount); 360 well._yscale *= Math.pow(2, amount); 342 361 343 362 normalizeWell(); … … 348 367 } 349 368 350 public function startZoomOut():Void369 public function zoomOut(amount:Number):Void 351 370 { 352 371 if(zoomLevel <= topLeftOutLimit.zoom && Math.round(well._xscale) <= 100) 353 372 return; 354 373 355 well._xscale /= Math.pow(2, .25);356 well._yscale /= Math.pow(2, .25);374 well._xscale /= Math.pow(2, amount); 375 well._yscale /= Math.pow(2, amount); 357 376 358 377 normalizeWell(); … … 363 382 } 364 383 365 /* 366 * TODO: 367 * Size relative to stage is currently hard-coded, but shouldn't be. 368 */ 369 public function onResize():Void 370 { 371 width = Stage.width - 2 * _x; 372 height = Stage.height - 2 * _y; 384 public function resizeTo(bottomLeft:Point):Void 385 { 386 width = bottomLeft.x; 387 height = bottomLeft.y; 373 388 374 389 centerWell(false); … … 378 393 } 379 394 380 public function pan East( pixels : Number ) :Void381 { 382 well._x -= pixels;383 positionTiles();384 centerWell(true);395 public function panRight(pixels:Number):Void 396 { 397 well._x -= pixels; 398 positionTiles(); 399 centerWell(true); 385 400 } 386 401 387 public function pan West( pixels : Number ) :Void388 { 389 well._x += pixels;390 positionTiles();402 public function panLeft(pixels:Number):Void 403 { 404 well._x += pixels; 405 positionTiles(); 391 406 centerWell(true); 392 407 } 393 394 public function panNorth( pixels : Number ) : Void395 {396 well._y -= pixels;397 positionTiles();398 centerWell(true);399 }400 408 401 public function pan South( pixels : Number ) :Void402 { 403 well._y += pixels;404 positionTiles();409 public function panUp(pixels:Number):Void 410 { 411 well._y += pixels; 412 positionTiles(); 405 413 centerWell(true); 406 414 } 415 416 public function panDown(pixels:Number):Void 417 { 418 well._y -= pixels; 419 positionTiles(); 420 centerWell(true); 421 } 422 423 /** 424 * Find out whether a tile is at the grid's native zoom level. 425 */ 426 private function nativeZoom(tile:Tile):Boolean 427 { 428 return (tile.coord.zoom == zoomLevel); 429 } 407 430 408 431 /** … … 509 532 510 533 for(var i:Number = 0; i < zoomAdjust; i += 1) { 534 splitTiles(); 511 535 zoomLevel += 1; 512 splitTiles();513 536 } 514 537 515 538 for(var i:Number = 0; i > zoomAdjust; i -= 1) { 539 mergeTiles(); 516 540 zoomLevel -= 1; 517 mergeTiles();518 541 } 519 542 … … 540 563 private function splitTiles():Void 541 564 { 542 var newTiles:/*Tile*/Array = [];543 565 var oldTile:Tile; 544 566 var newTile:Tile; 545 567 var xOffset:Number, yOffset:Number; 546 568 547 while(tiles.length) { 548 oldTile = Tile(tiles.pop()); 549 550 for(var q:Number = 0; q < 4; q += 1) { 551 // two-bit value into two one-bit values 552 xOffset = q & 1; 553 yOffset = (q >> 1) & 1; 554 555 newTile = createTile(oldTile); 556 newTile.coord = newTile.coord.zoomBy(1); 557 558 if(xOffset) 559 newTile.coord = newTile.coord.right(); 560 561 if(yOffset) 562 newTile.coord = newTile.coord.down(); 563 564 newTile._x = oldTile._x + (xOffset * tileWidth / 2); 565 newTile._y = oldTile._y + (yOffset * tileHeight / 2); 566 567 newTile._xscale = newTile._yscale = oldTile._xscale / 2; 568 newTiles.push(newTile); 569 newTile.redraw(); 570 } 571 572 destroyTile(oldTile); 569 for(var i:Number = tiles.length - 1; i >= 0; i -= 1) { 570 oldTile = tiles[i]; 571 572 if(nativeZoom(oldTile)) { 573 for(var q:Number = 0; q < 4; q += 1) { 574 // two-bit value into two one-bit values 575 xOffset = q & 1; 576 yOffset = (q >> 1) & 1; 577 578 newTile = createTile(oldTile); 579 newTile.coord = newTile.coord.zoomBy(1); 580 581 if(xOffset) 582 newTile.coord = newTile.coord.right(); 583 584 if(yOffset) 585 newTile.coord = newTile.coord.down(); 586 587 newTile._x = oldTile._x + (xOffset * tileWidth / 2); 588 newTile._y = oldTile._y + (yOffset * tileHeight / 2); 589 590 newTile._xscale = newTile._yscale = oldTile._xscale / 2; 591 newTile.redraw(); 592 593 // add newTile 594 tiles.push(newTile); 595 } 596 597 // remove oldTile 598 tiles.splice(i, 1); 599 destroyTile(oldTile); 600 } 573 601 } 574 602 575 603 rows *= 2; 576 604 columns *= 2; 577 578 tiles = newTiles;579 605 } 580 606 581 607 private function mergeTiles():Void 582 608 { 583 var newTiles:/*Tile*/Array = [];584 609 var oldTile:Tile; 585 610 var newTile:Tile; … … 604 629 } 605 630 606 while(tiles.length) { 607 oldTile = Tile(tiles.pop()); 608 609 if(oldTile.coord.zoomBy(-1).isEdge()) { 610 // we are only interested in tiles that are edges for this zoom 611 newTile = createTile(oldTile); 612 newTile.coord = newTile.coord.zoomBy(-1); 613 614 newTile._x = oldTile._x; 615 newTile._y = oldTile._y; 616 617 newTile._xscale = newTile._yscale = oldTile._xscale * 2; 618 newTiles.push(newTile); 619 newTile.redraw(); 620 } 621 622 destroyTile(oldTile); 631 for(var i:Number = tiles.length - 1; i >= 0; i -= 1) { 632 oldTile = tiles[i]; 633 634 if(nativeZoom(oldTile)) { 635 if(oldTile.coord.zoomBy(-1).isEdge()) { 636 // we are only interested in tiles that are edges for this zoom 637 newTile = createTile(oldTile); 638 newTile.coord = newTile.coord.zoomBy(-1); 639 640 newTile._x = oldTile._x; 641 newTile._y = oldTile._y; 642 643 newTile._xscale = newTile._yscale = oldTile._xscale * 2; 644 newTile.redraw(); 645 646 // add newTile 647 tiles.push(newTile); 648 } 649 650 // remove oldTile 651 tiles.splice(i, 1); 652 destroyTile(oldTile); 653 } 623 654 } 624 655 625 656 rows = rowsMerged; 626 657 columns = columnsMerged; 627 628 tiles = newTiles;629 658 } 630 659 … … 653 682 654 683 for(var i:Number = 0; i < tiles.length; i += 1) { 655 656 tile = Tile(tiles[i]); 684 685 tile = tiles[i]; 686 687 // only interested in moving tiles at the current zoom level 688 if(!nativeZoom(tile)) 689 break; 657 690 658 691 if(tile._y < yMin) { branches/darren tile painting/as2/lib/SampleClient.as
r46 r66 1 1 import mx.utils.Delegate; 2 2 import com.stamen.twisted.Reactor; 3 import com.modestmaps.geo.Map; 3 4 import com.modestmaps.core.TileGrid; 4 import com.modestmaps.core.Tile;5 5 import com.modestmaps.core.mapproviders.MapProviders; 6 6 … … 9 9 public static function main(clip:MovieClip):Void 10 10 { 11 var grid:TileGrid = TileGrid(clip.attachMovie(TileGrid.symbolName, 'tile', clip.getNextHighestDepth(),12 {mapProviderType: MapProviders.MICROSOFT_HYBRID, _x: 128, _y: 128, width: Stage.width - 256, height: Stage.height - 256}));13 11 var map:Map = Map(clip.attachMovie(Map.symbolName, 'map', clip.getNextHighestDepth(), 12 {mapProviderType: MapProviders.MICROSOFT_HYBRID, _x: 128, _y: 128, width: Stage.width - 256, height: Stage.height - 256})) 13 14 14 Stage.scaleMode = 'noScale'; 15 15 Stage.align = 'TL'; 16 Stage.addListener( grid);16 Stage.addListener(map); 17 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));18 var plus:MovieClip = makeButton(clip, 'plus', 'zoom in', Delegate.create(map, map.zoomIn)); 19 var minus:MovieClip = makeButton(clip, 'minus', 'zoom out', Delegate.create(map, map.zoomOut)); 20 var clear:MovieClip = makeButton(clip, 'clear', 'clear log', Delegate.create(map.grid, map.grid.clearLog)); 21 21 22 plus._x = grid._x;23 plus._y = grid._y - plus['label']._height - 10;22 plus._x = map._x; 23 plus._y = map._y - plus['label']._height - 10; 24 24 25 25 minus._x = plus._x + minus['label']._width + 4; … … 30 30 31 31 Reactor.run(clip, null, 50); 32 Reactor.callNextFrame(Delegate.create(map, map.nagAboutBoundsForever)); 32 33 } 33 34 branches/darren tile painting/as2/lib/SampleFlashLiteClient.as
r42 r66 1 1 import mx.utils.Delegate; 2 2 import com.stamen.twisted.Reactor; 3 import com.modestmaps. core.TileGrid;4 import com.modestmaps.core. Tile;3 import com.modestmaps.geo.Map; 4 import com.modestmaps.core.mapproviders.MapProviders; 5 5 6 6 class SampleFlashLiteClient … … 10 10 clip._focusRect = false; 11 11 12 var grid:TileGrid = TileGrid(clip.attachMovie(TileGrid.symbolName, 'tile', clip.getNextHighestDepth(),13 {_x: 0, _y: 0, width: Stage.width, height: Stage.height} ));14 12 var map:Map = Map(clip.attachMovie(Map.symbolName, 'map', clip.getNextHighestDepth(), 13 {mapProviderType: MapProviders.MICROSOFT_AERIAL, _x: 0, _y: 0, width: Stage.width, height: Stage.height})) 14 15 15 16 16 // Set up key listeners. … … 18 18 19 19 var myListener:Object = new Object(); 20 myListener. grid = grid;20 myListener.map = map; 21 21 myListener.onKeyDown = function() 22 22 { … … 24 24 { 25 25 case Key.RIGHT: 26 grid.panEast( Stage.width );26 map.panEast( Stage.width ); 27 27 break; 28 28 29 29 case Key.LEFT: 30 grid.panWest( Stage.width );30 map.panWest( Stage.width ); 31 31 break; 32 32 33 33 case Key.UP: 34 grid.panNorth( Stage.height );34 map.panNorth( Stage.height ); 35 35 break; 36 36 37 37 case Key.DOWN: 38 grid.panSouth( Stage.height );38 map.panSouth( Stage.height ); 39 39 break; 40 40 } … … 45 45 Stage.scaleMode = 'noScale'; 46 46 Stage.align = 'TL'; 47 Stage.addListener( grid);47 Stage.addListener(map); 48 48 49 49 Reactor.run(clip, null, 50);
