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(); |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame^] | 46 | this.zoomer = t2zs.getZoomer(); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 47 | }, |
| 48 | addLayout: function (data) { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 49 | |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 50 | this.background = data; |
| 51 | this.bgType = data.bgType; |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame^] | 52 | |
| 53 | var _this = this, |
| 54 | pan = [this.background.bgZoomPanX, this.background.bgZoomPanY]; |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 55 | |
| 56 | if (this.bgType === 'geo') { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 57 | |
| 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 Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 70 | _this.region.loaded('bgRendered', true); |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame^] | 71 | t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 72 | }); |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame^] | 73 | } else 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 | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame^] | 82 | t2zs.panAndZoom(pan, _this.background.bgZoomScale, 1000); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 83 | }); |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame^] | 84 | } 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 Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 90 | } |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 91 | }, |
| 92 | getBackgroundType: function () { |
| 93 | return this.bgType; |
Steven Burrows | 3bbd9af | 2017-03-16 14:44:14 +0000 | [diff] [blame] | 94 | }, |
| 95 | resetZoom: function () { |
| 96 | t2zs.getZoomer().reset(); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 97 | } |
| 98 | }); |
| 99 | |
| 100 | |
| 101 | return instance || new BackgroundView();; |
| 102 | } |
| 103 | ]); |
| 104 | })(); |