blob: 29c6a9309d28d24c353a13f93e4c0a074e77a35a [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
Simon Huntf0c6f542017-03-22 18:31:18 -070028 function getZoom(z) {
29 var u = z.usr,
30 c = z.cfg;
31 return (u && !u.useCfg) ? u : c;
32 }
33
34 // returns the pan (offset) values as an array [x, y]
35 function zoomPan(z) {
36 var zoom = getZoom(z);
37 return [zoom.offsetX, zoom.offsetY];
38 }
39
40 // returns the scale value
41 function zoomScale(z) {
42 var zoom = getZoom(z);
43 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
Steven Burrows68d6f952017-03-10 13:53:35 +000068 this.background = data;
69 this.bgType = data.bgType;
Simon Huntf0c6f542017-03-22 18:31:18 -070070 this.zoomData = data.bgZoom;
Steven Burrowse8a455a2017-03-16 16:58:59 +000071
72 var _this = this,
Simon Huntf0c6f542017-03-22 18:31:18 -070073 pan = zoomPan(this.zoomData);
Steven Burrows68d6f952017-03-10 13:53:35 +000074
75 if (this.bgType === 'geo') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000076
77 // Hide Sprite Layer and show Map
78 t2sls.hide();
79 t2ms.show();
80
Simon Huntf0c6f542017-03-22 18:31:18 -070081 t2ms.setUpMap(data.bgId, data.bgFilePath, zoomScale(data.bgZoom))
Steven Burrowsb43c1a92017-03-07 17:13:28 +000082 .then(function (proj) {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000083 t2mcs.projection(proj);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000084 $log.debug('** We installed the projection:', proj);
Steven Burrows68d6f952017-03-10 13:53:35 +000085 _this.region.loaded('bgRendered', true);
Simon Huntf0c6f542017-03-22 18:31:18 -070086 t2zs.panAndZoom(pan, zoomScale(_this.zoomData), 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000087 });
Steven Burrowse8a455a2017-03-16 16:58:59 +000088 } else if (this.bgType === 'grid') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000089
90 // Hide Sprite Layer and show Map
91 t2ms.hide();
92 t2sls.show();
93
Steven Burrows68d6f952017-03-10 13:53:35 +000094 t2sls.loadLayout(data.bgId).then(function (spriteLayout) {
95 _this.background.layout = spriteLayout;
96 _this.region.loaded('bgRendered', true);
Simon Huntf0c6f542017-03-22 18:31:18 -070097 t2zs.panAndZoom(pan, zoomScale(_this.zoomData), 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000098 });
Steven Burrowse8a455a2017-03-16 16:58:59 +000099 } else {
100 // No background type - Tell the region the background is ready for placing nodes
101 t2ms.hide();
102 t2sls.hide();
103 // _this.region.loaded('bgRendered', true);
104 // t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000105 }
Steven Burrows68d6f952017-03-10 13:53:35 +0000106 },
107 getBackgroundType: function () {
108 return this.bgType;
Steven Burrows3bbd9af2017-03-16 14:44:14 +0000109 },
110 resetZoom: function () {
111 t2zs.getZoomer().reset();
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000112 }
113 });
114
115
Simon Huntf0c6f542017-03-22 18:31:18 -0700116 return instance || new BackgroundView();
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000117 }
118 ]);
119})();