1
0
Эх сурвалжийг харах

throttle new image sources for annotation tool as long as download is in progress

Falko Schindler 3 жил өмнө
parent
commit
d228d9979e

+ 16 - 1
nicegui/elements/annotation_tool.js

@@ -14,6 +14,15 @@ Vue.component("annotation_tool", {
   mounted() {
   mounted() {
     comp_dict[this.$props.jp_props.id] = this;
     comp_dict[this.$props.jp_props.id] = this;
     const image = document.getElementById(this.$props.jp_props.id).firstChild;
     const image = document.getElementById(this.$props.jp_props.id).firstChild;
+    const handle_completion = () => {
+      if (this.waiting_source) {
+        image.src = this.waiting_source;
+      } else {
+        this.loading = false;
+      }
+    };
+    image.addEventListener("load", handle_completion);
+    image.addEventListener("error", handle_completion);
     const svg = document.getElementById(this.$props.jp_props.id).lastChild;
     const svg = document.getElementById(this.$props.jp_props.id).lastChild;
     const cross = svg.firstChild;
     const cross = svg.firstChild;
     image.ondragstart = () => false;
     image.ondragstart = () => false;
@@ -57,7 +66,13 @@ Vue.component("annotation_tool", {
   },
   },
   methods: {
   methods: {
     set_source(source) {
     set_source(source) {
-      document.getElementById(this.$props.jp_props.id).firstChild.src = source;
+      if (this.loading) {
+        this.waiting_source = source;
+        return;
+      }
+      this.loading = true;
+      image = document.getElementById(this.$props.jp_props.id).firstChild;
+      image.src = source;
     },
     },
   },
   },
   props: {
   props: {