Changeset 644
- Timestamp:
- 08/20/08 11:28:19 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/tom-tweenlite/lib/com/modestmaps/core/MarkerClip.as
r642 r644 8 8 import com.modestmaps.Map; 9 9 import com.modestmaps.events.MapEvent; 10 import com.modestmaps.events.MarkerEvent; 10 11 import com.modestmaps.geo.Location; 12 import com.modestmaps.mapproviders.IMapProvider; 11 13 12 14 import flash.display.DisplayObject; 13 15 import flash.display.Sprite; 14 16 import flash.events.Event; 17 import flash.events.MouseEvent; 15 18 import flash.geom.Point; 16 19 import flash.utils.Dictionary; 17 20 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")] 23 24 public class MarkerClip extends Sprite 24 25 { … … 43 44 public var markerSortFunction:Function = sortMarkersByYPosition; 44 45 46 // the projection of the current map's provider 47 // if this changes we need to recache coordinates 48 protected var previousGeometry:String; 49 45 50 // setting this.dirty = true will redraw an MapEvent.RENDERED 46 51 protected var _dirty:Boolean; … … 70 75 this.x = map.getWidth() / 2; 71 76 this.y = map.getHeight() / 2; 77 78 previousGeometry = map.getMapProvider().geometry(); 72 79 73 80 map.addEventListener(MapEvent.START_ZOOMING, onMapStartZooming); … … 80 87 map.addEventListener(MapEvent.EXTENT_CHANGED, onMapExtentChanged); 81 88 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 ); 82 95 83 96 addEventListener(Event.ADDED_TO_STAGE, onAddedToStage); … … 224 237 public function resetCoordinates():void 225 238 { 239 var provider:IMapProvider = map.getMapProvider(); 240 // I wish Array.map didn't require three parameters! 226 241 for each (var marker:DisplayObject in markers) { 227 coordinates[marker] = map.getMapProvider().locationCoordinate(locations[marker]);242 coordinates[marker] = provider.locationCoordinate(locations[marker]); 228 243 } 229 244 } … … 334 349 } 335 350 } 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 337 362 protected function set dirty(d:Boolean):void 338 363 { … … 347 372 return _dirty; 348 373 } 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 } 350 416 } 351 417 branches/tom-tweenlite/lib/com/modestmaps/Map.as
r642 r644 56 56 [Event(name="markerRollOut", type="com.modestmaps.events.MarkerEvent")] 57 57 [Event(name="markerClick", type="com.modestmaps.events.MarkerEvent")] 58 59 58 public class Map extends Sprite 60 59 { … … 105 104 106 105 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 );110 106 addChild(markerClip); 111 107 … … 414 410 { 415 411 setExtent(extent); 416 // notify the marker clip that its cached coordinates are invalid417 markerClip.resetCoordinates();418 412 } 419 413 414 // among other things this will notify the marker clip that its cached coordinates are invalid 420 415 dispatchEvent(new MapEvent(MapEvent.MAP_PROVIDER_CHANGED, newProvider)); 421 416 } … … 669 664 dispatchEvent(new MapEvent(MapEvent.BEGIN_EXTENT_CHANGE, getExtent())); 670 665 } 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 } 720 667 721 668 override public function set doubleClickEnabled(enabled:Boolean):void branches/tom-tweenlite/samples/as3/ModestMapsSample.as
r642 r644 70 70 var provider:AbstractGoogleMapProvider = new AbstractGoogleMapProvider(); 71 71 provider.addEventListener(AbstractGoogleMapProvider.READY, onGoogleProvidersReady); 72 73 72 } 74 73
