XYZ Maps Documentation
    Preparing search index...

    Interface TextStyle

    Interface for configuring the visual appearance of Text.

    interface TextStyle {
        alignment?:
            | "map"
            | "viewport"
            | StyleValueFunction<string>
            | StyleZoomRange<string>
            | StyleExpression<string>;
        altitude?:
            | number
            | boolean
            | "terrain"
            | StyleValueFunction<number | boolean | "terrain">
            | StyleZoomRange<number | boolean | "terrain">
            | StyleExpression<number | boolean | "terrain">;
        anchor?:
            | StyleValueFunction<string>
            | StyleZoomRange<string>
            | StyleExpression<string>
            | "Line"
            | "Coordinate"
            | "Centroid"
            | "Center";
        checkLineSpace?:
            | boolean
            | StyleValueFunction<boolean>
            | StyleZoomRange<boolean>
            | StyleExpression<boolean>;
        collide?:
            | boolean
            | StyleValueFunction<boolean>
            | StyleZoomRange<boolean>
            | StyleExpression<boolean>;
        collisionGroup?:
            | string
            | StyleValueFunction<string>
            | StyleZoomRange<string>
            | StyleExpression<string>;
        fill?:
            | Color
            | StyleZoomRange<Color>
            | StyleExpression<Color>
            | StyleValueFunction<Color>;
        font?:
            | string
            | StyleValueFunction<string>
            | StyleZoomRange<string>
            | StyleExpression<string>;
        lineWrap?:
            | number
            | StyleValueFunction<number>
            | StyleZoomRange<number>
            | StyleExpression<number>;
        offsetX?:
            | string
            | number
            | StyleZoomRange<string | number>
            | StyleExpression<string | number>
            | StyleValueFunction<string | number>;
        offsetY?:
            | number
            | StyleValueFunction<number>
            | StyleZoomRange<number>
            | StyleExpression<number>;
        offsetZ?:
            | string
            | number
            | StyleZoomRange<string | number>
            | StyleExpression<string | number>
            | StyleValueFunction<string | number>;
        opacity?:
            | number
            | StyleValueFunction<number>
            | StyleZoomRange<number>
            | StyleExpression<number>;
        priority?:
            | number
            | StyleValueFunction<number>
            | StyleZoomRange<number>
            | StyleExpression<number>;
        repeat?:
            | number
            | StyleValueFunction<number>
            | StyleZoomRange<number>
            | StyleExpression<number>;
        rotation?:
            | number
            | StyleValueFunction<number>
            | StyleZoomRange<number>
            | StyleExpression<number>;
        scaleByAltitude?:
            | boolean
            | StyleValueFunction<boolean>
            | StyleZoomRange<boolean>
            | StyleExpression<boolean>;
        stroke?:
            | Color
            | StyleZoomRange<Color>
            | StyleExpression<Color>
            | StyleValueFunction<Color>;
        strokeWidth?:
            | string
            | number
            | StyleZoomRange<string | number>
            | StyleExpression<string | number>
            | StyleValueFunction<string | number>;
        text?:
            | string
            | number
            | boolean
            | StyleValueFunction<string | number | boolean>
            | StyleZoomRange<string | number | boolean>;
        textAnchor?:
            | StyleValueFunction<string>
            | StyleZoomRange<string>
            | StyleExpression<string>
            | "Left"
            | "Center"
            | "Right"
            | "Top"
            | "TopLeft"
            | "TopRight"
            | "Bottom"
            | "BottomLeft"
            | "BottomRight";
        textRef?:
            | string
            | StyleValueFunction<string>
            | StyleZoomRange<string>
            | StyleExpression<string>;
        type: "Text";
        zIndex:
            | number
            | StyleValueFunction<number>
            | StyleZoomRange<number>
            | StyleExpression<number>;
        zLayer?: number | StyleValueFunction<number> | StyleExpression<number>;
    }
    Index
    alignment?:
        | "map"
        | "viewport"
        | StyleValueFunction<string>
        | StyleZoomRange<string>
        | StyleExpression<string>

    Alignment for styles of type "Text". Possible values are: "map" and "viewport". "map" aligns to the plane of the map and "viewport" aligns to the plane of the viewport/screen. Default alignment for Text based on point geometries is "viewport" while "map" is the default for line geometries.

    altitude?:
        | number
        | boolean
        | "terrain"
        | StyleValueFunction<number | boolean | "terrain">
        | StyleZoomRange<number | boolean | "terrain">
        | StyleExpression<number | boolean | "terrain">

    Altitude of the Text center in meters.

    Describes the vertical distance from the global ground plane (0m) to the Text.

    Supported values:

    • false (default): place at 0m.
    • true: use the altitude (z) from the feature geometry if present, else 0. Not re-aligned to the rendered terrain. If the geometry altitude source differs from the TerrainTileLayer source/resolution, the Text can appear slightly above or below the visible terrain surface.
    • number: fixed absolute altitude in meters. Also not adjusted when terrain tiles load; may not perfectly sit on the terrain unless both use exactly the same elevation source, datum and resolution.
    • 'terrain': sample (clamp to) the current terrain surface height. While the terrain tile is not yet loaded (or no terrain layer exists) the altitude is 0 and updates once data becomes available.

    Notes:

    • Use 'terrain' to keep the Text visually seated on the rendered terrain.
    • Use a numeric value for a constant absolute elevation independent of terrain updates.
    • To position something N meters above terrain: use 'terrain' plus offsetZ (e.g. offsetZ: '5m').
    • Expect mismatches (floating / sinking) when using true or a fixed number with a different terrain data source.
    false
    @experimental
    anchor?:
        | StyleValueFunction<string>
        | StyleZoomRange<string>
        | StyleExpression<string>
        | "Line"
        | "Coordinate"
        | "Centroid"
        | "Center"

    Sets the anchor point for styles of type "Text" used with Line or Polygon geometry.

    Possible values for Line geometry are "Coordinate" and "Line".

    • "Coordinate": the respective style is displayed at each coordinate of the polyline.
    • "Line": the respective style is displayed on the shape of the polyline when there is enough space. See checkLineSpace to disable the space check.

    Possible values for Polygon geometry are "Center" and "Centroid".

    • "Center": the center of the bounding box of the polygon.
    • "Centroid": the geometric centroid of the polygon geometry.
    For Polygon geometry the default is "Center". For Line geometry the default for styles of type "Text" is "Line".
    
    checkLineSpace?:
        | boolean
        | StyleValueFunction<boolean>
        | StyleZoomRange<boolean>
        | StyleExpression<boolean>

    Enable or disable the space check for point styles on line geometries. Only applies to "Text" styles with anchor set to "Line". If check checkLineSpace is enabled the respective style is only displayed if there is enough space on the line, otherwise it is not displayed.

    true
    
    collide?:
        | boolean
        | StyleValueFunction<boolean>
        | StyleZoomRange<boolean>
        | StyleExpression<boolean>

    Enable or disable collision detection. If the collision detection is enabled for multiple Styles within the same StyleGroup, the respective Styles are handled as a single Object ("CollisionGroup") where the combined bounding-box is determined automatically.

    • true: collision are allowed, Collision detection is disabled.
    • false: avoid collisions, Collision detection is enabled.
    false
    
    collisionGroup?:
        | string
        | StyleValueFunction<string>
        | StyleZoomRange<string>
        | StyleExpression<string>

    Enables collision detection and combines all styles of a StyleGroup with the same "CollisionGroup" into a single logical object for collision detection.

    fill?:
        | Color
        | StyleZoomRange<Color>
        | StyleExpression<Color>
        | StyleValueFunction<Color>

    Sets the color to fill the text.

    Color for a detailed list of possible supported formats.

    font?:
        | string
        | StyleValueFunction<string>
        | StyleZoomRange<string>
        | StyleExpression<string>

    CSS font string for texts. It is only valid for Text.

    “normal 12px Arial”
    
    lineWrap?:
        | number
        | StyleValueFunction<number>
        | StyleZoomRange<number>
        | StyleExpression<number>

    Enable oder Disable line wrapping for styles of type "Text". The line wrapping for text on (Multi)Linestring geometry with anchor set to "Line" is disabled by default, otherwise it's 14 characters.

    • number: Maximum number of characters per line [Default 14 characters]
    • false: disable line wrapping
    • true: enable line wrapping [Default 14 characters]
    14
    
    offsetX?:
        | string
        | number
        | StyleZoomRange<string | number>
        | StyleExpression<string | number>
        | StyleValueFunction<string | number>

    Offset the text in pixels on x-axis. A positive value offsets to the right, a negative value to the left. The default unit is pixels.

    // offset Text by 1m to the left
    { type: "Text", zIndex: 0, fill:'blue', offsetX: "-1m", text: 'XYZ'}
    offsetY?:
        | number
        | StyleValueFunction<number>
        | StyleZoomRange<number>
        | StyleExpression<number>

    Offset the text in pixels on y-axis. A positive value offsetY offsets downwards, a negative value upwards. The default unit is pixels.

    // offset Text by 1m to the left
    { type: "Text", zIndex: 0, fill:'blue', offsetY: "-1m", text: 'XYZ'}
    offsetZ?:
        | string
        | number
        | StyleZoomRange<string | number>
        | StyleExpression<string | number>
        | StyleValueFunction<string | number>

    Offset the text in pixels on z-axis. A positive value offsets up, a negative value down. The default unit is pixels.

    // offset Text by 1m to the top
    { type: "Text", zIndex: 0, fill:'blue', text: 'XYZ', offsetZ: "1m"}
    opacity?:
        | number
        | StyleValueFunction<number>
        | StyleZoomRange<number>
        | StyleExpression<number>

    Defines the opacity of the style. The value must be between 0.0 (fully transparent) and 1.0 (fully opaque). It is valid for all style types.

    1
    
    priority?:
        | number
        | StyleValueFunction<number>
        | StyleZoomRange<number>
        | StyleExpression<number>

    In case of label collision, Text with a higher priority (lower value) will be drawn before lower priorities (higher value). If the collision detection is enabled for multiple Styles within the same StyleGroup, the highest priority (lowest value) is used.

    repeat?:
        | number
        | StyleValueFunction<number>
        | StyleZoomRange<number>
        | StyleExpression<number>

    Minimum distance in pixels between repeated style-groups on line geometries. Applies per tile only.

    256 (pixels)
    
    rotation?:
        | number
        | StyleValueFunction<number>
        | StyleZoomRange<number>
        | StyleExpression<number>

    Rotate text around it's center in degrees.

    scaleByAltitude?:
        | boolean
        | StyleValueFunction<boolean>
        | StyleZoomRange<boolean>
        | StyleExpression<boolean>

    Controls perspective scaling of map-aligned Text labels based on their feature's altitude. When disabled, a label is scaled as if its feature were at ground level. This applies only when alignment is "map"; viewport-aligned labels are unaffected.

    Text font sizes are pixel-based, so scaling is disabled by default and enabled by default when altitude resolves to "terrain".

    false for pixel font sizes; true for terrain altitude
    @experimental
    stroke?:
        | Color
        | StyleZoomRange<Color>
        | StyleExpression<Color>
        | StyleValueFunction<Color>

    Sets the stroke color of the text (outline).

    Color for a detailed list of possible supported formats.

    strokeWidth?:
        | string
        | number
        | StyleZoomRange<string | number>
        | StyleExpression<string | number>
        | StyleValueFunction<string | number>

    Sets the width of the stroke (outline) to display the text with. The unit of strokeWidth is defined in pixels.

    // define a Text style with a strokeWidth of 8px
    {
    zIndex: 0,
    type: "Text",
    text: "doc",
    fill: "white",
    stroke: "black,
    strokeWidth: 8
    }
    text?:
        | string
        | number
        | boolean
        | StyleValueFunction<string | number | boolean>
        | StyleZoomRange<string | number | boolean>

    Text is either a string or a function that generates the string that should be displayed. It is valid for Text style only.

    // display the name property of a feature in uppercase
    ...
    text: function(feature){
    return feature.properties.name.toUpperCase();
    }
    textAnchor?:
        | StyleValueFunction<string>
        | StyleZoomRange<string>
        | StyleExpression<string>
        | "Left"
        | "Center"
        | "Right"
        | "Top"
        | "TopLeft"
        | "TopRight"
        | "Bottom"
        | "BottomLeft"
        | "BottomRight"

    The "textAnchor" attribute is used to align the text relative to the anchor point.

    Possible values:

    • "Left": The text is aligned left to the anchor.
    • "Right": The text is aligned right to the anchor.
    • "Center": The center of the Text is placed at the anchor point.
    • "Top": The top of the Text is placed closest the anchor point.
    • "TopLeft": The top left side of the Text is placed closest the anchor point.
    • "TopRight": The top right side of the Text is placed closest the anchor point.
    • "Bottom": The bottom of the Text is placed closest to the anchor point.
    • "BottomLeft": The bottom left side of the Text is placed closest the anchor point.
    • "BottomRight": The bottom right side of the Text is placed closest the anchor point.
    "Center"
    
    textRef?:
        | string
        | StyleValueFunction<string>
        | StyleZoomRange<string>
        | StyleExpression<string>

    "textRef" Reference to an attribute of an feature that's value should be displayed as text. If both "text" and "textRef" are set, "text" prevails. It is only required by Text.

    // display the property "name" of the feature's properties
    ...
    textRef: "properties.name"
    // display the id of the feature
    ...
    textRef: "id"
    type: "Text"

    Specifies the type of style to render.

    zIndex:
        | number
        | StyleValueFunction<number>
        | StyleZoomRange<number>
        | StyleExpression<number>

    Indicates the drawing order within a layer. Styles with larger zIndex value are rendered above those with smaller values. The zIndex is defined relative to the "zLayer" property. If "zLayer" is defined all zIndex values are relative to the "zLayer" value.

    zLayer?: number | StyleValueFunction<number> | StyleExpression<number>

    Indicates drawing order across multiple layers. Styles using zLayer with a high value are rendered on top of zLayers with a low value. If no zLayer is defined, it will fall back to the LayerStyle.zLayer or depend on the display layer order. The first (lowest) layer has a zLayer value of 1.

    {...zLayer: 2, zIndex: 5} will be rendered on top of {...zLayer: 1, zIndex: 10}