point-model.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /**
  30. * Create new Intersection By Line of Script .geo
  31. * @param {Map} map JavaScript Map
  32. * @param {List} list List of Generic Objects
  33. */
  34. static do(map, list) {
  35. const id = map.get("id");
  36. const x = map.get("param")[0] - 5;
  37. const y = -map.get("param")[1] + 5;
  38. const label = map.get("label")[0];
  39. return new PointModel(x, y, label, id);
  40. }
  41. }