blob: daa4fcb55bca0be4738858398d8b6aa450aa6513 [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
Sean Condon1ae15802019-03-02 09:07:18 +000016import {Component, EventEmitter, Input, Output} from '@angular/core';
Sean Condon0d064ec2019-02-04 21:53:53 +000017import {MapObject} from '../maputils';
Sean Condon1ae15802019-03-02 09:07:18 +000018import {MapBounds, TopoZoomPrefs, LogService, ZoomUtils} from 'gui2-fw-lib';
Sean Condonf4f54a12018-10-10 23:25:46 +010019
20/**
Sean Condonaa4366d2018-11-02 14:29:01 +000021 * model of the topo2CurrentLayout attrs from BgZoom below
22 */
23export interface BgZoomAttrs {
24 offsetX: number;
25 offsetY: number;
26 scale: number;
27}
28
29/**
30 * model of the topo2CurrentLayout background zoom attrs from Layout below
31 */
32export interface BgZoom {
33 cfg: BgZoomAttrs;
34 usr?: BgZoomAttrs;
35}
36
37/**
38 * model of the topo2CurrentLayout breadcrumb from Layout below
39 */
40export interface LayoutCrumb {
41 id: string;
42 name: string;
43}
44
45/**
46 * Enum of the topo2CurrentRegion location type from Location below
47 */
48export enum LocationType {
Sean Condon0c577f62018-11-18 22:40:05 +000049 NONE = 'none',
Sean Condonaa4366d2018-11-02 14:29:01 +000050 GEO = 'geo',
51 GRID = 'grid'
52}
53
54/**
55 * model of the topo2CurrentLayout WebSocket response
56 */
57export interface Layout {
58 id: string;
59 bgDefaultScale: number;
60 bgDesc: string;
61 bgFilePath: string;
62 bgId: string;
63 bgType: LocationType;
64 bgWarn: string;
65 bgZoom: BgZoom;
66 crumbs: LayoutCrumb[];
67 parent: string;
68 region: string;
69 regionName: string;
70}
71
72/**
Sean Condonf4f54a12018-10-10 23:25:46 +010073 * ONOS GUI -- Topology Background Layer View.
Sean Condon1ae15802019-03-02 09:07:18 +000074 *
75 * TODO: consider that this layer has only one component the MapSvg and hence
76 * might be able to be eliminated
Sean Condonf4f54a12018-10-10 23:25:46 +010077 */
78@Component({
79 selector: '[onos-backgroundsvg]',
80 templateUrl: './backgroundsvg.component.html',
81 styleUrls: ['./backgroundsvg.component.css']
82})
Sean Condon1ae15802019-03-02 09:07:18 +000083export class BackgroundSvgComponent {
Sean Condon0d064ec2019-02-04 21:53:53 +000084 @Input() map: MapObject;
Sean Condon1ae15802019-03-02 09:07:18 +000085 @Output() zoomlevel = new EventEmitter<TopoZoomPrefs>();
Sean Condonf4f54a12018-10-10 23:25:46 +010086
Sean Condonaa4366d2018-11-02 14:29:01 +000087 layoutData: Layout = <Layout>{};
88
Sean Condon1ae15802019-03-02 09:07:18 +000089 constructor(
90 private log: LogService
91 ) {
92 this.log.debug('BackgroundSvg constructed');
Sean Condon71910542019-02-16 18:16:42 +000093 }
94
Sean Condon1ae15802019-03-02 09:07:18 +000095 /**
96 * Called when ever the mapBounds event is raised by the MapSvgComponent
97 *
98 * @param bounds - the bounds of the newly loaded map in terms of Lat and Long
99 */
100 updatedBounds(bounds: MapBounds): void {
101 const zoomPrefs: TopoZoomPrefs =
102 ZoomUtils.convertBoundsToZoomLevel(bounds, this.log);
103
104 this.zoomlevel.emit(zoomPrefs);
Sean Condon71910542019-02-16 18:16:42 +0000105 }
106
Sean Condonf4f54a12018-10-10 23:25:46 +0100107}