Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 1 | /* |
| 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 Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 16 | import {Component, Input, OnInit} from '@angular/core'; |
| 17 | import {MapObject} from '../maputils'; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame^] | 18 | import {LocMeta, MetaUi} from '../forcesvg/models'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 19 | |
| 20 | /** |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 21 | * model of the topo2CurrentLayout attrs from BgZoom below |
| 22 | */ |
| 23 | export 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 | */ |
| 32 | export interface BgZoom { |
| 33 | cfg: BgZoomAttrs; |
| 34 | usr?: BgZoomAttrs; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * model of the topo2CurrentLayout breadcrumb from Layout below |
| 39 | */ |
| 40 | export interface LayoutCrumb { |
| 41 | id: string; |
| 42 | name: string; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Enum of the topo2CurrentRegion location type from Location below |
| 47 | */ |
| 48 | export enum LocationType { |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 49 | NONE = 'none', |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 50 | GEO = 'geo', |
| 51 | GRID = 'grid' |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * model of the topo2CurrentLayout WebSocket response |
| 56 | */ |
| 57 | export 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 Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame^] | 72 | const LONGITUDE_EXTENT = 180; |
| 73 | const LATITUDE_EXTENT = 75; |
| 74 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 75 | /** |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 76 | * ONOS GUI -- Topology Background Layer View. |
| 77 | */ |
| 78 | @Component({ |
| 79 | selector: '[onos-backgroundsvg]', |
| 80 | templateUrl: './backgroundsvg.component.html', |
| 81 | styleUrls: ['./backgroundsvg.component.css'] |
| 82 | }) |
| 83 | export class BackgroundSvgComponent implements OnInit { |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 84 | @Input() map: MapObject; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 85 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 86 | layoutData: Layout = <Layout>{}; |
| 87 | |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame^] | 88 | 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 Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 114 | constructor() { } |
| 115 | |
| 116 | ngOnInit() { |
| 117 | } |
| 118 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 119 | |
| 120 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 121 | } |