Closed mustaphatg closed 2 years ago
Hi @mustaphatg, thank you for the comment. Sorry, my English is poor. What does the "connected twice" mean? And what is the "ledger line"?
Sorry, it was a typo error. What I wanted was a way to prevent two LeaderLine on a single element.
You can access to joined elements via start
/end
options (properties).
For example:
if (lineA.start === lineB.start) {
console.log('This element was joined to line-A and line-B.');
}
I do not have reference to the object.
I am creating a matching app for kids where they match animals to their habitat together, by using leader line.
am using line.position() to update the position due to the mouse event am using to draw the leader line. So no reference to the object is saved. There are numerous element to match so the elements are not known beforehand. Its dynamic and its according to the user action. Is there a way detect that a leader line is already pointing to an element.
In normal computer programs, instances are saved to variables. And you can do that very easy.
const lineA = new LeaderLine(...);
This is best solution and it is standard program code. Also, dropping the instances is very strange and it may make another problems (e.g. memory leaking, slow action, etc.). Do you have any special reason why you drop the instances?
If you really want to check the connection without the instances, you can use class
of DOM.
if (!element.classList.contains('connected')) {
line.start = element;
element.classList.add('connected')
}
Of course this is not good way.
Thanks so much. I really appreciate it.
:smile:
HI @anseki , you built such an awesome tool and I really appreciate you.
Any idea on how I can prevent an element from being connected twice. Am building a matching question with javascript and I will like to detect if an element has a ledger line connected to it ,so I prevent double connection.
Thanks.