public class ViewPort extends Object implements Persistent, Cloneable
ViewPort
class represents the logic needed to transform a
rectangular area of a map to the available area in screen to display it.
Includes an affine transformation, between the rectangular area selected of the external map, in its own map coordinates, to the rectangular area available of a view in screen coordinates.
Elements:
ExtentHistory
with the last
previous extents.
ViewPortListener
registered.
Modifier and Type | Class and Description |
---|---|
static class |
ViewPort.RegisterPersistence |
Modifier and Type | Field and Description |
---|---|
protected Rectangle2D |
adjustedExtent
Location and dimensions of the extent adjusted to the image size.
|
protected Rectangle2D |
extent
Area selected by user using some tool.
|
protected ExtentHistory |
extentsHistory
History with the last extents of the view.
|
protected Time |
time |
Constructor and Description |
---|
ViewPort() |
ViewPort(IProjection proj)
Creates a new view port with the information of the projection in
proj argument, and default configuration:
distanceUnits = meters
mapUnits = meters
backColor = undefined
offset = new Point2D.Double(0, 0);
|
Modifier and Type | Method and Description |
---|---|
boolean |
addViewPortListener(ViewPortListener arg0)
Appends the specified
ViewPortListener listener if
weren't. |
protected void |
callExtentChanged(Envelope newRect)
Notifies to all view port listeners registered, that the adjusted extent of
this view port has changed.
|
protected void |
callTimeChanged(Time newTime)
Notifies to all view port listeners registered, that the time of this view
port has changed.
|
Object |
clone()
Clone the view port without clone the listeners nor the extent history.
|
Point |
convertToMapPoint(int x,
int y) |
Point |
convertToMapPoint(Point2D pScreen) |
double |
distanceWorld(Point2D pt1,
Point2D pt2)
Returns the real distance (in world coordinates) at the graphic
layers of two 2D points (in map coordinates) of the plane where is
selected the extent.
|
int |
fromMapDistance(double d)
Converts and returns the distance
d , that is in map
coordinates to screen coordinates using a delta transform
with the transformation affine information in the #trans
attribute. |
Point2D |
fromMapPoint(double x,
double y)
Converts and returns the 2D point
(x,y) , that is in map
coordinates to screen coordinates (pixels) using the affine
transformation in the #trans attribute. |
Point2D |
fromMapPoint(Point2D point)
Converts and returns the 2D point argument, that is in map
coordinates to screen coordinates (pixels) using the affine
transformation in the
#trans attribute. |
Rectangle2D |
fromMapRectangle(Rectangle2D r)
Converts and returns the
Rectangle2D , that is in map
coordinates to screen coordinates (pixels) using an inverse
transform with the transformation affine information in the
#trans attribute. |
Envelope |
getAdjustedEnvelope()
Returns the envelope currently covered by the view adjusted (scaled) to the
image size aspect.
|
Envelope |
getAdjustedExtent()
Deprecated.
use
getAdjustedEnvelope() instead |
AffineTransform |
getAffineTransform()
Affine transformation between map 2D coordinates to screen 2D
coordinates (pixels), preserving the "straightness" and "parallelism"
of the lines.
|
Color |
getBackColor()
Gets the background color.
|
double |
getDist1pixel()
Gets the distance in world coordinates equivalent to 1 pixel in the
view with the current extent.
|
double |
getDist3pixel()
Gets the distance in world coordinates equivalent to 3 pixels in the
view with the current extent.
|
int |
getDistanceArea()
Returns the measurement unit of this view port used for measuring areas and
displaying information.
|
int |
getDistanceUnits()
Returns the measurement unit of this view port used for measuring distances
and displaying information.
|
double |
getDPI() |
long |
getDrawVersion() |
Envelope |
getEnvelope()
Gets the envelope selected by user using some tool.
|
ExtentHistory |
getEnvelopes()
Returns the last previous extents of this view port.
|
Rectangle2D |
getExtent()
Deprecated.
use
getEnvelope() |
ExtentHistory |
getExtents()
Deprecated.
use
getEnvelopes() |
int |
getImageHeight()
Gets the height in screen coordinates of the rectangle where the
image is displayed.
|
Dimension |
getImageSize()
Returns the size of the image projected.
|
int |
getImageWidth()
Gets the width in screen coordinates of the rectangle where the
image is displayed.
|
int |
getMapUnits()
Gets the measurement unit used by this view port for the map.
|
Point2D |
getOffset()
Gets the offset.
|
IProjection |
getProjection()
Gets the projection used in this view port.
|
Time |
getTime() |
void |
loadFromState(PersistentState state)
Set the state of the object from the state passed as parameter.
|
void |
refreshExtent()
Changes the extent and adjusted extent of this view port:
Executes calculateAffineTransform(): getting the new scale, adjusted extent, affine transformation between map and screen coordinates, the real world coordinates equivalent to 1 pixel, and the real world coordinates equivalent to 3 pixels. |
boolean |
removeViewPortListener(ViewPortListener arg0)
Removes the specified
ViewPortListener listener,
if existed. |
void |
saveToState(PersistentState state)
Returns an XML entity that represents this view port instance:
Properties: className: name of this class. |
void |
setAdjustable(boolean adjustable)
Changes the status of the "adjustable extent" option to enabled or
disabled.
|
void |
setAffineTransform(AffineTransform at)
Sets only the affine transform to this view port, without updating
dependent attributes.
|
void |
setBackColor(Color c)
Sets the background color.
|
void |
setClipRect(Rectangle2D rectView)
Sets the position and size of the clipping rectangle.
|
void |
setDist1pixel(double dist1pixel)
Sets the distance in world coordinates equivalent to 1 pixel in the
view with the current extent.
|
void |
setDist3pixel(double dist3pixel)
Sets the distance in world coordinates equivalent to 3 pixels in the
view with the current extent.
|
void |
setDistanceArea(int distanceArea)
Sets the measurement unit of this view port used for measuring areas and
displaying information.
|
void |
setDistanceUnits(int distanceUnits)
Sets the measurement unit of this view port used for measuring distances
and displaying information.
|
void |
setDPI(double dpi) |
void |
setDPIToScreenDPI() |
void |
setEnvelope(Envelope r)
Changes the extent and adjusted extent of this view port:
Stores the previous extent. |
void |
setImageSize(Dimension imageSize)
Sets the size of the image projected, recalculating the parameters of this
view port.
|
void |
setMapUnits(int mapUnits)
Sets the measurement unit used by this view port for the map.
|
void |
setNextEnvelope()
Sets as envelope and adjusted envelope of this view port, the next.
|
void |
setOffset(Point2D p)
Sets the offset.
|
void |
setPreviousEnvelope()
Sets as envelope and adjusted envelope of this view port, the previous.
|
void |
setPreviousExtent()
Deprecated.
|
void |
setProjection(IProjection proj)
Sets the projection to this view port.
|
void |
setScale(long s)
Deprecated.
since 07/09/07, use MapContext.setScaleView(long)
|
void |
setTime(Time time) |
double |
toMapDistance(int d)
Converts and returns the distance
d , that is in screen
coordinates to map coordinates using the transformation affine
information in the #trans attribute. |
Point2D |
toMapPoint(int x,
int y)
Deprecated.
|
Point2D |
toMapPoint(Point2D pScreen)
Deprecated.
|
Rectangle2D |
toMapRectangle(Rectangle2D r)
Converts and returns the
Rectangle2D , that is in
screen coordinates (pixels) to map coordinates using
toMapDistance(int), and toMapPoint(int, int). |
String |
toString()
Returns a
String representation of the main values of this
view port: extent ,
adjustedExtent ,
imageSize , scale , and
trans . |
protected void |
updateDrawVersion() |
protected Rectangle2D extent
Area selected by user using some tool.
When the zoom changes (for instance when using the zoom in or zoom out tools, but also zooming to a selected feature or shape) the extent that covers that area is the value returned by this method. It is not the actual area shown in the view because it does not care about the aspect ratio of the available area. However, any part of the real world contained in this extent is shown in the view.
Probably this is not what you are looking for. If you are looking for the complete extent currently shown, you must use getAdjustedExtent() method which returns the extent that contains this one but regarding the current view's aspect ratio.
getExtent()
,
setEnvelope(Envelope)
protected Time time
protected Rectangle2D adjustedExtent
Location and dimensions of the extent adjusted to the image size.
getAdjustedExtent()
protected ExtentHistory extentsHistory
History with the last extents of the view.
setPreviousExtent()
,
getExtents()
public ViewPort()
public ViewPort(IProjection proj)
Creates a new view port with the information of the projection in
proj
argument, and default configuration:
distanceUnits
= meters
mapUnits
= meters
backColor
= undefined
offset
= new Point2D.Double(0, 0);
proj
- information of the projection for this view portpublic void setAdjustable(boolean adjustable)
Changes the status of the "adjustable extent" option to enabled or disabled.
If view port isn't adjustable, won't bear in mind the aspect ratio of the available rectangular area to calculate the affine transform from the original map in real coordinates. (Won't scale the image to adapt it to the available rectangular area).
boolean
- the boolean to be setpublic boolean addViewPortListener(ViewPortListener arg0)
Appends the specified ViewPortListener
listener if
weren't.
arg0
- the listener to addtrue
if has been added successfullyremoveViewPortListener(ViewPortListener)
public boolean removeViewPortListener(ViewPortListener arg0)
Removes the specified ViewPortListener
listener,
if existed.
arg0
- the listener to removetrue
if the contained the specified listener.addViewPortListener(ViewPortListener)
public int fromMapDistance(double d)
Converts and returns the distance d
, that is in map
coordinates to screen coordinates using a delta transform
with the transformation affine information in the #trans
attribute.
d
- distance in map coordinatestoMapDistance(int)
,
AffineTransform.deltaTransform(Point2D, Point2D)S
public Point2D fromMapPoint(double x, double y)
Converts and returns the 2D point (x,y)
, that is in map
coordinates to screen coordinates (pixels) using the affine
transformation in the #trans
attribute.
x
- the x
map coordinate of a 2D pointy
- the y
map coordinate of a 2D pointfromMapPoint(Point2D)
,
AffineTransform.transform(Point2D, Point2D)
public Point2D fromMapPoint(Point2D point)
Converts and returns the 2D point argument, that is in map
coordinates to screen coordinates (pixels) using the affine
transformation in the #trans
attribute.
point
- the 2D point in map coordinatestoMapPoint(Point2D)
,
fromMapPoint(double, double)
public Point2D toMapPoint(int x, int y)
convertToMapPoint(int, int)
Converts and returns the 2D point (x,y)
, that is in screen
coordinates (pixels) to map coordinates using the affine
transformation in the #trans
attribute.
x
- the x
screen coordinate of a 2D pointy
- the y
screen coordinate of a 2D pointtoMapPoint(Point2D)
,
fromMapPoint(double, double)
public Rectangle2D toMapRectangle(Rectangle2D r)
Converts and returns the Rectangle2D
, that is in
screen coordinates (pixels) to map coordinates using
toMapDistance(int), and toMapPoint(int, int).
r
- the 2D rectangle in screen coordinates (pixels)fromMapRectangle(Rectangle2D)
,
toMapDistance(int)
,
toMapPoint(int, int)
public double toMapDistance(int d)
Converts and returns the distance d
, that is in screen
coordinates to map coordinates using the transformation affine
information in the #trans
attribute.
d
- distance in pixelsfromMapDistance(double)
,
AffineTransform
public Point2D toMapPoint(Point2D pScreen)
convertToMapPoint(Point2D)
Converts and returns the 2D point argument, that is in screen
coordinates (pixels) to map coordinates using the inverse affine
transformation of the #trans
attribute.
pScreen
- the 2D point in screen coordinates (pixels)toMapPoint(int, int)
,
AffineTransform.createInverse()
,
AffineTransform.transform(Point2D, Point2D)
public Point convertToMapPoint(int x, int y)
public double distanceWorld(Point2D pt1, Point2D pt2)
Returns the real distance (in world coordinates) at the graphic layers of two 2D points (in map coordinates) of the plane where is selected the extent.
If the projection of this view is UTM, considers the Earth curvature.
pt1
- a 2D point in map coordinatespt2
- another 2D point in map coordinatesGeoCalcImpl#distanceVincenty(Point2D, Point2D)
public void setPreviousExtent()
setPreviousEnvelope()
Sets as extent and adjusted extent of this view port, the previous. Recalculating its parameters.
getExtents()
,
calculateAffineTransform()
public void setPreviousEnvelope()
Sets as envelope and adjusted envelope of this view port, the previous. Recalculating its parameters. Stores the current extent in the next extents of the history.
getExtents()
,
calculateAffineTransform()
public void setNextEnvelope()
Sets as envelope and adjusted envelope of this view port, the next. Recalculating its parameters. Stores the current extent in the previous extents of the history.
getExtents()
,
calculateAffineTransform()
public Rectangle2D getExtent()
getEnvelope()
Gets the area selected by user using some tool.
When the zoom changes (for instance using the zoom in or zoom out tools, but also zooming to a selected feature or shape) the extent that covers that area is the value returned by this method. It is not the actual area shown because it doesn't care about the aspect ratio of the image size of the view. However, any part of the real world contained in this extent is shown in the view.
If you are looking for the complete extent currently shown, you must use the getAdjustedExtent() method.
setEnvelope(Envelope)
,
getAdjustedExtent()
,
setPreviousExtent()
,
getExtents()
public Envelope getEnvelope()
Gets the envelope selected by user using some tool.
When the zoom changes (for instance using the zoom in or zoom out tools, but also zooming to a selected feature or shape) the envelope that covers that area is the value returned by this method. It is not the actual envelope shown because it doesn't care about the aspect ratio of the image size of the view. However, any part of the real world contained in this envelope is shown in the view.
If you are looking for the complete extent currently shown, you must use the getAdjustedEnvelope() method.
setEnvelope(Envelope)
,
getAdjustedEnvelope()
,
setPreviousEnvelope()
,
getEnvelopes()
public void setEnvelope(Envelope r)
Changes the extent and adjusted extent of this view port:
r
:
extent = new Rectangle2D.Double(r.getMinX() - 0.1, r.getMinY() - 0.1, r.getWidth() + 0.2, r.getHeight() + 0.2);
ViewPortListener
registered that
the extent has changed.
r
- the new extentgetExtent()
,
getExtents()
,
calculateAffineTransform()
,
setPreviousExtent()
,
#clear()
public void refreshExtent()
Changes the extent and adjusted extent of this view port:
ViewPortListener
registered
that the extent has changed.
public AffineTransform getAffineTransform()
Affine transformation between map 2D coordinates to screen 2D coordinates (pixels), preserving the "straightness" and "parallelism" of the lines.
setAffineTransform(AffineTransform)
,
calculateAffineTransform()
public Dimension getImageSize()
Returns the size of the image projected.
setImageSize(Dimension)
,
getImageHeight()
,
getImageWidth()
public void setImageSize(Dimension imageSize)
Sets the size of the image projected, recalculating the parameters of this view port.
imageSize
- the image sizegetImageSize()
,
calculateAffineTransform()
protected void callExtentChanged(Envelope newRect)
Notifies to all view port listeners registered, that the adjusted extent of this view port has changed.
newRect
- the new adjusted extendrefreshExtent()
,
setEnvelope(Envelope)
,
setPreviousExtent()
,
ExtentEvent
,
ViewPortListener
protected void callTimeChanged(Time newTime)
Notifies to all view port listeners registered, that the time of this view port has changed.
newTime
- the new timerefreshExtent()
,
setTime(Time)
,
ExtentEvent
,
ViewPortListener
public void setOffset(Point2D p)
Sets the offset.
The offset is the position where start drawing the map.
p
- 2D point that represents the offset in pixelsgetOffset()
public Point2D getOffset()
Gets the offset.
The offset is the position where start drawing the map.
setOffset(Point2D)
public void setBackColor(Color c)
Sets the background color.
c
- the new background colorgetBackColor()
public Color getBackColor()
Gets the background color.
setBackColor(Color)
public Envelope getAdjustedExtent()
getAdjustedEnvelope()
insteadReturns the extent currently covered by the view adjusted (scaled) to the image size aspect.
setAdjustable(boolean)
public Envelope getAdjustedEnvelope()
Returns the envelope currently covered by the view adjusted (scaled) to the image size aspect.
setAdjustable(boolean)
public int getDistanceUnits()
Returns the measurement unit of this view port used for measuring distances and displaying information.
setDistanceUnits(int)
public int getDistanceArea()
Returns the measurement unit of this view port used for measuring areas and displaying information.
setDistanceUnits(int)
public void setDistanceUnits(int distanceUnits)
Sets the measurement unit of this view port used for measuring distances and displaying information.
distanceUnits
- the measurement unit of this view used for measuring
distances and displaying informationgetDistanceUnits()
public void setDistanceArea(int distanceArea)
Sets the measurement unit of this view port used for measuring areas and displaying information.
distanceUnits
- the measurement unit of this view used for measuring
areas and displaying informationgetDistanceUnits()
public int getMapUnits()
Gets the measurement unit used by this view port for the map.
setMapUnits(int)
public void setMapUnits(int mapUnits)
Sets the measurement unit used by this view port for the map.
mapUnits
- the new map measure unitgetMapUnits()
public int getImageWidth()
Gets the width in screen coordinates of the rectangle where the image is displayed.
Used by calculateAffineTransform() to calculate:
scale
.
adjustableExtent
.
trans
.
dist1pixel
) .
dist3pixel
) .
public int getImageHeight()
Gets the height in screen coordinates of the rectangle where the image is displayed.
Used by calculateAffineTransform() to calculate:
scale
.
adjustableExtent
.
trans
.
dist1pixel
) .
dist3pixel
) .
getImageWidth()
,
getImageSize()
,
setImageSize(Dimension)
public double getDist1pixel()
Gets the distance in world coordinates equivalent to 1 pixel in the view with the current extent.
setDist1pixel(double)
public void setDist1pixel(double dist1pixel)
Sets the distance in world coordinates equivalent to 1 pixel in the view with the current extent.
dist1pixel
- the distancegetDist1pixel()
public double getDist3pixel()
Gets the distance in world coordinates equivalent to 3 pixels in the view with the current extent.
setDist3pixel(double)
public void setDist3pixel(double dist3pixel)
Sets the distance in world coordinates equivalent to 3 pixels in the view with the current extent.
dist3pixel
- the distancegetDist3pixel()
public ExtentHistory getExtents()
getEnvelopes()
Returns the last previous extents of this view port.
setPreviousExtent()
public ExtentHistory getEnvelopes()
Returns the last previous extents of this view port.
setPreviousExtent()
public IProjection getProjection()
Gets the projection used in this view port.
setProjection(IProjection)
public void setProjection(IProjection proj)
Sets the projection to this view port.
proj
- the new projectiongetProjection()
public void setAffineTransform(AffineTransform at)
Sets only the affine transform to this view port, without updating dependent attributes.
This method could be problematic!
at
- the affine transform to setgetAffineTransform()
,
calculateAffineTransform()
public void saveToState(PersistentState state) throws PersistenceException
Returns an XML entity that represents this view port instance:
imageSize
and
extent
.
ExtentHistory
.
saveToState
in interface Persistent
PersistenceException
#createFromXML(XMLEntity)
public void loadFromState(PersistentState state) throws PersistenceException
Persistent
loadFromState
in interface Persistent
PersistenceException
public Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- if the instance of the object cannot
be cloned. As this is extending Cloneable
so
its sure it implements it, so this exception may be used for problems
on specific object instances.Object#clone()}.
public String toString()
Returns a String
representation of the main values of this
view port: extent
,
adjustedExtent
,
imageSize
, scale
, and
trans
.
public void setClipRect(Rectangle2D rectView)
Sets the position and size of the clipping rectangle.
rectView
- the clipping rectangle to setpublic Rectangle2D fromMapRectangle(Rectangle2D r)
Converts and returns the Rectangle2D
, that is in map
coordinates to screen coordinates (pixels) using an inverse
transform with the transformation affine information in the
#trans
attribute.
r
- the 2D rectangle in map coordinatestoMapRectangle(Rectangle2D)
,
fromMapDistance(double)
,
fromMapPoint(Point2D)
public void setScale(long s)
Recalculates the current extent
using an scale.
It's necessary execute refreshExtent() after.
s
- the scale to setpublic long getDrawVersion()
protected void updateDrawVersion()
public Time getTime()
public void setTime(Time time)
public double getDPI()
public void setDPI(double dpi)
public void setDPIToScreenDPI()