Class LabelCacheImpl
- Object
- 
- LabelCacheImpl
 
- 
- All Implemented Interfaces:
- LabelCache
 
 public class LabelCacheImpl extends Object implements LabelCache Default LabelCache Implementation.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 TextSymbolizerspecifications, and drawing it, provided it does not overlap with other labels.This basic behaviour can be customised in a number of ways. PriorityTextSymbolizer.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 SummaryNested Classes Modifier and Type Class Description static classLabelCacheImpl.LabelRenderingMode
 - 
Field SummaryFields Modifier and Type Field Description static int[]DEFAULT_DISPLACEMENT_ANGLESdoubleDEFAULT_PRIORITYstatic booleanDISABLE_LETTER_LEVEL_CONFLICTprotected Map<LabelCacheItem,LabelCacheItem>groupedLabelsLookupUsed to locate grouped labels quicklyprotected ArrayList<LabelCacheItem>labelCachelabels get thrown in here, in insertion orderprotected LabelCacheImpl.LabelRenderingModelabelRenderingModestatic doubleMIN_CURVED_DELTAThe angle delta at which we switch from curved rendering to straight renderingprotected SLDStyleFactorystyleFactory
 - 
Constructor SummaryConstructors Constructor Description LabelCacheImpl()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRenderListener(RenderListener listener)adds a listener that responds to error events of feature rendered events.voidclear()Clears the cache completelyvoidclear(String layerId)Clears the cache of all information relating to the layer identified.MultiLineStringclipLineString(LineString line)try to be more robust dont bother returning pointsMultiPolygonclipPolygon(Polygon poly, Polygon bbox, Envelope displayGeomEnv)try to do a more robust way of clipping a polygon to a bounding box.voiddisableLayer(String layerId)Leaves the label information in the cache but ignores it when calculating what labels are drawn.voidenableLayer(String layerId)Enable a layer after being disabled.voidend(Graphics2D graphics, Rectangle displayArea)Called to indicate that the map is done rendering.voidendLayer(String layerId, Graphics2D graphics, Rectangle displayArea)Called to indicate that a layer is done rendering.List<LabelCacheItem>getActiveLabels()Returns a list of all active labelsLabelCacheImpl.LabelRenderingModegetLabelRenderingMode()doublegetPriority(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_PRIORITYList<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 linevoidput(Rectangle2D area)Reserve the provided geometry prior to sorting out where labels can go.voidput(String layerId, TextSymbolizer symbolizer, Feature feature, LiteShape2 shape, NumberRange scaleRange)Puts a Label in the cache.voidremoveFromHash(Map<Coordinate,List<LineString>> nodes, LineString ls)voidsetConstructPainter(BiFunction<Graphics2D,LabelCacheImpl.LabelRenderingMode,LabelPainter> constructPainter)Change the method used to construct LabelPainters.voidsetLabelRenderingMode(LabelCacheImpl.LabelRenderingMode mode)Sets the text rendering mode.voidstart()Called by renderer to indicate that the rendering process is starting.voidstartLayer(String layerId)Called by renderer to indication the start of rendering a layer.voidstop()Tells the cache to stop labelling.
 
- 
- 
- 
Field Detail- 
DISABLE_LETTER_LEVEL_CONFLICTpublic static boolean DISABLE_LETTER_LEVEL_CONFLICT 
 - 
DEFAULT_PRIORITYpublic double DEFAULT_PRIORITY 
 - 
DEFAULT_DISPLACEMENT_ANGLESpublic static final int[] DEFAULT_DISPLACEMENT_ANGLES 
 - 
MIN_CURVED_DELTApublic static double MIN_CURVED_DELTA The angle delta at which we switch from curved rendering to straight rendering
 - 
groupedLabelsLookupprotected Map<LabelCacheItem,LabelCacheItem> groupedLabelsLookup Used to locate grouped labels quickly
 - 
labelCacheprotected ArrayList<LabelCacheItem> labelCache labels get thrown in here, in insertion order
 - 
labelRenderingModeprotected LabelCacheImpl.LabelRenderingMode labelRenderingMode 
 - 
styleFactoryprotected SLDStyleFactory styleFactory 
 
- 
 - 
Method Detail- 
enableLayerpublic void enableLayer(String layerId) Description copied from interface:LabelCacheEnable 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:
- enableLayerin interface- LabelCache
- Parameters:
- layerId- layer to activate.
 
 - 
getLabelRenderingModepublic LabelCacheImpl.LabelRenderingMode getLabelRenderingMode() 
 - 
setLabelRenderingModepublic void setLabelRenderingMode(LabelCacheImpl.LabelRenderingMode mode) Sets the text rendering mode.
 - 
setConstructPainterpublic 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).
 - 
