Yahoo! background support for Potlatch 2
authorRichard Fairhurst <richard@systemed.net>
Sun, 11 Oct 2009 14:34:54 +0000 (14:34 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 11 Oct 2009 14:34:54 +0000 (14:34 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/MapEvent.as
potlatch2.mxml

index d98b794d6dd958aa06b6970294ebe3eaec474c76..d0d719f5e0fba0ba4276ff61c7e919beaac157d0 100755 (executable)
@@ -56,6 +56,8 @@ package net.systemeD.halcyon {
                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;
@@ -195,6 +197,7 @@ package net.systemeD.halcyon {
                        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);
 
@@ -206,7 +209,12 @@ package net.systemeD.halcyon {
                        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
 
@@ -229,6 +237,8 @@ package net.systemeD.halcyon {
                // 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 ) {
@@ -246,7 +256,7 @@ package net.systemeD.halcyon {
                // (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
@@ -368,6 +378,7 @@ package net.systemeD.halcyon {
                        x+=mouseX-lastxmouse;
                        y+=mouseY-lastymouse;
                        lastxmouse=mouseX; lastymouse=mouseY;
+                       setCentre();
                }
         
                // ------------------------------------------------------------------------------------------
index 87262d3e640f7fb4a129b0e1ee0b8b521f542b15..15cee9263801561449837c41ed3abb5c5cf2adb0 100644 (file)
@@ -5,14 +5,14 @@ package net.systemeD.halcyon {
     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;
         }
     }
 
index ca19e63de613aaef7310cf13c7cb40e78dd0ef04..82545fb7597c3d33aabfc21ce9f46eb29586296a 100755 (executable)
@@ -57,6 +57,9 @@
                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;