Support Staff2 Posted by AJ on 20 Sep, 2012 06:06 PM
Labeling things properly from OSM data can be rather complex as
the label information can be stored in different ways. Some states,
cities, etc have the label information stored in the shape of the
boundaries - this is the
case with Florida. Some parts of the OSM community are moving
toward this method of labeling things for various reasons, for one
thing because it is useful to know the size of an object you are
labeling. Unfortunately this means there is some inconsistency to
deal with on the rendering side (and as you noted even OSM.org
hasn't caught up to this mapping strategy yet).
One option is to use a 3rd party data source for state labels.
You could use Natural Earth (from the MapBox
geodata library) for this. This is how we currently do it on
MapBox Streets. Another option is to get your label information
from both points and polygons -- you could post-process your
administrative boundaries table to add points to your labels table
(though there will likely be some de-duplication to do).
4 Posted by Jane Delarson on 21 Sep, 2012 11:46 PM
I guess what I'm interested in specifically is how the markers
(the dots) next to the states were accomplished. It seems to be
auto aligning the label to either the left or the right which is
much more elegant than just statically doing text-dy/dx.
This means the renderer will try to position a label East of the
point first, and if there is no room at that position try
Northeast, then Southeast, and so on until it finds a position that
fits or decides there is no room for the label anywhere.
With this style alone you'd get a majority of labels with
East-positioned labels. In order to get a more even distribution,
we create an alternative style that prefers West-positioning
(text-placements: "W,NW,SW,E,NE,SE";). We choose which
side each label gets by calculating the direction of the nearest
city (via a PostGIS function that looks like this). A more simple approach
that would still improve the distribution would be to just randomly
assign an East or West preference for each label, just as by
generating a random number, or looking at whether its ID is odd or