Skip to content

Commit

Permalink
Merge pull request #1412 from matkoniecz/feature/editable-building-sw…
Browse files Browse the repository at this point in the history
…itcher

Allow to hide editable buildings.
  • Loading branch information
matkoniecz authored Oct 7, 2024
2 parents e7a5ec9 + f2eeee3 commit 1803d2b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
34 changes: 34 additions & 0 deletions app/src/frontend/displayPreferences-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ interface DisplayPreferencesContextState {
historicMapSwitch: (e: React.FormEvent<HTMLFormElement>) => void;
historicMapSwitchOnClick: React.MouseEventHandler<HTMLButtonElement>;

editableBuildings: LayerEnablementState;
editableBuildingsSwitch: (e: React.FormEvent<HTMLFormElement>) => void;
editableBuildingsSwitchOnClick: React.MouseEventHandler<HTMLButtonElement>;

darkLightTheme: MapTheme;
darkLightThemeSwitch: (e: React.FormEvent<HTMLFormElement>) => void;
darkLightThemeSwitchOnClick: React.MouseEventHandler<HTMLButtonElement>;
Expand Down Expand Up @@ -95,6 +99,10 @@ export const DisplayPreferencesContext = createContext<DisplayPreferencesContext
historicMapSwitch: stub,
historicMapSwitchOnClick: undefined,

editableBuildings: undefined,
editableBuildingsSwitch: stub,
editableBuildingsSwitchOnClick: undefined,

darkLightTheme: undefined,
darkLightThemeSwitch: stub,
darkLightThemeSwitchOnClick: undefined,
Expand All @@ -116,6 +124,7 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
const defaultConservation = 'disabled'
const defaultHistoricData = 'disabled'
const defaultHistoricMap = 'disabled'
const defaultEditableBuildings = 'enabled'
const defaultShowLayerSelection = 'disabled'
const [vista, setVista] = useState<LayerEnablementState>(defaultVista);
const [flood, setFlood] = useState<LayerEnablementState>(defaultFlood);
Expand All @@ -126,6 +135,7 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
const [conservation, setConservation] = useState<LayerEnablementState>(defaultConservation);
const [historicData, setHistoricData] = useState<LayerEnablementState>(defaultHistoricData);
const [historicMap, setHistoricMap] = useState<LayerEnablementState>(defaultHistoricMap);
const [editableBuildings, setEditableBuildings] = useState<LayerEnablementState>(defaultEditableBuildings);
const [darkLightTheme, setDarkLightTheme] = useState<MapTheme>('night');
const [showLayerSelection, setShowLayerSelection] = useState<LayerEnablementState>(defaultShowLayerSelection);

Expand All @@ -147,6 +157,7 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
setConservation(defaultConservation);
setHistoricData(defaultHistoricData);
setHistoricMap(defaultHistoricMap);
setEditableBuildings(defaultEditableBuildings)
setShowLayerSelection(defaultShowLayerSelection); // reset layers + hiding this panel is integrated into one action
//setDarkLightTheme('night'); // reset only layers
},
Expand Down Expand Up @@ -181,6 +192,10 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
if(historicMap != defaultHistoricMap) {
return true;
}
if(editableBuildings != defaultEditableBuildings) {
return true;
}
setEditableBuildings
//darkLightTheme not handled here
return false;
}
Expand Down Expand Up @@ -326,6 +341,21 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
setHistoricMap(newHistoric);
}

const editableBuildingsSwitch = useCallback(
(e) => {
flipEditableBuildings(e)
},
[editableBuildings],
)
const editableBuildingsSwitchOnClick = (e) => {
flipEditableBuildings(e)
}
function flipEditableBuildings(e) {
e.preventDefault();
const newValue = (editableBuildings === 'enabled')? 'disabled' : 'enabled';
setEditableBuildings(newValue);
}

const darkLightThemeSwitch = useCallback(
(e) => {
flipDarkLightTheme(e)
Expand Down Expand Up @@ -393,6 +423,10 @@ export const DisplayPreferencesProvider: React.FC<{}> = ({children}) => {
historicMapSwitch,
historicMapSwitchOnClick,

editableBuildings,
editableBuildingsSwitch,
editableBuildingsSwitchOnClick,

darkLightTheme,
darkLightThemeSwitch,
darkLightThemeSwitchOnClick,
Expand Down
16 changes: 16 additions & 0 deletions app/src/frontend/map/editable-buildings-switcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';

import './map-button.css';
import { useDisplayPreferences } from '../displayPreferences-context';

export const EditableBuildingsSwitcher: React.FC<{}> = () => {
const { editableBuildings, editableBuildingsSwitch, darkLightTheme } = useDisplayPreferences();
return (
<form className={`map-button ${editableBuildings}-state ${darkLightTheme}`} onSubmit={editableBuildingsSwitch}>
<button className="btn btn-outline btn-outline-dark"
type="submit">
{(editableBuildings === 'enabled')? 'Editable Buildings on' : 'Editable Buildings off'}
</button>
</form>
);
}
9 changes: 7 additions & 2 deletions app/src/frontend/map/layers/building-base-layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import { TileLayer } from 'react-leaflet';

import { MapTheme } from '../../config/map-config';
import { MapTileset } from '../../config/tileserver-config';

import { useDisplayPreferences } from '../../displayPreferences-context';
import {getTileLayerUrl } from './get-tile-layer-url';

export function BuildingBaseLayer({ theme }: {theme: MapTheme}) {
const tileset = `base_${theme}` as const;
const { editableBuildings } = useDisplayPreferences();

return <TileLayer
if(editableBuildings == "enabled") {
return <TileLayer
key={theme} /* needed because TileLayer url is not mutable in react-leaflet v3 */
url={getTileLayerUrl(tileset)}
minZoom={14}
maxZoom={19}
detectRetina={false}
/>;
} else {
return <div></div>
}
}
10 changes: 8 additions & 2 deletions app/src/frontend/map/layers/building-data-layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import * as React from 'react';
import { TileLayer } from 'react-leaflet';

import { BuildingMapTileset } from '../../config/tileserver-config';

import { useDisplayPreferences } from '../../displayPreferences-context';
import {getTileLayerUrl } from './get-tile-layer-url';

export function BuildingDataLayer({tileset, revisionId} : { tileset: BuildingMapTileset, revisionId: string }) {
return <TileLayer
const { editableBuildings } = useDisplayPreferences();

if(editableBuildings == "enabled") {
return <TileLayer
key={`${tileset}-${revisionId}`} /* needed because TileLayer url is not mutable in react-leaflet v3 */
url={getTileLayerUrl(tileset, {rev: revisionId})}
minZoom={9}
maxZoom={19}
detectRetina={false}
/>;
} else {
return <div></div>
}
}
2 changes: 2 additions & 0 deletions app/src/frontend/map/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { HistoricMapSwitcher } from './historic-map-switcher';
import { VistaSwitcher } from './vista-switcher';
import { CreativeSwitcher } from './creative-switcher';
import { HousingSwitcher } from './housing-switcher';
import { EditableBuildingsSwitcher } from './editable-buildings-switcher';
import { BuildingMapTileset } from '../config/tileserver-config';
import { useDisplayPreferences } from '../displayPreferences-context';
import { CategoryMapDefinition } from '../config/category-maps-config';
Expand Down Expand Up @@ -176,6 +177,7 @@ export const ColouringMap : FC<ColouringMapProps> = ({
<VistaSwitcher />
<HousingSwitcher />
<CreativeSwitcher />
<EditableBuildingsSwitcher />
</>
: <></>
}
Expand Down

0 comments on commit 1803d2b

Please sign in to comment.