Class LabelDefinition

  • All Implemented Interfaces:
    JsonSerializable

    public final class LabelDefinition
    extends Object
    implements JsonSerializable
    Defines a set of rules for how labeling is applied to a feature data source for a given scale range, and can specify:
    • which features are covered by the definition (by applying the label definition's where-clause)
    • what text should be displayed, based on the individual feature's attributes and the label definition label-expression formula
    • how the text should appear, using the definition's text symbol
    • where the text should appear, with respect to its feature, using the definition's label placement
    • how to move or avoid other labels or features that would overlap each label
    Label definitions can be set and updated with the following methods: A LabelDefinition instance can only be constructed from a JSON string, for example:
     
        String labelDefinitionString = "{\n"
        + "  \"allowOverrun\": false,\n"
        + "  \"deconflictionStrategy\":\"static\",\n"
        + "  \"labelExpressionInfo\": { \"expression\": \"round($feature.length,2) + 'm^2'\"},\n"
        + "  \"labelPlacement\": \"esriServerPolygonPlacementAlwaysHorizontal\",\n"
        + "  \"lineConnection\": \"none\",\n"
        + "  \"minScale\": 1999,\n"
        + "  \"maxScale\": 0,\n"
        + "  \"multiPart\": \"labelLargest\",\n"
        + "  \"name\":\"Building interior code\",\n"
        + "  \"priority\": 15,\n"
        + "  \"removeDuplicates\": \"featureType\",\n"
        + "  \"removeDuplicatesDistance\": 300,\n"
        + "  \"repeatLabel\":false,\n"
        + "  \"repeatLabelDistance\":0,\n"
        + "  \"stackLabel\": true,\n"
        + "  \"stackAlignment\": \"dynamic\",\n"
        + "  \"stackRowLength\": 20,\n"
        + "  \"stackBreakPosition\": \"before\",\n"
        + "  \"symbol\": {\"type\": \"esriTS\", \"color\": [0,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\"}},\n"
        + "}";
    
        LabelDefinition labelDefinition = LabelDefinition.fromJson(labelDefinitionString);
        GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
        graphicsOverlay.getLabelDefinitions().add(labelDefinition);
     
     
    Since:
    100.1.0
    • Method Detail

      • fromJson

        public static final LabelDefinition fromJson​(String json)
        Creates a LabelDefinition instance from a JSON string.
        Parameters:
        json - a valid string in JSON format
        Returns:
        a LabelDefinition instance
        Throws:
        IllegalArgumentException - if json is null or empty
        ArcGISRuntimeException - if json is in invalid format
        Since:
        100.1.0
      • toJson

        public String toJson()
        Description copied from interface: JsonSerializable
        Serializes this object to a JSON string. Note that unknown JSON is omitted from the serialized string.
        Specified by:
        toJson in interface JsonSerializable
        Returns:
        a JSON string
      • getUnknownJson

        public Map<String,​Object> getUnknownJson()
        Description copied from interface: JsonSerializable
        If this object was created from JSON, this method gets unknown data from the source JSON. Unknown JSON is a Map of values that were in the source JSON but are not known by the Runtime and therefore not exposed in the API.
        Specified by:
        getUnknownJson in interface JsonSerializable
        Returns:
        an unmodifiable Map containing unknown JSON data. The keys are Strings containing names. The types of the values depend on the types of tokens within the JSON as follows:
        • a Map<String, Object> represents an object in the JSON
        • a List<Object> represents an array in the JSON
        • a String represents a string in the JSON
        • a Double represents a number in the JSON
        • a Boolean represents true or false in the JSON
        • null represents null in the JSON
      • getUnsupportedJson

        public Map<String,​Object> getUnsupportedJson()
        Description copied from interface: JsonSerializable
        If this object was created from JSON, this method gets unsupported data from the source JSON. Unsupported JSON is a Map of values that are supported by webmaps and known to the version of the webmap specification the API supports (see system requirements), but are not explicitly exposed through the Runtime API.
        Specified by:
        getUnsupportedJson in interface JsonSerializable
        Returns:
        an unmodifiable Map containing unsupported JSON data. The keys are Strings containing names. The types of the values depend on the types of tokens within the JSON as follows:
        • a Map<String, Object> represents an object in the JSON
        • a List<Object> represents an array in the JSON
        • a String represents a string in the JSON
        • a Double represents a number in the JSON
        • a Boolean represents true or false in the JSON
        • null represents null in the JSON