Class MapPointItem

All Implemented Interfaces:
IFeedbackProvider, IDrawable, EventListener
Direct Known Subclasses:
MapMilSymbolItem

public class MapPointItem extends AMapItem
A map-native point item whose location is stored as a geographic coordinate (longitude/latitude in radians) rather than a world-space point.

Use cases

Cities, airports, GPS waypoints, observation stations, or any location marker that should remain at the same geographic position when the projection changes.

Rendering

On each draw, the geographic location is projected through the active IMapProjection to device pixels. If the point is on the far side of the globe (non-finite projection result, e.g. orthographic back-hemisphere), the item is not drawn.

The item can display either an ImageIcon or a symbol from SymbolType, controlled by the style. Alignment for icon drawing follows SwingUtilities constants (LEFT/CENTER/RIGHT horizontally, TOP/CENTER/BOTTOM vertically).

Interaction

  • Drag — moves the geographic location by the screen-space delta converted through the map projection. Unlike the raw lon/lat delta used by multi-point items, this conversion is exact at all latitudes because both the start and current pixel positions are independently inverse-projected to geographic coordinates.
  • Resize / Rotate — not applicable to a point; silently ignored.

Focus

The AItem._focus field holds the geographic location directly (x = longitude, y = latitude in radians). AMapItem.getFocusPoint(edu.cnu.mdi.container.IContainer) handles the projection to device pixels.

  • Field Details

    • icon

      protected ImageIcon icon
      Optional icon to display instead of a symbol. When non-null, icon drawing takes precedence over the style's SymbolType.
  • Constructor Details

    • MapPointItem

      public MapPointItem(Layer layer)
      Creates an unplaced map point item. The focus is initialised to (Double.NaN, Double.NaN); call setFocus(java.awt.geom.Point2D.Double) before the item is drawn.
      Parameters:
      layer - the layer; must not be null
    • MapPointItem

      public MapPointItem(Layer layer, Point2D.Double location)
      Creates a map point item at the given geographic location.
      Parameters:
      layer - the layer; must not be null
      location - geographic location in radians (x = longitude, y = latitude)
    • MapPointItem

      public MapPointItem(Layer layer, Point2D.Double location, Object... keyVals)
      Creates a map point item at the given geographic location, with optional property key/value pairs.
      Parameters:
      layer - the layer; must not be null
      location - geographic location in radians
      keyVals - optional PropertyUtils key/value pairs
    • MapPointItem

      public MapPointItem(Layer layer, Point2D.Double location, ImageIcon icon)
      Creates a map point item that displays an icon.
      Parameters:
      layer - the layer; must not be null
      location - geographic location in radians
      icon - the icon to display; if null the style symbol is used
  • Method Details

    • drawItem

      public void drawItem(Graphics2D g2, IContainer container)
      Draws the point at its projected screen location.

      The item is not drawn if the focus is unplaced (NaN) or projects to a non-finite coordinate. Icon drawing takes priority over symbol drawing.

      Specified by:
      drawItem in class AItem
      Parameters:
      g2 - the graphics context
      container - the rendering container; must be a MapContainer
    • shouldDraw

      public boolean shouldDraw(Graphics2D g2, IContainer container)
      Return true if this item should be drawn on the current frame.

      This is a secondary visibility check beyond the simple AItem._visible flag. A typical implementation checks whether the item's screen bounds intersect the current clip rectangle.

      Returns false if the focus is unplaced or the projected bounds do not intersect the visible component area.

      Specified by:
      shouldDraw in class AItem
      Parameters:
      g2 - the graphics context (may be used to read clip bounds)
      container - the container being rendered
      Returns:
      true if AItem.drawItem(java.awt.Graphics2D, edu.cnu.mdi.container.IContainer) should be called
    • getBounds

      public Rectangle getBounds(IContainer container)
      Returns the device-space bounding rectangle for this point item.

      For icon items: the rectangle is positioned according to the alignment settings. For symbol items: a square of size style.getSymbolSize() centred on the focus point.

      Returns null if the focus is unplaced or off-map.

      Overrides:
      getBounds in class AItem
      Parameters:
      container - the rendering container
      Returns:
      bounding rectangle in device coordinates, or null
    • getWorldBounds

      public Rectangle2D.Double getWorldBounds()
      Return the world-coordinate bounding rectangle of this item.

      Returns a null world bounding rectangle — a geographic point has no extent in world space.

      Specified by:
      getWorldBounds in class AItem
      Returns:
      the world-coordinate bounding rectangle
    • 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._modification is null.

      Records the geographic start location so drag can compute an absolute delta from the snapshot rather than accumulating incremental moves.

      Overrides:
      startModification in class AItem
    • 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: converts the start and current mouse positions independently to geographic coordinates and moves the focus by the difference. This gives an exact result at all latitudes — no raw lon/lat approximation.

      RESIZE / ROTATE: silently ignored for a point item.

      Specified by:
      modify in class AItem
    • setFocus

      public void setFocus(Point2D.Double location)
      Set the world-coordinate focus of this item.

      Stores the geographic location directly, with NaN used to represent an unplaced item.

      Overrides:
      setFocus in class AItem
      Parameters:
      location - the new focus; may be null to clear
    • translateWorld

      public void translateWorld(double dx, double dy)
      Translate this item by (dx, dy) in world coordinates.

      Adds the lon/lat offset to the stored geographic location. A no-op if the focus is unplaced (NaN) or the delta is negligible.

      Specified by:
      translateWorld in class AItem
      Parameters:
      dx - the world-coordinate offset along the X axis
      dy - 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.

      Reports the geographic coordinates of this point when the cursor is near it.

      Specified by:
      getFeedbackStrings in interface IFeedbackProvider
      Overrides:
      getFeedbackStrings in class AItem
      Parameters:
      container - the container rendering this item
      pp - the current mouse position in screen coordinates
      wp - the corresponding world-coordinate position
      feedbackStrings - the list to add strings to
    • getAlignmentH

      public int getAlignmentH()
      Returns:
      horizontal alignment for icon drawing (SwingConstants.LEFT, SwingConstants.CENTER, or SwingConstants.RIGHT)
    • setAlignmentH

      public void setAlignmentH(int xAlignment)
      Parameters:
      xAlignment - horizontal alignment constant from SwingUtilities
    • getAlignmentV

      public int getAlignmentV()
      Returns:
      vertical alignment for icon drawing (SwingConstants.TOP, SwingConstants.CENTER, or SwingConstants.BOTTOM)
    • setAlignmentV

      public void setAlignmentV(int yAlignment)
      Parameters:
      yAlignment - vertical alignment constant from SwingUtilities