package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.geom.Point;
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapOptions;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.controls.NavigationControl;
import com.google.maps.extras.rubberbandctrl.RubberBandCtrl;
/**
* The HelloMap class is a simple application that demonstrates a few concepts:
* 1. How to build a Google Map entirely from ActionScript 3 code
* 2. The use of the Preinitialize event to set the map's zoom and center.
* 3. Addition of built-in map controls.
* 4. Addition of Rubber band map control. This is a third-party control that
* provides more control over map navigation / pan / zoom, and can be downloaded
* from "http://code.google.com/p/gmaps-utility-library-flash".
*/
public class HelloMap extends Sprite
{
public function HelloMap ()
{
// POSITION AND SCALE MAP FRAME WITHIN BROWSER WINDOW
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
// REQUIRED MAP CONFIGURATION
map.key = " .. your API key goes here .. ";
map.setSize (new Point (900, 600));
// BUILT-IN MAP CONTROLS
map.addControl (new MapTypeControl ());
map.addControl (new NavigationControl ());
// REGISTER LISTENERS THAT WILL PERFORM MAP INITIALIZATION
map.addEventListener (MapEvent.MAP_PREINITIALIZE, onMapPreinitialize);
map.addEventListener (MapEvent.MAP_READY, onMapReady);
// MAKE THE MAP VISIBLE
addChild (map);
}
public function onMapPreinitialize (event:MapEvent):void
{
map.setInitOptions (
new MapOptions ( {
center: new LatLng (40,-90),
zoom: 4
}
));
}
public function onMapReady (event:MapEvent):void
{
// INITIALIZE RUBBER BAND CONTROL
rbCtrl.enable (map);
rbCtrl.setPanIncrement (250);
}
private const map:Map = new Map ();
private const rbCtrl:RubberBandCtrl = new RubberBandCtrl ();
}
}
