From ffc43abc87469fcd49b9c0a87a2d5d8f4c449f85 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Thu, 15 Mar 2018 10:46:14 +0100
Subject: [PATCH] getcenter method implemented

---
 .../src/main/js/map/AbstractCustomMap.js      |  5 +++++
 .../src/main/js/plugin/MinervaPluginProxy.js  |  7 +++++++
 .../test/js/plugin/MinervaPluginProxy-test.js | 20 +++++++++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js
index c5387bf2af..3c9ca63ffa 100644
--- a/frontend-js/src/main/js/map/AbstractCustomMap.js
+++ b/frontend-js/src/main/js/map/AbstractCustomMap.js
@@ -1069,6 +1069,11 @@ AbstractCustomMap.prototype.setCenter = function (coordinates) {
   }
 };
 
+AbstractCustomMap.prototype.getCenter = function () {
+  var coordinates = this.getGoogleMap().getCenter();
+  return this.fromLatLngToPoint(coordinates);
+};
+
 /**
  * Sets zoom level for google maps.
  *
diff --git a/frontend-js/src/main/js/plugin/MinervaPluginProxy.js b/frontend-js/src/main/js/plugin/MinervaPluginProxy.js
index 40eeb4fb94..496f20b31e 100644
--- a/frontend-js/src/main/js/plugin/MinervaPluginProxy.js
+++ b/frontend-js/src/main/js/plugin/MinervaPluginProxy.js
@@ -402,6 +402,13 @@ function createProjectMap(options) {
       }
       return submap.setCenter(new google.maps.Point(params.x, params.y));
     },
+    getCenter: function (params) {
+      var submap = map.getSubmapById(params.modelId);
+      if (submap === null) {
+        throw new Error("Unknown modelId: " + params.modelId);
+      }
+      return submap.getCenter();
+    },
     fitBounds: function (params) {
       var submap = map.getSubmapById(params.modelId);
       if (submap === null) {
diff --git a/frontend-js/src/test/js/plugin/MinervaPluginProxy-test.js b/frontend-js/src/test/js/plugin/MinervaPluginProxy-test.js
index f6ff68f9fd..72bb640b70 100644
--- a/frontend-js/src/test/js/plugin/MinervaPluginProxy-test.js
+++ b/frontend-js/src/test/js/plugin/MinervaPluginProxy-test.js
@@ -310,6 +310,26 @@ describe('MinervaPluginProxy', function () {
     });
   });
 
+  it("getCenter", function () {
+    var map, proxy;
+    return ServerConnector.getProject().then(function (project) {
+      map = helper.createCustomMap(project);
+      proxy = createProxy(map);
+      return proxy.project.map.setCenter({
+        modelId: 15781,
+        x: 10,
+        y: 20
+      });
+    }).then(function () {
+      var center = proxy.project.map.getCenter({modelId: 15781});
+      assert.ok(center instanceof google.maps.Point);
+      assert.closeTo(parseFloat(center.x), 10, helper.EPSILON);
+      assert.closeTo(parseFloat(center.y), 20, helper.EPSILON);
+    }).then(function () {
+      map.destroy();
+    });
+  });
+
   it("setZoom", function () {
     var map, proxy;
     return ServerConnector.getProject().then(function (project) {
-- 
GitLab