xushiting 1 年間 前
コミット
bc086f9cca

+ 2 - 2
src/view/case/draw/board/editCAD/Controls/UIControl.js

@@ -145,7 +145,7 @@ export default class UIControl {
         break;
       case "upload":
         if(type == VectorType.CustomImage){
-          customImageService.setCustomImageSrc(value.src);
+          customImageService.setCustomImageUrl(value.url);
           stateService.setEventName(LayerEvents.AddCustomImage);
         }  
         break;
@@ -221,7 +221,7 @@ export default class UIControl {
         }
         value = {
             version:'2.0',
-            src: customImage.src,
+            url: customImage.url,
         };
         break;
     }

+ 9 - 8
src/view/case/draw/board/editCAD/Geometry/CustomImage.js

@@ -1,24 +1,25 @@
 import VectorType from '../enum/VectorType.js'
 import Geometry from './Geometry'
+import { mathUtil } from '../MathUtil.js'
+import SelectState from '../enum/SelectState.js'
 
 export default class CustomImage extends Geometry {
-    constructor(src,center,vectorId) {
+    constructor(url,center,vectorId) {
         super()
         this.center = center
-        this.src = src;
+        this.url = url;
         this.image = null;
         this.width = 40;
         this.height = 30;
         this.angle = 0 //逆时针为负,顺时针为正。单位是:°
-        this.scale = 1 //缩放比例
+        //this.scale = 1 //缩放比例
         this.geoType = VectorType.CustomImage
         this.setId(vectorId)
     }
 
     isContain(position) {
-        const dis = mathUtil.getDistance(position, this.center)
-        let len = this.getLen() * this.scale
-        if (dis < len / 2) {
+        if(Math.abs(position.x - this.center.x)<this.width/2 && Math.abs(position.y - this.center.y)<this.height/2)
+        {
             return SelectState.Select
         } else {
             return null
@@ -29,7 +30,7 @@ export default class CustomImage extends Geometry {
         this.image = imgData;
     }
 
-    setSrc(src){
-        this.src = src;
+    setUrl(url){
+        this.url = url;
     }
 }

+ 1 - 1
src/view/case/draw/board/editCAD/Load.js

@@ -56,7 +56,7 @@ export default class Load {
 
             for (let key in floor.customImages) {
                 let customImage = customImageService.createCustomImage(floor.customImages[key].center, floor.customImages[key].vectorId)
-                customImage.setSrc(floor.customImages[key].src)
+                customImage.setUrl(floor.customImages[key].url)
             }
 
             for (let key in floor.tables) {

+ 31 - 0
src/view/case/draw/board/editCAD/Renderer/Draw.js

@@ -846,6 +846,37 @@ export default class Draw {
         }
     }
 
+    drawCustomImage(geometry){
+        if(geometry.url != null){
+            const pt = {
+                x:30,
+                y:150
+            }
+
+            this.context.save()
+            if(geometry.image == null)
+            {
+                var img = new Image()
+                img.url = geometry.url;
+                img.crossOrigin=""
+                img.onload = function () {
+                    this.context.drawImage(img, pt.x, pt.y, img.width, img.height)
+                }.bind(this)
+                geometry.image = img;
+            }
+            else{
+                if(geometry.hasOwnProperty('width')){
+                    this.context.drawImage(geometry.image, pt.x, pt.y, geometry.width, geometry.height)
+                }
+                else{
+                    this.context.drawImage(geometry.image, pt.x, pt.y, geometry.image.width, geometry.image.height)
+                }
+                
+            }
+            this.context.restore()
+        }
+    }
+
     drawCompass(geometry){
         
         this.context.save()

+ 9 - 1
src/view/case/draw/board/editCAD/Renderer/Render.js

@@ -52,8 +52,11 @@ export default class Render {
             case VectorType.Compass:
                 draw.drawCompass(vector)
                 return
+            case VectorType.CustomImage:
+                draw.drawCustomImage(vector)
+                return
         }
-
+        
         if (signService.isSign(vector.geoType)) {
             draw.drawSign(vector)
             return
@@ -191,6 +194,11 @@ export default class Render {
             this.drawGeometry(icons[key])
         }
 
+        let customImages = data.customImages
+        for (let key in customImages) {
+            this.drawGeometry(customImages[key])
+        }
+        
         this.redrawElements()
     }
 

+ 5 - 5
src/view/case/draw/board/editCAD/Service/CustomImageService.js

@@ -6,17 +6,17 @@ import Constant from '../Constant'
 
 export default class CustomImageService {
     constructor() {
-        this.src = null;
+        this.url = null;
     }
 
-    setCustomImageSrc(src){
-        this.src = src;
+    setCustomImageUrl(url){
+        this.url = url;
     }
 
     createCustomImage(center,vectorId) {
-        const customImage = new CustomImage(this.src, center,vectorId)
+        const customImage = new CustomImage(this.url, center,vectorId)
         floorplanService.addCustomImage(customImage)
-        this.src = null;
+        this.url = null;
         return customImage
     }
 

+ 1 - 1
src/view/case/draw/board/editCAD/Service/FloorplanService.js

@@ -401,7 +401,7 @@ export class FloorplanService {
         return floorplanData.floors[floor].signs
     }
 
-    getCustomImages(){
+    getCustomImages(floor){
         if (floor == null || typeof floor == 'undefined') {
             floor = this.currentFloor
         }