public var edge_r:Number; // |
public var edge_t:Number; // |
public var edge_b:Number; // |
+ public var centre_lat:Number; // centre lat/lon
+ public var centre_lon:Number; // |
public var baselon:Number; // urllon-xradius/masterscale;
public var basey:Number; // lat2lat2p(urllat)+yradius/masterscale;
edge_b=coord2lat(-y+mapheight);
edge_l=coord2lon(-x );
edge_r=coord2lon(-x+mapwidth );
+ setCentre();
addDebug("Lon "+edge_l+"-"+edge_r);
addDebug("Lat "+edge_b+"-"+edge_t);
var cx:Number=-(lon2coord(lon)-mapwidth/2);
updateCoords(cx,cy);
}
-
+
+ private function setCentre():void {
+ centre_lat=coord2lat(-y+mapheight/2);
+ centre_lon=coord2lon(-x+mapwidth/2);
+ this.dispatchEvent(new MapEvent(MapEvent.MOVE, {lat:centre_lat, lon:centre_lon, scale:scale}));
+ }
// Co-ordinate conversion functions
// Resize map size based on current stage and height
public function updateSize(w:uint, h:uint):void {
+ this.dispatchEvent(new MapEvent(MapEvent.RESIZE, {width:w, height:h}));
+
mapwidth = w;
mapheight= h;
if ( backdrop != null ) {
// (typically from whichways, but will want to add more connections)
public function download():void {
- this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD,edge_l,edge_r,edge_t,edge_b));
+ this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:edge_l, maxlon:edge_r, maxlat:edge_t, minlat:edge_b} ));
if (edge_l>=bigedge_l && edge_r<=bigedge_r &&
edge_b>=bigedge_b && edge_t<=bigedge_t) { return; } // we have already loaded this area, so ignore
x+=mouseX-lastxmouse;
y+=mouseY-lastymouse;
lastxmouse=mouseX; lastymouse=mouseY;
+ setCentre();
}
// ------------------------------------------------------------------------------------------
public class MapEvent extends Event {
public static const DOWNLOAD:String = "download";
- public var minlon:Number, maxlon:Number, maxlat:Number, minlat:Number;
+ public static const RESIZE:String = "resize";
+ public static const MOVE:String = "move";
- public function MapEvent(eventname:String, minlon:Number, maxlon:Number, maxlat:Number, minlat:Number) {
+ public var params:Object;
+
+ public function MapEvent(eventname:String, params:Object) {
super(eventname);
- this.minlat = minlat;
- this.minlon = minlon;
- this.maxlat = maxlat;
- this.maxlon = maxlon;
+ this.params=params;
}
}
import mx.core.IChildList;
import mx.containers.Canvas;
import mx.core.Application;
+ import com.yahoo.maps.api.YahooMap;
+ import com.yahoo.maps.api.YahooMapEvent;
+ import com.yahoo.maps.api.core.location.LatLon;
public var theMap:Map;
b.graphics.endFill();
_root.addChild(b);
+ // Add Yahoo! background
+ var yahoo:YahooMap = new YahooMap();
+ yahoo.init("f0a.sejV34HnhgIbNSmVHmndXFpijgGeun0fSIMG9428hW_ifF3pYKwbV6r9iaXojl1lU_dakekR", w, h);
+ yahoo.mapType="satellite";
+ _root.addChild(yahoo);
+
+ // Yahoo! listeners
+ var yahooListener:Object = new Object();
+ yahooListener.yahooInit=function(event:YahooMapEvent):void {
+ yahoo.zoomLevel = 18-theMap.scale;
+ yahoo.centerLatLon = new LatLon(theMap.centre_lat, theMap.centre_lon);
+
+ yahooListener.moveHandler=function(event:MapEvent):void {
+ yahoo.zoomLevel=18-event.params.scale;
+ yahoo.centerLatLon=new LatLon(event.params.lat, event.params.lon);
+ };
+ theMap.addEventListener(MapEvent.MOVE, yahooListener.moveHandler);
+
+ yahooListener.resizeHandler=function(event:MapEvent):void {
+ yahoo.setSize(event.params.width, event.params.height);
+ };
+ theMap.addEventListener(MapEvent.RESIZE, yahooListener.resizeHandler);
+ }
+ yahoo.addEventListener(YahooMapEvent.MAP_INITIALIZE, yahooListener.yahooInit);
+
// add map
theMap=new Map(this.loaderInfo.parameters);
theMap.backdrop=b;
// example listener event
var myListenerObj:Object = new Object();
myListenerObj.mapHandler=function(event:MapEvent):void {
- Globals.vars.debug.appendText("Download event fired - "+event.minlat+","+event.minlon+"\n");
+ Globals.vars.debug.appendText("Download event fired - "+event.params.minlat+","+event.params.minlon+"\n");
};
theMap.addEventListener(MapEvent.DOWNLOAD, myListenerObj.mapHandler);
// add debug field
var t:TextField=new TextField();
- t.width=400; t.height=100; t.border=true;
+ t.width=500; t.height=100; t.border=true;
t.multiline=true;
_root.addChild(t);
Globals.vars.debug=t;