Skip to content

geohierarchy.maps.layers

Modular layer-type registry, shared by the Folium and MapLibre renderers.

Every level a :class:~geohierarchy.maps.folium.render.HierarchyMap renders (hexagon-per-resolution, circle, census polygon, street/development overlay, ...) reduces to one of a small number of geometry-rendering primitives ("kinds") -- filled polygons, radius-scaled circle points, or stroked lines -- styled by a :class:~geohierarchy.maps.folium.style.ColorSpec. This module names that primitive-per-level-type mapping as an explicit registry (:data:LAYER_TYPES) instead of leaving it implicit/duplicated in each renderer, so:

  • Folium (Leaflet.VectorGrid) and MapLibre (PMTiles) renderers can both consume the same registry entry for a given layer type and stay visually consistent without hand-syncing style logic in two places.
  • Adding a genuinely new layer type (e.g. building footprints) is a one-time :func:register_layer_type call, not a rewrite of either renderer.

See :mod:geohierarchy.maps.maplibre.render for the consumer that turns a registry entry + a :class:~geohierarchy.maps.folium.render.MapLayer into an actual MapLibre GL source/layer pair.

LayerTypeSpec(name, kind, interactive=True, default_paint=dict(), description='') dataclass

A registered layer type.

Attributes:

Name Type Description
name str

Registry key, e.g. "hexagon", "circle", "census_polygon", "street_overlay", "development_overlay".

kind LayerKind

Geometry-rendering primitive -- see :data:LayerKind. Drives which MapLibre layer "type" is emitted (fill/circle/line) and which branch of :meth:~geohierarchy.maps.folium.style.ColorSpec.maplibre_paint / Leaflet vectorTileLayerStyles shape (fillColor vs. radius vs. stroke-only) applies.

interactive bool

Whether click/hover (popup + hover-highlight) should be wired up by default for this layer type. Overlay/annotation layers (e.g. a border-only development-priority overlay) often set this False.

default_paint Dict[str, object]

Optional MapLibre paint overrides merged UNDER whatever :meth:ColorSpec.maplibre_paint produces (e.g. a circle layer type's base radius). Renderer-supplied paint keys win.

description str

Human-readable summary, surfaced by :func:list_layer_types for discoverability.

register_layer_type(spec, *, overwrite=False)

Register a new layer type.

Parameters:

Name Type Description Default
spec LayerTypeSpec

The :class:LayerTypeSpec to register.

required
overwrite bool

If False (default), raises if spec.name is already registered -- catches accidental duplicate registration rather than silently shadowing an existing type.

False

Returns:

Type Description
LayerTypeSpec

spec, for convenient use as FOO = register_layer_type(...).

get_layer_type(name)

Look up a registered layer type by name.

Parameters:

Name Type Description Default
name Optional[str]

Registry key, or None to get the default ("polygon") -- the common case for most hierarchy levels (hexagons, census polygons, any other filled-area level).

required

Returns:

Type Description
LayerTypeSpec

The matching :class:LayerTypeSpec.

Raises:

Type Description
KeyError

If name isn't registered. Message lists what IS registered, since this is a config/typo error a caller should fix, not something to fall back silently from.

list_layer_types()

Return {name: description} for every registered layer type.