Changeset 340
- Timestamp:
- 08/13/07 10:45:48 (1 year ago)
- Files:
-
- trunk/as3/lib/com/modestmaps/core/MarkerClip.as (modified) (5 diffs)
- trunk/as3/lib/com/modestmaps/events/MapEvent.as (modified) (1 diff)
- trunk/as3/lib/com/modestmaps/Map.as (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/as3/lib/com/modestmaps/core/MarkerClip.as
r337 r340 31 31 private var markers:Array = []; // all markers 32 32 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; 33 38 34 39 public function MarkerClip(map:Map) 35 40 { 36 41 this.map = map; 42 this.x = map.getWidth() / 2; 43 this.y = map.getHeight() / 2; 37 44 map.addEventListener(MarkerEvent.ENTER, onMapMarkerEnters); 38 45 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); 42 49 map.addEventListener(MapEvent.START_PANNING, onMapStartPanning); 43 50 map.addEventListener(MapEvent.STOP_PANNING, onMapStopPanning); … … 49 56 public function attachMarker(marker:DisplayObject, location:Location):void 50 57 { 58 map.grid.putMarker(marker.name, map.getMapProvider().locationCoordinate(location), location); 59 51 60 locations[marker] = location; 52 61 markersByName[marker.name] = marker; … … 68 77 public function removeMarker(id:String):void 69 78 { 79 map.grid.removeMarker(id); 70 80 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 } 78 90 } 79 91 80 92 private function updateClips(event:Event=null):void 81 93 { 82 var t:int = flash.utils.getTimer();94 //var t:int = flash.utils.getTimer(); 83 95 for each (var marker:DisplayObject in markers) { 84 96 updateClip(marker); 85 97 } 86 trace("reprojected all markers in " + (flash.utils.getTimer() - t) + "ms");98 //trace("reprojected all markers in " + (flash.utils.getTimer() - t) + "ms"); 87 99 } 88 100 … … 95 107 } 96 108 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 98 114 { 99 115 if (!getChildByName(event.marker)) { 100 116 var marker:DisplayObject = getMarker(event.marker); 101 addChild(marker); 117 if (marker) { 118 addChild(marker); 119 } 102 120 } 103 121 } 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 106 128 { 107 129 if (getChildByName(event.marker)) { … … 138 160 } 139 161 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 140 185 } 141 186 trunk/as3/lib/com/modestmaps/events/MapEvent.as
r292 r340 31 31 public var newSize:Array; 32 32 33 public static const COPYRIGHT_CHANGED:String = 'copyright changed';33 public static const COPYRIGHT_CHANGED:String = 'copyrightChanged'; 34 34 public var newCopyright:String; 35 35 36 public static const EXTENT_CHANGED:String = 'extent changed';36 public static const EXTENT_CHANGED:String = 'extentChanged'; 37 37 public var newExtent:MapExtent; 38 38 trunk/as3/lib/com/modestmaps/Map.as
r338 r340 38 38 import flash.events.Event; 39 39 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 41 53 public class Map extends Sprite 42 54 { … … 111 123 112 124 markerClip = new MarkerClip(this); 113 markerClip.x = __width/2;114 markerClip.y = __height/2;115 125 addChild(markerClip); 116 126 … … 554 564 __animSteps.push(new ZoomAnimationStep(ZOOM, dir/zoomFrames, i == zoomFrames)); 555 565 } 566 556 567 if(!__animTask) { 557 568 __startingZoom = grid.zoomLevel; … … 575 586 { 576 587 var step:AnimationStep = __animSteps.shift(); 577 if (step.type == PAN)588 if (step.type == PAN) 578 589 { 579 590 //grid.allowPainting(__animSteps.length <= 1); … … 634 645 public function putMarker(id:String, location:Location, marker:DisplayObject=null):void 635 646 { 636 //trace('Marker '+id+': '+location.toString());637 grid.putMarker(id, __mapProvider.locationCoordinate(location), location);638 647 if (marker) { 639 648 //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); 641 653 } 642 654 } … … 659 671 public function removeMarker(id:String):void 660 672 { 661 grid.removeMarker(id); 662 markerClip.removeMarker(id); 673 markerClip.removeMarker(id); // also calls grid.removeMarker 663 674 } 664 675 … … 861 872 } 862 873 863 864 874 import flash.geom.Point; 865 875 866 876 867 877 class AnimationStep extends Object … … 886 896 this.amount = amount; 887 897 } 898 888 899 } 889 900
