Changeset 624
- Timestamp:
- 07/20/08 19:52:48 (2 months ago)
- Files:
-
- branches/tom-tweenlite/lib/com/modestmaps/core/TileGrid.as (modified) (1 diff)
- branches/tom-tweenlite/lib/com/modestmaps/events/MapEvent.as (modified) (5 diffs)
- branches/tom-tweenlite/lib/com/modestmaps/extras/MapCopyright.as (added)
- branches/tom-tweenlite/lib/com/modestmaps/Map.as (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/tom-tweenlite/lib/com/modestmaps/core/TileGrid.as
r622 r624 605 605 else if (previousOpenRequests > 0 && openRequests.length == 0) { 606 606 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 608 608 dirty = true; 609 609 } branches/tom-tweenlite/lib/com/modestmaps/events/MapEvent.as
r569 r624 6 6 { 7 7 import com.modestmaps.core.MapExtent; 8 import com.modestmaps.mapproviders.IMapProvider; 8 9 9 10 import flash.events.Event; … … 37 38 public var newExtent:MapExtent; 38 39 40 public static const MAP_PROVIDER_CHANGED:String = 'mapProviderChanged'; 41 public var newProvider:IMapProvider; 42 39 43 public static const BEGIN_TILE_LOADING:String = 'beginTileLoading'; 40 44 public static const ALL_TILES_LOADED:String = 'alLTilesLoaded'; … … 55 59 } 56 60 break; 61 case EXTENT_CHANGED: 62 if (rest.length > 0 && rest[0] is MapExtent) { 63 newExtent = rest[0]; 64 } 65 break; 57 66 case START_ZOOMING: 58 67 case STOP_ZOOMING: … … 71 80 } 72 81 break; 73 case EXTENT_CHANGED:74 if (rest.length > 0 && rest[0] is MapExtent) {75 newExtent = rest[0];76 }77 break;78 82 case BEGIN_EXTENT_CHANGE: 79 83 if (rest.length > 0 && rest[0] is MapExtent) { … … 81 85 } 82 86 break; 87 case MAP_PROVIDER_CHANGED: 88 if (rest.length > 0 && rest[0] is IMapProvider) { 89 newProvider = rest[0]; 90 } 83 91 } 84 92 branches/tom-tweenlite/lib/com/modestmaps/Map.as
r622 r624 50 50 [Event(name="panned", type="com.modestmaps.events.MapEvent")] 51 51 [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")] 53 53 [Event(name="beginExtentChange", type="com.modestmaps.events.MapEvent")] 54 54 [Event(name="extentChanged", type="com.modestmaps.events.MapEvent")] … … 74 74 protected var mapProvider:IMapProvider; 75 75 76 /** htmlText to be added to a label - listen for MapEvent.COPYRIGHT_CHANGED */77 public var copyright:String = "";78 79 76 /** fraction of width/height to pan panLeft, panRight, panUp, panDown 80 77 * @default 0.333333333 … … 115 112 addChild(markerClip); 116 113 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 125 114 // if rest was passed in from super constructor in a subclass, 126 115 // it will be an array... … … 182 171 grid.resetTiles(locationsCoordinate( [ extent.northWest, extent.southEast ] )); 183 172 onExtentChanged(); 184 requestCopyrightUpdate();185 173 } 186 174 … … 207 195 grid.resetTiles(mapProvider.locationCoordinate(location).zoomTo(zoom)); 208 196 onExtentChanged(); 209 requestCopyrightUpdate();210 197 } 211 198 } … … 223 210 public function setZoom(zoom:Number):void 224 211 { 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); 227 215 } 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 } 236 222 237 223 public function locationsCoordinate(locations:Array):Coordinate … … 336 322 337 323 /** 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 350 340 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())); 356 343 } 357 344 … … 430 417 } 431 418 432 requestCopyrightUpdate();419 dispatchEvent(new MapEvent(MapEvent.MAP_PROVIDER_CHANGED, newProvider)); 433 420 } 434 421 … … 444 431 { 445 432 var coord:Coordinate = mapProvider.locationCoordinate(location); 446 return grid.coordinatePoint(coord, context || this);433 return grid.coordinatePoint(coord, context); 447 434 } 448 435 … … 457 444 public function pointLocation(point:Point, context:DisplayObject=null):Location 458 445 { 459 var coord:Coordinate = grid.pointCoordinate(point, context || this);446 var coord:Coordinate = grid.pointCoordinate(point, context); 460 447 return mapProvider.coordinateLocation(coord); 461 448 } … … 571 558 grid.resetTiles(mapProvider.locationCoordinate(location).zoomTo(grid.zoomLevel)); 572 559 onExtentChanged(); 573 requestCopyrightUpdate();574 560 } 575 561 … … 655 641 } 656 642 657 protected var copyrightTimeout:uint;658 659 protected function requestCopyrightUpdate():void660 {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():void672 {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 it704 * include copyright.js and override the modestMaps.copyright function to call705 * swfname.setCopyright("© blah blah")706 *707 * e.g. in the head of your html page, where your SWF is embedded with the name MyMap708 *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 for717 * the COPYRIGHT_CHANGED MapEvent718 */719 public function setCopyright(copyright:String):void {720 this.copyright = copyright;721 this.copyright = this.copyright.replace(/©/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.RESIZED730 */731 public function onResized():void732 {733 dispatchEvent(new MapEvent(MapEvent.RESIZED, this.getSize()));734 }735 736 643 /** 737 644 * Dispatches MapEvent.EXTENT_CHANGED when the map is recentered.
