From: Richard Fairhurst Date: Tue, 1 Jun 2010 12:12:52 +0000 (+0000) Subject: make Yahoo code less horrid, and fix the overzooming bug X-Git-Tag: 0.5~432 X-Git-Url: https://git.openstreetmap.org/potlatch2.git/commitdiff_plain/7d0f75b82169983ba7ba1fe3468c8b372e3ae1f3 make Yahoo code less horrid, and fix the overzooming bug --- diff --git a/TODO.txt b/TODO.txt index 62afb099..654d59e2 100644 --- 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 diff --git a/net/systemeD/potlatch2/BackgroundSelector.mxml b/net/systemeD/potlatch2/BackgroundSelector.mxml index db54c984..1503f306 100644 --- a/net/systemeD/potlatch2/BackgroundSelector.mxml +++ b/net/systemeD/potlatch2/BackgroundSelector.mxml @@ -30,22 +30,16 @@ 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 index 00000000..04705289 --- /dev/null +++ b/net/systemeD/potlatch2/Yahoo.as @@ -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