[Geoserver-users] [SLD] Boxed Labels with TextSymbolizer

Hi!

I'm trying to draw a box around the text on a label. My goal is to
make something like the boxed labels used for Highways on Google Maps.
For the API documentation, I can see that TextSymbolizer has methods
to set the background color of the text glyphs, but I can't seem to
find a way of expressing that in an SLD.

Can someone please give me an hint over this?

Thanks!

Hugo Ferreira

--
GPG Fingerprint: B0D7 1249 447D F5BB 22C5 5B9B 078C 2615 504B 7B85

Hugo,

Although it's not actually a part of the SLD specification, Geoserver allows the use of a "Graphics" tag inside a TextSymbolizer. This allows you to put an external or stroked graphic (like a graphic of a "box") under a label.

Here's the JIRA bug that enabled it, with an example included. Anything that usually goes in the "Graphic" tag is allowed, I think.

http://jira.codehaus.org/browse/GEOS-434

--saul

I'm trying to draw a box around the text on a label. My goal is to
make something like the boxed labels used for Highways on Google Maps.
For the API documentation, I can see that TextSymbolizer has methods
to set the background color of the text glyphs, but I can't seem to
find a way of expressing that in an SLD.

Can someone please give me an hint over this?

Thanks for answering...

Problem is, how do I make this box the same height and width of the
label's bounding box?

Cheers!

On 12/22/06, Saul Farber <Saul.Farber@anonymised.com> wrote:

Hugo,

Although it's not actually a part of the SLD specification, Geoserver
allows the use of a "Graphics" tag inside a TextSymbolizer. This allows
you to put an external or stroked graphic (like a graphic of a "box")
under a label.

Here's the JIRA bug that enabled it, with an example included. Anything
that usually goes in the "Graphic" tag is allowed, I think.

http://jira.codehaus.org/browse/GEOS-434

--saul

> I'm trying to draw a box around the text on a label. My goal is to
> make something like the boxed labels used for Highways on Google Maps.
> For the API documentation, I can see that TextSymbolizer has methods
> to set the background color of the text glyphs, but I can't seem to
> find a way of expressing that in an SLD.
>
> Can someone please give me an hint over this?
>

--
GPG Fingerprint: B0D7 1249 447D F5BB 22C5 5B9B 078C 2615 504B 7B85

Great question! I'm not sure I have an answer...anyone else have any great ideas?

I guess you could do some math in the <size> of the box. Have it be dependent on the length of the name string. Anyone know how Hugo could formulate that SLD expression? <size><Mult><Func name="length">STREET_NAME</Func><Literal>20</Literal></Mult></size

Is there a function to get the length of a string attribute?

--saul

Hugo Ferreira wrote:

Thanks for answering...

Problem is, how do I make this box the same height and width of the
label's bounding box?

Cheers!

Saul Farber ha scritto:

Great question! I'm not sure I have an answer...anyone else have any great ideas?

I guess you could do some math in the <size> of the box. Have it be dependent on the length of the name string. Anyone know how Hugo could formulate that SLD expression? <size><Mult><Func name="length">STREET_NAME</Func><Literal>20</Literal></Mult></size

Is there a function to get the length of a string attribute?

strLength(attribute) does compute the number of chars.
Yet I'm not sure it's what you want, since the rendered width
of "MMMM" and "||||" is different.
Unfortunately afaik we do not have a function that does return
actual rendered width and height.

In fact, to provide a proper answer to this problem, a new
element similar to halo should be added to TextSymbolizer,
since it has the same function as a halo, that is, make
text easier to read... well, it could even be a Halo
new attribute.
Both would require changing published API in 2.2.x, so I'm
not sure we're speaking about a quick change (I doubt it...
everything handling styles would need to be changed as
an effect, parsers, encoders, implementations of the interface...)

Cheers
Andrea

Jody Garnett ha scritto:

Andrea Aime wrote:

Saul Farber ha scritto:

Great question! I'm not sure I have an answer...anyone else have any great ideas?

I guess you could do some math in the <size> of the box. Have it be dependent on the length of the name string. Anyone know how Hugo could formulate that SLD expression? <size><Mult><Func name="length">STREET_NAME</Func><Literal>20</Literal></Mult></size

Is there a function to get the length of a string attribute?
    
strLength(attribute) does compute the number of chars.
Yet I'm not sure it's what you want, since the rendered width
of "MMMM" and "||||" is different.
Unfortunately afaik we do not have a function that does return
actual rendered width and height.

In fact, to provide a proper answer to this problem, a new
element similar to halo should be added to TextSymbolizer,
since it has the same function as a halo, that is, make
text easier to read... well, it could even be a Halo
new attribute.
Both would require changing published API in 2.2.x, so I'm
not sure we're speaking about a quick change (I doubt it...
everything handling styles would need to be changed as
an effect, parsers, encoders, implementations of the interface...)
  

We do support optional extensions beyond the SLD specification, for example we did "label shields" where a Mark could be dropped in behind the
final text position. This box sounds like a similar idea.

And how does a Halo new attribute sound, shape="radial" (just like now) and shape="rectangular" (new rectangle based distance, take the rectangle that bounds the text and use radius to increase its size in
each direction)?

Cheers
Andrea

