Labeling objects

Overview

This topic discusses the JSON labeling objects as returned by the REST API.

The following objects are discussed here:

Label placement

Label placement is represented as a literal string. It specifies the placement of the label with respect to that of its feature. The following table lists label placement values categorized by the geometry type of the feature:

Label placement values for point features

esriServerPointLabelPlacementAboveCenter

esriServerPointLabelPlacementAboveLeft

esriServerPointLabelPlacementAboveRight

esriServerPointLabelPlacementBelowCenter

esriServerPointLabelPlacementBelowLeft

esriServerPointLabelPlacementBelowRight

esriServerPointLabelPlacementCenterCenter

esriServerPointLabelPlacementCenterLeft

esriServerPointLabelPlacementCenterRight

Label placement values for line features

esriServerLinePlacementAboveAfter

esriServerLinePlacementAboveAlong

esriServerLinePlacementAboveBefore

esriServerLinePlacementAboveStart

esriServerLinePlacementAboveEnd

esriServerLinePlacementBelowAfter

esriServerLinePlacementBelowAlong

esriServerLinePlacementBelowBefore

esriServerLinePlacementBelowStart

esriServerLinePlacementBelowEnd

esriServerLinePlacementCenterAfter

esriServerLinePlacementCenterAlong

esriServerLinePlacementCenterBefore

esriServerLinePlacementCenterStart

esriServerLinePlacementCenterEnd

Label placement values for polygon features

esriServerPolygonPlacementAlwaysHorizontal

Label class

A label class specifies the label definition for a given scale range.

New in 10.1

  • where—Use where to determine the features that are labeled with the label class that contains it.
  • Use labelExpression to adjust the formatting of labels. A label expression is limited to a single line of code. Apart from specifying a string value and/or an attribute field value, the following keywords are supported:

    Keyword

    Description

    CONCAT

    Concatenate two values.

    Example: "\"State: \" CONCAT [State_Name]"

    NEWLINE

    Insert a new line.

    Example: "\"State: \" CONCAT NEWLINE CONCAT [State_Name]"

    UCASE([Field])

    Convert string value to uppercase string.

    Example: "\"State: \" CONCAT UCASE([State_Name])"

    LCASE([Field])

    Convert string value to lowercase string.

    Example: "\"State: \" CONCAT LCASE([State_Name])"

    ROUND([Field], n)

    Round a decimal number to set number of decimals as specified by (n).

    Example: "\"Area: \" CONCAT ROUND([Area], 3)"

    FORMATDATETIME([Field], "FormatString")

    Format a date/time value with the specified format (FormatString*). The following keywords are recognized:

    • d—Day of the month
    • ddd—Abbreviated day of the week
    • dddd—Full day of the week
    • M—Month in number
    • MMM—Abbreviated month name
    • MMMM—Full month name
    • y—Two digit year
    • yyyy—Four digit year
    • h—Hour in 12-hour format
    • H—Hour in 24-hour format
    • m—Two digit minute
    • s—Two digit second

    Example: "\"Date Modified: \" CONCAT FORMATDATETIME([modified],\"dddd, MMM d, yyyy\")"

    * FormatString also supports full range of Python date/time formats.

JSON syntax

{
  "labelPlacement" : "<labelPlacement>",
  "labelExpression" : "<labelExpression>",
  "useCodedValues": <true | false>
  "symbol" : "<textSymbol>",
  "minScale" : <minScale>,
  "maxScale" : <maxScale>,
  "where" : "<where clause>"
}

JSON example

{
    "labelPlacement": "esriServerPointLabelPlacementAboveRight",
    "labelExpression": "[NAME]",
    "useCodedValues": false,
    "symbol": {
     "type": "esriTS",
     "color": [38,115,0,255],
     "backgroundColor": null,
     "borderLineColor": null,
     "verticalAlignment": "bottom",
     "horizontalAlignment": "left",
     "rightToLeft": false,
     "angle": 0,
     "xoffset": 0,
     "yoffset": 0,
     "kerning": true,
     "font": {
      "family": "Arial",
      "size": 11,
      "style": "normal",
      "weight": "bold",
      "decoration": "none"
     }
    },
    "minScale": 0,
    "maxScale": 0,
    "where" : "NAME LIKE 'A%'" //label only those feature where name begins with A
  }

Labeling info

The labeling info object specifies the label definition for a layer. It is expressed as an array of label classes.

JSON syntax

[ <labelClass1>, <labelClass2> ]

JSON example

[
   {
    "labelPlacement": "esriServerPolygonPlacementAlwaysHorizontal",
    "labelExpression": "[TAG]",
    "useCodedValues": false,
    "symbol": {
     "type": "esriTS",
     "color": [78,78,78,255],
     "backgroundColor": null,
     "borderLineColor": null,
     "verticalAlignment": "bottom",
     "horizontalAlignment": "left",
     "rightToLeft": false,
     "angle": 0,
     "xoffset": 0,
     "yoffset": 0,
     "font": {
      "family": "Arial",
      "size": 12,
      "style": "normal",
      "weight": "bold",
      "decoration": "none"
     }
    },
    "minScale": 1999,
    "maxScale": 0,
    "where": ""
   },
   {
    "labelPlacement": "esriServerPolygonPlacementAlwaysHorizontal",
    "labelExpression": "[TAG]",
    "useCodedValues": true,
    "symbol": {
     "type": "esriTS",
     "color": [78,78,78,255],
     "backgroundColor": null,
     "borderLineColor": null,
     "verticalAlignment": "bottom",
     "horizontalAlignment": "left",
     "rightToLeft": false,
     "angle": 0,
     "xoffset": 0,
     "yoffset": 0,
     "font": {
      "family": "Arial",
      "size": 12,
      "style": "normal",
      "weight": "bold",
      "decoration": "none"
     }
    },
    "minScale": 0,
    "maxScale": 7100,
    "where": ""
   }
  ]

9/13/2017