From 11ca2dc3f5abc885edc82a4b73efbab25ecb5d23 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Mon, 3 Jul 2017 18:25:34 +0200
Subject: [PATCH] point marker constructor simplified,

some logic moved to init function
---
 frontend-js/src/main/js/map/CustomMap.js      | 12 ++++---
 .../src/main/js/map/marker/PointMarker.js     | 34 +++++++++----------
 .../src/test/js/map/AbstractCustomMap-test.js | 13 ++++---
 3 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/frontend-js/src/main/js/map/CustomMap.js b/frontend-js/src/main/js/map/CustomMap.js
index 586bc98cf1..812f4c60cb 100644
--- a/frontend-js/src/main/js/map/CustomMap.js
+++ b/frontend-js/src/main/js/map/CustomMap.js
@@ -1273,10 +1273,14 @@ CustomMap.prototype.createMarkerForDbOverlay = function(element, dbOverlay) {
       return result;
     });
   } else if (element.getType() === "POINT") {
-    var pointData = submap.getModel().getPointDataByPoint(element.getPoint());
-    result = new PointMarker(pointData, element.getIcon(), submap);
-    dbOverlay.markers[element.getType()][element.getId()] = result;
-    return Promise.resolve(result);
+    result = new PointMarker({
+      element : element,
+      map : submap
+    });
+    return result.init().then(function() {
+      dbOverlay.markers[element.getType()][element.getId()] = result;
+      return result;
+    });
   } else {
     throw new Error("Unknown type of the element in overlay: " + element.type);
   }
diff --git a/frontend-js/src/main/js/map/marker/PointMarker.js b/frontend-js/src/main/js/map/marker/PointMarker.js
index a66fd27de9..88bfb6d6de 100644
--- a/frontend-js/src/main/js/map/marker/PointMarker.js
+++ b/frontend-js/src/main/js/map/marker/PointMarker.js
@@ -2,38 +2,34 @@
 
 var AbstractMarker = require('./AbstractMarker');
 var IdentifiedElement = require('../data/IdentifiedElement');
+var PointData = require('../data/PointData');
 
 /**
  * This class describes Google maps marker (connected to some specific point,
  * but not to any element) that is visualized on the map.
  */
-function PointMarker(pointData, icon, map) {
-  var ie = new IdentifiedElement(pointData);
-  ie.setIcon(icon);
-  AbstractMarker.call(this, {
-    element : ie,
-    map : map
-  });
-  this._pointData = pointData;
-  if (icon === null || icon === undefined) {
-    throw new Error("Icon must be not null");
-  }
-  if (typeof map === "undefined") {
-    throw new Error("Map must be passed");
-  }
-  this._init();
-  this.show();
+function PointMarker(params) {
+  var self = this;
+  AbstractMarker.call(self, params);
+  self.setPointData(new PointData(self.getIdentifiedElement()));
 }
 PointMarker.prototype = Object.create(AbstractMarker.prototype);
 PointMarker.prototype.constructor = PointMarker;
 
+PointMarker.prototype.init = function() {
+  var self = this;
+  return self._init().then(function() {
+    self.show();
+  });
+};
+
 /**
  * Returns identifier of the object.
  * 
  * @returns identifier of the object
  */
 PointMarker.prototype.getId = function() {
-  return this._id;
+  return this.getPointData().getId();
 };
 
 /**
@@ -45,6 +41,10 @@ PointMarker.prototype.getPointData = function() {
   return this._pointData;
 };
 
+PointMarker.prototype.setPointData = function(pointData) {
+  this._pointData = pointData;
+};
+
 PointMarker.prototype.getCoordinates = function() {
   return this._pointData.getPoint();
 };
diff --git a/frontend-js/src/test/js/map/AbstractCustomMap-test.js b/frontend-js/src/test/js/map/AbstractCustomMap-test.js
index bfb40b124e..14f888c8a0 100644
--- a/frontend-js/src/test/js/map/AbstractCustomMap-test.js
+++ b/frontend-js/src/test/js/map/AbstractCustomMap-test.js
@@ -352,10 +352,15 @@ describe('AbstractCustomMap', function() {
       var point = new google.maps.Point(2, 3.45);
       var pointData = new PointData(point, 15781);
 
-      var pointMarker = new PointMarker(pointData, "empty.png", mockObject);
-
-      assert.equal(null, mockObject.getPointInfoWindowById(pointData.getId()));
-      return mockObject._openInfoWindowForIdentifiedElement(pointMarker.getIdentifiedElement()).then(function() {
+      var pointMarker = new PointMarker({
+        element : new IdentifiedElement(pointData),
+        map : mockObject
+      });
+      
+      return pointMarker.init().then(function() {
+        assert.equal(null, mockObject.getPointInfoWindowById(pointData.getId()));
+        return mockObject._openInfoWindowForIdentifiedElement(pointMarker.getIdentifiedElement());
+      }).then(function() {
         assert.ok(mockObject.getPointInfoWindowById(pointData.getId()));
       });
     });
-- 
GitLab