Dispatch an event when the map sprites etc have been initialized
[potlatch2.git] / net / systemeD / halcyon / Map.as
old mode 100755 (executable)
new mode 100644 (file)
index 6e83556..836c0e1
@@ -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);                                                     //   |
@@ -143,6 +143,7 @@ package net.systemeD.halcyon {
                        basey      =lat2latp(startlat)+(mapheight/2)/scalefactor;
                        addDebug("Baselon "+baselon+", basey "+basey);
                        updateCoords(0,0);
+            this.dispatchEvent(new Event(MapEvent.INITIALISED));
                        download();
                        
         }
@@ -220,10 +221,9 @@ package net.systemeD.halcyon {
             }
                }
 
-               // ------------------------------------------------------------------------------------------
-               // Download map data
-               // (typically from whichways, but will want to add more connections)
-
+        /** Download map data. Data is downloaded for the connection and the vector layers, where supported.
+        * The bounding box for the download is taken from the current map edges.
+        */
                public function download():void {
                        this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:edge_l, maxlon:edge_r, maxlat:edge_t, minlat:edge_b} ));
                        
@@ -236,6 +236,11 @@ package net.systemeD.halcyon {
                        }
                        addDebug("Calling download with "+edge_l+"-"+edge_r+", "+edge_t+"-"+edge_b);
                        connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
+
+            // Do the same for vector layers
+            for each (var layer:VectorLayer in vectorlayers) {
+              layer.loadBbox(edge_l,edge_r,edge_t,edge_b);
+            }
                }
 
         private function newWayCreated(event:EntityEvent):void {
@@ -266,20 +271,22 @@ package net.systemeD.halcyon {
         }
 
         public function setHighlightOnNodes(way:Way, settings:Object):void {
-                       paint.wayuis[way.id].setHighlightOnNodes(settings);
+                       if (paint.wayuis[way.id]) paint.wayuis[way.id].setHighlightOnNodes(settings);
         }
 
-               public function setPurgable(entity:Entity, purgable:Boolean):void {
-                       if ( entity is Way  ) {
-                               var way:Way=entity as Way;
-                               paint.wayuis[way.id].purgable=purgable;
-                               for (var i:uint=0; i<way.length; i++) {
-                                       if (paint.nodeuis[way.getNode(i).id]) {
-                                               paint.nodeuis[way.getNode(i).id].purgable=purgable;
+               public function setPurgable(entities:Array, purgable:Boolean):void {
+                       for each (var entity:Entity in entities) {
+                               if ( entity is Way  ) {
+                                       var way:Way=entity as Way;
+                                       if (paint.wayuis[way.id]) { paint.wayuis[way.id].purgable=purgable; }
+                                       for (var i:uint=0; i<way.length; i++) {
+                                               if (paint.nodeuis[way.getNode(i).id]) {
+                                                       paint.nodeuis[way.getNode(i).id].purgable=purgable;
+                                               }
                                        }
+                               } else if ( entity is Node && paint.nodeuis[entity.id]) { 
+                                       paint.nodeuis[entity.id].purgable=purgable;
                                }
-                       } else if ( entity is Node ) { 
-                               paint.nodeuis[entity.id].purgable=purgable;
                        }
                }
 
@@ -355,9 +362,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 {
@@ -462,6 +469,7 @@ package net.systemeD.halcyon {
                }
                        
                public function addDebug(text:String):void {
+                       trace(text);
                        if (!Globals.vars.hasOwnProperty('debug')) return;
                        if (!Globals.vars.debug.visible) return;
                        Globals.vars.debug.appendText(text+"\n");