public class ViewPort
extends java.lang.Object
implements org.gvsig.tools.persistence.Persistent, org.gvsig.tools.lang.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 java.awt.geom.Rectangle2D |
adjustedExtent
Location and dimensions of the extent adjusted to the image size.
|
protected java.awt.geom.Rectangle2D |
extent
Area selected by user using some tool.
|
protected ExtentHistory |
extents
History with the last extents of the view.
|
protected org.gvsig.timesupport.Time |
time |
Constructor and Description |
---|
ViewPort() |
ViewPort(org.cresques.cts.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(org.gvsig.fmap.geom.primitive.Envelope newRect)
Notifies to all view port listeners registered, that the adjusted extent
of this view port has changed.
|
protected void |
callTimeChanged(org.gvsig.timesupport.Time newTime)
Notifies to all view port listeners registered, that the time
of this view port has changed.
|
java.lang.Object |
clone()
Clone the view port without clone the listeners nor the extent history.
|
org.gvsig.fmap.geom.primitive.Point |
convertToMapPoint(int x,
int y) |
org.gvsig.fmap.geom.primitive.Point |
convertToMapPoint(java.awt.geom.Point2D pScreen) |
double |
distanceWorld(java.awt.geom.Point2D pt1,
java.awt.geom.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. |
java.awt.geom.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. |
java.awt.geom.Point2D |
fromMapPoint(java.awt.geom.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. |
java.awt.geom.Rectangle2D |
fromMapRectangle(java.awt.geom.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. |
org.gvsig.fmap.geom.primitive.Envelope |
getAdjustedEnvelope()
Returns the envelope currently covered by the view adjusted (scaled) to
the image size aspect.
|
java.awt.geom.AffineTransform |
getAffineTransform()
Affine transformation between map 2D coordinates to screen 2D
coordinates (pixels), preserving the "straightness" and "parallelism"
of the lines.
|
java.awt.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.
|
long |
getDrawVersion() |
org.gvsig.fmap.geom.primitive.Envelope |
getEnvelope()
Gets the envelope selected by user using some tool.
|
ExtentHistory |
getEnvelopes()
Returns the last previous extents of this view port.
|
int |
getImageHeight()
Gets the height in screen coordinates of the rectangle where the
image is displayed.
|
java.awt.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.
|
java.awt.geom.Point2D |
getOffset()
Gets the offset.
|
org.cresques.cts.IProjection |
getProjection()
Gets the projection used in this view port.
|
org.gvsig.timesupport.Time |
getTime() |
void |
loadFromState(org.gvsig.tools.persistence.PersistentState state) |
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(org.gvsig.tools.persistence.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(java.awt.geom.AffineTransform at)
Sets only the affine transform to this view port, without updating
dependent attributes.
|
void |
setBackColor(java.awt.Color c)
Sets the background color.
|
void |
setClipRect(java.awt.geom.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 |
setEnvelope(org.gvsig.fmap.geom.primitive.Envelope r)
Changes the extent and adjusted extent of this view port:
Stores the previous extent. |
void |
setImageSize(java.awt.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 |
setOffset(java.awt.geom.Point2D p)
Sets the offset.
|
void |
setPreviousEnvelope()
Sets as envelope and adjusted envelope of this view port, the previous.
|
void |
setProjection(org.cresques.cts.IProjection proj)
Sets the projection to this view port.
|
void |
setTime(org.gvsig.timesupport.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. |
java.awt.geom.Rectangle2D |
toMapRectangle(java.awt.geom.Rectangle2D r)
Converts and returns the
Rectangle2D , that is in
screen coordinates (pixels) to map coordinates using
toMapDistance(int), and toMapPoint(int, int). |
java.lang.String |
toString()
Returns a
String representation of the main values of this
view port: extent ,
adjustedExtent ,
imageSize , scale ,
and trans . |
protected void |
updateDrawVersion() |
protected java.awt.geom.Rectangle2D adjustedExtent
Location and dimensions of the extent adjusted to the image size.
getAdjustedExtent()
protected java.awt.geom.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 ExtentHistory extents
History with the last extents of the view.
setPreviousExtent()
,
getExtents()
protected org.gvsig.timesupport.Time time
public ViewPort()
public ViewPort(org.cresques.cts.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 boolean addViewPortListener(ViewPortListener arg0)
Appends the specified ViewPortListener
listener
if weren't.
arg0
- the listener to addtrue
if has been added successfullyremoveViewPortListener(ViewPortListener)
protected void callExtentChanged(org.gvsig.fmap.geom.primitive.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(org.gvsig.timesupport.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 java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public org.gvsig.fmap.geom.primitive.Point convertToMapPoint(int x, int y)
public org.gvsig.fmap.geom.primitive.Point convertToMapPoint(java.awt.geom.Point2D pScreen)
public double distanceWorld(java.awt.geom.Point2D pt1, java.awt.geom.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 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 java.awt.geom.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 java.awt.geom.Point2D fromMapPoint(java.awt.geom.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 java.awt.geom.Rectangle2D fromMapRectangle(java.awt.geom.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 org.gvsig.fmap.geom.primitive.Envelope getAdjustedEnvelope()
Returns the envelope currently covered by the view adjusted (scaled) to the image size aspect.
setAdjustable(boolean)
public java.awt.geom.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 java.awt.Color getBackColor()
Gets the background color.
setBackColor(Color)
public double getDist1pixel()
Gets the distance in world coordinates equivalent to 1 pixel in the view with the current extent.
setDist1pixel(double)
public double getDist3pixel()
Gets the distance in world coordinates equivalent to 3 pixels in the view with the current extent.
setDist3pixel(double)
public int getDistanceArea()
Returns the measurement unit of this view port used for measuring areas and displaying information.
setDistanceUnits(int)
public int getDistanceUnits()
Returns the measurement unit of this view port used for measuring distances and displaying information.
setDistanceUnits(int)
public long getDrawVersion()
public org.gvsig.fmap.geom.primitive.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 ExtentHistory getEnvelopes()
Returns the last previous extents of this view port.
setPreviousExtent()
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 java.awt.Dimension getImageSize()
Returns the size of the image projected.
setImageSize(Dimension)
,
getImageHeight()
,
getImageWidth()
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 getMapUnits()
Gets the measurement unit used by this view port for the map.
setMapUnits(int)
public java.awt.geom.Point2D getOffset()
Gets the offset.
The offset is the position where start drawing the map.
setOffset(Point2D)
public org.cresques.cts.IProjection getProjection()
Gets the projection used in this view port.
setProjection(IProjection)
public org.gvsig.timesupport.Time getTime()
public void loadFromState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException
loadFromState
in interface org.gvsig.tools.persistence.Persistent
org.gvsig.tools.persistence.exception.PersistenceException
public void refreshExtent()
Changes the extent and adjusted extent of this view port:
ViewPortListener
registered
that the extent has changed.
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 void saveToState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException
Returns an XML entity that represents this view port instance:
imageSize
and
extent
.
ExtentHistory
.
saveToState
in interface org.gvsig.tools.persistence.Persistent
org.gvsig.tools.persistence.exception.PersistenceException
#createFromXML(XMLEntity)
public 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 void setAffineTransform(java.awt.geom.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 setBackColor(java.awt.Color c)
Sets the background color.
c
- the new background colorgetBackColor()
public void setClipRect(java.awt.geom.Rectangle2D rectView)
Sets the position and size of the clipping rectangle.
rectView
- the clipping rectangle to setpublic 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 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 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 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 setEnvelope(org.gvsig.fmap.geom.primitive.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()
public void setImageSize(java.awt.Dimension imageSize)
Sets the size of the image projected, recalculating the parameters of this view port.
imageSize
- the image sizegetImageSize()
,
calculateAffineTransform()
public void setMapUnits(int mapUnits)
Sets the measurement unit used by this view port for the map.
mapUnits
- the new map measure unitgetMapUnits()
public void setOffset(java.awt.geom.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 void setPreviousEnvelope()
Sets as envelope and adjusted envelope of this view port, the previous. Recalculating its parameters.
getExtents()
,
calculateAffineTransform()
public void setProjection(org.cresques.cts.IProjection proj)
Sets the projection to this view port.
proj
- the new projectiongetProjection()
public void setTime(org.gvsig.timesupport.Time time)
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 java.awt.geom.Rectangle2D toMapRectangle(java.awt.geom.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 java.lang.String toString()
Returns a String
representation of the main values of this
view port: extent
,
adjustedExtent
,
imageSize
, scale
,
and trans
.
toString
in class java.lang.Object
string
representation of the main values of this
view portprotected void updateDrawVersion()
Copyright © 2013 gvSIG Association. All rights reserved.