blob: f0312f5ac9ef8c149458e8d245d4c1066b735c87 [file] [log] [blame]
Steven Burrowsb43c1a92017-03-07 17:13:28 +00001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Topology Background Module.
19 Module that maintains the map and sprite layers
20 */
21
22(function () {
23
24 var $log;
25
26 var instance;
27
Steven Burrowse9e45712017-03-24 12:39:14 +000028 function getZoom(z, useCfg) {
Simon Huntf0c6f542017-03-22 18:31:18 -070029 var u = z.usr,
30 c = z.cfg;
Steven Burrowse9e45712017-03-24 12:39:14 +000031 return (u && !u.useCfg && !useCfg) ? u : c;
Simon Huntf0c6f542017-03-22 18:31:18 -070032 }
33
34 // returns the pan (offset) values as an array [x, y]
Steven Burrowse9e45712017-03-24 12:39:14 +000035 function zoomPan(z, useCfg) {
36 var zoom = getZoom(z, useCfg);
Simon Huntf0c6f542017-03-22 18:31:18 -070037 return [zoom.offsetX, zoom.offsetY];
38 }
39
40 // returns the scale value
Steven Burrowse9e45712017-03-24 12:39:14 +000041 function zoomScale(z, useCfg) {
42 var zoom = getZoom(z, useCfg);
Simon Huntf0c6f542017-03-22 18:31:18 -070043 return zoom.scale;
44 }
45
Steven Burrowsb43c1a92017-03-07 17:13:28 +000046 angular.module('ovTopo2')
47 .factory('Topo2BackgroundService', [
48 '$log', 'Topo2ViewController', 'Topo2SpriteLayerService', 'Topo2MapService',
Steven Burrows3bbd9af2017-03-16 14:44:14 +000049 'Topo2MapConfigService', 'Topo2ZoomService',
50 function (_$log_, ViewController, t2sls, t2ms, t2mcs, t2zs) {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000051
52 $log = _$log_;
53
54 var BackgroundView = ViewController.extend({
55
56 id: 'topo2-background',
57 displayName: 'Background',
58
59 init: function () {
60 instance = this;
61 this.appendElement('#topo2-zoomlayer', 'g');
62 t2sls.init();
63 t2ms.init();
Steven Burrowse8a455a2017-03-16 16:58:59 +000064 this.zoomer = t2zs.getZoomer();
Steven Burrowsb43c1a92017-03-07 17:13:28 +000065 },
66 addLayout: function (data) {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000067
Simon Huntb3656d42017-04-07 18:15:35 -070068 var oldBgType = this.bgType,
69 oldBgId = this.bgId;
70
Steven Burrows68d6f952017-03-10 13:53:35 +000071 this.background = data;
72 this.bgType = data.bgType;
Simon Huntb3656d42017-04-07 18:15:35 -070073 this.bgId = data.bgId;
Simon Huntf0c6f542017-03-22 18:31:18 -070074 this.zoomData = data.bgZoom;
Steven Burrowse8a455a2017-03-16 16:58:59 +000075
76 var _this = this,
Simon Huntf7e7d4a2017-03-24 15:22:20 -070077 pan = zoomPan(this.zoomData),
78 scale = zoomScale(this.zoomData);
Steven Burrows68d6f952017-03-10 13:53:35 +000079
80 if (this.bgType === 'geo') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000081 // Hide Sprite Layer and show Map
82 t2sls.hide();
83 t2ms.show();
84
Steven Burrows7d1efef2017-03-25 02:07:43 +000085 t2ms.setUpMap(data.bgId, data.bgFilePath)
Steven Burrowsb43c1a92017-03-07 17:13:28 +000086 .then(function (proj) {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000087 t2mcs.projection(proj);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000088 $log.debug('** We installed the projection:', proj);
Steven Burrows68d6f952017-03-10 13:53:35 +000089 _this.region.loaded('bgRendered', true);
Simon Huntf7e7d4a2017-03-24 15:22:20 -070090 t2zs.panAndZoom(pan, scale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000091 });
Steven Burrowse8a455a2017-03-16 16:58:59 +000092 } else if (this.bgType === 'grid') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000093
94 // Hide Sprite Layer and show Map
95 t2ms.hide();
96 t2sls.show();
97
Steven Burrows68d6f952017-03-10 13:53:35 +000098 t2sls.loadLayout(data.bgId).then(function (spriteLayout) {
99 _this.background.layout = spriteLayout;
100 _this.region.loaded('bgRendered', true);
Simon Huntf7e7d4a2017-03-24 15:22:20 -0700101 t2zs.panAndZoom(pan, scale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000102 });
Steven Burrowse8a455a2017-03-16 16:58:59 +0000103 } else {
104 // No background type - Tell the region the background is ready for placing nodes
105 t2ms.hide();
106 t2sls.hide();
Simon Huntb3656d42017-04-07 18:15:35 -0700107
108 // TODO: don't just use previous layout's pan/zoom settings!
Steven Burrowse8a455a2017-03-16 16:58:59 +0000109 // _this.region.loaded('bgRendered', true);
110 // t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000111 }
Steven Burrows68d6f952017-03-10 13:53:35 +0000112 },
113 getBackgroundType: function () {
114 return this.bgType;
Steven Burrows3bbd9af2017-03-16 14:44:14 +0000115 },
116 resetZoom: function () {
Steven Burrowse9e45712017-03-24 12:39:14 +0000117 var pan = zoomPan(this.zoomData, true);
118 t2zs.panAndZoom(pan, zoomScale(this.zoomData, true), 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000119 }
120 });
121
Simon Huntf0c6f542017-03-22 18:31:18 -0700122 return instance || new BackgroundView();
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000123 }
124 ]);
125})();