Enlarge requested bbox by 20% on each side to make for easier panning; keep list...
authorRichard Fairhurst <richard@systemeD.net>
Sat, 2 Apr 2011 12:49:31 +0000 (13:49 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 2 Apr 2011 12:49:31 +0000 (13:49 +0100)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/XMLBaseConnection.as
net/systemeD/halcyon/connection/XMLConnection.as

index 793ea839eeab60c9ab5cd9ae4dd238428246c6a1..ffc920a02d63f6c2d8d235a03711ec4cdd840e66 100644 (file)
@@ -37,10 +37,6 @@ package net.systemeD.halcyon {
                public var scale:uint=14;                                                
                /** current scaling factor for lon/latp */
                public var scalefactor:Number=MASTERSCALE;
-               public var bigedge_l:Number= 999999;                    // area of largest whichways
-               public var bigedge_r:Number=-999999;                    //  |
-               public var bigedge_b:Number= 999999;                    //  |
-               public var bigedge_t:Number=-999999;                    //  |
 
                public var edge_l:Number;                                               // current bounding box
                public var edge_r:Number;                                               //  |
@@ -282,14 +278,6 @@ package net.systemeD.halcyon {
         */
                public function download():void {
                        this.dispatchEvent(new MapEvent(MapEvent.DOWNLOAD, {minlon:edge_l, maxlon:edge_r, maxlat:edge_t, minlat:edge_b} ));
-                       
-                       if (edge_l>=bigedge_l && edge_r<=bigedge_r &&
-                               edge_b>=bigedge_b && edge_t<=bigedge_t) { return; }     // we have already loaded this area, so ignore
-                       bigedge_l=edge_l; bigedge_r=edge_r;
-                       bigedge_b=edge_b; bigedge_t=edge_t;
-                       if (connection.waycount>1000) {
-                               connection.purgeOutside(edge_l,edge_r,edge_t,edge_b);
-                       }
                        connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
 
             // Do the same for vector layers
index 9e3b7bc935c9821b657104fbcb664d3d817adc92..0821a5b94f9a06ea65ee1f72e976a8a12fbdd2c0 100644 (file)
@@ -101,6 +101,10 @@ package net.systemeD.halcyon.connection {
         private var traces:Array = [];
         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;
 
         protected function get nextNegative():Number {
             return negativeID--;
@@ -362,6 +366,31 @@ 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]);
+               }
+
                // Changeset tracking
 
         protected function setActiveChangeset(changeset:Changeset):void {
index b99e70fb98e1a52bbe17663c9ba44a9124e94e9a..7d083b5e6019a6876b3bff905552040b40474194 100644 (file)
@@ -139,6 +139,7 @@ package net.systemeD.halcyon.connection {
                 }
             }
             
+            markBboxLoaded(minlon,maxlon,maxlat,minlat);
             registerPOINodes();
             dispatchEvent(new Event(LOAD_COMPLETED));
         }
index c7baa4d7f2afc0fb4fd12803bbeaaf1498ad3de9..cd0b4ae927eab751a6a1e68e8c47c7238a03c9c0 100644 (file)
@@ -28,6 +28,15 @@ 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;