point-model.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { GeometricObject } from "../../../core/models/objects/geometric-object";
  2. import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
  3. export class PointModel extends GeometricObject {
  4. /**
  5. *
  6. * @param {number} posX X Position ex: (38.5) float precision
  7. * @param {number} posY Y Position ex: (-38.5) float precision
  8. * @param {string} label Label ex: (P)
  9. */
  10. constructor(posX, posY, label, id) {
  11. super(id);
  12. this.posX = posX;
  13. this.posY = posY;
  14. this.setLabel(label);
  15. super.setClass(ELEMENTS_CLASS.POINT);
  16. this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
  17. this.color = -16711936;
  18. }
  19. /**
  20. *
  21. * @param {konvaObject} Object of Konva Library
  22. * @param {*} event
  23. */
  24. update(konvaObject, event) {
  25. this.posX = konvaObject.attrs.startPosX + event.target._lastPos.x;
  26. this.posY = konvaObject.attrs.startPosY + event.target._lastPos.y;
  27. this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
  28. }
  29. bind(posX, posY, label, id) {
  30. super.id = id;
  31. this.posX = posX;
  32. this.posY = posY;
  33. this.setLabel(label);
  34. this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
  35. }
  36. /**
  37. * Create new Intersection By Line of Script .geo
  38. * @param {Map} map JavaScript Map
  39. * @param {List} list List of Generic Objects
  40. */
  41. static do(map, list) {
  42. const id = map.get("id");
  43. const x = map.get("param")[0] - 5;
  44. const y = -map.get("param")[1] + 5;
  45. const label = map.get("label")[0];
  46. return new PointModel(x, y, label, id);
  47. }
  48. }