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 | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 16 | import {Component, EventEmitter, Input, Output} from '@angular/core'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 17 | import {MapObject} from '../maputils'; |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 18 | import {MapBounds, TopoZoomPrefs, LogService, ZoomUtils} from 'gui2-fw-lib/public_api'; |
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 | |
| 72 | /** |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 73 | * ONOS GUI -- Topology Background Layer View. |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 74 | * |
| 75 | * TODO: consider that this layer has only one component the MapSvg and hence |
| 76 | * might be able to be eliminated |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 77 | */ |
| 78 | @Component({ |
| 79 | selector: '[onos-backgroundsvg]', |
| 80 | templateUrl: './backgroundsvg.component.html', |
| 81 | styleUrls: ['./backgroundsvg.component.css'] |
| 82 | }) |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 83 | export class BackgroundSvgComponent { |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 84 | @Input() map: MapObject; |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 85 | @Output() zoomlevel = new EventEmitter<TopoZoomPrefs>(); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 86 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 87 | layoutData: Layout = <Layout>{}; |
| 88 | |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 89 | constructor( |
| 90 | private log: LogService |
| 91 | ) { |
| 92 | this.log.debug('BackgroundSvg constructed'); |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Sean Condon | 1ae1580 | 2019-03-02 09:07:18 +0000 | [diff] [blame] | 95 | /** |
| 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 Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 107 | } |