Changeset 644

Show
Ignore:
Timestamp:
08/20/08 11:28:19 (3 months ago)
Author:
tom
Message:

changed MarkerClip? in tweenlite branch so that it handles provider changes and MarkerEvents? for itself

Files:

Legend:

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

    r642 r644  
    88        import com.modestmaps.Map; 
    99        import com.modestmaps.events.MapEvent; 
     10        import com.modestmaps.events.MarkerEvent; 
    1011        import com.modestmaps.geo.Location; 
     12        import com.modestmaps.mapproviders.IMapProvider; 
    1113         
    1214        import flash.display.DisplayObject; 
    1315        import flash.display.Sprite; 
    1416        import flash.events.Event; 
     17        import flash.events.MouseEvent; 
    1518        import flash.geom.Point; 
    1619        import flash.utils.Dictionary; 
    1720         
    18     /** This is different from the as2 version for now, because 
    19          *  it makes more sense to me if you give it a Sprite  
    20          *  (or DisplayObject) to take care of rather than ask it to 
    21          *  make one for you. 
    22          */ 
     21    [Event(name="markerRollOver",    type="com.modestmaps.events.MarkerEvent")] 
     22    [Event(name="markerRollOut",     type="com.modestmaps.events.MarkerEvent")] 
     23    [Event(name="markerClick",       type="com.modestmaps.events.MarkerEvent")] 
    2324        public class MarkerClip extends Sprite 
    2425        { 
     
    4344        public var markerSortFunction:Function = sortMarkersByYPosition; 
    4445 
     46                // the projection of the current map's provider 
     47                // if this changes we need to recache coordinates 
     48                protected var previousGeometry:String; 
     49 
    4550                // setting this.dirty = true will redraw an MapEvent.RENDERED 
    4651                protected var _dirty:Boolean; 
     
    7075                this.x = map.getWidth() / 2; 
    7176                this.y = map.getHeight() / 2; 
     77                         
     78                previousGeometry = map.getMapProvider().geometry(); 
    7279 
    7380                map.addEventListener(MapEvent.START_ZOOMING, onMapStartZooming); 
     
    8087                map.addEventListener(MapEvent.EXTENT_CHANGED, onMapExtentChanged); 
    8188                map.addEventListener(MapEvent.RENDERED, updateClips); 
     89                map.addEventListener(MapEvent.MAP_PROVIDER_CHANGED, onMapProviderChanged); 
     90 
     91                        // these were previously in Map, but now MarkerEvents bubble it makes more sense to have them here 
     92                        addEventListener( MouseEvent.CLICK, onMarkerClick ); 
     93                        addEventListener( MouseEvent.ROLL_OVER, onMarkerRollOver, true );                
     94                        addEventListener( MouseEvent.ROLL_OUT, onMarkerRollOut, true );  
    8295 
    8396                addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); 
     
    224237            public function resetCoordinates():void 
    225238            { 
     239                var provider:IMapProvider = map.getMapProvider(); 
     240                // I wish Array.map didn't require three parameters! 
    226241                for each (var marker:DisplayObject in markers) { 
    227                                 coordinates[marker] = map.getMapProvider().locationCoordinate(locations[marker]); 
     242                                coordinates[marker] = provider.locationCoordinate(locations[marker]); 
    228243                } 
    229244            } 
     
    334349                } 
    335350            } 
    336  
     351             
     352            protected function onMapProviderChanged(event:MapEvent):void 
     353            { 
     354                var mapProvider:IMapProvider = event.newProvider;        
     355                if (mapProvider.geometry() != previousGeometry) 
     356                        { 
     357                        resetCoordinates(); 
     358                        previousGeometry = mapProvider.geometry(); 
     359                } 
     360            } 
     361             
    337362                protected function set dirty(d:Boolean):void 
    338363                { 
     
    347372                        return _dirty; 
    348373                } 
    349                  
     374 
     375                /** 
     376            * Dispatches MarkerEvent.CLICK when a marker is clicked. 
     377            *  
     378            * The MarkerEvent includes a reference to the marker and its location. 
     379            * 
     380            * @see com.modestmaps.events.MarkerEvent.CLICK 
     381            */ 
     382            protected function onMarkerClick(event:MouseEvent):void 
     383        { 
     384                var marker:DisplayObject = event.target as DisplayObject; 
     385                var location:Location = getMarkerLocation( marker ); 
     386                dispatchEvent( new MarkerEvent( MarkerEvent.CLICK, marker, location, true) ); 
     387        } 
     388         
     389                /** 
     390            * Dispatches MarkerEvent.ROLL_OVER 
     391            *  
     392            * The MarkerEvent includes a reference to the marker and its location. 
     393            * 
     394            * @see com.modestmaps.events.MarkerEvent.ROLL_OVER 
     395            */ 
     396        protected function onMarkerRollOver(event:MouseEvent):void 
     397        { 
     398                var marker:DisplayObject = event.target as DisplayObject; 
     399                var location:Location = getMarkerLocation( marker ); 
     400                dispatchEvent( new MarkerEvent( MarkerEvent.ROLL_OVER, marker, location, true) ); 
     401        } 
     402         
     403        /** 
     404            * Dispatches MarkerEvent.ROLL_OUT 
     405            *  
     406            * The MarkerEvent includes a reference to the marker and its location. 
     407            * 
     408            * @see com.modestmaps.events.MarkerEvent.ROLL_OUT 
     409            */ 
     410        protected function onMarkerRollOut(event:MouseEvent):void 
     411        { 
     412            var marker:DisplayObject = event.target as DisplayObject; 
     413            var location:Location = getMarkerLocation( marker ); 
     414                dispatchEvent( new MarkerEvent( MarkerEvent.ROLL_OUT, marker, location, true) ); 
     415        }                
    350416        } 
    351417         
  • branches/tom-tweenlite/lib/com/modestmaps/Map.as

    r642 r644  
    5656    [Event(name="markerRollOut",     type="com.modestmaps.events.MarkerEvent")] 
    5757    [Event(name="markerClick",       type="com.modestmaps.events.MarkerEvent")] 
    58  
    5958    public class Map extends Sprite 
    6059        { 
     
    105104                 
    106105                        markerClip = new MarkerClip(this); 
    107                         markerClip.addEventListener( MouseEvent.CLICK, onMarkerClick ); 
    108                         markerClip.addEventListener( MouseEvent.ROLL_OVER, onMarkerRollOver, true );             
    109                         markerClip.addEventListener( MouseEvent.ROLL_OUT, onMarkerRollOut, true );       
    110106                        addChild(markerClip); 
    111107 
     
    414410                        { 
    415411                        setExtent(extent); 
    416                         // notify the marker clip that its cached coordinates are invalid 
    417                         markerClip.resetCoordinates(); 
    418412                } 
    419413                 
     414                // among other things this will notify the marker clip that its cached coordinates are invalid 
    420415                dispatchEvent(new MapEvent(MapEvent.MAP_PROVIDER_CHANGED, newProvider)); 
    421416            } 
     
    669664                        dispatchEvent(new MapEvent(MapEvent.BEGIN_EXTENT_CHANGE, getExtent())); 
    670665                } 
    671             }        
    672              
    673            /** 
    674             * Dispatches MarkerEvent.CLICK when a marker is clicked. 
    675             *  
    676             * The MarkerEvent includes a reference to the marker and its location. 
    677             * 
    678             * @see com.modestmaps.events.MarkerEvent.CLICK 
    679             */ 
    680             protected function onMarkerClick(event:MouseEvent):void 
    681         { 
    682                 if (hasEventListener(MarkerEvent.CLICK)) { 
    683                         var marker:DisplayObject = event.target as DisplayObject; 
    684                         var location:Location = markerClip.getMarkerLocation( marker ); 
    685                         dispatchEvent( new MarkerEvent( MarkerEvent.CLICK, marker, location) ); 
    686                 } 
    687         } 
    688          
    689                 /** 
    690             * Dispatches MarkerEvent.ROLL_OVER 
    691             *  
    692             * The MarkerEvent includes a reference to the marker and its location. 
    693             * 
    694             * @see com.modestmaps.events.MarkerEvent.ROLL_OVER 
    695             */ 
    696         protected function onMarkerRollOver(event:MouseEvent):void 
    697         { 
    698                 if (hasEventListener(MarkerEvent.ROLL_OVER)) { 
    699                         var marker:DisplayObject = event.target as DisplayObject; 
    700                         var location:Location = markerClip.getMarkerLocation( marker ); 
    701                         dispatchEvent( new MarkerEvent( MarkerEvent.ROLL_OVER, marker, location) ); 
    702                 } 
    703         } 
    704          
    705         /** 
    706             * Dispatches MarkerEvent.ROLL_OUT 
    707             *  
    708             * The MarkerEvent includes a reference to the marker and its location. 
    709             * 
    710             * @see com.modestmaps.events.MarkerEvent.ROLL_OUT 
    711             */ 
    712         protected function onMarkerRollOut(event:MouseEvent):void 
    713         { 
    714                 if (hasEventListener(MarkerEvent.ROLL_OUT)) { 
    715                     var marker:DisplayObject = event.target as DisplayObject; 
    716                     var location:Location = markerClip.getMarkerLocation( marker ); 
    717                         dispatchEvent( new MarkerEvent( MarkerEvent.ROLL_OUT, marker, location) ); 
    718                 } 
    719         } 
     666            } 
    720667 
    721668                override public function set doubleClickEnabled(enabled:Boolean):void 
  • branches/tom-tweenlite/samples/as3/ModestMapsSample.as

    r642 r644  
    7070            var provider:AbstractGoogleMapProvider = new AbstractGoogleMapProvider(); 
    7171            provider.addEventListener(AbstractGoogleMapProvider.READY, onGoogleProvidersReady); 
    72              
    7372        } 
    7473