mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-01-19 03:06:31 +00:00
Update project-map-menu.component.ts
This commit is contained in:
parent
c2263336a9
commit
077c94f567
@ -9,6 +9,7 @@ import { saveAs } from 'file-saver';
|
||||
import { SymbolService } from '../../../services/symbol.service';
|
||||
import { select } from 'd3-selection';
|
||||
import downloadSvg from 'svg-crowbar';
|
||||
import { ElectronService } from 'ngx-electron';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -33,35 +34,42 @@ export class ProjectMapMenuComponent implements OnInit, OnDestroy {
|
||||
private toolsService: ToolsService,
|
||||
private mapSettingsService: MapSettingsService,
|
||||
private drawingService: DrawingService,
|
||||
private symbolService: SymbolService
|
||||
private symbolService: SymbolService,
|
||||
private electronService: ElectronService
|
||||
) {}
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
public async takeScreenshot() {
|
||||
// original, first & second version
|
||||
// let splittedSvg = document.getElementsByTagName("svg")[0].outerHTML.split('image');
|
||||
// let i = 1;
|
||||
if (this.electronService.isWindows) {
|
||||
let splittedSvg = document.getElementsByTagName("svg")[0].outerHTML.split('image');
|
||||
let i = 1;
|
||||
|
||||
// while (i < splittedSvg.length) {
|
||||
// let splittedImage = splittedSvg[i].split("\"");
|
||||
// let splittedUrl = splittedImage[1].split("/");
|
||||
while (i < splittedSvg.length) {
|
||||
let splittedImage = splittedSvg[i].split("\"");
|
||||
let splittedUrl = splittedImage[1].split("/");
|
||||
|
||||
// let elem = await this.symbolService.raw(this.server, splittedUrl[7]).toPromise();
|
||||
// let splittedElement = elem.split('-->');
|
||||
// splittedSvg[i] = splittedElement[1].substring(2);
|
||||
// i += 2;
|
||||
// }
|
||||
// let svgString = splittedSvg.join();
|
||||
let elem = await this.symbolService.raw(this.server, splittedUrl[7]).toPromise();
|
||||
let splittedElement = elem.split('-->');
|
||||
splittedSvg[i] = splittedElement[1].substring(2);
|
||||
i += 2;
|
||||
}
|
||||
let svgString = splittedSvg.join();
|
||||
|
||||
// let placeholder = document.createElement('div');
|
||||
// placeholder.innerHTML = svgString;
|
||||
// let element = placeholder.firstChild;
|
||||
let placeholder = document.createElement('div');
|
||||
placeholder.innerHTML = svgString;
|
||||
let element = placeholder.firstChild;
|
||||
|
||||
// original version
|
||||
// svg.saveSvgAsPng(element, "screenshot.png");
|
||||
svg.saveSvgAsPng(element, "screenshot.png");
|
||||
} else {
|
||||
var svg_el = select("svg")
|
||||
.attr("version", 1.1)
|
||||
.attr("xmlns", "http://www.w3.org/2000/svg")
|
||||
.node();
|
||||
downloadSvg(select("svg").node(), 'screenshot');
|
||||
}
|
||||
|
||||
// first version
|
||||
// first alternative version
|
||||
// var canvas = document.createElement('canvas');
|
||||
// canvas.innerHTML = svgString;
|
||||
// canvas.width = 2000;
|
||||
@ -75,13 +83,6 @@ export class ProjectMapMenuComponent implements OnInit, OnDestroy {
|
||||
|
||||
// second version
|
||||
// this.svgString2Image( svgString, 2000, 1000, 'png'); // passes Blob and filesize String to the callback
|
||||
|
||||
// third version
|
||||
var svg_el = select("svg")
|
||||
.attr("version", 1.1)
|
||||
.attr("xmlns", "http://www.w3.org/2000/svg")
|
||||
.node();
|
||||
downloadSvg(select("svg").node(), 'screenshot');
|
||||
}
|
||||
|
||||
// svgString2Image( svgString, width, height, format) {
|
||||
|
Loading…
Reference in New Issue
Block a user