Mapscript - Sorting labels
Stephen Woodbridge
woodbri at SWOODBRIDGE.COM
Sat Jun 11 05:34:40 PDT 2005
Gribol wrote:
> ; Try sorting your shapefile in ascending order by population, instead of
> ; descending order. My experience with MapServer's labeling is that labels
> ; that are drawn later are given preference to those that were
> ; drawn earlier.
> ;
> ; If sorting your shapefile in ascending order doesn't help, you could try
> ; defining a number of ANNOTATION layers that are responsible for labeling
> ; cities within specified (and disjoint) population ranges. (e.g. layer1 to
> ; label cities where: POPULATION<10000; layer2 to label cities where:
> ; 10000<=POPULATION<20000; layer3 to label: 20000<=POPULATION<40000; etc.)
> ; Then arrange the layers in your mapfile so that layers for
> ; annotating small
> ; cities are drawn first. The number of ANNOTATION layers you use
> ; will depend
> ; on how tolerant you are for occasional labeling "mistakes" (where
> ; a smaller
> ; city's label is drawn in preference to that of a larger city).
> ;
> ; Hope this helps,
> ; -SM
>
> Steven,
>
> If I do an ascending sort on the shapefile, it's working.
> MapServer's labeling is very strange !
> Thank you for your help.
Actually, mapserver's labeling is very logical if you think about it for
a bit. When you draw a map you draw the least important features first
and the most important last. But you want last items that you drew to be
labeled first because they are most important. So mapserver draws all
the layers and objects and places their respective labels in a cache.
After all the geometry has been draw the cache is processed with a last
in first out strategy. That is the last object draw is from the set of
most important objects so it is labels first, if there is room for
additional labels they are also drawn, but if an area of the map is full
of labels and you try to draw another in that area it will not fit and
gets thrown out, and so on through the whole cache.
This way in spare areas you are more likely to see the labels from the
earlier layers and in cities you are more likely to see the labels of
points and streets.
-Steve W.
More information about the MapServer-users
mailing list