Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion demo/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const framePlugin = createFramePlugin({

const datasetsPlugin = createDatasetsPlugin({
layerAdapter: maplibreLayerAdapter,

// Example: Dynamic bbox-based fetching (uncomment to test)
datasets: [
{
Expand Down
4 changes: 3 additions & 1 deletion plugins/beta/datasets/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// /plugins/datasets/index.js
import './datasets.scss'

export default function createPlugin (options = {}) {
export default function createPlugin (options = { }) {
console.log('options', options)
const plugin = {
noKeyItemText: 'No features displayed',
...options,
id: 'datasets',
load: async () => {
Expand Down
7 changes: 7 additions & 0 deletions plugins/beta/datasets/src/panels/EmptyKey.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const EmptyKey = ({ text }) => {
return (
<div class='im-c-datasets-key'>
<p class='im-c-datasets-key__empty-message'>{text}</p>
</div>
)
}
6 changes: 5 additions & 1 deletion plugins/beta/datasets/src/panels/Key.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { getValueForStyle } from '../../../../../src/utils/getValueForStyle'
import { hasPattern, getKeyPatternPaths } from '../../../../../src/utils/patternUtils.js'
import { mergeSublayer } from '../utils/mergeSublayer.js'
import { hasSymbol, getSymbolDef, getSymbolStyleColors, getSymbolViewBox } from '../../../../../src/utils/symbolUtils.js'
import { EmptyKey } from './EmptyKey.jsx'

const SVG_SIZE = 20
const SVG_SYMBOL_SIZE = 38
const SVG_CENTER = SVG_SIZE / 2
const PATTERN_INSET = 2

export const Key = ({ mapState, pluginState, services }) => {
export const Key = ({ pluginConfig, mapState, pluginState, services }) => {
if (!pluginState?.key?.items?.length) {
return (<EmptyKey text={pluginConfig.noKeyItemText} />)
}
const { mapStyle } = mapState
const { symbolRegistry, patternRegistry } = services

Expand Down
13 changes: 2 additions & 11 deletions plugins/beta/datasets/src/reducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { applyDatasetDefaults } from './defaults.js'
import { buildKeyState } from './utils/buildKeyState.js'
import { keyReducer } from './reducers/keyReducer.js'

const initialState = {
datasets: null,
Expand Down Expand Up @@ -195,17 +195,8 @@ const setSublayerOpacity = (state, payload) => {

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

const buildKeyGroups = (state) => {
const visibleDatasets = state.datasets
? state.datasets.filter(dataset => dataset.showInKey && dataset.visibility !== 'hidden')
: []
const items = buildKeyState(visibleDatasets)
const hasGroups = items.some(item => item.type === 'sublayers' || item.type === 'group')
return { ...state, key: { items, hasGroups } }
}

const actions = {
BUILD_KEY_GROUPS: buildKeyGroups,
BUILD_KEY_GROUPS: keyReducer,
SET_DATASETS: setDatasets,
ADD_DATASET: addDataset,
REMOVE_DATASET: removeDataset,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
export const buildKeyState = (datasets) => {
export const keyReducer = (state) => {
const datasets = state.datasets || []
const seenGroups = new Set()
const items = []
let hasGroups = false
datasets.forEach(dataset => {
if (!dataset.showInKey || dataset.visibility === 'hidden') {
return
}
if (dataset.sublayers?.length) {
items.push({ type: 'sublayers', dataset })
const { sublayerVisibility = [] } = dataset
if (Object.values(sublayerVisibility).some((value) => value !== 'hidden')) {
hasGroups = true
items.push({ type: 'sublayers', dataset })
}
return
}
if (dataset.groupLabel) {
if (seenGroups.has(dataset.groupLabel)) {
return
}
seenGroups.add(dataset.groupLabel)
hasGroups = true
items.push({
type: 'group',
groupLabel: dataset.groupLabel,
Expand All @@ -20,5 +30,5 @@ export const buildKeyState = (datasets) => {
}
items.push({ type: 'flat', dataset })
})
return items
return { ...state, key: { items, hasGroups } }
}
Loading