1

I'm making a program in Java that displays a map using JMapViewer and draws a static polygon. When the user clicks in the map the program say "the point where you have clicked is in polygon" or "not in polygon". How I can do for calculate when the point is in polygon or not? Is there any ready method/class to do that?

Thank you, Luca

Luca
  • 13
  • 4

1 Answers1

1

In outline,

  • Construct a MapPolygon as shown here.

  • Detect mouse clicks using a custom DefaultMapController as shown here.

  • In mouseClicked(), construct a java.awt.Polygon by iterating through the List<ICoordinate> returned by MapPolygon::getPoints; use the JMapViewer::getPosition method to convert each ICoordinate to a Point.

  • Use Polygon::contains to determine whether the mouse coordinates are inside this Polygon.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045