Skip to content

Commit

Permalink
Merge pull request #1720 from terrestris/showLegends
Browse files Browse the repository at this point in the history
feat: show legends per default
  • Loading branch information
TreffN authored Aug 5, 2024
2 parents 2dd8582 + c068bc2 commit c4e9a5f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ import {
EditLevel
} from './store/editFeature';
import { setFeatureInfoActiveCopyTools } from './store/featureInfo';
import { setLayerTreeActiveUploadTools } from './store/layerTree';
import {
setLayerTreeActiveUploadTools,
setLayerTreeShowLegends
} from './store/layerTree';
import {
setLegal
} from './store/legal';
Expand Down Expand Up @@ -271,6 +274,9 @@ const setApplicationToStore = async (application?: Application) => {
if (tool.name === 'tree' && Array.isArray(tool.config.uploadTools)) {
store.dispatch(setLayerTreeActiveUploadTools(tool.config.uploadTools));
}
if (tool.name === 'tree' && tool.config.showLegends) {
store.dispatch(setLayerTreeShowLegends(tool.config.showLegends));
}
});
store.dispatch(setAvailableTools(availableTools));
}
Expand Down
13 changes: 5 additions & 8 deletions src/components/ToolMenu/LayerTree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import {
getBearerTokenHeader
} from '@terrestris/shogun-util/dist/security/getBearerTokenHeader';

import useAppSelector from '../../../hooks/useAppSelector';
import useSHOGunAPIClient from '../../../hooks/useSHOGunAPIClient';
import { UploadTools } from '../../../store/layerTree';

import WmsTimeSlider from '../../WmsTimeSlider';

Expand All @@ -58,11 +58,6 @@ export type LayerTileLoadCounter = {
};
};

export type LayerTreeConfig = {
enabled?: boolean;
activeUploadTools?: UploadTools[];
};

export const LayerTree: React.FC<LayerTreeProps> = ({
...restProps
}): JSX.Element => {
Expand All @@ -72,11 +67,13 @@ export const LayerTree: React.FC<LayerTreeProps> = ({
t
} = useTranslation();

const [visibleLegendsIds, setVisibleLegendsIds] = useState<string[]>([]);
const [layerTileLoadCounter, setLayerTileLoadCounter] = useState<LayerTileLoadCounter>({});
const showLegendsState: boolean = useAppSelector(state => state.layerTree.showLegends) ?? false;

const initialLayersUid = map?.getAllLayers().map(l => getUid(l));

const [visibleLegendsIds, setVisibleLegendsIds] = useState<string[]> (showLegendsState ? initialLayersUid ?? [] : []);
const [layerTileLoadCounter, setLayerTileLoadCounter] = useState<LayerTileLoadCounter>({});

const registerTileLoadHandler = useCallback(() => {
if (!map) {
return;
Expand Down
15 changes: 12 additions & 3 deletions src/store/layerTree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
PayloadAction
} from '@reduxjs/toolkit';

import { LayerTreeConfig } from '../../components/ToolMenu/LayerTree';
export type LayerTreeConfig = {
enabled?: boolean;
activeUploadTools?: UploadTools[];
showLegends?: boolean;
};

// eslint-disable-next-line no-shadow
export enum UploadTools {
Expand All @@ -13,7 +17,8 @@ export enum UploadTools {

const initialState: LayerTreeConfig = {
enabled: false,
activeUploadTools: [UploadTools.addWMS, UploadTools.dataUpload]
activeUploadTools: [UploadTools.addWMS, UploadTools.dataUpload],
showLegends: false
};

export const slice = createSlice({
Expand All @@ -28,13 +33,17 @@ export const slice = createSlice({
},
setLayerTreeActiveUploadTools(state, action: PayloadAction<UploadTools[]>) {
state.activeUploadTools = action.payload;
},
setLayerTreeShowLegends(state, action: PayloadAction<boolean>) {
state.showLegends = action.payload;
}
}
});

export const {
setLayerTreeEnabled,
setLayerTreeActiveUploadTools
setLayerTreeActiveUploadTools,
setLayerTreeShowLegends
} = slice.actions;

export default slice.reducer;

0 comments on commit c4e9a5f

Please sign in to comment.