Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 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 Burrows | e9e4571 | 2017-03-24 12:39:14 +0000 | [diff] [blame] | 28 | function getZoom(z, useCfg) { |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 29 | var u = z.usr, |
| 30 | c = z.cfg; |
Steven Burrows | e9e4571 | 2017-03-24 12:39:14 +0000 | [diff] [blame] | 31 | return (u && !u.useCfg && !useCfg) ? u : c; |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // returns the pan (offset) values as an array [x, y] |
Steven Burrows | e9e4571 | 2017-03-24 12:39:14 +0000 | [diff] [blame] | 35 | function zoomPan(z, useCfg) { |
| 36 | var zoom = getZoom(z, useCfg); |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 37 | return [zoom.offsetX, zoom.offsetY]; |
| 38 | } |
| 39 | |
| 40 | // returns the scale value |
Steven Burrows | e9e4571 | 2017-03-24 12:39:14 +0000 | [diff] [blame] | 41 | function zoomScale(z, useCfg) { |
| 42 | var zoom = getZoom(z, useCfg); |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 43 | return zoom.scale; |
| 44 | } |
| 45 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 46 | angular.module('ovTopo2') |
| 47 | .factory('Topo2BackgroundService', [ |
| 48 | '$log', 'Topo2ViewController', 'Topo2SpriteLayerService', 'Topo2MapService', |
Steven Burrows | 3bbd9af | 2017-03-16 14:44:14 +0000 | [diff] [blame] | 49 | 'Topo2MapConfigService', 'Topo2ZoomService', |
| 50 | function (_$log_, ViewController, t2sls, t2ms, t2mcs, t2zs) { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 51 | |
| 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 Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame] | 64 | this.zoomer = t2zs.getZoomer(); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 65 | }, |
Simon Hunt | 47f8fb7 | 2017-04-11 13:49:31 -0700 | [diff] [blame] | 66 | |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 67 | addLayout: function (data) { |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 68 | this.background = data; |
| 69 | this.bgType = data.bgType; |
Simon Hunt | b3656d4 | 2017-04-07 18:15:35 -0700 | [diff] [blame] | 70 | this.bgId = data.bgId; |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 71 | this.zoomData = data.bgZoom; |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame] | 72 | |
| 73 | var _this = this, |
Simon Hunt | f7e7d4a | 2017-03-24 15:22:20 -0700 | [diff] [blame] | 74 | pan = zoomPan(this.zoomData), |
| 75 | scale = zoomScale(this.zoomData); |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 76 | |
| 77 | if (this.bgType === 'geo') { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 78 | // Hide Sprite Layer and show Map |
| 79 | t2sls.hide(); |
| 80 | t2ms.show(); |
| 81 | |
Steven Burrows | 7d1efef | 2017-03-25 02:07:43 +0000 | [diff] [blame] | 82 | t2ms.setUpMap(data.bgId, data.bgFilePath) |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 83 | .then(function (proj) { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 84 | t2mcs.projection(proj); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 85 | $log.debug('** We installed the projection:', proj); |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 86 | _this.region.loaded('bgRendered', true); |
Simon Hunt | f7e7d4a | 2017-03-24 15:22:20 -0700 | [diff] [blame] | 87 | t2zs.panAndZoom(pan, scale, 1000); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 88 | }); |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame] | 89 | } else if (this.bgType === 'grid') { |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 90 | |
| 91 | // Hide Sprite Layer and show Map |
| 92 | t2ms.hide(); |
| 93 | t2sls.show(); |
| 94 | |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 95 | t2sls.loadLayout(data.bgId).then(function (spriteLayout) { |
| 96 | _this.background.layout = spriteLayout; |
| 97 | _this.region.loaded('bgRendered', true); |
Simon Hunt | f7e7d4a | 2017-03-24 15:22:20 -0700 | [diff] [blame] | 98 | t2zs.panAndZoom(pan, scale, 1000); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 99 | }); |
Steven Burrows | e8a455a | 2017-03-16 16:58:59 +0000 | [diff] [blame] | 100 | } else { |
| 101 | // No background type - Tell the region the background is ready for placing nodes |
| 102 | t2ms.hide(); |
| 103 | t2sls.hide(); |
Simon Hunt | b3656d4 | 2017-04-07 18:15:35 -0700 | [diff] [blame] | 104 | |
Simon Hunt | 47f8fb7 | 2017-04-11 13:49:31 -0700 | [diff] [blame] | 105 | _this.region.loaded('bgRendered', true); |
| 106 | |
| 107 | // Use default zoom and pan |
| 108 | t2zs.panAndZoom([0, 0], 1); |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 109 | } |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 110 | }, |
Simon Hunt | 47f8fb7 | 2017-04-11 13:49:31 -0700 | [diff] [blame] | 111 | |
Steven Burrows | 68d6f95 | 2017-03-10 13:53:35 +0000 | [diff] [blame] | 112 | getBackgroundType: function () { |
| 113 | return this.bgType; |
Steven Burrows | 3bbd9af | 2017-03-16 14:44:14 +0000 | [diff] [blame] | 114 | }, |
Simon Hunt | 47f8fb7 | 2017-04-11 13:49:31 -0700 | [diff] [blame] | 115 | |
Steven Burrows | 3bbd9af | 2017-03-16 14:44:14 +0000 | [diff] [blame] | 116 | resetZoom: function () { |
Steven Burrows | e9e4571 | 2017-03-24 12:39:14 +0000 | [diff] [blame] | 117 | var pan = zoomPan(this.zoomData, true); |
| 118 | t2zs.panAndZoom(pan, zoomScale(this.zoomData, true), 1000); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 119 | }, |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 120 | }); |
| 121 | |
Simon Hunt | f0c6f54 | 2017-03-22 18:31:18 -0700 | [diff] [blame] | 122 | return instance || new BackgroundView(); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 123 | }, |
Steven Burrows | b43c1a9 | 2017-03-07 17:13:28 +0000 | [diff] [blame] | 124 | ]); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 125 | })(); |