Changeset 160

Show
Ignore:
Timestamp:
03/09/07 15:35:52 (2 years ago)
Author:
migurski
Message:

Merged API branch

Files:

Legend:

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

    r144 r160  
    44 */ 
    55 
    6 import com.modestmaps.geo.Map; 
     6import com.modestmaps.Map; 
    77import com.modestmaps.geo.Location; 
    88import com.modestmaps.core.Coordinate; 
     
    114114    public function resetTiles(coord:Coordinate, point:Point):Void 
    115115    { 
     116        if(!tiles) { 
     117            setInitialTile(coord, point); 
     118            return; 
     119        } 
     120     
    116121        var initTile:Tile; 
    117122        var condemnedTiles:/*Tile*/Array = activeTiles(); 
     
    187192    } 
    188193     
    189     public function putMarker(name:String, coord:Coordinate, location:Location):Marker 
    190     { 
    191         var marker:Marker = new Marker(name, coord, location); 
    192         //log('Marker '+name+': '+coord.toString()); 
     194    public function putMarker(id:String, coord:Coordinate, location:Location):Marker 
     195    { 
     196        var marker:Marker = new Marker(id, coord, location); 
     197        //log('Marker '+id+': '+coord.toString()); 
    193198        markers.put(marker); 
    194199 
     
    197202    } 
    198203 
    199     public function removeMarker(name:String):Void 
    200     { 
    201         var marker:Marker = markers.getMarker(name); 
    202         if (marker) 
    203         { 
     204    public function removeMarker(id:String):Void 
     205    { 
     206        var marker:Marker = markers.getMarker(id); 
     207        if(marker) 
    204208            markers.remove(marker); 
    205         } 
    206209    } 
    207210         
     
    321324 
    322325        if(previousPosition.x != well._x || previousPosition.y != well._y) 
    323             map.onWellPanned(new Point(well._x - __startingWellPosition.x, well._y - __startingWellPosition.y)); 
     326            map.onPanned(new Point(well._x - __startingWellPosition.x, well._y - __startingWellPosition.y)); 
    324327         
    325328        wellDragTask = Reactor.callNextFrame(Delegate.create(this, this.onWellDrag), new Point(well._x, well._y)); 
     
    409412    { 
    410413        var point:Point = new Point(0, 0); 
     414        return pointCoordinate(point); 
     415    } 
     416     
     417    public function centerCoordinate():Coordinate 
     418    { 
     419        var point:Point = new Point(width/2, height/2); 
    411420        return pointCoordinate(point); 
    412421    } 
     
    490499        //log('Starting well position: '+__startingWellPosition.toString()); 
    491500         
    492         map.onStartDrag(); 
     501        map.onStartPan(); 
    493502        well.startDrag(false, xMin, yMin, xMax, yMax); 
    494503        onWellDrag(__startingWellPosition.copy()); 
     
    501510    private function stopWellDrag():Void 
    502511    { 
    503         map.onStopDrag(); 
     512        map.onStopPan(); 
    504513        wellDragTask.cancel(); 
    505514        well.stopDrag(); 
     
    965974        for(var id:String in newOverlappingMarkers) { 
    966975            if(newOverlappingMarkers[id] && !__overlappingMarkers[id]) { 
    967                 map.onMarkerEnters(markers.getMarker(id)); 
     976                map.onMarkerEnters(id, markers.getMarker(id).location); 
    968977                __overlappingMarkers[id] = true; 
    969978            } 
     
    972981        for(var id:String in __overlappingMarkers) { 
    973982            if(!newOverlappingMarkers[id] && __overlappingMarkers[id]) { 
    974                 map.onMarkerLeaves(markers.getMarker(id)); 
     983                map.onMarkerLeaves(id, markers.getMarker(id).location); 
    975984                delete __overlappingMarkers[id]; 
    976985            } 
  • trunk/as2/lib/com/modestmaps/geo/Location.as

    r57 r160  
    1212    public function toString():String 
    1313    { 
    14         return '(' + lat + ',' + lon + ')'; 
     14        var roundLat:Number = Math.round(lat * 10000) / 10000; 
     15        var roundLon:Number = Math.round(lon * 10000) / 10000; 
     16 
     17        return '('+roundLat+','+roundLon+')'; 
    1518    } 
    1619} 
  • trunk/as2/lib/SampleClient.as

    r143 r160  
    11import mx.utils.Delegate; 
    22import com.stamen.twisted.Reactor; 
    3 import com.modestmaps.geo.Map; 
     3import com.modestmaps.Map; 
    44import com.modestmaps.core.TileGrid; 
    55import com.modestmaps.mapproviders.MapProviders; 
     
    99class SampleClient 
    1010{ 
    11         private static var __map : Map; 
    12          
    13         private static var __mpButtons : MovieClip
     11        private static var __map:Map; 
     12        private static var __mapButtons:MovieClip; 
     13        private static var __status:TextField
    1414         
    1515    public static function main(clip:MovieClip):Void 
     
    1717        Reactor.run(clip, null, 50); 
    1818 
    19                 var initObj : Object = 
    20                 { 
    21                         mapProvider: MapProviderFactory.getInstance().getMapProvider(MapProviders.GOOGLE_ROAD),  
    22                         _x: 128,  
    23                         _y: 128,  
    24                         width: Stage.width - 256,  
    25                         height: Stage.height - 256, 
    26                         draggable: true 
    27                 }; 
    28  
    29         __map = Map(clip.attachMovie(Map.symbolName, 'map', clip.getNextHighestDepth(), initObj )); 
     19        __map = Map(clip.attachMovie(Map.symbolName, 'map', clip.getNextHighestDepth())); 
     20        __map.init(Stage.width-256, Stage.height-256, true, MapProviderFactory.getInstance().getMapProvider(MapProviders.GOOGLE_ROAD)); 
     21        __map.addEventListener(Map.EVENT_ZOOMED_BY, onZoomed); 
     22        __map.addEventListener(Map.EVENT_STOP_ZOOMING, onStopZoom); 
     23        __map.addEventListener(Map.EVENT_PANNED_BY, onPanned); 
     24        __map.addEventListener(Map.EVENT_STOP_PANNING, onStopPan); 
     25        __map.addEventListener(Map.EVENT_RESIZED_TO, onResized); 
     26         
     27        __status = clip.createTextField('status', clip.getNextHighestDepth(), 0, 0, 600, 100); 
     28        __status.selectable = false; 
     29        __status.textColor = 0x000000; 
     30        __status.text = '...'; 
     31        __status._height = __status.textHeight + 2; 
    3032 
    3133        var extent:/*Location*/Array = [new Location(37.829853, -122.514725), 
    3234                                        new Location(37.700121, -122.212601)]; 
    3335         
    34         __map.setInitialExtent(extent); 
     36        __map.setExtent(extent); 
    3537 
    3638        //Reactor.callLater(2000, Delegate.create(__map, __map.setNewCenter), new Location(37.811411, -122.360916), 14); 
     
    5052        Stage.align = 'TL'; 
    5153        Stage.addListener(SampleClient); 
     54        onResize(); 
    5255         
    53         var buttons : Array = new Array(); 
     56        var buttons:Array = new Array(); 
    5457         
    55         buttons.push( makeButton(clip, 'plus', 'zoom in', Delegate.create(__map, __map.zoomIn))); 
    56         buttons.push( makeButton(clip, 'minus', 'zoom out', Delegate.create(__map, __map.zoomOut))); 
    57         buttons.push( makeButton(clip, 'clear', 'clear log', Delegate.create(__map.grid, __map.grid.clearLog))); 
     58        buttons.push(makeButton(clip, 'plus', 'zoom in', Delegate.create(__map, __map.zoomIn))); 
     59        buttons.push(makeButton(clip, 'minus', 'zoom out', Delegate.create(__map, __map.zoomOut))); 
     60        buttons.push(makeButton(clip, 'left', 'pan left', Delegate.create(__map, __map.panLeft))); 
     61        buttons.push(makeButton(clip, 'up', 'pan up', Delegate.create(__map, __map.panUp))); 
     62        buttons.push(makeButton(clip, 'down', 'pan down', Delegate.create(__map, __map.panDown))); 
     63        buttons.push(makeButton(clip, 'left', 'pan right', Delegate.create(__map, __map.panRight))); 
     64        buttons.push(makeButton(clip, 'clear', 'clear log', Delegate.create(__map.grid, __map.grid.clearLog))); 
    5865 
    59                 var nextX : Number = __map._x; 
    60                 var nextY : Number = __map._y - buttons[0]['label']._height - 10; 
     66                var nextX:Number = __map._x; 
     67                var nextY:Number = __map._y - buttons[0]['label']._height - 10; 
    6168                 
    62                 for ( var i : Number = 0; i < buttons.length; i++ ) 
    63                 { 
     69                for(var i:Number = 0; i < buttons.length; i++) { 
    6470                        buttons[i]._x = nextX; 
    6571                        buttons[i]._y = nextY; 
     
    6773                } 
    6874 
    69  
    7075                // mapProvider buttons 
    7176 
    72                 __mpButtons = clip.createEmptyMovieClip( "mpButtons", clip.getNextHighestDepth() ); 
     77                __mapButtons = clip.createEmptyMovieClip("mpButtons", clip.getNextHighestDepth()); 
    7378 
    7479        buttons = new Array(); 
    7580                 
    76                 buttons.push( makeButton(__mpButtons, 'MICROSOFT_ROAD', 'ms road', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    77         buttons.push( makeButton(__mpButtons, 'MICROSOFT_AERIAL', 'ms aerial', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    78         buttons.push( makeButton(__mpButtons, 'MICROSOFT_HYBRID', 'ms hybrid', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     81                buttons.push(makeButton(__mapButtons, 'MICROSOFT_ROAD', 'ms road', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     82        buttons.push(makeButton(__mapButtons, 'MICROSOFT_AERIAL', 'ms aerial', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     83        buttons.push(makeButton(__mapButtons, 'MICROSOFT_HYBRID', 'ms hybrid', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    7984 
    80                 buttons.push( makeButton(__mpButtons, 'GOOGLE_ROAD', 'google road', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    81         buttons.push( makeButton(__mpButtons, 'GOOGLE_AERIAL', 'google aerial', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    82         buttons.push( makeButton(__mpButtons, 'GOOGLE_HYBRID', 'google hybrid', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     85                buttons.push(makeButton(__mapButtons, 'GOOGLE_ROAD', 'google road', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     86        buttons.push(makeButton(__mapButtons, 'GOOGLE_AERIAL', 'google aerial', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     87        buttons.push(makeButton(__mapButtons, 'GOOGLE_HYBRID', 'google hybrid', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    8388 
    84                 buttons.push( makeButton(__mpButtons, 'YAHOO_ROAD', 'yahoo road', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    85         buttons.push( makeButton(__mpButtons, 'YAHOO_AERIAL', 'yahoo aerial', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    86         buttons.push( makeButton(__mpButtons, 'YAHOO_HYBRID', 'yahoo hybrid', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     89                buttons.push(makeButton(__mapButtons, 'YAHOO_ROAD', 'yahoo road', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     90        buttons.push(makeButton(__mapButtons, 'YAHOO_AERIAL', 'yahoo aerial', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     91        buttons.push(makeButton(__mapButtons, 'YAHOO_HYBRID', 'yahoo hybrid', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    8792 
    88         buttons.push( makeButton(__mpButtons, 'BLUE_MARBLE', 'blue marble', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    89         buttons.push( makeButton(__mpButtons, 'OPEN_STREET_MAP', 'open street map', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     93        buttons.push(makeButton(__mapButtons, 'BLUE_MARBLE', 'blue marble', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
     94        buttons.push(makeButton(__mapButtons, 'OPEN_STREET_MAP', 'open street map', Delegate.create(SampleClient, SampleClient.switchMapProvider))); 
    9095 
    91                 __mpButtons._x = 128 + __map._x + __map._width; 
    92                 __mpButtons._y = __map._y + 10; 
    93                  
    9496                nextY = 0; 
    9597                 
    96                 for ( var i : Number = 0; i < buttons.length; i++ ) 
    97                 { 
     98                for(var i:Number = 0; i < buttons.length; i++) { 
    9899                        buttons[i]._y = nextY; 
    99100                        nextY += buttons[i]['label']._height + 5; 
    100101                        buttons[i]._alpha = 60; 
    101102                } 
    102                  
    103103 
    104         Reactor.callNextFrame(Delegate.create(__map, __map.nagAboutBoundsForever)); 
    105          
    106104        _root.createEmptyMovieClip('marks', _root.getNextHighestDepth()); 
    107105    } 
    108106     
    109107     
    110     private static function switchMapProvider( button : MovieClip ) : Void 
     108    private static function switchMapProvider(button:MovieClip):Void 
    111109    { 
    112110        __map.setMapProvider(MapProviderFactory.getInstance().getMapProvider(MapProviders[button._name])); 
    113111    } 
    114      
    115112     
    116113    public static function makeButton(clip:MovieClip, name:String, label:String, action:Function):MovieClip 
     
    135132        button.onRelease = function() 
    136133        { 
    137                 action.apply( SampleClient, [button] ); 
     134                action.apply(SampleClient, [button]); 
    138135        }; 
    139136         
     
    141138    } 
    142139     
    143     public static function output( str : String ) : Void 
     140    public static function output(str:String):Void 
    144141    { 
    145         trace( str );  
     142        trace(str);    
    146143    } 
    147144     
    148145    // Event Handlers 
    149146     
    150     private static function onResize() : Void 
     147    private static function onResize():Void 
    151148    { 
     149        __map._x = __map._y = 50; 
    152150        __map.setSize(Stage.width - 2*__map._x, Stage.height - 2*__map._y); 
    153                 __mpButtons._x = __map._x + (Stage.width - 2*__map._x) - __mpButtons._width - 10;     
     151 
     152                __mapButtons._x = __map._x + (Stage.width - 2*__map._x) - __mapButtons._width - 10; 
     153                __mapButtons._y = __map._y + 10; 
     154 
     155                __status._width = __map.getSize()[0]; 
     156                __status._x = __map._x + 2; 
     157                __status._y = __map._y + __map.getSize()[1]; 
    154158        } 
     159     
     160    private static function onPanned(event:Object):Void 
     161    { 
     162        __status.text = 'Panned by '+event.delta.toString()+', top left: '+__map.getExtent()[0].toString()+', bottom right: '+__map.getExtent()[3].toString(); 
     163    } 
     164     
     165    private static function onStopPan(event:Object):Void 
     166    { 
     167        __status.text = 'Stopped panning, top left: '+__map.getExtent()[0].toString()+', center: '+__map.getCenterZoom()[0].toString()+', bottom right: '+__map.getExtent()[3].toString()+', zoom: '+__map.getCenterZoom()[1]; 
     168    } 
     169     
     170    private static function onZoomed(event:Object):Void 
     171    { 
     172        __status.text = 'Zoomed by '+event.delta.toString()+', top left: '+__map.getExtent()[0].toString()+', bottom right: '+__map.getExtent()[3].toString(); 
     173    } 
     174     
     175    private static function onStopZoom(event:Object):Void 
     176    { 
     177        __status.text = 'Stopped zooming, top left: '+__map.getExtent()[0].toString()+', center: '+__map.getCenterZoom()[0].toString()+', bottom right: '+__map.getExtent()[3].toString()+', zoom: '+__map.getCenterZoom()[1]; 
     178    } 
     179     
     180    private static function onResized(event:Object):Void 
     181    { 
     182        __status.text = 'Resized to: '+event.width+' x '+event.height; 
     183    } 
    155184     
    156185    private static function onMarkerEnters(event:Object):Void 
    157186    { 
    158         __map.grid.log('+ '+event.markerID.toString()+' =)'); 
     187        __map.grid.log('+ '+event.id+' =)'); 
    159188    } 
    160189     
    161190    private static function onMarkerLeaves(event:Object):Void 
    162191    { 
    163         __map.grid.log('- '+event.markerID.toString()+' =('); 
     192        __map.grid.log('- '+event.id+' =('); 
    164193    } 
    165194} 
  • trunk/as2/lib/SampleFlashLiteClient.as

    r137 r160  
    11import mx.utils.Delegate; 
    22import com.stamen.twisted.Reactor; 
    3 import com.modestmaps.geo.Map; 
     3import com.modestmaps.Map; 
    44import com.modestmaps.geo.Location; 
    55import com.modestmaps.mapproviders.MapProviders; 
     
    1717         
    1818        __map = Map(clip.attachMovie(Map.symbolName, 'map', clip.getNextHighestDepth(), 
    19                                      {mapProvider: MapProviderFactory.getInstance().getMapProvider(MapProviders.MICROSOFT_AERIAL), 
    20                                       _x: 0, _y: 0, width: Stage.width, height: Stage.height, 
    21                                       draggable: true})); 
     19                                     {_x: 0, _y: 0})); 
    2220         
     21        __map.init(Stage.width, Stage.height, true, MapProviderFactory.getInstance().getMapProvider(MapProviders.MICROSOFT_AERIAL));  
    2322 
    2423        var extent:/*Location*/Array = [new Location(37.829853, -122.514725), 
    2524                                        new Location(37.700121, -122.212601)]; 
    2625         
    27         __map.setInitialExtent(extent); 
     26        __map.setExtent(extent); 
    2827         
    2928                // Set up key listeners.  
     
    3837                        { 
    3938                                case Key.RIGHT: 
    40                                         map.panEast( Stage.width ); 
     39                                        map.panRight(); 
    4140                                        break;   
    4241                                 
    4342                                case Key.LEFT: 
    44                                         map.panWest( Stage.width ); 
     43                                        map.panLeft(); 
    4544                                        break; 
    4645 
    4746                                case Key.UP: 
    48                                         map.panNorth( Stage.height ); 
     47                                        map.panUp(); 
    4948                                        break;   
    5049                                 
    5150                                case Key.DOWN: 
    52                                         map.panSouth( Stage.height ); 
     51                                        map.panDown(); 
    5352                                        break; 
    5453                        }