Class StyledMapRenderer
- All Implemented Interfaces:
Rendering
- Direct Known Subclasses:
StyledTiledMapRenderer
- Since:
- 486
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis stores a style and a primitive that should be painted with that style. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Objectprivate Supplier<RenderBenchmarkCollector>private doubleprivate static final double(package private) static final intA primitive withAbstractPrimitive.isDisabled()(package private) static final intA primitive withOsmPrimitive.isMemberOfSelected()(package private) static final intFlags used to store the primitive state along with the style.(package private) static final intA primitive withOsmPrimitive.isOuterMemberOfSelected()(package private) static final intA primitive withOsmPrimitive.isSelected()private static final AbstractProperty<Integer>The line with to use for highlightingprivate static final AbstractProperty<Integer>private static final AbstractProperty<Integer>private Colorprivate Collection<WaySegment>private booleanprivate booleanprivate MapPaintSettingsprivate static final doublestatic final AbstractProperty<Boolean>Indicates that the renderer should enable anti-aliasingprivate static final AbstractProperty<Boolean>If we should use left hand traffic.static final AbstractProperty<String>The mode that is used for anti-aliasingprivate doubleprivate booleanprivate booleanprivate static final doubleprivate ElemStylesprivate static final ForkJoinPoolprivate booleanprivate final booleanprivate static final AbstractProperty<Integer>Fields inherited from class org.openstreetmap.josm.data.osm.visitor.paint.AbstractMapRenderer
backgroundColor, doSlowOperations, g, highlightColor, inactiveColor, isInactiveMode, mapState, nc, nodeColor, relationSelectedColor, segmentNumberSpace, selectedColor, virtualNodeSize, virtualNodeSpace -
Constructor Summary
ConstructorsConstructorDescriptionStyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode) Constructs a newStyledMapRenderer.StyledMapRenderer(Graphics2D g, NavigatableComponent nc, boolean isInactiveMode, MapPaintSettings paintSettings) Constructs a newStyledMapRendererwith custom map paint settings. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidappendOnewayPath(boolean onewayReversed, MapViewState.MapViewPoint p1, double nx, double ny, double dist, double onewaySize, Path2D onewayPath) private static voidbuildPFClip(Path2D.Double clip, List<? extends INode> nodes, double extent) Fix the clipping area of unclosed polygons for partial fill.private voidcomputeFill(Shape shape, Float extent, MapViewPath pfClip, float mitterLimit) Fill the given shape.static intcomputeFlags(IPrimitive primitive, boolean checkOuterMember) Computes the flags for a given OSM primitive.private static doublecomputeStartOffset(double phase, double repeat) private voiddisplaySegments(MapViewPath path, Path2D orientationArrows, Path2D onewayArrows, Path2D onewayArrowsCasing, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor) private voiddisplayText(Runnable fill, Supplier<Shape> outline, boolean disabled, TextLabel text) Displays text at specified position including its halo, if applicable.private voiddisplayText(IPrimitive osm, TextLabel text, String name, AffineTransform at) private voiddisplayText(IPrimitive osm, TextLabel text, String name, Rectangle2D nb, MapViewPositionAndRotation center) voiddrawArea(IWay<?> w, Color color, MapImage fillImage, Float extent, Float extentThreshold, boolean disabled) Draws an area defined by a way.voiddrawArea(Relation r, Color color, MapImage fillImage, Float extent, Float extentThreshold, boolean disabled) Draws a multipolygon area.protected voiddrawArea(MapViewPath area, Color color, MapImage fillImage, Float extent, MapViewPath pfClip, boolean disabled) Worker function for drawing areas.voiddrawAreaIcon(IPrimitive osm, MapImage img, boolean disabled, boolean selected, boolean member, double theta, PositionForAreaStrategy iconPosition) Draw the icon for a given area.voiddrawBoxText(INode n, BoxTextElement bs) Draw a text onto a nodeprivate voiddrawIcon(double x, double y, MapImage img, boolean disabled, boolean selected, boolean member, double theta, BiConsumer<Graphics2D, Rectangle2D> selectionDrawer) voidDraw the node as small square with the given color.voiddrawNodeIcon(INode n, MapImage img, boolean disabled, boolean selected, boolean member, double theta) Draw the icon for a given node.voiddrawNodeSymbol(INode n, Symbol s, Color fillColor, Color strokeColor) Draw the symbol and possibly a highlight marking on a given node.voiddrawOrderNumber(INode n1, INode n2, int orderNumber, Color clr) Draw a number of the order of the two consecutive nodes within the parents wayprivate voiddrawPathHighlight(MapViewPath path, BasicStroke line) highlights a given GeneralPath using the settings from BasicStroke to match the line's style.private voiddrawPointHighlight(Point2D p, int size) highlights a given point by drawing a rounded rectangle around it.voiddrawRepeatImage(IWay<?> way, MapImage pattern, boolean disabled, double offset, double spacing, double phase, float opacity, RepeatImageElement.LineImageAlignment align) Draw an image along a way repeatedly.voiddrawRestriction(IRelation<?> r, MapImage icon, boolean disabled) Draw a turn restrictionvoiddrawText(IPrimitive osm, TextLabel text, PositionForAreaStrategy labelPositionStrategy) Draws a text for the given primitivevoiddrawWay(IWay<?> way, Color color, BasicStroke line, BasicStroke dashes, Color dashedColor, float offset, boolean showOrientation, boolean showHeadArrowOnly, boolean showOneway, boolean onewayReversed) draw way.private voidforEachPolygon(IPrimitive osm, Consumer<MapViewPath> consumer) Calls a consumer for each path of the area shape-doubleGets the "circum".voidReads the color definitions from preferences.private MapViewPathprivate static Path2D.Doubleprivate static Path2D.DoublegetPFClip(Multipolygon.PolyData pd, double extent) private static EastNorthgetPFDisplacedEndPoint(EastNorth p1, EastNorth p2, EastNorth p3, double extent) Get the point to add to the clipping area for partial fill of unclosed polygons.private ColorgetSelectionHintColor(boolean disabled, boolean selected) voidgetSettings(boolean virtual) Reads all the settings from preferences.private booleanisAreaVisible(Path2D.Double area) Test if the area is visiblestatic booleanCheck, if this System has the GlyphVector double translation bug.booleanDetermines if the paint visitor shall render OSM objects such that they look inactive.booleanCheck if icons should be renderedbooleanTest if names should be renderedprivate static ForkJoinPoolprivate voidpaintRecord(StyledMapRenderer.StyleRecord styleRecord) private voidpaintWithLock(OsmData<?, ?, ?, ?> data, boolean renderVirtualNodes, RenderBenchmarkCollector benchmark, BBox bbox) voidRenders the OSM data indatavoidsetBenchmarkFactory(Supplier<RenderBenchmarkCollector> benchmarkFactory) Sets the factory that creates the benchmark data receivers.voidsetStyles(ElemStyles styles) Set theElemStylesinstance to use for this renderer.private MapViewPathConvert shape in EastNorth coordinates to MapViewPath and remove invisible parts.private booleanusePartialFill(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.Methods inherited from class org.openstreetmap.josm.data.osm.visitor.paint.AbstractMapRenderer
drawOrderNumber, drawVirtualNodes, enableSlowOperations, isLargeSegment, isSegmentVisible, isSegmentVisible, visitVirtual
-
Field Details
-
THREAD_POOL
-
IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG
-
circum
-
scale
-
paintSettings
-
styles
-
highlightColorTransparent
-
FLAG_NORMAL
Flags used to store the primitive state along with the style. This is the normal style.Not used in any public interfaces.
- See Also:
-
FLAG_DISABLED
A primitive withAbstractPrimitive.isDisabled()- See Also:
-
FLAG_MEMBER_OF_SELECTED
A primitive withOsmPrimitive.isMemberOfSelected()- See Also:
-
FLAG_SELECTED
A primitive withOsmPrimitive.isSelected()- See Also:
-
FLAG_OUTERMEMBER_OF_SELECTED
A primitive withOsmPrimitive.isOuterMemberOfSelected()- See Also:
-
PHI
-
cosPHI
-
sinPHI
-
PREFERENCE_LEFT_HAND_TRAFFIC
If we should use left hand traffic. -
PREFERENCE_ANTIALIASING_USE
Indicates that the renderer should enable anti-aliasing- Since:
- 11758
-
PREFERENCE_TEXT_ANTIALIASING
The mode that is used for anti-aliasing- Since:
- 11758
-
HIGHLIGHT_LINE_WIDTH
The line with to use for highlighting -
HIGHLIGHT_POINT_RADIUS
-
WIDER_HIGHLIGHT
-
HIGHLIGHT_STEP
-
highlightWaySegments
-
useWiderHighlight
-
useStrokes
-
showNames
-
showIcons
-
isOutlineOnly
-
leftHandTraffic
-
antialiasing
-
benchmarkFactory
-
-
Constructor Details
-
Method Details
-
newForkJoinPool
-
isGlyphVectorDoubleTranslationBug
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
Set theElemStylesinstance to use for this renderer.- Parameters:
styles- theElemStylesinstance 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 polygonscolor- 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 completelypfClip- clipping area for partial fill (only needed for unclosed polygons)disabled- If this should be drawn with a special disabled style.
-
computeFill
Fill the given shape. If partial fill is used, computes the clipping.- Parameters:
shape- the given shapeextent- 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 completelypfClip- 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 relationcolor- 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 completelyextentThreshold- if not null, determines if the partial filled should be replaced by plain fill, when it covers a certain fraction of the total areadisabled- 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 completelyextentThreshold- if not null, determines if the partial filled should be replaced by plain fill, when it covers a certain fraction of the total areadisabled- If this should be drawn with a special disabled style.- Since:
- 12285
-
usePartialFill
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 objectextent- the "width" of partial fillthreshold- 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 asperimeter * extent- Returns:
- true, if the partial fill should be used, false otherwise
-
drawBoxText
Draw a text onto a node- Parameters:
n- The node to draw the text onbs- 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 waypattern- the imagedisabled- If this should be drawn with a special disabled style.offset- offset from the wayspacing- spacing between two imagesphase- initial spacingopacity- the opacityalign- alignment of the image. The top, center or bottom edge can be aligned with the way.
-
computeStartOffset
-
drawNode
Description copied from class:AbstractMapRendererDraw the node as small square with the given color.- Specified by:
drawNodein classAbstractMapRenderer- Parameters:
n- The node to draw.color- The color of the node.size- size in pixelsfill- 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 nodeimg- The icon to draw at the node positiondisabled- true to render disabled version,falsefor the standard versionselected- true to render it as selected,falseotherwisemember- true to render it as a relation member,falseotherwisetheta- 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 forimg- The icon to drawdisabled- true to render disabled version,falsefor the standard versionselected- true to render it as selected,falseotherwisemember- true to render it as a relation member,falseotherwisetheta- the angle of rotation in radiansiconPosition- 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
-
drawNodeSymbol
Draw the symbol and possibly a highlight marking on a given node.- Parameters:
n- The position to draw the symbol ons- The symbol to drawfillColor- The color to fill the symbol withstrokeColor- The color to use for the outer corner of the symbol
-
drawOrderNumber
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
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 drawline- line style
-
drawPointHighlight
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- pointsize- highlight size
-
drawRestriction
Draw a turn restriction- Parameters:
r- The turn restriction relationicon- The icon to draw at the turn pointdisabled- draw using disabled style
-
drawText
Draws a text for the given primitive- Parameters:
osm- The primitive to draw the text fortext- The text definition (font/position/.../text content) to drawlabelPositionStrategy- The position of the text- Since:
- 11722
-
displayText
private void displayText(IPrimitive osm, TextLabel text, String name, Rectangle2D nb, MapViewPositionAndRotation center) -
displayText
-
displayText
Displays text at specified position including its halo, if applicable.- Parameters:
fill- The function that fills the textoutline- The function to draw the outlinedisabled-trueif element is disabled (filtered out)text- text style to use
-
forEachPolygon
Calls a consumer for each path of the area shape-- Parameters:
osm- A way or a multipolygonconsumer- 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 drawcolor- The base color to draw the way inline- The line style to use. This is drawn using color.dashes- The dash style to use. This is drawn using dashedColor.nullif unused.dashedColor- The color of the dashes.offset- The offsetshowOrientation- 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 waterwayonewayReversed- 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
Gets the "circum". This is the distance on the map in meters that 100 screen pixels represent.- Returns:
- The "circum"
-
getColors
Description copied from class:AbstractMapRendererReads the color definitions from preferences. This function ispublic, so that color names in preferences can be displayed even without calling the wireframe display before.- Overrides:
getColorsin classAbstractMapRenderer
-
getSettings
Description copied from class:AbstractMapRendererReads all the settings from preferences. Calls theAbstractMapRenderer.getColors()function.- Overrides:
getSettingsin classAbstractMapRenderer- Parameters:
virtual-trueif virtual nodes are used
-
getPath
-
getPFClip
-
getPFClip
-
buildPFClip
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 polygonextent- 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 andp3the opposite endpoint.- Parameters:
p1- 1st pointp2- 2nd pointp3- 3rd pointextent- 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
Test if the area is visible- Parameters:
area- The area, interpreted in east/north space.- Returns:
- true if it is visible.
-
isInactiveMode
Determines if the paint visitor shall render OSM objects such that they look inactive.- Returns:
trueif the paint visitor shall render OSM objects such that they look inactive
-
isShowIcons
Check if icons should be rendered- Returns:
trueto display icons
-
isShowNames
Test if names should be rendered- Returns:
trueto display names
-
computeFlags
Computes the flags for a given OSM primitive.- Parameters:
primitive- The primititve to compute the flags for.checkOuterMember-trueif we should also addFLAG_OUTERMEMBER_OF_SELECTED- Returns:
- The flag.
- Since:
- 13676 (signature)
-
setBenchmarkFactory
Sets the factory that creates the benchmark data receivers.- Parameters:
benchmarkFactory- The factory.- Since:
- 10697
-
render
Description copied from interface:RenderingRenders the OSM data in
data- Parameters:
data- the data set to be renderedrenderVirtualNodes- if true, renders virtual nodes. Otherwise, ignores them.bounds- the bounding box for the data to be rendered. Only objects within or intersecting withbboxare rendered
-
paintWithLock
private void paintWithLock(OsmData<?, ?, ?, ?> data, boolean renderVirtualNodes, RenderBenchmarkCollector benchmark, BBox bbox) -
paintRecord
-