mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-25 05:19:43 +00:00
Update project-map.component.ts
This commit is contained in:
parent
ebd2614b84
commit
2981d6eafe
@ -395,8 +395,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fitInView() {
|
public fitInView() {
|
||||||
if ((this.nodes.length === 0) || (this.drawings.length === 0)) { return };
|
if ((this.nodes.length === 0) && (this.drawings.length === 0)) { return };
|
||||||
|
|
||||||
let minX: number = + this.project.scene_width/2;
|
let minX: number = + this.project.scene_width/2;
|
||||||
let minY: number = + this.project.scene_height/2;
|
let minY: number = + this.project.scene_height/2;
|
||||||
let maxX: number = - this.project.scene_width/2;
|
let maxX: number = - this.project.scene_width/2;
|
||||||
@ -416,20 +415,38 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
maxY = drawing.y > maxY ? drawing.y : maxY;
|
maxY = drawing.y > maxY ? drawing.y : maxY;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(maxX);
|
||||||
|
console.log(minX);
|
||||||
|
console.log(maxY);
|
||||||
|
console.log(minY);
|
||||||
|
console.log('-----------------------------');
|
||||||
|
|
||||||
let windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
let windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
||||||
let windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
let windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
||||||
let margin = 0;
|
let widthOfAreaToShow = maxX - minX;
|
||||||
let widthToSceneWidthRatio = ((maxX-minX) + margin) / windowWidth;
|
let heightOfAreaToShow = maxY - minY;
|
||||||
let heightToSceneHeightRatio = ((maxY-minY) + margin) / windowHeight;
|
let widthToSceneWidthRatio = widthOfAreaToShow / windowWidth;
|
||||||
|
let heightToSceneHeightRatio = heightOfAreaToShow / windowHeight;
|
||||||
|
|
||||||
let scaleToSet = 1 / Math.max(widthToSceneWidthRatio, heightToSceneHeightRatio);
|
console.log(widthOfAreaToShow);
|
||||||
this.mapScaleService.setScale(scaleToSet);
|
console.log(heightOfAreaToShow);
|
||||||
|
console.log(widthToSceneWidthRatio);
|
||||||
|
console.log(heightToSceneHeightRatio);
|
||||||
|
console.log('-----------------------------');
|
||||||
|
|
||||||
this.project.scene_width = this.project.scene_width * scaleToSet;
|
let scale = 1 / Math.max(widthToSceneWidthRatio, heightToSceneHeightRatio);
|
||||||
this.project.scene_height = this.project.scene_height * scaleToSet;
|
this.mapScaleService.setScale(scale);
|
||||||
|
|
||||||
|
console.log(scale);
|
||||||
|
|
||||||
|
this.project.scene_width = this.project.scene_width * scale;
|
||||||
|
this.project.scene_height = this.project.scene_height * scale;
|
||||||
|
let scrollX: number = ((minX + maxX)/2 * scale) + this.project.scene_width/2;
|
||||||
|
let scrollY: number = ((minY + maxY)/2 * scale) + this.project.scene_height/2;
|
||||||
|
|
||||||
|
console.log('scrollx ', scrollX);
|
||||||
|
console.log('scrolly ', scrollY);
|
||||||
|
|
||||||
let scrollX: number = (minX + maxX)/2 * scaleToSet;
|
|
||||||
let scrollY: number = (minY + maxY)/2 * scaleToSet;
|
|
||||||
window.scrollTo(scrollX, scrollY);
|
window.scrollTo(scrollX, scrollY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user