public class StyledMapRenderer extends AbstractMapRenderer
Modifier and Type | Class and Description |
---|---|
static class |
StyledMapRenderer.StyleRecord
This stores a style and a primitive that should be painted with that style.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
antialiasing |
private java.util.function.Supplier<RenderBenchmarkCollector> |
benchmarkFactory |
private double |
circum |
private static double |
cosPHI |
(package private) static int |
FLAG_DISABLED
A primitive with
OsmPrimitive.isDisabled() |
(package private) static int |
FLAG_MEMBER_OF_SELECTED
A primitive with
OsmPrimitive.isMemberOfSelected() |
(package private) static int |
FLAG_NORMAL
Flags used to store the primitive state along with the style.
|
(package private) static int |
FLAG_OUTERMEMBER_OF_SELECTED
A primitive with
OsmPrimitive.isOuterMemberOfSelected() |
(package private) static int |
FLAG_SELECTED
A primitive with
OsmPrimitive.isSelected() |
private static AbstractProperty<java.lang.Integer> |
HIGHLIGHT_LINE_WIDTH
The line with to use for highlighting
|
private static AbstractProperty<java.lang.Integer> |
HIGHLIGHT_POINT_RADIUS |
private static AbstractProperty<java.lang.Integer> |
HIGHLIGHT_STEP |
private java.awt.Color |
highlightColorTransparent |
private java.util.Collection<WaySegment> |
highlightWaySegments |
private static java.util.Map<java.awt.Font,java.lang.Boolean> |
IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG |
private boolean |
isOutlineOnly |
private boolean |
leftHandTraffic |
private MapPaintSettings |
paintSettings |
private static double |
PHI |
static AbstractProperty<java.lang.Boolean> |
PREFERENCE_ANTIALIASING_USE
Indicates that the renderer should enable anti-aliasing
|
private static AbstractProperty<java.lang.Boolean> |
PREFERENCE_LEFT_HAND_TRAFFIC
If we should use left hand traffic.
|
static AbstractProperty<java.lang.String> |
PREFERENCE_TEXT_ANTIALIASING
The mode that is used for anti-aliasing
|
private double |
scale |
private boolean |
showIcons |
private boolean |
showNames |
private static double |
sinPHI |
private ElemStyles |
styles |
private static java.util.concurrent.ForkJoinPool |
THREAD_POOL |
private boolean |
useStrokes |
private boolean |
useWiderHighlight |
private static AbstractProperty<java.lang.Integer> |
WIDER_HIGHLIGHT |
backgroundColor, doSlowOperations, g, highlightColor, inactiveColor, isInactiveMode, mapState, nc, nodeColor, relationSelectedColor, segmentNumberSpace, selectedColor, virtualNodeSize, virtualNodeSpace
Constructor and Description |
---|
StyledMapRenderer(java.awt.Graphics2D g,
NavigatableComponent nc,
boolean isInactiveMode)
Constructs a new
StyledMapRenderer . |
Modifier and Type | Method and Description |
---|---|
private static void |
appendOnewayPath(boolean onewayReversed,
MapViewState.MapViewPoint p1,
double nx,
double ny,
double dist,
double onewaySize,
java.awt.geom.Path2D onewayPath) |
private static void |
buildPFClip(java.awt.geom.Path2D.Double clip,
java.util.List<? extends INode> nodes,
double extent)
Fix the clipping area of unclosed polygons for partial fill.
|
private void |
computeFill(java.awt.Shape shape,
java.lang.Float extent,
MapViewPath pfClip,
float mitterLimit)
Fill the given shape.
|
static int |
computeFlags(IPrimitive primitive,
boolean checkOuterMember)
Computes the flags for a given OSM primitive.
|
private static double |
computeStartOffset(double phase,
double repeat) |
private void |
displaySegments(MapViewPath path,
java.awt.geom.Path2D orientationArrows,
java.awt.geom.Path2D onewayArrows,
java.awt.geom.Path2D onewayArrowsCasing,
java.awt.Color color,
java.awt.BasicStroke line,
java.awt.BasicStroke dashes,
java.awt.Color dashedColor) |
private void |
displayText(IPrimitive osm,
TextLabel text,
java.lang.String name,
java.awt.geom.Rectangle2D nb,
MapViewPositionAndRotation center) |
private void |
displayText(java.lang.Runnable fill,
java.util.function.Supplier<java.awt.Shape> outline,
boolean disabled,
TextLabel text)
Displays text at specified position including its halo, if applicable.
|
void |
drawArea(IWay<?> w,
java.awt.Color color,
MapImage fillImage,
java.lang.Float extent,
java.lang.Float extentThreshold,
boolean disabled)
Draws an area defined by a way.
|
protected void |
drawArea(MapViewPath path,
java.awt.Color color,
MapImage fillImage,
java.lang.Float extent,
MapViewPath pfClip,
boolean disabled)
Worker function for drawing areas.
|
void |
drawArea(Relation r,
java.awt.Color color,
MapImage fillImage,
java.lang.Float extent,
java.lang.Float extentThreshold,
boolean disabled)
Draws a multipolygon area.
|
void |
drawAreaIcon(IPrimitive osm,
MapImage img,
boolean disabled,
boolean selected,
boolean member,
double theta,
PositionForAreaStrategy iconPosition)
Draw the icon for a given area.
|
void |
drawBoxText(INode n,
BoxTextElement bs)
Draw a text onto a node
|
private void |
drawIcon(MapViewState.MapViewPoint p,
MapImage img,
boolean disabled,
boolean selected,
boolean member,
double theta,
java.util.function.BiConsumer<java.awt.Graphics2D,java.awt.geom.Rectangle2D> selectionDrawer) |
void |
drawNode(INode n,
java.awt.Color color,
int size,
boolean fill)
Draw the node as small square with the given color.
|
void |
drawNodeIcon(INode n,
MapImage img,
boolean disabled,
boolean selected,
boolean member,
double theta)
Draw the icon for a given node.
|
void |
drawNodeSymbol(INode n,
Symbol s,
java.awt.Color fillColor,
java.awt.Color strokeColor)
Draw the symbol and possibly a highlight marking on a given node.
|
void |
drawOrderNumber(INode n1,
INode n2,
int orderNumber,
java.awt.Color clr)
Draw a number of the order of the two consecutive nodes within the
parents way
|
private void |
drawPathHighlight(MapViewPath path,
java.awt.BasicStroke line)
highlights a given GeneralPath using the settings from BasicStroke to match the line's
style.
|
private void |
drawPointHighlight(java.awt.geom.Point2D p,
int size)
highlights a given point by drawing a rounded rectangle around it.
|
void |
drawRepeatImage(IWay<?> way,
MapImage pattern,
boolean disabled,
double offset,
double spacing,
double phase,
RepeatImageElement.LineImageAlignment align)
Draw an image along a way repeatedly.
|
void |
drawRestriction(java.awt.Image img,
java.awt.Point pVia,
double vx,
double vy,
double angle,
boolean selected)
Draws a restriction.
|
void |
drawRestriction(IRelation<?> r,
MapImage icon,
boolean disabled)
Draw a turn restriction
|
void |
drawText(IPrimitive osm,
TextLabel text,
PositionForAreaStrategy labelPositionStrategy)
Draws a text for the given primitive
|
void |
drawWay(IWay<?> way,
java.awt.Color color,
java.awt.BasicStroke line,
java.awt.BasicStroke dashes,
java.awt.Color dashedColor,
float offset,
boolean showOrientation,
boolean showHeadArrowOnly,
boolean showOneway,
boolean onewayReversed)
draw way.
|
private void |
forEachPolygon(IPrimitive osm,
java.util.function.Consumer<MapViewPath> consumer)
Calls a consumer for each path of the area shape-
|
double |
getCircum()
Gets the "circum".
|
void |
getColors()
Reads the color definitions from preferences.
|
private MapViewPath |
getPath(IWay<?> w) |
private static java.awt.geom.Path2D.Double |
getPFClip(IWay<?> w,
double extent) |
private static java.awt.geom.Path2D.Double |
getPFClip(Multipolygon.PolyData pd,
double extent) |
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.
|
private java.awt.Color |
getSelectionHintColor(boolean disabled,
boolean selected) |
void |
getSettings(boolean virtual)
Reads all the settings from preferences.
|
private boolean |
isAreaVisible(java.awt.geom.Path2D.Double area)
Test if the area is visible
|
static boolean |
isGlyphVectorDoubleTranslationBug(java.awt.Font font)
Check, if this System has the GlyphVector double translation bug.
|
boolean |
isInactiveMode()
Determines if the paint visitor shall render OSM objects such that they look inactive.
|
boolean |
isShowIcons()
Check if icons should be rendered
|
boolean |
isShowNames()
Test if names should be rendered
|
private static java.util.concurrent.ForkJoinPool |
newForkJoinPool() |
private void |
paintRecord(StyledMapRenderer.StyleRecord record) |
private void |
paintWithLock(OsmData<?,?,?,?> data,
boolean renderVirtualNodes,
RenderBenchmarkCollector benchmark,
BBox bbox) |
void |
render(OsmData<?,?,?,?> data,
boolean renderVirtualNodes,
Bounds bounds)
Renders the OSM data in
data |
void |
setBenchmarkFactory(java.util.function.Supplier<RenderBenchmarkCollector> benchmarkFactory)
Sets the factory that creates the benchmark data receivers.
|
void |
setStyles(ElemStyles styles)
Set the
ElemStyles instance to use for this renderer. |
private MapViewPath |
shapeEastNorthToMapView(java.awt.geom.Path2D.Double shape)
Convert shape in EastNorth coordinates to MapViewPath and remove invisible parts.
|
private boolean |
usePartialFill(Geometry.AreaAndPerimeter ap,
float extent,
java.lang.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.
|
drawOrderNumber, drawVirtualNodes, enableSlowOperations, isLargeSegment, isSegmentVisible, visitVirtual
private static final java.util.concurrent.ForkJoinPool THREAD_POOL
private static final java.util.Map<java.awt.Font,java.lang.Boolean> IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG
private double circum
private double scale
private MapPaintSettings paintSettings
private ElemStyles styles
private java.awt.Color highlightColorTransparent
static final int FLAG_NORMAL
Not used in any public interfaces.
static final int FLAG_DISABLED
OsmPrimitive.isDisabled()
static final int FLAG_MEMBER_OF_SELECTED
OsmPrimitive.isMemberOfSelected()
static final int FLAG_SELECTED
OsmPrimitive.isSelected()
static final int FLAG_OUTERMEMBER_OF_SELECTED
OsmPrimitive.isOuterMemberOfSelected()
private static final double PHI
private static final double cosPHI
private static final double sinPHI
private static final AbstractProperty<java.lang.Boolean> PREFERENCE_LEFT_HAND_TRAFFIC
public static final AbstractProperty<java.lang.Boolean> PREFERENCE_ANTIALIASING_USE
public static final AbstractProperty<java.lang.String> PREFERENCE_TEXT_ANTIALIASING
private static final AbstractProperty<java.lang.Integer> HIGHLIGHT_LINE_WIDTH
private static final AbstractProperty<java.lang.Integer> HIGHLIGHT_POINT_RADIUS
private static final AbstractProperty<java.lang.Integer> WIDER_HIGHLIGHT
private static final AbstractProperty<java.lang.Integer> HIGHLIGHT_STEP
private java.util.Collection<WaySegment> highlightWaySegments
private boolean useWiderHighlight
private boolean useStrokes
private boolean showNames
private boolean showIcons
private boolean isOutlineOnly
private boolean leftHandTraffic
private java.lang.Object antialiasing
private java.util.function.Supplier<RenderBenchmarkCollector> benchmarkFactory
public StyledMapRenderer(java.awt.Graphics2D g, NavigatableComponent nc, boolean isInactiveMode)
StyledMapRenderer
.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.java.lang.IllegalArgumentException
- if g
is nulljava.lang.IllegalArgumentException
- if nc
is nullprivate static java.util.concurrent.ForkJoinPool newForkJoinPool()
public static boolean isGlyphVectorDoubleTranslationBug(java.awt.Font font)
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.)font
- The font to check.public void setStyles(ElemStyles styles)
ElemStyles
instance to use for this renderer.styles
- the ElemStyles
instance to useprivate void displaySegments(MapViewPath path, java.awt.geom.Path2D orientationArrows, java.awt.geom.Path2D onewayArrows, java.awt.geom.Path2D onewayArrowsCasing, java.awt.Color color, java.awt.BasicStroke line, java.awt.BasicStroke dashes, java.awt.Color dashedColor)
protected void drawArea(MapViewPath path, java.awt.Color color, MapImage fillImage, java.lang.Float extent, MapViewPath pfClip, boolean disabled)
path
- 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.private void computeFill(java.awt.Shape shape, java.lang.Float extent, MapViewPath pfClip, float mitterLimit)
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 BasicStrokepublic void drawArea(Relation r, java.awt.Color color, MapImage fillImage, java.lang.Float extent, java.lang.Float extentThreshold, boolean disabled)
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.private MapViewPath shapeEastNorthToMapView(java.awt.geom.Path2D.Double shape)
shape
- the shape to convertpublic void drawArea(IWay<?> w, java.awt.Color color, MapImage fillImage, java.lang.Float extent, java.lang.Float extentThreshold, boolean disabled)
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.private boolean usePartialFill(Geometry.AreaAndPerimeter ap, float extent, java.lang.Float threshold)
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 as perimeter * extent
public void drawBoxText(INode n, BoxTextElement bs)
n
- The node to draw the text onbs
- The text and it's alignment.public void drawRepeatImage(IWay<?> way, MapImage pattern, boolean disabled, double offset, double spacing, double phase, RepeatImageElement.LineImageAlignment align)
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 spacingalign
- alignment of the image. The top, center or bottom edge can be aligned with the way.private static double computeStartOffset(double phase, double repeat)
public void drawNode(INode n, java.awt.Color color, int size, boolean fill)
AbstractMapRenderer
drawNode
in class AbstractMapRenderer
n
- The node to draw.color
- The color of the node.size
- size in pixelsfill
- determines if the square mmust be filledpublic void drawNodeIcon(INode n, MapImage img, boolean disabled, boolean selected, boolean member, double theta)
n
- The nodeimg
- The icon to draw at the node positiondisabled
- true to render disabled version, false
for the standard versionselected
- true to render it as selected, false
otherwisemember
- true to render it as a relation member, false
otherwisetheta
- the angle of rotation in radianspublic void drawAreaIcon(IPrimitive osm, MapImage img, boolean disabled, boolean selected, boolean member, double theta, PositionForAreaStrategy iconPosition)
osm
- The primitive to draw the icon forimg
- The icon to drawdisabled
- true to render disabled version, false
for the standard versionselected
- true to render it as selected, false
otherwisemember
- true to render it as a relation member, false
otherwisetheta
- the angle of rotation in radiansiconPosition
- Where to place the icon.private void drawIcon(MapViewState.MapViewPoint p, MapImage img, boolean disabled, boolean selected, boolean member, double theta, java.util.function.BiConsumer<java.awt.Graphics2D,java.awt.geom.Rectangle2D> selectionDrawer)
private java.awt.Color getSelectionHintColor(boolean disabled, boolean selected)
public void drawNodeSymbol(INode n, Symbol s, java.awt.Color fillColor, java.awt.Color strokeColor)
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 symbolpublic void drawOrderNumber(INode n1, INode n2, int orderNumber, java.awt.Color clr)
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.private void drawPathHighlight(MapViewPath path, java.awt.BasicStroke line)
path
- path to drawline
- line styleprivate void drawPointHighlight(java.awt.geom.Point2D p, int size)
p
- pointsize
- highlight sizepublic void drawRestriction(java.awt.Image img, java.awt.Point pVia, double vx, double vy, double angle, boolean selected)
img
- symbol imagepVia
- "via" nodevx
- X offsetvy
- Y offsetangle
- the rotated angle, in degree, clockwiseselected
- if true, draws a selection rectanglepublic void drawRestriction(IRelation<?> r, MapImage icon, boolean disabled)
r
- The turn restriction relationicon
- The icon to draw at the turn pointdisabled
- draw using disabled stylepublic void drawText(IPrimitive osm, TextLabel text, PositionForAreaStrategy labelPositionStrategy)
osm
- The primitive to draw the text fortext
- The text definition (font/position/.../text content) to drawlabelPositionStrategy
- The position of the textprivate void displayText(IPrimitive osm, TextLabel text, java.lang.String name, java.awt.geom.Rectangle2D nb, MapViewPositionAndRotation center)
private void displayText(java.lang.Runnable fill, java.util.function.Supplier<java.awt.Shape> outline, boolean disabled, TextLabel text)
fill
- The function that fills the textoutline
- The function to draw the outlinedisabled
- true
if element is disabled (filtered out)text
- text style to useprivate void forEachPolygon(IPrimitive osm, java.util.function.Consumer<MapViewPath> consumer)
osm
- A way or a multipolygonconsumer
- The consumer to call.public void drawWay(IWay<?> way, java.awt.Color color, java.awt.BasicStroke line, java.awt.BasicStroke dashes, java.awt.Color dashedColor, float offset, boolean showOrientation, boolean showHeadArrowOnly, boolean showOneway, boolean onewayReversed)
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. null
if 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 similarprivate static void appendOnewayPath(boolean onewayReversed, MapViewState.MapViewPoint p1, double nx, double ny, double dist, double onewaySize, java.awt.geom.Path2D onewayPath)
public double getCircum()
public void getColors()
AbstractMapRenderer
public
, so that
color names in preferences can be displayed even without calling the wireframe display before.getColors
in class AbstractMapRenderer
public void getSettings(boolean virtual)
AbstractMapRenderer
getSettings
in class AbstractMapRenderer
virtual
- true
if virtual nodes are usedprivate MapViewPath getPath(IWay<?> w)
private static java.awt.geom.Path2D.Double getPFClip(Multipolygon.PolyData pd, double extent)
private static void buildPFClip(java.awt.geom.Path2D.Double clip, java.util.List<? extends INode> nodes, double extent)
clip
- the clipping area to modify (initially empty)nodes
- nodes of the polygonextent
- the extentprivate static EastNorth getPFDisplacedEndPoint(EastNorth p1, EastNorth p2, EastNorth p3, double extent)
(p1,p2)
is the first or last way segment and p3
the
opposite endpoint.p1
- 1st pointp2
- 2nd pointp3
- 3rd pointextent
- the extentextent
. 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.)private boolean isAreaVisible(java.awt.geom.Path2D.Double area)
area
- The area, interpreted in east/north space.public boolean isInactiveMode()
true
if the paint visitor shall render OSM objects such that they look inactivepublic boolean isShowIcons()
true
to display iconspublic boolean isShowNames()
true
to display namespublic static int computeFlags(IPrimitive primitive, boolean checkOuterMember)
primitive
- The primititve to compute the flags for.checkOuterMember
- true
if we should also add FLAG_OUTERMEMBER_OF_SELECTED
public void setBenchmarkFactory(java.util.function.Supplier<RenderBenchmarkCollector> benchmarkFactory)
benchmarkFactory
- The factory.public void render(OsmData<?,?,?,?> data, boolean renderVirtualNodes, Bounds bounds)
Rendering
Renders the OSM data in data
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
with bbox
are renderedprivate void paintWithLock(OsmData<?,?,?,?> data, boolean renderVirtualNodes, RenderBenchmarkCollector benchmark, BBox bbox)
private void paintRecord(StyledMapRenderer.StyleRecord record)