org.geotools.renderer.label
Class LabelCacheImpl

java.lang.Object
  extended by org.geotools.renderer.label.LabelCacheImpl
All Implemented Interfaces:
LabelCache

public final class LabelCacheImpl
extends java.lang.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

Author:
jeichar, dblasby, Andrea Aime - OpenGeo

Field Summary
 double DEFAULT_PRIORITY
           
protected  java.util.Map<java.lang.String,LabelCacheItem> labelCache
          Map the label cache
protected  java.util.ArrayList<LabelCacheItem> labelCacheNonGrouped
          non-grouped labels get thrown in here*
static double MIN_CURVED_DELTA
          The angle delta at which we switch from curved rendering to straight rendering
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(java.lang.String layerId)
          Clears the cache of all information relating to the layer identified.
 com.vividsolutions.jts.geom.MultiLineString clipLineString(com.vividsolutions.jts.geom.LineString line, com.vividsolutions.jts.geom.Polygon bbox, com.vividsolutions.jts.geom.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.
 com.vividsolutions.jts.geom.MultiPolygon clipPolygon(com.vividsolutions.jts.geom.Polygon poly, com.vividsolutions.jts.geom.Polygon bbox, com.vividsolutions.jts.geom.Envelope displayGeomEnv)
          try to do a more robust way of clipping a polygon to a bounding box.
 void disableLayer(java.lang.String layerId)
          Leaves the label information in the cache but ignores it when calculating what labels are drawn.
 void enableLayer(java.lang.String layerId)
          Enable a layer after being disabled.
 void end(java.awt.Graphics2D graphics, java.awt.Rectangle displayArea)
          Called to indicate that the map is done rendering.
 void endLayer(java.lang.String layerId, java.awt.Graphics2D graphics, java.awt.Rectangle displayArea)
          Called to indicate that a layer is done rendering.
 double getPriority(TextSymbolizer symbolizer, org.opengis.feature.simple.SimpleFeature feature)
          get the priority from the symbolizer its an expression, so it will try to evaluate it: 1.
 boolean isOutlineRenderingEnabled()
           
 java.util.List<LabelCacheItem> orderedLabels()
          Return a list with all the values in priority order.
 java.util.List<com.vividsolutions.jts.geom.LineString> processNodes(java.util.List<com.vividsolutions.jts.geom.LineString> edges, java.util.Map<com.vividsolutions.jts.geom.Coordinate,java.util.List<com.vividsolutions.jts.geom.LineString>> nodes)
          pull a line from the list, and: 1.
 void put(java.awt.geom.Rectangle2D area)
          Reserve the provided geometry prior to sorting out where labels can go.
 void put(java.lang.String layerId, TextSymbolizer symbolizer, org.opengis.feature.simple.SimpleFeature feature, LiteShape2 shape, NumberRange scaleRange)
          Puts a Label in the cache.
 void removeFromHash(java.util.Map<com.vividsolutions.jts.geom.Coordinate,java.util.List<com.vividsolutions.jts.geom.LineString>> nodes, com.vividsolutions.jts.geom.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(java.lang.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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PRIORITY

public double DEFAULT_PRIORITY

MIN_CURVED_DELTA

public static double MIN_CURVED_DELTA
The angle delta at which we switch from curved rendering to straight rendering


labelCache

protected java.util.Map<java.lang.String,LabelCacheItem> labelCache
Map the label cache


labelCacheNonGrouped

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


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(java.lang.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(java.lang.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(java.lang.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(java.lang.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,
                          org.opengis.feature.simple.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(java.lang.String layerId,
                TextSymbolizer symbolizer,
                org.opengis.feature.simple.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)

put

public void put(java.awt.geom.Rectangle2D area)
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 interface LabelCache

endLayer

public void endLayer(java.lang.String layerId,
                     java.awt.Graphics2D graphics,
                     java.awt.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 java.util.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:
list with all values in priority order

end

public void end(java.awt.Graphics2D graphics,
                java.awt.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 com.vividsolutions.jts.geom.MultiLineString clipLineString(com.vividsolutions.jts.geom.LineString line,
                                                                  com.vividsolutions.jts.geom.Polygon bbox,
                                                                  com.vividsolutions.jts.geom.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 com.vividsolutions.jts.geom.MultiPolygon clipPolygon(com.vividsolutions.jts.geom.Polygon poly,
                                                            com.vividsolutions.jts.geom.Polygon bbox,
                                                            com.vividsolutions.jts.geom.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 java.util.List<com.vividsolutions.jts.geom.LineString> processNodes(java.util.List<com.vividsolutions.jts.geom.LineString> edges,
                                                                           java.util.Map<com.vividsolutions.jts.geom.Coordinate,java.util.List<com.vividsolutions.jts.geom.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(java.util.Map<com.vividsolutions.jts.geom.Coordinate,java.util.List<com.vividsolutions.jts.geom.LineString>> nodes,
                           com.vividsolutions.jts.geom.LineString ls)


Copyright © 1996-2010 Geotools. All Rights Reserved.