Hello all,
I've added code to the geotools codebase to support "label
shields"...basically graphics that render underneath labeled text to
make them look more distinct.
Here are a few examples.
The attached file "grayshields.png" comes from rendering a dataset with
the following TextSymbolizer:
<TextSymbolizer>
<Label>
<PropertyName xmlns="http://www.opengis.net/ogc/filter">RT\_NUMBER</PropertyName>
</Label>
<Fill>
<CssParameter name="fill">#000000</CssParameter>
q</Fill>
<Font>
<CssParameter name="font-family">/usr/lib/j2sdk1.5-sun/jre/lib/fonts/LucidaSansDemiBold.ttf</CssParameter>
<CssParameter name="font-weight">medium</CssParameter>
<CssParameter name="font-style">bold</CssParameter>
<CssParameter name="font-size">18</CssParameter>
</Font>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#BBBBBB</CssParameter>
</Fill>
</Mark>
<Opacity>.5</Opacity>
<Size>30</Size>
</Graphic>
</TextSymbolizer>
The attached file "interstate.png" comes from rendering a dataset with
the following TextSymbolizer. Please pardon the crapiness of my
interstate road shield...I'm not a very good artist!
<TextSymbolizer>
<Label>
<PropertyName xmlns="http://www.opengis.net/ogc/filter">RT\_NUMBER</PropertyName>
</Label>
<Fill>
<CssParameter name="fill">#FFFFFF</CssParameter>
q</Fill>
<Font>
<CssParameter name="font-family">/usr/lib/j2sdk1.5-sun/jre/lib/fonts/LucidaSansDemiBold.ttf</CssParameter>
<CssParameter name="font-weight">medium</CssParameter>
<CssParameter name="font-style">bold</CssParameter>
<CssParameter name="font-size">18</CssParameter>
</Font>
<Graphic>
<ExternalGraphic>
<OnlineResource xlink:href="http://<myip>/~sfarber/images/Interstate_shield.gif"/>
<Format>image/gif</Format>
</ExternalGraphic>
<Size>30</Size>
</Graphic>
</TextSymbolizer>
The basic changes were to allow a "<Graphic>" sub-element in the
TextSymbolizer and render it underneath the label. There were a few
tweaks here and there based on this change. One doesn't want
auto-rotated labels on a shield, so I had to account for that, and I had
to position everything so that the center of the label was in the center
of the shield. Other than that it was just adding fields for the right
objects and connecting them up.
Here's the result of looking at the modified files in the geotools
"main" module:
$ find src -mtime -2 | grep -v .svn
src/org/geotools/renderer/lite/StyledShapePainter.java
src/org/geotools/renderer/lite/LabelCacheDefault.java
src/org/geotools/renderer/lite/LabelCacheItem.java
src/org/geotools/renderer/style/GraphicStyle2D.java
src/org/geotools/renderer/style/TextStyle2D.java
src/org/geotools/renderer/style/SLDStyleFactory.java
src/org/geotools/styling/ExternalGraphicImpl.java
src/org/geotools/styling/TextSymbolizer.java
src/org/geotools/styling/TextSymbolizerImpl.java
src/org/geotools/styling/SLDParser.java
I think, in the end, however, no changes were made to
ExternalGraphicImpl, GraphicStyle2D or StyledShapePainter.
So now I have a few questions about what to do.
* Is this a desirable change?
* If it is, which branch of the geotools source should it go to? I'm
guessing that with the move from gt2.1 to gt2.2.x, it's not clear that
this has an easy home.
I was thinking that what I should do is to make a patch out of what I
have (which is changes against the geoserver-1.3.0.RC4.SC1 tag of
geotools) and then re-implement the changes in gt2.2.x whenever the
switch gets made in geoserver.
That way folks who want this RIGHT NOW can apply the patch to an
appropriate gt source tree and rebuild their main-2.1.1.jar and those
that think this is a nice idea but aren't jumping out of their boots for
it can just wait till geoserver starts working against gt 2.2.x.
Is this a good idea? Is there a better path I should be taking instead?
As soon as svn.geotools.org comes back i'll post a patch of the changes
and I'd love it if someone could look them over and give me some
feedback.
Thanks much,
--saul
(attachments)