npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@open-pioneer/toc

v1.4.0

Published

This package provides a UI component that displays the map content to the user and allows them to control it.

Readme

@open-pioneer/toc

This package provides a UI component that displays the map content to the user and allows them to control it.

Unavailable operational layers are marked with an icon and will be deactivated for selection. If a layer was configured as initially visible, it remains visible.

Usage

To integrate the TOC (table of contents) in your app, insert the following snippet (and reference a map):

<Toc
    map={map}
/> /* instead of passing the map, the `DefaultMapProvider` can alternatively be used */

Tools

Additional tools are available for operational layers. To show the toolset menu, set the showTools property to true.

<Toc map={map} showTools={true} />

The default tools provided by the TOC are:

  • A button to hide all layers (sets visibility to false, enabled by default)
  • A button to collapse all groups (enabled by default if groups are collapsible)

These tools can be configured by using the toolsConfig property.

Basemaps

By default, the TOC shows the basemap switcher as an embedded element.

To hide the basemap switcher, set the showBasemapSwitcher property to false:

<Toc map={map} showBasemapSwitcher={false} />

To configure the embedded basemap switcher, use the basemapSwitcherProps property:

<Toc
    map={map}
    basemapSwitcherProps={{
        allowSelectingEmptyBasemap: true
    }}
/>

Layer IDs as CSS classes on list items

List items for individual operational layers receive the layer's id as an additional CSS class (layer-${id}).

For example, given a layer with the ID test-geojson, the TOC's list item for that layer is rendered as:

<li class="toc-layer-item layer-test-geojson ...">
    <!-- -->
</li>

NOTE: Non-alphanumeric characters present in the layer's ID are removed from the class name. Whitespace is replaced with a single -.

NOTE: List items are not guaranteed to be rendered as li. Only the CSS class name is guaranteed.

Automatic parent layer visibility

When showing a layer via the TOC component (e.g. by clicking the checkbox next to its name), all parent layers of that layer will also be made visible by default.

This can be disabled by configuring autoShowParents={false} on the TOC component.

// Default: true
<Toc autoShowParents={false} />

Collapsible groups

The TOC renders the hierarchy of layers as a tree structure of nested lists ("groups"). Groups can be made collapsible through user action by setting the collapsibleGroups property to true. If enabled, a toggle button appears next to parent nodes by which the user can expand or collapse the group.

<Toc
    map={map}
    collapsibleGroups={true}
    initiallyCollapsed={true} // Whether groups are collapsed by default. Defaults to false.
/>

Hide certain layers in Toc

Layers that are marked as internal are not considered by the Toc.

//internal layer will not be displayed in the Toc
const internalLayer = layerFactory.create({
    type: SimpleLayer,
    id: "layer1",
    title: "layer 1",
    olLayer: myOlLayer,
    internal: true
});

The layer's internal state also affects other UI widgets (e.g. Legend). If the layer should be hidden specifically in the Toc (but not in other widgets) the listMode attribute can be used to hide the layer item.

//use listMode to hide the layer specifically in Toc
const hiddenLayer = layerFactory.create({
    type: SimpleLayer,
    id: "layer1",
    title: "layer 1",
    olLayer: myOlLayer,
    attributes: {
        toc: {
            listMode: "hide"
        }
    }
});

Valid values for listMode are:

  • "show" layer item is displayed in Toc
  • "hide" layer item is not rendered in Toc
  • "hide-children" layer item for the layer itself is displayed in Toc but no layer items for child layers (e.g. sublayers of a group) are rendered

The listMode always has precedence over the layer's internal property. For example, if the listMode is "show" the layer item is displayed even if internal is true.

Using the Toc API to manipulate Toc Items programmatically

The Toc API allows programmatic access to the Toc.

Currently, the Toc API allows accessing the individual Toc items.
Toc items can be expanded/collapsed and provide access to the corresponding DOM element.

import { Toc, TocApi, TocReadyEvent } from "@open-pioneer/toc";
import { Button } from "@chakra-ui/react";

const tocApi = useRef<TocApi>(undefined);

// Expand or collapse group layer with the Toc API
function toggleTocItem(layerId: string) {
    if (!tocApi.current) {
        return; // toc not ready yet
    }

    const layerItem = tocApi.current.getItemByLayerId(layerId);
    if (!layerItem) {
        return; // item not found
    }

    console.log("Current html element", layerItem.htmlElement); // access DOM element (e.g. for scrolling)
    const newState = !layerItem.isExpanded;
    layerItem.setExpanded(newState);
}

<Toc
    // get API object from ready event and store it somewhere
    onReady={(e) => { tocApi.current = e.api; }}

    // don't use the API object after the toc has been destroyed
    onDisposed={() => { tocApi.current = undefined; }}
/>

<Button onClick={() => toggleTocItem("myGroupLayer")}>Toggle group layer</Button>

License

Apache-2.0 (see LICENSE file)