MCPcopy Create free account
hub / github.com/protomaps/PMTiles / LayersPanel

Function LayersPanel

app/src/LayersPanel.tsx:17–137  ·  view source on GitHub ↗
(props: {
  layerVisibility: Accessor<LayerVisibility[]>;
  setLayerVisibility: Setter<LayerVisibility[]>;
  layerFeatureCounts?: Record<string, number>;

  basemapOption?: boolean;
  basemap?: Accessor<boolean>;
  setBasemap?: Setter<boolean>;
})

Source from the content-addressed store, hash-verified

15}
16
17export function LayersPanel(props: {
18 layerVisibility: Accessor<LayerVisibility[]>;
19 setLayerVisibility: Setter<LayerVisibility[]>;
20 layerFeatureCounts?: Record<string, number>;
21
22 basemapOption?: boolean;
23 basemap?: Accessor<boolean>;
24 setBasemap?: Setter<boolean>;
25}) {
26 let checkallRef: HTMLInputElement | undefined;
27 const [expanded, setExpanded] = createSignal<boolean>(true);
28
29 const onChange = (id: string) => {
30 const newLayerVisibility = props
31 .layerVisibility()
32 .map((l: LayerVisibility) =>
33 l.id === id ? { ...l, visible: !l.visible } : l,
34 );
35 props.setLayerVisibility(newLayerVisibility);
36 };
37
38 const allChecked = createMemo(() => {
39 const visibleLayersCount = props
40 .layerVisibility()
41 .filter((l: LayerVisibility) => l.visible).length;
42 return visibleLayersCount === props.layerVisibility().length;
43 });
44
45 const toggleAll = () => {
46 props.setLayerVisibility(
47 props
48 .layerVisibility()
49 .map((l: LayerVisibility) => ({ ...l, visible: !allChecked() })),
50 );
51 };
52
53 createEffect(() => {
54 const visibleLayersCount = props
55 .layerVisibility()
56 .filter((l) => l.visible).length;
57 const indeterminate =
58 visibleLayersCount > 0 &&
59 visibleLayersCount !== props.layerVisibility().length;
60 if (checkallRef) {
61 checkallRef.indeterminate = indeterminate;
62 }
63 });
64
65 return (
66 <div class="app-bg rounded app-border flex flex-col overflow-y-scroll max-h-100">
67 <button
68 type="button"
69 classList={{
70 "app-well": true,
71 "rounded-t": expanded(),
72 rounded: !expanded(),
73 "cursor-pointer": true,
74 "min-w-8": true,

Callers

nothing calls this directly

Calls 3

colorForIdxFunction · 0.90
onChangeFunction · 0.85
layerFeatureCountsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…