diff --git a/front/src/applications/editor/tools/pointEdition/components.tsx b/front/src/applications/editor/tools/pointEdition/components.tsx index c83d0ba5b81..83ca974ec93 100644 --- a/front/src/applications/editor/tools/pointEdition/components.tsx +++ b/front/src/applications/editor/tools/pointEdition/components.tsx @@ -20,7 +20,6 @@ import { TrackSectionEntity, RouteEntity, } from 'types'; -import { SIGNALS_TO_SYMBOLS } from 'common/Map/Consts/SignalsNames'; import { osrdEditoastApi } from 'common/api/osrdEditoastApi'; import { PointEditionState } from './types'; import EditorForm from '../../components/EditorForm'; @@ -354,8 +353,6 @@ export const BasePointEditionLayers: FC<{ { prefix: '', colors: colors[mapStyle], - signalsList: [type], - symbolsList: SIGNALS_TO_SYMBOLS[type] || [], isEmphasized: true, showIGNBDORTHO: false, layersSettings, diff --git a/front/src/common/Map/Layers/BufferStops.tsx b/front/src/common/Map/Layers/BufferStops.tsx index 95fa7221fa4..e36f584e458 100644 --- a/front/src/common/Map/Layers/BufferStops.tsx +++ b/front/src/common/Map/Layers/BufferStops.tsx @@ -2,10 +2,10 @@ import React, { FC } from 'react'; import { useSelector } from 'react-redux'; import { Source, SymbolLayer } from 'react-map-gl/maplibre'; import { getInfraID } from 'reducers/osrdconf/selectors'; -import { RootState } from 'reducers'; import { Theme, OmitLayer } from 'types'; import { MAP_URL } from 'common/Map/const'; import OrderedLayer from 'common/Map/Layers/OrderedLayer'; +import { getLayersSettings } from 'reducers/map/selectors'; export function getBufferStopsLayerProps(params: { sourceTable?: string }): OmitLayer { const res: OmitLayer = { @@ -40,7 +40,7 @@ interface BufferStopsProps { const BufferStops: FC = ({ layerOrder }) => { const infraID = useSelector(getInfraID); - const { layersSettings } = useSelector((state: RootState) => state.map); + const layersSettings = useSelector(getLayersSettings); return layersSettings.bufferstops ? ( = ({ colors, layerOrder }) => { const infraID = useSelector(getInfraID); - const { layersSettings } = useSelector((state: RootState) => state.map); + const layersSettings = useSelector(getLayersSettings); const layerPoint = getDetectorsLayerProps({ colors, sourceTable: 'detectors' }); const layerName = getDetectorsNameLayerProps({ colors, sourceTable: 'detectors' }); diff --git a/front/src/common/Map/Layers/GeoJSONs.tsx b/front/src/common/Map/Layers/GeoJSONs.tsx index fa72aadc694..8e825b9a17d 100644 --- a/front/src/common/Map/Layers/GeoJSONs.tsx +++ b/front/src/common/Map/Layers/GeoJSONs.tsx @@ -26,7 +26,6 @@ import { getPointTextErrorsLayerProps, } from './Errors'; import { LayerType } from '../../../applications/editor/tools/types'; -import { ALL_SIGNAL_LAYERS, SYMBOLS_TO_LAYERS } from '../Consts/SignalsNames'; import { MAP_TRACK_SOURCE, MAP_URL } from '../const'; import { getSpeedSectionsFilter, @@ -47,8 +46,6 @@ import { getCatenariesProps, getCatenariesTextParams } from './Catenaries'; import configKPLabelLayer from './configKPLabelLayer'; import OrderedLayer from './OrderedLayer'; -const SIGNAL_TYPE_KEY = 'extensions_sncf_installation_type'; - const POINT_ENTITIES_MIN_ZOOM = 12; /** @@ -144,6 +141,9 @@ function getTrackSectionLayers(context: LayerContext, prefix: string): LayerProp } function getSignalLayers(context: LayerContext, prefix: string): LayerProps[] { + const signalProps = getSignalLayerProps(context); + const { paint } = signalProps; + const opacity = paint && typeof paint['icon-opacity'] === 'number' ? paint['icon-opacity'] : 1; return [ { ...getSignalMatLayerProps(context), id: `${prefix}geo/signal-mat` }, { ...getPointLayerProps(context), id: `${prefix}geo/signal-point` }, @@ -157,23 +157,13 @@ function getSignalLayers(context: LayerContext, prefix: string): LayerProps[] { sourceLayer: context.sourceTable || '', }), id: `${prefix}geo/signal-kp`, - filter: ['in', 'extensions_sncf_installation_type', ...context.symbolsList], - } as LayerProps, - ].concat( - context.symbolsList.map((symbol) => { - const props = getSignalLayerProps(context, symbol); - const { paint } = props; - const opacity = - paint && typeof paint['icon-opacity'] === 'number' ? paint['icon-opacity'] : 1; - - return { - ...props, - paint: { ...props.paint, 'icon-opacity': opacity * (context.isEmphasized ? 1 : 0.2) }, - filter: ['==', SIGNAL_TYPE_KEY, SYMBOLS_TO_LAYERS[symbol]], - id: `${prefix}geo/signal-${symbol}`, - }; - }) - ); + }, + { + ...signalProps, + paint: { ...signalProps.paint, 'icon-opacity': opacity * (context.isEmphasized ? 1 : 0.2) }, + id: `${prefix}geo/signal`, + }, + ]; } function getBufferStopsLayers(context: LayerContext, prefix: string): LayerProps[] { return [ @@ -402,8 +392,6 @@ const GeoJSONs: FC<{ const layerContext: LayerContext = useMemo( () => ({ colors, - signalsList: ALL_SIGNAL_LAYERS, - symbolsList: ALL_SIGNAL_LAYERS, prefix: mapStyle === 'blueprint' ? 'SCHB ' : '', isEmphasized, showIGNBDORTHO, diff --git a/front/src/common/Map/Layers/Signals.tsx b/front/src/common/Map/Layers/Signals.tsx index e45ac22a49b..caf4ed0a43f 100644 --- a/front/src/common/Map/Layers/Signals.tsx +++ b/front/src/common/Map/Layers/Signals.tsx @@ -1,21 +1,14 @@ import React from 'react'; import { useSelector } from 'react-redux'; import { Source, MapRef } from 'react-map-gl/maplibre'; -import { get } from 'lodash'; -import { RootState } from 'reducers'; import { Theme } from 'types'; import { MAP_URL } from 'common/Map/const'; -import { - ALL_SIGNAL_LAYERS, - LIGHT_SIGNALS, - SIGNS_STOPS, - SIGNS_TIVS, -} from 'common/Map/Consts/SignalsNames'; import OrderedLayer from 'common/Map/Layers/OrderedLayer'; import { getInfraID } from 'reducers/osrdconf/selectors'; +import { getLayersSettings, getMapStyle } from 'reducers/map/selectors'; import { getPointLayerProps, getSignalLayerProps, @@ -33,39 +26,20 @@ interface PlatformProps { } function Signals(props: PlatformProps) { - const { mapStyle, signalsSettings } = useSelector((state: RootState) => state.map); + const mapStyle = useSelector(getMapStyle); + const layersSettings = useSelector(getLayersSettings); const infraID = useSelector(getInfraID); - const { colors, sourceTable, hovered, layerOrder } = props; + const { colors, sourceTable, layerOrder } = props; const prefix = mapStyle === 'blueprint' ? 'SCHB ' : ''; - const getSignalsList = () => { - let signalsList: Array = []; - if (signalsSettings.all) { - return ALL_SIGNAL_LAYERS; - } - if (signalsSettings.stops) { - signalsList = signalsList.concat(SIGNS_STOPS); - } - if (signalsSettings.tivs) { - signalsList = signalsList.concat(SIGNS_TIVS); - } - if (signalsSettings.lights) { - signalsList = signalsList.concat(LIGHT_SIGNALS); - } - return signalsList; - }; - - const signalsList = getSignalsList(); - const context: SignalContext = { prefix, colors, - signalsList, sourceTable, }; - return ( + return layersSettings.signals ? ( - - {signalsList.map((sig) => { - const layerId = `chartis/signal/geo/${sig}`; - const isHovered = hovered && hovered.layer === layerId; - const signalDef = getSignalLayerProps(context, sig); - const opacity = get(signalDef.paint, 'icon-opacity', 1) as number; - - return ( - - ); - })} + - ); + ) : null; } export default Signals; diff --git a/front/src/common/Map/Layers/geoSignalsLayers.ts b/front/src/common/Map/Layers/geoSignalsLayers.ts index ae0ece17f3f..62a59394026 100644 --- a/front/src/common/Map/Layers/geoSignalsLayers.ts +++ b/front/src/common/Map/Layers/geoSignalsLayers.ts @@ -1,34 +1,20 @@ import { CircleLayer, SymbolLayer } from 'react-map-gl/maplibre'; -import { SIGNALS_SIGNS } from 'common/Map/const'; import { Theme, OmitLayer } from '../../../types'; const signalTextOffsetX = 5; const signalTextOffsetY = -1; const signalCenteredTextOffset = [0, 6]; -export interface SignalsSettings { - all?: boolean; - stops?: boolean; - tivs?: boolean; - lights?: boolean; -} - export interface SignalContext { prefix: string; sourceTable?: string; colors: Theme; - signalsList: string[]; } -export function getPointLayerProps({ - signalsList, - sourceTable, - colors, -}: SignalContext): OmitLayer { +export function getPointLayerProps({ sourceTable, colors }: SignalContext): OmitLayer { const props: OmitLayer = { type: 'circle', minzoom: 9, - filter: ['in', 'extensions_sncf_installation_type', ...signalsList], paint: { 'circle-color': colors.signal.point, 'circle-radius': 3, @@ -40,14 +26,10 @@ export function getPointLayerProps({ return props; } -export function getSignalMatLayerProps({ - signalsList, - sourceTable, -}: SignalContext): OmitLayer { +export function getSignalMatLayerProps({ sourceTable }: SignalContext): OmitLayer { const props: OmitLayer = { type: 'symbol', minzoom: 12, - filter: ['in', 'extensions_sncf_installation_type', ...signalsList], paint: {}, layout: { 'text-field': '', // '{extensions_sncf_installation_type} / {extensions_sncf_value} / {extensions_sncf_label}', @@ -77,17 +59,10 @@ export function getSignalMatLayerProps({ return props; } -export function getSignalLayerProps(context: SignalContext, type: string): OmitLayer { - const { sourceTable, prefix, colors } = context; - let offsetY = -105; - let iconOffsetX = 45; - if (SIGNALS_SIGNS.indexOf(type) !== -1 && SIGNALS_SIGNS.indexOf(type) === -1) { - iconOffsetX = 55; - offsetY = -60; - } else if (prefix !== '') { - iconOffsetX = 30; - offsetY = -80; - } +export function getSignalLayerProps(context: SignalContext): OmitLayer { + const { sourceTable, colors } = context; + const offsetY = -105; + const iconOffsetX = 45; const iconOffset: Required['layout']['icon-offset'] = [ 'case', diff --git a/front/src/common/Map/Layers/types.ts b/front/src/common/Map/Layers/types.ts index 8be0f02ec02..8a18bb88870 100644 --- a/front/src/common/Map/Layers/types.ts +++ b/front/src/common/Map/Layers/types.ts @@ -3,7 +3,6 @@ import { SignalContext } from './geoSignalsLayers'; export interface LayerContext extends SignalContext { sourceTable?: string; - symbolsList: string[]; isEmphasized: boolean; showIGNBDORTHO: boolean; layersSettings: MapState['layersSettings']; diff --git a/front/src/common/Map/Settings/MapSettingsLayers.tsx b/front/src/common/Map/Settings/MapSettingsLayers.tsx index dfb4f14c4ad..df771831533 100644 --- a/front/src/common/Map/Settings/MapSettingsLayers.tsx +++ b/front/src/common/Map/Settings/MapSettingsLayers.tsx @@ -4,8 +4,7 @@ import { useTranslation } from 'react-i18next'; import { updateLayersSettings } from 'reducers/map'; import { GiElectric, GiUnplugged } from 'react-icons/gi'; -import MapSettingsSignals from 'common/Map/Settings/MapSettingsSignals'; - +import SignalsSVGFile from 'assets/pictures/layersicons/layer_signal.svg'; import BufferStopSVGFile from 'assets/pictures/layersicons/bufferstop.svg'; import OPsSVGFile from 'assets/pictures/layersicons/ops.svg'; import SwitchesSVGFile from 'assets/pictures/layersicons/switches.svg'; @@ -60,41 +59,41 @@ export const Icon2SVG: FC<{ file: string; altName?: string }> = ({ file, altName ); const MapSettingsLayers: FC = () => ( - <> - -
-
- } /> -
-
- } /> -
-
- } - /> -
-
- } - /> -
-
- } - /> -
-
- } - /> -
+
+
+ } /> +
+
+ } /> +
+
+ } /> +
+
+ } + /> +
+
+ } + /> +
+
+ } + /> +
+
+ } + />
- +
); export default MapSettingsLayers; diff --git a/front/src/common/Map/Settings/MapSettingsSignals.tsx b/front/src/common/Map/Settings/MapSettingsSignals.tsx deleted file mode 100644 index c1c45be459d..00000000000 --- a/front/src/common/Map/Settings/MapSettingsSignals.tsx +++ /dev/null @@ -1,94 +0,0 @@ -import React, { FC, useCallback } from 'react'; -import { useSelector, useDispatch } from 'react-redux'; -import { useTranslation } from 'react-i18next'; -import { fromPairs } from 'lodash'; - -import SwitchSNCF from 'common/BootstrapSNCF/SwitchSNCF/SwitchSNCF'; -import stopsIcon from 'assets/pictures/layersicons/layer_stops.svg'; -import lightsIcon from 'assets/pictures/layersicons/layer_signal.svg'; -import { updateSignalsSettings } from 'reducers/map'; -import { getMap } from 'reducers/map/selectors'; -import { RootState } from 'reducers'; - -type SettingsSignals = RootState['map']['signalsSettings']; -const SIGNAL_SETTINGS: Array = ['lights']; // 'all', 'stops' temporarely desactivated -const CONSTS_SVG: Partial> = { - stops: stopsIcon, - lights: lightsIcon, -}; - -function switchAllSettings( - settingSwitch: keyof SettingsSignals, - stateOfSettings: SettingsSignals -): SettingsSignals { - return fromPairs( - SIGNAL_SETTINGS.map((s) => [s, !stateOfSettings[settingSwitch]]) - ) as SettingsSignals; -} - -function checkAllSettingsAreTheSame( - settingSwitch: keyof SettingsSignals, - stateOfSettings: SettingsSignals -): boolean { - const filteredSettingKeys = Object.keys(stateOfSettings).filter( - (key) => key !== settingSwitch && key !== 'all' - ) as Array; - const settingValues = filteredSettingKeys.map((settingKey) => stateOfSettings[settingKey]); - return settingValues.every((settingValue) => settingValue === !stateOfSettings[settingSwitch]); -} - -const MapSettingsSignals: FC = () => { - const { signalsSettings } = useSelector(getMap); - const dispatch = useDispatch(); - const { t } = useTranslation(['map-settings']); - - const setSignalsList = useCallback( - (setting: keyof SettingsSignals) => { - let newSettings; - - if (setting === 'all' || checkAllSettingsAreTheSame(setting, signalsSettings)) { - newSettings = switchAllSettings(setting, signalsSettings); - } else { - newSettings = { - ...signalsSettings, - [setting]: !signalsSettings[setting], - }; - } - dispatch(updateSignalsSettings(newSettings)); - }, - [dispatch, signalsSettings] - ); - - return ( -
- {SIGNAL_SETTINGS.map((setting) => ( -
-
- setSignalsList(setting)} - name={`map-settings-${setting}`} - id={`map-settings-${setting}`} - checked={signalsSettings[setting]} - /> - {setting === 'all' ? ( - {t('all')} - ) : ( - <> - {`${setting} - {t(setting)} - - )} -
-
- ))} -
- ); -}; - -export default MapSettingsSignals; diff --git a/front/src/reducers/index.ts b/front/src/reducers/index.ts index 08d3cc4a111..3c763517c51 100644 --- a/front/src/reducers/index.ts +++ b/front/src/reducers/index.ts @@ -37,7 +37,6 @@ const mapWhiteList = [ 'layers', 'layersSettings', 'userPreference', - 'signalsSettings', 'terrain3DExaggeration', ]; diff --git a/front/src/reducers/map/index.ts b/front/src/reducers/map/index.ts index 3946db47507..de90b7ebc9d 100644 --- a/front/src/reducers/map/index.ts +++ b/front/src/reducers/map/index.ts @@ -30,12 +30,6 @@ export interface MapState { terrain3DExaggeration: number; viewport: Viewport; featureInfoClickID?: number; - signalsSettings: { - all: boolean; - stops: boolean; - lights: boolean; - tivs: boolean; - }; layersSettings: { bufferstops: boolean; catenaries: boolean; @@ -43,6 +37,7 @@ export interface MapState { detectors: boolean; operationalpoints: boolean; routes: boolean; + signals: boolean; signalingtype: boolean; sncf_psl: boolean; speedlimittag: string; @@ -76,12 +71,6 @@ export const mapInitialState: MapState = { transformRequest: transformMapRequest, }, featureInfoClickID: undefined, - signalsSettings: { - all: false, - stops: true, - lights: false, - tivs: false, - }, layersSettings: { bufferstops: false, catenaries: false, @@ -89,6 +78,7 @@ export const mapInitialState: MapState = { detectors: false, operationalpoints: false, routes: false, + signals: false, signalingtype: true, sncf_psl: false, speedlimittag: '', @@ -144,9 +134,6 @@ const mapSlice = createSlice({ updateLayersSettings: (state, action: PayloadAction) => { state.layersSettings = action.payload; }, - updateSignalsSettings: (state, action: PayloadAction) => { - state.signalsSettings = action.payload; - }, updateTerrain3DExaggeration: ( state, action: PayloadAction @@ -191,7 +178,6 @@ export const { updateShowIGNSCAN25, updateShowOSM, updateShowOSMtracksections, - updateSignalsSettings, updateTerrain3DExaggeration, updateTransformRequest, updateViewportAction, diff --git a/front/src/reducers/map/mapReducer.spec.ts b/front/src/reducers/map/mapReducer.spec.ts index bae0c275e87..3d0c25b754c 100644 --- a/front/src/reducers/map/mapReducer.spec.ts +++ b/front/src/reducers/map/mapReducer.spec.ts @@ -14,7 +14,6 @@ import { updateShowOSMtracksections, updateFeatureInfoClick, updateLayersSettings, - updateSignalsSettings, updateTerrain3DExaggeration, updateTransformRequest, } from 'reducers/map'; @@ -135,6 +134,7 @@ describe('mapReducer', () => { detectors: true, operationalpoints: true, routes: true, + signals: false, signalingtype: true, sncf_psl: true, speedlimittag: '60', @@ -148,19 +148,6 @@ describe('mapReducer', () => { expect(mapState).toEqual({ ...mapState, layersSettings }); }); - it('should handle updateSignalsSettings', () => { - const store = createStore(); - const signalsSettings = { - all: true, - stops: true, - lights: true, - tivs: true, - }; - store.dispatch(updateSignalsSettings(signalsSettings)); - const mapState = store.getState().map; - expect(mapState).toEqual({ ...mapState, signalsSettings }); - }); - it('should handle updateTerrain3DExaggeration', () => { const store = createStore(); store.dispatch(updateTerrain3DExaggeration(10)); diff --git a/front/src/reducers/map/selectors.ts b/front/src/reducers/map/selectors.ts index d72090e8320..2f2ced99ba6 100644 --- a/front/src/reducers/map/selectors.ts +++ b/front/src/reducers/map/selectors.ts @@ -15,6 +15,5 @@ export const getShowOSM = makeMapStateSelector('showOSM'); export const getShowOSMtracksections = makeMapStateSelector('showOSMtracksections'); export const getTerrain3DExaggeration = makeMapStateSelector('terrain3DExaggeration'); export const getViewport = makeMapStateSelector('viewport'); -export const getSignalsSettings = makeMapStateSelector('signalsSettings'); export const getLayersSettings = makeMapStateSelector('layersSettings'); export const getMapSearchMarker = makeMapStateSelector('mapSearchMarker');