Explorar el Código

'图片item优化和添加等比缩放模式'

zhangyu hace 5 años
padre
commit
03df11f187

+ 3 - 1
saga-web-big/src/enums/SImageShowType.ts

@@ -7,5 +7,7 @@ export enum SImageShowType {
     /** 铺满  */
     Full,
     /** 自适应 */
-    AutoFit
+    AutoFit,
+    /** 等比缩放 */
+    Equivalency,
 } // Enum SImageShowType

+ 2 - 0
saga-web-big/src/enums/SMarkerType.ts

@@ -8,4 +8,6 @@ export enum SMarkerType {
 	Image,
 	/** 线类型    */
 	Line,
+    /** 文本类型    */
+    Text
 } // Enum SMarkerType

+ 12 - 5
saga-web-big/src/items/SImageItem.ts

@@ -40,9 +40,11 @@ export class SImageItem extends SObjectItem {
      * 构造函数
      *
      * @param   parent      指向父Item
+     * @param   url         图片地址
      */
-    constructor(parent: SGraphItem | null) {
+    constructor(parent: SGraphItem | null, url?: string) {
         super(parent);
+        if (url) this._url = url;
     } // Constructor
 
     /**
@@ -77,9 +79,9 @@ export class SImageItem extends SObjectItem {
     onDraw(painter: SPainter): void {
         if (this.img) {
             // 要绘制图片的宽度
-            let width = 0;
+            let width: number = 0;
             // 要绘制图片的宽度
-            let height = 0;
+            let height: number = 0;
             // 图片item的宽高比
             let itemAspectRatio: number = this.width / this.height;
             // 原始图片的宽高比
@@ -91,7 +93,7 @@ export class SImageItem extends SObjectItem {
             if (this.showType == SImageShowType.Full) {
                 width = this.width;
                 height = this.height;
-            } else if (this.showType == SImageShowType.AutoFit) {
+            } else if (this.showType == SImageShowType.Equivalency) {
                 if (itemAspectRatio > imgAspectRatio) {
                     height = this.height;
                     width = imgAspectRatio * height;
@@ -102,8 +104,13 @@ export class SImageItem extends SObjectItem {
                     width = this.width;
                     height = this.height;
                 }
+            } else if (this.showType == SImageShowType.AutoFit) {
+                this.width = this.img.width as number;
+                this.height = this.img.height as number;
+                width = this.width;
+                height = this.height;
             }
-            painter.drawImage(this.img, -width / 2, -height / 2, width, height);
+            painter.drawImage(this.img, - width / 2, - height / 2, width, height);
         }
     } // Function onDraw()
 } // Class SImageItem