SSCPZZoneLegendItem.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import { SColor, SFont, SPoint, SLineCapStyle } from "@saga-web/draw";
  2. import { STextItem } from '@saga-web/graph/lib';
  3. import { SItemStatus, ItemOrder, SPolygonItem } from '@saga-web/big/lib';
  4. import { hexify } from "../../components/mapClass/until";
  5. /**
  6. * 图例节点Item(区域类型 --石材铺装)
  7. *
  8. * * @author 张宇(taohuzy@163.com)
  9. */
  10. export class SSCPZZoneLegendItem extends SPolygonItem {
  11. /**
  12. * 构造函数
  13. *
  14. * @param parent 指向父对象
  15. * @param data 图例节点对象数据
  16. */
  17. constructor(parent, data) {
  18. super(parent);
  19. /** text item */
  20. this.textItem = new STextItem(this);
  21. /** 是否显示文字 */
  22. this._showText = true;
  23. /** 是否蒙版遮罩 */
  24. this._maskFlag = false;
  25. this.zOrder = ItemOrder.polygonOrder;
  26. this.data = data;
  27. this.id = data.ID;
  28. this.name = data.Name;
  29. this.text = data.Name;
  30. if (data) {
  31. this.setPointList = [];
  32. let setPointList;
  33. if (data.OutLine) {
  34. if (data.OutLine[0] instanceof SPoint) {
  35. this.setPointList = data.OutLine;
  36. }
  37. else {
  38. setPointList = data.OutLine.map(i => {
  39. return (new SPoint(i.X, i.Y));
  40. });
  41. this.setPointList = setPointList;
  42. }
  43. }
  44. // 设置线宽
  45. if (data.Properties.LineWidth) {
  46. this.lineWidth = data.Properties.LineWidth;
  47. }
  48. if (data.Properties.StrokeColor) {
  49. this.strokeColor = data.Properties.StrokeColor.includes('#') ? new SColor(data.Properties.StrokeColor) : new SColor(hexify(data.Properties.StrokeColor));
  50. }
  51. if (data.Properties.FillColor) {
  52. this.fillColor = data.Properties.FillColor.includes('#') ? new SColor(data.Properties.FillColor) : new SColor(hexify(data.Properties.FillColor));
  53. }
  54. if (data.Properties.TextPos) {
  55. this.textItem.moveTo(data.Properties.TextPos.X, data.Properties.TextPos.Y);
  56. }
  57. if (data.Properties.color) {
  58. this.color = new SColor(data.Properties.color);
  59. }
  60. if (data.Properties.font) {
  61. this.font = new SFont("sans-serif", data.Properties.font);
  62. }
  63. // if( data.Properties.LineDash){
  64. // this.LineDash =this._legend.Properties.LineDash
  65. // }
  66. }
  67. // 监听多边形创建完成事件,并动态计算文本位置
  68. this.connect("finishCreated", this, () => {
  69. // 计算文本位置
  70. let x = this.getPointList.reduce((pre, cur, index, arr) => {
  71. return pre + (cur.x / arr.length);
  72. }, 0), y = this.getPointList.reduce((pre, cur, index, arr) => {
  73. return pre + (cur.y / arr.length);
  74. }, 0);
  75. this.textItem.moveTo(x, y);
  76. });
  77. }
  78. get text() {
  79. return this.textItem.text;
  80. }
  81. set text(v) {
  82. this.textItem.text = v;
  83. this.update();
  84. }
  85. get color() {
  86. return this.textItem.color;
  87. }
  88. set color(v) {
  89. this.textItem.color = v;
  90. }
  91. get font() {
  92. return this.textItem.font;
  93. }
  94. set font(v) {
  95. this.textItem.font = v;
  96. }
  97. get status() {
  98. return this._status;
  99. }
  100. // 编辑当前状态
  101. set status(value) {
  102. this._status = value;
  103. // 如果状态为show则需清栈
  104. if (value == SItemStatus.Normal) {
  105. // 切换显示状态显示文本
  106. this.showText = true;
  107. // 切换显示状态不可移动文本
  108. this.textItem.moveable = false;
  109. if (this.undoStack) {
  110. this.undoStack.clear();
  111. }
  112. }
  113. else if (value == SItemStatus.Edit) {
  114. // 切换编辑状态显示文本
  115. this.showText = true;
  116. // 切换编辑状态可移动文本
  117. this.textItem.moveable = true;
  118. }
  119. else if (value == SItemStatus.Create) {
  120. // 切换创建状态不显示文本
  121. this.showText = false;
  122. // 切换创建状态不可移动文本
  123. this.textItem.moveable = false;
  124. }
  125. this.update();
  126. }
  127. ;
  128. get showText() {
  129. return this._showText;
  130. }
  131. set showText(v) {
  132. if (v === this._showText) {
  133. return;
  134. }
  135. this._showText = v;
  136. if (v) {
  137. this.textItem.show();
  138. }
  139. else {
  140. this.textItem.hide();
  141. }
  142. }
  143. get maskFlag() {
  144. return this._maskFlag;
  145. }
  146. set maskFlag(v) {
  147. if (v === this._maskFlag) {
  148. return;
  149. }
  150. this._maskFlag = v;
  151. this.update();
  152. }
  153. /** 图例说明 */
  154. set itemExplain(v) {
  155. this.data.Properties.ItemExplain = v;
  156. }
  157. get itemExplain() {
  158. return this.data.Properties.ItemExplain;
  159. }
  160. toData() {
  161. this.data.Pos = { X: this.x, Y: this.y };
  162. this.data.Name = this.text;
  163. this.data.Properties.FillColor = this.fillColor.value;
  164. this.data.Properties.StrokeColor = this.strokeColor.value;
  165. this.data.Properties.LineWidth = this.lineWidth;
  166. this.data.OutLine = this.getPointList.map(pos => {
  167. return {
  168. X: pos.x,
  169. Y: pos.y
  170. };
  171. });
  172. this.data.Properties.TextPos = { X: this.textItem.x, Y: this.textItem.y };
  173. this.data.Properties.font = this.font.size;
  174. this.data.Properties.color = this.color.value;
  175. return this.data;
  176. }
  177. onDraw(painter) {
  178. if (this.maskFlag && this.status == SItemStatus.Normal) {
  179. let color = new SColor(this.strokeColor);
  180. color.alpha = 100;
  181. let brushcolor = new SColor(this.fillColor);
  182. brushcolor.alpha = 100;
  183. painter.pen.color = color;
  184. painter.pen.lineCapStyle = SLineCapStyle.Square;
  185. painter.pen.lineWidth = painter.toPx(this._lineWidth);
  186. painter.brush.color = brushcolor;
  187. // @ts-ignore
  188. painter.drawPolygon([...this.pointList]);
  189. }
  190. else {
  191. super.onDraw(painter);
  192. }
  193. }
  194. } // Class SZoneLegendItem