SImageMarkerItem.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SImageMarkerItem = void 0;
  4. const lib_1 = require("@persagy-web/graph/lib");
  5. class SImageMarkerItem extends lib_1.SImageItem {
  6. constructor(parent, data) {
  7. super(parent);
  8. this._scaleX = 1;
  9. this._scaleY = 1;
  10. this._rolate = 0;
  11. this.data = data;
  12. this.moveTo(data.Pos.X, data.Pos.Y);
  13. if (this.data.Scale) {
  14. this.scaleX = this.data.Scale.X;
  15. this.scaleY = this.data.Scale.Y;
  16. }
  17. if (this.data.Rolate && this.data.Rolate.Z) {
  18. this.rolate = this.data.Rolate.Z;
  19. }
  20. if (this.data.Size) {
  21. this.width = this.data.Size.Width;
  22. this.height = this.data.Size.Height;
  23. }
  24. if (this.data.Properties && this.data.Properties.Url) {
  25. if (this.data.Properties.Url instanceof String) {
  26. this.url = this.data.Properties.Url;
  27. }
  28. }
  29. }
  30. get scaleX() {
  31. return this._scaleX;
  32. }
  33. set scaleX(v) {
  34. this._scaleX = v;
  35. if (this.data.Scale) {
  36. this.data.Scale.X = v;
  37. }
  38. this.update();
  39. }
  40. get scaleY() {
  41. return this._scaleY;
  42. }
  43. set scaleY(v) {
  44. this._scaleY = v;
  45. if (this.data.Scale) {
  46. this.data.Scale.Y = v;
  47. }
  48. this.update();
  49. }
  50. get rolate() {
  51. return this._rolate;
  52. }
  53. set rolate(v) {
  54. this._rolate = v;
  55. if (this.data.Rolate) {
  56. this.data.Rolate.Z = v;
  57. }
  58. this.update();
  59. }
  60. set name(v) {
  61. this.data.Name = v;
  62. }
  63. set url(v) {
  64. if (this.data.Properties) {
  65. this.data.Properties.Url = v;
  66. }
  67. }
  68. set x(v) {
  69. this.data.Pos.X = v;
  70. }
  71. set y(v) {
  72. this.data.Pos.Y = v;
  73. }
  74. set width(v) {
  75. if (this.data.Size) {
  76. this.data.Size.Width = v;
  77. }
  78. }
  79. set height(v) {
  80. if (this.data.Size) {
  81. this.data.Size.Height = v;
  82. }
  83. }
  84. onDraw(painter) {
  85. if (this.img) {
  86. let width = 0;
  87. let height = 0;
  88. let itemAspectRatio = this.width / this.height;
  89. let imgAspectRatio = this.img.width / this.img.height;
  90. let imgHwRatio = this.img.height / this.img.width;
  91. if (this.showType == lib_1.SImageShowType.Full) {
  92. width = this.width;
  93. height = this.height;
  94. }
  95. else if (this.showType == lib_1.SImageShowType.Equivalency) {
  96. if (itemAspectRatio > imgAspectRatio) {
  97. height = this.height;
  98. width = imgAspectRatio * height;
  99. }
  100. else if (itemAspectRatio < imgAspectRatio) {
  101. width = this.width;
  102. height = width * imgHwRatio;
  103. }
  104. else {
  105. width = this.width;
  106. height = this.height;
  107. }
  108. }
  109. else if (this.showType == lib_1.SImageShowType.AutoFit) {
  110. this.width = this.img.width;
  111. this.height = this.img.height;
  112. width = this.width;
  113. height = this.height;
  114. }
  115. painter.scale(this.scaleX, this.scaleY);
  116. painter.rotate(this.rolate);
  117. painter.drawImage(this.img, -width / 2, -height / 2, width, height);
  118. }
  119. }
  120. }
  121. exports.SImageMarkerItem = SImageMarkerItem;