source: imaps-frontend/src/scripts/base/MapNode.js

main
Last change on this file was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import MapShape from "./MapShape.js";
2import Konva from "konva";
3
4export default class MapNode extends MapShape{
5
6 constructor(config, layer, blockSize, snap) {
7 if (new.target === MapNode) {
8 throw new Error("Cannot instantiate abstract class NodeShape directly.");
9 }
10
11 super(config,layer,blockSize,snap);
12 this.connectionLines = [];
13
14 this.connLine = new Konva.Line({
15 stroke: "rgba(245,37,37,0.85)",
16 dash: [2,3],
17 strokeWidth: 2,
18 lineCap: 'round',
19 lineJoin: 'miter',
20 opacity: 0.8
21 });
22 this.connLine.cache();
23
24 this.on("dragmove",() => {
25 this.connectionLines.forEach(lineWrapper => {
26 console.log("other",lineWrapper.otherShape)
27 let updatedPoints = [this.x(),this.y(),lineWrapper.otherShape.x(),lineWrapper.otherShape.y()]
28 lineWrapper.line.points(updatedPoints);
29 })
30 })
31 }
32
33 connect(node,draw = true){
34
35
36 if(!node.info.selectedPins.includes(this.info.name)){
37 console.log("vleze conn 2ds")
38 node.info.selectedPins.push(this.info.name);
39 }
40
41 if(!draw) return
42
43 const line = this.connLine.clone({
44 points: [this.x(),this.y(),node.x(),node.y()]
45 });
46
47 let lineWrapper = {
48 line: line,
49 otherShape: node
50 };
51
52 this.connectionLines.push(lineWrapper);
53
54 let lineWrapperSend = {
55 line: line,
56 otherShape: this
57 };
58
59 node.addLineReference(lineWrapperSend);
60
61 this.layer.add(lineWrapper.line);
62 }
63
64
65
66 addLineReference(line){
67 this.connectionLines.push(line);
68 }
69
70 removeLineWrapper(target){
71 this.connectionLines = this.connectionLines.filter(lineWrapper => lineWrapper.otherShape !== target);
72 }
73
74 removeConnection(shape){
75 this.info.selectedPins = this.info.selectedPins.filter(sl => sl !== shape.info.name)
76 }
77
78
79 removeConnectionLine(target){
80 this.connectionLines.forEach(lineWrapper => {
81 if (lineWrapper.otherShape === target){
82 lineWrapper.line.remove();
83 target.removeLineWrapper(this);
84 this.removeLineWrapper(target);
85 }
86 })
87 }
88
89
90 destroy() {
91 super.destroy();
92 this.connectionLines.forEach(lineWrapper => {
93 lineWrapper.line.remove()
94 lineWrapper.otherShape.removeLineWrapper(this);
95 });
96 }
97
98
99}
Note: See TracBrowser for help on using the repository browser.