Layer

Layer#

class ipydeck.Layer(type: str, data: Any | None = None, id: str | None = None, *, visible: bool | None = None, pickable: bool | None = None, opacity: float | None = None, on_click: bool | None = None, **kwargs)[source]#

Base representation of a deck.gl layer.

The class normalizes Python data structures so they can be serialized and consumed by the front-end widget. Subclasses typically provide sensible defaults for type along with any layer-specific keyword arguments.

Examples

>>> from ipydeck.layers.base import Layer
>>> layer = Layer(
...     type="ScatterplotLayer",
...     data=[{"position": [-122.4, 37.8]}],
... )
>>> layer.serialize()["type"]
'ScatterplotLayer'

Instantiate a deck.gl layer definition.

Parameters:
  • type (str) – deck.gl layer type, for example ScatterplotLayer.

  • data (Any | None) – Optional source data. Pandas, GeoPandas, and Geo Interface objects are automatically converted into JSON-friendly structures.

  • id (str | None) – Stable identifier used to diff layers between renders.

  • visible (bool | None) – Whether the layer is drawn in the current frame.

  • pickable (bool | None) – Enables pointer interaction in deck.gl if True.

  • opacity (float | None) – Base alpha multiplier provided to deck.gl.

  • on_click (bool | None) – Whether click events should be forwarded to Python.

  • **kwargs – Additional properties that are passed through to deck.gl unchanged.

serialize()[source]#

Return a JSON-serializable representation of the layer.

Examples

>>> from ipydeck.layers.base import Layer
>>> Layer(type="TextLayer", data=[{"text": "hello"}]).serialize()["type"]
'TextLayer'