From 7f67121cc5929e2c79720573598067426393fc7b Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Thu, 5 Jul 2018 12:34:11 +0200
Subject: [PATCH] triggereing events moved to init (due to promise use)

---
 frontend-js/src/main/js/map/CustomMap.js | 67 +++++++++++++-----------
 frontend-js/src/test/js/minerva-test.js  |  4 +-
 2 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/frontend-js/src/main/js/map/CustomMap.js b/frontend-js/src/main/js/map/CustomMap.js
index f2989dc1a5..76e1d04497 100644
--- a/frontend-js/src/main/js/map/CustomMap.js
+++ b/frontend-js/src/main/js/map/CustomMap.js
@@ -95,17 +95,42 @@ CustomMap.prototype.init = function () {
     ids.push(mapType);
   }
 
-  return Promise.each(ids, function (overlayId) {
-    try {
-      return self.openDataOverlay(overlayId);
-    } catch (e) {
-      if (e instanceof SecurityError) {
-        logger.debug(e.message);
-        sessionData.setSelectedBackgroundOverlay(self.getProject().getDataOverlays()[0].getId());
-      } else {
-        return Promise.reject(e);
-      }
+  return Promise.all([self.getMapCanvas().triggerListeners('resize'),
+    // noinspection SpellCheckingInspection
+    self.getMapCanvas().triggerListeners('maptypeid_changed'),
+    self.getMapCanvas().triggerListeners('projection_changed')
+  ]).then(function() {
+
+    // center map and zoom in to fit into browser window if there is no
+    // information about coordinates in the session
+
+    var x = self.getModel().getDefaultCenterX();
+    var y = self.getModel().getDefaultCenterY();
+    var zoom = self.getModel().getDefaultZoomLevel();
+    if (self.getServerConnector().getSessionData(self.getProject()).getCenter(self.getModel()) === undefined &&
+      (x === undefined || y === undefined || zoom === undefined ||
+        x === null || y === null || zoom === null
+      )) {
+      var bounds = new Bounds();
+      bounds.extend(self.getTopLeft());
+      bounds.extend(self.getBottomRight());
+
+      self.getMapCanvas().fitBounds(bounds);
     }
+
+
+    return Promise.each(ids, function (overlayId) {
+      try {
+        return self.openDataOverlay(overlayId);
+      } catch (e) {
+        if (e instanceof SecurityError) {
+          logger.debug(e.message);
+          sessionData.setSelectedBackgroundOverlay(self.getProject().getDataOverlays()[0].getId());
+        } else {
+          return Promise.reject(e);
+        }
+      }
+    });
   }).then(function () {
     return self.getServerConnector().getLogoImg();
   }).then(function (url) {
@@ -473,28 +498,6 @@ CustomMap.prototype.customizeGoogleMapView = function (div) {
   self.createMapCanvas(div);
 
   self.createLogo();
-
-  self.getMapCanvas().triggerListeners('resize');
-  // noinspection SpellCheckingInspection
-  self.getMapCanvas().triggerListeners('maptypeid_changed');
-  self.getMapCanvas().triggerListeners('projection_changed');
-
-  // center map and zoom in to fit into browser window if there is no
-  // information about coordinates in the session
-
-  var x = self.getModel().getDefaultCenterX();
-  var y = self.getModel().getDefaultCenterY();
-  var zoom = self.getModel().getDefaultZoomLevel();
-  if (self.getServerConnector().getSessionData(self.getProject()).getCenter(self.getModel()) === undefined &&
-    (x === undefined || y === undefined || zoom === undefined ||
-      x === null || y === null || zoom === null
-    )) {
-    var bounds = new Bounds();
-    bounds.extend(self.getTopLeft());
-    bounds.extend(self.getBottomRight());
-
-    self.getMapCanvas().fitBounds(bounds);
-  }
 };
 
 /**
diff --git a/frontend-js/src/test/js/minerva-test.js b/frontend-js/src/test/js/minerva-test.js
index 48bdb5c1e3..c05f6d7095 100644
--- a/frontend-js/src/test/js/minerva-test.js
+++ b/frontend-js/src/test/js/minerva-test.js
@@ -108,8 +108,8 @@ describe('minerva global', function () {
       }).then(function (result) {
         var center = ServerConnectorMock.getSessionData(options.getProject()).getCenter(options.getProject().getModels()[0]);
         assert.ok(center instanceof Point);
-        assert.equal(center.x, 5);
-        assert.equal(center.y, 6);
+        assert.closeTo(center.x, 5, helper.EPSILON);
+        assert.closeTo(center.y, 6, helper.EPSILON);
         return result.destroy();
       });
     });
-- 
GitLab