Changeset 340

Show
Ignore:
Timestamp:
08/13/07 10:45:48 (1 year ago)
Author:
tom
Message:

markerclip is now standalone (no api change) and added event metadata

Files:

Legend:

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

    r337 r340  
    3131            private var markers:Array = []; // all markers 
    3232            private var markersByName:Object = {}; 
     33 
     34        // enable this if you want intermediate zooming steps to 
     35        // stretch your graphics instead of reprojecting the points 
     36        // it looks worse and probably isn't faster, but there it is :) 
     37        public var scaleZoom:Boolean = false; 
    3338         
    3439            public function MarkerClip(map:Map) 
    3540            { 
    3641                this.map = map; 
     42                this.x = map.getWidth() / 2; 
     43                this.y = map.getHeight() / 2; 
    3744                map.addEventListener(MarkerEvent.ENTER, onMapMarkerEnters); 
    3845                map.addEventListener(MarkerEvent.LEAVE, onMapMarkerLeaves); 
    39                 map.addEventListener(MapEvent.START_ZOOMING, updateClips); 
    40                 map.addEventListener(MapEvent.STOP_ZOOMING, updateClips); 
    41                 map.addEventListener(MapEvent.ZOOMED_BY, updateClips); 
     46                map.addEventListener(MapEvent.START_ZOOMING, onMapStartZooming); 
     47                map.addEventListener(MapEvent.STOP_ZOOMING, onMapStopZooming); 
     48                map.addEventListener(MapEvent.ZOOMED_BY, onMapZoomedBy); 
    4249                map.addEventListener(MapEvent.START_PANNING, onMapStartPanning); 
    4350                map.addEventListener(MapEvent.STOP_PANNING, onMapStopPanning); 
     
    4956            public function attachMarker(marker:DisplayObject, location:Location):void 
    5057            { 
     58                map.grid.putMarker(marker.name, map.getMapProvider().locationCoordinate(location), location); 
     59                 
    5160                locations[marker] = location; 
    5261                markersByName[marker.name] = marker; 
     
    6877            public function removeMarker(id:String):void 
    6978            { 
     79                map.grid.removeMarker(id); 
    7080                var marker:DisplayObject = getMarker(id); 
    71                 if (this.getChildByName(id)) removeChild(marker); 
    72                 var index:int = markers.indexOf(marker); 
    73                 if (index >= 0) { 
    74                         markers.splice(index,1); 
    75                 } 
    76                 delete locations[marker]; 
    77                 delete markersByName[marker.name]; 
     81                if (marker) { 
     82                if (this.getChildByName(id)) removeChild(marker); 
     83                var index:int = markers.indexOf(marker); 
     84                if (index >= 0) { 
     85                        markers.splice(index,1); 
     86                } 
     87                delete locations[marker]; 
     88                delete markersByName[marker.name]; 
     89            } 
    7890            } 
    7991                 
    8092            private function updateClips(event:Event=null):void 
    8193            { 
    82                 var t:int = flash.utils.getTimer(); 
     94                //var t:int = flash.utils.getTimer(); 
    8395                for each (var marker:DisplayObject in markers) { 
    8496                        updateClip(marker); 
    8597                } 
    86                 trace("reprojected all markers in " + (flash.utils.getTimer() - t) + "ms"); 
     98                //trace("reprojected all markers in " + (flash.utils.getTimer() - t) + "ms"); 
    8799            } 
    88100             
     
    95107            } 
    96108                     
    97             public function onMapMarkerEnters(event:MarkerEvent):void 
     109            /** This uses addChild, and onMapMarkerLeaves uses removeChild,  
     110             *  so that you're free to mess with .visible=true/false 
     111             *  yourself if you want to filter markers  
     112             */ 
     113            private function onMapMarkerEnters(event:MarkerEvent):void 
    98114            { 
    99115                if (!getChildByName(event.marker)) { 
    100116                        var marker:DisplayObject = getMarker(event.marker); 
    101                         addChild(marker); 
     117                        if (marker) { 
     118                            addChild(marker); 
     119                        } 
    102120                }  
    103121            } 
    104              
    105             public function onMapMarkerLeaves(event:MarkerEvent):void 
     122 
     123            /** This uses removeChild, and onMapMarkerEnters uses removeChild,  
     124             *  so that you're free to mess with .visible=true/false 
     125             *  yourself if you want to filter markers  
     126             */ 
     127            private function onMapMarkerLeaves(event:MarkerEvent):void 
    106128            { 
    107129                if (getChildByName(event.marker)) { 
     
    138160            } 
    139161             
     162            public function onMapStartZooming(event:MapEvent):void 
     163            { 
     164                // updateClips();  
     165            } 
     166             
     167            public function onMapStopZooming(event:MapEvent):void 
     168            { 
     169                if (scaleZoom) { 
     170                    scaleX = scaleY = 1.0; 
     171                } 
     172            updateClips(); 
     173            } 
     174             
     175            public function onMapZoomedBy(event:MapEvent):void 
     176            { 
     177                if (scaleZoom) { 
     178                scaleX = scaleY = Math.pow(2, event.zoomDelta); 
     179                } 
     180                else { 
     181                updateClips(); 
     182                } 
     183            } 
     184             
    140185        } 
    141186         
  • trunk/as3/lib/com/modestmaps/events/MapEvent.as

    r292 r340  
    3131            public var newSize:Array; 
    3232                     
    33             public static const COPYRIGHT_CHANGED:String = 'copyright changed'; 
     33            public static const COPYRIGHT_CHANGED:String = 'copyrightChanged'; 
    3434            public var newCopyright:String; 
    3535             
    36             public static const EXTENT_CHANGED:String = 'extent changed'; 
     36            public static const EXTENT_CHANGED:String = 'extentChanged'; 
    3737                public var newExtent:MapExtent; 
    3838 
  • trunk/as3/lib/com/modestmaps/Map.as

    r338 r340  
    3838        import flash.events.Event; 
    3939        import flash.display.DisplayObject; 
    40          
     40 
     41    [Event(name="startZooming",     type="com.modestmaps.events.MapEvent")] 
     42    [Event(name="stopZooming",      type="com.modestmaps.events.MapEvent")] 
     43    [Event(name="zoomedBy",         type="com.modestmaps.events.MapEvent")] 
     44    [Event(name="startPanning",     type="com.modestmaps.events.MapEvent")] 
     45    [Event(name="stopPanning",      type="com.modestmaps.events.MapEvent")] 
     46    [Event(name="pannedBy",         type="com.modestmaps.events.MapEvent")] 
     47    [Event(name="resized",          type="com.modestmaps.events.MapEvent")] 
     48    [Event(name="copyrightChanged", type="com.modestmaps.events.MapEvent")] 
     49    [Event(name="extentChanged",    type="com.modestmaps.events.MapEvent")] 
     50    [Event(name="markerEnter",      type="com.modestmaps.events.MarkerEvent")] 
     51    [Event(name="markerLeave",      type="com.modestmaps.events.MarkerEvent")] 
     52 
    4153        public class Map extends Sprite 
    4254        { 
     
    111123 
    112124                        markerClip = new MarkerClip(this); 
    113                         markerClip.x = __width/2; 
    114                         markerClip.y = __height/2; 
    115125                        addChild(markerClip); 
    116126 
     
    554564                    __animSteps.push(new ZoomAnimationStep(ZOOM, dir/zoomFrames, i == zoomFrames)); 
    555565                } 
     566                 
    556567                if(!__animTask) { 
    557568                    __startingZoom = grid.zoomLevel; 
     
    575586                        { 
    576587                    var step:AnimationStep = __animSteps.shift(); 
    577                   if (step.type == PAN) 
     588                  if (step.type == PAN) 
    578589                                { 
    579590                        //grid.allowPainting(__animSteps.length <= 1); 
     
    634645            public function putMarker(id:String, location:Location, marker:DisplayObject=null):void 
    635646            { 
    636                 //trace('Marker '+id+': '+location.toString()); 
    637                 grid.putMarker(id, __mapProvider.locationCoordinate(location), location); 
    638647                if (marker) { 
    639648                        //if (marker.name != id) throw new Error("marker name must match id"); 
    640                         markerClip.attachMarker(marker, location); 
     649                        markerClip.attachMarker(marker, location); // calls grid.putMarker as well 
     650                } 
     651                else { 
     652                grid.putMarker(id, __mapProvider.locationCoordinate(location), location);             
    641653                } 
    642654            } 
     
    659671            public function removeMarker(id:String):void 
    660672            { 
    661                 grid.removeMarker(id); 
    662                 markerClip.removeMarker(id); 
     673                markerClip.removeMarker(id); // also calls grid.removeMarker 
    663674            } 
    664675             
     
    861872} 
    862873 
    863  
    864874import flash.geom.Point; 
    865          
     875 
    866876 
    867877class AnimationStep extends Object 
     
    886896                this.amount = amount; 
    887897        } 
     898         
    888899} 
    889900