PolygonDrawingTool draw on top of other Nodes

Hello,

I implemented the PolygonDrawingTool in my diagram and everything is working fine except for…

image

In this picture, you see a circle and a polygon. In order do get a polygon over the circle, I need to draw it on the canvas itself(clear space) and have to make sure not to press on any other nodes, as this will select the node instead of adding a point to the polygon. Is there some way to priorize placing a point for the polygon over every other mouse interaction in the diagram?

Best regards
Martin

Look at the definition of PolygonDrawingTool.canStart:

PolygonDrawingTool.prototype.canStart = function() {
  if (!this.isEnabled) return false;
  var diagram = this.diagram;
  if (diagram === null || diagram.isReadOnly || diagram.isModelReadOnly) return false;
  var model = diagram.model;
  if (model === null) return false;
  // require left button
  if (!diagram.firstInput.left) return false;
  // can't start when mouse-down on an existing Part
  var obj = diagram.findObjectAt(diagram.firstInput.documentPoint, null, null);
  return (obj === null);
};

You probably want to override (or just modify your copy of) the method so that it does not call Diagram.findObjectAt but just returns true. Or perhaps you have some additional prerequisites that should be included in the canStart predicate.

Thank you very much, I changed it so that it does not check for the object, but rather if “polygonDrawMode” is true, which is a boolean that can be triggered by clicking on a HTML button.