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