Package hec.map

Class MapScale

java.lang.Object
hec.map.MapScale
Direct Known Subclasses:
TransformMapScale

public class MapScale extends Object
Manages map scaling parameters and performs coordinate transforms.

See Also:
  • Field Details

    • _regionExtents

      protected WorldRect _regionExtents
      world coordinate bounding rectangle of the entire mapped region
    • _origin

      protected WorldPt _origin
      center of view port in world coordinates
    • _zoom

      protected double _zoom
      1/fraction of mapped region visible in viewport
    • _viewRect

      protected LocalRect _viewRect
      size of the viewport in local (device) coordinates
    • _aniso

      protected double _aniso
      ratio of y to x direction scaling
    • _worldRect

      protected WorldRect _worldRect
      world coordinates of the corners of the viewport
    • _xscale

      protected double _xscale
      world to local scale factor in x direction
    • _yscale

      protected double _yscale
      world to local scale factor in y direction
    • _defaultRegionExtents

      protected boolean _defaultRegionExtents
      Flag for whether Extents are currently defaults.
  • Constructor Details

    • MapScale

      public MapScale()
      Create a new MapScale object
    • MapScale

      public MapScale(MapScale scl)
      Create a new MapScale object

      Parameters:
      scl - MapScale to initialize from
  • Method Details

    • getXScale

      public double getXScale()
    • getYScale

      public double getYScale()
    • getAvgW2LScale

      public double getAvgW2LScale()
      returns the average world to local scaling factor

      Returns:
      The average scaling factor
    • contains

      public boolean contains(WorldPt wpt)
      determines if the given point in world coordinates is in the current viewing area

      Parameters:
      wpt - a point in world coordinates

      Returns:
      true if the current viewing area contains wpt
    • contains

      public boolean contains(LocalPt pt)
      determines if the given point in local coordinates is in the current viewing area

      Parameters:
      pt - a point in local coordinates

      Returns:
      true if the current viewing area contains pt
    • showAll

      public void showAll()
      zoom out to the world coordinates
    • setRegionExtents

      public void setRegionExtents(WorldRect rc)
      Set the map region extents

      Parameters:
      rc - The new RegionExtents value
    • growRegionExtents

      public void growRegionExtents(WorldRect rc)
      grow the map reqion extents to rc

      Parameters:
      rc - extents to grow the map region to
    • setDefaultRegionExtents

      public void setDefaultRegionExtents(boolean onOff)
      Sets the DefaultRegionExtents attribute of the MapScale object

      Parameters:
      onOff - The new DefaultRegionExtents value
    • isDefaultRegionExtents

      public boolean isDefaultRegionExtents()
      Returns the value of the default region extents flag.

      Returns:
    • getRegionExtents

      public WorldRect getRegionExtents()
      Get a copy of the current region extents

      Returns:
      The current Region Extents
    • setOrigin

      public void setOrigin(WorldPt p)
      Set the origin of the map view position

      Parameters:
      p - The new Origin value
    • setOrigin

      public void setOrigin(WorldPt p, boolean computeScaling)
      Set the origin of the map view position

      Parameters:
      p - The new Origin value
      computeScaling - true to recompute scaling
    • getOrigin

      public WorldPt getOrigin()
      Get a copy of the current origin

      Returns:
      The current Origin
    • setZoom

      public void setZoom(double z)
      Set the zoom factor

      Parameters:
      z - The new Zoom factor
    • getZoom

      public double getZoom()
      Get the current zoom factor

      Returns:
      The current Zoom factor
    • setViewRect

      public void setViewRect(LocalRect rc)
      Set the viewport rectangle

      Parameters:
      rc - The new Viewport rectangle
    • setViewRect

      public void setViewRect(Dimension d)
      set the viewport rectangle to d

      Parameters:
      d - the new viewport rectangle
    • getViewRect

      public LocalRect getViewRect()
      Get a copy of the current view rectangle in local coodinates

      Returns:
      The current Viewport rectangle
    • getWorldRect

      public WorldRect getWorldRect()
      Get a copy of the current view rectangle in world coordinates

      Returns:
      The current Viewport rectangle
    • computeScaling

      public boolean computeScaling()
      Computes scaling parameters based on region, zoom, origin, and view rect.

      Returns:
      true if the scaling was recomputed
    • zoomByFactor

      public void zoomByFactor(double factor)
      Change the zoom scaling by the given factor.

      Parameters:
      factor - the new zoom scaling factor
    • zoomIn

      public boolean zoomIn(WorldRect wc)
    • zoomIn

      public boolean zoomIn(LocalRect rc)
      Zoom in to the given rectangle in local coordinates.

      Parameters:
      rc - the new viewport

      Returns:
      true if the viewport was zoomed to rc
    • world2LocalTransform

      public AffineTransform world2LocalTransform(AffineTransform transform)
      Coordinate conversion routines Creates or updates an existing AffineTransform to change from world to local coordinates.

      Parameters:
      transform - AffineTransform the transform to adjust. If null, a new transform is created.

      Returns:
      AffineTransform
    • local2WorldTransform

      public AffineTransform local2WorldTransform(AffineTransform transform)
      Creates or updates an existing AffineTransform to change from local to world coordinates.

      Parameters:
      transform - AffineTransform the transform to adjust. If null, a new transform is created.

      Returns:
      AffineTransform
    • e2x

      @Deprecated public int e2x(double e)
      Deprecated.
      call wp2lp. With the addition of map transforms the e/n axis are no longer independent. i.e. the x-shift will be smaller or larger, depending on your location on the earth
      Converts world east coordinate to local x coordinate.

      Parameters:
      e - the world east coordinate

      Returns:
      the local x coordinate for e

    • n2y

      @Deprecated public int n2y(double n)
      Deprecated.
      call wp2lp. With the addition of map transforms the e/n axis are no longer independent. i.e. the x-shift will be smaller or larger, depending on your location on the earth
      Converts world north coordinate to local y coordinate.

      Parameters:
      n - the world north coordinate

      Returns:
      the local y coordinate for n

    • x2e

      @Deprecated public double x2e(int x)
      Deprecated.
      call wp2lp. With the addition of map transforms the e/n axis are no longer independent. i.e. the x-shift will be smaller or larger, depending on your location on the earth
      Converts local x coordinate to world east coordinate.

      Parameters:
      x - the local x coordinate

      Returns:
      the world east coordinate for x

    • y2n

      @Deprecated public double y2n(int y)
      Deprecated.
      call wp2lp. With the addition of map transforms the e/n axis are no longer independent. i.e. the x-shift will be smaller or larger, depending on your location on the earth
      Converts local y coordinate to world north coordinate.

      Parameters:
      y - the local y coordinate

      Returns:
      the world north coordinate for y

    • wp2lp

      public void wp2lp(WorldPt wpt, LocalPt lpt)
      Converts a point in world coordinates to local coordinates.

      Parameters:
      wpt - a point in world coordinates
      lpt - the local point for wpt
    • wp2lp

      public final LocalPt wp2lp(WorldPt wpt)
      Converts a point in world coordinates to local coordinates, returning a newly allocated Point.

      Parameters:
      wpt - a point in world coordinates

      Returns:
      a new LocalPt for wpt
    • lp2wp

      public void lp2wp(LocalPt lpt, WorldPt wpt)
      Converts a point in local coordinates to world coordinates.

      Parameters:
      lpt - a point in local coordinates
      wpt - the world point set to the lpt coverted value
    • lp2wp

      public final WorldPt lp2wp(LocalPt lpt)
      Converts a point in local coordinates to world coordinates, returning a newly allocated Point.

      Parameters:
      lpt - a point in local coordinates

      This method is final. We end up calling lp2wp(lpt,wpt) with nothing realy computed.

      Returns:
      a new WorldPt for lpt
    • wr2lr

      public LocalRect wr2lr(WorldRect wr)
      Converts a WorldRect to a LocalRect, returning a newly allocated LocalRect

      Parameters:
      wr - a rect in world coordinates

      Returns:
      a new LocalRect for wr
    • wr2lr

      public LocalRect wr2lr(WorldRect wr, LocalRect lr)
      Converts a WorldRect to a LocalRect, returning a newly allocated LocalRect

      Parameters:
      wr - a rect in world coordinates
      lr - a rect in local coordinates to get filled in, or null and a new LocalRect will be created

      Returns:
      the LocalRect for wr
    • lr2wr

      public WorldRect lr2wr(LocalRect lr)
      Converts a LocalRect to a WorldRect, returning a newly allocated WorldRect

      Parameters:
      lr - a rect in local coordinates

      Returns:
      a new WorldRect for lr