From 1754fa3debb8004fb33e92224fc1e17c18c0370f Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Thu, 19 Jul 2018 14:55:05 +0200
Subject: [PATCH] overlay aliases are processed only on a submap when it's
 necessary

---
 .../src/main/js/map/AbstractCustomMap.js      | 86 +++++++++----------
 1 file changed, 42 insertions(+), 44 deletions(-)

diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js
index 967fff2cb0..37df8b1d24 100644
--- a/frontend-js/src/main/js/map/AbstractCustomMap.js
+++ b/frontend-js/src/main/js/map/AbstractCustomMap.js
@@ -362,65 +362,63 @@ AbstractCustomMap.prototype._showSelectedDataOverlay = function (overlayId, inde
   // end ratio
   var endX = (index + 1) * (1.0 / length);
 
-  var overlayAliases;
-  var overlayReactions;
+  var overlayAliases = [];
+  var overlayReactions = [];
 
   return self.getProject().getDataOverlayById(overlayId).then(function (overlay) {
-    overlayAliases = overlay.getAliases();
-    overlayReactions = overlay.getReactions();
+    var aliases = overlay.getAliases();
+    var reactions = overlay.getReactions();
 
     var i, identifiedElements = [];
-    for (i = 0; i < overlayAliases.length; i++) {
-      if (overlayAliases[i].getModelId() === self.getId()) {
-        identifiedElements.push(new IdentifiedElement(overlayAliases[i]));
+    for (i = 0; i < aliases.length; i++) {
+      if (aliases[i].getModelId() === self.getId()) {
+        identifiedElements.push(new IdentifiedElement(aliases[i]));
+        overlayAliases.push(aliases[i]);
       }
     }
-    for (i = 0; i < overlayReactions.length; i++) {
-      if (overlayReactions[i].getModelId() === self.getId()) {
-        identifiedElements.push(new IdentifiedElement(overlayReactions[i]));
+    for (i = 0; i < reactions.length; i++) {
+      if (reactions[i].getModelId() === self.getId()) {
+        identifiedElements.push(new IdentifiedElement(reactions[i]));
+        overlayReactions.push(reactions[i]);
       }
     }
     return self.getModel().getByIdentifiedElements(identifiedElements, false);
   }).then(function () {
     return Promise.each(overlayAliases, function (overlayAlias) {
-      if (overlayAlias.getModelId() === self.getId()) {
-        return self.getModel().getAliasById(overlayAlias.getId()).then(function (aliasData) {
-          var surface = new AliasSurface({
-            overlayAlias: overlayAlias,
-            alias: aliasData,
-            map: self,
-            startX: startX,
-            endX: endX,
-            onClick: [function () {
-              return self.getTopMap().getOverlayByName("search").searchByTarget(new IdentifiedElement(aliasData));
-            }, function () {
-              return self.getTopMap().callListeners("onBioEntityClick", new IdentifiedElement(aliasData));
-            }]
-          });
-          self.selectedLayoutOverlays[overlayId].push(surface);
-          return surface.show();
+      return self.getModel().getAliasById(overlayAlias.getId()).then(function (aliasData) {
+        var surface = new AliasSurface({
+          overlayAlias: overlayAlias,
+          alias: aliasData,
+          map: self,
+          startX: startX,
+          endX: endX,
+          onClick: [function () {
+            return self.getTopMap().getOverlayByName("search").searchByTarget(new IdentifiedElement(aliasData));
+          }, function () {
+            return self.getTopMap().callListeners("onBioEntityClick", new IdentifiedElement(aliasData));
+          }]
         });
-      }
+        self.selectedLayoutOverlays[overlayId].push(surface);
+        return surface.show();
+      });
     });
   }).then(function () {
     return Promise.each(overlayReactions, function (overlayReaction) {
-      if (overlayReaction.getModelId() === self.getId()) {
-        return self.getModel().getReactionById(overlayReaction.getId()).then(function (reactionData) {
-          var surface = new ReactionSurface({
-            layoutReaction: overlayReaction,
-            reaction: reactionData,
-            map: self,
-            onClick: [function () {
-              return self.getTopMap().getOverlayByName("search").searchByTarget(new IdentifiedElement(reactionData));
-            }, function () {
-              return self.getTopMap().callListeners("onBioEntityClick", new IdentifiedElement(reactionData));
-            }],
-            customized: (length === 1)
-          });
-          self.selectedLayoutOverlays[overlayId].push(surface);
-          return surface.show();
+      return self.getModel().getReactionById(overlayReaction.getId()).then(function (reactionData) {
+        var surface = new ReactionSurface({
+          layoutReaction: overlayReaction,
+          reaction: reactionData,
+          map: self,
+          onClick: [function () {
+            return self.getTopMap().getOverlayByName("search").searchByTarget(new IdentifiedElement(reactionData));
+          }, function () {
+            return self.getTopMap().callListeners("onBioEntityClick", new IdentifiedElement(reactionData));
+          }],
+          customized: (length === 1)
         });
-      }
+        self.selectedLayoutOverlays[overlayId].push(surface);
+        return surface.show();
+      });
     });
   });
 };
@@ -440,7 +438,7 @@ AbstractCustomMap.prototype._hideSelectedLayout = function (overlayId) {
     return Promise.resolve();
   }
 
-  var promises =[];
+  var promises = [];
   for (var i = 0; i < this.selectedLayoutOverlays[overlayId].length; i++) {
     promises.push(this.selectedLayoutOverlays[overlayId][i].hide());
   }
-- 
GitLab