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