SImageLegendItem.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { SIconTextItem } from '@saga-web/big/lib/items/SIconTextItem';
  2. import { ItemOrder } 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. this.isTransform = false;
  21. this.zOrder = ItemOrder.markOrder;
  22. this.data = data;
  23. this.id = data.ID;
  24. this.name = data.Name;
  25. this.moveTo(data.Pos.X, data.Pos.Y);
  26. if (data.Num) {
  27. this._num = data.Num;
  28. }
  29. if (data.Size) {
  30. this.width = data.Size.Width;
  31. this.height = data.Size.Height;
  32. }
  33. if (data.Num) {
  34. this.text = `${data.Name}${data.Num > 1 ? ` × ${data.Num}` : ''}`;
  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.text = `${this.data.Name}${this.data.Num > 1 ? ` × ${this.data.Num}` : ''}`;
  81. this.update();
  82. }
  83. toData() {
  84. this.data.Pos = { X: this.x, Y: this.y };
  85. this.data.Size = { Width: this.width, Height: this.height };
  86. this.data.Name = this.name;
  87. this.data.Properties.Url = this.img.url;
  88. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y };
  89. this.data.Properties.ImgPos = { X: this.img.x, Y: this.img.y };
  90. this.data.Properties.sWidth = this.sWidth;
  91. this.data.Properties.sHeight = this.sHeight;
  92. this.data.Properties.font = this.font.size;
  93. this.data.Properties.color = this.color.value;
  94. this.data.Properties.FrameColor = this.activeColor.value;
  95. this.data.Properties.IsActive = this.isActive;
  96. this.data.AnchorList = this.anchorList.map(t => {
  97. return {
  98. ID: t.id,
  99. Pos: {
  100. X: t.x,
  101. Y: t.y
  102. }
  103. };
  104. });
  105. return this.data;
  106. }
  107. } // Class SImageLegendItem