Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 1 | /* |
| 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 Burrows | 3bbd9af | 2017-03-16 14:44:14 +0000 | [diff] [blame] | 31 | 'Topo2MapConfigService', 'Topo2ZoomService', |
| 32 | function (_$log_, ViewController, t2sls, t2ms, t2mcs, t2zs) { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 33 | |
| 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 Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 48 | |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 49 | 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 Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 56 | |
| 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 Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 69 | _this.region.loaded('bgRendered', true); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 70 | }); |
| 71 | } |
| 72 | |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 73 | if (this.bgType === 'grid') { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 74 | |
| 75 | // Hide Sprite Layer and show Map |
| 76 | t2ms.hide(); |
| 77 | t2sls.show(); |
| 78 | |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 79 | t2sls.loadLayout(data.bgId).then(function (spriteLayout) { |
| 80 | _this.background.layout = spriteLayout; |
| 81 | _this.region.loaded('bgRendered', true); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 82 | }); |
| 83 | } |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 84 | }, |
| 85 | getBackgroundType: function () { |
| 86 | return this.bgType; |
Steven Burrows | 3bbd9af | 2017-03-16 14:44:14 +0000 | [diff] [blame] | 87 | }, |
| 88 | resetZoom: function () { |
| 89 | t2zs.getZoomer().reset(); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 90 | } |
| 91 | }); |
| 92 | |
| 93 | |
| 94 | return instance || new BackgroundView();; |
| 95 | } |
| 96 | ]); |
| 97 | })(); |