Package org.openstreetmap.josm.gui.draw
Class MapViewPath
- java.lang.Object
-
- java.awt.geom.Path2D
-
- java.awt.geom.Path2D.Double
-
- org.openstreetmap.josm.gui.draw.MapPath2D
-
- org.openstreetmap.josm.gui.draw.MapViewPath
-
- All Implemented Interfaces:
java.awt.Shape
,java.io.Serializable
,java.lang.Cloneable
public class MapViewPath extends MapPath2D
This is a version of a java Path2D that allows you to add points to it by simply giving their east/north, lat/lon or node coordinates.It is possible to clip the part of the path that is outside the view. This is useful when drawing dashed lines. Those lines use up a lot of performance if the zoom level is high and the part outside the view is long. See
computeClippedLine(Stroke)
.- Since:
- 10875
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
MapViewPath.AbstractMapPathVisitor
private class
MapViewPath.ClampingPathVisitor
private class
MapViewPath.LineVisitor
private class
MapViewPath.OffsetPathVisitor
static interface
MapViewPath.PathSegmentConsumer
This class is used to visit the segments of this path.private static interface
MapViewPath.PathVisitor
-
Field Summary
Fields Modifier and Type Field Description private MapViewState
state
-
Constructor Summary
Constructors Constructor Description MapViewPath(MapView mv)
Create a new pathMapViewPath(MapViewState state)
Create a new path
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MapViewPath
append(java.lang.Iterable<? extends ILatLon> nodes, boolean connect)
Append a list of nodesMapViewPath
appendClosed(java.lang.Iterable<? extends ILatLon> nodes, boolean connect)
Append a list of nodes as closed way.void
appendFromEastNorth(java.awt.geom.Path2D.Double path)
Converts a path in east/north coordinates to view space.private void
appendWay(java.lang.Iterable<? extends ILatLon> nodes, boolean connect, boolean close)
java.awt.Shape
computeClippedLine(java.awt.Stroke stroke)
Compute a line that is similar to the current path expect for that parts outside the screen are skipped using moveTo commands.double
getLength()
Gets the length of the way in visual space.MapViewState
getMapViewState()
Gets the map view state this path is used for.MapViewPath
lineTo(EastNorth eastNorth)
Draw a line to the position.MapViewPath
lineTo(ILatLon n)
Draw a line to the node.MapViewPath
lineTo(MapViewState.MapViewPoint p)
Draw a line to the view position of given pointMapViewPath
moveTo(EastNorth eastNorth)
Move the cursor to the given position.MapViewPath
moveTo(ILatLon n)
Move the cursor to the given node.MapViewPath
moveTo(MapViewState.MapViewPoint p)
Move the path to the view position of given pointMapViewPath
offset(double viewOffset)
Create a newMapViewPath
that is the same as the current one except that it is offset in the view.MapViewPath
shapeAround(EastNorth eastNorth, SymbolShape symbol, double size)
Add the given shape centered around the current position.MapViewPath
shapeAround(ILatLon p1, SymbolShape symbol, double size)
Add the given shape centered around the current node.MapViewPath
shapeAround(MapViewState.MapViewPoint p, SymbolShape symbol, double size)
Add the given shape centered around the given pointboolean
visitClippedLine(double strokeLength, MapViewPath.PathSegmentConsumer consumer)
Visits all straight segments of this path.boolean
visitClippedLine(java.awt.Stroke stroke, MapViewPath.PathSegmentConsumer consumer)
Visits all straight segments of this path.double
visitLine(MapViewPath.PathSegmentConsumer consumer)
Visits all segments of this path.-
Methods inherited from class java.awt.geom.Path2D.Double
append, clone, curveTo, getBounds2D, getPathIterator, lineTo, moveTo, quadTo, transform, trimToSize
-
Methods inherited from class java.awt.geom.Path2D
append, closePath, contains, contains, contains, contains, contains, contains, contains, contains, createTransformedShape, getBounds, getCurrentPoint, getPathIterator, getWindingRule, intersects, intersects, intersects, intersects, reset, setWindingRule
-
-
-
-
Field Detail
-
state
private final MapViewState state
-
-
Constructor Detail
-
MapViewPath
public MapViewPath(MapView mv)
Create a new path- Parameters:
mv
- The map view to use for coordinate conversion.
-
MapViewPath
public MapViewPath(MapViewState state)
Create a new path- Parameters:
state
- The state to use for coordinate conversion.
-
-
Method Detail
-
getMapViewState
public MapViewState getMapViewState()
Gets the map view state this path is used for.- Returns:
- The state.
- Since:
- 11748
-
moveTo
public MapViewPath moveTo(ILatLon n)
Move the cursor to the given node.- Parameters:
n
- The node- Returns:
- this for easy chaining.
-
moveTo
public MapViewPath moveTo(EastNorth eastNorth)
Move the cursor to the given position.- Parameters:
eastNorth
- The position- Returns:
- this for easy chaining.
-
moveTo
public MapViewPath moveTo(MapViewState.MapViewPoint p)
Description copied from class:MapPath2D
Move the path to the view position of given point
-
lineTo
public MapViewPath lineTo(ILatLon n)
Draw a line to the node.line clamping to view is done automatically.
- Parameters:
n
- The node- Returns:
- this for easy chaining.
-
lineTo
public MapViewPath lineTo(EastNorth eastNorth)
Draw a line to the position.line clamping to view is done automatically.
- Parameters:
eastNorth
- The position- Returns:
- this for easy chaining.
-
lineTo
public MapViewPath lineTo(MapViewState.MapViewPoint p)
Description copied from class:MapPath2D
Draw a line to the view position of given point
-
shapeAround
public MapViewPath shapeAround(ILatLon p1, SymbolShape symbol, double size)
Add the given shape centered around the current node.- Parameters:
p1
- The point to draw aroundsymbol
- The symbol typesize
- The size of the symbol in pixel- Returns:
- this for easy chaining.
-
shapeAround
public MapViewPath shapeAround(EastNorth eastNorth, SymbolShape symbol, double size)
Add the given shape centered around the current position.- Parameters:
eastNorth
- The point to draw aroundsymbol
- The symbol typesize
- The size of the symbol in pixel- Returns:
- this for easy chaining.
-
shapeAround
public MapViewPath shapeAround(MapViewState.MapViewPoint p, SymbolShape symbol, double size)
Description copied from class:MapPath2D
Add the given shape centered around the given point- Overrides:
shapeAround
in classMapPath2D
- Parameters:
p
- The point to draw aroundsymbol
- The symbol typesize
- The size of the symbol in pixel- Returns:
- this for easy chaining.
-
append
public MapViewPath append(java.lang.Iterable<? extends ILatLon> nodes, boolean connect)
Append a list of nodes- Parameters:
nodes
- The nodes to appendconnect
-true
if we should use a lineTo as first command.- Returns:
- this for easy chaining.
-
appendClosed
public MapViewPath appendClosed(java.lang.Iterable<? extends ILatLon> nodes, boolean connect)
Append a list of nodes as closed way.- Parameters:
nodes
- The nodes to appendconnect
-true
if we should use a lineTo as first command.- Returns:
- this for easy chaining.
-
appendWay
private void appendWay(java.lang.Iterable<? extends ILatLon> nodes, boolean connect, boolean close)
-
appendFromEastNorth
public void appendFromEastNorth(java.awt.geom.Path2D.Double path)
Converts a path in east/north coordinates to view space.- Parameters:
path
- The path- Since:
- 11748
-
visitLine
public double visitLine(MapViewPath.PathSegmentConsumer consumer)
Visits all segments of this path.- Parameters:
consumer
- The consumer to send path segments to- Returns:
- the total line length
- Since:
- 11748
-
computeClippedLine
public java.awt.Shape computeClippedLine(java.awt.Stroke stroke)
Compute a line that is similar to the current path expect for that parts outside the screen are skipped using moveTo commands. The line is computed in a way that dashes stay in their place when moving the view. The resulting line is not intended to fill areas.- Parameters:
stroke
- The stroke to compute the line for.- Returns:
- The new line shape.
- Since:
- 11147
-
visitClippedLine
public boolean visitClippedLine(java.awt.Stroke stroke, MapViewPath.PathSegmentConsumer consumer)
Visits all straight segments of this path. The segments are clamped to the view. If they are clamped, the start points are aligned with the pattern.- Parameters:
stroke
- The stroke to take the dash information from.consumer
- The consumer to call for each segment- Returns:
- false if visiting the path failed because there e.g. were non-straight segments.
- Since:
- 11147
-
visitClippedLine
public boolean visitClippedLine(double strokeLength, MapViewPath.PathSegmentConsumer consumer)
Visits all straight segments of this path. The segments are clamped to the view. If they are clamped, the start points are aligned with the pattern.- Parameters:
strokeLength
- The dash pattern length. 0 to use no pattern. Only segments of this length will be removed from the line.consumer
- The consumer to call for each segment- Returns:
- false if visiting the path failed because there e.g. were non-straight segments.
- Since:
- 11147
-
getLength
public double getLength()
Gets the length of the way in visual space.- Returns:
- The length.
- Since:
- 11748
-
offset
public MapViewPath offset(double viewOffset)
Create a newMapViewPath
that is the same as the current one except that it is offset in the view.- Parameters:
viewOffset
- The offset in view pixels- Returns:
- The new path
- Since:
- 12505
-
-