Don't reload the entire bbox when panning, just the newly uncovered bits.
[potlatch2.git] / net / systemeD / halcyon / connection / Connection.as
index 5893d8491f3a151fe99c3922ceb3ad6521807df6..4a7e12ba6e1b17268f256474f535be3a8e562dd6 100644 (file)
@@ -7,6 +7,7 @@ package net.systemeD.halcyon.connection {
     import net.systemeD.halcyon.AttentionEvent;
     import net.systemeD.halcyon.MapEvent;
     import net.systemeD.halcyon.connection.actions.*;
+    import net.systemeD.halcyon.connection.bboxes.*;
     import net.systemeD.halcyon.Globals;
 
        public class Connection extends EventDispatcher {
@@ -78,6 +79,10 @@ package net.systemeD.halcyon.connection {
                public static var RESUME_REDRAW:String = "resume_redraw";
         public static var TRACES_LOADED:String = "traces_loaded";
 
+               /** maximum number of /map calls to request for each pan/zoom */
+               protected const MAX_BBOXES:uint=3;
+               protected var fetchSet:FetchSet = new FetchSet(MAX_BBOXES);
+
         // store the data we download
         private var negativeID:Number = -1;
         private var nodes:Object = {};
@@ -94,7 +99,6 @@ package net.systemeD.halcyon.connection {
         private var traces:Vector.<Trace> = new Vector.<Trace>();
         private var nodePositions:Object = {};
         protected var traces_loaded:Boolean = false;
-               private var loadedBboxes:Array = [];
 
                /** maximum number of ways to keep in memory before purging */
                protected const MAXWAYS:uint=3000;
@@ -392,29 +396,12 @@ package net.systemeD.halcyon.connection {
                        return modified;
                }
 
-               // Keep track of the bboxes we've loaded
-
-               /** Has the data within this bbox already been loaded? */
-               protected function isBboxLoaded(left:Number,right:Number,top:Number,bottom:Number):Boolean {
-                       var l:Number,r:Number,t:Number,b:Number;
-                       for each (var box:Array in loadedBboxes) {
-                               l=box[0]; r=box[1]; t=box[2]; b=box[3];
-                               if (left>=l && left<=r && right>=l && right<=r && top>=b && top<=t && bottom>=b && bottom<=t) {
-                                       return true;
-                               }
-                       }
-                       return false;
-               }
-               /** Mark that bbox is loaded */
-               protected function markBboxLoaded(left:Number,right:Number,top:Number,bottom:Number):void {
-                       if (isBboxLoaded(left,right,top,bottom)) return;
-                       loadedBboxes.push([left,right,top,bottom]);
-               }
                /** Purge all data if number of ways exceeds limit */
                public function purgeIfFull(left:Number,right:Number,top:Number,bottom:Number):void {
                        if (waycount<=MAXWAYS) return;
                        purgeOutside(left,right,top,bottom);
-                       loadedBboxes=[[left,right,top,bottom]];
+                       fetchSet=new FetchSet(MAX_BBOXES);
+                       fetchSet.add(new Box().fromBbox(left,bottom,right,top));
                }
 
                // Changeset tracking