Download on resize
[potlatch2.git] / net / systemeD / halcyon / Map.as
index 8a45b07..29aded4 100644 (file)
@@ -64,6 +64,7 @@ package net.systemeD.halcyon {
                public const NOT_DRAGGING:uint=0;                               //  |
                public const NOT_MOVED:uint=1;                                  //  |
                public const DRAGGING:uint=2;                                   //  |
+               public const SWALLOW_MOUSEUP:uint=3;                    //  |
                /** How far the map can be dragged without actually triggering a pan. */
                public const TOLERANCE:uint=7;                                  //  |
                
@@ -120,7 +121,7 @@ package net.systemeD.halcyon {
                // ------------------------------------------------------------------------------------------
                /** Recalculate co-ordinates from new Flash origin */
 
-               public function updateCoords(tx:Number,ty:Number):void {
+               private function updateCoords(tx:Number,ty:Number):void {
                        setScrollRectXY(tx,ty);
 
                        edge_t=coord2lat(-ty          );
@@ -133,7 +134,7 @@ package net.systemeD.halcyon {
                }
                
                /** Move the map to centre on a given latitude/longitude. */
-               public function updateCoordsFromLatLon(lat:Number,lon:Number):void {
+               private function updateCoordsFromLatLon(lat:Number,lon:Number):void {
                        var cy:Number=-(lat2coord(lat)-mapheight/2);
                        var cx:Number=-(lon2coord(lon)-mapwidth/2);
                        updateCoords(cx,cy);
@@ -205,6 +206,7 @@ package net.systemeD.halcyon {
                        mapwidth = w; centre_lon=coord2lon(-getX()+w/2);
                        mapheight= h; centre_lat=coord2lat(-getY()+h/2);
                        setScrollRectSize(w,h);
+                       updateCoords(getX(),getY());
 
                        this.dispatchEvent(new MapEvent(MapEvent.RESIZE, {width:w, height:h}));
                        
@@ -218,13 +220,14 @@ package net.systemeD.halcyon {
             }
                }
 
-        /** Download map data. Data is downloaded for the connection and the vector layers, where supported.
+        /** Download map data. Data is downloaded for the currently visible layers
         * 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} ));
                        for (var i:uint=0; i<paintContainer.numChildren; i++)
-                               getLayerAt(i).connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
+                               if(getLayerAt(i).visible == true) {
+                    getLayerAt(i).connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
+                }
                }
 
         // Handle mouse events on ways/nodes
@@ -388,7 +391,8 @@ package net.systemeD.halcyon {
                /** Prepare for being dragged by recording start time and location of mouse. */
                public function mouseDownHandler(event:MouseEvent):void {
                        if (!_draggable) { return; }
-                       dragstate=NOT_MOVED;
+                       if (dragstate==DRAGGING) { moveMap(x,y); dragstate=SWALLOW_MOUSEUP; }   // cancel drag if mouse-up occurred outside the window (thanks, Safari)
+                       else { dragstate=NOT_MOVED; }
                        lastxmouse=stage.mouseX; downX=stage.mouseX;
                        lastymouse=stage.mouseY; downY=stage.mouseY;
                        downTime=new Date().getTime();
@@ -427,6 +431,7 @@ package net.systemeD.halcyon {
 
                private function everyFrame(event:Event):void {
                        if (tileset) { tileset.serviceQueue(); }
+                       if (stage.focus && !stage.contains(stage.focus)) { stage.focus=stage; }
                }
 
                // ------------------------------------------------------------------------------------------
@@ -445,21 +450,5 @@ package net.systemeD.halcyon {
                        }
                }
 
-               // ------------------------------------------------------------------------------------------
-               // Debugging
-               
-               public function clearDebug():void {
-                       if (!Globals.vars.hasOwnProperty('debug')) return;
-                       Globals.vars.debug.text='';
-               }
-                       
-               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");
-                       Globals.vars.debug.scrollV=Globals.vars.debug.maxScrollV;
-               }
-
        }
 }