blob: 9c5eb81ab72b13c65c23ae2739b715ab486baae1 [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();
46 },
47 addLayout: function (data) {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000048
Steven Burrows68d6f952017-03-10 13:53:35 +000049 var _this = this;
50
51 this.background = data;
52 this.bgType = data.bgType;
53 _this.region.loaded('bgRendered', false);
54
55 if (this.bgType === 'geo') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000056
57 // Hide Sprite Layer and show Map
58 t2sls.hide();
59 t2ms.show();
60
61 t2ms.setUpMap(data.bgId, data.bgFilePath, data.bgZoomScale)
62 .then(function (proj) {
63 // var z = ps.getPrefs('topo2_zoom', { tx: 0, ty: 0, sc: 1 });
64 // zoomer.panZoom([z.tx, z.ty], z.sc);
65
66 t2mcs.projection(proj);
67 // $log.debug('** Zoom restored:', z);
68 $log.debug('** We installed the projection:', proj);
Steven Burrows68d6f952017-03-10 13:53:35 +000069 _this.region.loaded('bgRendered', true);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000070 });
71 }
72
Steven Burrows68d6f952017-03-10 13:53:35 +000073 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 Burrowsb43c1a92017-03-07 17:13:28 +000082 });
83 }
Steven Burrows68d6f952017-03-10 13:53:35 +000084 },
85 getBackgroundType: function () {
86 return this.bgType;
Steven Burrows3bbd9af2017-03-16 14:44:14 +000087 },
88 resetZoom: function () {
89 t2zs.getZoomer().reset();
Steven Burrowsb43c1a92017-03-07 17:13:28 +000090 }
91 });
92
93
94 return instance || new BackgroundView();;
95 }
96 ]);
97})();