public class LabelCacheImpl extends Object implements LabelCache
The label cache sports a number of features that are enabled depending on the programmatic configuration and the TextSymbolizer options.
The basic functionality of the label cache consist in finding the best label position for each
Feature according to the TextSymbolizer
specifications, and drawing it, provided it does
not overlap with other labels.
This basic behaviour can be customised in a number of ways.
TextSymbolizer.getPriority()
OGC Expression controls a label priority.
A label with high priority will be drawn before others, increasing its likeliness to appear on the screen
Modifier and Type | Class and Description |
---|---|
static class |
LabelCacheImpl.LabelRenderingMode |
Modifier and Type | Field and Description |
---|---|
static int[] |
DEFAULT_DISPLACEMENT_ANGLES |
double |
DEFAULT_PRIORITY |
static boolean |
DISABLE_LETTER_LEVEL_CONFLICT |
protected Map<LabelCacheItem,LabelCacheItem> |
groupedLabelsLookup
Used to locate grouped labels quickly
|
protected ArrayList<LabelCacheItem> |
labelCache
labels get thrown in here, in insertion order
|
protected LabelCacheImpl.LabelRenderingMode |
labelRenderingMode |
static double |
MIN_CURVED_DELTA
The angle delta at which we switch from curved rendering to straight rendering
|
protected SLDStyleFactory |
styleFactory |
Constructor and Description |
---|
LabelCacheImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addRenderListener(RenderListener listener)
adds a listener that responds to error events of feature rendered events.
|
void |
clear()
Clears the cache completely
|
void |
clear(String layerId)
Clears the cache of all information relating to the layer identified.
|
MultiLineString |
clipLineString(LineString line)
try to be more robust dont bother returning points
This will try to solve robustness problems, but read code as to what it does.
|
MultiPolygon |
clipPolygon(Polygon poly,
Polygon bbox,
Envelope displayGeomEnv)
try to do a more robust way of clipping a polygon to a bounding box.
|
void |
disableLayer(String layerId)
Leaves the label information in the cache but ignores it when calculating what labels are
drawn.
|
void |
enableLayer(String layerId)
Enable a layer after being disabled.
|
void |
end(Graphics2D graphics,
Rectangle displayArea)
Called to indicate that the map is done rendering.
|
void |
endLayer(String layerId,
Graphics2D graphics,
Rectangle displayArea)
Called to indicate that a layer is done rendering.
|
List<LabelCacheItem> |
getActiveLabels()
Returns a list of all active labels
|
LabelCacheImpl.LabelRenderingMode |
getLabelRenderingMode() |
double |
getPriority(TextSymbolizer symbolizer,
Feature feature)
get the priority from the symbolizer its an expression, so it will try to evaluate it: 1. if
its missing --> DEFAULT_PRIORITY 2. if its a number, return that number 3. if its not a
number, convert to string and try to parse the number; return the number 4. otherwise, return
DEFAULT_PRIORITY
|
List<LabelCacheItem> |
orderedLabels()
Return a list with all the values in priority order.
|
List<LineString> |
processNodes(List<LineString> edges,
Map<Coordinate,List<LineString>> nodes)
pull a line from the list, and: 1. if nothing connects to it (its issolated), add it to
"result" 2. otherwise, merge it at the start/end with the LONGEST line there. 3. remove the
original line, and the lines it merged with from the hashtables 4. go again, with the merged
line
|
void |
put(Rectangle2D area)
Reserve the provided geometry prior to sorting out where labels can go.
|
void |
put(String layerId,
TextSymbolizer symbolizer,
Feature feature,
LiteShape2 shape,
NumberRange scaleRange)
Puts a Label in the cache.
|
void |
removeFromHash(Map<Coordinate,List<LineString>> nodes,
LineString ls) |
void |
setConstructPainter(BiFunction<Graphics2D,LabelCacheImpl.LabelRenderingMode,LabelPainter> constructPainter)
Change the method used to construct LabelPainters.
|
void |
setLabelRenderingMode(LabelCacheImpl.LabelRenderingMode mode)
Sets the text rendering mode.
|
void |
start()
Called by renderer to indicate that the rendering process is starting.
|
void |
startLayer(String layerId)
Called by renderer to indication the start of rendering a layer.
|
void |
stop()
Tells the cache to stop labelling.
|
public static boolean DISABLE_LETTER_LEVEL_CONFLICT
public double DEFAULT_PRIORITY
public static final int[] DEFAULT_DISPLACEMENT_ANGLES
public static double MIN_CURVED_DELTA
protected Map<LabelCacheItem,LabelCacheItem> groupedLabelsLookup
protected ArrayList<LabelCacheItem> labelCache
protected LabelCacheImpl.LabelRenderingMode labelRenderingMode
protected SLDStyleFactory styleFactory
public void enableLayer(String layerId)
LabelCache
enableLayer
in interface LabelCache
layerId
- layer to activate.public LabelCacheImpl.LabelRenderingMode getLabelRenderingMode()
public void setLabelRenderingMode(LabelCacheImpl.LabelRenderingMode mode)
public void setConstructPainter(BiFunction<Graphics2D,LabelCacheImpl.LabelRenderingMode,LabelPainter> constructPainter)
LabelPainter.LabelPainter(java.awt.Graphics2D, org.geotools.renderer.label.LabelCacheImpl.LabelRenderingMode)
.public void stop()
LabelCache
stop
in interface LabelCache
public void start()
LabelCache
start
in interface LabelCache
LabelCache.start()
public void clear()
LabelCache
clear
in interface LabelCache
public void clear(String layerId)
LabelCache
clear
in interface LabelCache
layerId
- id of the layerpublic void disableLayer(String layerId)
LabelCache
disableLayer
in interface LabelCache
layerId
- id of the layer to disable.public void startLayer(String layerId)
LabelCache
startLayer
in interface LabelCache
layerId
- an id for the layerLabelCache.startLayer(String)
public double getPriority(TextSymbolizer symbolizer, Feature feature)
symbolizer
- feature
- public void put(String layerId, TextSymbolizer symbolizer, Feature feature, LiteShape2 shape, NumberRange scaleRange)
LabelCache
put
in interface LabelCache
layerId
- id indicating the layer the feature is part ofsymbolizer
- The symbolizer containing the style informationfeature
- the feature that has the information required for the symbolizer to calculate
the required render information.shape
- the shape to be labeled. This is in screen coordinates.scaleRange
- the scaleRange that the symbolizer is legalLabelCache.put(String,TextSymbolizer,Feature,
LiteShape2,NumberRange)
public void put(Rectangle2D area)
LabelCache
This facility is used to reserve an area so that labels do not end up overlapping on screen constructs like scalebars or north arrows etc...
put
in interface LabelCache
public void endLayer(String layerId, Graphics2D graphics, Rectangle displayArea)
LabelCache
endLayer
in interface LabelCache
layerId
- an id for the layergraphics
- the graphics to draw on.displayArea
- The size of the display areaLabelCache.endLayer(String,Graphics2D,Rectangle)
public List<LabelCacheItem> orderedLabels()
orderedLabels
in interface LabelCache
public List<LabelCacheItem> getActiveLabels()
public void end(Graphics2D graphics, Rectangle displayArea)
LabelCache
end
in interface LabelCache
graphics
- the graphics to draw on.displayArea
- The size of the display area.LabelCache.end(java.awt.Graphics2D, java.awt.Rectangle)
public MultiLineString clipLineString(LineString line)
This will try to solve robustness problems, but read code as to what it does. It might return the unclipped line if there's a problem!
line
- public MultiPolygon clipPolygon(Polygon poly, Polygon bbox, Envelope displayGeomEnv)
poly
- bbox
- displayGeomEnv
- public List<LineString> processNodes(List<LineString> edges, Map<Coordinate,List<LineString>> nodes)
edges
- nodes
- public void addRenderListener(RenderListener listener)
listener
- the listener to add.RenderListener
Copyright © 1996–2019 Geotools. All rights reserved.