org.geotools.renderer.label
Class LabelCacheImpl

Object
  extended by LabelCacheImpl
All Implemented Interfaces:
LabelCache

public final 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 functionalitty 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 customized 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

Vendor options

TextSymbolizer.getOptions() contains a map of vendor specific options other than priority which are not part of the SLD specification. Here is a list of their names, default values, and meaning:

Author:
jeichar, dblasby, Andrea Aime - OpenGeo
Module:

Field Summary
 boolean DEFAULT_ALLOW_OVERRUNS
           
 boolean DEFAULT_FOLLOW_LINE
           
 boolean DEFAULT_GROUP
           
 boolean DEFAULT_LABEL_ALL_GROUP
           
 int DEFAULT_LABEL_REPEAT
           
 double DEFAULT_MAX_ANGLE_DELTA
           
 int DEFAULT_MAX_DISPLACEMENT
           
 int DEFAULT_MIN_GROUP_DISTANCE
           
 double DEFAULT_PRIORITY
           
 boolean DEFAULT_REMOVE_OVERLAPS
           
 int DEFAULT_SPACE_AROUND
           
protected  Map<String,LabelCacheItem> labelCache
          Map the label cache
protected  ArrayList<LabelCacheItem> labelCacheNonGrouped
          non-grouped labels get thrown in here*
protected  boolean outlineRenderingEnabled
          When true, the text is rendered as its GlyphVector outline (as a geometry) instead of using drawGlypVector.
protected  SLDStyleFactory styleFactory
           
 
Constructor Summary
LabelCacheImpl()
           
 
Method Summary
 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, Polygon bbox, Envelope displayGeomEnv)
          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.
 double getPriority(TextSymbolizer symbolizer, SimpleFeature 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
 boolean isOutlineRenderingEnabled()
           
 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(String layerId, TextSymbolizer symbolizer, SimpleFeature feature, LiteShape2 shape, NumberRange scaleRange)
          Puts a Label in the cache.
 void removeFromHash(Map<Coordinate,List<LineString>> nodes, LineString ls)
           
 void setOutlineRenderingEnabled(boolean outlineRenderingEnabled)
          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.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PRIORITY

public double DEFAULT_PRIORITY

labelCache

protected Map<String,LabelCacheItem> labelCache
Map the label cache


labelCacheNonGrouped

protected ArrayList<LabelCacheItem> labelCacheNonGrouped
non-grouped labels get thrown in here*


DEFAULT_GROUP

public boolean DEFAULT_GROUP

DEFAULT_SPACE_AROUND

public int DEFAULT_SPACE_AROUND

DEFAULT_MAX_DISPLACEMENT

public int DEFAULT_MAX_DISPLACEMENT

DEFAULT_MIN_GROUP_DISTANCE

public int DEFAULT_MIN_GROUP_DISTANCE

DEFAULT_LABEL_REPEAT

public int DEFAULT_LABEL_REPEAT

DEFAULT_LABEL_ALL_GROUP

public boolean DEFAULT_LABEL_ALL_GROUP

DEFAULT_ALLOW_OVERRUNS

public boolean DEFAULT_ALLOW_OVERRUNS

DEFAULT_REMOVE_OVERLAPS

public boolean DEFAULT_REMOVE_OVERLAPS

DEFAULT_FOLLOW_LINE

public boolean DEFAULT_FOLLOW_LINE

DEFAULT_MAX_ANGLE_DELTA

public double DEFAULT_MAX_ANGLE_DELTA

outlineRenderingEnabled

protected boolean outlineRenderingEnabled
When true, the text is rendered as its GlyphVector outline (as a geometry) instead of using drawGlypVector. Pro: labels and halos are perfectly centered, some people prefer the extra antialiasing obtained. Cons: possibly slower, some people do not like the extra antialiasing :)


styleFactory

protected SLDStyleFactory styleFactory
Constructor Detail

LabelCacheImpl

public LabelCacheImpl()
Method Detail

enableLayer

public void enableLayer(String layerId)
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 interface LabelCache
Parameters:
layerId - layer to activate.

isOutlineRenderingEnabled

public boolean isOutlineRenderingEnabled()

setOutlineRenderingEnabled

public void setOutlineRenderingEnabled(boolean outlineRenderingEnabled)
Sets the text rendering mode. When true, the text is rendered as its GlyphVector outline (as a geometry) instead of using drawGlypVector. Pro: labels and halos are perfectly centered, some people prefer the extra antialiasing obtained. Cons: possibly slower, some people do not like the extra antialiasing :)


stop

public void stop()
Description copied from interface: LabelCache
Tells the cache to stop labelling.

Specified by:
stop in interface LabelCache

start

public void start()
Description copied from interface: LabelCache
Called by renderer to indicate that the rendering process is starting.

Specified by:
start in interface LabelCache
See Also:
LabelCache.start()

clear

public void clear()
Description copied from interface: LabelCache
Clears the cache completely

Specified by:
clear in interface LabelCache

clear

public void clear(String layerId)
Description copied from interface: LabelCache
Clears the cache of all information relating to the layer identified.

Specified by:
clear in interface LabelCache
Parameters:
layerId - id of the layer

disableLayer

public void disableLayer(String layerId)
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 interface LabelCache
Parameters:
layerId - id of the layer to disable.

startLayer

public void startLayer(String layerId)
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 interface LabelCache
Parameters:
layerId - an id for the layer
See Also:
org.geotools.renderer.lite.LabelCache#startLayer()

getPriority

public double getPriority(TextSymbolizer symbolizer,
                          SimpleFeature 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

Parameters:
symbolizer -
feature -

put

public void put(String layerId,
                TextSymbolizer symbolizer,
                SimpleFeature feature,
                LiteShape2 shape,
                NumberRange scaleRange)
Description copied from interface: LabelCache
Puts a Label in the cache.

Specified by:
put in 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:
org.geotools.renderer.lite.LabelCache#put(org.geotools.renderer.style.TextStyle2D, org.geotools.renderer.lite.LiteShape)

endLayer

public void endLayer(String layerId,
                     Graphics2D graphics,
                     Rectangle displayArea)
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 interface LabelCache
Parameters:
layerId - an id for the layer
graphics - the graphics to draw on.
displayArea - The size of the display area
See Also:
org.geotools.renderer.lite.LabelCache#endLayer(java.awt.Graphics2D, java.awt.Rectangle)

orderedLabels

public List<LabelCacheItem> orderedLabels()
Return a list with all the values in priority order. Both grouped and non-grouped

Specified by:
orderedLabels in interface LabelCache
Returns:

end

public void end(Graphics2D graphics,
                Rectangle displayArea)
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 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)

clipLineString

public MultiLineString clipLineString(LineString line,
                                      Polygon bbox,
                                      Envelope displayGeomEnv)
try to be more robust dont bother returning points 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!

Parameters:
line -
bbox - MUST BE A BOUNDING BOX

clipPolygon

public 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.

Parameters:
poly -
bbox -
displayGeomEnv -
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

Parameters:
edges -
nodes -
result -

removeFromHash

public void removeFromHash(Map<Coordinate,List<LineString>> nodes,
                           LineString ls)


Copyright © 1996-2009 Geotools. All Rights Reserved.