Skip to content

Commit e749807

Browse files
committed
Keys now handle no items in groups or overall
1 parent 88789c9 commit e749807

File tree

6 files changed

+30
-17
lines changed

6 files changed

+30
-17
lines changed

demo/js/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const framePlugin = createFramePlugin({
7070

7171
const datasetsPlugin = createDatasetsPlugin({
7272
layerAdapter: maplibreLayerAdapter,
73-
7473
// Example: Dynamic bbox-based fetching (uncomment to test)
7574
datasets: [
7675
{

plugins/beta/datasets/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// /plugins/datasets/index.js
22
import './datasets.scss'
33

4-
export default function createPlugin (options = {}) {
4+
export default function createPlugin (options = { }) {
5+
console.log('options', options)
56
const plugin = {
7+
noKeyItemText: 'No features displayed',
68
...options,
79
id: 'datasets',
810
load: async () => {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const EmptyKey = ({ text }) => {
2+
return (
3+
<div class='im-c-datasets-key'>
4+
<p class='im-c-datasets-key__empty-message'>{text}</p>
5+
</div>
6+
)
7+
}

plugins/beta/datasets/src/panels/Key.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import { getValueForStyle } from '../../../../../src/utils/getValueForStyle'
33
import { hasPattern, getKeyPatternPaths } from '../../../../../src/utils/patternUtils.js'
44
import { mergeSublayer } from '../utils/mergeSublayer.js'
55
import { hasSymbol, getSymbolDef, getSymbolStyleColors, getSymbolViewBox } from '../../../../../src/utils/symbolUtils.js'
6+
import { EmptyKey } from './EmptyKey.jsx'
67

78
const SVG_SIZE = 20
89
const SVG_SYMBOL_SIZE = 38
910
const SVG_CENTER = SVG_SIZE / 2
1011
const PATTERN_INSET = 2
1112

12-
export const Key = ({ mapState, pluginState, services }) => {
13+
export const Key = ({ pluginConfig, mapState, pluginState, services }) => {
14+
if (!pluginState?.key?.items?.length) {
15+
return (<EmptyKey text={pluginConfig.noKeyItemText} />)
16+
}
1317
const { mapStyle } = mapState
1418
const { symbolRegistry, patternRegistry } = services
1519

plugins/beta/datasets/src/reducer.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { applyDatasetDefaults } from './defaults.js'
2-
import { buildKeyState } from './utils/buildKeyState.js'
2+
import { keyReducer } from './reducers/keyReducer.js'
33

44
const initialState = {
55
datasets: null,
@@ -195,17 +195,8 @@ const setSublayerOpacity = (state, payload) => {
195195

196196
const setLayerAdapter = (state, payload) => ({ ...state, layerAdapter: payload })
197197

198-
const buildKeyGroups = (state) => {
199-
const visibleDatasets = state.datasets
200-
? state.datasets.filter(dataset => dataset.showInKey && dataset.visibility !== 'hidden')
201-
: []
202-
const items = buildKeyState(visibleDatasets)
203-
const hasGroups = items.some(item => item.type === 'sublayers' || item.type === 'group')
204-
return { ...state, key: { items, hasGroups } }
205-
}
206-
207198
const actions = {
208-
BUILD_KEY_GROUPS: buildKeyGroups,
199+
BUILD_KEY_GROUPS: keyReducer,
209200
SET_DATASETS: setDatasets,
210201
ADD_DATASET: addDataset,
211202
REMOVE_DATASET: removeDataset,
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
export const buildKeyState = (datasets) => {
1+
export const keyReducer = (state) => {
2+
const datasets = state.datasets || []
23
const seenGroups = new Set()
34
const items = []
5+
let hasGroups = false
46
datasets.forEach(dataset => {
7+
if (!dataset.showInKey || dataset.visibility === 'hidden') {
8+
return
9+
}
510
if (dataset.sublayers?.length) {
6-
items.push({ type: 'sublayers', dataset })
11+
const { sublayerVisibility = [] } = dataset
12+
if (Object.values(sublayerVisibility).some((value) => value !== 'hidden')) {
13+
hasGroups = true
14+
items.push({ type: 'sublayers', dataset })
15+
}
716
return
817
}
918
if (dataset.groupLabel) {
1019
if (seenGroups.has(dataset.groupLabel)) {
1120
return
1221
}
1322
seenGroups.add(dataset.groupLabel)
23+
hasGroups = true
1424
items.push({
1525
type: 'group',
1626
groupLabel: dataset.groupLabel,
@@ -20,5 +30,5 @@ export const buildKeyState = (datasets) => {
2030
}
2131
items.push({ type: 'flat', dataset })
2232
})
23-
return items
33+
return { ...state, key: { items, hasGroups } }
2434
}

0 commit comments

Comments
 (0)