Topo2 - Prevent the map to reload when naviggating regions with the same mapId

Change-Id: Ib9c896aa28b95982f106fdb617418c39f98f54fb
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Background.js b/web/gui/src/main/webapp/app/view/topo2/topo2Background.js
index 7aee3ed..f0312f5 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Background.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Background.js
@@ -77,16 +77,7 @@
                             pan = zoomPan(this.zoomData),
                             scale = zoomScale(this.zoomData);
 
-                        // TODO: test for same background... avoid reload on same
-
-                        //  Avoid re-loading the background / sprite layer
-                        //  if the type and ID are same as last time.
-
-                        //  For example, europe map can be panned/zoomed to
-                        //   focus on different countries
-
                         if (this.bgType === 'geo') {
-
                             // Hide Sprite Layer and show Map
                             t2sls.hide();
                             t2ms.show();
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Map.js b/web/gui/src/main/webapp/app/view/topo2/topo2Map.js
index 2c28ec0..06a5885 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Map.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Map.js
@@ -29,7 +29,7 @@
     var MapSelectionDialog;
 
     // internal state
-    var instance, mapG, zoomLayer, zoomer;
+    var instance, mapG, zoomLayer, zoomer, currentMap;
 
     function init() {
         this.appendElement('#topo2-background', 'g');
@@ -37,9 +37,16 @@
         zoomer = t2zs.getZoomer();
     }
 
-    // TODO: to be re-worked: map-id, filePath, scale/pan to be passed as params
     function setUpMap(mapId, mapFilePath, mapScale) {
 
+        if (currentMap === mapId) {
+            return new Promise(function(resolve) {
+                resolve();
+            });
+        }
+
+        currentMap = mapId;
+
         var loadMap = ms.loadMapInto,
             promise, cfilter;
 
@@ -59,21 +66,6 @@
         return promise;
     }
 
-    // TODO: deprecated - the layout will tell us which map
-    //   no longer stored in user preferences
-    function currentMap() {
-        return ps.getPrefs(
-            'topo2_mapid',
-            {
-                mapid: 'usa',
-                mapscale: 1,
-                mapfilepath: '*continental_us',
-                tint: 'off'
-            },
-            $loc.search()
-        );
-    }
-
     // TODO: deprecated - maps are defined per layout on the server side.
     function setMap(map) {
         ps.setPrefs('topo2_mapid', map);
@@ -102,6 +94,10 @@
         this.node().style('stroke-width', (2.0 / sc) + 'px');
     }
 
+    function getCurrentMap() {
+        return currentMap;
+    }
+
     angular.module('ovTopo2')
     .factory('Topo2MapService', [
         '$log', '$location', 'Topo2ViewController', 'PrefsService',
@@ -132,7 +128,8 @@
                 setUpMap: setUpMap,
                 openMapSelection: openMapSelection,
                 resetZoom: resetZoom,
-                zoomCallback: zoomCallback
+                zoomCallback: zoomCallback,
+                getCurrentMap: getCurrentMap
             });
 
             return instance || new MapLayer();