Class ViewPort
- All Implemented Interfaces:
Cloneable,org.gvsig.tools.lang.Cloneable,org.gvsig.tools.persistence.Persistent
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:
- extent: the area selected of the map, in map coordinates.
- imageSize: width and height in pixels (screen coordinates) of the area available in screen to display the area selected of the map.
- adjustedExtent: the area selected must be an scale of
imageSize.
This implies adapt the extent, preserving and centering it, and adding around the needed area to fill all the image size. That added area will be extracted from the original map, wherever exists, and filled with the background color wherever not. - scale: the scale between the adjusted extent and the image size.
- backColor: the default background color in the view, if there is no map.
- trans: the affine transformation.
- proj: map projection used in this view.
- distanceUnits: distance measurement units, of data in screen.
- mapUnits: measurement units, of data in map.
- extents: an
ExtentHistorywith the last previous extents. - offset: position in pixels of the available rectangular area, where start drawing the map.
- dist1pixel: the distance in world coordinates equivalent to 1 pixel in the view with the current extent.
- dist3pixel: the distance in world coordinates equivalent to 3 pixels in the view with the current extent.
- listeners: list with the
ViewPortListenerregistered.
- Author:
- Vicente Caballero Navarro
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Rectangle2DLocation and dimensions of the extent adjusted to the image size.protected Rectangle2DArea selected by user using some tool.protected ExtentHistoryHistory with the last extents of the view.protected org.gvsig.timesupport.Time -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddViewPortListener(ViewPortListener listener) Appends the specifiedViewPortListenerlistener if weren't.protected voidcallExtentChanged(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 voidcallTimeChanged(org.gvsig.timesupport.Time newTime) Notifies to all view port listeners registered, that the time of this view port has changed.clone()Clone the view port without clone the listeners nor the extent history.org.gvsig.fmap.geom.primitive.PointconvertToMapPoint(int x, int y) org.gvsig.fmap.geom.primitive.PointconvertToMapPoint(Point2D pScreen) doubledistanceWorld(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.intfromMapDistance(double d) Converts and returns the distanced, that is in map coordinates to screen coordinates using a delta transform with the transformation affine information in the#transattribute.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#transattribute.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#transattribute.Converts and returns theRectangle2D, that is in map coordinates to screen coordinates (pixels) using an inverse transform with the transformation affine information in the#transattribute.org.gvsig.fmap.geom.primitive.EnvelopeReturns the envelope currently covered by the view adjusted (scaled) to the image size aspect.org.gvsig.fmap.geom.primitive.EnvelopeReturns the extent currently covered by the view adjusted (scaled) to the image size aspect.Affine transformation between map 2D coordinates to screen 2D coordinates (pixels), preserving the "straightness" and "parallelism" of the lines.Gets the background color.doubleGets the distance in world coordinates equivalent to 1 pixel in the view with the current extent.doubleGets the distance in world coordinates equivalent to 3 pixels in the view with the current extent.intReturns the measurement unit of this view port used for measuring areas and displaying information.intReturns the measurement unit of this view port used for measuring distances and displaying information.doublegetDPI()longorg.gvsig.fmap.geom.primitive.EnvelopeGets the envelope selected by user using some tool.Returns the last previous extents of this view port.Gets the area selected by user using some tool.Returns the last previous extents of this view port.intGets the height in screen coordinates of the rectangle where the image is displayed.Returns the size of the image projected.intGets the width in screen coordinates of the rectangle where the image is displayed.intGets the measurement unit used by this view port for the map.Gets the offset.org.gvsig.crs.projection.lib.ProjectionGets the projection used in this view port.Gets the selection color.org.gvsig.timesupport.TimegetTime()voidloadFromState(org.gvsig.tools.persistence.PersistentState state) voidChanges 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.booleanremoveViewPortListener(ViewPortListener listener) Removes the specifiedViewPortListenerlistener, if existed.voidsaveToState(org.gvsig.tools.persistence.PersistentState state) Returns an XML entity that represents this view port instance:
Properties: className: name of this class.voidsetAdjustable(boolean adjustable) Changes the status of the "adjustable extent" option to enabled or disabled.voidSets only the affine transform to this view port, without updating dependent attributes.voidSets the background color.voidsetClipRect(Rectangle2D rectView) Sets the position and size of the clipping rectangle.voidsetDist1pixel(double dist1pixel) Sets the distance in world coordinates equivalent to 1 pixel in the view with the current extent.voidsetDist3pixel(double dist3pixel) Sets the distance in world coordinates equivalent to 3 pixels in the view with the current extent.voidsetDistanceArea(int distanceArea) Sets the measurement unit of this view port used for measuring areas and displaying information.voidsetDistanceUnits(int distanceUnits) Sets the measurement unit of this view port used for measuring distances and displaying information.voidsetDPI(double dpi) voidvoidsetEnvelope(org.gvsig.fmap.geom.primitive.Envelope r) Changes the extent and adjusted extent of this view port:
Stores the previous extent.voidsetImageSize(Dimension imageSize) Sets the size of the image projected, recalculating the parameters of this view port.voidsetMapUnits(int mapUnits) Sets the measurement unit used by this view port for the map.voidSets as envelope and adjusted envelope of this view port, the next.voidSets the offset.voidSets as envelope and adjusted envelope of this view port, the previous.voidSets as extent and adjusted extent of this view port, the previous.voidsetProjection(org.gvsig.crs.projection.lib.Projection proj) Sets the projection to this view port.voidsetScale(long s) Recalculates the currentextentusing an scale.voidSets the selection color.voidsetTime(org.gvsig.timesupport.Time time) doubletoMapDistance(int d) Converts and returns the distanced, that is in screen coordinates to map coordinates using the transformation affine information in the#transattribute.toMapPoint(int x, int y) Converts and returns the 2D point(x,y), that is in screen coordinates (pixels) to map coordinates using the affine transformation in the#transattribute.toMapPoint(Point2D pScreen) Converts and returns the 2D point argument, that is in screen coordinates (pixels) to map coordinates using the inverse affine transformation of the#transattribute.Converts and returns theRectangle2D, that is in screen coordinates (pixels) to map coordinates using toMapDistance(int), and toMapPoint(int, int).toString()Returns aStringrepresentation of the main values of this view port:extent,adjustedExtent,imageSize,scale, andtrans.protected void
-
Field Details
-
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.
- See Also:
-
time
protected org.gvsig.timesupport.Time time -
adjustedExtent
Location and dimensions of the extent adjusted to the image size.
- See Also:
-
extentsHistory
History with the last extents of the view.
- See Also:
-
-
Constructor Details
-
ViewPort
public ViewPort() -
ViewPort
public ViewPort(org.gvsig.crs.projection.lib.Projection proj) Creates a new view port with the information of the projection in
projargument, and default configuration:distanceUnits= metersmapUnits= metersbackColor= undefinedoffset=new Point2D.Double(0, 0);
- Parameters:
proj- information of the projection for this view port
-
-
Method Details
-
setAdjustable
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).
- Parameters:
boolean- the boolean to be set
-
addViewPortListener
Appends the specified
ViewPortListenerlistener if weren't.- Parameters:
listener- the listener to add- Returns:
trueif has been added successfully- See Also:
-
removeViewPortListener
Removes the specified
ViewPortListenerlistener, if existed.- Parameters:
listener- the listener to remove- Returns:
trueif the contained the specified listener.- See Also:
-
fromMapDistance
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#transattribute.- Parameters:
d- distance in map coordinates- Returns:
- distance equivalent in screen coordinates
- See Also:
-
fromMapPoint
Converts and returns the 2D point
(x,y), that is in map coordinates to screen coordinates (pixels) using the affine transformation in the#transattribute.- Parameters:
x- thexmap coordinate of a 2D pointy- theymap coordinate of a 2D point- Returns:
- 2D point equivalent in screen coordinates (pixels)
- See Also:
-
fromMapPoint
Converts and returns the 2D point argument, that is in map coordinates to screen coordinates (pixels) using the affine transformation in the
#transattribute.- Parameters:
point- the 2D point in map coordinates- Returns:
- 2D point equivalent in screen coordinates (pixels)
- See Also:
-
toMapPoint
Converts and returns the 2D point
(x,y), that is in screen coordinates (pixels) to map coordinates using the affine transformation in the#transattribute.- Parameters:
x- thexscreen coordinate of a 2D pointy- theyscreen coordinate of a 2D point- Returns:
- 2D point equivalent in map coordinates
- See Also:
-
toMapRectangle
Converts and returns the
Rectangle2D, that is in screen coordinates (pixels) to map coordinates using toMapDistance(int), and toMapPoint(int, int).- Parameters:
r- the 2D rectangle in screen coordinates (pixels)- Returns:
- 2D rectangle equivalent in map coordinates
- See Also:
-
toMapDistance
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#transattribute.- Parameters:
d- distance in pixels- Returns:
- distance equivalent in map coordinates
- See Also:
-
toMapPoint
Converts and returns the 2D point argument, that is in screen coordinates (pixels) to map coordinates using the inverse affine transformation of the
#transattribute.- Parameters:
pScreen- the 2D point in screen coordinates (pixels)- Returns:
- 2D point equivalent in map coordinates
- See Also:
-
convertToMapPoint
-
convertToMapPoint
public org.gvsig.fmap.geom.primitive.Point convertToMapPoint(int x, int y) -
distanceWorld
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.
- Parameters:
pt1- a 2D point in map coordinatespt2- another 2D point in map coordinates- Returns:
- the distance in meters between the two points 2D
- See Also:
-
setPreviousExtent
public void setPreviousExtent()Sets as extent and adjusted extent of this view port, the previous. Recalculating its parameters.
- See Also:
-
setPreviousEnvelope
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.
- See Also:
-
setNextEnvelope
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.
- See Also:
-
getExtent
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.
- Returns:
- the current extent
- See Also:
-
getEnvelope
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.
- Returns:
- the current envelope
- See Also:
-
setEnvelope
public void setEnvelope(org.gvsig.fmap.geom.primitive.Envelope r) Changes the extent and adjusted extent of this view port:
- Stores the previous extent.
- Calculates the new extent using
r:extent = new Rectangle2D.Double(r.getMinX() - 0.1, r.getMinY() - 0.1, r.getWidth() + 0.2, r.getHeight() + 0.2); - 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.
- Notifies all
ViewPortListenerregistered that the extent has changed.
- Parameters:
r- the new extent- See Also:
-
refreshExtent
public 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.
- Notifies to all
ViewPortListenerregistered that the extent has changed.
- See Also:
-
getAffineTransform
Affine transformation between map 2D coordinates to screen 2D coordinates (pixels), preserving the "straightness" and "parallelism" of the lines.
- Returns:
- the affine transformation
- See Also:
-
getImageSize
Returns the size of the image projected.
- Returns:
- the image size
- See Also:
-
setImageSize
Sets the size of the image projected, recalculating the parameters of this view port.
- Parameters:
imageSize- the image size- See Also:
-
callExtentChanged
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.
- Parameters:
newRect- the new adjusted extend- See Also:
-
callTimeChanged
protected void callTimeChanged(org.gvsig.timesupport.Time newTime) Notifies to all view port listeners registered, that the time of this view port has changed.
- Parameters:
newTime- the new time- See Also:
-
setOffset
Sets the offset.
The offset is the position where start drawing the map.
- Parameters:
p- 2D point that represents the offset in pixels- See Also:
-
getOffset
Gets the offset.
The offset is the position where start drawing the map.
- Returns:
- 2D point that represents the offset in pixels
- See Also:
-
setBackColor
Sets the background color.
- Parameters:
c- the new background color- See Also:
-
setSelectionColor
Sets the selection color.
- Parameters:
c- the new selection color- See Also:
-
getBackColor
Gets the background color.
- Returns:
- the background color of the view
- See Also:
-
getSelectionColor
Gets the selection color.
- Returns:
- the selection color of the view
- See Also:
-
getAdjustedExtent
public org.gvsig.fmap.geom.primitive.Envelope getAdjustedExtent()Returns the extent currently covered by the view adjusted (scaled) to the image size aspect.
- Returns:
- extent of the view adjusted to the image size aspect
- See Also:
-
getAdjustedEnvelope
public org.gvsig.fmap.geom.primitive.Envelope getAdjustedEnvelope()Returns the envelope currently covered by the view adjusted (scaled) to the image size aspect.
- Returns:
- envelope of the view adjusted to the image size aspect
- See Also:
-
getDistanceUnits
public int getDistanceUnits()Returns the measurement unit of this view port used for measuring distances and displaying information.
- Returns:
- the measurement unit of this view used for measuring distances and displaying information
- See Also:
-
getDistanceArea
public int getDistanceArea()Returns the measurement unit of this view port used for measuring areas and displaying information.
- Returns:
- the measurement unit of this view used for measuring areas and displaying information
- See Also:
-
setDistanceUnits
public void setDistanceUnits(int distanceUnits) Sets the measurement unit of this view port used for measuring distances and displaying information.
- Parameters:
distanceUnits- the measurement unit of this view used for measuring distances and displaying information- See Also:
-
setDistanceArea
public void setDistanceArea(int distanceArea) Sets the measurement unit of this view port used for measuring areas and displaying information.
- Parameters:
distanceUnits- the measurement unit of this view used for measuring areas and displaying information- See Also:
-
getMapUnits
public int getMapUnits()Gets the measurement unit used by this view port for the map.
- Returns:
- Returns the current map measure unit
- See Also:
-
setMapUnits
public void setMapUnits(int mapUnits) Sets the measurement unit used by this view port for the map.
- Parameters:
mapUnits- the new map measure unit- See Also:
-
getImageWidth
public int getImageWidth()Gets the width in screen coordinates of the rectangle where the image is displayed.
Used by calculateAffineTransform() to calculate:
- The new
scale. - The new
adjustableExtent. - The new
trans. - The new real world coordinates equivalent to 1 pixel (
dist1pixel) . - The new real world coordinates equivalent to 3 pixels (
dist3pixel) .
- See Also:
- The new
-
getImageHeight
public int getImageHeight()Gets the height in screen coordinates of the rectangle where the image is displayed.
Used by calculateAffineTransform() to calculate:
- The new
scale. - The new
adjustableExtent. - The new
trans. - The new real world coordinates equivalent to 1 pixel (
dist1pixel) . - The new real world coordinates equivalent to 3 pixels (
dist3pixel) .
- See Also:
- The new
-
getDist1pixel
public double getDist1pixel()Gets the distance in world coordinates equivalent to 1 pixel in the view with the current extent.
- Returns:
- the distance
- See Also:
-
setDist1pixel
public void setDist1pixel(double dist1pixel) Sets the distance in world coordinates equivalent to 1 pixel in the view with the current extent.
- Parameters:
dist1pixel- the distance- See Also:
-
getDist3pixel
public double getDist3pixel()Gets the distance in world coordinates equivalent to 3 pixels in the view with the current extent.
- Returns:
- the distance
- See Also:
-
setDist3pixel
public void setDist3pixel(double dist3pixel) Sets the distance in world coordinates equivalent to 3 pixels in the view with the current extent.
- Parameters:
dist3pixel- the distance- See Also:
-
getExtents
Returns the last previous extents of this view port.
- Returns:
- the last previous extents of this view port
- See Also:
-
getEnvelopes
Returns the last previous extents of this view port.
- Returns:
- the last previous extents of this view port
- See Also:
-
getProjection
public org.gvsig.crs.projection.lib.Projection getProjection()Gets the projection used in this view port.
- Returns:
- projection used in this view port
- See Also:
-
setProjection
public void setProjection(org.gvsig.crs.projection.lib.Projection proj) Sets the projection to this view port.
- Parameters:
proj- the new projection- See Also:
-
setAffineTransform
Sets only the affine transform to this view port, without updating dependent attributes.
This method could be problematic!
- Parameters:
at- the affine transform to set- See Also:
-
saveToState
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:
- Properties:
- className: name of this class.
- If defined, the adjusted extent:
- adjustedExtentX: X coordinate of the adjusted extent.
- adjustedExtentY: Y coordinate of the adjusted extent.
- adjustedExtentW: width of the adjusted extent.
- adjustedExtentH: height of the adjusted extent.
- If defined, the background color:
- backColor: background color.
- If defined, the clip:
- clipX: X coordinate of the clip.
- clipY: Y coordinate of clip.
- clipW: width of the clip.
- clipH: height of the clip.
- dist1pixel: the distance in world coordinates equivalent to 1 pixel in the view.
- dist3pixel: the distance in world coordinates equivalent to 3 pixels in the view.
- distanceUnits: the distance measurement unit.
- If defined, the extent:
- extentX: X coordinate of the extent.
- extentY: Y coordinate of the extent.
- extentW: width of the extent.
- extentH: height of the extent.
- mapUnits: the map measurement unit.
- offsetX: X coordinate of the offset.
- offsetY: Y coordinate of the offset.
- If defined, the projection:
- If its defined, the projection:
- proj: the projection.
- If its defined, the projection:
- scale: ratio between the size of
imageSizeandextent.
- Child branches:
- XML entity of the internal
ExtentHistory.
- XML entity of the internal
- Specified by:
saveToStatein interfaceorg.gvsig.tools.persistence.Persistent- Throws:
org.gvsig.tools.persistence.exception.PersistenceException- See Also:
- Properties:
-
loadFromState
public void loadFromState(org.gvsig.tools.persistence.PersistentState state) throws org.gvsig.tools.persistence.exception.PersistenceException - Specified by:
loadFromStatein interfaceorg.gvsig.tools.persistence.Persistent- Throws:
org.gvsig.tools.persistence.exception.PersistenceException
-
clone
Clone the view port without clone the listeners nor the extent history.- Specified by:
clonein interfaceorg.gvsig.tools.lang.Cloneable- Overrides:
clonein classObject- Returns:
- the cloned view port
- Throws:
CloneNotSupportedException
-
toString
Returns a
Stringrepresentation of the main values of this view port:extent,adjustedExtent,imageSize,scale, andtrans. -
setClipRect
Sets the position and size of the clipping rectangle.
- Parameters:
rectView- the clipping rectangle to set
-
fromMapRectangle
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#transattribute.- Parameters:
r- the 2D rectangle in map coordinates- Returns:
- 2D rectangle equivalent in screen coordinates (pixels)
- See Also:
-
setScale
public void setScale(long s) Recalculates the current
extentusing an scale. It's necessary execute refreshExtent() after.- Parameters:
s- the scale to set
-
getDrawVersion
public long getDrawVersion() -
updateDrawVersion
protected void updateDrawVersion() -
getTime
public org.gvsig.timesupport.Time getTime() -
setTime
public void setTime(org.gvsig.timesupport.Time time) -
getDPI
public double getDPI() -
setDPI
public void setDPI(double dpi) -
setDPIToScreenDPI
public void setDPIToScreenDPI()
-