Class AMapMultiPointItem
- All Implemented Interfaces:
IFeedbackProvider,IDrawable,EventListener
- Direct Known Subclasses:
MapPolygonItem,MapPolylineItem
Shared behaviour
Provides vertex storage, modification lifecycle (drag / vertex resize),
hit-testing, bounds, selection handles, projection caching, and feedback.
Subclasses (MapPolylineItem, MapPolygonItem) supply only
AItem.drawItem(java.awt.Graphics2D, edu.cnu.mdi.container.IContainer) and the buildShape(edu.cnu.mdi.mapping.container.MapContainer) factory method.
Vertex indexing
Vertices are in _latLons in construction order. For a closed polygon
the path is implicitly closed — no duplicate of vertex 0 is stored.
Drag
Raw lon/lat delta from drag-start to current cursor is applied to all vertices
from their snapshot positions (no incremental accumulation). Same high-latitude
caveat as MapLineItem: at high latitudes a purely northward drag may
introduce a small longitudinal error.
Resize
Moves the vertex at ItemModification.getSelectIndex()
to the current geographic cursor location.
Rotation
Rotation is silently ignored for arbitrary multi-vertex geographic shapes
because there is no single unambiguous spherical rotation centre or
"bearing change" for non-line shapes. Subclasses with a well-defined centre
(e.g. a geodesic circle) may override modify() to add it.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classImmutable snapshot of all vertex positions at drag-start. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Point2D.Double[]Geographic vertices in radians (x = longitude, y = latitude).protected MapGraphics.ProjectedMapShapeCached projected shape.Fields 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
ConstructorsModifierConstructorDescriptionprotectedAMapMultiPointItem(Layer layer, Point2D.Double[] latLons, Object... keyVals) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract MapGraphics.ProjectedMapShapeBuild the projected shape from the current vertices.booleancontains(IContainer container, Point screenPoint) Test whether this item, as rendered, contains the given screen point.protected booleancontainsPoint(MapGraphics.ProjectedMapShape shape, Point screenPoint) Tests whether a screen point hits the projected shape.protected static Point2D.Double[]copyVertices(Point2D.Double[] src) Deep defensive copy of a vertex array.protected voidensureProjectedShape(IContainer container) Rebuilds_projectedShapeif null.getBounds(IContainer container) Return the screen-coordinate bounding rectangle of this item.voidgetFeedbackStrings(IContainer container, Point pp, Point2D.Double wp, List<String> feedbackStrings) Populate the feedback string list with information about this item.Point[]getSelectionPoints(IContainer container) Returns all vertices projected to device-space handles, omitting any that are off-map (non-finite projection result).intReturn the world-coordinate bounding rectangle of this item.protected Point2D.DoublelocalToLatLon(MapContainer mc, Point p) Converts a device-space point to geographic lon/lat in radians.voidmodify()Update this item's geometry in response to a mouse movement during an active modification.voidPrepare this item for removal from its layer.protected PointprojectLatLon(MapContainer mc, Point2D.Double latLon) Projects a geographic point to device pixels.voidsetDirty(boolean dirty) Set the dirty flag.voidsetLatLons(Point2D.Double[] latLons) Replace all vertices and mark dirty.booleanshouldDraw(Graphics2D g2, IContainer container) Returntrueif this item should be drawn on the current frame.voidClassify and begin a drag, resize, or rotate modification.voidtranslateWorld(double dx, double dy) Translate this item by(dx, dy)in world coordinates.protected voidRecomputes the focus as the geographic mean of all vertices.Methods 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, drawItem, 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
-
Field Details
-
_latLons
Geographic vertices in radians (x = longitude, y = latitude). Nevernullafter construction; length ≥ 2. -
_projectedShape
Cached projected shape. Cleared bysetDirty(boolean)and rebuilt lazily byensureProjectedShape(edu.cnu.mdi.container.IContainer).
-
-
Constructor Details
-
AMapMultiPointItem
- Parameters:
layer- the layer; must not benulllatLons- geographic vertices in radians; must not benull, length ≥ 2keyVals- optionalPropertyUtilskey/value pairs- Throws:
IllegalArgumentException- iflatLonshas fewer than 2 points
-
-
Method Details
-
getLatLons
- Returns:
- a defensive copy of the vertex array; never
null
-
setLatLons
Replace all vertices and mark dirty.- Parameters:
latLons- new vertices; must not benull, length ≥ 2
-
getVertexCount
public int getVertexCount()- Returns:
- number of vertices (≥ 2)
-
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.- Parameters:
mc- the owning map container- Returns:
- projected shape; never
null
-
shouldDraw
Description copied from class:AItemReturntrueif this item should be drawn on the current frame.This is a secondary visibility check beyond the simple
AItem._visibleflag. A typical implementation checks whether the item's screen bounds intersect the current clip rectangle.- Specified by:
shouldDrawin classAItem- Parameters:
g2- the graphics context (may be used to read clip bounds)container- the container being rendered- Returns:
trueifAItem.drawItem(java.awt.Graphics2D, edu.cnu.mdi.container.IContainer)should be called
-
getBounds
Description copied from class:AItemReturn the screen-coordinate bounding rectangle of this item.The default implementation returns
null. Subclasses should override to return a meaningful bounding box used for hit-testing and rubber-band selection. -
contains
Description copied from class:AItemTest whether this item, as rendered, contains the given screen point.Priority order:
AItem._lastDrawnPolygon— exact hit test.AItem.getBounds(IContainer)— axis-aligned bounding rectangle.AItem.inASelectRect(edu.cnu.mdi.container.IContainer, java.awt.Point)— selection/rotation handle rectangles.
-
containsPoint
Tests whether a screen point hits the projected shape.Default: 6-pixel proximity (correct for open polylines).
MapPolygonItemoverrides to also test interior containment.- Parameters:
shape- projected shape (may benull)screenPoint- device-space test point- Returns:
trueif the point hits the shape
-
getSelectionPoints
Returns all vertices projected to device-space handles, omitting any that are off-map (non-finite projection result).- Overrides:
getSelectionPointsin classAItem- Parameters:
container- the container rendering this item- Returns:
- handle positions, or
nullif none are visible
-
startModification
public void startModification()Classify and begin a drag, resize, or rotate modification.Priority: rotate (if start point is in rotation handle) → resize (if start point is in a selection handle) → drag (otherwise).
This method is a no-op if
AItem._modificationisnull.Stores a
AMapMultiPointItem.MultiPointStartStatesnapshot of all vertex positions in the modification's user-object slot.- Overrides:
startModificationin classAItem
-
modify
public void modify()Update this item's geometry in response to a mouse movement during an active modification.Called repeatedly while the user is dragging, resizing, or rotating. The current mouse position is available through
AItem._modification.DRAG: shifts all vertices by the lon/lat delta from the start snapshot. RESIZE: moves the selected vertex to the cursor. ROTATE: silently ignored.
-
getWorldBounds
Return the world-coordinate bounding rectangle of this item.Returns the axis-aligned lon/lat bounding box of the vertex set. May under-estimate arcs that bulge beyond the chord; use
getBounds(IContainer)for exact pixel bounds.- Specified by:
getWorldBoundsin classAItem- Returns:
- the world-coordinate bounding rectangle
-
translateWorld
public void translateWorld(double dx, double dy) Translate this item by(dx, dy)in world coordinates.Applies raw lon/lat offsets to all vertices. See
MapLineItemfor the high-latitude caveat.- Specified by:
translateWorldin classAItem- Parameters:
dx- the world-coordinate offset along the X axisdy- the world-coordinate offset along the Y axis
-
getFeedbackStrings
public void getFeedbackStrings(IContainer container, Point pp, Point2D.Double wp, List<String> feedbackStrings) Populate the feedback string list with information about this item. The default implementation is a no-op.Adds vertex count and total great-circle perimeter when the cursor is over the item.
- Specified by:
getFeedbackStringsin interfaceIFeedbackProvider- Overrides:
getFeedbackStringsin classAItem- Parameters:
container- the container rendering this itempp- the current mouse position in screen coordinateswp- the corresponding world-coordinate positionfeedbackStrings- the list to add strings to
-
updateFocus
protected void updateFocus()Recomputes the focus as the geographic mean of all vertices.- Overrides:
updateFocusin classAMapItem
-
setDirty
public void setDirty(boolean dirty) Description copied from class:AItemSet the dirty flag. Setting totruealso clearsAItem._lastDrawnPolygon. -
prepareForRemoval
public void prepareForRemoval()Description copied from class:AItemPrepare this item for removal from its layer.Performs two operations:
- Feedback de-registration. The item unregisters itself from the
container's
FeedbackControlso that it is no longer polled after removal. The container reference is captured beforeAItem._layeris nulled. - Reference nulling. Heavyweight references are set to
nullto assist garbage collection and to cause fast, obviousNullPointerExceptions if the item is used after removal.
Subclasses holding additional heavyweight references should override this method, null those fields, and call
super.prepareForRemoval()either first or last.- Specified by:
prepareForRemovalin interfaceIDrawable- Overrides:
prepareForRemovalin classAItem
- Feedback de-registration. The item unregisters itself from the
container's
-
ensureProjectedShape
Rebuilds_projectedShapeif null. -
projectLatLon
Projects a geographic point to device pixels.- Returns:
- device-space point, or
nullif off-map
-
localToLatLon
Converts a device-space point to geographic lon/lat in radians.- Returns:
- geographic point, or
nullif either argument isnull
-
copyVertices
Deep defensive copy of a vertex array.
-