Class MapPolygonItem
- All Implemented Interfaces:
IFeedbackProvider,IDrawable,EventListener
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:
- Every edge is a proper great-circle arc — no straight chord appears for the closing edge.
Path2D.closePath()is never called, so seam-split sub-paths are not incorrectly filled with a straight closing line.- The shape is drawn via
MapGraphics.drawMapPolyline(Graphics2D, MapContainer, Point2D.Double[], edu.cnu.mdi.graphics.style.IStyled)with fill handled separately as a pre-pass.
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).
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.cnu.mdi.mapping.item.AMapMultiPointItem
AMapMultiPointItem.MultiPointStartState -
Field Summary
Fields inherited from class edu.cnu.mdi.mapping.item.AMapMultiPointItem
_latLons, _projectedShapeFields inherited from class edu.cnu.mdi.item.AItem
_connectable, _deletable, _dirty, _displayName, _doubleClickable, _draggable, _enabled, _focus, _FOCUSFILL, _lastDrawnPolygon, _layer, _line, _locked, _modification, _path, _popupMenu, _resizable, _resizePolicy, _rightClickable, _rotatable, _selectable, _selected, _style, _styleEditable, _visible, rotateIcon, RPSIZE, RPSIZE2, SPSIZE, SPSIZE2 -
Constructor Summary
ConstructorsConstructorDescriptionMapPolygonItem(Layer layer, Point2D.Double[] latLons) Creates a map-native spherical polygon.MapPolygonItem(Layer layer, Point2D.Double[] latLons, Object... keyVals) Creates a map-native spherical polygon with optional property key/value pairs. -
Method Summary
Modifier and TypeMethodDescriptionprotected MapGraphics.ProjectedMapShapeBuild the projected shape from the current vertices.protected booleancontainsPoint(MapGraphics.ProjectedMapShape shape, Point screenPoint) Tests whether a screen point hits the projected shape.voiddrawItem(Graphics2D g2, IContainer container) Draws the closed spherical polygon.Methods inherited from class edu.cnu.mdi.mapping.item.AMapMultiPointItem
contains, copyVertices, ensureProjectedShape, getBounds, getFeedbackStrings, getLatLons, getSelectionPoints, getVertexCount, getWorldBounds, localToLatLon, modify, prepareForRemoval, projectLatLon, setDirty, setLatLons, shouldDraw, startModification, translateWorld, updateFocusMethods inherited from class edu.cnu.mdi.mapping.item.AMapItem
getFocusPointMethods inherited from class edu.cnu.mdi.item.AItem
acceptModification, applyGeometryProperties, applyProperties, applyStyleProperties, createPopupMenu, doubleClicked, draw, drawSelections, enclosed, equals, focusFill, geometryChanged, getAzimuth, getContainer, getDisplayName, getFocus, getItemModification, getLastDrawnPolygon, getLayer, getLine, getPath, getPopupMenu, getResizePolicy, getRotatePoint, getStyle, getStyleSafe, getView, hashCode, inASelectRect, inRotatePoint, inSelectPoint, isConnectable, isDeletable, isDirty, isDoubleClickable, isDraggable, isEnabled, isLocked, isResizable, isRightClickable, isRotatable, isSelectable, isSelected, isStyleEditable, isTrackable, isVisible, modificationRejected, prepareForPopup, setAzimuth, setConnectable, setDeletable, setDisplayName, setDoubleClickable, setDraggable, setEnabled, setFillFocus, setFocus, setLocked, setModification, setResizable, setResizePolicy, setRightClickable, setRotatable, setSelectable, setSelected, setStyle, setStyleEditable, setVisible, stopModification, translateLocal
-
Constructor Details
-
MapPolygonItem
Creates a map-native spherical polygon.- Parameters:
layer- the layer; must not benulllatLons- geographic vertices in radians (x = longitude, y = latitude); must not benull, length ≥ 3- Throws:
IllegalArgumentException- iflatLonshas fewer than 3 points
-
MapPolygonItem
Creates a map-native spherical polygon with optional property key/value pairs.- Parameters:
layer- the layer; must not benulllatLons- geographic vertices in radians; must not benull, length ≥ 3keyVals- optionalPropertyUtilskey/value pairs- Throws:
IllegalArgumentException- iflatLonshas fewer than 3 points
-
-
Method Details
-
drawItem
Draws the closed spherical polygon.Fill (if any) is painted first using a true projected polygon shape (correct interior semantics even across seam splits), then the outline is drawn as a closed polyline of great-circle arcs so that the closing edge is a genuine arc rather than a straight chord. A separate outline shape is cached in
_projectedShapefor bounds/edge hit-testing.- Specified by:
drawItemin classAItem- Parameters:
g2- the graphics contextcontainer- the rendering container; must be aMapContainer
-
containsPoint
Tests whether a screen point hits the projected shape.Default: 6-pixel proximity (correct for open polylines).
MapPolygonItemoverrides to also test interior containment.Interior containment is tested using a spherical ray-casting algorithm on the geographic
AMapMultiPointItem._latLonsarray, so the result is correct regardless of how the projection splits the boundary into sub-paths. Outline proximity (6-pixel tolerance) is tested as a fallback so the boundary is always clickable even for unfilled polygons.- Overrides:
containsPointin classAMapMultiPointItem- Parameters:
shape- projected shape (may benull)screenPoint- device-space test point- Returns:
trueif the point hits the shape
-
buildShape
Build the projected shape from the current vertices.Use
MapGraphics.buildProjectedPolyline(edu.cnu.mdi.mapping.container.MapContainer, java.awt.geom.Point2D.Double[])for open items,MapGraphics.buildProjectedPolygon(edu.cnu.mdi.mapping.container.MapContainer, java.awt.geom.Point2D.Double[])for closed items.Builds an open polyline of the N+1 closed-polygon vertices (vertex[0] duplicated at the end) so that all edges, including the closing edge, are great-circle arcs.
Path2D.closePath()is not used.- Specified by:
buildShapein classAMapMultiPointItem- Parameters:
mc- the owning map container- Returns:
- projected shape; never
null
-