[Mapserver-users] Re: polygon label placement
blaise
bpicinbono at worldonline.fr
Wed Mar 31 01:03:39 PST 2004
Dean Gadoury wrote :
-----
Every now and then I need to label polygons in MapServer and I'm often
unsatisfied with the resulting placement. Labeling is fine for points
and lines, but when it comes to polygons it can be unpredictable....
If I'm not mistaken the POSITION parameter will only place the label
relative to the point at which MapServer decides the label will go.
Depending on the label's POSITION its quite possible to have labels that
fall completely outside a polygon. Is there a way to force labels to be
within a polygon? Is there anything else I'm missing?
-----
I have seen some discussions some times ago in the list about having the
polygon labels inside the polygons.
First try the different label position parameters (vertical : up,
center, down; horizontal : left, center, right). (i.e. : CC)
If you can do some mapserver scripting, you can put the labels wherever
you want (acoording you know where they have to go) :
-- have a separate label (or point) layer where you will draw the labels
for the polygons,
-- for each polygon, compute the X/Y coordinates of each vertex to find
the best point place for the label to be,
-- insert a label (or a labeled point) at this computed location on your
label layer.
For the computation, you can use the simple :
X = middle of Xmin - Xmax
Y = middle of Ymin - Ymax
But this won't give you good results if you deal with "inside-curved"
polygons.
I think you can find a lot of doc for the computation of the "center" of
polygons.
You can have a look at a demo where you can precisly set the polygon
labels with the simple computation above and by the means of two
X-offset and Y-offset parameters :
http://webmaps.ouvaton.org link: java-tools demo
(switch to html with the green java switch left to the scale bar (all
editing and updating tools have not yet been developped in java), put
the purple polygon layer in update mode and digitize new polygons or
update the X/Y-offset of the existing ones, or update the vertex.)
'hope it'll help
Blaise
More information about the MapServer-users
mailing list