Don't reload the entire bbox when panning, just the newly uncovered bits.
[potlatch2.git] / net / systemeD / halcyon / connection / XMLConnection.as
index 9b94f2079f92792359cfcd5266fc59f2c8d6609b..d07ef96dd8e91cf80d82434a30410dbdda59323f 100644 (file)
@@ -9,6 +9,7 @@ package net.systemeD.halcyon.connection {
 
        import net.systemeD.halcyon.AttentionEvent;
        import net.systemeD.halcyon.MapEvent;
+    import net.systemeD.halcyon.connection.bboxes.*;
 
     /**
     * XMLConnection provides all the methods required to connect to a live
@@ -18,6 +19,8 @@ package net.systemeD.halcyon.connection {
     */
        public class XMLConnection extends XMLBaseConnection {
 
+               private const MARGIN:Number=0.05;
+
         /**
         * Create a new XML connection
         * @param name The name of the connection
@@ -38,21 +41,24 @@ package net.systemeD.halcyon.connection {
                override public function loadBbox(left:Number,right:Number,
                                                                top:Number,bottom:Number):void {
             purgeIfFull(left,right,top,bottom);
-            if (isBboxLoaded(left,right,top,bottom)) return;
-
-            // enlarge bbox by 20% on each edge
-            var xmargin:Number=(right-left)/5;
-            var ymargin:Number=(top-bottom)/5;
-            left-=xmargin; right+=xmargin;
-            bottom-=ymargin; top+=ymargin;
-
-            var mapVars:URLVariables = new URLVariables();
-            mapVars.bbox= left+","+bottom+","+right+","+top;
-
-            var mapRequest:URLRequest = new URLRequest(apiBaseURL+"map");
-            mapRequest.data = mapVars;
-
-            sendLoadRequest(mapRequest);
+                       var requestBox:Box=new Box().fromBbox(left,bottom,right,top);
+                       var boxes:Array=fetchSet.getBoxes(requestBox,MAX_BBOXES);
+                       for each (var box:Box in boxes) {
+                               // enlarge bbox by given margin on each edge
+                               var xmargin:Number=(box.right-box.left)*MARGIN;
+                               var ymargin:Number=(box.top-box.bottom)*MARGIN;
+                               left  =box.left  -xmargin; right=box.right+xmargin;
+                               bottom=box.bottom-ymargin; top  =box.top  +ymargin;
+
+                               dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:left, maxlon:right, maxlat:top, minlat:bottom} ));
+
+                               // send HTTP request
+                               var mapVars:URLVariables = new URLVariables();
+                               mapVars.bbox=left+","+bottom+","+right+","+top;
+                               var mapRequest:URLRequest = new URLRequest(apiBaseURL+"map");
+                               mapRequest.data = mapVars;
+                               sendLoadRequest(mapRequest);
+                       }
                }
 
                override public function loadEntityByID(type:String, id:Number):void {
@@ -76,7 +82,6 @@ package net.systemeD.halcyon.connection {
                        dispatchEvent(new Event(LOAD_COMPLETED));
         }
         private function mapLoadStatus(event:HTTPStatusEvent):void {
-            trace("loading map status = "+event.status);
         }
 
         protected var appID:OAuthConsumer;