Class MapViewPath

All Implemented Interfaces:
Shape, Serializable, 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:
  • Field Details

  • Constructor Details

    • 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 Details

    • getMapViewState

      Gets the map view state this path is used for.
      Returns:
      The state.
      Since:
      11748
    • moveTo

      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

      Description copied from class: MapPath2D
      Move the path to the view position of given point
      Overrides:
      moveTo in class MapPath2D
      Parameters:
      p - The point
      Returns:
      this for easy chaining.
    • lineTo

      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

      Description copied from class: MapPath2D
      Draw a line to the view position of given point
      Overrides:
      lineTo in class MapPath2D
      Parameters:
      p - The point
      Returns:
      this for easy chaining.
    • 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 around
      symbol - The symbol type
      size - 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 around
      symbol - The symbol type
      size - 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 class MapPath2D
      Parameters:
      p - The point to draw around
      symbol - The symbol type
      size - The size of the symbol in pixel
      Returns:
      this for easy chaining.
    • append

      public MapViewPath append(Iterable<? extends ILatLon> nodes, boolean connect)
      Append a list of nodes
      Parameters:
      nodes - The nodes to append
      connect - true if we should use a lineTo as first command.
      Returns:
      this for easy chaining.
    • appendClosed

      public MapViewPath appendClosed(Iterable<? extends ILatLon> nodes, boolean connect)
      Append a list of nodes as closed way.
      Parameters:
      nodes - The nodes to append
      connect - true if we should use a lineTo as first command.
      Returns:
      this for easy chaining.
    • appendWay

      private void appendWay(Iterable<? extends ILatLon> nodes, boolean connect, boolean close)
    • appendFromEastNorth

      public void appendFromEastNorth(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 Shape computeClippedLine(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(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 new MapViewPath 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