org.geotools.renderer.lite
Class LabelCacheDefault

java.lang.Object
  extended byorg.geotools.renderer.lite.LabelCacheDefault
All Implemented Interfaces:
LabelCache

public class LabelCacheDefault
extends java.lang.Object
implements LabelCache

Default LabelCache Implementation DJB (major changes on May 11th, 2005): 1.The old version of the labeler, if given a *set* of points, lines, or polygons justed labels the first item in the set. The sets are formed when you want to only put a single "Main St" on the map even if you have a bunch of small "Main St" segments. I changed this to be much much wiser. Basically, the new way looks at the set of geometries that its going to put a label on and find the "best" one that represents it. That geometry is then labeled (see below for details on where that label is placed). 2. I changed the actual drawing routines; 1. get the "representative geometry" 2. for points, label as before 3. for lines, find the middle point on the line (old version just averaged start and end points) and centre label on that point (rotated) 4. for polygon, put the label in the middle 3. ie. for lines, try the label at the 1/3, 1/2, and 2/3 location. Metric is how close the label bounding box is to the line. ie. for polygons, bisect the polygon (about the centroid) in to North, South, East and West polygons. Use the location that has the label best inside the polygon. After this is done, you can start doing constraint relaxation... 4. TODO: deal with labels going off the edge of the screen (much reduced now). 5. TODO: add a "minimum quality" parameter (ie. if you're labeling a tiny polygon with a tiny label, dont bother). Metrics are descibed in #3. 6. TODO: add ability for SLD to tweak parameters (ie. "always label"). ------------------------------------------------------------------------------------------ I've added extra functionality; a) priority -- if you set the in a TextSymbolizer, then you can control the order of labelling ** see mailing list for more details b) no --- turns off grouping for this symbolizer c) 5 -- do not put labels within 5 pixels of this label.

Since:
0.9.0
Author:
jeichar,dblasby

Field Summary
 boolean DEFAULT_GROUP
           
 double DEFAULT_PRIORITY
           
 int DEFAULT_SPACEAROUND
           
protected  java.util.Map labelCache
          Map the label cache
protected  java.util.ArrayList labelCacheNonGrouped
          non-grouped labels get thrown in here
 double MIN_GOODNESS_FIT
          labels that arent this good will not be shown
protected  SLDStyleFactory styleFactory
           
 
Constructor Summary
LabelCacheDefault()
           
 
Method Summary
 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 end(java.awt.Graphics2D graphics, java.awt.Rectangle displayArea)
          Called to indicate that the map is done rendering.
 void endLayer(java.awt.Graphics2D graphics, java.awt.Rectangle displayArea)
          Called to indicate that a layer is done rendering.
 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
 java.util.List orderedLabels()
          return a list with all the values in priority order.
 void put(TextSymbolizer symbolizer, Feature feature, LiteShape2 shape, javax.media.jai.util.Range scaleRange)
          Puts a TextStyle and its associated shape in the cache.
 void start()
          Called by renderer to indicate that the rendering process is starting.
 void startLayer()
          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

MIN_GOODNESS_FIT

public double MIN_GOODNESS_FIT
labels that arent this good will not be shown


DEFAULT_PRIORITY

public double DEFAULT_PRIORITY

labelCache

protected java.util.Map labelCache
Map the label cache


labelCacheNonGrouped

protected java.util.ArrayList labelCacheNonGrouped
non-grouped labels get thrown in here


DEFAULT_GROUP

public boolean DEFAULT_GROUP

DEFAULT_SPACEAROUND

public int DEFAULT_SPACEAROUND

styleFactory

protected SLDStyleFactory styleFactory
Constructor Detail

LabelCacheDefault

public LabelCacheDefault()
Method Detail

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()

startLayer

public void startLayer()
Description copied from interface: LabelCache
Called by renderer to indication the start of rendering a layer.

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

getPriority

public 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

Parameters:
symbolizer -
feature -
Returns:

put

public void put(TextSymbolizer symbolizer,
                Feature feature,
                LiteShape2 shape,
                javax.media.jai.util.Range scaleRange)
Description copied from interface: LabelCache
Puts a TextStyle and its associated shape in the cache.

Specified by:
put in interface LabelCache
Parameters:
shape - the shape to be labeled
See Also:
org.geotools.renderer.lite.LabelCache#put(org.geotools.renderer.style.TextStyle2D, org.geotools.renderer.lite.LiteShape)

endLayer

public void endLayer(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:
graphics - the graphics to draw on.
displayArea - The size of the display area.
See Also:
LabelCache.endLayer(java.awt.Graphics2D, java.awt.Rectangle)

orderedLabels

public java.util.List orderedLabels()
return a list with all the values in priority order. Both grouped and non-grouped

Returns:

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
Returns:

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:
bbox -
Returns:


Copyright © GeoTools. All Rights Reserved.