Changeset 286

Show
Ignore:
Timestamp:
05/22/07 12:49:59 (1 year ago)
Author:
migurski
Message:

Merged branch AS3 onto trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/as2/lib/com/modestmaps/core/Bounds.as

    r15 r286  
    1 import com.modestmaps.core.Point; 
     1import flash.geom.Point; 
    22 
    33class com.modestmaps.core.Bounds 
  • trunk/as2/lib/com/modestmaps/core/Marker.as

    r125 r286  
    1 //import com.modestmaps.core.Point; 
     1//import flash.geom.Point; 
    22import com.modestmaps.core.Coordinate; 
    33import com.modestmaps.geo.Location; 
  • trunk/as2/lib/com/modestmaps/core/Tile.as

    r225 r286  
    44import com.bigspaceship.utils.Delegate; 
    55import com.modestmaps.core.Coordinate; 
    6 import com.modestmaps.core.Point; 
    76import com.modestmaps.core.TileGrid; 
    87import com.modestmaps.core.TilePaintCall; 
     
    109import com.modestmaps.mapproviders.IMapProvider; 
    1110import com.stamen.twisted.Reactor; 
     11import flash.geom.Point; 
    1212 
    1313class com.modestmaps.core.Tile  
  • trunk/as2/lib/com/modestmaps/core/TileGrid.as

    r258 r286  
    33 * $Id$ 
    44 */ 
     5 
     6import flash.geom.Point; 
    57 
    68import com.bigspaceship.utils.Delegate; 
     
    911import com.modestmaps.core.Marker; 
    1012import com.modestmaps.core.MarkerSet; 
    11 import com.modestmaps.core.Point; 
    1213import com.modestmaps.core.Tile; 
    1314import com.modestmaps.geo.Location; 
     
    475476        __map.onStartPan(); 
    476477        __well.startDrag(false, xMin, yMin, xMax, yMax); 
    477         onWellDrag(__startingWellPosition.copy()); 
     478        onWellDrag(new Point(__startingWellPosition.x, __startingWellPosition.y)); 
    478479    } 
    479480     
  • trunk/as2/lib/com/modestmaps/geo/AbstractProjection.as

    r166 r286  
    11import Math; 
    2 import com.modestmaps.core.Point; 
     2import flash.geom.Point; 
    33import com.modestmaps.core.Coordinate; 
    44import com.modestmaps.geo.Location; 
  • trunk/as2/lib/com/modestmaps/geo/IProjection.as

    r99 r286  
    1 import com.modestmaps.core.Point; 
     1import flash.geom.Point; 
    22import com.modestmaps.core.Coordinate; 
    33import com.modestmaps.geo.Location; 
  • trunk/as2/lib/com/modestmaps/geo/LinearProjection.as

    r166 r286  
    1 import com.modestmaps.core.Point; 
     1import flash.geom.Point; 
    22import com.modestmaps.geo.Transformation; 
    33import com.modestmaps.geo.AbstractProjection;  
  • trunk/as2/lib/com/modestmaps/geo/MercatorProjection.as

    r73 r286  
    11import Math; 
    2 import com.modestmaps.core.Point; 
     2import flash.geom.Point; 
    33import com.modestmaps.core.Coordinate; 
    44import com.modestmaps.geo.Transformation; 
  • trunk/as2/lib/com/modestmaps/geo/Transformation.as

    r123 r286  
    1 import com.modestmaps.core.Point; 
     1import flash.geom.Point; 
    22  
    33class com.modestmaps.geo.Transformation 
  • trunk/as2/lib/com/modestmaps/Map.as

    r258 r286  
    2626 
    2727import com.bigspaceship.utils.Delegate; 
    28  
    2928import org.casaframework.movieclip.DispatchableMovieClip; 
    30  
     29import flash.geom.Point; 
     30 
     31import com.modestmaps.core.MapExtent; 
     32import com.modestmaps.core.MapPosition; 
    3133import com.modestmaps.core.Coordinate; 
    32 import com.modestmaps.core.Point; 
    3334import com.modestmaps.core.TileGrid; 
     35import com.modestmaps.core.MarkerClip; 
    3436import com.modestmaps.geo.Location; 
    3537import com.modestmaps.mapproviders.IMapProvider; 
     
    6466    public var grid:TileGrid; 
    6567 
     68    // markers are attached here 
     69    private var __markers:MarkerClip; 
     70    private var __mask:MovieClip; 
     71 
    6672    // Who do we get our Map graphics from? 
    6773    private var __mapProvider:IMapProvider; 
     
    7177    public static var EVENT_MARKER_LEAVES:String = 'Marker leaves'; 
    7278    public static var EVENT_START_ZOOMING:String = 'Start zooming'; 
    73     public static var EVENT_STOP_ZOOMING:String = 'Stop Zooming'; 
     79    public static var EVENT_STOP_ZOOMING:String = 'Stop zooming'; 
    7480    public static var EVENT_ZOOMED_BY:String = 'Zoomed by...'; 
    7581    public static var EVENT_START_PANNING:String = 'Start panning'; 
     
    7783    public static var EVENT_PANNED_BY:String = 'Panned by...'; 
    7884    public static var EVENT_RESIZED_TO:String = 'Resized to...'; 
     85    public static var EVENT_EXTENT_CHANGED:String = 'Extent changed'; 
    7986 
    8087    public static var symbolName:String = '__Packages.com.modestmaps.Map'; 
     
    110117        grid = TileGrid(attachMovie(TileGrid.symbolName, 'grid', getNextHighestDepth())); 
    111118        grid.init(width, height, draggable, provider, this); 
     119 
     120        __markers = MarkerClip(attachMovie(MarkerClip.symbolName, '__markers', getNextHighestDepth(), {_x: __width/2, _y: __height/2})); 
     121        __mask = createEmptyMovieClip('__mask', getNextHighestDepth()); 
     122        __markers.setMask(__mask); 
     123        __markers.setMap(this); 
     124         
     125        redraw(); 
    112126    } 
    113127 
    114128   /* 
    115     * Based on an array of locations, determine appropriate map 
    116     * bounds using calculateMapExtent(), and inform the grid of 
     129    * Based on a MapExtent, determine appropriate map 
     130    * bounds using extentPosition(), and inform the grid of 
    117131    * tile coordinate and point by calling grid.resetTiles(). 
    118132    * Resulting map extent will ensure that all passed locations 
    119133    * are visible. 
    120134    * 
    121     * @param    Array of locations
    122     * 
    123     * @see com.modestmaps.Map#calculateMapExtent 
     135    * @param    MapExtent
     136    * 
     137    * @see com.modestmaps.Map#extentPosition 
    124138    * @see com.modestmaps.core.TileGrid#resetTiles 
    125139    */ 
    126     public function setExtent(locations:/*Location*/Array):Void 
    127     { 
    128         if(!locations.length) 
    129             return; 
    130      
    131         var extent:Object = calculateMapExtent(locations); 
     140    public function setExtent(extent:MapExtent):Void 
     141    { 
     142        // what to do if a bad extent is passed? 
     143        var position:MapPosition = extentPosition(extent); 
    132144     
    133145        // tell grid what the rock is cooking 
    134         grid.resetTiles(Coordinate(extent['coord']), Point(extent['point'])); 
     146        grid.resetTiles(position.coord, position.point); 
     147        onExtentChanged(getExtent()); 
     148        Reactor.callNextFrame(Delegate.create(this, this.callCopyright)); 
    135149        Reactor.callNextFrame(Delegate.create(this, this.callCopyright)); 
    136150    } 
     
    138152   /* 
    139153    * Based on a location and zoom level, determine appropriate initial 
    140     * tile coordinate and point using calculateMapCenter(), and inform 
     154    * tile coordinate and point using coordinatePosition(), and inform 
    141155    * the grid of tile coordinate and point by calling grid.resetTiles(). 
    142156    * 
     
    144158    * @param    Desired zoom level. 
    145159    * 
    146     * @see com.modestmaps.Map#calculateMapExtent 
     160    * @see com.modestmaps.Map#extentPosition 
    147161    * @see com.modestmaps.core.TileGrid#resetTiles 
    148162    */ 
    149163    public function setCenterZoom(location:Location, zoom:Number):Void 
    150164    { 
    151         var center:Object = calculateMapCenter(__mapProvider.locationCoordinate(location).zoomTo(zoom)); 
     165        var center:MapPosition = coordinatePosition(__mapProvider.locationCoordinate(location).zoomTo(zoom)); 
    152166         
    153167        // tell grid what the rock is cooking 
    154         grid.resetTiles(Coordinate(center['coord']), Point(center['point'])); 
     168        grid.resetTiles(center.coord, center.point); 
     169        onExtentChanged(getExtent()); 
     170        Reactor.callNextFrame(Delegate.create(this, this.callCopyright)); 
    155171        Reactor.callNextFrame(Delegate.create(this, this.callCopyright)); 
    156172    } 
     
    158174   /* 
    159175    * Based on a coordinate, determine appropriate starting tile and position, 
    160     * and return a two-element object with a coord and a point
    161     */ 
    162     private function calculateMapCenter(centerCoord:Coordinate):Object 
     176    * and return a MapPosition
     177    */ 
     178    private function coordinatePosition(centerCoord:Coordinate):MapPosition 
    163179    { 
    164180        // initial tile coordinate 
     
    170186        var initPoint:Point = new Point(Math.round(initX), Math.round(initY)); 
    171187         
    172         return {coord: initTileCoord, point: initPoint}
     188        return new MapPosition(initTileCoord, initPoint)
    173189    } 
    174190     
    175191   /* 
    176192    * Based on an array of locations, determine appropriate map bounds 
    177     * in terms of tile grid, and return a two-element object with a coord 
    178     * and a point from calculateMapCenter(). 
    179     */ 
    180     private function calculateMapExtent(locations:/*Location*/Array):Object 
     193    * in terms of tile grid, and return a MapPosition from coordinatePosition(). 
     194    */ 
     195    private function locationsPosition(locations:/*Location*/Array):MapPosition 
    181196    { 
    182197        // my kingdom for a decent map() function in AS2 
     
    226241        var centerCoord:Coordinate = (new Coordinate(centerRow, centerColumn, centerZoom)).zoomTo(initZoom); 
    227242         
    228         return calculateMapCenter(centerCoord); 
    229     } 
    230      
     243        return coordinatePosition(centerCoord); 
     244    } 
     245 
    231246   /* 
    232     * Return the current coverage area of the map, as four locations. 
    233     * 
    234     * @return   Array of four locations: [top-left, top-right, bottom-left, bottom-right]. 
    235     */ 
    236     public function getExtent():/*Location*/Array 
    237     { 
    238         var corners:/*Location*/Array = []; 
    239          
     247    * Based on a MapExtent, determine appropriate map bounds 
     248    * in terms of tile grid, and return a MapPosition from calculateMapCenter(). 
     249    */ 
     250    private function extentPosition(extent:MapExtent):MapPosition 
     251    { 
     252        var locations:/*Location*/Array = [extent.northWest, extent.southEast]; 
     253        return locationsPosition(locations); 
     254    } 
     255     
     256   /* 
     257    * Return the current coverage area of the map, as MapExtent. 
     258    * 
     259    * @return   MapExtent. 
     260    */ 
     261    public function getExtent():MapExtent 
     262    { 
    240263        if(!__mapProvider) 
    241             return corners; 
    242  
    243         var TL:Coordinate = grid.topLeftCoordinate(); 
    244         var BR:Coordinate = grid.bottomRightCoordinate(); 
    245         var TR:Coordinate = new Coordinate(TL.row, BR.column, TL.zoom); 
    246         var BL:Coordinate = new Coordinate(BR.row, TL.column, BR.zoom); 
    247  
    248         corners.push(__mapProvider.coordinateLocation(TL)); 
    249         corners.push(__mapProvider.coordinateLocation(TR)); 
    250         corners.push(__mapProvider.coordinateLocation(BL)); 
    251         corners.push(__mapProvider.coordinateLocation(BR)); 
    252          
    253         /* 
    254         trace('top left: '+corners[0].toString()); 
    255         trace('top right: '+corners[1].toString()); 
    256         trace('bottom left: '+corners[2].toString()); 
    257         trace('bottom right: '+corners[3].toString()); 
    258         */ 
    259  
    260         return corners; 
     264            return new MapExtent(); 
     265 
     266        var coordTL:Coordinate = grid.topLeftCoordinate(); 
     267        var coordBR:Coordinate = grid.bottomRightCoordinate(); 
     268        var coordTR:Coordinate = new Coordinate(coordTL.row, coordBR.column, coordTL.zoom); 
     269        var coordBL:Coordinate = new Coordinate(coordBR.row, coordTL.column, coordBR.zoom); 
     270         
     271        var TL:Location = __mapProvider.coordinateLocation(coordTL); 
     272        var BR:Location = __mapProvider.coordinateLocation(coordBR); 
     273        var TR:Location = __mapProvider.coordinateLocation(coordTR); 
     274        var BL:Location = __mapProvider.coordinateLocation(coordBL); 
     275         
     276        return new MapExtent(Math.max(Math.max(TL.lat, TR.lat), Math.max(BL.lat, BR.lat)), 
     277                             Math.min(Math.min(TL.lat, TR.lat), Math.min(BL.lat, BR.lat)), 
     278                             Math.max(Math.max(TL.lon, TR.lon), Math.max(BL.lon, BR.lon)), 
     279                             Math.min(Math.min(TL.lon, TR.lon), Math.min(BL.lon, BR.lon))); 
    261280    } 
    262281 
     
    283302        __width = width; 
    284303        __height = height; 
     304        redraw(); 
     305 
    285306        grid.resizeTo(new Point(__width, __height)); 
    286307        onResized(); 
     
    320341    { 
    321342        var previousGeometry:String = __mapProvider.geometry(); 
    322         var extent:/*Location*/Array = getExtent(); 
     343        var extent:MapExtent = getExtent(); 
    323344         
    324345        __mapProvider = newProvider; 
     
    506527    * @param    ID of marker, opaque string. 
    507528    * @param    Location of marker. 
    508     */ 
    509     public function putMarker(id:String, location:Location):Void 
     529    * @param    Optional symbol name if a clip is to be attached. 
     530    * @return   Optional attached movie clip, if a valid symbol was provided. 
     531    */ 
     532    public function putMarker(id:String, location:Location, symbol:String):MovieClip 
    510533    { 
    511534        //trace('Marker '+id+': '+location.toString()); 
    512535        grid.putMarker(id, __mapProvider.locationCoordinate(location), location); 
     536         
     537        if(symbol) 
     538            return __markers.attachMarker(id, location, symbol); 
     539             
     540        return undefined; 
     541    } 
     542 
     543   /** 
     544    * Get a marker clip with the given id if one was created. 
     545    * 
     546    * @param    ID of marker, opaque string. 
     547    * @return   Optional attached movie clip, if a valid symbol was provided. 
     548    */ 
     549    public function getMarker(id:String):MovieClip 
     550    { 
     551        return __markers.getMarker(id); 
    513552    } 
    514553 
     
    521560    { 
    522561        grid.removeMarker(id); 
     562        __markers.removeMarker(id); 
    523563    } 
    524564     
     
    665705        dispatchEvent( EVENT_RESIZED_TO, __width, __height ); 
    666706    } 
     707     
     708   /** 
     709    * Dispatches EVENT_EXTENT_CHANGED when the map extent changes. 
     710    * Callback arguments include extent:MapExtent. 
     711    * 
     712    * @see com.modestmaps.Map#EVENT_EXTENT_CHANGED 
     713    */ 
     714    public function onExtentChanged(extent:MapExtent):Void 
     715    { 
     716        dispatchEvent( EVENT_RESIZED_TO, extent ); 
     717    } 
     718     
     719    private function redraw() 
     720    { 
     721        clear(); 
     722 
     723        __mask.clear(); 
     724        __mask.moveTo(0, 0); 
     725        __mask.lineStyle(); 
     726        __mask.beginFill(0xFF00FF, 0); 
     727        __mask.lineTo(0, __height); 
     728        __mask.lineTo(__width, __height); 
     729        __mask.lineTo(__width, 0); 
     730        __mask.lineTo(0, 0); 
     731        __mask.endFill(); 
     732    } 
    667733} 
  • trunk/as2/lib/com/modestmaps/mapproviders/AbstractImageBasedMapProvider.as

    r260 r286  
    66 * @author migurski 
    77 * 
    8  * AbstractImageBasedMapProvider is the base class for all MapProviders 
    9  * that use externally loaded images to paint Tiles. 
     8 * AbstractImageBasedMapProvider is the base class for all map 
     9 * providers that use externally loaded images to paint Tiles. 
    1010 *  
    1111 * @see com.modestmaps.mapproviders.AbstractMapProvider 
     
    5151                request.addEventObserver( this, MapProviderPaintThrottledRequest.EVENT_RESPONSE_ERROR, "onResponseError"); 
    5252                request.send(); 
    53                  
    54                 //createLabel( clip, coord.toString() ); 
    5553        } 
    5654 
  • trunk/as2/lib/com/modestmaps/mapproviders/AbstractMapProvider.as

    r191 r286  
    66 * @author migurski 
    77 * 
    8  * AbstractMapProvider is the base class for all MapProviders. 
     8 * AbstractMapProvider is the base class for all map providers. 
    99 *  
    10  * @description AbstractMapProvider is the base class for all  
    11  *                              MapProviders. MapProviders are primarily responsible 
    12  *                              for "painting" map Tiles with the correct  
    13  *                              graphic imagery. 
     10 * @description AbstractMapProvider is the base class for all map providers. 
     11 *                              Map providers are primarily responsible for "painting" map 
     12 *              tiles with the correct graphic imagery. 
    1413 */ 
    1514 
     
    9594    } 
    9695 
    97         /** 
    98          * Creates a text label for debugging purposes. 
    99          *  
    100          * @param clip The MovieClip to contain the label. 
    101          * @param label The text the label. 
    102          */ 
    103         public function createLabel( clip : MovieClip, label : String ) : Void 
    104         { 
    105                 clip["labelTF"].removeTextField(); 
    106                  
    107                 clip.createTextField('labelTF', 1, 0, 0, 1, 1); 
    108             var tf : TextField = clip["labelTF"]; 
    109             tf.autoSize = true; 
    110             tf.selectable = false; 
    111             tf.textColor = 0xFF0000; 
    112                 tf.text = label;         
    113         } 
    114  
    11596   /* 
    11697    * Return projected and transformed coordinate for a location. 
  • trunk/as2/lib/com/modestmaps/mapproviders/google/GoogleHybridMapProvider.as

    r260 r286  
    4848                        enqueuePaintRequest( clip, coord ); 
    4949                } 
    50                  
    51                 //createLabel( clip, coord.toString() ); 
    5250        }        
    5351 
  • trunk/as2/lib/com/modestmaps/mapproviders/VanillaMapProvider.as

    r191 r286  
    66  
    77import org.casaframework.event.DispatchableInterface; 
     8import com.modestmaps.geo.MercatorProjection; 
     9import com.modestmaps.geo.Transformation; 
    810 
    911import com.modestmaps.core.Coordinate; 
     
    1517implements IMapProvider, DispatchableInterface 
    1618{ 
    17         public function paintTile( clip : MovieClip, coord : Coordinate ) : Void  
     19    public function VanillaMapProvider() 
     20    { 
     21        super(); 
     22 
     23            // see: http://modestmaps.mapstraction.com/trac/wiki/TileCoordinateComparisons#TileGeolocations 
     24            var t:Transformation = new Transformation(1.068070779e7, 0, 3.355443185e7, 
     25                                                          0, -1.068070890e7, 3.355443057e7); 
     26                                                           
     27        __projection = new MercatorProjection(26, t); 
     28 
     29        __topLeftOutLimit = new Coordinate(0, Number.NEGATIVE_INFINITY, 0); 
     30        __bottomRightInLimit = (new Coordinate(1, Number.POSITIVE_INFINITY, 0)).zoomTo(20); 
     31    } 
     32 
     33        public function paint(clip:MovieClip, coord:Coordinate):Void  
    1834        { 
    19            super.paint( clip, coord ); 
    20  
    21                 with ( clip ) 
    22                 { 
    23                         clear(); 
    24                     moveTo(0, 0); 
    25                     lineStyle(0, 0x0099FF, 100); 
    26                     beginFill(0x000000, 20); 
    27                     lineTo(0, clip._height); 
    28                     lineTo(clip._width, clip._height); 
    29                     lineTo(clip._width, 0); 
    30                     lineTo(0, 0); 
    31                     endFill(); 
    32                 } 
    33  
    34             createLabel( clip, coord.toString() ); 
    35  
    36                 raisePaintComplete(); 
     35        super.paint(clip, coord); 
     36         
     37        clip.createTextField('label', clip.getNextHighestDepth(), 0, 0, 100, 100); 
     38        clip['label'].selectable = false; 
     39        clip['label'].textColor = 0xFFFFFF; 
     40        clip['label'].text = coord.toString(); 
     41        clip['label']._width = clip['label'].textWidth + 4; 
     42        clip['label']._height = clip['label'].textHeight + 2; 
     43         
     44        raisePaintComplete(); 
    3745        } 
    3846} 
  • trunk/as2/lib/com/modestmaps/mapproviders/yahoo/YahooAerialMapProvider.as

    r215 r286  
    1919        private function getTileUrl(coord:Coordinate):String 
    2020        {                
    21         return "http://us.maps3.yimg.com/aerial.maps.yimg.com/img?md=200605101500" + getZoomString(sourceCoordinate(coord));    
     21        return "http://us.maps3.yimg.com/aerial.maps.yimg.com/tile?v=1.7&t=a" + getZoomString(sourceCoordinate(coord)); 
    2222        } 
    2323         
     
    2525        {                
    2626        var row : Number = ( Math.pow( 2, coord.zoom ) /2 ) - coord.row - 1; 
    27  
    28                 var zoomString : String = "&x=" + coord.column +  
    29                         "&y=" + row +  
    30                         "&z=" + ( 18 - coord.zoom ) + 
    31                         "&v=1.5&t=a"; 
    32                 return zoomString;  
     27        return "&x=" + coord.column + "&y=" + row + "&z=" + (18 - coord.zoom); 
    3328        }        
    3429} 
  • trunk/as2/lib/com/modestmaps/mapproviders/yahoo/YahooHybridMapProvider.as

    r260 r286  
    4343        private function getBGTileUrl(coord:Coordinate):String 
    4444        {                
    45                return "http://us.maps3.yimg.com/aerial.maps.yimg.com/img?md=200605101500" + getZoomString(sourceCoordinate(coord)) + "&v=1.5&t=a"
     45        return "http://us.maps3.yimg.com/aerial.maps.yimg.com/tile?v=1.7&t=a" + getZoomString(sourceCoordinate(coord))
    4646        } 
    4747 
    4848        private function getOverlayTileUrl(coord:Coordinate):String 
    4949        {                
    50         return "http://us.maps3.yimg.com/aerial.maps.yimg.com/img?md=200608221700&v=2.0&t=h" + getZoomString(sourceCoordinate(coord)); 
     50        return "http://us.maps3.yimg.com/aerial.maps.yimg.com/png?v=2.2&t=h" + getZoomString(sourceCoordinate(coord)); 
    5151        } 
    5252         
     
    5555        {                
    5656        var row : Number = ( Math.pow( 2, coord.zoom ) /2 ) - coord.row - 1; 
    57  
    58                 var zoomString : String = "&x=" + coord.column +  
    59                         "&y=" + row +  
    60                         "&z=" + ( 18 - coord.zoom ); 
    61                 return zoomString;  
     57        return "&x=" + coord.column + "&y=" + row + "&z=" + (18 - coord.zoom); 
    6258        }        
    6359</