Package org.openstreetmap.josm.gui
Class MapViewState
- java.lang.Object
-
- org.openstreetmap.josm.gui.MapViewState
-
- All Implemented Interfaces:
Serializable
public final class MapViewState extends Object implements Serializable
This class represents a state of theMapView
.- Since:
- 10343
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
MapViewState.MapViewEastNorthPoint
class
MapViewState.MapViewPoint
A class representing a point in the map view.class
MapViewState.MapViewRectangle
A rectangle on the MapView.private class
MapViewState.MapViewViewPoint
-
Field Summary
Fields Modifier and Type Field Description private static int
CLIP_BOUNDS
Additional pixels outside the view for where to start clipping.static int
OUTSIDE_BOTTOM
A flag indicating that the point is outside to the bottom of the map view.static int
OUTSIDE_LEFT
A flag indicating that the point is outside to the left of the map view.static int
OUTSIDE_RIGHT
A flag indicating that the point is outside to the right of the map view.static int
OUTSIDE_TOP
A flag indicating that the point is outside to the top of the map view.private Projecting
projecting
private double
scale
private static long
serialVersionUID
private EastNorth
topLeft
Top leftEastNorth
coordinate of the view.private Point
topLeftInWindow
private Point
topLeftOnScreen
private int
viewHeight
private int
viewWidth
-
Constructor Summary
Constructors Modifier Constructor Description private
MapViewState(double scale, MapViewState mvs)
private
MapViewState(JComponent position, MapViewState mvs)
private
MapViewState(EastNorth topLeft, MapViewState mvs)
private
MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft)
private
MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft, Point topLeftInWindow, Point topLeftOnScreen)
Create a newMapViewState
private
MapViewState(Projecting projecting, MapViewState mvs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static EastNorth
calculateDefaultCenter()
static MapViewState
createDefaultState(int width, int height)
Create the defaultMapViewState
object for the given map view.boolean
equalsInWindow(MapViewState other)
Check if this MapViewState equals another one, disregarding the position of the JOSM window on screen.(package private) static Point
findTopLeftInWindow(JComponent position)
This is visible for JMockit.(package private) static Point
findTopLeftOnScreen(JComponent position)
This is visible for JMockit.AffineTransform
getAffineTransform()
Creates an affine transform that is used to convert the east/north coordinates to view coordinates.Area
getArea(Bounds bounds)
Returns the area for the given bounds.MapViewState.MapViewPoint
getCenter()
Gets the center of the view.MapViewState.MapViewPoint
getForView(double x, double y)
Gets the MapViewPoint representation for a position in view coordinates.MapViewState.MapViewPoint
getPointFor(EastNorth eastNorth)
Gets theMapViewState.MapViewPoint
for the givenEastNorth
coordinate.MapViewState.MapViewPoint
getPointFor(ILatLon latlon)
Gets theMapViewState.MapViewPoint
for the givenLatLon
coordinate.MapViewState.MapViewPoint
getPointFor(LatLon latlon)
Gets theMapViewState.MapViewPoint
for the givenLatLon
coordinate.MapViewState.MapViewPoint
getPointFor(Node node)
Gets theMapViewState.MapViewPoint
for the given node.Projecting
getProjecting()
Gets the current projecting instance that is used to convert between east/north and lat/lon space.Projection
getProjection()
Gets the current projection used for the MapView.double
getScale()
The scale in east/north units per pixel.MapViewState.MapViewRectangle
getViewArea()
Gets a rectangle representing the whole view area.MapViewState.MapViewRectangle
getViewArea(Rectangle2D rectangle)
Gets a rectangle of the view as map view area.MapViewState.MapViewRectangle
getViewClipRectangle()
Gets a rectangle that is several pixel bigger than the view.double
getViewHeight()
Gets the height of the view on the Screen;double
getViewWidth()
Gets the width of the view on the Screen;MapViewState
movedTo(MapViewState.MapViewPoint mapViewPoint, EastNorth newEastNorthThere)
Creates a new state that is moved to an east/north coordinate.String
toString()
MapViewState
usingCenter(EastNorth newCenter)
Creates a new state that is the same as the current state except for that it is using a new center.MapViewState
usingLocation(JComponent position)
Creates a new state that is the same as the current state except for that it is using the location of the given component.MapViewState
usingProjection(Projection projection)
Creates a state that uses the projection.MapViewState
usingScale(double newScale)
Creates a new state that is the same as the current state except for that it is using a new scale.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
OUTSIDE_TOP
public static final int OUTSIDE_TOP
A flag indicating that the point is outside to the top of the map view.- Since:
- 10827
- See Also:
- Constant Field Values
-
OUTSIDE_BOTTOM
public static final int OUTSIDE_BOTTOM
A flag indicating that the point is outside to the bottom of the map view.- Since:
- 10827
- See Also:
- Constant Field Values
-
OUTSIDE_LEFT
public static final int OUTSIDE_LEFT
A flag indicating that the point is outside to the left of the map view.- Since:
- 10827
- See Also:
- Constant Field Values
-
OUTSIDE_RIGHT
public static final int OUTSIDE_RIGHT
A flag indicating that the point is outside to the right of the map view.- Since:
- 10827
- See Also:
- Constant Field Values
-
CLIP_BOUNDS
private static final int CLIP_BOUNDS
Additional pixels outside the view for where to start clipping.- See Also:
- Constant Field Values
-
projecting
private final transient Projecting projecting
-
viewWidth
private final int viewWidth
-
viewHeight
private final int viewHeight
-
scale
private final double scale
-
topLeftOnScreen
private final Point topLeftOnScreen
-
topLeftInWindow
private final Point topLeftInWindow
-
-
Constructor Detail
-
MapViewState
private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft, Point topLeftInWindow, Point topLeftOnScreen)
Create a newMapViewState
- Parameters:
projection
- The projection to use.viewWidth
- The view widthviewHeight
- The view heightscale
- The scale to usetopLeft
- The top left corner in east/north space.topLeftInWindow
- The top left point in windowtopLeftOnScreen
- The top left point on screen
-
MapViewState
private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft)
-
MapViewState
private MapViewState(EastNorth topLeft, MapViewState mvs)
-
MapViewState
private MapViewState(double scale, MapViewState mvs)
-
MapViewState
private MapViewState(JComponent position, MapViewState mvs)
-
MapViewState
private MapViewState(Projecting projecting, MapViewState mvs)
-
-
Method Detail
-
findTopLeftInWindow
static Point findTopLeftInWindow(JComponent position)
This is visible for JMockit.- Parameters:
position
- The component to get the top left position of its window- Returns:
- the top left point in window
-
findTopLeftOnScreen
static Point findTopLeftOnScreen(JComponent position)
This is visible for JMockit.- Parameters:
position
- The component to get the top left position of its screen- Returns:
- the top left point on screen
-
getScale
public double getScale()
The scale in east/north units per pixel.- Returns:
- The scale.
-
getForView
public MapViewState.MapViewPoint getForView(double x, double y)
Gets the MapViewPoint representation for a position in view coordinates.- Parameters:
x
- The x coordinate inside the view.y
- The y coordinate inside the view.- Returns:
- The MapViewPoint.
-
getPointFor
public MapViewState.MapViewPoint getPointFor(EastNorth eastNorth)
Gets theMapViewState.MapViewPoint
for the givenEastNorth
coordinate.- Parameters:
eastNorth
- the position.- Returns:
- The point for that position.
-
getPointFor
public MapViewState.MapViewPoint getPointFor(LatLon latlon)
Gets theMapViewState.MapViewPoint
for the givenLatLon
coordinate.This method exists to not break binary compatibility with old plugins
- Parameters:
latlon
- the position- Returns:
- The point for that position.
- Since:
- 10651
-
getPointFor
public MapViewState.MapViewPoint getPointFor(ILatLon latlon)
Gets theMapViewState.MapViewPoint
for the givenLatLon
coordinate.- Parameters:
latlon
- the position- Returns:
- The point for that position.
- Since:
- 12161
-
getPointFor
public MapViewState.MapViewPoint getPointFor(Node node)
Gets theMapViewState.MapViewPoint
for the given node. This is faster thangetPointFor(LatLon)
because it uses the node east/north cache.- Parameters:
node
- The node- Returns:
- The position of that node.
- Since:
- 10827
-
getViewArea
public MapViewState.MapViewRectangle getViewArea()
Gets a rectangle representing the whole view area.- Returns:
- The rectangle.
-
getViewArea
public MapViewState.MapViewRectangle getViewArea(Rectangle2D rectangle)
Gets a rectangle of the view as map view area.- Parameters:
rectangle
- The rectangle to get.- Returns:
- The view area.
- Since:
- 10827
-
getCenter
public MapViewState.MapViewPoint getCenter()
Gets the center of the view.- Returns:
- The center position.
-
getViewWidth
public double getViewWidth()
Gets the width of the view on the Screen;- Returns:
- The width of the view component in screen pixel.
-
getViewHeight
public double getViewHeight()
Gets the height of the view on the Screen;- Returns:
- The height of the view component in screen pixel.
-
getProjection
public Projection getProjection()
Gets the current projection used for the MapView.- Returns:
- The projection.
- See Also:
getProjecting()
-
getProjecting
public Projecting getProjecting()
Gets the current projecting instance that is used to convert between east/north and lat/lon space.- Returns:
- The projection.
- Since:
- 12161
-
getAffineTransform
public AffineTransform getAffineTransform()
Creates an affine transform that is used to convert the east/north coordinates to view coordinates.- Returns:
- The affine transform. It should not be changed.
- Since:
- 10375
-
getViewClipRectangle
public MapViewState.MapViewRectangle getViewClipRectangle()
Gets a rectangle that is several pixel bigger than the view. It is used to define the view clipping.- Returns:
- The rectangle.
-
getArea
public Area getArea(Bounds bounds)
Returns the area for the given bounds.- Parameters:
bounds
- bounds- Returns:
- the area for the given bounds
-
usingCenter
public MapViewState usingCenter(EastNorth newCenter)
Creates a new state that is the same as the current state except for that it is using a new center.- Parameters:
newCenter
- The new center coordinate.- Returns:
- The new state.
- Since:
- 10375
-
movedTo
public MapViewState movedTo(MapViewState.MapViewPoint mapViewPoint, EastNorth newEastNorthThere)
Creates a new state that is moved to an east/north coordinate.- Parameters:
mapViewPoint
- The reference point.newEastNorthThere
- The east/north coordinate that should be there.- Returns:
- The new state.
- Since:
- 10375
-
usingScale
public MapViewState usingScale(double newScale)
Creates a new state that is the same as the current state except for that it is using a new scale.- Parameters:
newScale
- The new scale to use.- Returns:
- The new state.
- Since:
- 10375
-
usingLocation
public MapViewState usingLocation(JComponent position)
Creates a new state that is the same as the current state except for that it is using the location of the given component.The view is moved so that the center is the same as the old center.
- Parameters:
position
- The new location to use.- Returns:
- The new state.
- Since:
- 10375
-
usingProjection
public MapViewState usingProjection(Projection projection)
Creates a state that uses the projection.- Parameters:
projection
- The projection to use.- Returns:
- The new state.
- Since:
- 10486
-
createDefaultState
public static MapViewState createDefaultState(int width, int height)
Create the defaultMapViewState
object for the given map view. The screen position won't be set so that this method can be used before the view was added to the hierarchy.- Parameters:
width
- The view widthheight
- The view height- Returns:
- The state
- Since:
- 10375
-
calculateDefaultCenter
private static EastNorth calculateDefaultCenter()
-
equalsInWindow
public boolean equalsInWindow(MapViewState other)
Check if this MapViewState equals another one, disregarding the position of the JOSM window on screen.- Parameters:
other
- the other MapViewState- Returns:
- true if the other MapViewState has the same size, scale, position and projection, false otherwise
-
-