layer.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Konva from "konva";
  2. import { ActionManager } from "../models/application/actions/action-manager";
  3. export class Layer {
  4. constructor(id, konvaLayer) {
  5. this.id = id;
  6. this.name = "New Construction " + this.id;
  7. this.konvaLayer = konvaLayer;
  8. this.aggregators = [];
  9. this.selectedAggregators = [];
  10. this.konvaGroup = new Konva.Group({
  11. draggable: false,
  12. resizeEnabled: false
  13. });
  14. this.konvaLayer.add(this.konvaGroup);
  15. this.actionManager = new ActionManager();
  16. }
  17. getKonvaGroup() {
  18. return this.konvaGroup;
  19. }
  20. getKonvaLayer() {
  21. return this.konvaLayer;
  22. }
  23. addAggregator(aggregator) {
  24. this.aggregators.push(aggregator);
  25. }
  26. getAggregators() {
  27. return this.aggregators;
  28. }
  29. getSelectedAggregators() {
  30. return this.selectedAggregators;
  31. }
  32. setSelectedAggregator(aggregator) {
  33. if (!this.selectedAggregators.includes(aggregator)) {
  34. this.selectedAggregators.push(aggregator);
  35. }
  36. }
  37. removeSelectedAggregator(aggregator) {
  38. if (this.selectedAggregators.includes(aggregator)) {
  39. let index = this.selectedAggregators.indexOf(aggregator);
  40. this.selectedAggregators.splice(index, 1);
  41. }
  42. }
  43. removeAggregator(aggregator) {
  44. let index = this.aggregators.indexOf(aggregator);
  45. //console.log('indexOf(aggregator): ', index) Debug
  46. this.aggregators.splice(index, 1);
  47. /*if (this.selectedAggregators.includes(aggregator)) {
  48. let index = this.selectedAggregators.indexOf(aggregator);
  49. this.selectedAggregators.splice(index, 1);
  50. } TODO = trecho estava causando conflitos, checar propósito*/
  51. this.actionManager.remove(aggregator.genericObject);
  52. aggregator.konvaObject.destroy();
  53. }
  54. }