SImageLegendItem.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { SGraphItem } from "@saga-web/graph/lib";
  2. import { SIconTextItem } from '@saga-web/big/lib/items/SIconTextItem';
  3. import { Legend } from '../types/Legend';
  4. import { ItemOrder, SItemStatus } from '@saga-web/big/lib';
  5. import { SFont, SColor, SPainter, SRect } from '@saga-web/draw/lib';
  6. /**
  7. * 图例节点Item(图标类型)
  8. *
  9. * * @author 张宇(taohuzy@163.com)
  10. */
  11. export class SImageLegendItem extends SIconTextItem {
  12. /** 图例节点对象数据 */
  13. data: Legend;
  14. /** 图例数量 */
  15. _num: number = 1;
  16. get num(): number {
  17. return this._num;
  18. }
  19. set num(v: number) {
  20. if (v) {
  21. this._num = v;
  22. this.data.Num = v;
  23. } else {
  24. this._num = 1;
  25. this.data.Num = 1;
  26. }
  27. this.data.Properties.Num = this._num;
  28. this.textItem.text = `${this.name}${this.num > 1 ? ` × ${this.num}` : ''}`;
  29. this.update();
  30. }
  31. get text(): string {
  32. return this.textItem.text;
  33. }
  34. set text(v: string) {
  35. this.name = v;
  36. this.data.Name = v;
  37. this.textItem.text = `${this.name}${this.num > 1 ? ` × ${this.num}` : ''}`;
  38. this.update();
  39. }
  40. /** 是否蒙版遮罩 */
  41. _maskFlag: boolean = false;
  42. get maskFlag(): boolean {
  43. return this._maskFlag;
  44. }
  45. set maskFlag(v: boolean) {
  46. if (v === this._maskFlag) {
  47. return
  48. }
  49. this._maskFlag = v;
  50. this.update()
  51. }
  52. /**
  53. * 构造函数
  54. *
  55. * @param parent 指向父对象
  56. * @param data 图例节点对象数据
  57. */
  58. constructor(parent: SGraphItem | null, data: Legend) {
  59. super(parent, data.AnchorList);
  60. this.isTransform = false;
  61. this.zOrder = ItemOrder.markOrder;
  62. this.data = data;
  63. this.id = data.ID;
  64. this.name = data.Name;
  65. this.moveTo(data.Pos.X, data.Pos.Y);
  66. if (data.Num) {
  67. this._num = data.Num;
  68. }
  69. if (data.Size) {
  70. this.width = data.Size.Width;
  71. this.height = data.Size.Height;
  72. }
  73. if (data.Num) {
  74. this.text = `${data.Name}${data.Num > 1 ? ` × ${data.Num}` : ''}`;
  75. }
  76. if (data.Properties && data.Properties.Url) {
  77. this.img.url = data.Properties.Url;
  78. }
  79. if (data.Properties.ImgPos) {
  80. this.img.moveTo(data.Properties.ImgPos.X, data.Properties.ImgPos.Y);
  81. }
  82. if (data.Properties.TextPos) {
  83. this.textItem.moveTo(data.Properties.TextPos.X, data.Properties.TextPos.Y);
  84. }
  85. if (data.Properties && data.Properties.sWidth) {
  86. this.sWidth = data.Properties.sWidth;
  87. }
  88. if (data.Properties && data.Properties.sHeight) {
  89. this.sHeight = data.Properties.sHeight;
  90. }
  91. if (data.Properties && data.Properties.font) {
  92. this.font = new SFont("sans-serif", data.Properties.font);
  93. }
  94. if (data.Properties && data.Properties.color) {
  95. this.color = new SColor(data.Properties.color);
  96. }
  97. if (data.Properties && data.Properties.IsActive) {
  98. this.isActive = data.Properties.IsActive;
  99. }
  100. if (data.AttachObjectIds && data.AttachObjectIds.length) {
  101. this.isActive = true;
  102. }
  103. if (data.Properties && data.Properties.FrameColor) {
  104. this.activeColor = new SColor(data.Properties.FrameColor);
  105. }
  106. }
  107. toData(): Legend {
  108. this.data.Pos = { X: this.x, Y: this.y };
  109. this.data.Size = { Width: this.width, Height: this.height };
  110. this.data.Name = this.name;
  111. this.data.Properties.Url = this.img.url;
  112. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y };
  113. this.data.Properties.ImgPos = { X: this.img.x, Y: this.img.y };
  114. this.data.Properties.sWidth = this.sWidth;
  115. this.data.Properties.sHeight = this.sHeight;
  116. this.data.Properties.font = this.font.size;
  117. this.data.Properties.color = this.color.value;
  118. this.data.Properties.FrameColor = this.activeColor.value;
  119. this.data.Properties.IsActive = this.isActive;
  120. this.data.AnchorList = this.anchorList.map(t => {
  121. return {
  122. ID: t.id,
  123. Pos: {
  124. X: t.x,
  125. Y: t.y
  126. }
  127. }
  128. })
  129. return this.data;
  130. }
  131. /**
  132. * Item绘制框架
  133. *
  134. * @param painter painter对象
  135. * @param rect 绘制区域
  136. */
  137. onPaint(painter: SPainter, rect: SRect): void {
  138. super.onPaint(painter, rect);
  139. if (this.maskFlag && this.status == SItemStatus.Normal) {
  140. painter.pen.color = SColor.Transparent;
  141. painter.brush.color = new SColor("#ffffffa1");
  142. if (this.selected) {
  143. painter.drawCircle(this.img.x, this.img.y, (this.sWidth / 2.0) * 1.25);
  144. } else {
  145. painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0);
  146. }
  147. }
  148. } // Function onPaint()
  149. } // Class SImageLegendItem