SolidPolygonLayer¶
lonboard.SolidPolygonLayer ¶
Bases: BaseArrowLayer
The SolidPolygonLayer
renders filled and/or extruded polygons.
Note
This layer is similar to the PolygonLayer
but will
not render an outline around polygons. In most cases, you'll want to use the
PolygonLayer
directly, but for very large datasets not drawing the outline can
significantly improve performance, in which case you may want to use this layer.
Example:
From GeoPandas:
import geopandas as gpd
from lonboard import Map, SolidPolygonLayer
# A GeoDataFrame with Polygon or MultiPolygon geometries
gdf = gpd.GeoDataFrame()
layer = SolidPolygonLayer.from_geopandas(
gdf,
get_fill_color=[255, 0, 0],
)
m = Map(layer)
From geoarrow-rust:
from geoarrow.rust.core import read_parquet
from lonboard import Map, SolidPolygonLayer
# Example: A GeoParquet file with Polygon or MultiPolygon geometries
table = read_parquet("path/to/file.parquet")
layer = SolidPolygonLayer(
table=table,
get_fill_color=[255, 0, 0],
)
m = Map(layer)
auto_highlight
class-attribute
instance-attribute
¶
auto_highlight = tag(sync=True)
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
elevation_scale
class-attribute
instance-attribute
¶
elevation_scale = tag(sync=True)
Elevation multiplier. The final elevation is calculated by elevation_scale *
get_elevation(d)
. elevation_scale
is a handy property to scale all elevation
without updating the data.
- Type:
float
, optional - Default:
1
extensions
class-attribute
instance-attribute
¶
extensions = tag(sync=True, **widget_serialization)
A list of layer extension objects to add additional features to a layer.
extruded
class-attribute
instance-attribute
¶
extruded = tag(sync=True)
Whether to extrude the polygons (based on the elevations provided by the
get_elevation
accessor'). If set to False
, all polygons will be flat, this
generates less geometry and is faster than simply returning 0
from
get_elevation
.
- Type:
bool
, optional - Default:
False
filled
class-attribute
instance-attribute
¶
filled = tag(sync=True)
Whether to fill the polygons (based on the color provided by the
get_fill_color
accessor).
- Type:
bool
, optional - Default:
True
get_elevation
class-attribute
instance-attribute
¶
get_elevation = FloatAccessor(None, allow_none=True)
The elevation to extrude each polygon with, in meters.
Only applies if extruded=True
.
- Type: FloatAccessor, optional
- If a number is provided, it is used as the width for all polygons.
- If an array is provided, each value in the array will be used as the width for the polygon at the same row index.
- Default:
1000
.
get_fill_color
class-attribute
instance-attribute
¶
get_fill_color = ColorAccessor(None, allow_none=True)
The fill color of each polygon in the format of [r, g, b, [a]]
. Each channel is a
number between 0-255 and a
is 255 if not supplied.
- Type: ColorAccessor, optional
- If a single
list
ortuple
is provided, it is used as the fill color for all polygons. - If a numpy or pyarrow array is provided, each value in the array will be used as the fill color for the polygon at the same row index.
- If a single
- Default:
[0, 0, 0, 255]
.
get_line_color
class-attribute
instance-attribute
¶
get_line_color = ColorAccessor(None, allow_none=True)
The line color of each polygon in the format of [r, g, b, [a]]
. Each channel is a
number between 0-255 and a
is 255 if not supplied.
Only applies if extruded=True
.
- Type: ColorAccessor, optional
- If a single
list
ortuple
is provided, it is used as the line color for all polygons. - If a numpy or pyarrow array is provided, each value in the array will be used as the line color for the polygon at the same row index.
- If a single
- Default:
[0, 0, 0, 255]
.
opacity
class-attribute
instance-attribute
¶
opacity = tag(sync=True)
The opacity of the layer.
- Type:
float
. Must range between 0 and 1. - Default:
1
pickable
class-attribute
instance-attribute
¶
pickable = tag(sync=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
class-attribute
instance-attribute
¶
selected_index = tag(sync=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.
table
class-attribute
instance-attribute
¶
table = PyarrowTableTrait(allowed_geometry_types={POLYGON, MULTIPOLYGON})
A GeoArrow table with a Polygon or MultiPolygon 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
][lonboard.SolidPolygonLayer.from_geopandas] instead.
visible
class-attribute
instance-attribute
¶
visible = tag(sync=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
wireframe
class-attribute
instance-attribute
¶
wireframe = tag(sync=True)
Whether to generate a line wireframe of the polygon. The outline will have "horizontal" lines closing the top and bottom polygons and a vertical line (a "strut") for each vertex on the polygon.
- Type:
bool
, optional - Default:
False
Remarks:
- These lines are rendered with
GL.LINE
and will thus always be 1 pixel wide. - Wireframe and solid extrusions are exclusive, you'll need to create two layers with the same data if you want a combined rendering effect.