Merge pull request #523 from GNS3/WebUI-starts-at-0,0-position

Option to center view added
This commit is contained in:
piotrpekala7 2019-10-04 12:51:27 +02:00 committed by GitHub
commit 70c9b98c3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -115,6 +115,12 @@
<mat-icon>settings_applications</mat-icon>
</button>
</mat-toolbar-row>
<mat-toolbar-row *ngIf="!readonly">
<button matTooltip="Center view" mat-icon-button (click)="centerView()">
<mat-icon>center_focus_strong</mat-icon>
</button>
</mat-toolbar-row>
</mat-toolbar>
</div>

View File

@ -1,4 +1,4 @@
import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation, ElementRef } from '@angular/core';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { Observable, Subject, Subscription, from } from 'rxjs';
@ -394,6 +394,17 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
});
}
public centerView() {
if (this.project) {
let scrollX: number = (this.project.scene_width - document.documentElement.clientWidth) > 0 ? (this.project.scene_width - document.documentElement.clientWidth)/2 : 0;
let scrollY: number = (this.project.scene_height - document.documentElement.clientHeight) > 0 ? (this.project.scene_height - document.documentElement.clientHeight)/2 : 0;
window.scrollTo(scrollX, scrollY);
} else {
this.toasterService.error('Please wait until all components are loaded.');
}
}
public onDrawingSaved() {
this.projectMapMenuComponent.resetDrawToolChoice();
}