LEADER

Description

Since version 6.2, MapServer has the ability to draw label lines to features where space is an issue for the label (often when the label text is larger than the polygon being labelled). This feature was added through MS RFC 81: Offset Labels with Leader Lines.

Supported Layer Types

POINT, LINE, POLYGON

Mapfile Parameters

GRIDSTEP [integer]

Specifies the number of pixels between positions that are tested for a label line. You might start with a value of 5, and increase depending on performance (see example below). Must be greater than 0.

MAXDISTANCE [integer]

Specifies the maximum distance in pixels from the normal label location that a leader line can be drawn. You might start with a value of 30, and increase depending on the resulting placement (see example below). Must be greater than 0.

STYLE

Signals the start of a STYLE object. Use this to style the leader line.

Mapfile Snippet

LAYER
  NAME "my-labels"
  TYPE POLYGON
  ...
  CLASS
    ...
    LABEL
     ...
    END
    LEADER
      GRIDSTEP 5 # number of pixels between positions that are tested
      MAXDISTANCE 30 # distance in pixels that leader text can be drawn
      STYLE # normal line styles are supported
        COLOR 255 0 0
        WIDTH 1
      END
    END
  END
END

Example: World Countries Labels

The following example uses a polygon layer to display country labels.

Informacja

The data and mapfile for this example are available for download at: https://download.osgeo.org/mapserver/tickets/label-leader.zip (11MB).

Mapfile Example #1

MAP

NAME "leader-test"
STATUS ON
SIZE 800 600
SYMBOLSET "../etc/symbols.txt"
EXTENT -43 10 83 83
UNITS DD
SHAPEPATH "../data"
IMAGECOLOR 255 255 255
FONTSET "../etc/fonts.txt"

WEB
  IMAGEPATH "/ms4w/tmp/ms_tmp/"
  IMAGEURL "/ms_tmp/"
END


#
# Start of layer definitions
#

LAYER
  NAME "continents"
  TYPE POLYGON
  STATUS ON
  DATA "world_countries-dissolve.shp"
  LABELITEM "NA2DESC"
  CLASS
    NAME "World Countries"
    STYLE
      COLOR 200 200 200
      OUTLINECOLOR 120 120 120
    END
    LABEL
     COLOR  0 0 0
     FONT sans
     TYPE truetype
     SIZE 8
     POSITION AUTO
     PARTIALS FALSE
     OUTLINECOLOR 255 255 255
     MINFEATURESIZE 2
     MINDISTANCE 1000
     BUFFER 5
    END
    ################################
    # Leader Object
    ################################
    LEADER
      GRIDSTEP 40
      MAXDISTANCE 1000
      STYLE
        COLOR 200 100 100
        WIDTH 2
      END
    END
  END
END


END # Map File

Map Image

../_images/leader1.png

Mapfile Example #2

This time use a shorter maximum leader line (MAXDISTANCE) and increase the number of tests (GRIDSTEP).

MAP

LAYER
  ...
  CLASS
    ...
    LABEL
     ...
    END
    ################################
    # Leader Object
    ################################
    LEADER
      GRIDSTEP 10
      MAXDISTANCE 100
      STYLE
        COLOR 200 100 100
        WIDTH 2
      END
    END
  END
END


END # Map File

Map Image

../_images/leader2.png