point.js 2.0 KB

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