point.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { app as App } from "../app";
  2. import { label as Label } from "../components/label";
  3. import { menu as Menu } from "../core/components/menu";
  4. import { ELEMENTS_CLASS } from "../core/enums/elements-class-enum";
  5. export const point = (function() {
  6. let style = {
  7. fill: "#9bc364",
  8. strokeWidth: 1,
  9. stroke: "#9bc364"
  10. };
  11. let _tool = {};
  12. let states = ["center"];
  13. let state = undefined;
  14. let points = [0, 0];
  15. function _draw(e) {
  16. if (state == undefined) {
  17. state = states[0];
  18. App.setStatus("Selecione o centro do Ponto");
  19. } else if (state == states[0]) {
  20. let pos = App.pos();
  21. points[0] = pos.x;
  22. points[1] = pos.y;
  23. let p = points.slice();
  24. let po = _drawPoint(p[0], p[1], true);
  25. }
  26. }
  27. function _bootstrap() {
  28. Menu.add(_tool);
  29. }
  30. function _drawPoint(x, y, useLabel) {
  31. let group = new Konva.Group({
  32. draggable: true,
  33. resizeEnabled: false
  34. });
  35. let circle = new Konva.Circle({
  36. x: x,
  37. y: y,
  38. radius: 5,
  39. fill: "#9bc364",
  40. stroke: "#9bc364",
  41. strokeWidth: 1,
  42. strokeScaleEnabled: false,
  43. draggable: false,
  44. resizeEnabled: false,
  45. transformEnabled: false,
  46. style: style,
  47. class: ELEMENTS_CLASS.POINT,
  48. connections: []
  49. });
  50. let text = new Konva.Text({
  51. x: x + 10,
  52. y: y - 10,
  53. text: Label.draw(),
  54. fontSize: 12,
  55. fontFamily: "Calibri",
  56. fill: "#434a45",
  57. draggable: false,
  58. resizeEnabled: false,
  59. transformEnabled: false,
  60. selectable: false
  61. });
  62. group.add(circle);
  63. if (useLabel != undefined && useLabel) {
  64. group.add(text);
  65. }
  66. let layer = App.currentLayer();
  67. layer.add(group);
  68. App.stage.draw();
  69. App.pushObject(group);
  70. _clearState();
  71. App.clearSelectedTool();
  72. App.setStatus("");
  73. }
  74. function _click(e) {
  75. if (state == states[0]) {
  76. App.clearSelectedTool();
  77. _clearState();
  78. return;
  79. }
  80. App.setSelectedTool(_tool);
  81. state = states[0];
  82. App.setStatus("Selecione o centro da Ponto");
  83. }
  84. function _clearState() {
  85. state = undefined;
  86. }
  87. _tool = {
  88. id: "point",
  89. title: "Ponto",
  90. icon: "point",
  91. click: _click,
  92. draw: _draw,
  93. points: points
  94. };
  95. _bootstrap();
  96. return {
  97. draw: _draw,
  98. click: _click
  99. };
  100. })();