public class MapViewport extends Object
MapContent
will be used to record additional
information such as elevation and time as required for rendering.
When both world and screen bounds are defined, the viewport calculates AffineTransforms
to convert the coordinates of one bounds to those of the other. It can also
optionally adjust the world bounds to maintain an identical aspect ratio with the screen bounds.
Note however that aspect ratio adjustment should not be enabled when the viewport is used with a
service such as WMS which mandates that specified screen and world bounds must be honoured
exactly, regardless of the resulting aspect ratio differences.
The AffineTransforms
can be retrieved with the methods getScreenToWorld() and getWorldToScreen(). The following rules apply to the
return values of these methods:
null
is returned.
Modifier and Type | Field and Description |
---|---|
protected static Logger |
LOGGER
The logger for the map module.
|
Constructor and Description |
---|
MapViewport()
Creates a new view port.
|
MapViewport(boolean matchAspectRatio)
Creates a new view port.
|
MapViewport(MapViewport sourceViewport)
Creates a new viewport based on an existing instance.
|
MapViewport(ReferencedEnvelope bounds)
Creates a new view port with the specified display area in world coordinates.
|
MapViewport(ReferencedEnvelope bounds,
boolean matchAspectRatio)
Creates a new viewport with the specified world bounds.
|
Modifier and Type | Method and Description |
---|---|
void |
addMapBoundsListener(MapBoundsListener listener)
Used by client application to track the bounds of this viewport.
|
protected void |
fireMapBoundsListenerMapBoundsChanged(MapBoundsEvent.Type type,
ReferencedEnvelope oldBounds,
ReferencedEnvelope newBounds)
Notifies MapBoundsListeners about a change to the bounds or crs.
|
ReferencedEnvelope |
getBounds()
Gets the display area in world coordinates.
|
CoordinateReferenceSystem |
getCoordinateReferenceSystem()
The coordinate reference system used for rendering the map.
|
Rectangle |
getScreenArea()
Gets a copy of the current screen area.
|
AffineTransform |
getScreenToWorld()
Gets the current screen to world coordinate transform.
|
AffineTransform |
getWorldToScreen()
Gets the current world to screen coordinate transform.
|
boolean |
isEditable()
Tests whether this viewport's attributes can be changed.
|
boolean |
isEmpty()
Checks if the view port bounds are empty (undefined).
|
boolean |
isMatchingAspectRatio()
Queries whether input worlds bounds will be adjusted to match the aspect ratio of the screen
area.
|
void |
removeMapBoundsListener(MapBoundsListener listener) |
void |
setBounds(ReferencedEnvelope requestedBounds)
Sets the display area in world coordinates.
|
void |
setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
Set the
CoordinateReferenceSystem for the viewport. |
void |
setEditable(boolean editable)
Sets whether the value of this viewport's attributes can be changed.
|
void |
setMatchingAspectRatio(boolean enabled)
Sets whether to adjust input world bounds to match the aspect ratio of the screen area.
|
void |
setScreenArea(Rectangle screenArea)
Sets the display area in screen (window, image) coordinates.
|
protected static final Logger LOGGER
public MapViewport()
public MapViewport(boolean matchAspectRatio)
matchAspectRatio
- whether to enable aspect ratio matchingpublic MapViewport(ReferencedEnvelope bounds)
The initial screen area will be empty and aspect ratio matching will be disabled.
bounds
- display area in world coordinates (may be null
)public MapViewport(ReferencedEnvelope bounds, boolean matchAspectRatio)
The initial screen area will be empty.
bounds
- display area in world coordinates (may be null
)matchAspectRatio
- whether to enable aspect ratio matchingpublic MapViewport(MapViewport sourceViewport)
sourceViewport
are copied.
Note: The new viewport will be editable even if sourceViewport
is
not editable.
sourceViewport
- the viewport to copyIllegalArgumentException
- if viewport
is null
public boolean isEditable()
true
if this viewport is editablepublic void setEditable(boolean editable)
editable
- true
to allow changespublic void setMatchingAspectRatio(boolean enabled)
enabled
- whether to enable aspect ratio adjustmentpublic boolean isMatchingAspectRatio()
true
if enabledpublic void addMapBoundsListener(MapBoundsListener listener)
listener
- public void removeMapBoundsListener(MapBoundsListener listener)
public boolean isEmpty()
true
if either or
both of the world bounds and screen bounds are empty.true
if emptypublic ReferencedEnvelope getBounds()
Note Well: this only covers spatial extent; you may wish to use the user data map to record the current viewport time or elevation.
public void setBounds(ReferencedEnvelope requestedBounds)
If bounds
is null
or empty, default identity coordinate transforms will be
set.
If bounds
is not empty, and aspect ratio matching is enabled, the coordinate
transforms will be calculated to centre the requested bounds in the current screen area (if
defined), after which the world bounds will be adjusted (enlarged) as required to match the
screen area's aspect ratio.
A MapBoundsEvent
will be fired to inform listeners of the change from old to new
bounds. Note that when aspect ratio matching is enabled, the new bounds carried by the event
will be the viewport's adjusted bounds, not the originally requested bounds.
requestedBounds
- the requested bounds (may be null
)public Rectangle getScreenArea()
public void setScreenArea(Rectangle screenArea)
screenArea
- display area in screen coordinates (may be null
)public CoordinateReferenceSystem getCoordinateReferenceSystem()
null
is
returned.
The coordinate reference system used for rendering is often considered to be the "world" coordinate reference system; this is distinct from the coordinate reference system used for each layer (which is often data dependent).
null
).public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs)
CoordinateReferenceSystem
for the viewport. If crs
is null, the
existing reference system will be discarded.crs
- the new coordinate reference system, or null
for no reference systemprotected void fireMapBoundsListenerMapBoundsChanged(MapBoundsEvent.Type type, ReferencedEnvelope oldBounds, ReferencedEnvelope newBounds)
event
- The event to be firedpublic AffineTransform getScreenToWorld()
null
if the transform is
not setpublic AffineTransform getWorldToScreen()
null
if the transform is
not setCopyright © 1996–2019 Geotools. All rights reserved.