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

4

1 回答 1

1

概括地说,

  • 构造一个MapPolygon如图所示的here

  • 使用自定义检测鼠标点击DefaultMapController如下所示。

  • 在中,通过遍历返回的 by来mouseClicked()构造a 使用该方法将每个转换为.java.awt.PolygonList<ICoordinate>MapPolygon::getPointsJMapViewer::getPositionICoordinatePoint

  • 用于Polygon::contains判断鼠标坐标是否在 this 内Polygon

图片

于 2016-05-24T22:39:38.643 回答