SImageLegendItem.ts 6.2 KB

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