Changeset 624

Show
Ignore:
Timestamp:
07/20/08 19:52:48 (2 months ago)
Author:
tom
Message:

added provider changed event, moved copyright stuff to separate class (with new injection technique)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/tom-tweenlite/lib/com/modestmaps/core/TileGrid.as

    r622 r624  
    605605                        else if (previousOpenRequests > 0 && openRequests.length == 0) { 
    606606                                dispatchEvent(new MapEvent(MapEvent.ALL_TILES_LOADED)); 
    607                                 trace("requesting redraw to take parent and child tiles off the stage if we haven't already"); 
     607                                // request redraw to take parent and child tiles off the stage if we haven't already 
    608608                                dirty = true; 
    609609                        } 
  • branches/tom-tweenlite/lib/com/modestmaps/events/MapEvent.as

    r569 r624  
    66{ 
    77        import com.modestmaps.core.MapExtent; 
     8        import com.modestmaps.mapproviders.IMapProvider; 
    89         
    910        import flash.events.Event; 
     
    3738                public var newExtent:MapExtent; 
    3839 
     40            public static const MAP_PROVIDER_CHANGED:String = 'mapProviderChanged'; 
     41                public var newProvider:IMapProvider; 
     42 
    3943            public static const BEGIN_TILE_LOADING:String = 'beginTileLoading'; 
    4044            public static const ALL_TILES_LOADED:String = 'alLTilesLoaded'; 
     
    5559                                        } 
    5660                                        break; 
     61                                case EXTENT_CHANGED: 
     62                                if (rest.length > 0 && rest[0] is MapExtent) { 
     63                                        newExtent = rest[0]; 
     64                                } 
     65                                        break;               
    5766                                case START_ZOOMING: 
    5867                                case STOP_ZOOMING: 
     
    7180                                } 
    7281                                        break;               
    73                                 case EXTENT_CHANGED: 
    74                                 if (rest.length > 0 && rest[0] is MapExtent) { 
    75                                         newExtent = rest[0]; 
    76                                 } 
    77                                         break;               
    7882                                case BEGIN_EXTENT_CHANGE: 
    7983                                if (rest.length > 0 && rest[0] is MapExtent) { 
     
    8185                                } 
    8286                                        break;               
     87                                case MAP_PROVIDER_CHANGED: 
     88                                if (rest.length > 0 && rest[0] is IMapProvider) { 
     89                                        newProvider = rest[0]; 
     90                                } 
    8391                        } 
    8492                         
  • branches/tom-tweenlite/lib/com/modestmaps/Map.as

    r622 r624  
    5050    [Event(name="panned",            type="com.modestmaps.events.MapEvent")] 
    5151    [Event(name="resized",           type="com.modestmaps.events.MapEvent")] 
    52     [Event(name="copyrightChanged",  type="com.modestmaps.events.MapEvent")] 
     52    [Event(name="mapProviderChanged",type="com.modestmaps.events.MapEvent")] 
    5353    [Event(name="beginExtentChange", type="com.modestmaps.events.MapEvent")] 
    5454    [Event(name="extentChanged",     type="com.modestmaps.events.MapEvent")] 
     
    7474            protected var mapProvider:IMapProvider; 
    7575         
    76                 /** htmlText to be added to a label - listen for MapEvent.COPYRIGHT_CHANGED */ 
    77                 public var copyright:String = ""; 
    78  
    7976                /** fraction of width/height to pan panLeft, panRight, panUp, panDown 
    8077                 * @default 0.333333333   
     
    115112                        addChild(markerClip); 
    116113 
    117                         try { 
    118                         ExternalInterface.addCallback("setCopyright", setCopyright); 
    119                         } 
    120                         catch (error:Error) { 
    121                                 //trace("problem adding setCopyright as callback in Map.as"); 
    122                                 //trace(error.getStackTrace()); 
    123                         } 
    124                          
    125114                        // if rest was passed in from super constructor in a subclass, 
    126115                        // it will be an array... 
     
    182171                grid.resetTiles(locationsCoordinate( [ extent.northWest, extent.southEast ] )); 
    183172                onExtentChanged(); 
    184             requestCopyrightUpdate(); 
    185173            } 
    186174             
     
    207195                grid.resetTiles(mapProvider.locationCoordinate(location).zoomTo(zoom)); 
    208196                onExtentChanged(); 
    209                 requestCopyrightUpdate(); 
    210197            } 
    211198            } 
     
    223210        public function setZoom(zoom:Number):void 
    224211        { 
    225                         if (zoom == grid.zoomLevel) { // do nothing! 
    226                                 return; 
     212                        if (zoom != grid.zoomLevel) { 
     213                                // TODO: if grid enforces this in enforceBounds, do we need to do it here too? 
     214                                grid.zoomLevel = Math.min(Math.max(zoom, grid.minZoom), grid.maxZoom); 
    227215                        } 
    228                         else { // else hard reset 
    229                                 onExtentChanging(); 
    230                                 // tell grid what the rock is cooking 
    231                                 grid.resetTiles(grid.centerCoordinate.zoomTo(zoom)); 
    232                                 onExtentChanged(); 
    233                                 requestCopyrightUpdate(); 
    234                         } 
    235         } 
     216        } 
     217 
     218                public function extentCoordinate(extent:MapExtent):Coordinate 
     219                { 
     220                        return locationsCoordinate([ extent.northWest, extent.southEast ]); 
     221                } 
    236222                 
    237223                public function locationsCoordinate(locations:Array):Coordinate 
     
    336322         
    337323           /** 
    338             * Set new map size, call onResized(). 
    339             * 
    340             * @param    New map width. 
    341             * @param    New map height. 
    342             * 
    343             * @see com.modestmaps.Map#onResized 
    344             */ 
    345             public function setSize(width:Number, height:Number):void 
    346             { 
    347                 mapWidth = width; 
    348                 mapHeight = height; 
    349  
     324            * Set new map size, dispatch MapEvent.RESIZED.  
     325            * The MapEvent includes the newSize. 
     326            * 
     327            * @param w New map width. 
     328            * @param h New map height. 
     329            * 
     330            * @see com.modestmaps.events.MapEvent.RESIZED 
     331            */ 
     332            public function setSize(w:Number, h:Number):void 
     333            { 
     334                mapWidth = w; 
     335                mapHeight = h; 
     336 
     337                // mask out out of bounds marker remnants 
     338                scrollRect = new Rectangle(0,0,mapWidth,mapHeight); 
     339                 
    350340                grid.resizeTo(new Point(mapWidth, mapHeight)); 
    351  
    352                 onResized(); 
    353                  
    354                 // mask out out of bounds marker remnants 
    355                 scrollRect = new Rectangle(0,0,width,height); 
     341                 
     342                dispatchEvent(new MapEvent(MapEvent.RESIZED, this.getSize()));           
    356343            } 
    357344         
     
    430417                } 
    431418                 
    432                 requestCopyrightUpdate(); 
     419                dispatchEvent(new MapEvent(MapEvent.MAP_PROVIDER_CHANGED, newProvider)); 
    433420            } 
    434421             
     
    444431            { 
    445432                var coord:Coordinate = mapProvider.locationCoordinate(location); 
    446                 return grid.coordinatePoint(coord, context || this); 
     433                return grid.coordinatePoint(coord, context); 
    447434            } 
    448435             
     
    457444            public function pointLocation(point:Point, context:DisplayObject=null):Location 
    458445            { 
    459                 var coord:Coordinate = grid.pointCoordinate(point, context || this); 
     446                var coord:Coordinate = grid.pointCoordinate(point, context); 
    460447                return mapProvider.coordinateLocation(coord); 
    461448            } 
     
    571558                        grid.resetTiles(mapProvider.locationCoordinate(location).zoomTo(grid.zoomLevel)); 
    572559                        onExtentChanged(); 
    573                         requestCopyrightUpdate(); 
    574560                } 
    575561 
     
    655641            } 
    656642             
    657             protected var copyrightTimeout:uint; 
    658              
    659             protected function requestCopyrightUpdate():void 
    660             { 
    661                 if (copyrightTimeout) { 
    662                         clearTimeout(copyrightTimeout); 
    663                 } 
    664                 copyrightTimeout = setTimeout(callCopyright, 250); 
    665             } 
    666              
    667            /** 
    668             * Call javascript:modestMaps.copyright() with details about current view. 
    669             * See js/copyright.js. 
    670             */ 
    671             protected function callCopyright():void 
    672             { 
    673                 if (copyrightTimeout) { 
    674                         clearTimeout(copyrightTimeout); 
    675                 } 
    676                  
    677                 var cenP:Point = new Point(mapWidth/2, mapHeight/2); 
    678                 var minP:Point = new Point(mapWidth/5, mapHeight/5); 
    679                 var maxP:Point = new Point(mapWidth*4/5, mapHeight*4/5); 
    680                 
    681                 var cenC:Coordinate = grid.pointCoordinate(cenP, this); 
    682                 var minC:Coordinate = grid.pointCoordinate(minP, this); 
    683                 var maxC:Coordinate = grid.pointCoordinate(maxP, this); 
    684                 
    685                 var cenL:Location = mapProvider.coordinateLocation(mapProvider.sourceCoordinate(cenC)); 
    686                 var minL:Location = mapProvider.coordinateLocation(mapProvider.sourceCoordinate(minC)); 
    687                 var maxL:Location = mapProvider.coordinateLocation(mapProvider.sourceCoordinate(maxC)); 
    688             
    689                 var minLat:Number = Math.min(minL.lat, maxL.lat); 
    690                 var minLon:Number = Math.min(minL.lon, maxL.lon); 
    691                 var maxLat:Number = Math.max(minL.lat, maxL.lat); 
    692                 var maxLon:Number = Math.max(minL.lon, maxL.lon); 
    693                 
    694                 try { 
    695                     ExternalInterface.call("modestMaps.copyright", mapProvider.toString(), cenL.lat, cenL.lon, minLat, minLon, maxLat, maxLon, grid.zoomLevel); 
    696                 } 
    697                 catch (error:Error) { 
    698                         //trace("problem setting copyright in Map.as"); 
    699                         //trace(error.getStackTrace());  
    700                 } 
    701             } 
    702              
    703            /**  this function gets exposed to javascript as a callback, to use it 
    704             *   include copyright.js and override the modestMaps.copyright function to call 
    705             *   swfname.setCopyright("&copy blah blah") 
    706             *  
    707             *   e.g. in the head of your html page, where your SWF is embedded with the name MyMap 
    708             *  
    709             *   <script type="text/javascript" src="copyright.js"> 
    710             *   <script type="text/javascript"> 
    711             *     modestMaps.copyrightCallback = function(holdersHTML) { 
    712         *       MyMap.setCopyright(holdersHTML); 
    713         *     } 
    714         *   </script> 
    715         *  
    716         *   to display the copyright string in your flash piece, you then need to listen for  
    717         *   the COPYRIGHT_CHANGED MapEvent 
    718             */ 
    719             public function setCopyright(copyright:String):void { 
    720                 this.copyright = copyright; 
    721                 this.copyright = this.copyright.replace(/&copy;/g,"©"); 
    722                 dispatchEvent(new MapEvent(MapEvent.COPYRIGHT_CHANGED, this.copyright)); 
    723             } 
    724                      
    725            /** 
    726             * Dispatches MapEvent.RESIZED when the map is resized. 
    727             * The MapEvent includes the newSize. 
    728             * 
    729             * @see com.modestmaps.events.MapEvent.RESIZED 
    730             */ 
    731             public function onResized():void 
    732             { 
    733                 dispatchEvent(new MapEvent(MapEvent.RESIZED, this.getSize())); 
    734             } 
    735              
    736643           /** 
    737644            * Dispatches MapEvent.EXTENT_CHANGED when the map is recentered.