layer.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. this.aggregators.splice(index, 1);
  46. if (this.selectedAggregators.includes(aggregator)) {
  47. let index = this.selectedAggregators.indexOf(aggregator);
  48. this.selectedAggregators.splice(index, 1);
  49. }
  50. this.actionManager.remove(aggregator.genericObject);
  51. aggregator.konvaObject.destroy();
  52. }
  53. }