SImageLegendItem.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.text = data.Name;
  28. this.moveTo(data.Pos.X, data.Pos.Y);
  29. if (data.Num) {
  30. this.num = data.Num;
  31. }
  32. if (data.Size) {
  33. this.width = data.Size.Width;
  34. this.height = data.Size.Height;
  35. }
  36. if (data.Properties && data.Properties.Url) {
  37. this.img.url = data.Properties.Url;
  38. }
  39. if (data.Properties.ImgPos) {
  40. this.img.moveTo(data.Properties.ImgPos.X, data.Properties.ImgPos.Y);
  41. }
  42. if (data.Properties.TextPos) {
  43. this.textItem.moveTo(data.Properties.TextPos.X, data.Properties.TextPos.Y);
  44. }
  45. if (data.Properties && data.Properties.sWidth) {
  46. this.sWidth = data.Properties.sWidth;
  47. }
  48. if (data.Properties && data.Properties.sHeight) {
  49. this.sHeight = data.Properties.sHeight;
  50. }
  51. if (data.Properties && data.Properties.font) {
  52. this.font = new SFont("sans-serif", data.Properties.font);
  53. }
  54. if (data.Properties && data.Properties.color) {
  55. this.color = new SColor(data.Properties.color);
  56. }
  57. if (data.Properties && data.Properties.IsActive) {
  58. this.isActive = data.Properties.IsActive;
  59. }
  60. if (data.AttachObjectIds && data.AttachObjectIds.length) {
  61. this.isActive = true;
  62. }
  63. if (data.Properties && data.Properties.FrameColor) {
  64. this.activeColor = new SColor(data.Properties.FrameColor);
  65. }
  66. }
  67. get num() {
  68. return this._num;
  69. }
  70. set num(v) {
  71. if (v) {
  72. this._num = v;
  73. this.data.Num = v;
  74. }
  75. else {
  76. this._num = 1;
  77. this.data.Num = 1;
  78. }
  79. this.data.Properties.Num = this._num;
  80. this.textItem.text = `${this.name}${this.num > 1 ? ` × ${this.num}` : ''}`;
  81. this.update();
  82. }
  83. get text() {
  84. return this.textItem.text;
  85. }
  86. set text(v) {
  87. this.name = v;
  88. this.data.Name = v;
  89. this.textItem.text = `${this.name}${this.num > 1 ? ` × ${this.num}` : ''}`;
  90. this.update();
  91. }
  92. get maskFlag() {
  93. return this._maskFlag;
  94. }
  95. set maskFlag(v) {
  96. if (v === this._maskFlag) {
  97. return;
  98. }
  99. this._maskFlag = v;
  100. this.update();
  101. }
  102. toData() {
  103. this.data.Pos = { X: this.x, Y: this.y };
  104. this.data.Size = { Width: this.width, Height: this.height };
  105. this.data.Name = this.name;
  106. this.data.Properties.Url = this.img.url;
  107. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y };
  108. this.data.Properties.ImgPos = { X: this.img.x, Y: this.img.y };
  109. this.data.Properties.sWidth = this.sWidth;
  110. this.data.Properties.sHeight = this.sHeight;
  111. this.data.Properties.font = this.font.size;
  112. this.data.Properties.color = this.color.value;
  113. this.data.Properties.FrameColor = this.activeColor.value;
  114. this.data.Properties.IsActive = this.isActive;
  115. this.data.AnchorList = this.anchorList.map(t => {
  116. return {
  117. ID: t.id,
  118. Pos: {
  119. X: t.x,
  120. Y: t.y
  121. }
  122. };
  123. });
  124. return this.data;
  125. }
  126. /**
  127. * Item绘制框架
  128. *
  129. * @param painter painter对象
  130. * @param rect 绘制区域
  131. */
  132. onPaint(painter, rect) {
  133. super.onPaint(painter, rect);
  134. if (this.maskFlag && this.status == SItemStatus.Normal) {
  135. painter.pen.color = SColor.Transparent;
  136. painter.brush.color = new SColor("#ffffffa1");
  137. if (this.selected) {
  138. painter.drawCircle(this.img.x, this.img.y, (this.sWidth / 2.0) * 1.25);
  139. }
  140. else {
  141. painter.drawCircle(this.img.x, this.img.y, this.sWidth / 2.0);
  142. }
  143. }
  144. } // Function onPaint()
  145. } // Class SImageLegendItem