blob: cc41fb67af4e6d784024e0eba08a6bed606c69a8 [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 Condon0d064ec2019-02-04 21:53:53 +000016import {Component, Input, OnInit} from '@angular/core';
17import {MapObject} from '../maputils';
Sean Condon71910542019-02-16 18:16:42 +000018import {LocMeta, MetaUi} from '../forcesvg/models';
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
Sean Condon71910542019-02-16 18:16:42 +000072const LONGITUDE_EXTENT = 180;
73const LATITUDE_EXTENT = 75;
74
Sean Condonaa4366d2018-11-02 14:29:01 +000075/**
Sean Condonf4f54a12018-10-10 23:25:46 +010076 * ONOS GUI -- Topology Background Layer View.
77 */
78@Component({
79 selector: '[onos-backgroundsvg]',
80 templateUrl: './backgroundsvg.component.html',
81 styleUrls: ['./backgroundsvg.component.css']
82})
83export class BackgroundSvgComponent implements OnInit {
Sean Condon0d064ec2019-02-04 21:53:53 +000084 @Input() map: MapObject;
Sean Condonf4f54a12018-10-10 23:25:46 +010085
Sean Condonaa4366d2018-11-02 14:29:01 +000086 layoutData: Layout = <Layout>{};
87
Sean Condon71910542019-02-16 18:16:42 +000088 static convertGeoToCanvas(location: LocMeta): MetaUi {
89 const calcX = (LONGITUDE_EXTENT + location.lng) / ( LONGITUDE_EXTENT * 2 ) * 2000 - 500;
90 const calcY = (LATITUDE_EXTENT - location.lat) / ( LATITUDE_EXTENT * 2 ) * 1000;
91 return <MetaUi>{
92 x: calcX,
93 y: calcY,
94 equivLoc: {
95 lat: location.lat,
96 lng: location.lng
97 }
98 };
99 }
100
101 static convertXYtoGeo(x: number, y: number): MetaUi {
102 const calcLong: number = (x + 500) * 2 * LONGITUDE_EXTENT / 2000 - LONGITUDE_EXTENT;
103 const calcLat: number = -(y * 2 * LATITUDE_EXTENT / 1000 - LATITUDE_EXTENT);
104 return <MetaUi>{
105 x: x,
106 y: y,
107 equivLoc: <LocMeta>{
108 lat: calcLat,
109 lng: calcLong
110 }
111 };
112 }
113
Sean Condonf4f54a12018-10-10 23:25:46 +0100114 constructor() { }
115
116 ngOnInit() {
117 }
118
Sean Condonaa4366d2018-11-02 14:29:01 +0000119
120
Sean Condonf4f54a12018-10-10 23:25:46 +0100121}