title: JavaFX - Clickable line on canvas
body: <p>I have this JavaFX application that lets you plot locations on a map and connect them.</p>
  
  <p><img src="https://i.stack.imgur.com/0JaCE.png" alt="enter image description here"></p>
  
  <p>I do this by drawing a map as a background image on a canvas and then drawing circles and lines on it. I have made the circles clickable by using the contains() method in the Circle class, but how can I make the lines clickable?</p>
  
  <p>edit: Look at this example where I just draw a line and set an event handler:</p>
  
  <pre><code>    Canvas canvas = new Canvas();
      GraphicsContext gc = canvas.getGraphicsContext2D();
  
      gc.setLineWidth(5);
      gc.strokeLine(100, 100, 200, 200);
  
      canvas.setOnMouseClicked(event -&gt; {
          double x = event.getX(), y = event.getY();
      });
  </code></pre>
  
  <p>My question is simply this: how do I finish the event handler so that it detects if the click is inside the line I just drew?</p>