Hi Jonn,
jon321 <jonn.farrcovalentsoftware.com> wrote
on 10/26/2007 11:26:08 AM:
> I have a complex svg file that draws a map with various areas. I want
to
> programmatically label these areas using batik. Ideally what I want
to do is
> put a text label in the center of the area.
> So say I have a path drawing this shape, how do I get the center of
it and
> apply a text label to it? Assuming you have booted the SVG DOM
(see the Wiki if you don't know what I mean). They you can use getBBox on just
about any SVG element and it will tell you the location of that element
in it's local coordinate system. Then it's a trivial matter to calculate
it's geometric center.
However, this is occasionally not useful
for mapping applications where the shape of the element may be such that the geometric
center is outside of the filled region for the shape. Handling
these cases automatically is far from trivial, so I am forced to leave you with
a problem rather than a solution.