SImageLegendItem.ts 5.5 KB

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