Search code examples
javagoogle-mapsjmapviewer

JMapViewer draw a polygon that will look like arrow


I want to create an arrow (---->) on my map, connecting 2 given coordinates.

By now I used the draw line using polygon implementation suggested here and here

Is there a way to acheieve it?

Thanks, Ozrad


Solution

  • Generally yes, you could use the concepts demonstrated in Java make a directed line and make it move and mouse motion listener only in one direction for some ideas.

    These both use Path2D to generate the shape and calculate the angle between two points to orientate the shape.

    Your requirement is actually a little easier, as you will already have a start and end point, so it should be possible to either calculate the length of the line or angle of the arrow head, depending on which is simpler for you (I'd be calculating the length of the line between the points and rotating it, but that's just me)