Changeset 297

Show
Ignore:
Timestamp:
06/15/07 19:21:23 (1 year ago)
Author:
tom
Message:

shaking fist at Flex Builder's default tab width

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/as3/lib/com/modestmaps/core/TileGrid.as

    r292 r297  
    66package com.modestmaps.core 
    77{ 
    8        import com.modestmaps.Map; 
    9        import com.modestmaps.mapproviders.IMapProvider; 
    10        import com.modestmaps.core.*; 
    11        import com.modestmaps.geo.Location; 
    12        import com.stamen.twisted.*; 
     8    import com.modestmaps.Map; 
     9    import com.modestmaps.mapproviders.IMapProvider; 
     10    import com.modestmaps.core.*; 
     11    import com.modestmaps.geo.Location; 
     12    import com.stamen.twisted.*; 
    1313 
    14        import flash.geom.Point; 
    15        import flash.display.Sprite; 
    16        import flash.utils.Dictionary; 
    17        import flash.geom.Rectangle; 
    18        import flash.events.MouseEvent; 
    19        import flash.geom.Transform; 
    20        import flash.geom.Matrix; 
    21        import flash.events.Event; 
    22        import flash.display.Stage; 
    23          
    24        public class TileGrid extends Sprite 
    25        
    26            // Real maps use 256. 
    27            public static const TILE_WIDTH:Number = 256; 
    28            public static const TILE_HEIGHT:Number = 256; 
    29          
    30            protected var _map:Map; 
    31          
    32            protected var _width:Number; 
    33            protected var _height:Number; 
    34                protected var _draggable:Boolean;           
    35          
    36            // Row and column counts are kept up-to-date. 
    37            protected var _rows:int; 
    38            protected var _columns:int; 
    39            protected var _tiles:/*Tile*/Array; 
    40             
    41            // overlay markers 
    42            protected var markers:MarkerSet; 
    43             
    44            // Markers overlapping the currently-included set of tiles, hash of booleans 
    45            protected var _overlappingMarkers:Dictionary; 
    46          
    47            // Allow (true) or prevent (false) tiles to paint themselves. 
    48            protected var _paintingAllowed:Boolean; 
    49             
    50            // Starting point for the very first tile 
    51            protected var _initTilePoint:Point; 
    52            protected var _initTileCoord:Coordinate; 
    53             
    54            // the currently-native zoom level 
    55            public var zoomLevel:int; 
    56             
    57            // some limits on scrolling distance, initially set to none 
    58            protected var topLeftOutLimit:Coordinate; 
    59            protected var bottomRightInLimit:Coordinate; 
    60             
    61            protected var _startingWellPosition:Point; 
    62          
    63            // Tiles attach to the well. 
    64            protected var _well:Sprite; 
    65             
    66            // Mask clip to hide outside edges of tiles. 
    67            protected var _mask:Sprite; 
    68          
    69            // Active when the well is being dragged on the stage. 
    70            protected var _wellDragTask:DelayedCall; 
    71             
    72            // Defines a ring of extra, masked-out tiles around 
    73            // the edges of the well, acting as a pre-fetching cache. 
    74            // High tileBuffer may hurt performance. 
    75            protected var _tileBuffer:int = 0; 
    76          
    77            // Who do we get our Map graphics from? 
    78            protected var _mapProvider:IMapProvider; 
    79          
    80                protected var _drawWell:Boolean = true
    81                protected var _drawGridArea:Boolean = true
    82          
    83            public function init(width:Number, height:Number, draggable:Boolean, provider:IMapProvider, map:Map):void 
    84            { 
    85                if (!Reactor.running()) 
    86                    throw new Error('com.modestmaps.core.TileGrid.init(): com.stamen.Twisted.Reactor really ought to be running at this point. Seriously.'); 
    87          
    88                _map = map; 
    89                _width = width; 
    90                _height = height; 
    91                _draggable = draggable; 
    92                _mapProvider = provider; 
    93             
    94                buildWell(); 
    95                buildMask(); 
    96                allowPainting(true); 
    97                redraw();    
    98                 
    99                _overlappingMarkers = new Dictionary(true); 
    100                markers = new MarkerSet(this); 
    101                 
    102                setInitialTile(new Coordinate(0,0,1), new Point(-TILE_WIDTH, -TILE_HEIGHT)); 
    103                initializeTiles(); 
    104            } 
    105             
    106           /** 
    107            * Set initTileCoord and initTilePoint for use by initializeTiles(). 
     14    import flash.geom.Point; 
     15    import flash.display.Sprite; 
     16    import flash.utils.Dictionary; 
     17    import flash.geom.Rectangle; 
     18    import flash.events.MouseEvent; 
     19    import flash.geom.Transform; 
     20    import flash.geom.Matrix; 
     21    import flash.events.Event; 
     22    import flash.display.Stage; 
     23     
     24    public class TileGrid extends Sprite 
     25   
     26        // Real maps use 256. 
     27        public static const TILE_WIDTH:Number = 256; 
     28        public static const TILE_HEIGHT:Number = 256; 
     29     
     30        protected var _map:Map; 
     31     
     32        protected var _width:Number; 
     33        protected var _height:Number; 
     34        protected var _draggable:Boolean;          
     35     
     36        // Row and column counts are kept up-to-date. 
     37        protected var _rows:int; 
     38        protected var _columns:int; 
     39        protected var _tiles:/*Tile*/Array; 
     40         
     41        // overlay markers 
     42        protected var markers:MarkerSet; 
     43         
     44        // Markers overlapping the currently-included set of tiles, hash of booleans 
     45        protected var _overlappingMarkers:Dictionary; 
     46     
     47        // Allow (true) or prevent (false) tiles to paint themselves. 
     48        protected var _paintingAllowed:Boolean; 
     49         
     50        // Starting point for the very first tile 
     51        protected var _initTilePoint:Point; 
     52        protected var _initTileCoord:Coordinate; 
     53         
     54        // the currently-native zoom level 
     55        public var zoomLevel:int; 
     56         
     57        // some limits on scrolling distance, initially set to none 
     58        protected var topLeftOutLimit:Coordinate; 
     59        protected var bottomRightInLimit:Coordinate; 
     60         
     61        protected var _startingWellPosition:Point; 
     62     
     63        // Tiles attach to the well. 
     64        protected var _well:Sprite; 
     65         
     66        // Mask clip to hide outside edges of tiles. 
     67        protected var _mask:Sprite; 
     68     
     69        // Active when the well is being dragged on the stage. 
     70        protected var _wellDragTask:DelayedCall; 
     71         
     72        // Defines a ring of extra, masked-out tiles around 
     73        // the edges of the well, acting as a pre-fetching cache. 
     74        // High tileBuffer may hurt performance. 
     75        protected var _tileBuffer:int = 0; 
     76     
     77        // Who do we get our Map graphics from? 
     78        protected var _mapProvider:IMapProvider; 
     79     
     80        protected var _wellColor:uint = 0x000000
     81        protected var _gridAreaColor:uint = 0x000000
     82     
     83        public function init(width:Number, height:Number, draggable:Boolean, provider:IMapProvider, map:Map):void 
     84        { 
     85            if (!Reactor.running()) 
     86                throw new Error('com.modestmaps.core.TileGrid.init(): com.stamen.Twisted.Reactor really ought to be running at this point. Seriously.'); 
     87     
     88            _map = map; 
     89            _width = width; 
     90            _height = height; 
     91            _draggable = draggable; 
     92            _mapProvider = provider; 
     93         
     94            buildWell(); 
     95            buildMask(); 
     96            allowPainting(true); 
     97            redraw();    
     98             
     99            _overlappingMarkers = new Dictionary(true); 
     100            markers = new MarkerSet(this); 
     101             
     102            setInitialTile(new Coordinate(0,0,1), new Point(-TILE_WIDTH, -TILE_HEIGHT)); 
     103            initializeTiles(); 
     104        } 
     105         
     106       /** 
     107        * Set initTileCoord and initTilePoint for use by initializeTiles(). 
    108108            */ 
    109109            public function setInitialTile(coord:Coordinate, point:Point):void 
     
    119119            public function resetTiles(coord:Coordinate, point:Point):void 
    120120            { 
    121 //             trace('resetting tiles...'); 
     121                //trace('resetting tiles...'); 
    122122                if (!_tiles) 
    123                        
    124 //                             trace("no _tiles for resetTiles() yet"); 
     123               
     124                    //trace("no _tiles for resetTiles() yet"); 
    125125                    setInitialTile(coord, point); 
    126126                    return; 
    127127                } 
    128128             
    129 //             trace('REALLY resetting tiles...'); 
     129                //trace('REALLY resetting tiles...'); 
    130130 
    131                        try { 
    132                        var initTile:Tile; 
    133                        var condemnedTiles:/*Tile*/Array = activeTiles(); 
     131                try { 
     132                    var initTile:Tile; 
     133                    var condemnedTiles:/*Tile*/Array = activeTiles(); 
    134134                 
    135                        for (var i:int = 0; i < condemnedTiles.length; i++) 
    136                        { 
    137                            condemnedTiles[i].expire(); 
    138                        } 
     135                    for (var i:int = 0; i < condemnedTiles.length; i++) 
     136                    { 
     137                        condemnedTiles[i].expire(); 
     138                    } 
    139139                 
    140                        Reactor.callLater(condemnationDelay(), destroyTiles, condemnedTiles); 
     140                    Reactor.callLater(condemnationDelay(), destroyTiles, condemnedTiles); 
    141141 
    142                                zoomLevel = coord.zoom;                                 
    143                        initTile = createTile(this, coord, point.x, point.y); 
     142                    zoomLevel = coord.zoom;                            
     143                    initTile = createTile(this, coord, point.x, point.y); 
    144144                                                                                   
    145                        centerWell(true); 
     145                    centerWell(true); 
    146146                 
    147                        _rows = 1; 
    148                        _columns = 1; 
     147                    _rows = 1; 
     148                    _columns = 1; 
    149149                 
    150                        allocateTiles(); 
    151                        
    152                    catch(e:Error) { 
    153                        trace(e.getStackTrace()); 
    154                    } 
     150                    allocateTiles(); 
     151               
     152                catch(e:Error) { 
     153                    trace(e.getStackTrace()); 
     154                } 
    155155                 
    156156            } 
     
    165165//              trace('initializing...'); 
    166166 
    167             if (!_initTileCoord) { 
    168                 trace("no _initTileCoord"); 
    169                 return;                        
    170             }         
     167                if (!_initTileCoord) { 
     168                    trace("no _initTileCoord"); 
     169                    return;                    
     170                }             
    171171                                         
    172172                // impose some limits 
     
    175175                bottomRightInLimit = _mapProvider.outerLimits()[1]; 
    176176                 
    177 //             trace('REALLY initializing, like _tiles and shit...'); 
    178                  
    179             _tiles = []; 
     177                //trace('REALLY initializing, like _tiles and shit...'); 
     178                 
     179                _tiles = []; 
    180180                initTile = createTile(this, _initTileCoord, _initTilePoint.x, _initTilePoint.y); 
    181181                                                                           
     
    221221                _well.name = 'well'; 
    222222                 
    223                         if (_draggable) { 
    224                                 _well.mouseChildren = false; 
    225                                 _well.addEventListener(MouseEvent.MOUSE_DOWN, startWellDrag); 
    226                                 _well.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag); 
    227                         } 
     223                if (_draggable)  
     224                { 
     225                    _well.mouseChildren = false; 
     226                    _well.addEventListener(MouseEvent.MOUSE_DOWN, startWellDrag); 
     227                    _well.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag); 
     228                } 
    228229                 
    229230                addChild(_well);                 
     
    259260         
    260261                if (_mapProvider.geometry() != previousGeometry) 
    261                        
     262               
    262263                    markers.initializeIndex(); 
    263264                    markers.indexAtZoom(zoomLevel); 
     
    287288            protected function destroyTile(tile:Tile):void 
    288289            { 
    289 //             trace('Destroying tile: '+tile.toString()); 
     290                //trace('Destroying tile: '+tile.toString()); 
    290291                _tiles.splice(tileIndex(tile), 1); 
    291292                tile.cancelDraw(); 
     
    299300            { 
    300301                if (tiles.length) 
    301                        
     302               
    302303                    destroyTile(Tile(tiles.shift())); 
    303304                    Reactor.callLater(0, destroyTiles, tiles); 
     
    448449                max.y = _well.y - max.y; 
    449450                 
    450 ///            trace('min/max for drag: '+min+', '+max+' ('+topLeftOutLimit+', '+bottomRightInLimit+')'); 
     451                //trace('min/max for drag: '+min+', '+max+' ('+topLeftOutLimit+', '+bottomRightInLimit+')'); 
    451452                 
    452453                // weird negative edge conditions, limit all movement on an axis 
     
    466467            public function startWellDrag(event:MouseEvent):void 
    467468            { 
    468                        stage.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag);              
     469                stage.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag);             
    469470                stage.addEventListener(MouseEvent.MOUSE_OUT, stopWellDrag); 
    470471 
     
    498499                                        : bounds.max.y); 
    499500                                         
    500 //             trace('Drag bounds would be: '+xMin+', '+yMin+', '+xMax+', '+yMax); 
    501                 
    502                _startingWellPosition = new Point(_well.x, _well.y); 
    503 //             trace('Starting well position: '+_startingWellPosition.toString()); 
     501                //trace('Drag bounds would be: '+xMin+', '+yMin+', '+xMax+', '+yMax); 
     502                                 
     503                _startingWellPosition = new Point(_well.x, _well.y); 
     504                //trace('Starting well position: '+_startingWellPosition.toString()); 
    504505                 
    505506                _map.onStartPan(); 
     
    519520                _map.onStopPan(); 
    520521                if (_wellDragTask) { 
    521                     _wellDragTask.call(); // issue final onPan, notify markers, etc. 
     522                    _wellDragTask.call();   // issue final onPan, notify markers, etc. 
    522523                    _wellDragTask.cancel(); // but cancel the follow-on call 
    523524                } 
     
    550551                    normalizeWell(); 
    551552                    allocateTiles(); 
    552 //                 trace('New well scale: '+_well.scaleX.toString()); 
     553                    //trace('New well scale: '+_well.scaleX.toString()); 
    553554                } 
    554555            } 
     
    627628                var matches:Array = new Array(); 
    628629                if (_tiles) { 
    629                        matches = _tiles.filter(function(item:Tile, index:int, list:Array):Boolean { return item.isActive();} ); 
    630                                if (matches.length == 0) { 
    631                                        trace("no matches for active tiles... DOOM!"); 
    632                                
    633                    } 
     630                    matches = _tiles.filter(function(item:Tile, index:int, list:Array):Boolean { return item.isActive();} ); 
     631                    if (matches.length == 0) { 
     632                        trace("no matches for active tiles... DOOM!"); 
     633                   
     634                } 
    634635                return matches; 
    635636            } 
     
    742743                centerWell(true); 
    743744         
    744                        trace("well scale: " + _well.scaleX + " " + _well.scaleY); 
     745                trace("well scale: " + _well.scaleX + " " + _well.scaleY); 
    745746                if(Math.abs(_well.scaleX - 1.0) < 0.01) { 
    746747                    active = activeTiles(); 
     
    773774                    //trace('This is where we scale the whole well by '+zoomAdjust+' zoom levels: '+(100 / scaleAdjust)+'%'); 
    774775 
    775                                var n:int; 
     776                    var n:int; 
    776777                    for (n  = 0; n < zoomAdjust; n += 1) 
    777                                
     778                   
    778779                        splitTiles(); 
    779780                        zoomLevel += 1; 
     
    781782                         
    782783                    for (n = 0; n > zoomAdjust; n -= 1) 
    783                                
     784                   
    784785                        mergeTiles(); 
    785786                        zoomLevel -= 1; 
     
    838839                // this should never happen 
    839840                if(!referenceTile) { 
    840                        trace("TileGrid problem - no reference tile"); 
     841                    trace("TileGrid problem - no reference tile"); 
    841842                    return; 
    842843                } 
     
    844845                // this should never happen either 
    845846                if(!referenceTile.coord) { 
    846                        trace("TileGrid problem - no coord in reference tile"); 
     847                    trace("TileGrid problem - no coord in reference tile"); 
    847848                    return; 
    848849                } 
     
    906907                // this should never happen 
    907908                if(!referenceTile) { 
    908                        throw new Error("no reference tile in mergeTiles()"); 
     909                    throw new Error("no reference tile in mergeTiles()"); 
    909910                } 
    910911 
    911912                // this should never happen either 
    912913                if(!referenceTile.coord) { 
    913                        throw new Error("no reference tile coord in mergeTiles()"); 
     914                    throw new Error("no reference tile coord in mergeTiles()"); 
    914915                } 
    915916         
     
    10091010                    newOverlappingMarkers[visible[i].id] = visible[i]; 
    10101011         
    1011                        var id:String; 
     1012                var id:String; 
    10121013                // check for newly-visible markers 
    10131014                for (id in newOverlappingMarkers) { 
     
    11021103                return function(a:Tile, b:Tile):Number 
    11031104                { 
    1104                        // TODO: can probably nix the sqrt if we're just sorting by distance 
    1105                        // FYI: this whole method isn't really ever used, it can probably just go away entirely 
     1105                    // TODO: can probably nix the sqrt if we're just sorting by distance 
     1106                    // FYI: this whole method isn't really ever used, it can probably just go away entirely 
    11061107                    var aDist:Number = Math.sqrt(Math.pow(a.center().x - p.x, 2) + Math.pow(a.center().y - p.y, 2)); 
    11071108                    var bDist:Number = Math.sqrt(Math.pow(b.center().x - p.x, 2) + Math.pow(b.center().y - p.y, 2)); 
     
    11171118                if(a.coord.row == b.coord.row) { 
    11181119                    return a.coord.column - b.coord.column; 
    1119                      
    11201120                } else { 
    11211121                    return a.coord.row - b.coord.row; 
    1122                      
    11231122                } 
    11241123            } 
     
    11311130                if(a.coord.column == b.coord.column) { 
    11321131                    return a.coord.row - b.coord.row; 
    1133                      
    11341132                } else { 
    11351133                    return a.coord.column - b.coord.column; 
    1136                      
    11371134                } 
    11381135            } 
     
    11631160            } 
    11641161 
    1165                 // set to false, and set drawGridArea to false, if you want the background swf color to show through 
    1166                public function set drawWell(draw:Boolean):void { 
    1167                        _drawWell = draw
    1168                        redrawWell(); 
    1169                
    1170                 // set to false, and set drawWell to false, if you want the background swf color to show through 
    1171                public function set drawGridArea(draw:Boolean):void { 
    1172                        _drawGridArea = draw
    1173                        redrawGridArea(); 
    1174                
     1162            /** you can probably set to a color with no alpha if you want the grid area color to show through */ 
     1163            public function set wellColor(color:uint):void { 
     1164                    _wellColor = color
     1165                    redrawWell(); 
     1166           
     1167            /** you can probably set to a color with no alpha if you want the background swf color to show through */ 
     1168            public function set drawGridArea(color:uint):void { 
     1169                    _gridAreaColor = color
     1170                    redrawGridArea(); 
     1171           
    11751172             
    11761173            protected function redraw():void { 
     
    11841181                with (graphics) 
    11851182                { 
    1186                         clear(); 
    1187                         if (_drawGridArea) { 
    1188                                 moveTo(0, 0); 
    1189                                 // lineStyle(2, 0x990099, 100); 
    1190                                 beginFill(0x666666, 0.2); 
    1191                                 lineTo(0, _height); 
    1192                                 lineTo(_width, _height); 
    1193                                 lineTo(_width, 0); 
    1194                                 lineTo(0, 0); 
    1195                                 endFill(); 
    1196                             } 
    1197                 } 
    1198             } 
    1199              
     1183                    clear(); 
     1184                    moveTo(0, 0); 
     1185                    // lineStyle(2, 0x990099, 100); 
     1186                    beginFill(_gridAreaColor); 
     1187                    lineTo(0, _height); 
     1188                    lineTo(_width, _height); 
     1189                    lineTo(_width, 0); 
     1190                    lineTo(0, 0); 
     1191                    endFill(); 
     1192                } 
     1193            } 
     1194         
    12001195            protected function redrawMask():void 
    1201                
     1196           
    12021197                with (_mask.graphics) 
    12031198                { 
    1204                         clear(); 
    1205                         moveTo(0, 0); 
    1206 //                      lineStyle(2, 0x990099, 100); 
    1207                         lineStyle(); 
    1208                         beginFill(0x000000, 0); 
    1209                         lineTo(0, _height); 
    1210                         lineTo(_width, _height); 
    1211                         lineTo(_width, 0); 
    1212                         lineTo(0, 0); 
    1213                         endFill(); 
    1214                     } 
     1199                    clear(); 
     1200                    moveTo(0, 0); 
     1201                    lineStyle(); 
     1202                    beginFill(0x000000, 0); 
     1203                    lineTo(0, _height); 
     1204                    lineTo(_width, _height); 
     1205                    lineTo(_width, 0); 
     1206                    lineTo(0, 0); 
     1207                    endFill(); 
     1208                } 
    12151209            } 
    12161210 
    12171211            protected function redrawWell():void 
    1218                
     1212           
    12191213                // note that _well (0, 0) is grid center. 
    12201214                with (_well.graphics) 
    12211215                { 
    1222                         clear(); 
    1223                         if (_drawWell) { 
    1224                             moveTo(_width/-2, _height/-2); 
    1225                             lineStyle(); 
    1226                             beginFill(0x666666, 0.2); 
    1227                             lineTo(_width/-2, _height/2); 
    1228                             lineTo(_width/2, _height/2); 
    1229                             lineTo(_width/2, _height/-2); 
    1230                             lineTo(_width/-2, _height/-2); 
    1231                             endFill(); 
    1232                         } 
     1216                    clear(); 
     1217                    moveTo(_width/-2, _height/-2); 
     1218                    lineStyle(); 
     1219                    beginFill(_wellColor); 
     1220                    lineTo(_width/-2, _height/2); 
     1221                    lineTo(_width/2, _height/2); 
     1222                    lineTo(_width/2, _height/-2); 
     1223                    lineTo(_width/-2, _height/-2); 
     1224                    endFill(); 
    12331225                } 
    12341226            } 
  • trunk/as3/lib/com/modestmaps/Map.as

    r292 r297  
    1010 * 
    1111 * @description Map is the base class and interface for Modest Maps. 
    12  *                             Correctly attaching an instance of this Sprite subclass  
    13  *                             should result in a pannable map. Controls and event  
    14  *                             handlers must be added separately. 
     12 *                 Correctly attaching an instance of this Sprite subclass  
     13 *                 should result in a pannable map. Controls and event  
     14 *                 handlers must be added separately. 
    1515 * 
    1616 * @usage <code> 
     
    2727package com.modestmaps 
    2828{ 
    29        import com.modestmaps.core.*; 
    30        import com.modestmaps.events.MapEvent; 
    31        import com.modestmaps.events.MarkerEvent; 
    32        import com.modestmaps.geo.Location; 
    33        import com.modestmaps.mapproviders.IMapProvider; 
    34        import com.stamen.twisted.DelayedCall; 
    35        import com.stamen.twisted.Reactor; 
    36          
    37        import flash.display.Sprite; 
    38        import flash.geom.Point; 
    39        import flash.events.MouseEvent; 
    40        import flash.external.ExternalInterface; 
    41        import flash.events.Event; 
    42          
    43        public class Map extends Sprite 
    44        
    45                public static const PAN:String = 'pan'; 
    46                public static const ZOOM:String = 'zoom'; 
    47  
    48            protected var __width:Number = 320; 
    49            protected var __height:Number = 240; 
    50            protected var __draggable:Boolean = true; 
    51             
    52            // pending animation steps, array of {type:'pan'/'zoom', amount:Point/Number, redraw:Boolean} 
    53            protected var __animSteps:Array; 
    54          
    55            // associated animation call 
    56            protected var __animTask:DelayedCall; 
    57          
    58            // frames-per-2x-zoom 
    59            public var zoomFrames:Number = 6; 
    60             
    61            // frames-per-full-pan 
    62            public var panFrames:Number = 12; 
    63             
    64            protected var __startingPosition:Point; 
    65            protected var __currentPosition:Point; 
    66            protected var __startingZoom:Number; 
    67            protected var __currentZoom:Number; 
    68          
    69            // das grid 
    70            public var grid:TileGrid; 
    71          
    72            // Who do we get our Map graphics from? 
    73            protected var __mapProvider:IMapProvider; 
    74          
    75                /** htmlText to be added to a label - listen for MapEvent.COPYRIGHT_CHANGED */ 
    76                public var copyright:String = ""; 
    77          
    78           /* 
    79            * Initialize the map: set properties, add a tile grid, draw it. 
    80            * This method must be called before the map can be used! 
    81            * Default extent covers the entire globe, (+/-85, +/-180). 
    82            * 
    83            * @param    Width of map, in pixels. 
    84            * @param    Height of map, in pixels. 
    85            * @param    Whether the map can be dragged or not. 
    86            * @param    Desired map provider, e.g. Blue Marble. 
    87            * 
    88            * @see com.modestmaps.core.TileGrid 
    89            */ 
    90            public function init(width:Number, height:Number, draggable:Boolean, provider:IMapProvider):void 
    91            { 
    92                if (!Reactor.running()) 
    93                
    94                        // should this really be fatal? 
    95                        trace('com.modestmaps.Map.init(): com.stamen.Twisted.Reactor ought to be running at this point.'); 
    96                        Reactor.run(this, 100); 
    97                
    98  
    99                         try { 
    100                         ExternalInterface.addCallback("setCopyright", setCopyright); 
    101                         } 
    102                         catch (error:Error) { 
    103                                 trace("problem adding setCopyright as callback in Map.as"); 
    104                                trace(error.getStackTrace()); 
    105                         } 
    106                   
    107  
    108                __animSteps = new Array(); 
    109  
    110                setSize(width, height); 
    111  
    112                        grid = new TileGrid(); 
    113                addChild(grid); // before init, so init can add mouse handlers to stage 
    114                grid.init(__width, __height, draggable, provider, this); 
    115  
    116                setMapProvider(provider); 
    117  
    118                        var extent:MapExtent = new MapExtent(85, -85, 180, -180); 
    119                setExtent(extent); 
    120                 
    121            } 
    122          
    123           /* 
    124            * Based on an array of locations, determine appropriate map 
    125            * bounds using calculateMapExtent(), and inform the grid of 
    126            * tile coordinate and point by calling grid.resetTiles(). 
    127            * Resulting map extent will ensure that all passed locations 
    128            * are visible. 
    129            * 
    130            * @param    Array of locations. 
    131            * 
    132            * @see com.modestmaps.Map#calculateMapExtent 
    133            * @see com.modestmaps.core.TileGrid#resetTiles 
    134            */ 
    135            public function setExtent(extent:MapExtent):void 
    136            { 
    137                var position:MapPosition = extentPosition(extent); 
    138                // tell grid what the rock is cooking 
    139                grid.resetTiles(position.coord, position.point); 
    140                onExtentChanged(this.getExtent()); 
     29    import com.modestmaps.core.*; 
     30    import com.modestmaps.events.MapEvent; 
     31    import com.modestmaps.events.MarkerEvent; 
     32    import com.modestmaps.geo.Location; 
     33    import com.modestmaps.mapproviders.IMapProvider; 
     34    import com.stamen.twisted.DelayedCall; 
     35    import com.stamen.twisted.Reactor; 
     36     
     37    import flash.display.Sprite; 
     38    import flash.geom.Point; 
     39    import flash.events.MouseEvent; 
     40    import flash.external.ExternalInterface; 
     41    import flash.events.Event; 
     42     
     43    public class Map extends Sprite 
     44   
     45        public static const PAN:String = 'pan'; 
     46        public static const ZOOM:String = 'zoom'; 
     47 
     48        protected var __width:Number = 320; 
     49        protected var __height:Number = 240; 
     50        protected var __draggable:Boolean = true; 
     51         
     52        // pending animation steps, array of {type:'pan'/'zoom', amount:Point/Number, redraw:Boolean} 
     53        protected var __animSteps:Array; 
     54     
     55        // associated animation call 
     56        protected var __animTask:DelayedCall; 
     57     
     58        // frames-per-2x-zoom 
     59        public var zoomFrames:Number = 6; 
     60         
     61        // frames-per-full-pan 
     62        public var panFrames:Number = 12; 
     63         
     64        protected var __startingPosition:Point; 
     65        protected var __currentPosition:Point; 
     66        protected var __startingZoom:Number; 
     67        protected var __currentZoom:Number; 
     68     
     69        // das grid 
     70        public var grid:TileGrid; 
     71     
     72        // Who do we get our Map graphics from? 
     73        protected var __mapProvider:IMapProvider; 
     74     
     75        /** htmlText to be added to a label - listen for MapEvent.COPYRIGHT_CHANGED */ 
     76        public var copyright:String = ""; 
     77     
     78       /* 
     79        * Initialize the map: set properties, add a tile grid, draw it. 
     80        * This method must be called before the map can be used! 
     81        * Default extent covers the entire globe, (+/-85, +/-180). 
     82        * 
     83        * @param    Width of map, in pixels. 
     84        * @param    Height of map, in pixels. 
     85        * @param    Whether the map can be dragged or not. 
     86        * @param    Desired map provider, e.g. Blue Marble. 
     87        * 
     88        * @see com.modestmaps.core.TileGrid 
     89        */ 
     90        public function init(width:Number, height:Number, draggable:Boolean, provider:IMapProvider):void 
     91        { 
     92            if (!Reactor.running()) 
     93           
     94                // should this really be fatal? 
     95                trace('com.modestmaps.Map.init(): com.stamen.Twisted.Reactor ought to be running at this point.'); 
     96                Reactor.run(this, 100); 
     97           
     98 
     99            // see setCopyright for more details 
     100            try { 
     101                ExternalInterface.addCallback("setCopyright", setCopyright); 
     102            } 
     103            catch (error:Error) { 
     104                trace("problem adding setCopyright as callback in Map.as"); 
     105                trace(error.getStackTrace()); 
     106            } 
     107 
     108            __animSteps = new Array(); 
     109 
     110            setSize(width, height); 
     111 
     112            grid = new TileGrid(); 
     113            addChild(grid); // before init, so init can add mouse handlers to stage 
     114            grid.init(__width, __height, draggable, provider, this); 
     115 
     116            setMapProvider(provider); 
     117 
     118            var extent:MapExtent = new MapExtent(85, -85, 180, -180); 
     119            setExtent(extent); 
     120             
     121        } 
     122     
     123       /* 
     124        * Based on an array of locations, determine appropriate map 
     125        * bounds using calculateMapExtent(), and inform the grid of 
     126        * tile coordinate and point by calling grid.resetTiles(). 
     127        * Resulting map extent will ensure that all passed locations 
     128        * are visible. 
     129        * 
     130        * @param    Array of locations. 
     131        * 
     132        * @see com.modestmaps.Map#calculateMapExtent 
     133        * @see com.modestmaps.core.TileGrid#resetTiles 
     134        */ 
     135        public function setExtent(extent:MapExtent):void 
     136        { 
     137            var position:MapPosition = extentPosition(extent); 
     138            // tell grid what the rock is cooking 
     139            grid.resetTiles(position.coord, position.point); 
     140            onExtentChanged(this.getExtent()); 
    141141            Reactor.callNextFrame(callCopyright); 
    142            } 
    143             
    144           /* 
    145            * Based on a location and zoom level, determine appropriate initial 
    146            * tile coordinate and point using calculateMapCenter(), and inform 
    147            * the grid of tile coordinate and point by calling grid.resetTiles(). 
    148            * 
    149            * @param    Location of center. 
    150            * @param    Desired zoom level. 
    151            * 
    152            * @see com.modestmaps.Map#calculateMapExtent 
    153            * @see com.modestmaps.core.TileGrid#resetTiles 
    154            */ 
    155            public function setCenterZoom(location:Location, zoom:Number):void 
    156            { 
    157                var center:MapPosition = coordinatePosition(__mapProvider.locationCoordinate(location).zoomTo(zoom)); 
    158                // tell grid what the rock is cooking 
    159