I have a class that extends the GoJS DraggingTool class. In that class I have a canStart method, in which I call super.canStart. If super.canStart yields a value of true then I need to get the object that is being dragged in order to figure out if the object is a group and to make sure that I am trying to drag from the group header not someplace else in the group.
I am using diagram.findObjectAt(this.diagram.lastInput.documentPoint)
to find the object that is being dragged. For some reason sometimes the object comes back undefined. I don’t know why it is coming back undefined, the left click should always have a documentPoint that is the dragged element. This is happening when trying to drag one object.
Have there been problems with the mouse click not having the correct documentPoint?
Here is my code -
/**
* Check if the object at the event location should start being dragged
* @returns boolean
*/
canStart(): boolean {
const canStartDrag = super.canStart();
if (!canStartDrag) return false;
const obj = this.diagram.findObjectAt(this.diagram.lastInput.documentPoint);
if (!obj) return false;
const { part, panel } = obj;
// Only allow dragging a group if the header is the panel that's selected
if (isGroup(part) && !isGroupHeader(panel)) {
return false;
}
return canStartDrag;
}```