@xtramaps/layer-control-maplibre
v1.3.1
Published
Framework-agnostic core logic for the LayerControl component: parses a nested group / radio-group / merge-group configuration (or a style's own embedded `metadata["ldproxy:layerControl"]`) against a MapLibre style into a hydrated, ready-to-render tree.
Readme
@xtramaps/layer-control-maplibre
Framework-agnostic core logic for the LayerControl component: parses a nested group / radio-group / merge-group configuration (or a style's own embedded metadata["ldproxy:layerControl"]) against a MapLibre style into a hydrated, ready-to-render tree.
Install
npm install @xtramaps/layer-control-maplibreUses @xtramaps/legend-symbols-maplibre's loadSprites() for sprite loading.
Usage
import { parse, initialCfg } from "@xtramaps/layer-control-maplibre";
const config = await parse(style, entries, /* preferStyle */ true);
// config.entries -> hydrated tree ready to render
// config.selectedIds / radioIds -> initial selection, derived from the layers' `visibility`
// config.openedIds -> initially expanded groups (all except those with `opened: false`)
// config.deps / depsParent / depsChild -> selection-cascade dependency mapsLayers with layout.visibility: "none" in the style start deselected, groups start selected only if all their entries are selected, merge-groups (shown as a single entry) as soon as one of their layers is visible, and radio-groups start with their first entry that is not hidden. Groups and radio-groups are expanded unless configured with opened: false.
Exports
parse()- the main entry point: hydratesentriesagainst a style's layers and loads spritesgetIds(),getDeps(),getParentDeps(),getChildDeps(),getRadioGroups(),asLayer(),getId(),getLabel()- tree-walking helpersinitialCfg- empty default config, useful as initial React/Vue/Svelte state
License
MIT
