geohierarchy.maps.folium.style¶
Declarative styling for vector-tile layers.
Leaflet.VectorGrid styles tiles client-side via a vectorTileLayerStyles
callback that receives each feature's properties, so a Python-side
style can't be a plain callable -- it has to be codegen'd into a small
JS snippet. :class:ColorSpec is the declarative way to build that
snippet (and the matching branca colormap for the legend); a raw
style_js string bypasses it entirely.
ColorSpec(column, cmap='viridis', domain=None, categories=None, kind='continuous', opacity=0.7, weight=1.0, color=None, fill=True, nodata_color='#888888')
dataclass
¶
Declarative color/style rule for one hierarchy level's vector tiles.
Attributes:
| Name | Type | Description |
|---|---|---|
column |
str
|
Feature property to color by. |
cmap |
Any
|
Name of a branca/matplotlib colormap (continuous) or a list of hex colors (categorical, cycled/keyed by sorted category). |
domain |
Optional[Tuple[float, float]]
|
|
categories |
Optional[Dict[str, str]]
|
Explicit category -> color mapping for
|
kind |
Literal['continuous', 'categorical']
|
|
opacity |
float
|
Fill opacity. |
weight |
float
|
Stroke weight (px). |
color |
Optional[str]
|
Stroke color. Defaults to the fill color if not given. |
fill |
bool
|
Whether polygons/points are filled. |
nodata_color |
str
|
Color used when |
branca_colormap(gdf=None)
¶
Build the matching :mod:branca.colormap object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
Optional GeoDataFrame/DataFrame used to infer |
None
|
Returns:
| Type | Description |
|---|---|
|
A |
|
|
continuous, step for categorical). |
style_js(gdf=None, var_name='style')
¶
Generate the JS style function body for this spec.
Returns:
| Type | Description |
|---|---|
str
|
JS source defining |
str
|
returning a Leaflet path-style object, suitable for use inside |
str
|
a |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
Optional level data, used to sample the colour scale when the spec has no fixed domain. |
None
|
|
var_name
|
str
|
Name of the JavaScript function. |
'style'
|
maplibre_fill_color_expr(gdf=None)
¶
Build a MapLibre GL style expression for this spec's fill color.
Mirrors :meth:style_js (same sampling/lookup logic) but targets
MapLibre's declarative expression language instead of a Leaflet.
VectorGrid callback, so a Folium-vector-tile level and a MapLibre
PMTiles layer sourced from the same tiles reach the same visual
result -- this is the piece that lets
:mod:geohierarchy.maps.maplibre reach base-layer parity with
:mod:geohierarchy.maps.folium without re-deriving color logic.
Returns:
| Type | Description |
|---|---|
Any
|
A MapLibre expression (JSON-serializable list), usable directly |
Any
|
as a |
Any
|
value. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
Optional level data, used to sample the colour scale when the spec has no fixed domain. |
None
|
maplibre_paint(kind='polygon', gdf=None)
¶
Build a full MapLibre paint dict for this spec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
One of |
'polygon'
|
gdf
|
Optional data used to infer domain/categories (see
:meth: |
None
|
build_vector_tile_layer_styles_js(layer_name, style_js_body)
¶
Wrap a per-layer style function into a vectorTileLayerStyles entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_name
|
str
|
Vector tile layer name (matches the layer name used
when encoding tiles in :mod: |
required |
style_js_body
|
str
|
JS source produced by :meth: |
required |
Returns:
| Type | Description |
|---|---|
str
|
A JS object-literal fragment: |