Class MapfishMapContext

java.lang.Object
org.mapfish.print.attribute.map.MapfishMapContext

public final class MapfishMapContext extends Object
Utility class that adjusts the bounds and the map size in case a rotation is set. Also, it provides an AffineTransform to render the layer graphics.
  • Constructor Details

    • MapfishMapContext

      public MapfishMapContext(MapBounds bounds, Dimension mapSize, double dpi, Boolean forceLongitudeFirst, boolean dpiSensitiveStyle)
      Constructor.
      Parameters:
      bounds - the map bounds
      mapSize - the map size
      dpi - the dpi of the printed map
      forceLongitudeFirst - If true then force longitude coordinates as the first coordinate.
      dpiSensitiveStyle - Scale the vector styles?
    • MapfishMapContext

      public MapfishMapContext(MapBounds bounds, Dimension mapSize, double rotation, double dpi, Boolean forceLongitudeFirst, boolean dpiSensitiveStyle)
      Constructor.
      Parameters:
      bounds - the map bounds
      mapSize - the map size
      rotation - the rotation
      dpi - the dpi of the printed map
      forceLongitudeFirst - If true then force longitude coordinates as the first coordinate.
      dpiSensitiveStyle - Scale the vector styles?
    • MapfishMapContext

      public MapfishMapContext(MapfishMapContext parent, MapBounds bounds, Dimension mapSize, double dpi, Boolean forceLongitudeFirst, boolean dpiSensitiveStyle)
      Constructor.
      Parameters:
      parent - the context that this context is derived from
      bounds - the map bounds
      mapSize - the map size
      dpi - the dpi of the printed map
      forceLongitudeFirst - If true then force longitude coordinates as the first coordinate.
      dpiSensitiveStyle - Scale the vector styles?
    • MapfishMapContext

      public MapfishMapContext(MapfishMapContext parent, MapBounds bounds, Dimension mapSize, double rotation, double dpi, Boolean forceLongitudeFirst, boolean dpiSensitiveStyle)
      Constructor.
      Parameters:
      parent - the context that this context is derived from
      bounds - the map bounds
      mapSize - the map size
      rotation - the rotation
      dpi - the dpi of the printed map
      forceLongitudeFirst - If true then force longitude coordinates as the first coordinate.
      dpiSensitiveStyle - Scale the vector styles?
  • Method Details

    • rectangleDoubleToDimension

      public static Dimension rectangleDoubleToDimension(Rectangle2D.Double rectangle)
      Round the size of a rectangle with double values.
      Parameters:
      rectangle - The rectangle.
    • getRotation

      public double getRotation()
      Returns:
      The rotation in radians.
    • getRotationDegree

      public double getRotationDegree()
      Returns:
      The rotation in degree.
    • getBounds

      public MapBounds getBounds()
    • getRotatedBounds

      public MapBounds getRotatedBounds()
      Return the map bounds rotated with the set rotation.
      Returns:
      Rotated bounds.
    • getRotatedBounds

      public MapBounds getRotatedBounds(Rectangle2D.Double paintAreaPrecise, Rectangle paintArea)
      Return the map bounds rotated with the set rotation. The bounds are adapted to rounding changes of the size of the paint area.
      Parameters:
      paintAreaPrecise - The exact size of the paint area.
      paintArea - The rounded size of the paint area.
      Returns:
      Rotated bounds.
    • getRotatedBoundsAdjustedForPreciseRotatedMapSize

      public MapBounds getRotatedBoundsAdjustedForPreciseRotatedMapSize()
      Return the map bounds rotated with the set rotation. The bounds are adapted to rounding changes of the size of the set paint area.
      Returns:
      Rotated bounds.
    • getMapSize

      public Dimension getMapSize()
    • getScale

      public Scale getScale()
    • getGeodeticScaleDenominator

      public double getGeodeticScaleDenominator()
    • getRoundedScaleDenominator

      public double getRoundedScaleDenominator()
      Get a nicely rounded scale for to use for displaying the map scale.

      One of the output parameters of the CreateMapProcessor is 'mapContext' which can be accessed in a template. If the scale is required in the template then it can be accessed via: $P{mapContext}.getRoundedScaleDenominator()

    • getRoundedScaleDenominator

      public double getRoundedScaleDenominator(boolean geodetic)
      Get a nicely rounded scale for to use for displaying the map scale.

      One of the output parameters of the CreateMapProcessor is 'mapContext' which can be accessed in a template. If the scale is required in the template then it can be accessed via: $P{mapContext}.getRoundedScaleDenominator()

      Parameters:
      geodetic - Get geodetic scale
    • getCenterX

      public double getCenterX()
      Utility method use to display the center in the report.
      Returns:
      the center X
    • getCenterY

      public double getCenterY()
      Utility method use to display the center in the report.
      Returns:
      the center Y
    • getRotatedMapSize

      public Dimension getRotatedMapSize()
      Returns:
      The new map size taking the rotation into account.
    • getRotatedMapSizePrecise

      public Rectangle2D.Double getRotatedMapSizePrecise()
      Returns:
      The new map size taking the rotation into account.
    • getTransform

      public AffineTransform getTransform()
      Returns an AffineTransform taking the rotation into account.
      Returns:
      an affine transformation
    • getDPI

      public double getDPI()
    • getPaintArea

      public Rectangle getPaintArea()
    • isForceLongitudeFirst

      @Nonnull public Boolean isForceLongitudeFirst()
    • isDpiSensitiveStyle

      public Boolean isDpiSensitiveStyle()
    • toReferencedEnvelope

      public org.geotools.geometry.jts.ReferencedEnvelope toReferencedEnvelope()
      Get the bounds as a referenced envelope.
      Returns:
      bounds as a referenced envelope.
    • getParentContext

      @Nullable public MapfishMapContext getParentContext()
      Get the parent context if there is one. A parent context is the context that this context is derived from. Normally there are some parameters that have been changed for this context from the parent. An example of when there might be a parent is when the child has been rotated and has a bounds to envelope the original bounds. It can be useful in some cases to be able to access the parent (and original bounds).
      Returns:
      the parent context or null if there is no parent.
    • getRootContext

      @Nonnull public MapfishMapContext getRootContext()
      Return the root context which is this context or the context found by recursively calling parent.getRootContext().