Class ProjectionFactory

java.lang.Object
edu.cnu.mdi.mapping.projection.ProjectionFactory

public final class ProjectionFactory extends Object
Factory for creating IMapProjection instances from EProjection identifiers.

Purpose

Centralizing projection construction here means that calling code (e.g. MapView2D) never depends directly on concrete classes such as MercatorProjection or OrthographicProjection. Adding a new projection requires only: a new EProjection constant, a new case in create(EProjection, MapTheme, Point2D.Double), and the concrete implementation class itself.

Theme guarantee

Every projection returned by this factory has its MapTheme set before the instance is returned. Callers can therefore call drawing methods immediately without risk of NullPointerException.

Typical usage


 // Default center
 IMapProjection mercator = ProjectionFactory.create(EProjection.MERCATOR, MapTheme.light());

 // Explicit center (orthographic centred on the USA)
 Point2D.Double center = new Point2D.Double(Math.toRadians(-100.0), Math.toRadians(40.0));
 IMapProjection ortho  = ProjectionFactory.create(EProjection.ORTHOGRAPHIC, MapTheme.dark(), center);
 

This class is not instantiable.

  • Method Details

    • create

      public static IMapProjection create(EProjection type, MapTheme theme)
      Creates a projection with the given type and theme, using each projection's built-in default center.

      This is a convenience overload of create(EProjection, MapTheme, Point2D.Double) that passes null for the center.

      Parameters:
      type - projection type; must not be null
      theme - map theme; must not be null
      Returns:
      a fully initialized IMapProjection with the theme set
      Throws:
      IllegalArgumentException - if type or theme is null, or type is not yet handled by this factory
    • create

      public static IMapProjection create(EProjection type, MapTheme theme, Point2D.Double center)
      Creates a projection with the given type, theme, and optional center.

      Center conventions

      • The center parameter is a Point2D.Double with x = λ₀ (longitude, radians) and y = φ₀ (latitude, radians).
      • If center is null a projection-specific default is used (see individual cases below).
      • Mercator, Mollweide, and Equal Earth use only the longitude component of center; the latitude component is ignored.

      Default centers

      • MERCATOR — defaults to a central longitude of -70°.
      • ORTHOGRAPHIC — defaults to (λ = 0°, φ = 50°), a balanced mid-latitude northern hemisphere view.
      • MOLLWEIDE — defaults to a central longitude of -70°.
      • EQUAL_EARTH — defaults to a central longitude of -70°.
      • LAMBERT_EQUAL_AREA — defaults to (λ = 0°, φ = 0°), i.e., centered on the intersection of the equator and prime meridian.
      Parameters:
      type - projection type; must not be null
      theme - map theme; must not be null
      center - optional projection center in radians (x=λ, y=φ); null uses the projection's built-in default
      Returns:
      a fully initialized IMapProjection with the theme set
      Throws:
      IllegalArgumentException - if type or theme is null, or type is not yet handled by this factory