SImageLegendItem.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. if (v) {
  51. this.textItem.visible = false;
  52. } else {
  53. this.textItem.visible = true;
  54. }
  55. this.update()
  56. }
  57. /**
  58. * 构造函数
  59. *
  60. * @param parent 指向父对象
  61. * @param data 图例节点对象数据
  62. */
  63. constructor(parent: SGraphItem | null, data: Legend) {
  64. super(parent, data.AnchorList);
  65. this.isTransform = false;
  66. this.zOrder = ItemOrder.markOrder;
  67. this.data = data;
  68. this.id = data.ID;
  69. this.name = data.Name;
  70. this.text = data.Name;
  71. this.moveTo(data.Pos.X, data.Pos.Y);
  72. if (data.Num) {
  73. this.num = data.Num;
  74. }
  75. if (data.Size) {
  76. this.width = data.Size.Width;
  77. this.height = data.Size.Height;
  78. }
  79. if (data.Properties.Zorder) {
  80. this.zOrder = data.Properties.Zorder;
  81. }
  82. if (data.Properties && data.Properties.Url) {
  83. this.img.url = data.Properties.Url;
  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.ImgPos) {
  92. this.img.moveTo(data.Properties.ImgPos.X, data.Properties.ImgPos.Y);
  93. }
  94. if (data.Properties && data.Properties.font) {
  95. this.font = new SFont("sans-serif", data.Properties.font);
  96. }
  97. if (data.Properties.TextPos) {
  98. this.textItem.moveTo(data.Properties.TextPos.X, data.Properties.TextPos.Y);
  99. } else {
  100. // 偏移二分之一文本高度
  101. this.textItem.moveTo((this.img.width * 0.5), -(this.font.size * 1.25 * 0.5));
  102. }
  103. if (data.Properties && data.Properties.color) {
  104. this.color = new SColor(data.Properties.color);
  105. }
  106. if (data.Properties && data.Properties.IsActive) {
  107. this.isActive = data.Properties.IsActive;
  108. }
  109. if (data.AttachObjectIds && data.AttachObjectIds.length) {
  110. this.isActive = true;
  111. }
  112. if (data.Properties && data.Properties.FrameColor) {
  113. this.activeColor = new SColor(data.Properties.FrameColor);
  114. }
  115. }
  116. toData(): Legend {
  117. this.data.Pos = { X: this.x, Y: this.y };
  118. this.data.Size = { Width: this.width, Height: this.height };
  119. this.data.Name = this.name;
  120. this.data.Properties.Zorder = this.zOrder;
  121. this.data.Properties.Url = this.img.url;
  122. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y };
  123. this.data.Properties.ImgPos = { X: this.img.x, Y: this.img.y };
  124. this.data.Properties.sWidth = this.sWidth;
  125. this.data.Properties.sHeight = this.sHeight;
  126. this.data.Properties.font = this.font.size;
  127. this.data.Properties.color = this.color.value;
  128. this.data.Properties.FrameColor = this.activeColor.value;
  129. this.data.Properties.IsActive = this.isActive;
  130. this.data.AnchorList = this.anchorList.map(t => {
  131. return {
  132. ID: t.id,
  133. Pos: {
  134. X: t.x,
  135. Y: t.y
  136. }
  137. }
  138. })
  139. return this.data;
  140. }
  141. /**
  142. * Item绘制框架
  143. *
  144. * @param painter painter对象
  145. * @param rect 绘制区域
  146. */
  147. onPaint(painter: SPainter, rect: SRect): void {
  148. super.onPaint(painter, rect);
  149. if (this.maskFlag && this.status == SItemStatus.Normal) {
  150. painter.pen.color = SColor.Transparent;
  151. painter.brush.color = new SColor("#ffffffa1");
  152. if (this.selected) {
  153. painter.drawCircle(this.img.x, this.img.y, (this.sWidth / 2.0) * 1.25);
  154. } else {
  155. painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0);
  156. }
  157. }
  158. } // Function onPaint()
  159. } // Class SImageLegendItem