GeoFrame.Kino.Deck (GeoFrame v0.3.4)

Copy Markdown View Source

A deck.gl map for Livebook that draws geometry from binary buffers, not GeoJSON.

Build one with GeoFrame.Kino.deck/2. This module is compiled only when :kino is available.

How data reaches the browser

The geometry is reprojected to EPSG:4326 (a series without a CRS is assumed to be longitude/latitude already), then Rust flattens it into typed-array buffers: interleaved Float64 coordinates, Int32 part offsets and row indices, and, for polygons, Uint32 triangle indices computed natively with ear clipping (holes supported). All buffers travel in one Kino.JS.Live binary payload, each 8-byte aligned so JavaScript maps them with zero parsing; deck.gl reads them as binary attributes, so no per-feature JavaScript object is ever created. Z and M are dropped.

  • Precision: coordinates stay Float64. Deck.gl splits them into high and low 32-bit halves on the GPU, so positions remain exact at street scale and no origin offset is needed. The price is 16 bytes per vertex on the wire (1 million points = 16 MB).
  • Triangulation: done in Rust at build time, so deck.gl runs SolidPolygonLayer with _normalize: false and skips its own tessellation. Polygons that cross the antimeridian are not cut.
  • Per-feature styles: a column color or size is expanded in Rust into one value per point, or one per vertex for lines and polygons (the layout deck.gl expects for binary path and polygon attributes). A fixed color or size costs nothing: it travels as a single value.
  • Rows: null and empty rows draw nothing. A multi geometry becomes one part per member. Every layer carries the source row of each part, which maps hover tooltips and per-row styles back to the table.
  • GeometryCollections: decomposed into their members (nested collections included), each drawn in the layer of its kind and carrying the collection's row, so a hover on any member shows the collection's tooltip.

Options

  • :color - {r, g, b} or {r, g, b, a} (0-255), or {column, :viridis} (numeric ramp between the column's min and max) or {column, :categorical} (one palette color per distinct value). Missing values are gray. Default: blue.

  • :radius - point radius in pixels (number), or a numeric column scaled to 2-20 px so that the circle area follows the value (square-root scale). Default 4.

  • :width - line and polygon outline width in pixels, or a numeric column scaled to 1-8 px (lines only; outlines use the number). Default 2.

  • :opacity - layer opacity, 0 to 1. Default 0.8.

  • :tooltip - list of attribute columns shown on hover (needs a GeoFrame.GeoDataFrame). Values are sent as JSON, strings cut at 200 characters, and at most 2000000 cells (rows x columns) are allowed.

  • :popup - true or a list of attribute columns shown in a closable card anchored at the clicked feature, like explore(popup=True) of GeoPandas (needs a GeoFrame.GeoDataFrame). true lists every attribute column (at most 20); a list takes at most 20 columns. It shares the tooltip's cell and string caps and coexists with it: the tooltip appears on hover, the popup on click. Values are inserted as plain text, never as HTML. Default: off.

  • :max_features - maximum number of rows, default 1000000. A larger input raises ArgumentError; filter or sample it, or raise the option.

  • :max_vertices - maximum number of vertices (coordinates of all non-empty geometries), default 10000000 (about 160 MB of positions). The wire size follows vertices, not rows, so a few huge polygons cost more than many points. A larger input raises ArgumentError naming the count; simplify, filter or sample it, or raise the option.

  • :basemap - a MapLibre style URL, or nil for a blank background. The default is Carto Positron (https://basemaps.cartocdn.com/gl/positron-gl-style/style.json), which needs internet access in the browser.

  • :height - widget height in pixels, default 480.

  • :legend - true (default) or false. With a column color ({column, :viridis} or {column, :categorical}) a card in the bottom-right corner explains the colors, like GeoPandas explore(legend=True): a gradient bar of the same ramp with the column name and three ticks (min, middle, max, three significant digits) for a numeric column; swatches in the exact colors and order the widget assigns for a categorical one, capped at 10 entries followed by "N more". A gray entry marks missing values when there are any. A fixed color draws no legend. The legend data is computed in Elixir next to the colors and travels in the payload; JavaScript only draws it.

  • :scale - true (default) or false. Draws metric and imperial scale bars in the bottom-left corner (MapLibre ScaleControl), like the control_scale=True of GeoPandas explore.

  • :name - the layer's name in the layer control (several layers only), default "Layer N".

Several layers

Pass a list instead of one frame to draw several frames on one map, like m = gdf1.explore(); gdf2.explore(m=m) plus folium.LayerControl() in GeoPandas. Each entry is a frame, or {frame, options} with its own :color, :radius, :width, :opacity, :tooltip, :popup, :legend and :name:

GeoFrame.Kino.deck(
  [
    {countries, name: "Countries", color: {"POP_EST", :viridis}, popup: ["NAME"]},
    {cities, name: "Cities", color: {200, 30, 30}, radius: 4, tooltip: ["name"]}
  ],
  height: 600
)

Layer options given in the second argument are defaults for every layer; an entry's own options win. The options of the whole map (:basemap, :height, :scale, :max_features, :max_vertices) are top-level only. A top-left panel has a checkbox per layer; hiding a layer also hides its legend and closes its popup, and each layer keeps its own legend card, tooltip and popup. The map fits the union of the layers' bounds. A list of one frame still draws the layer control; a bare frame draws none and sends the same payload as before.

:max_features and :max_vertices are totals over all layers of the widget, so ten layers of 100 000 rows count as 1 000 000 features. The tooltip and popup cell caps apply to each layer. All layers travel in the one binary payload, each buffer named "<layer>.<name>".

deck.gl and MapLibre GL load in the browser from pinned jsDelivr URLs, so the widget needs internet access there.

Summary

Types

A frame drawn by the widget.

One layer: a frame, or a frame with its own options.

Functions

Builds the widget kino. See the module docs for the options and for drawing several frames as layers.

Types

frame()

A frame drawn by the widget.

layer()

@type layer() :: frame() | {frame(), keyword()}

One layer: a frame, or a frame with its own options.

Functions

new(frame, opts \\ [])

@spec new(frame() | [layer()], keyword()) :: Kino.JS.Live.t()

Builds the widget kino. See the module docs for the options and for drawing several frames as layers.

Raises ArgumentError for invalid options, unknown columns, an input above :max_features or one with nothing to draw.