xushiting %!s(int64=2) %!d(string=hai) anos
pai
achega
8716828f20
Modificáronse 2 ficheiros con 26 adicións e 2 borrados
  1. 21 0
      src/graphic/Geometry/Img.js
  2. 5 2
      src/graphic/Load.js

+ 21 - 0
src/graphic/Geometry/Img.js

@@ -1,3 +1,4 @@
+import { mathUtil } from "../Util/MathUtil.js";
 import VectorType from "../enum/VectorType.js";
 import Geometry from "./Geometry";
 
@@ -7,12 +8,32 @@ export default class Img extends Geometry {
     this.src = null;
     this.angle = 0;
     this.display = true;
+    this.center = null;
+    this.imageData = null;
     this.geoType = VectorType.Img;
     this.setId(vectorId);
     this.setSrc(src);
   }
 
+  setCenter(value) {
+    this.center = {};
+    mathUtil.clonePoint(this.center, value);
+  }
+
   setSrc(src) {
     this.src = src;
   }
+
+  setImageData() {
+    return Promise((resolve, reject) => {
+      this.imageData = new Image();
+      this.imageData.src = this.src;
+      this.imageData.onload = function () {
+        resolve();
+      };
+      this.imageData.onerror = function () {
+        reject();
+      };
+    });
+  }
 }

+ 5 - 2
src/graphic/Load.js

@@ -3,6 +3,7 @@ import { lineService } from "./Service/LineService.js";
 import { pointService } from "./Service/PointService.js";
 import { imageService } from "./Service/ImageService.js";
 import VectorCategory from "./enum/VectorCategory.js";
+import { coordinate } from "./Coordinate.js";
 
 export default class Load {
   constructor(layer) {
@@ -12,13 +13,15 @@ export default class Load {
     this.newVectorId = null;
   }
 
-  load(dataLocal, data3d) {
+  async load(dataLocal, data3d) {
     if (dataLocal) {
       dataService.vectorData = JSON.parse(JSON.stringify(dataLocal));
     }
     if (data3d) {
       if (data3d.backImage) {
-        imageService.create(data3d.backImage);
+        let bgImg = imageService.create(data3d.backImage);
+        bgImg.setCenter(coordinate.center);
+        await bgImg.setImageData();
       }
       if (data3d.baseLines) {
         for (let i = 0; i < data3d.baseLines.length; ++i) {