make Yahoo code less horrid, and fix the overzooming bug
authorRichard Fairhurst <richard@systemed.net>
Tue, 1 Jun 2010 12:12:52 +0000 (12:12 +0000)
committerRichard Fairhurst <richard@systemed.net>
Tue, 1 Jun 2010 12:12:52 +0000 (12:12 +0000)
TODO.txt
net/systemeD/potlatch2/BackgroundSelector.mxml
net/systemeD/potlatch2/Yahoo.as [new file with mode: 0644]

index 62afb09912bce9b83807eb06e1cea5ed3ca0282a..654d59e24452b503f0c37815728ef84f21d1593d 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -51,7 +51,6 @@ Potlatch 2: main outstanding issues
 * Quick-search on add-relations-to-way dialog (RelationSelectPanel)
 * Bug: when drawing way, escape ends drawing. Should revert to previous way.
 * Mouse icon should indicate when a join is being made (blue nodes might not be visible)
-* Yahoo! layer can't handle z18+, (Bug:) and continues to show z17 when zoomed in
 * i18n
 
 
index db54c9845bead30ad9e42a4337f47582342f8aa6..1503f3061e372ffa9ab8795fbe3f26f437a2c917 100644 (file)
                import net.systemeD.potlatch2.*;
                import mx.core.*;
                import mx.managers.PopUpManager;
-               import com.yahoo.maps.api.YahooMap;
-               import com.yahoo.maps.api.YahooMapEvent;
-               import com.yahoo.maps.api.core.location.LatLon;
 
                private function updateBackground():void {
             var theMap:Map = Globals.vars.root;
-            var yahoo:YahooMap = Globals.vars.yahoo;
                        var bg:String=background.selectedItem.data;
                        if (bg=='yahoo') {
                                theMap.tileset.init('',false);
-                               yahoo.visible=true;
-                               yahoo.zoomLevel = 18-theMap.scale;
-                               yahoo.centerLatLon = new LatLon(theMap.centre_lat, theMap.centre_lon);
+                               Globals.vars.yahoo.show();
                        } else {
                                theMap.tileset.init(background.selectedItem.data,true);
-                               yahoo.visible=false;
+                               Globals.vars.yahoo.hide();
                        }
                }
                
diff --git a/net/systemeD/potlatch2/Yahoo.as b/net/systemeD/potlatch2/Yahoo.as
new file mode 100644 (file)
index 0000000..0470528
--- /dev/null
@@ -0,0 +1,61 @@
+package net.systemeD.potlatch2 {
+
+       import flash.display.*;
+       import net.systemeD.halcyon.Map;
+       import net.systemeD.halcyon.MapEvent;
+       import com.yahoo.maps.api.YahooMap;
+       import com.yahoo.maps.api.YahooMapEvent;
+       import com.yahoo.maps.api.core.location.LatLon;
+       
+    public class Yahoo extends YahooMap {
+
+               private var map:Map;
+               private static const token:String="f0a.sejV34HnhgIbNSmVHmndXFpijgGeun0fSIMG9428hW_ifF3pYKwbV6r9iaXojl1lU_dakekR";
+               private static const MAXZOOM:int=17;
+
+               public function Yahoo(w:Number, h:Number, map:Map) {
+                       super();
+                       this.init(token, w, h);  
+                       this.mapType="satellite";
+                       this.alpha=0.5;
+                       this.map=map;
+               }
+               
+               public function show():void {
+                       this.visible=true;
+                       this.zoomLevel = 18-map.scale;
+                       this.centerLatLon = new LatLon(map.centre_lat, map.centre_lon);
+
+                       this.addEventListener(YahooMapEvent.MAP_INITIALIZE, initHandler);
+                       map.addEventListener(MapEvent.MOVE, moveHandler);
+                       map.addEventListener(MapEvent.RESIZE, resizeHandler);
+               }
+
+               public function hide():void {
+                       this.visible=false;
+
+                       this.removeEventListener(YahooMapEvent.MAP_INITIALIZE, initHandler);
+                       map.removeEventListener(MapEvent.MOVE, moveHandler);
+                       map.removeEventListener(MapEvent.RESIZE, resizeHandler);
+               }
+               
+               private function initHandler(event:YahooMapEvent):void {
+                       moveto(map.centre_lat, map.centre_lon, map.scale);
+               }
+
+               private function moveHandler(event:MapEvent):void {
+                       moveto(event.params.lat, event.params.lon, event.params.scale);
+               }
+
+               private function moveto(lat:Number,lon:Number,scale:uint):void {
+                       if (scale>MAXZOOM) { this.visible=false; return; }
+                       this.visible=true;
+                       this.zoomLevel=18-scale;
+                       this.centerLatLon=new LatLon(lat, lon);
+               }
+
+               private function resizeHandler(event:MapEvent):void {
+                       this.setSize(event.params.width, event.params.height);
+               }
+       }
+}
\ No newline at end of file