Skip to content

TextLayer

lonboard.experimental.TextLayer

Bases: BaseArrowLayer

Render text labels at given coordinates.

auto_highlight

auto_highlight = Bool(default_value=False)

When true, the current object pointed to by the mouse pointer (when hovered over) is highlighted with highlightColor.

Requires pickable to be True.

  • Type: bool
  • Default: False

background_padding

background_padding = Any(None, allow_none=True)

The padding of the background.

  • If an array of 2 is supplied, it is interpreted as [padding_x, padding_y] in pixels.
  • If an array of 4 is supplied, it is interpreted as [padding_left, padding_top, padding_right, padding_bottom] in pixels.

default [0, 0, 0, 0]

before_id

before_id = Unicode(None, allow_none=True)

The identifier of a layer in the Maplibre basemap layer stack.

This deck.gl layer will be rendered just before the layer with the given identifier. You can find such an identifier by inspecting the basemap style JSON.

For example, in the Carto Positron style, if you look at the raw JSON data, each layer has an "id" property. The first layer in the basemap stack has "id": "background". So if you pass before_id="background", you won't see your deck.gl layer because it will be rendered below all layers in the Maplibre basemap.

A common choice for Carto-based styles is to use before_id="watername_ocean" so that your deck.gl layer is rendered above the core basemap elements but below all text labels.

Info

This only has an effect when the map's basemap is a MaplibreBasemap, and the map is rendering in "interleaved" mode.

billboard

billboard = Bool(None, allow_none=True)

If true, the text always faces camera. Otherwise the text faces up (z).

  • Type: bool
  • Default: True

character_set

character_set = Any(None, allow_none=True)

Specifies a list of characters to include in the font. If set to 'auto', will be automatically generated from the data set.

default (ASCII characters 32-128)

extensions

extensions = tag(sync=True, **(widget_serialization))

A list of layer extension objects to add additional features to a layer.

font_family

font_family = Any(None, allow_none=True)

CSS font family

default 'Monaco, monospace'

font_settings

font_settings = Any(None, allow_none=True)

Advance options for fine tuning the appearance and performance of the generated shared fontAtlas.

font_weight

font_weight = Any(None, allow_none=True)

CSS font weight

default 'normal'

get_alignment_baseline

get_alignment_baseline = Any(None, allow_none=True)

Vertical alignment accessor

default 'center'

get_angle

get_angle = FloatAccessor(None, allow_none=True)

Label rotation accessor, in degrees

default 0

get_background_color

get_background_color = ColorAccessor(None, allow_none=True)

Background color accessor.

default [255, 255, 255, 255]

get_border_color

get_border_color = ColorAccessor(None, allow_none=True)

Border color accessor.

default [0, 0, 0, 255]

get_border_width

get_border_width = FloatAccessor(None, allow_none=True)

Border width accessor.

default 0

get_color

get_color = ColorAccessor(None, allow_none=True)

Label color accessor

default [0, 0, 0, 255]

get_pixel_offset

get_pixel_offset = Any(None, allow_none=True)

Label offset from the anchor position, [x, y] in pixels

default [0, 0]

get_size

get_size = FloatAccessor(None, allow_none=True)

Label size accessor

default 32

get_text

get_text = TextAccessor(None, allow_none=True)

Label text accessor

get_text_anchor

get_text_anchor = Any(None, allow_none=True)

Horizontal alignment accessor

default 'middle'

highlight_color

highlight_color = VariableLengthTuple(
    Int(), default_value=(0, 0, 128, 128), minlen=3, maxlen=4
)

RGBA color to blend with the highlighted object (the hovered over object if auto_highlight=true). When the value is a 3 component (RGB) array, a default alpha of 255 is applied.

  • Type: List or Tuple of integers
  • Default: [0, 0, 128, 128]

line_height

line_height = Any(None, allow_none=True)

A unitless number that will be multiplied with the current text size to set the line height.

max_width

max_width = Any(None, allow_none=True)

A unitless number that will be multiplied with the current text size to set the width limit of a string.

If specified, when the text is longer than the width limit, it will be wrapped into multiple lines using the strategy of wordBreak.

default -1

opacity

opacity = Float(1, min=0, max=1)

The opacity of the layer.

  • Type: float. Must range between 0 and 1.
  • Default: 1

outline_color

outline_color = Any(None, allow_none=True)

Color of outline around the text, in [r, g, b, [a]]. Each channel is a number between 0-255 and a is 255 if not supplied.

default [0, 0, 0, 255]

outline_width

outline_width = Any(None, allow_none=True)

Width of outline around the text, relative to the text size. Only effective if fontSettings.sdf is true.

default 0

pickable

pickable = Bool(default_value=True)

Whether the layer responds to mouse pointer picking events.

This must be set to True for tooltips and other interactive elements to be available. This can also be used to only allow picking on specific layers within a map instance.

Note that picking has some performance overhead in rendering. To get the absolute best rendering performance with large data (at the cost of removing interactivity), set this to False.

  • Type: bool
  • Default: True

selected_index

selected_index = Int(None, allow_none=True)

The positional index of the most-recently clicked on row of data.

You can use this to access the full row of data from a GeoDataFrame

gdf.iloc[layer.selected_index]

