Class LabelCacheImpl
- All Implemented Interfaces:
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.
Priority
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
- Author:
- jeichar, dblasby, Andrea Aime - OpenGeo
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int[]
double
static boolean
protected Map<LabelCacheItem,
LabelCacheItem> Used to locate grouped labels quicklyprotected ArrayList<LabelCacheItem>
labels get thrown in here, in insertion orderprotected LabelCacheImpl.LabelRenderingMode
static double
The angle delta at which we switch from curved rendering to straight renderingprotected SLDStyleFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRenderListener
(RenderListener listener) adds a listener that responds to error events of feature rendered events.void
clear()
Clears the cache completelyvoid
Clears the cache of all information relating to the layer identified.clipLineString
(LineString line) try to be more robust dont bother returning pointsclipPolygon
(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.Returns a list of all active labelsdouble
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_PRIORITYReturn a list with all the values in priority order.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 linevoid
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
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.
-
Field Details
-
DISABLE_LETTER_LEVEL_CONFLICT
public static boolean DISABLE_LETTER_LEVEL_CONFLICT -
DEFAULT_PRIORITY
public double DEFAULT_PRIORITY -
DEFAULT_DISPLACEMENT_ANGLES
public static final int[] DEFAULT_DISPLACEMENT_ANGLES -
MIN_CURVED_DELTA
public static double MIN_CURVED_DELTAThe angle delta at which we switch from curved rendering to straight rendering -
groupedLabelsLookup
Used to locate grouped labels quickly -
labelCache
labels get thrown in here, in insertion order -
labelRenderingMode
-
styleFactory
-
-
Constructor Details
-
LabelCacheImpl
public LabelCacheImpl()
-
-
Method Details
-
enableLayer
Description copied from interface:LabelCache
Enable a layer after being disabled. If startLayer is called this does not need to be called as start layer implicitely activates the layer.- Specified by:
enableLayer
in interfaceLabelCache
- Parameters:
layerId
- layer to activate.
-
getLabelRenderingMode
-
setLabelRenderingMode
Sets the text rendering mode. -
setConstructPainter
public void setConstructPainter(BiFunction<Graphics2D, LabelCacheImpl.LabelRenderingMode, LabelPainter> constructPainter) Change the method used to construct LabelPainters. Defaults toLabelPainter(java.awt.Graphics2D, org.geotools.renderer.label.LabelCacheImpl.LabelRenderingMode)
. -
stop
public void stop()Description copied from interface:LabelCache
Tells the cache to stop labelling.- Specified by:
stop
in interfaceLabelCache
-
start
public void start()Description copied from interface:LabelCache
Called by renderer to indicate that the rendering process is starting.- Specified by:
start
in interfaceLabelCache
- See Also:
-
clear
public void clear()Description copied from interface:LabelCache
Clears the cache completely- Specified by:
clear
in interfaceLabelCache
-
clear
Description copied from interface:LabelCache
Clears the cache of all information relating to the layer identified.- Specified by:
clear
in interfaceLabelCache
- Parameters:
layerId
- id of the layer
-
disableLayer
Description copied from interface:LabelCache
Leaves the label information in the cache but ignores it when calculating what labels are drawn.- Specified by:
disableLayer
in interfaceLabelCache
- Parameters:
layerId
- id of the layer to disable.
-
startLayer
Description copied from interface:LabelCache
Called by renderer to indication the start of rendering a layer. Will add the layer to the set of active layers.- Specified by:
startLayer
in interfaceLabelCache
- Parameters:
layerId
- an id for the layer- See Also:
-
getPriority
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 -
put
public void put(String layerId, TextSymbolizer symbolizer, Feature feature, LiteShape2 shape, NumberRange scaleRange) Description copied from interface:LabelCache
Puts a Label in the cache.- Specified by:
put
in interfaceLabelCache
- Parameters:
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 legal- See Also:
-
put
Description copied from interface:LabelCache
Reserve the provided geometry prior to sorting out where labels can go.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...
- Specified by:
put
in interfaceLabelCache
- Parameters:
area
- The Area of the screen to reserve (in screen coordinates)
-
endLayer
Description copied from interface:LabelCache
Called to indicate that a layer is done rendering. The method may draw labels if appropriate for the labeling algorithm- Specified by:
endLayer
in interfaceLabelCache
- Parameters:
layerId
- an id for the layergraphics
- the graphics to draw on.displayArea
- The size of the display area- See Also:
-
orderedLabels
Return a list with all the values in priority order. Both grouped and non-grouped- Specified by:
orderedLabels
in interfaceLabelCache
- Returns:
- list with all values in priority order
-
getActiveLabels
Returns a list of all active labels -
end
Description copied from interface:LabelCache
Called to indicate that the map is done rendering. The method may draw labels if appropriate for the labeling algorithm- Specified by:
end
in interfaceLabelCache
- Parameters:
graphics
- the graphics to draw on.displayArea
- The size of the display area.- See Also:
-
clipLineString
try to be more robust dont bother returning pointsThis 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!
-
clipPolygon
try to do a more robust way of clipping a polygon to a bounding box. This might return the orginal polygon if it cannot clip TODO: this is a bit simplistic, there's lots more to do.- Returns:
- a MutliPolygon
-
processNodes
public 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 -
removeFromHash
-
addRenderListener
adds a listener that responds to error events of feature rendered events.- Parameters:
listener
- the listener to add.- See Also:
-