Class StyledMapRenderer

java.lang.Object
org.openstreetmap.josm.data.osm.visitor.paint.AbstractMapRenderer
org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer
All Implemented Interfaces:
Rendering
Direct Known Subclasses:
StyledTiledMapRenderer

A map renderer which renders a map according to style rules in a set of style sheets.
Since:
486
  • Field Details

  • Constructor Details

    • StyledMapRenderer

      public StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode)
      Constructs a new StyledMapRenderer.
      Parameters:
      g - the graphics context. Must not be null.
      nc - the map viewport. Must not be null.
      isInactiveMode - if true, the paint visitor shall render OSM objects such that they look inactive. Example: rendering of data in an inactive layer using light gray as color only.
      Throws:
      IllegalArgumentException - if g is null
      IllegalArgumentException - if nc is null
    • StyledMapRenderer

      public StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode, MapPaintSettings paintSettings)
      Constructs a new StyledMapRenderer with custom map paint settings.
      Parameters:
      g - the graphics context. Must not be null.
      nc - the map viewport. Must not be null.
      isInactiveMode - if true, the paint visitor shall render OSM objects such that they look inactive. Example: rendering of data in an inactive layer using light gray as color only.
      paintSettings - the map paint settings to use. Must not be null.
      Throws:
      IllegalArgumentException - if g is null
      IllegalArgumentException - if nc is null
      IllegalArgumentException - if paintSettings is null
      Since:
      19549
  • Method Details

    • newForkJoinPool

      private static ForkJoinPool newForkJoinPool()
    • isGlyphVectorDoubleTranslationBug

      public static boolean isGlyphVectorDoubleTranslationBug(Font font)
      Check, if this System has the GlyphVector double translation bug.

      With this bug, gv.setGlyphTransform(i, trfm) has a different effect than on most other systems, namely the translation components ("m02" & "m12", AffineTransform) appear to be twice as large, as they actually are. The rotation is unaffected (scale & shear not tested so far).

      This bug has only been observed on Mac OS X, see #7841.

      After switch to Java 7, this test is a false positive on Mac OS X (see #10446), i.e. it returns true, but the real rendering code does not require any special handling. It hasn't been further investigated why the test reports a wrong result in this case, but the method has been changed to simply return false by default. (This can be changed with a setting in the advanced preferences.)

      Parameters:
      font - The font to check.
      Returns:
      false by default, but depends on the value of the advanced preference glyph-bug=false|true|auto, where auto is the automatic detection method which apparently no longer gives a useful result for Java 7.
    • setStyles

      public void setStyles(ElemStyles styles)
      Set the ElemStyles instance to use for this renderer.
      Parameters:
      styles - the ElemStyles instance to use
    • displaySegments

      private void displaySegments(MapViewPath path, Path2D orientationArrows, Path2D onewayArrows, Path2D onewayArrowsCasing, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor)
    • drawArea

      protected void drawArea(MapViewPath area, Color color, MapImage fillImage, Float extent, MapViewPath pfClip, boolean disabled)
      Worker function for drawing areas.
      Parameters:
      area - the path object for the area that should be drawn; in case of multipolygons, this can path can be a complex shape with one outer polygon and one or more inner polygons
      color - The color to fill the area with.
      fillImage - The image to fill the area with. Overrides color.
      extent - if not null, area will be filled partially; specifies, how far to fill from the boundary towards the center of the area; if null, area will be filled completely
      pfClip - clipping area for partial fill (only needed for unclosed polygons)
      disabled - If this should be drawn with a special disabled style.
    • computeFill

      private void computeFill(Shape shape, Float extent, MapViewPath pfClip, float mitterLimit)
      Fill the given shape. If partial fill is used, computes the clipping.
      Parameters:
      shape - the given shape
      extent - if not null, area will be filled partially; specifies, how far to fill from the boundary towards the center of the area; if null, area will be filled completely
      pfClip - clipping area for partial fill (only needed for unclosed polygons)
      mitterLimit - parameter for BasicStroke
    • drawArea

      public void drawArea(Relation r, Color color, MapImage fillImage, Float extent, Float extentThreshold, boolean disabled)
      Draws a multipolygon area.
      Parameters:
      r - The multipolygon relation
      color - The color to fill the area with.
      fillImage - The image to fill the area with. Overrides color.
      extent - if not null, area will be filled partially; specifies, how far to fill from the boundary towards the center of the area; if null, area will be filled completely
      extentThreshold - if not null, determines if the partial filled should be replaced by plain fill, when it covers a certain fraction of the total area
      disabled - If this should be drawn with a special disabled style.
      Since:
      12285
    • shapeEastNorthToMapView

      Convert shape in EastNorth coordinates to MapViewPath and remove invisible parts. For complex shapes this improves performance drastically because the methods in Graphics2D.clip() and Graphics2D.draw() are rather slow.
      Parameters:
      shape - the shape to convert
      Returns:
      the converted shape
    • drawArea

      public void drawArea(IWay<?> w, Color color, MapImage fillImage, Float extent, Float extentThreshold, boolean disabled)
      Draws an area defined by a way. They way does not need to be closed, but it should.
      Parameters:
      w - The way.
      color - The color to fill the area with.
      fillImage - The image to fill the area with. Overrides color.
      extent - if not null, area will be filled partially; specifies, how far to fill from the boundary towards the center of the area; if null, area will be filled completely
      extentThreshold - if not null, determines if the partial filled should be replaced by plain fill, when it covers a certain fraction of the total area
      disabled - If this should be drawn with a special disabled style.
      Since:
      12285
    • usePartialFill

      private boolean usePartialFill(Geometry.AreaAndPerimeter ap, float extent, Float threshold)
      Determine, if partial fill should be turned off for this object, because only a small unfilled gap in the center of the area would be left.

      This is used to get a cleaner look for urban regions with many small areas like buildings, etc.

      Parameters:
      ap - the area and the perimeter of the object
      extent - the "width" of partial fill
      threshold - when the partial fill covers that much of the total area, the partial fill is turned off; can be greater than 100% as the covered area is estimated as perimeter * extent
      Returns:
      true, if the partial fill should be used, false otherwise
    • drawBoxText

      public void drawBoxText(INode n, BoxTextElement bs)
      Draw a text onto a node
      Parameters:
      n - The node to draw the text on
      bs - The text and it's alignment.
    • drawRepeatImage

      public void drawRepeatImage(IWay<?> way, MapImage pattern, boolean disabled, double offset, double spacing, double phase, float opacity, RepeatImageElement.LineImageAlignment align)
      Draw an image along a way repeatedly.
      Parameters:
      way - the way
      pattern - the image
      disabled - If this should be drawn with a special disabled style.
      offset - offset from the way
      spacing - spacing between two images
      phase - initial spacing
      opacity - the opacity
      align - alignment of the image. The top, center or bottom edge can be aligned with the way.
    • computeStartOffset

      private static double computeStartOffset(double phase, double repeat)
    • drawNode

      public void drawNode(INode n, Color color, int size, boolean fill)
      Description copied from class: AbstractMapRenderer
      Draw the node as small square with the given color.
      Specified by:
      drawNode in class AbstractMapRenderer
      Parameters:
      n - The node to draw.
      color - The color of the node.
      size - size in pixels
      fill - determines if the square must be filled
    • drawNodeIcon

      public void drawNodeIcon(INode n, MapImage img, boolean disabled, boolean selected, boolean member, double theta)
      Draw the icon for a given node.
      Parameters:
      n - The node
      img - The icon to draw at the node position
      disabled - true to render disabled version, false for the standard version
      selected - true to render it as selected, false otherwise
      member - true to render it as a relation member, false otherwise
      theta - the angle of rotation in radians
    • drawAreaIcon

      public void drawAreaIcon(IPrimitive osm, MapImage img, boolean disabled, boolean selected, boolean member, double theta, PositionForAreaStrategy iconPosition)
      Draw the icon for a given area. Normally, the icon is drawn around the center of the area.
      Parameters:
      osm - The primitive to draw the icon for
      img - The icon to draw
      disabled - true to render disabled version, false for the standard version
      selected - true to render it as selected, false otherwise
      member - true to render it as a relation member, false otherwise
      theta - the angle of rotation in radians
      iconPosition - Where to place the icon.
      Since:
      11670
    • drawIcon

      private void drawIcon(double x, double y, MapImage img, boolean disabled, boolean selected, boolean member, double theta, BiConsumer<Graphics2D,Rectangle2D> selectionDrawer)
    • getSelectionHintColor

      private Color getSelectionHintColor(boolean disabled, boolean selected)
    • drawNodeSymbol

      public void drawNodeSymbol(INode n, Symbol s, Color fillColor, Color strokeColor)
      Draw the symbol and possibly a highlight marking on a given node.
      Parameters:
      n - The position to draw the symbol on
      s - The symbol to draw
      fillColor - The color to fill the symbol with
      strokeColor - The color to use for the outer corner of the symbol
    • drawOrderNumber

      public void drawOrderNumber(INode n1, INode n2, int orderNumber, Color clr)
      Draw a number of the order of the two consecutive nodes within the parents way
      Parameters:
      n1 - First node of the way segment.
      n2 - Second node of the way segment.
      orderNumber - The number of the segment in the way.
      clr - The color to use for drawing the text.
    • drawPathHighlight

      private void drawPathHighlight(MapViewPath path, BasicStroke line)
      highlights a given GeneralPath using the settings from BasicStroke to match the line's style. Width of the highlight can be changed by user preferences
      Parameters:
      path - path to draw
      line - line style
    • drawPointHighlight

      private void drawPointHighlight(Point2D p, int size)
      highlights a given point by drawing a rounded rectangle around it. Give the size of the object you want to be highlighted, width is added automatically.
      Parameters:
      p - point
      size - highlight size
    • drawRestriction

      public void drawRestriction(IRelation<?> r, MapImage icon, boolean disabled)
      Draw a turn restriction
      Parameters:
      r - The turn restriction relation
      icon - The icon to draw at the turn point
      disabled - draw using disabled style
    • drawText

      public void drawText(IPrimitive osm, TextLabel text, PositionForAreaStrategy labelPositionStrategy)
      Draws a text for the given primitive
      Parameters:
      osm - The primitive to draw the text for
      text - The text definition (font/position/.../text content) to draw
      labelPositionStrategy - The position of the text
      Since:
      11722
    • displayText

      private void displayText(IPrimitive osm, TextLabel text, String name, Rectangle2D nb, MapViewPositionAndRotation center)
    • displayText

      private void displayText(IPrimitive osm, TextLabel text, String name, AffineTransform at)
    • displayText

      private void displayText(Runnable fill, Supplier<Shape> outline, boolean disabled, TextLabel text)
      Displays text at specified position including its halo, if applicable.
      Parameters:
      fill - The function that fills the text
      outline - The function to draw the outline
      disabled - true if element is disabled (filtered out)
      text - text style to use
    • forEachPolygon

      private void forEachPolygon(IPrimitive osm, Consumer<MapViewPath> consumer)
      Calls a consumer for each path of the area shape-
      Parameters:
      osm - A way or a multipolygon
      consumer - The consumer to call.
    • drawWay

      public void drawWay(IWay<?> way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, float offset, boolean showOrientation, boolean showHeadArrowOnly, boolean showOneway, boolean onewayReversed)
      draw way. This method allows for two draw styles (line using color, dashes using dashedColor) to be passed.
      Parameters:
      way - The way to draw
      color - The base color to draw the way in
      line - The line style to use. This is drawn using color.
      dashes - The dash style to use. This is drawn using dashedColor. null if unused.
      dashedColor - The color of the dashes.
      offset - The offset
      showOrientation - show arrows that indicate the technical orientation of the way (defined by order of nodes)
      showHeadArrowOnly - True if only the arrow at the end of the line but not those on the segments should be displayed.
      showOneway - show symbols that indicate the direction of the feature, e.g. oneway street or waterway
      onewayReversed - for oneway=-1 and similar
    • appendOnewayPath

      private static void appendOnewayPath(boolean onewayReversed, MapViewState.MapViewPoint p1, double nx, double ny, double dist, double onewaySize, Path2D onewayPath)
    • getCircum

      public double getCircum()
      Gets the "circum". This is the distance on the map in meters that 100 screen pixels represent.
      Returns:
      The "circum"
    • getColors

      public void getColors()
      Description copied from class: AbstractMapRenderer
      Reads the color definitions from preferences. This function is public, so that color names in preferences can be displayed even without calling the wireframe display before.
      Overrides:
      getColors in class AbstractMapRenderer
    • getSettings

      public void getSettings(boolean virtual)
      Description copied from class: AbstractMapRenderer
      Reads all the settings from preferences. Calls the AbstractMapRenderer.getColors() function.
      Overrides:
      getSettings in class AbstractMapRenderer
      Parameters:
      virtual - true if virtual nodes are used
    • getPath

      private MapViewPath getPath(IWay<?> w)
    • getPFClip

      private static Path2D.Double getPFClip(IWay<?> w, double extent)
    • getPFClip

      private static Path2D.Double getPFClip(Multipolygon.PolyData pd, double extent)
    • buildPFClip

      private static void buildPFClip(Path2D.Double clip, List<? extends INode> nodes, double extent)
      Fix the clipping area of unclosed polygons for partial fill.

      The current algorithm for partial fill simply strokes the polygon with a large stroke width after masking the outside with a clipping area. This works, but for unclosed polygons, the mask can crop the corners at both ends (see #12104).

      This method fixes the clipping area by sort of adding the corners to the clip outline.

      Parameters:
      clip - the clipping area to modify (initially empty)
      nodes - nodes of the polygon
      extent - the extent
    • getPFDisplacedEndPoint

      private static EastNorth getPFDisplacedEndPoint(EastNorth p1, EastNorth p2, EastNorth p3, double extent)
      Get the point to add to the clipping area for partial fill of unclosed polygons.

      (p1,p2) is the first or last way segment and p3 the opposite endpoint.

      Parameters:
      p1 - 1st point
      p2 - 2nd point
      p3 - 3rd point
      extent - the extent
      Returns:
      a point q, such that p1,p2,q form a right angle and the distance of q to p2 is extent. The point q lies on the same side of the line p1,p2 as the point p3. Returns null if p1,p2,p3 forms an angle greater 90 degrees. (In this case the corner of the partial fill would not be cut off by the mask, so an additional point is not necessary.)
    • isAreaVisible

      private boolean isAreaVisible(Path2D.Double area)
      Test if the area is visible
      Parameters:
      area - The area, interpreted in east/north space.
      Returns:
      true if it is visible.
    • isInactiveMode

      public boolean isInactiveMode()
      Determines if the paint visitor shall render OSM objects such that they look inactive.
      Returns:
      true if the paint visitor shall render OSM objects such that they look inactive
    • isShowIcons

      public boolean isShowIcons()
      Check if icons should be rendered
      Returns:
      true to display icons
    • isShowNames

      public boolean isShowNames()
      Test if names should be rendered
      Returns:
      true to display names
    • computeFlags

      public static int computeFlags(IPrimitive primitive, boolean checkOuterMember)
      Computes the flags for a given OSM primitive.
      Parameters:
      primitive - The primititve to compute the flags for.
      checkOuterMember - true if we should also add FLAG_OUTERMEMBER_OF_SELECTED
      Returns:
      The flag.
      Since:
      13676 (signature)
    • setBenchmarkFactory

      public void setBenchmarkFactory(Supplier<RenderBenchmarkCollector> benchmarkFactory)
      Sets the factory that creates the benchmark data receivers.
      Parameters:
      benchmarkFactory - The factory.
      Since:
      10697
    • render

      public void render(OsmData<?,?,?,?> data, boolean renderVirtualNodes, Bounds bounds)
      Description copied from interface: Rendering

      Renders the OSM data in data

      Parameters:
      data - the data set to be rendered
      renderVirtualNodes - if true, renders virtual nodes. Otherwise, ignores them.
      bounds - the bounding box for the data to be rendered. Only objects within or intersecting with bbox are rendered
    • paintWithLock

      private void paintWithLock(OsmData<?,?,?,?> data, boolean renderVirtualNodes, RenderBenchmarkCollector benchmark, BBox bbox)
    • paintRecord

      private void paintRecord(StyledMapRenderer.StyleRecord styleRecord)