SImageLegendItem.js 4.6 KB

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