blob: f83d92168e9d28cba679f648075357f63d589d8f [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
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 Huntf7e7d4a2017-03-24 15:22:20 -070073 pan = zoomPan(this.zoomData),
74 scale = zoomScale(this.zoomData);
Steven Burrows68d6f952017-03-10 13:53:35 +000075
76 if (this.bgType === 'geo') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000077
78 // Hide Sprite Layer and show Map
79 t2sls.hide();
80 t2ms.show();
81
Steven Burrows7d1efef2017-03-25 02:07:43 +000082 t2ms.setUpMap(data.bgId, data.bgFilePath)
Steven Burrowsb43c1a92017-03-07 17:13:28 +000083 .then(function (proj) {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000084 t2mcs.projection(proj);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000085 $log.debug('** We installed the projection:', proj);
Steven Burrows68d6f952017-03-10 13:53:35 +000086 _this.region.loaded('bgRendered', true);
Simon Huntf7e7d4a2017-03-24 15:22:20 -070087 t2zs.panAndZoom(pan, scale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000088 });
Steven Burrowse8a455a2017-03-16 16:58:59 +000089 } else if (this.bgType === 'grid') {
Steven Burrowsb43c1a92017-03-07 17:13:28 +000090
91 // Hide Sprite Layer and show Map
92 t2ms.hide();
93 t2sls.show();
94
Steven Burrows68d6f952017-03-10 13:53:35 +000095 t2sls.loadLayout(data.bgId).then(function (spriteLayout) {
96 _this.background.layout = spriteLayout;
97 _this.region.loaded('bgRendered', true);
Simon Huntf7e7d4a2017-03-24 15:22:20 -070098 t2zs.panAndZoom(pan, scale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +000099 });
Steven Burrowse8a455a2017-03-16 16:58:59 +0000100 } else {
101 // No background type - Tell the region the background is ready for placing nodes
102 t2ms.hide();
103 t2sls.hide();
104 // _this.region.loaded('bgRendered', true);
105 // t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000106 }
Steven Burrows68d6f952017-03-10 13:53:35 +0000107 },
108 getBackgroundType: function () {
109 return this.bgType;
Steven Burrows3bbd9af2017-03-16 14:44:14 +0000110 },
111 resetZoom: function () {
Steven Burrowse9e45712017-03-24 12:39:14 +0000112 var pan = zoomPan(this.zoomData, true);
113 t2zs.panAndZoom(pan, zoomScale(this.zoomData, true), 1000);
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000114 }
115 });
116
Simon Huntf0c6f542017-03-22 18:31:18 -0700117 return instance || new BackgroundView();
Steven Burrowsb43c1a92017-03-07 17:13:28 +0000118 }
119 ]);
120})();