Merge remote-tracking branch 'randomjunk/minor-updates'
authorRichard Fairhurst <richard@systemeD.net>
Sat, 2 Apr 2011 12:52:44 +0000 (13:52 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 2 Apr 2011 12:52:44 +0000 (13:52 +0100)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/XMLBaseConnection.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/potlatch2/TagGrid.mxml
net/systemeD/potlatch2/TagViewer.mxml

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;
 
index 555e6ef6318732f1d53d7658fa20a59846d3462f..6abbd69e7a9cbc143b4321801133774ca20a27e0 100644 (file)
 
                /** Assign a new selected Entity, and update editing controls appropriately. */
                public function init(entity:Entity):void {
+                       if (selectedEntity==entity) return;
+                       if (selectedEntity) selectedEntity.removeEventListener(Connection.TAG_CHANGED, tagChanged);
+
+                       selectedEntity=entity;
+                       if (!selectedEntity) return;
+                       selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged, false, 0, true);
+
                        if ( tagDataProvider == null ) {
                                tagDataProvider = new ArrayCollection();
                                dataProvider = tagDataProvider;
+                       } else {
+                               tagDataProvider.removeAll();
                        }
 
-                       if (selectedEntity==entity) return;
-                       selectedEntity=entity;
-                       updateTagDataProvider(true);
-               }
-
-               private function updateTagDataProvider(force:Boolean=false):void {
-                       if (editedItemPosition && !force) return;
-
-                       tagDataProvider.removeAll();
-                       if (selectedEntity==null) { return; }
                        var tags:Array = selectedEntity.getTagArray();
                        tags.sortOn("key");
                        for each(var tag:Tag in tags) { tagDataProvider.addItem(tag); }
                }
 
+               /** Update dataProvider in response to a tag being edited or removed */
+               private function tagChanged(event:TagEvent):void {
+                       var set:Boolean=false;
+                       for (var i:uint=0; i<tagDataProvider.length; i++) {
+                               if (tagDataProvider[i].key==event.oldKey) {
+                                       if (event.newValue && event.key) {
+                                               if (!set) {
+                                                       // this entry in the dataProvider has changed
+                                                       tagDataProvider[i].key=event.key;
+                                                       tagDataProvider[i].value=event.newValue;
+                                                       set=true;
+                                               } else {
+                                                       // trap duplicate tags
+                                                       tagDataProvider.removeItemAt(i);
+                                               }
+                                       } else {
+                                               // this entry in the dataProvider has been deleted
+                                               tagDataProvider.removeItemAt(i);
+                                       }
+                               }
+                       }
+                       // tell Flex to redraw the grid because we've changed a tag
+                       invalidateList();
+               }
+
                /** Create editing controls for a new key/value pair, with default values. */
                public function addNewTag():void {
                        var newKey:String = "(new tag)";
                public function removeTag():void {
                        var k:String = selectedItem.key;
                        selectedEntity.setTag(k, null, MainUndoStack.getGlobalStack().addAction);
-                       updateTagDataProvider();
                }
 
                /** Return the type ("node", "way", "relation") of the selected entity. */
index bc79c8d6ce77cbb16068ca9f9dd644a65c346cd2..3c4c9c0c306ec8eac1ac52455b671175478eb2b1 100644 (file)
        }
 
       private function tagChanged(event:TagEvent):void {
-             if(selectedEntity != null && selectedEntity is EntityCollection) {
-                       setupMultiAdvanced(selectedEntity);
-                   return;
-                 }
-
           refreshFeatureIcon();
-          // ** FIXME - changing tags on Advanced tab should update simple view
-          // (but putting initialiseEditors here breaks other stuff, because it causes
-          // the Basic pane to be selected)
-
-          // if the advancedTagGrid has already been set up, it needs to be refreshed.
-          // FIXME make this better, maybe advancedTagGrid should be event listening.
-          if(advancedContainer.initialized) {
-            checkAdvanced();
-          }
       }
 
       public function loadFeatures():void {