Changeset 66

Show
Ignore:
Timestamp:
01/22/07 22:38:42 (2 years ago)
Author:
migurski
Message:

Merged branch "migurski geocoding" on to branch "darren tile painting"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/darren tile painting/as2/lib/com/modestmaps/core/Coordinate.as

    r61 r66  
    1515    { 
    1616        return '(' + row + ',' + column + ' @' + zoom + ')'; 
     17    } 
     18     
     19    public function copy():Coordinate 
     20    { 
     21        return new Coordinate(row, column, zoom); 
    1722    } 
    1823     
  • branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/AbstractMapProvider.as

    r47 r66  
    55import com.modestmaps.core.Coordinate; 
    66import com.modestmaps.events.IDispatchable; 
    7  
     7import com.modestmaps.geo.IProjection; 
     8import com.modestmaps.geo.LinearProjection; 
     9import com.modestmaps.geo.Transformation; 
     10import com.modestmaps.geo.Location; 
    811 
    912/** 
     
    1720         
    1821        private var __requestThrottler : RequestThrottler; 
     22        private var __projection:IProjection; 
    1923 
    2024        // tracks if we're set up to broadcast events 
     
    3337                } 
    3438 
    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); 
    3643        } 
    3744 
     
    8289                super.dispatchEvent( eventObj ); 
    8390        } 
     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    } 
    84107} 
  • branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/AbstractMicrosoftMapProvider.as

    r63 r66  
    44import com.modestmaps.io.LoadMovieThrottledRequest; 
    55import mx.utils.Delegate; 
     6import com.modestmaps.geo.MercatorProjection; 
     7import com.modestmaps.geo.Transformation; 
    68 
    79/** 
     
    1719        { 
    1820                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); 
    1927        } 
    2028         
  • branches/darren tile painting/as2/lib/com/modestmaps/core/mapproviders/IMapProvider.as

    r44 r66  
    33 */ 
    44import com.modestmaps.core.Coordinate;  
     5import com.modestmaps.geo.Location; 
    56  
    67interface com.modestmaps.core.mapproviders.IMapProvider  
    78{ 
    89        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; 
    920} 
  • branches/darren tile painting/as2/lib/com/modestmaps/core/TileGrid.as

    r65 r66  
    44import com.modestmaps.core.Tile; 
    55import com.modestmaps.core.mapproviders.IMapProvider; 
    6 import com.modestmaps.core.mapproviders.MapProviderFactory; 
    7 import com.modestmaps.core.mapproviders.MapProviders; 
    86 
    97import mx.utils.Delegate; 
     
    5048 
    5149    // Who do we get our Map graphics from? 
    52     public var mapProviderType:Number; 
    53     public var mapProvider : IMapProvider; 
     50    public var mapProvider:IMapProvider; 
    5451 
    5552    public static var symbolName:String = '__Packages.com.modestmaps.core.TileGrid'; 
     
    5956    public function TileGrid() 
    6057    { 
    61         setMapProvider(mapProviderType); 
    62  
    6358                this.createEmptyMovieClip( "labelContainer", getNextHighestDepth() ); 
    6459        labelContainer.createTextField('label', 1, 10, 10, width-20, height-20); 
     
    110105        well.onRelease = Delegate.create(this, this.stopWellDrag); 
    111106        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        */ 
    112120    } 
    113121     
     
    154162    { 
    155163        label.text = ''; 
    156     } 
    157      
    158     private function setMapProvider( mapProviderType : Number ) : Void 
    159     { 
    160         this.mapProviderType = mapProviderType; 
    161         var mapProviderFactory : MapProviderFactory = MapProviderFactory.getInstance(); 
    162         mapProvider = MapProviderFactory.getInstance().getMapProvider( mapProviderType );  
    163164    } 
    164165     
     
    221222    } 
    222223     
    223     /* 
    224224    private function pointCoordinate(point:Point):Coordinate 
    225225    { 
     
    230230        // an arbitrary reference tile, zoomed to the maximum 
    231231        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); 
    234234         
    235235        // distance in tile widths from reference tile to point 
    236236        var xTiles:Number = (point.x - tile._x) / tileWidth; 
    237237        var yTiles:Number = (point.y - tile._y) / tileHeight; 
    238          
     238 
    239239        // 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)); 
    242242         
    243243        // new point coordinate reflecting that distance 
     
    246246                                    tileCoord.zoom); 
    247247         
    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    } 
    251270     
    252271   /* 
     
    333352    } 
    334353     
    335     public function startZoomIn():Void 
     354    public function zoomIn(amount:Number):Void 
    336355    { 
    337356        if(zoomLevel >= bottomRightInLimit.zoom && Math.round(well._xscale) >= 100) 
    338357            return; 
    339358     
    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); 
    342361         
    343362        normalizeWell(); 
     
    348367    } 
    349368     
    350     public function startZoomOut():Void 
     369    public function zoomOut(amount:Number):Void 
    351370    { 
    352371        if(zoomLevel <= topLeftOutLimit.zoom && Math.round(well._xscale) <= 100) 
    353372            return; 
    354373     
    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); 
    357376         
    358377        normalizeWell(); 
     
    363382    } 
    364383 
    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; 
    373388 
    374389        centerWell(false); 
     
    378393    } 
    379394     
    380     public function panEast( pixels : Number ) : Void 
    381     { 
    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); 
    385400    } 
    386401  
    387     public function panWest( pixels : Number ) : Void 
    388     { 
    389        well._x += pixels; 
    390        positionTiles(); 
     402    public function panLeft(pixels:Number):Void 
     403    { 
     404        well._x += pixels; 
     405        positionTiles(); 
    391406        centerWell(true); 
    392407    }  
    393      
    394     public function panNorth( pixels : Number ) : Void 
    395     { 
    396         well._y -= pixels; 
    397         positionTiles(); 
    398         centerWell(true); 
    399     } 
    400408  
    401     public function panSouth( pixels : Number ) : Void 
    402     { 
    403        well._y += pixels; 
    404        positionTiles(); 
     409    public function panUp(pixels:Number):Void 
     410    { 
     411        well._y += pixels; 
     412        positionTiles(); 
    405413        centerWell(true); 
    406414    }       
     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    } 
    407430 
    408431   /** 
     
    509532 
    510533            for(var i:Number = 0; i < zoomAdjust; i += 1) { 
     534                splitTiles(); 
    511535                zoomLevel += 1; 
    512                 splitTiles(); 
    513536            } 
    514537                 
    515538            for(var i:Number = 0; i > zoomAdjust; i -= 1) { 
     539                mergeTiles(); 
    516540                zoomLevel -= 1; 
    517                 mergeTiles(); 
    518541            } 
    519542                 
     
    540563    private function splitTiles():Void 
    541564    { 
    542         var newTiles:/*Tile*/Array = []; 
    543565        var oldTile:Tile; 
    544566        var newTile:Tile; 
    545567        var xOffset:Number, yOffset:Number; 
    546568         
    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            } 
    573601        } 
    574602         
    575603        rows *= 2; 
    576604        columns *= 2; 
    577          
    578         tiles = newTiles; 
    579605    } 
    580606     
    581607    private function mergeTiles():Void 
    582608    { 
    583         var newTiles:/*Tile*/Array = []; 
    584609        var oldTile:Tile; 
    585610        var newTile:Tile; 
     
    604629        } 
    605630 
    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            } 
    623654        } 
    624655         
    625656        rows = rowsMerged; 
    626657        columns = columnsMerged; 
    627          
    628         tiles = newTiles; 
    629658    } 
    630659     
     
    653682         
    654683        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; 
    657690             
    658691            if(tile._y < yMin) { 
  • branches/darren tile painting/as2/lib/SampleClient.as

    r46 r66  
    11import mx.utils.Delegate; 
    22import com.stamen.twisted.Reactor; 
     3import com.modestmaps.geo.Map; 
    34import com.modestmaps.core.TileGrid; 
    4 import com.modestmaps.core.Tile; 
    55import com.modestmaps.core.mapproviders.MapProviders; 
    66 
     
    99    public static function main(clip:MovieClip):Void 
    1010    { 
    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         
    1414        Stage.scaleMode = 'noScale'; 
    1515        Stage.align = 'TL'; 
    16         Stage.addListener(grid);  
     16        Stage.addListener(map);  
    1717         
    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)); 
    2121 
    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; 
    2424         
    2525        minus._x = plus._x + minus['label']._width + 4; 
     
    3030 
    3131        Reactor.run(clip, null, 50); 
     32        Reactor.callNextFrame(Delegate.create(map, map.nagAboutBoundsForever)); 
    3233    } 
    3334     
  • branches/darren tile painting/as2/lib/SampleFlashLiteClient.as

    r42 r66  
    11import mx.utils.Delegate; 
    22import com.stamen.twisted.Reactor; 
    3 import com.modestmaps.core.TileGrid
    4 import com.modestmaps.core.Tile
     3import com.modestmaps.geo.Map
     4import com.modestmaps.core.mapproviders.MapProviders
    55 
    66class SampleFlashLiteClient  
     
    1010        clip._focusRect = false; 
    1111         
    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         
    1515 
    1616                // Set up key listeners.  
     
    1818         
    1919        var myListener:Object = new Object(); 
    20         myListener.grid = grid
     20        myListener.map = map
    2121                myListener.onKeyDown = function()  
    2222                { 
     
    2424                        { 
    2525                                case Key.RIGHT: 
    26                                         grid.panEast( Stage.width ); 
     26                                        map.panEast( Stage.width ); 
    2727                                        break;   
    2828                                 
    2929                                case Key.LEFT: 
    30                                         grid.panWest( Stage.width ); 
     30                                        map.panWest( Stage.width ); 
    3131                                        break; 
    3232 
    3333                                case Key.UP: 
    34                                         grid.panNorth( Stage.height ); 
     34                                        map.panNorth( Stage.height ); 
    3535                                        break;   
    3636                                 
    3737                                case Key.DOWN: 
    38                                         grid.panSouth( Stage.height ); 
     38                                        map.panSouth( Stage.height ); 
    3939                                        break; 
    4040                        } 
     
    4545        Stage.scaleMode = 'noScale'; 
    4646        Stage.align = 'TL'; 
    47         Stage.addListener(grid); 
     47        Stage.addListener(map); 
    4848         
    4949        Reactor.run(clip, null, 50);