Class MapPolygonItem

All Implemented Interfaces:
IFeedbackProvider, IDrawable, EventListener

public class MapPolygonItem extends AMapMultiPointItem
A map-native closed spherical polygon defined by an ordered array of geographic vertices, with every edge (including the closing edge from the last vertex back to the first) rendered as a great-circle arc.

Use cases

User-drawn region boundaries, search areas, territorial outlines, or any closed shape whose vertices must remain geographically pinned when the projection changes.

Drawing model — closed polyline, not Path2D.closePath()

All N edges (including the closing edge vertex[N-1] → vertex[0]) are sampled as great-circle arcs by passing a length-(N+1) vertex array (vertex[0] duplicated at the end) to MapGraphics.buildProjectedPolyline(edu.cnu.mdi.mapping.container.MapContainer, java.awt.geom.Point2D.Double[]). This means:

Hit-testing

Because seam splitting produces multiple disconnected sub-paths, Java2D's Path2D.contains(double, double) cannot reliably test interior containment for the full polygon. Instead, a spherical ray-casting test is applied directly to the geographic AMapMultiPointItem._latLons array, which is both projection-independent and exact. The test counts how many great-circle edges the meridian from the test point north to the pole crosses; an odd count means the point is inside.

Interaction

  • Drag — moves all vertices by the geographic delta of the mouse.
  • Resize — moves the grabbed handle vertex to the cursor.
  • Rotate — not supported (see AMapMultiPointItem).
  • Constructor Details

    • MapPolygonItem

      public MapPolygonItem(Layer layer, Point2D.Double[] latLons)
      Creates a map-native spherical polygon.
      Parameters:
      layer - the layer; must not be null
      latLons - geographic vertices in radians (x = longitude, y = latitude); must not be null, length ≥ 3
      Throws:
      IllegalArgumentException - if latLons has fewer than 3 points
    • MapPolygonItem

      public MapPolygonItem(Layer layer, Point2D.Double[] latLons, Object... keyVals)
      Creates a map-native spherical polygon with optional property key/value pairs.
      Parameters:
      layer - the layer; must not be null
      latLons - geographic vertices in radians; must not be null, length ≥ 3
      keyVals - optional PropertyUtils key/value pairs
      Throws:
      IllegalArgumentException - if latLons has fewer than 3 points
  • Method Details