SImageLegendItem.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. }
  58. get num() {
  59. return this._num;
  60. }
  61. set num(v) {
  62. if (v) {
  63. this._num = v;
  64. this.data.Num = v;
  65. }
  66. else {
  67. this._num = 1;
  68. this.data.Num = 1;
  69. }
  70. this.data.Properties.Num = this._num;
  71. this.text = `${this.data.Name}${this.data.Num > 1 ? ` × ${this.data.Num}` : ''}`;
  72. this.update();
  73. }
  74. toData() {
  75. this.data.Pos = { X: this.x, Y: this.y };
  76. this.data.Size = { Width: this.width, Height: this.height };
  77. this.data.Name = this.name;
  78. this.data.Properties.Url = this.img.url;
  79. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y };
  80. this.data.Properties.ImgPos = { X: this.img.x, Y: this.img.y };
  81. this.data.Properties.sWidth = this.sWidth;
  82. this.data.Properties.sHeight = this.sHeight;
  83. this.data.Properties.font = this.font.size;
  84. this.data.Properties.color = this.color.value;
  85. this.data.AnchorList = this.anchorList.map(t => {
  86. return {
  87. ID: t.id,
  88. Pos: {
  89. X: t.x,
  90. Y: t.y
  91. }
  92. };
  93. });
  94. return this.data;
  95. }
  96. } // Class SImageLegendItem