Class MapfishMapContext


  • public final class MapfishMapContext
    extends java.lang.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 Detail

      • MapfishMapContext

        public MapfishMapContext​(MapBounds bounds,
                                 java.awt.Dimension mapSize,
                                 double dpi,
                                 java.lang.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,
                                 java.awt.Dimension mapSize,
                                 double rotation,
                                 double dpi,
                                 java.lang.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,
                                 java.awt.Dimension mapSize,
                                 double dpi,
                                 java.lang.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,
                                 java.awt.Dimension mapSize,
                                 double rotation,
                                 double dpi,
                                 java.lang.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 Detail

      • rectangleDoubleToDimension

        public static java.awt.Dimension rectangleDoubleToDimension​(java.awt.geom.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.
      • getRotatedBounds

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

        public MapBounds getRotatedBounds​(java.awt.geom.Rectangle2D.Double paintAreaPrecise,
                                          java.awt.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 java.awt.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}.getRoundedScaleDenominato()

        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 java.awt.Dimension getRotatedMapSize()
        Returns:
        The new map size taking the rotation into account.
      • getRotatedMapSizePrecise

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

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

        public double getDPI()
      • getPaintArea

        public java.awt.Rectangle getPaintArea()
      • isForceLongitudeFirst

        @Nullable
        public java.lang.Boolean isForceLongitudeFirst()
      • isDpiSensitiveStyle

        public java.lang.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().