stoppublic void stop() Description copied from interface:LabelCacheTells the cache to stop labelling.- Specified by:
- stopin interface- LabelCache
 
 - 
startpublic void start() Description copied from interface:LabelCacheCalled by renderer to indicate that the rendering process is starting.- Specified by:
- startin interface- LabelCache
- See Also:
- LabelCache.start()
 
 - 
clearpublic void clear() Description copied from interface:LabelCacheClears the cache completely- Specified by:
- clearin interface- LabelCache
 
 - 
clearpublic void clear(String layerId) Description copied from interface:LabelCacheClears the cache of all information relating to the layer identified.- Specified by:
- clearin interface- LabelCache
- Parameters:
- layerId- id of the layer
 
 - 
disableLayerpublic void disableLayer(String layerId) Description copied from interface:LabelCacheLeaves the label information in the cache but ignores it when calculating what labels are drawn.- Specified by:
- disableLayerin interface- LabelCache
- Parameters:
- layerId- id of the layer to disable.
 
 - 
startLayerpublic void startLayer(String layerId) Description copied from interface:LabelCacheCalled by renderer to indication the start of rendering a layer. Will add the layer to the set of active layers.- Specified by:
- startLayerin interface- LabelCache
- Parameters:
- layerId- an id for the layer
- See Also:
- LabelCache.startLayer(String)
 
 - 
getPrioritypublic 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
 - 
putpublic void put(String layerId, TextSymbolizer symbolizer, Feature feature, LiteShape2 shape, NumberRange scaleRange) Description copied from interface:LabelCachePuts a Label in the cache.- Specified by:
- putin interface- LabelCache
- Parameters:
- layerId- id indicating the layer the feature is part of
- symbolizer- The symbolizer containing the style information
- feature- 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:
- LabelCache.put(String,TextSymbolizer,Feature, LiteShape2,NumberRange)
 
 - 
putpublic void put(Rectangle2D area) Description copied from interface:LabelCacheReserve 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:
- putin interface- LabelCache
- Parameters:
- area- The Area of the screen to reserve (in screen coordinates)
 
 - 
endLayerpublic void endLayer(String layerId, Graphics2D graphics, Rectangle displayArea) Description copied from interface:LabelCacheCalled to indicate that a layer is done rendering. The method may draw labels if appropriate for the labeling algorithm- Specified by:
- endLayerin interface- LabelCache
- Parameters:
- layerId- an id for the layer
- graphics- the graphics to draw on.
- displayArea- The size of the display area
- See Also:
- LabelCache.endLayer(String,Graphics2D,Rectangle)
 
 - 
orderedLabelspublic List<LabelCacheItem> orderedLabels() Return a list with all the values in priority order. Both grouped and non-grouped- Specified by:
- orderedLabelsin interface- LabelCache
- Returns:
- list with all values in priority order
 
 - 
getActiveLabelspublic List<LabelCacheItem> getActiveLabels() Returns a list of all active labels
 - 
endpublic void end(Graphics2D graphics, Rectangle displayArea) Description copied from interface:LabelCacheCalled to indicate that the map is done rendering. The method may draw labels if appropriate for the labeling algorithm- Specified by:
- endin interface- LabelCache
- Parameters:
- graphics- the graphics to draw on.
- displayArea- The size of the display area.
- See Also:
- LabelCache.end(java.awt.Graphics2D, java.awt.Rectangle)
 
 - 
clipLineStringpublic MultiLineString clipLineString(LineString line) 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! 
 - 
clipPolygonpublic MultiPolygon clipPolygon(Polygon poly, Polygon bbox, Envelope displayGeomEnv) 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
 
 - 
processNodespublic 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
 - 
removeFromHashpublic void removeFromHash(Map<Coordinate,List<LineString>> nodes, LineString ls) 
 - 
addRenderListenerpublic void addRenderListener(RenderListener listener) adds a listener that responds to error events of feature rendered events.- Parameters:
- listener- the listener to add.
- See Also:
- RenderListener
 
 
- 
 
-