STextMarkerItem.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { SGraphItem, STextItem, SLineStyle } from "@saga-web/graph/lib";
  2. import { SPainter, SColor,SFont, SPoint } from "@saga-web/draw";
  3. import { Marker } from '../types/Marker';
  4. import { ItemOrder } from '@saga-web/big/lib';
  5. /**
  6. * 标识对象Item(文本类型)
  7. *
  8. * * @author 张宇(taohuzy@163.com)
  9. */
  10. export class STextMarkerItem extends STextItem {
  11. /** 标识对象数据 */
  12. data: Marker;
  13. /**
  14. * 构造函数
  15. *
  16. * @param parent 指向父对象
  17. * @param data 标识对象数据
  18. */
  19. constructor(parent: SGraphItem | null, data: Marker) {
  20. super(parent);
  21. this.zOrder = ItemOrder.textOrder;
  22. this.isTransform = false;
  23. this.data = data;
  24. this.id = data.ID;
  25. this.name = data.Name;
  26. this.moveTo(data.Pos.X, data.Pos.Y);
  27. if (data.Size) {
  28. this.width = data.Size.Width;
  29. this.height = data.Size.Height;
  30. }
  31. if (data.Properties && data.Properties.Text) {
  32. this.text = data.Properties.Text;
  33. }
  34. if (data.Properties && data.Properties.Color) {
  35. this.color = new SColor(data.Properties.Color);
  36. }
  37. if (data.Properties && data.Properties.Font) {
  38. this.font = new SFont("sans-serif", data.Properties.Font);;
  39. }
  40. if (data.Properties && data.Properties.BackgroundColor) {
  41. this.backgroundColor = new SColor(data.Properties.BackgroundColor);
  42. }
  43. } // Constructor
  44. /**
  45. * 根据换行切割文本,绘制多行并计算外轮廓宽高
  46. *
  47. */
  48. protected drawFormatText(): void {
  49. super.drawFormatText();
  50. this.origin = new SPoint(this.width / 2, this.height / 2);
  51. } // Function drawFormatText()
  52. toData(): Marker {
  53. this.data.Pos = {X: this.x, Y: this.y};
  54. this.data.Size = {Width: this.width, Height: this.height};
  55. this.data.Properties.Text = this.text;
  56. this.data.Properties.Color = this.color.value;
  57. this.data.Properties.Font = this.font.size;
  58. this.data.Properties.BackgroundColor = this.backgroundColor.value;
  59. return this.data;
  60. }
  61. } // Class STextMarkerItem