Actually, I think there was a draft of SLD where a "Block" attribute
of Halo could be defined... For example, it appears here
(http://cgns-dev.nrcan.gc.ca/cgns_web/docs/sld-071-r0.pdf). From the
draft:

Block: Gives the absolute size of a block extension in pixels encoded
as a double float. This parameter is similar to the font Radius parameter
except that this is applied to the bounding box of a label of a font
with square corners. Whether the bounding box is defined by the exact
label or by the font in general is system- and font-depenent. The effect
is a block background

How hard it would be to implement a plugin to do this kind of labeling?

Cheers!

Hugo Ferreira

On 12/22/06, Andrea Aime <aaime@anonymised.com> wrote:

Jody Garnett ha scritto:
> Andrea Aime wrote:
>> Saul Farber ha scritto:
>>
>>> Great question! I'm not sure I have an answer...anyone else have any
>>> great ideas?
>>>
>>> I guess you could do some math in the <size> of the box. Have it be
>>> dependent on the length of the name string. Anyone know how Hugo
>>> could formulate that SLD expression? <size><Mult><Func
>>> name="length">STREET_NAME</Func><Literal>20</Literal></Mult></size
>>>
>>> Is there a function to get the length of a string attribute?
>>>
>>
>> strLength(attribute) does compute the number of chars.
>> Yet I'm not sure it's what you want, since the rendered width
>> of "MMMM" and "||||" is different.
>> Unfortunately afaik we do not have a function that does return
>> actual rendered width and height.
>>
>> In fact, to provide a proper answer to this problem, a new
>> element similar to halo should be added to TextSymbolizer,
>> since it has the same function as a halo, that is, make
>> text easier to read... well, it could even be a Halo
>> new attribute.
>> Both would require changing published API in 2.2.x, so I'm
>> not sure we're speaking about a quick change (I doubt it...
>> everything handling styles would need to be changed as
>> an effect, parsers, encoders, implementations of the interface...)
>>
> We do support optional extensions beyond the SLD specification, for
> example we did "label shields" where a Mark could be dropped in behind the
> final text position. This box sounds like a similar idea.

And how does a Halo new attribute sound, shape="radial" (just like now)
and shape="rectangular" (new rectangle based distance, take the
rectangle that bounds the text and use radius to increase its size in
each direction)?

Cheers
Andrea

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

--
GPG Fingerprint: B0D7 1249 447D F5BB 22C5 5B9B 078C 2615 504B 7B85

Give me the details, like cut and paste from that pdf, as a Jira report and assign it to me. I would honestly like a few more examples of going beyond a specification, and SLD is especially tempting.

We do not have a plugin for actually making good on the block attribute, that would be a change to the renderer.
Cheers,
Jody

Actually, I think there was a draft of SLD where a "Block" attribute
of Halo could be defined... For example, it appears here
(http://cgns-dev.nrcan.gc.ca/cgns_web/docs/sld-071-r0.pdf). From the
draft:

Block: Gives the absolute size of a block extension in pixels encoded
as a double float. This parameter is similar to the font Radius parameter
except that this is applied to the bounding box of a label of a font
with square corners. Whether the bounding box is defined by the exact
label or by the font in general is system- and font-depenent. The effect
is a block background

How hard it would be to implement a plugin to do this kind of labeling?

Cheers!

Hugo Ferreira

On 12/22/06, Andrea Aime <aaime@anonymised.com> wrote:

Jody Garnett ha scritto:
> Andrea Aime wrote:
>> Saul Farber ha scritto:
>>
>>> Great question! I'm not sure I have an answer...anyone else have any
>>> great ideas?
>>>
>>> I guess you could do some math in the <size> of the box. Have it be
>>> dependent on the length of the name string. Anyone know how Hugo
>>> could formulate that SLD expression? <size><Mult><Func
>>> name="length">STREET_NAME</Func><Literal>20</Literal></Mult></size
>>>
>>> Is there a function to get the length of a string attribute?
>>>
>>
>> strLength(attribute) does compute the number of chars.
>> Yet I'm not sure it's what you want, since the rendered width
>> of "MMMM" and "||||" is different.
>> Unfortunately afaik we do not have a function that does return
>> actual rendered width and height.
>>
>> In fact, to provide a proper answer to this problem, a new
>> element similar to halo should be added to TextSymbolizer,
>> since it has the same function as a halo, that is, make
>> text easier to read... well, it could even be a Halo
>> new attribute.
>> Both would require changing published API in 2.2.x, so I'm
>> not sure we're speaking about a quick change (I doubt it...
>> everything handling styles would need to be changed as
>> an effect, parsers, encoders, implementations of the interface...)
>>
> We do support optional extensions beyond the SLD specification, for
> example we did "label shields" where a Mark could be dropped in behind the
> final text position. This box sounds like a similar idea.

And how does a Halo new attribute sound, shape="radial" (just like now)
and shape="rectangular" (new rectangle based distance, take the
rectangle that bounds the text and use radius to increase its size in
each direction)?

Cheers
Andrea

-------------------------------------------------------------------------

Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Jody Garnett ha scritto:

Give me the details, like cut and paste from that pdf, as a Jira report and assign it to me. I would honestly like a few more examples of going beyond a specification, and SLD is especially tempting.

We do not have a plugin for actually making good on the block attribute, that would be a change to the renderer.

Here you go:
http://jira.codehaus.org/browse/GEOS-827
http://jira.codehaus.org/browse/GEOT-1091

Cheers
Andrea