refactor node stateClasses and stylelist calculation
[potlatch2.git] / net / systemeD / halcyon / VectorLayer.as
index 9ef040ea912710f469db399f62473f8c7d9bae6a..b27e0e8de04edcd1ee94a7a9a558337be8d1f779 100644 (file)
@@ -51,16 +51,14 @@ package net.systemeD.halcyon {
                public function getObjectsByBbox(left:Number, right:Number, top:Number, bottom:Number):Object {
                        // ** FIXME: this is just copied-and-pasted from Connection.as, which really isn't very
                        // good practice. Is there a more elegant way of doing it?
-                       var o:Object = { poisInside: [], poisOutside: [], waysInside: [], waysOutside: [] };
+                       var o:Object = { nodesInside: [], nodesOutside: [], waysInside: [], waysOutside: [] };
                        for each (var way:Way in ways) {
                                if (way.within(left,right,top,bottom)) { o.waysInside.push(way); }
                                                                  else { o.waysOutside.push(way); }
                        }
                        for each (var node:Node in nodes) {
-                               if (!node.hasParentWays) {
-                                       if (node.within(left,right,top,bottom)) { o.poisInside.push(node); }
-                                                                          else { o.poisOutside.push(node); }
-                               }
+                               if (node.within(left,right,top,bottom)) { o.nodesInside.push(node); }
+                                                                  else { o.nodesOutside.push(node); }
                        }
                        return o;
                }
@@ -70,14 +68,18 @@ package net.systemeD.halcyon {
                        if (entity is Way) {
                                // copy way through to main layer
                                // ** shouldn't do this if the nodes are already in the main layer
+                               //    (or maybe we should just match on lat/long to avoid ways in background having nodes in foreground)
                                var oldWay:Way=Way(entity);
                                var newWay:Way=connection.createWay(oldWay.getTagsCopy(), [], MainUndoStack.getGlobalStack().addAction);
+                               var nodemap:Object={};
+                               var oldNode:Node, newNode:Node;
                                for (i=0; i<oldWay.length; i++) {
-                                       var oldNode:Node = oldWay.getNode(i);
-                                       var newNode:Node = connection.createNode(
+                                       oldNode = oldWay.getNode(i);
+                                       newNode = nodemap[oldNode.id] ? nodemap[oldNode.id] : connection.createNode(
                                                oldNode.getTagsCopy(), oldNode.lat, oldNode.lon, 
                                                MainUndoStack.getGlobalStack().addAction);
                                        newWay.appendNode(newNode, MainUndoStack.getGlobalStack().addAction);
+                                       nodemap[oldNode.id]=newNode;
                                }
                                // delete this way
                                while (oldWay.length) {