Bing support. Add a <scheme>microsoft</scheme> parameter to imagery.xml for this...
authorRichard Fairhurst <richard@systemed.net>
Tue, 23 Nov 2010 18:31:33 +0000 (18:31 +0000)
committerRichard Fairhurst <richard@systemed.net>
Tue, 23 Nov 2010 18:31:33 +0000 (18:31 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/TileSet.as
potlatch2.mxml

index 748d12c..772b1b5 100644 (file)
@@ -66,8 +66,8 @@ package net.systemeD.halcyon {
                public var initparams:Object;                                   // object containing HTML page parameters
 
                public var backdrop:Object;                                             // reference to backdrop sprite
-               public var tileset:TileSet;                                             // 900913 tile background
-               private var tileurl:String='';                                  // internal tile URL
+               public var tileset:TileSet;                                             // background tile object
+               private var tileparams:Object={ url:'' };               // background tile URL, name and scheme
                private var styleurl:String='';                                 // internal style URL
                public var showall:Boolean=true;                                // show all objects, even if unstyled?
                
@@ -120,7 +120,7 @@ package net.systemeD.halcyon {
 
                        tileset=new TileSet(this);                                      // 0 - 900913 background
                        addChild(tileset);                                                      //   |
-                       tileset.init(tileurl);                                          //   |
+                       tileset.init(tileparams);                                       //   |
 
                        vectorbg = new Sprite();                                        // 1 - vector background layers
                        addChild(vectorbg);                                                     //   |
@@ -361,9 +361,9 @@ package net.systemeD.halcyon {
                        }
         }
 
-               public function setBackground(url:String):void {
-                       tileurl=url;
-                       if (tileset) { tileset.init(url, url!=''); }
+               public function setBackground(bg:Object):void {
+                       tileparams=bg;
+                       if (tileset) { tileset.init(bg, bg.url!=''); }
                }
 
                public function setDimming(dim:Boolean):void {
index 0b2b81d..9f829fa 100644 (file)
@@ -21,6 +21,7 @@ package net.systemeD.halcyon {
                private var tiles:Object={};            // key is "z,x,y"; value "true" (needed) or reference to sprite
                private var waiting:int=0;                      // number of tiles currently being downloaded
                private var baseurl:String;                     // e.g. http://npe.openstreetmap.org/$z/$x/$y.png
+               private var scheme:String;                      // 900913 or microsoft
 
                private var map:Map;
 
@@ -32,8 +33,9 @@ package net.systemeD.halcyon {
                        map.addEventListener(MapEvent.NUDGE_BACKGROUND, nudgeHandler);
                }
        
-               public function init(url:String=null, update:Boolean=false):void {
-                       baseurl=url;
+               public function init(params:Object, update:Boolean=false):void {
+                       baseurl=params.url;
+                       scheme =params.scheme ? params.scheme : '900913';
                        tiles={};
                        offset_lon=offset_lat=x=y=0;
                        while (numChildren) { removeChildAt(0); }
@@ -95,7 +97,7 @@ package net.systemeD.halcyon {
                                        var loader:Loader = new Loader();
                                        loader.contentLoaderInfo.addEventListener(Event.INIT, doImgInit);
                        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, missingTileError);
-                                       loader.load(new URLRequest(tileURL(tx,ty)), 
+                                       loader.load(new URLRequest(tileURL(tx,ty,tz)), 
                                                    new LoaderContext(true));
                                        l=this.getChildAt(map.scale-map.MINSCALE);
                                        Sprite(l).addChild(loader);
@@ -127,8 +129,23 @@ package net.systemeD.halcyon {
                
                // Assemble tile URL
                
-               private function tileURL(tx:int,ty:int):String {
-                       return baseurl.replace('$z',map.scale).replace('$x',tx).replace('$y',ty);
+               private function tileURL(tx:int,ty:int,tz:uint):String {
+                       switch (scheme.toLowerCase()) {
+
+                               case 'microsoft':
+                                       var u:String='';
+                                       for (var zoom:uint=tz; zoom>0; zoom--) {
+                                               var byte:uint=0;
+                                               var mask:uint=1<<(zoom-1);
+                                               if ((tx & mask)!=0) byte++;
+                                               if ((ty & mask)!=0) byte+=2;
+                                               u+=String(byte);
+                                       }
+                                       return baseurl.replace('$quadkey',u);
+
+                               default:
+                                       return baseurl.replace('$z',map.scale).replace('$x',tx).replace('$y',ty);
+                       }       
                }
                
                public function get url():String {
index ce71e99..0c87181 100644 (file)
                }
                
                public function setBackground(bg:Object):void {
-                       if (bg.url=='yahoo') { theMap.setBackground(''    ); yahoo.show(); }
-                                       else { theMap.setBackground(bg.url); yahoo.hide(); }
+                       if (bg.url=='yahoo') { theMap.setBackground(''); yahoo.show(); }
+                                       else { theMap.setBackground(bg); yahoo.hide(); }
                        theController.imagerySelected=bg;
                        var obj:SharedObject = SharedObject.getLocal("user_state");
                        obj.setProperty('background_url' ,String(bg.url));