ONOS-2470: Implement "Reset Node Locations" function in topology view.
- also cleaned up some Long/Lat code.
- Note also that metadata from client is structured so 'lng/lat' properties
    (from repositioned node) are wrapped in 'equivLoc' object.

Change-Id: I5afc53d26ef56fc0932f8650e8f7df79b36c3947
diff --git a/web/gui/src/main/webapp/app/view/topo/topoModel.js b/web/gui/src/main/webapp/app/view/topo/topoModel.js
index a21fc93..418285c 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoModel.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoModel.js
@@ -62,7 +62,13 @@
             y = meta && meta.y,
             xy;
 
-        // If we have [x,y] already, use that...
+        // if the device contains explicit LONG/LAT data, use that to position
+        if (setLongLat(node)) {
+            // indicate we want to update cached meta data...
+            return true;
+        }
+
+        // else if we have [x,y] cached in meta data, use that...
         if (x && y) {
             node.fixed = true;
             node.px = node.x = x;
@@ -70,17 +76,6 @@
             return;
         }
 
-        var location = node.location,
-            coord;
-
-        if (location && location.type === 'latlng') {
-            coord = coordFromLngLat(location);
-            node.fixed = true;
-            node.px = node.x = coord[0];
-            node.py = node.y = coord[1];
-            return true;
-        }
-
         // if this is a node update (not a node add).. skip randomizer
         if (forUpdate) {
             return;
@@ -116,6 +111,25 @@
         angular.extend(node, xy);
     }
 
+    function setLongLat(node) {
+        var loc = node.location,
+            coord;
+
+        if (loc && loc.type === 'lnglat') {
+            coord = coordFromLngLat(loc);
+            node.fixed = true;
+            node.px = node.x = coord[0];
+            node.py = node.y = coord[1];
+            return true;
+        }
+    }
+
+    function resetAllLocations() {
+        nodes.forEach(function (d) {
+            setLongLat(d);
+        });
+    }
+
     function mkSvgCls(dh, t, on) {
         var ndh = 'node ' + dh,
             ndht = t ? ndh + ' ' + t : ndh;
@@ -428,6 +442,7 @@
                 destroyModel: destroyModel,
 
                 positionNode: positionNode,
+                resetAllLocations: resetAllLocations,
                 createDeviceNode: createDeviceNode,
                 createHostNode: createHostNode,
                 createHostLink: createHostLink,