Kaynağa Gözat

构造函数修改

zhangyu 4 yıl önce
ebeveyn
işleme
46d28b0974

+ 52 - 0
src/lib/items/SImageLegendItem.ts

@@ -11,6 +11,40 @@ import { Legend } from '../types/Legend';
 export class SImageLegendItem extends SIconTextItem {
     /** 图例节点对象数据 */
     data: Legend;
+    /** 图例数量 */
+    _num: number = 0;
+    get num(): number {
+        return this._num;
+    }
+    set num(v: number) {
+        this._num = v;
+        this.data.Num = v;
+        this.update();
+    }
+
+    set name(v: string) {
+        this.data.Name = v;
+    }
+
+    set x(v: number) {
+        this.data.Pos.X = v;
+    }
+
+    set y(v: number) {
+        this.data.Pos.Y = v;
+    }
+
+    set width(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Width = v;
+        }
+    }
+
+    set height(v: number) {
+        if (this.data.Size) {
+            this.data.Size.Height = v;
+        }
+    }
 
     /**
      * 构造函数
@@ -22,5 +56,23 @@ export class SImageLegendItem extends SIconTextItem {
         super(parent);
         this.data = data;
         this.id = data.ID;
+        this.moveTo(data.Pos.X, data.Pos.Y);
+        if (data.Num) {
+            this._num = data.Num;
+        }
+        if (data.Size) {
+            this.width = data.Size.Width;
+            this.height = data.Size.Height;
+        }
+        if (data.Properties && data.Properties.Text) {
+            if (data.Properties.Text instanceof String) {
+                this.text = `${data.Properties.Text}${data.Num?` × ${data.Num}`:''}`;
+            }
+        }
+        if (data.Properties && data.Properties.Url) {
+            if (data.Properties.Url instanceof String) {
+                this.img.url = data.Properties.Url;
+            }
+        }
     }
 } // Class SImageLegendItem

+ 11 - 56
src/lib/items/SImageMarkerItem.ts

@@ -92,66 +92,21 @@ export class SImageMarkerItem extends SImageItem {
         this.data = data;
         this.id = data.ID;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        // if (this.data.Scale) {
-        //     this.scaleX = this.data.Scale.X;
-        //     this.scaleY = this.data.Scale.Y;
+        // if (data.Scale) {
+        //     this.scaleX = data.Scale.X;
+        //     this.scaleY = data.Scale.Y;
         // }
-        // if (this.data.Rolate && this.data.Rolate.Z) {
-        //     this.rolate = this.data.Rolate.Z;
+        // if (data.Rolate && data.Rolate.Z) {
+        //     this.rolate = data.Rolate.Z;
         // }
-        if (this.data.Size) {
-            this.width = this.data.Size.Width;
-            this.height = this.data.Size.Height;
+        if (data.Size) {
+            this.width = data.Size.Width;
+            this.height = data.Size.Height;
         }
-        if (this.data.Properties && this.data.Properties.Url) {
-            if (this.data.Properties.Url instanceof String) {
-                this.url = this.data.Properties.Url;
+        if (data.Properties && data.Properties.Url) {
+            if (data.Properties.Url instanceof String) {
+                this.url = data.Properties.Url;
             }
         }
     } // Constructor
-
-    /**
-     * Item绘制操作
-     *
-     * @param   painter      绘画类
-     */
-    onDraw(painter: SPainter): void {
-        if (this.img) {
-            // 要绘制图片的宽度
-            let width = 0;
-            // 要绘制图片的宽度
-            let height = 0;
-            // 图片item的宽高比
-            let itemAspectRatio: number = this.width / this.height;
-            // 原始图片的宽高比
-            let imgAspectRatio: number =
-                (this.img.width as number) / (this.img.height as number);
-            // 原始图片的高宽比
-            let imgHwRatio: number =
-                (this.img.height as number) / (this.img.width as number);
-            if (this.showType == SImageShowType.Full) {
-                width = this.width;
-                height = this.height;
-            } else if (this.showType == SImageShowType.Equivalency) {
-                if (itemAspectRatio > imgAspectRatio) {
-                    height = this.height;
-                    width = imgAspectRatio * height;
-                } else if (itemAspectRatio < imgAspectRatio) {
-                    width = this.width;
-                    height = width * imgHwRatio;
-                } else {
-                    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.scale(this.scaleX, this.scaleY);
-            // painter.rotate(this.rolate);
-            painter.drawImage(this.img, -width / 2, -height / 2, width, height);
-        }
-    } // Function onDraw()
 } // Class SImageMarkerItem

+ 10 - 10
src/lib/items/SLineLegendItem.ts

@@ -93,19 +93,19 @@ export class SLineLegendItem extends SPolylineItem {
         this.data = data;
         this.id = data.ID;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        // if (this.data.Scale) {
-        //     this.scaleX = this.data.Scale.X;
-        //     this.scaleY = this.data.Scale.Y;
+        // if (data.Scale) {
+        //     this.scaleX = data.Scale.X;
+        //     this.scaleY = data.Scale.Y;
         // }
-        // if (this.data.Rolate && this.data.Rolate.Z) {
-        //     this.rolate = this.data.Rolate.Z;
+        // if (data.Rolate && this.data.Rolate.Z) {
+        //     this.rolate = data.Rolate.Z;
         // }
-        if (this.data.Size) {
-            this.width = this.data.Size.Width;
-            this.height = this.data.Size.Height;
+        if (data.Size) {
+            this.width = data.Size.Width;
+            this.height = data.Size.Height;
         }
-        if (this.data.Properties && this.data.Properties.Line) {
-            this.line = this.data.Properties.Line;
+        if (data.Properties && data.Properties.Line) {
+            this.line = data.Properties.Line;
         }
     }
 } // Class SLineLegendItem

+ 10 - 10
src/lib/items/SLineMarkerItem.ts

@@ -93,19 +93,19 @@ export class SLineMarkerItem extends SPolylineItem {
         this.data = data;
         this.id = data.ID;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        // if (this.data.Scale) {
-        //     this.scaleX = this.data.Scale.X;
-        //     this.scaleY = this.data.Scale.Y;
+        // if (data.Scale) {
+        //     this.scaleX = data.Scale.X;
+        //     this.scaleY = data.Scale.Y;
         // }
-        // if (this.data.Rolate && this.data.Rolate.Z) {
-        //     this.rolate = this.data.Rolate.Z;
+        // if (data.Rolate && data.Rolate.Z) {
+        //     this.rolate = data.Rolate.Z;
         // }
-        if (this.data.Size) {
-            this.width = this.data.Size.Width;
-            this.height = this.data.Size.Height;
+        if (data.Size) {
+            this.width = data.Size.Width;
+            this.height = data.Size.Height;
         }
-        if (this.data.Properties && this.data.Properties.Line) {
-            this.line = this.data.Properties.Line;
+        if (data.Properties && data.Properties.Line) {
+            this.line = data.Properties.Line;
         }
     } // Constructor
 } // Class SLineMarkerItem

+ 11 - 11
src/lib/items/STextMarkerItem.ts

@@ -112,20 +112,20 @@ export class STextMarkerItem extends STextItem {
         this.data = data;
         this.id = data.ID;
         this.moveTo(data.Pos.X, data.Pos.Y);
-        // if (this.data.Scale) {
-        //     this.scaleX = this.data.Scale.X;
-        //     this.scaleY = this.data.Scale.Y;
+        // if (data.Scale) {
+        //     this.scaleX = data.Scale.X;
+        //     this.scaleY = data.Scale.Y;
         // }
-        // if (this.data.Rolate && this.data.Rolate.Z) {
-        //     this.rolate = this.data.Rolate.Z;
+        // if (data.Rolate && data.Rolate.Z) {
+        //     this.rolate = data.Rolate.Z;
         // }
-        if (this.data.Size) {
-            this.width = this.data.Size.Width;
-            this.height = this.data.Size.Height;
+        if (data.Size) {
+            this.width = data.Size.Width;
+            this.height = data.Size.Height;
         }
-        if (this.data.Properties && this.data.Properties.Text) {
-            if (this.data.Properties.Text instanceof String) {
-                this.text = this.data.Properties.Text;
+        if (data.Properties && data.Properties.Text) {
+            if (data.Properties.Text instanceof String) {
+                this.text = data.Properties.Text;
             }
         }
     } // Constructor

+ 2 - 2
src/lib/items/SZoneLegendItem.ts

@@ -69,12 +69,12 @@ export class SZoneLegendItem extends SPolygonItem {
             // 设置线宽
             this.lineWidth = data.Properties.lineWidth;
             // 设置线宽颜色
-            this.strokeColor = new SColor(data.Properties.strokeColor)
+            this.strokeColor = new SColor(data.Properties.strokeColor);
             //
             this.fillColor = new SColor(data.Properties.fillColor) ;
         }
     }
-    toData(): any {
+    getData(): Legend {
         this.data.Properties.fillColor = this.fillColor;
         this.data.Properties.strokeColor = this.strokeColor;
         this.data.Properties.lineWidth = this.lineWidth;

+ 2 - 0
src/lib/types/Legend.ts

@@ -40,6 +40,8 @@ export interface Legend {
     GraphElementType: SGraphElementType;
     /** 对应的图例ID  */
     GraphElementId: string;
+    /** 图例数量  */
+    Num?: number;
     /** 位置  */
     Pos: Point;
     /** 缩放  */