blob: d52154ccf99ffd7f0edcadf879f65df268e07ec3 [file] [log] [blame]
Steven Burrows0616e802016-10-06 21:45:07 -05001/*
2 * Copyright 2016-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/*
Simon Hunt95f4b422017-03-03 13:49:05 -080018 ONOS GUI -- Topology Zoom Module.
19 Module that handles Zoom events.
Steven Burrows0616e802016-10-06 21:45:07 -050020 */
21
22(function () {
Steven Burrows0616e802016-10-06 21:45:07 -050023 'use strict';
24
Simon Hunt95f4b422017-03-03 13:49:05 -080025 // injected references
26 var fs, zs, ps;
Steven Burrows1742bb82016-10-27 10:36:25 -050027
Simon Hunt95f4b422017-03-03 13:49:05 -080028 // internal state
Steven Burrows1742bb82016-10-27 10:36:25 -050029 var zoomer,
30 zoomEventListeners = [];
Steven Burrows0616e802016-10-06 21:45:07 -050031
Simon Hunt95f4b422017-03-03 13:49:05 -080032 function createZoomer(options) {
33 // need to wrap the original zoom callback to extend its behavior
34 var origCallback = fs.isF(options.zoomCallback) || function () {};
35
36 options.zoomCallback = function () {
37 origCallback();
38
39 angular.forEach(zoomEventListeners, function (ev) {
40 ev(zoomer);
41 });
42 };
43
44 zoomer = zs.createZoomer(options);
45 return zoomer;
46 }
47
Steven Burrowsaf96a212016-12-28 12:57:02 +000048 function getZoomer() {
49 return zoomer;
50 }
51
Steven Burrows0616e802016-10-06 21:45:07 -050052 function findZoomEventListener(ev) {
Simon Hunt95f4b422017-03-03 13:49:05 -080053 for (var i = 0, len = zoomEventListeners.length; i < len; i++) {
Steven Burrows0616e802016-10-06 21:45:07 -050054 if (zoomEventListeners[i] === ev) return i;
55 }
Steven Burrows0616e802016-10-06 21:45:07 -050056 return -1;
57 }
58
59 function addZoomEventListener(callback) {
60 zoomEventListeners.push(callback);
61 }
62
63 function removeZoomEventListener(callback) {
Steven Burrows0616e802016-10-06 21:45:07 -050064 var evIndex = findZoomEventListener(callback);
65
66 if (evIndex !== -1) {
67 zoomEventListeners.splice(evIndex);
68 }
69 }
70
71 function scale() {
72 return zoomer.scale();
73 }
74
Steven Burrows1742bb82016-10-27 10:36:25 -050075 function panAndZoom(translate, scale) {
76 zoomer.panZoom(translate, scale, 1000);
77 }
78
Steven Burrows0616e802016-10-06 21:45:07 -050079 angular.module('ovTopo2')
Steven Burrowsaf96a212016-12-28 12:57:02 +000080 .factory('Topo2ZoomService', [
Simon Hunt95f4b422017-03-03 13:49:05 -080081 'FnService', 'ZoomService', 'PrefsService',
82 function (_fs_, _zs_, _ps_) {
Steven Burrows0616e802016-10-06 21:45:07 -050083
Simon Hunt95f4b422017-03-03 13:49:05 -080084 fs = _fs_;
Steven Burrows0616e802016-10-06 21:45:07 -050085 zs = _zs_;
86 ps = _ps_;
87
88 return {
Steven Burrowsaf96a212016-12-28 12:57:02 +000089 getZoomer: getZoomer,
Steven Burrows0616e802016-10-06 21:45:07 -050090 createZoomer: createZoomer,
91 addZoomEventListener: addZoomEventListener,
92 removeZoomEventListener: removeZoomEventListener,
93
Steven Burrows1742bb82016-10-27 10:36:25 -050094 scale: scale,
95 panAndZoom: panAndZoom
Steven Burrows0616e802016-10-06 21:45:07 -050096 };
97 }]);
98})();