From 141d46a513c92f9670529bbbd495d2edaf42138d Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Wed, 8 Feb 2023 17:35:47 +0100 Subject: [PATCH] Add loading message and improve webapp-error if a map could not be loaded --- BlueMapCommon/webapp/public/lang/de.conf | 5 +++++ BlueMapCommon/webapp/public/lang/en.conf | 5 +++++ BlueMapCommon/webapp/src/App.vue | 16 +++++++++++++-- .../src/components/ControlBar/ControlBar.vue | 20 +++++++++++-------- BlueMapCommon/webapp/src/js/BlueMapApp.js | 11 ++++++---- BlueMapCommon/webapp/src/js/MapViewer.js | 8 +++++++- 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/BlueMapCommon/webapp/public/lang/de.conf b/BlueMapCommon/webapp/public/lang/de.conf index c1cea628..7aab5d3c 100644 --- a/BlueMapCommon/webapp/public/lang/de.conf +++ b/BlueMapCommon/webapp/public/lang/de.conf @@ -4,6 +4,11 @@ title: "MenĂ¼" tooltip: "MenĂ¼" } + map: { + unloaded: "Keine Karte geladen." + loading: "Lade Karte..." + errored: "Beim laden der Karte ist ein Fehler aufgetreten!" + } maps: { title: "Karten" button: "Karten" diff --git a/BlueMapCommon/webapp/public/lang/en.conf b/BlueMapCommon/webapp/public/lang/en.conf index bbde4758..31107a95 100644 --- a/BlueMapCommon/webapp/public/lang/en.conf +++ b/BlueMapCommon/webapp/public/lang/en.conf @@ -4,6 +4,11 @@ title: "Menu" tooltip: "Menu" } + map: { + unloaded: "No map loaded." + loading: "Loading map..." + errored: "There was an error trying to load this map!" + } maps: { title: "Maps" button: "Maps" diff --git a/BlueMapCommon/webapp/src/App.vue b/BlueMapCommon/webapp/src/App.vue index 7c567973..12680544 100644 --- a/BlueMapCommon/webapp/src/App.vue +++ b/BlueMapCommon/webapp/src/App.vue @@ -1,8 +1,9 @@ @@ -24,6 +25,7 @@ export default { data() { return { appState: this.$bluemap.appState, + mapViewer: this.$bluemap.mapViewer.data } } } @@ -51,5 +53,15 @@ export default { @media (max-width: $mobile-break) { font-size: 1.5rem; } + + .map-state-message { + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + color: var(--theme-fg-light); + line-height: 1em; + text-align: center; + } } diff --git a/BlueMapCommon/webapp/src/components/ControlBar/ControlBar.vue b/BlueMapCommon/webapp/src/components/ControlBar/ControlBar.vue index cded75a2..c1fda508 100644 --- a/BlueMapCommon/webapp/src/components/ControlBar/ControlBar.vue +++ b/BlueMapCommon/webapp/src/components/ControlBar/ControlBar.vue @@ -8,7 +8,7 @@ - - + - +
- +
- + - - + + @@ -82,6 +82,7 @@ return { appState: this.$bluemap.appState, markers: this.$bluemap.mapViewer.markers.data, + mapViewer: this.$bluemap.mapViewer.data } }, computed: { @@ -97,6 +98,9 @@ markers: [], fake: true, } + }, + showMapMenu() { + return this.mapViewer.mapState === "loading" || this.mapViewer.mapState === "loaded"; } }, methods: { @@ -150,7 +154,7 @@ margin: 0; width: 100%; - background-color: var(--theme-bg-light); + background-color: var(--theme-bg); .pos-input { max-width: unset; diff --git a/BlueMapCommon/webapp/src/js/BlueMapApp.js b/BlueMapCommon/webapp/src/js/BlueMapApp.js index 0075e0f3..ff9d673a 100644 --- a/BlueMapCommon/webapp/src/js/BlueMapApp.js +++ b/BlueMapCommon/webapp/src/js/BlueMapApp.js @@ -160,9 +160,13 @@ export class BlueMapApp { } // switch to map - if (!await this.loadPageAddress()) { - if (this.maps.length > 0) await this.switchMap(this.maps[0].data.id); - this.resetCamera(); + try { + if (!await this.loadPageAddress()) { + if (this.maps.length > 0) await this.switchMap(this.maps[0].data.id); + this.resetCamera(); + } + } catch (e) { + console.error("Failed to load map!", e); } // map position address @@ -180,7 +184,6 @@ export class BlueMapApp { // save user settings this.saveUserSettings(); - // load settings-scripts if (this.settings.scripts) for (let scriptUrl of this.settings.scripts) { let scriptElement = document.createElement("script"); diff --git a/BlueMapCommon/webapp/src/js/MapViewer.js b/BlueMapCommon/webapp/src/js/MapViewer.js index faa310aa..bab735fc 100644 --- a/BlueMapCommon/webapp/src/js/MapViewer.js +++ b/BlueMapCommon/webapp/src/js/MapViewer.js @@ -52,6 +52,7 @@ export class MapViewer { this.data = reactive({ map: null, + mapState: "unloaded", camera: null, controlsManager: null, uniforms: { @@ -366,6 +367,7 @@ export class MapViewer { */ switchMap(map = null) { if (this.map && this.map.isMap) this.map.unload(); + this.data.mapState = "loading"; this.map = map; @@ -385,12 +387,16 @@ export class MapViewer { setTimeout(this.updateLoadedMapArea); + this.data.mapState = "loaded"; + dispatchEvent(this.events, "bluemapMapChanged", { map: map }); }) .catch(error => { - alert(this.events, error, "error"); + this.data.mapState = "errored"; + this.map = null; + throw error; }); } else { return Promise.resolve();