There is a picture "map" - programmatically traced the road. If you click on the road, then an event will occur. Question: how do i implement this?

How can you programmatically create a line that will respond to events? Is there any object with similar properties?


Found the answer - Obedient lines

    1 answer 1

    In general, the solution is.

    Create a class or record for storing the lines of roads in a convenient form. Sort of:

    type TRoad = record From : TPoint; To: TPoint; end; 

    Store somewhere your roads (array, list, etc.). Draw lines on the canvas. By clicking on the canvas, take the coordinates of the point and determine whether they belong to one of the lines.

    If you belong, you process it as you need (for example, change the color of the line; to do this, add color to the TRoad).

    Well, and then the optimization of drawing and processing the whole of this business, cutting off invisible lines, perhaps combining lines into a graph, searching for paths. In general, it depends on the task you have there).

    You may need some knowledge of algebra, geometry and computer graphics. Well, Algolist to help you.

    • But how will the line react, for example, to onClick - Dima Faleleev
    • 2
      The component will react to OnClick where the drawing will occur, but in this handler it is already necessary to determine whether there is a line under it and, if there is, to call the user event handler, by the current position of the cursor. - KiTE
    • @KiTE, truly so. - Nofate