Setting a value here from Python will do nothing. This attribute only exists to be updated from JavaScript on a map click. Note that pickable must be True (the default) on this layer for the JavaScript onClick handler to work; if pickable is set to False, selected_index will never update.

Note that you can use observe to call a function whenever a new value is received from JavaScript. Refer here for an example.

size_max_pixels

size_max_pixels = Any(None, allow_none=True)

The maximum size in pixels. When using non-pixel sizeUnits, this prop can be used to prevent the icon from getting too big when zoomed in.

  • Type: float, optional
  • Default: None

size_min_pixels

size_min_pixels = Any(None, allow_none=True)

The minimum size in pixels. When using non-pixel sizeUnits, this prop can be used to prevent the icon from getting too small when zoomed out.

  • Type: float, optional
  • Default: 0

size_scale

size_scale = Any(None, allow_none=True)

Text size multiplier.

  • Type: float.
  • Default: 1

size_units

size_units = Any(None, allow_none=True)

The units of the size, one of 'meters', 'common', and 'pixels'. default 'pixels'. See unit system.

  • Type: str, optional
  • Default: 'pixels'

table

table = ArrowTableTrait(allowed_geometry_types={POINT})

A GeoArrow table with a Point or MultiPoint column.

This is the fastest way to plot data from an existing GeoArrow source, such as geoarrow-rust or geoarrow-pyarrow.

If you have a GeoPandas GeoDataFrame, use from_geopandas instead.

visible

visible = Bool(default_value=True)

Whether the layer is visible.

Under most circumstances, using the visible attribute to control the visibility of layers is recommended over removing/adding the layer from the Map.layers list.

In particular, toggling the visible attribute will persist the layer on the JavaScript side, while removing/adding the layer from the Map.layers list will re-download and re-render from scratch.

  • Type: bool
  • Default: True

word_break

word_break = Any(None, allow_none=True)

Available options are break-all and break-word. A valid maxWidth has to be provided to use wordBreak.

default 'break-word'

__init__

__init__(
    table: ArrowStreamExportable,
    *,
    _rows_per_chunk: int | None = None,
    **kwargs: Unpack[BaseLayerKwargs]
) -> None

Construct a Layer from a GeoArrow table.

This accepts Arrow data from any library implementing the Arrow PyCapsule Interface, including pyarrow, arro3, DuckDB, and others.

The geometry column will be reprojected to EPSG:4326 if it is not already in that coordinate system.

Parameters:

  • table (ArrowStreamExportable) –

    An Arrow table or stream object from a library implementing the [Arrow PyCapsule Interface]. This object must contain a column with a geometry type that has the geoarrow extension metadata.

Other Parameters:

  • kwargs (Unpack[BaseLayerKwargs]) –

    parameters passed on to __init__

Returns:

  • None –

    A Layer with the initialized data.

from_duckdb

from_duckdb(
    sql: str | DuckDBPyRelation,
    con: DuckDBPyConnection | None = None,
    *,
    crs: str | CRS | None = None,
    **kwargs: Unpack[BaseLayerKwargs]
) -> Self

Construct a Layer from a duckdb-spatial query.

With DuckDB >= 1.5, the CRS of a GEOMETRY column is read automatically from the column type (e.g. GEOMETRY('EPSG:3857')) and the data is reprojected to EPSG:4326 as needed.

The crs keyword parameter is deprecated for such input and is only needed when the data cannot describe its own CRS: WKB_BLOB or 2D columns (POINT_2D, LINESTRING_2D, POLYGON_2D, BOX_2D), DuckDB older than 1.5, or a GEOMETRY column without a CRS encoded. In those cases, the user must ensure that data has been reprojected to EPSG:4326 or pass the existing CRS of the data in the crs keyword parameter.

Parameters:

  • sql (str | DuckDBPyRelation) –

    The SQL input to visualize. This can either be a string containing a SQL query or the output of the duckdb sql function.

  • con (DuckDBPyConnection | None, default: None ) –

    The current DuckDB connection. This is required when passing a str to the sql parameter.

Other Parameters:

  • crs (str | CRS | None) –

    The CRS of the input data, for input that cannot describe its own CRS (see above). This can either be a string passed to pyproj.CRS.from_user_input or a pyproj.CRS object. Errors if it conflicts with the CRS encoded in a DuckDB >= 1.5 GEOMETRY column. Defaults to None.

  • kwargs (Unpack[BaseLayerKwargs]) –

    parameters passed on to __init__

Returns:

  • Self –

    A Layer with the initialized data.

from_geopandas

from_geopandas(
    gdf: GeoDataFrame,
    *,
    auto_downcast: bool = True,
    **kwargs: Unpack[BaseLayerKwargs]
) -> Self

Construct a Layer from a geopandas GeoDataFrame.

The GeoDataFrame will be reprojected to EPSG:4326 if it is not already in that coordinate system.

Parameters:

  • gdf (GeoDataFrame) –

    The GeoDataFrame to set on the layer.

Other Parameters:

  • auto_downcast (bool) –

    If True, automatically downcast to smaller-size data types if possible without loss of precision. This calls pandas.DataFrame.convert_dtypes and pandas.to_numeric under the hood.

  • kwargs (Unpack[BaseLayerKwargs]) –

    parameters passed on to __init__

Returns:

  • Self –

    A Layer with the initialized data.