Topo2: Handle regions without a map/sprite
Change-Id: Ifa944499992843c1506462caae0e1646b204996b
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 9c5eb81..8fa9822 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Background.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Background.js
@@ -43,14 +43,15 @@
this.appendElement('#topo2-zoomlayer', 'g');
t2sls.init();
t2ms.init();
+ this.zoomer = t2zs.getZoomer();
},
addLayout: function (data) {
- var _this = this;
-
this.background = data;
this.bgType = data.bgType;
- _this.region.loaded('bgRendered', false);
+
+ var _this = this,
+ pan = [this.background.bgZoomPanX, this.background.bgZoomPanY];
if (this.bgType === 'geo') {
@@ -67,10 +68,9 @@
// $log.debug('** Zoom restored:', z);
$log.debug('** We installed the projection:', proj);
_this.region.loaded('bgRendered', true);
+ t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
});
- }
-
- if (this.bgType === 'grid') {
+ } else if (this.bgType === 'grid') {
// Hide Sprite Layer and show Map
t2ms.hide();
@@ -79,7 +79,14 @@
t2sls.loadLayout(data.bgId).then(function (spriteLayout) {
_this.background.layout = spriteLayout;
_this.region.loaded('bgRendered', true);
+ t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
});
+ } else {
+ // No background type - Tell the region the background is ready for placing nodes
+ t2ms.hide();
+ t2sls.hide();
+ // _this.region.loaded('bgRendered', true);
+ // t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
}
},
getBackgroundType: function () {
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Link.js b/web/gui/src/main/webapp/app/view/topo2/topo2Link.js
index e94ed6c..fbdeab3 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Link.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Link.js
@@ -299,6 +299,9 @@
}
},
setScale: function () {
+
+ if (!this.el) return;
+
var width = linkScale(widthRatio) / t2zs.scale();
this.el.style('stroke-width', width + 'px');
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2NodeModel.js b/web/gui/src/main/webapp/app/view/topo2/topo2NodeModel.js
index fa3a345..94a4ef9 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2NodeModel.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2NodeModel.js
@@ -229,6 +229,8 @@
},
setScale: function () {
+ if (!this.el) return;
+
var dim = devIconDim,
multipler = 1;
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2NodePosition.js b/web/gui/src/main/webapp/app/view/topo2/topo2NodePosition.js
index af708fb..d41acfe 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2NodePosition.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2NodePosition.js
@@ -150,13 +150,11 @@
function coordFromXY(loc) {
- // Something this is wrong in the config
- if (!t2sls.getWidth() || !t2sls.getHeight()) {
- return [0, 0];
- }
+ var bgWidth = t2sls.getWidth() || 100,
+ bgHeight = t2sls.getHeight() || 100;
- var scale = 1000 / t2sls.getWidth(),
- yOffset = (1000 - (t2sls.getHeight() * scale)) / 2;
+ var scale = 1000 / bgWidth,
+ yOffset = (1000 - (bgHeight * scale)) / 2;
// 1000 is a hardcoded HTML value of the SVG element (topo2.html)
var x = scale * loc.gridX,