blob: 8fa9822764fa79cd1d638a77d506988c6392d26b [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
28 angular.module('ovTopo2')
29 .factory('Topo2BackgroundService', [
30 '$log', 'Topo2ViewController', 'Topo2SpriteLayerService', 'Topo2MapService',
Steven Burrows3bbd9af2017-03-16 14:44:14 +000031 'Topo2MapConfigService', 'Topo2ZoomService',
32 function (_$log_, ViewController, t2sls, t2ms, t2mcs, t2zs) {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000033
34 $log = _$log_;
35
36 var BackgroundView = ViewController.extend({
37
38 id: 'topo2-background',
39 displayName: 'Background',
40
41 init: function () {
42 instance = this;
43 this.appendElement('#topo2-zoomlayer', 'g');
44 t2sls.init();
45 t2ms.init();
Steven Burrowse8a455a2017-03-16 16:58:59 +000046 this.zoomer = t2zs.getZoomer();
Steven Burrowsb43c1a92017-03-07 17:13:28 +000047 },
48 addLayout: function (data) {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000049
Steven Burrows68d6f952017-03-10 13:53:35 +000050 this.background = data;
51 this.bgType = data.bgType;
Steven Burrowse8a455a2017-03-16 16:58:59 +000052
53 var _this = this,
54 pan = [this.background.bgZoomPanX, this.background.bgZoomPanY];
Steven Burrows68d6f952017-03-10 13:53:35 +000055
56 if (this.bgType === 'geo') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000057
58 // Hide Sprite Layer and show Map
59 t2sls.hide();
60 t2ms.show();
61
62 t2ms.setUpMap(data.bgId, data.bgFilePath, data.bgZoomScale)
63 .then(function (proj) {
64 // var z = ps.getPrefs('topo2_zoom', { tx: 0, ty: 0, sc: 1 });
65 // zoomer.panZoom([z.tx, z.ty], z.sc);
66
67 t2mcs.projection(proj);
68 // $log.debug('** Zoom restored:', z);
69 $log.debug('** We installed the projection:', proj);
Steven Burrows68d6f952017-03-10 13:53:35 +000070 _this.region.loaded('bgRendered', true);
Steven Burrowse8a455a2017-03-16 16:58:59 +000071 t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000072 });
Steven Burrowse8a455a2017-03-16 16:58:59 +000073 } else if (this.bgType === 'grid') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000074
75 // Hide Sprite Layer and show Map
76 t2ms.hide();
77 t2sls.show();
78
Steven Burrows68d6f952017-03-10 13:53:35 +000079 t2sls.loadLayout(data.bgId).then(function (spriteLayout) {
80 _this.background.layout = spriteLayout;
81 _this.region.loaded('bgRendered', true);
Steven Burrowse8a455a2017-03-16 16:58:59 +000082 t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000083 });
Steven Burrowse8a455a2017-03-16 16:58:59 +000084 } else {
85 // No background type - Tell the region the background is ready for placing nodes
86 t2ms.hide();
87 t2sls.hide();
88 // _this.region.loaded('bgRendered', true);
89 // t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000090 }
Steven Burrows68d6f952017-03-10 13:53:35 +000091 },
92 getBackgroundType: function () {
93 return this.bgType;
Steven Burrows3bbd9af2017-03-16 14:44:14 +000094 },
95 resetZoom: function () {
96 t2zs.getZoomer().reset();
Steven Burrowsb43c1a92017-03-07 17:13:28 +000097 }
98 });
99
100
101 return instance || new BackgroundView();;
102 }
103 ]);
104})();