Changeset 337

Show
Ignore:
Timestamp:
08/11/07 20:50:59 (1 year ago)
Author:
tom
Message:

cleaned up dragging listeners (and tab formatting) in TileGrid to help with MarkerClip? weirdness

Files:

Legend:

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

    r335 r337  
    1616        import flash.utils.Dictionary; 
    1717        import flash.display.DisplayObject; 
     18        import flash.utils.getTimer; 
    1819         
    1920        /** This is different from the as2 version for now, because 
     
    2425        public class MarkerClip extends Sprite 
    2526        { 
    26                 // TODO: mask me! 
     27                // TODO: mask me? 
    2728            private var map:Map; 
    2829            private var starting:Point; 
    2930            private var locations:Dictionary = new Dictionary(); 
    30             private var markers:Array = []; 
     31            private var markers:Array = []; // all markers 
    3132            private var markersByName:Object = {}; 
    3233         
     
    7475                } 
    7576                delete locations[marker]; 
     77                delete markersByName[marker.name]; 
    7678            } 
    7779                 
    7880            private function updateClips(event:Event=null):void 
    7981            { 
     82                var t:int = flash.utils.getTimer(); 
    8083                for each (var marker:DisplayObject in markers) { 
    8184                        updateClip(marker); 
    8285                } 
     86                trace("reprojected all markers in " + (flash.utils.getTimer() - t) + "ms"); 
    8387            } 
    8488             
     
    8690            { 
    8791                var location:Location = locations[marker]; 
    88                 var point:Point = map.locationPoint(location,this); 
     92                var point:Point = map.locationPoint(location, this); 
    8993                marker.x = point.x; 
    9094                marker.y = point.y; 
     
    9498            { 
    9599                if (!getChildByName(event.marker)) { 
    96                         addChild(getMarker(event.marker)); 
     100                        var marker:DisplayObject = getMarker(event.marker); 
     101                        addChild(marker); 
    97102                }  
    98103            } 
     
    101106            { 
    102107                if (getChildByName(event.marker)) { 
    103                         removeChild(getMarker(event.marker)); 
     108                        var marker:DisplayObject = getMarker(event.marker); 
     109                        removeChild(marker); 
    104110                }  
    105111            } 
  • trunk/as3/lib/com/modestmaps/core/TileGrid.as

    r336 r337  
    7878        protected var _mapProvider:IMapProvider; 
    7979     
    80         protected var _drawWell:Boolean = true; 
    81         protected var _drawGridArea:Boolean = true; 
     80        protected var _drawWell:Boolean = true; 
     81        protected var _drawGridArea:Boolean = true; 
    8282     
    8383        public function init(width:Number, height:Number, draggable:Boolean, provider:IMapProvider, map:Map):void 
     
    111111            _initTileCoord = coord; 
    112112            _initTilePoint = point; 
    113 //            Reactor.callNextFrame(initializeTiles); 
    114113        } 
    115114         
     
    119118        public function resetTiles(coord:Coordinate, point:Point):void 
    120119        { 
    121                 //trace('resetting tiles...'); 
    122120            if (!_tiles) 
    123121                { 
    124                     //trace("no _tiles for resetTiles() yet"); 
    125122                setInitialTile(coord, point); 
    126123                return; 
    127124            } 
    128125         
    129                 //trace('REALLY resetting tiles...'); 
     126            try { 
     127                var initTile:Tile; 
     128                var condemnedTiles:/*Tile*/Array = activeTiles(); 
     129     
     130                for (var i:int = 0; i < condemnedTiles.length; i++) 
     131                { 
     132                    condemnedTiles[i].expire(); 
     133                } 
     134     
     135                Reactor.callLater(condemnationDelay(), destroyTiles, condemnedTiles); 
    130136 
    131                 try { 
    132                     var initTile:Tile; 
    133                     var condemnedTiles:/*Tile*/Array = activeTiles(); 
    134          
    135                     for (var i:int = 0; i < condemnedTiles.length; i++) 
    136                     { 
    137                         condemnedTiles[i].expire(); 
    138                     } 
    139          
    140                     Reactor.callLater(condemnationDelay(), destroyTiles, condemnedTiles); 
    141  
    142                     zoomLevel = coord.zoom;                 
    143                     initTile = createTile(this, coord, point.x, point.y); 
    144                                                                            
    145                     centerWell(true); 
    146          
    147                     _rows = 1; 
    148                     _columns = 1; 
    149          
    150                     allocateTiles(); 
    151                 } 
    152                 catch(e:Error) { 
    153                     trace(e.getStackTrace()); 
    154                 } 
     137                zoomLevel = coord.zoom;                 
     138                initTile = createTile(this, coord, point.x, point.y); 
     139                                                                       
     140                centerWell(true); 
     141     
     142                _rows = 1; 
     143                _columns = 1; 
     144     
     145                allocateTiles(); 
     146            } 
     147            catch(e:Error) { 
     148                trace(e.getStackTrace()); 
     149            } 
    155150             
    156151        } 
     
    163158            var initTile:Tile; 
    164159             
    165 //            trace('initializing...'); 
    166  
    167                 if (!_initTileCoord) { 
    168                     trace("no _initTileCoord"); 
    169                     return;             
    170                 }            
     160            if (!_initTileCoord) { 
     161                trace("no _initTileCoord"); 
     162                return;             
     163            }            
    171164                          
    172165            // impose some limits 
     
    175168            bottomRightInLimit = _mapProvider.outerLimits()[1]; 
    176169             
    177                 //trace('REALLY initializing, like _tiles and shit...'); 
    178              
    179                 _tiles = []; 
     170            _tiles = []; 
    180171            initTile = createTile(this, _initTileCoord, _initTilePoint.x, _initTilePoint.y); 
    181172                                                                       
     
    199190        { 
    200191            var marker:Marker = new Marker(id, coord, location); 
    201             //trace('Marker '+id+': '+coord.toString()); 
    202192            markers.put(marker); 
    203193     
     
    221211            _well.name = 'well'; 
    222212             
    223                 if (_draggable)  
    224                
    225                     _well.mouseChildren = false; 
    226                     _well.addEventListener(MouseEvent.MOUSE_DOWN, startWellDrag); 
    227                     _well.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag); 
    228                
     213            if (_draggable)  
     214           
     215                _well.mouseChildren = false; 
     216                _well.addEventListener(MouseEvent.MOUSE_DOWN, startWellDrag); 
     217                _well.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag); 
     218           
    229219             
    230220            addChild(_well);             
     
    240230            _mask.name = 'mask'; 
    241231            // as3 masks need to be child, so add the mask to the grid not the well 
    242                 // because well children are all tiles 
    243                 addChild(_mask); 
     232            // because well children are all tiles 
     233            addChild(_mask); 
    244234            this.mask = _mask; 
    245235        } 
     
    260250     
    261251            if (_mapProvider.geometry() != previousGeometry) 
    262                
     252           
    263253                markers.initializeIndex(); 
    264254                markers.indexAtZoom(zoomLevel); 
     
    288278        protected function destroyTile(tile:Tile):void 
    289279        { 
    290                 //trace('Destroying tile: '+tile.toString()); 
    291280            _tiles.splice(tileIndex(tile), 1); 
    292281            tile.cancelDraw(); 
     
    300289        { 
    301290            if (tiles.length) 
    302                
     291           
    303292                destroyTile(Tile(tiles.shift())); 
    304293                Reactor.callLater(0, destroyTiles, tiles); 
     
    448437            max.x = _well.x - max.x; 
    449438            max.y = _well.y - max.y; 
    450              
    451                 //trace('min/max for drag: '+min+', '+max+' ('+topLeftOutLimit+', '+bottomRightInLimit+')'); 
    452              
     439                         
    453440            // weird negative edge conditions, limit all movement on an axis 
    454441            if(min.x > max.x) 
     
    467454        public function startWellDrag(event:MouseEvent):void 
    468455        { 
    469                 stage.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag);             
    470             stage.addEventListener(MouseEvent.MOUSE_OUT, stopWellDrag); 
     456            stage.addEventListener(MouseEvent.MOUSE_UP, stopWellDrag);             
     457            stage.addEventListener(Event.MOUSE_LEAVE, stopWellDrag); 
    471458 
    472459            var bounds:Bounds = getWellBounds(true); 
     
    499486                                    : bounds.max.y); 
    500487                                     
    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()); 
     488            _startingWellPosition = new Point(_well.x, _well.y); 
    505489             
    506490            _map.onStartPan(); 
     
    514498        * Halts _wellDragTask. 
    515499        */ 
    516         public function stopWellDrag(event:MouseEvent):void 
    517         { 
    518             stage.removeEventListener(MouseEvent.MOUSE_OUT, stopWellDrag); 
     500        public function stopWellDrag(event:Event):void 
     501        { 
     502            stage.removeEventListener(MouseEvent.MOUSE_UP, stopWellDrag);             
     503            stage.removeEventListener(Event.MOUSE_LEAVE, stopWellDrag); 
    519504 
     505            if (_wellDragTask) { 
     506                _wellDragTask.call();   // issue final onPan, notify markers, etc. 
     507                _wellDragTask.cancel(); // but cancel the follow-on call 
     508            } 
    520509            _map.onStopPan(); 
    521             if (_wellDragTask) { 
    522                     _wellDragTask.call();   // issue final onPan, notify markers, etc. 
    523                     _wellDragTask.cancel(); // but cancel the follow-on call 
    524                 } 
    525510            _well.stopDrag(); 
    526511     
     
    628613            var matches:Array = new Array(); 
    629614            if (_tiles) { 
    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                
     615                matches = _tiles.filter(function(item:Tile, index:int, list:Array):Boolean { return item.isActive();} ); 
     616                if (matches.length == 0) { 
     617                    trace("no matches for active tiles... DOOM!"); 
     618               
     619           
    635620            return matches; 
    636621        } 
     
    774759                //trace('This is where we scale the whole well by '+zoomAdjust+' zoom levels: '+(100 / scaleAdjust)+'%'); 
    775760 
    776                     var n:int; 
     761                var n:int; 
    777762                for (n  = 0; n < zoomAdjust; n += 1) 
    778                    
     763               
    779764                    splitTiles(); 
    780765                    zoomLevel += 1; 
     
    782767                     
    783768                for (n = 0; n > zoomAdjust; n -= 1) 
    784                    
     769               
    785770                    mergeTiles(); 
    786771                    zoomLevel -= 1; 
     
    839824            // this should never happen 
    840825            if(!referenceTile) { 
    841                     trace("TileGrid problem - no reference tile"); 
     826                trace("TileGrid problem - no reference tile"); 
    842827                return; 
    843828            } 
     
    845830            // this should never happen either 
    846831            if(!referenceTile.coord) { 
    847                     trace("TileGrid problem - no coord in reference tile"); 
     832                trace("TileGrid problem - no coord in reference tile"); 
    848833                return; 
    849834            } 
     
    907892            // this should never happen 
    908893            if(!referenceTile) { 
    909                     throw new Error("no reference tile in mergeTiles()"); 
     894                throw new Error("no reference tile in mergeTiles()"); 
    910895            } 
    911896 
    912897            // this should never happen either 
    913898            if(!referenceTile.coord) { 
    914                     throw new Error("no reference tile coord in mergeTiles()"); 
     899                throw new Error("no reference tile coord in mergeTiles()"); 
    915900            } 
    916901     
     
    11031088            return function(a:Tile, b:Tile):Number 
    11041089            { 
    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 
     1090                // TODO: can probably nix the sqrt if we're just sorting by distance 
     1091                // FYI: this whole method isn't really ever used, it can probably just go away entirely 
    11071092                var aDist:Number = Math.sqrt(Math.pow(a.center().x - p.x, 2) + Math.pow(a.center().y - p.y, 2)); 
    11081093                var bDist:Number = Math.sqrt(Math.pow(b.center().x - p.x, 2) + Math.pow(b.center().y - p.y, 2)); 
     
    11601145        } 
    11611146 
    1162          // set to false, and set drawGridArea to false, if you want the background swf color to show through 
    1163          public function set drawWell(draw:Boolean):void { 
    1164              _drawWell = draw; 
     1147        /** 
     1148         * Set to false if you want the background swf color to show through 
     1149         * See TileGrid.drawGridArea too. 
     1150         */ 
     1151        public function set drawWell(draw:Boolean):void { 
     1152            _drawWell = draw; 
    11651153            redrawWell(); 
    11661154        } 
    1167          // set to false, and set drawWell to false, if you want the background swf color to show through 
    1168          public function set drawGridArea(draw:Boolean):void { 
     1155         
     1156        /**  
     1157         * Set to false if you want the background swf color to show through 
     1158         * See TileGrid.drawWell too. 
     1159         */ 
     1160        public function set drawGridArea(draw:Boolean):void { 
    11691161            _drawGridArea = draw; 
    11701162            redrawGridArea();