SImageLegendItem.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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);
  18. /** 图例数量 */
  19. this._num = 1;
  20. this.zOrder = ItemOrder.markOrder;
  21. this.data = data;
  22. this.id = data.ID;
  23. this.name = data.Name;
  24. this.moveTo(data.Pos.X, data.Pos.Y);
  25. if (data.Num) {
  26. this._num = data.Num;
  27. }
  28. if (data.Size) {
  29. this.width = data.Size.Width;
  30. this.height = data.Size.Height;
  31. }
  32. if (data.Num) {
  33. this.text = `${data.Name}${data.Num > 1 ? ` × ${data.Num}` : ''}`;
  34. }
  35. if (data.Properties && data.Properties.Url) {
  36. this.img.url = data.Properties.Url;
  37. }
  38. if (data.Properties && data.Properties.sWidth) {
  39. this.sWidth = data.Properties.sWidth;
  40. }
  41. if (data.Properties && data.Properties.sHeight) {
  42. this.sHeight = data.Properties.sHeight;
  43. }
  44. if (data.Properties && data.Properties.font) {
  45. this.font = new SFont("sans-serif", data.Properties.font);
  46. }
  47. if (data.Properties && data.Properties.color) {
  48. this.color = new SColor(data.Properties.color);
  49. }
  50. }
  51. get num() {
  52. return this._num;
  53. }
  54. set num(v) {
  55. if (v) {
  56. this._num = v;
  57. this.data.Num = v;
  58. }
  59. else {
  60. this._num = 1;
  61. this.data.Num = 1;
  62. }
  63. this.data.Properties.Num = this._num;
  64. this.text = `${this.data.Name}${this.data.Num > 1 ? ` × ${this.data.Num}` : ''}`;
  65. this.update();
  66. }
  67. toData() {
  68. this.data.Pos = { X: this.x, Y: this.y };
  69. this.data.Size = { Width: this.width, Height: this.height };
  70. this.data.Name = this.name;
  71. this.data.Properties.Url = this.img.url;
  72. this.data.Properties.sWidth = this.sWidth;
  73. this.data.Properties.sHeight = this.sHeight;
  74. this.data.Properties.font = this.font.size;
  75. this.data.Properties.color = this.color.value;
  76. return this.data;
  77. }
  78. } // Class SImageLegendItem