From 057f20821a25b897ae21b2ee9167e522d212eda3 Mon Sep 17 00:00:00 2001 From: Nestu Date: Tue, 20 Sep 2022 15:28:19 +0200 Subject: [PATCH] Add Screenshot functionality (#44) * Add screenshot button * Move screenshot button to menu * Add option for screenshots to be copied to clipboard * Update English and Spanish lang files --- public/lang/en.js | 5 +++++ public/lang/es.js | 5 +++++ src/components/Menu/MainMenu.vue | 1 + src/components/Menu/SettingsMenu.vue | 4 ++++ src/i18n/fallback.js | 5 +++++ src/js/BlueMapApp.js | 25 +++++++++++++++++++++++++ 6 files changed, 45 insertions(+) diff --git a/public/lang/en.js b/public/lang/en.js index 0763c26..66e83eb 100644 --- a/public/lang/en.js +++ b/public/lang/en.js @@ -78,6 +78,11 @@ export default { compass: { tooltip: "Compass / Face North" }, + screenshot: { + title: "Screenshot", + button: "Take Screenshot", + clipboard: "Copy to Clipboard" + }, controls: { title: "View / Controls", perspective: { diff --git a/public/lang/es.js b/public/lang/es.js index e75ec80..0e496f2 100644 --- a/public/lang/es.js +++ b/public/lang/es.js @@ -76,6 +76,11 @@ export default { compass: { tooltip: "Brújula / Norte" }, + screenshot: { + title: "Captura de Pantalla", + button: "Tomar Captura de Pantalla", + clipboard: "Copiar al Portapapeles", + }, controls: { title: "Vista / Controles", perspective: { diff --git a/src/components/Menu/MainMenu.vue b/src/components/Menu/MainMenu.vue index dfe8b86..723ca62 100644 --- a/src/components/Menu/MainMenu.vue +++ b/src/components/Menu/MainMenu.vue @@ -13,6 +13,7 @@
{{ $t("goFullscreen.button") }} {{ $t("resetCamera.button") }} + {{ $t("screenshot.button") }} {{ $t("updateMap.button") }} diff --git a/src/components/Menu/SettingsMenu.vue b/src/components/Menu/SettingsMenu.vue index 2394e5e..31195e5 100644 --- a/src/components/Menu/SettingsMenu.vue +++ b/src/components/Menu/SettingsMenu.vue @@ -41,6 +41,10 @@ >{{theme.name}} + + {{ $t("screenshot.clipboard") }} + + { + let link = document.createElement("a"); + link.download = "bluemap-screenshot.png"; + link.href = this.mapViewer.renderer.domElement.toDataURL('image/png'); + link.click(); + + if (this.appState.screenshot.clipboard) { + this.mapViewer.renderer.domElement.toBlob(blob => { + // eslint-disable-next-line no-undef + navigator.clipboard.write([new ClipboardItem({ ['image/png']: blob })]).catch(e => { + alert(this.events, "Failed to copy screenshot to clipboard: " + e, "error"); + }); + }); + } + } + }