new interface for layer handling

closes #1059
This commit is contained in:
Mateusz Konieczny 2023-01-19 14:12:33 +01:00
parent 7d7edf6df3
commit 17688e9e38
5 changed files with 68 additions and 62 deletions

View File

@ -3,8 +3,8 @@ import React, { createContext, useCallback, useContext, useEffect, useState } fr
import { LayerEnablementState, MapTheme } from './config/map-config'; import { LayerEnablementState, MapTheme } from './config/map-config';
interface DisplayPreferencesContextState { interface DisplayPreferencesContextState {
resetLayers: (e: React.FormEvent<HTMLFormElement>) => void; showOverlayList: (e: React.FormEvent<HTMLFormElement>) => void;
anyLayerModifiedState: () => boolean; resetLayersAndHideTheirList: (e: React.FormEvent<HTMLFormElement>) => void;
vista: LayerEnablementState; vista: LayerEnablementState;
vistaSwitch: (e: React.FormEvent<HTMLFormElement>) => void; vistaSwitch: (e: React.FormEvent<HTMLFormElement>) => void;
@ -41,6 +41,10 @@ interface DisplayPreferencesContextState {
darkLightTheme: MapTheme; darkLightTheme: MapTheme;
darkLightThemeSwitch: (e: React.FormEvent<HTMLFormElement>) => void; darkLightThemeSwitch: (e: React.FormEvent<HTMLFormElement>) => void;
darkLightThemeSwitchOnClick: React.MouseEventHandler<HTMLButtonElement>; darkLightThemeSwitchOnClick: React.MouseEventHandler<HTMLButtonElement>;
showLayerSelection: LayerEnablementState;
showLayerSelectionSwitch: (e: React.FormEvent<HTMLFormElement>) => void;
showLayerSelectionSwitchOnClick: React.MouseEventHandler<HTMLButtonElement>;
} }
const stub = (): never => { const stub = (): never => {
@ -48,8 +52,8 @@ const stub = (): never => {
}; };
export const DisplayPreferencesContext = createContext<DisplayPreferencesContextState>({ export const DisplayPreferencesContext = createContext<DisplayPreferencesContextState>({
resetLayers: stub, showOverlayList: stub,
anyLayerModifiedState: stub, resetLayersAndHideTheirList: stub,
vista: undefined, vista: undefined,
vistaSwitch: stub, vistaSwitch: stub,
@ -86,6 +90,10 @@ export const DisplayPreferencesContext = createContext<DisplayPreferencesContext
darkLightTheme: undefined, darkLightTheme: undefined,
darkLightThemeSwitch: stub, darkLightThemeSwitch: stub,
darkLightThemeSwitchOnClick: undefined, darkLightThemeSwitchOnClick: undefined,
showLayerSelection: undefined,
showLayerSelectionSwitch: stub,
showLayerSelectionSwitchOnClick: undefined,
}); });
const noop = () => {}; const noop = () => {};
@ -99,6 +107,7 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
const defaultParcel = 'disabled' const defaultParcel = 'disabled'
const defaultConservation = 'disabled' const defaultConservation = 'disabled'
const defaultHistoricData = 'disabled' const defaultHistoricData = 'disabled'
const defaultShowLayerSelection = 'disabled'
const [vista, setVista] = useState<LayerEnablementState>(defaultVista); const [vista, setVista] = useState<LayerEnablementState>(defaultVista);
const [flood, setFlood] = useState<LayerEnablementState>(defaultFlood); const [flood, setFlood] = useState<LayerEnablementState>(defaultFlood);
const [creative, setCreative] = useState<LayerEnablementState>(defaultCreative); const [creative, setCreative] = useState<LayerEnablementState>(defaultCreative);
@ -108,10 +117,17 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
const [conservation, setConservation] = useState<LayerEnablementState>(defaultConservation); const [conservation, setConservation] = useState<LayerEnablementState>(defaultConservation);
const [historicData, setHistoricData] = useState<LayerEnablementState>(defaultHistoricData); const [historicData, setHistoricData] = useState<LayerEnablementState>(defaultHistoricData);
const [darkLightTheme, setDarkLightTheme] = useState<MapTheme>('night'); const [darkLightTheme, setDarkLightTheme] = useState<MapTheme>('night');
const [showLayerSelection, setShowLayerSelection] = useState<LayerEnablementState>(defaultShowLayerSelection);
const resetLayers = useCallback( const showOverlayList = useCallback(
(e) => {
setShowLayerSelection('enabled')
},
[]
)
const resetLayersAndHideTheirList = useCallback(
(e) => { (e) => {
e.preventDefault();
setVista(defaultVista); setVista(defaultVista);
setFlood(defaultFlood); setFlood(defaultFlood);
setCreative(defaultCreative); setCreative(defaultCreative);
@ -120,6 +136,7 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
setParcel(defaultParcel); setParcel(defaultParcel);
setConservation(defaultConservation); setConservation(defaultConservation);
setHistoricData(defaultHistoricData); setHistoricData(defaultHistoricData);
setShowLayerSelection(defaultShowLayerSelection); // reset layers + hiding this panel is integrated into one action
//setDarkLightTheme('night'); // reset only layers //setDarkLightTheme('night'); // reset only layers
}, },
[] []
@ -289,11 +306,26 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
setDarkLightTheme(newDarkLightTheme); setDarkLightTheme(newDarkLightTheme);
} }
const showLayerSelectionSwitch = useCallback(
(e) => {
flipShowLayerSelection(e)
},
[showLayerSelection],
)
const showLayerSelectionSwitchOnClick = (e) => {
flipShowLayerSelection(e)
}
function flipShowLayerSelection(e) {
e.preventDefault();
const newShowLayerSelection = (showLayerSelection === 'enabled')? 'disabled' : 'enabled';
setShowLayerSelection(newShowLayerSelection);
}
return ( return (
<DisplayPreferencesContext.Provider value={{ <DisplayPreferencesContext.Provider value={{
resetLayers, showOverlayList,
anyLayerModifiedState, resetLayersAndHideTheirList,
vista, vista,
vistaSwitch, vistaSwitch,
@ -324,7 +356,11 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
darkLightTheme, darkLightTheme,
darkLightThemeSwitch, darkLightThemeSwitch,
darkLightThemeSwitchOnClick darkLightThemeSwitchOnClick,
showLayerSelection,
showLayerSelectionSwitch,
showLayerSelectionSwitchOnClick
}}> }}>
{children} {children}
</DisplayPreferencesContext.Provider> </DisplayPreferencesContext.Provider>

View File

@ -4,17 +4,23 @@ import './map-button.css';
import { useDisplayPreferences } from '../displayPreferences-context'; import { useDisplayPreferences } from '../displayPreferences-context';
interface DataLayerSwitcherProps { interface DataLayerSwitcherProps {
currentDisplay: string;
onSubmit: (e: React.FormEvent<HTMLFormElement>) => void;
} }
const DataLayerSwitcher: React.FC<DataLayerSwitcherProps> = (props) => { const DataLayerSwitcher: React.FC<DataLayerSwitcherProps> = (props) => {
const { darkLightTheme } = useDisplayPreferences(); const { showLayerSelection, showOverlayList, resetLayersAndHideTheirList, darkLightTheme } = useDisplayPreferences();
const handleSubmit = (evt) => {
evt.preventDefault();
if (showLayerSelection === 'enabled') {
resetLayersAndHideTheirList(evt)
} else {
showOverlayList(evt)
}
}
return ( return (
<form className={`data-switcher map-button ${darkLightTheme}`} onSubmit={props.onSubmit}> <form className={`data-switcher map-button ${darkLightTheme}`} onSubmit={handleSubmit}>
<button className="btn btn-outline btn-outline-dark" <button className="btn btn-outline btn-outline-dark"
type="submit"> type="submit">
{(props.currentDisplay === 'enabled')? 'Hide layer options' : 'Show layer options'} {(showLayerSelection === 'enabled')? 'Clear layer options' : 'Show layer options'}
</button> </button>
</form> </form>
); );

View File

@ -17,6 +17,10 @@
.map-button .btn { .map-button .btn {
margin: 0; margin: 0;
min-width: 310px; min-width: 310px;
color: #191b1d;
}
.map-button .btn:hover {
color: #fff;
} }
.map-button.night .btn { .map-button.night .btn {
color: #fff; color: #fff;
@ -24,7 +28,7 @@
border-color: #343a40; border-color: #343a40;
} }
.map-button.night .btn:hover { .map-button.night .btn:hover {
color: #343a40; color: #d4d7da;
background-color: transparent; background-color: transparent;
background-image: none; background-image: none;
border-color: #343a40; border-color: #343a40;
@ -46,11 +50,11 @@
background-image: none; background-image: none;
} }
.map-button.enabled-state { .map-button.enabled-state {
color: #61ef61; color: #75e775;
background-color: #61ef61; background-color: #75e775;
} }
.map-button.enabled-state .btn{ .map-button.enabled-state .btn{
background-color: #61ef61; background-color: #75e775;
} }
.map-button.night.enabled-state { .map-button.night.enabled-state {
color: #448844; color: #448844;
@ -73,14 +77,6 @@
} }
} }
.reset-switcher {
top: 37px;
margin-right: 60px;
}
.reset-switcher .btn {
min-width: 280px;
}
.theme-switcher { .theme-switcher {
top: 77px; top: 77px;
} }

View File

@ -29,7 +29,6 @@ import { Legend } from './legend';
import SearchBox from './search-box'; import SearchBox from './search-box';
import ThemeSwitcher from './theme-switcher'; import ThemeSwitcher from './theme-switcher';
import DataLayerSwitcher from './data-switcher'; import DataLayerSwitcher from './data-switcher';
import { ResetSwitcher } from './reset-switcher';
import { BoroughSwitcher } from './borough-switcher'; import { BoroughSwitcher } from './borough-switcher';
import { ParcelSwitcher } from './parcel-switcher'; import { ParcelSwitcher } from './parcel-switcher';
import { FloodSwitcher } from './flood-switcher'; import { FloodSwitcher } from './flood-switcher';
@ -62,8 +61,7 @@ export const ColouringMap : FC<ColouringMapProps> = ({
categoryMapDefinitions, categoryMapDefinitions,
children children
}) => { }) => {
const { darkLightTheme, darkLightThemeSwitch } = useDisplayPreferences(); const { darkLightTheme, darkLightThemeSwitch, showLayerSelection } = useDisplayPreferences();
const [dataLayers, setDataLayers] = useState<LayerEnablementState>('disabled');
const [position, setPosition] = useState(initialMapViewport.position); const [position, setPosition] = useState(initialMapViewport.position);
const [zoom, setZoom] = useState(initialMapViewport.zoom); const [zoom, setZoom] = useState(initialMapViewport.zoom);
@ -86,15 +84,6 @@ export const ColouringMap : FC<ColouringMapProps> = ({
[onBuildingAction], [onBuildingAction],
) )
const layerSwitch = useCallback(
(e) => {
e.preventDefault();
const newDisplayState = (dataLayers === 'enabled')? 'disabled' : 'enabled';
setDataLayers(newDisplayState);
},
[dataLayers],
)
return ( return (
<div className="map-container"> <div className="map-container">
<MapContainer <MapContainer
@ -169,11 +158,10 @@ export const ColouringMap : FC<ColouringMapProps> = ({
mode !== 'basic' && mode !== 'basic' &&
<> <>
<Legend mapColourScaleDefinitions={categoryMapDefinitions} mapColourScale={mapColourScale} onMapColourScale={onMapColourScale}/> <Legend mapColourScaleDefinitions={categoryMapDefinitions} mapColourScale={mapColourScale} onMapColourScale={onMapColourScale}/>
<ResetSwitcher/>
<ThemeSwitcher onSubmit={darkLightThemeSwitch} currentTheme={darkLightTheme} /> <ThemeSwitcher onSubmit={darkLightThemeSwitch} currentTheme={darkLightTheme} />
<DataLayerSwitcher onSubmit={layerSwitch} currentDisplay={dataLayers} /> <DataLayerSwitcher />
{ {
(dataLayers == "enabled") ? (showLayerSelection == "enabled") ?
<> <>
<BoroughSwitcher/> <BoroughSwitcher/>
<ParcelSwitcher/> <ParcelSwitcher/>

View File

@ -1,20 +0,0 @@
import React from 'react';
import './map-button.css';
import { useDisplayPreferences } from '../displayPreferences-context';
export const ResetSwitcher: React.FC<{}> = () => {
const { resetLayers, darkLightTheme, anyLayerModifiedState } = useDisplayPreferences();
if(anyLayerModifiedState()) {
return (
<form className={`reset-switcher map-button ${darkLightTheme}`} onSubmit={resetLayers}>
<button className="btn btn-outline btn-outline-dark"
type="submit">
{"Reset layers"}
</button>
</form>
);
} else {
return <></>
}
}