Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: refacto signals settings on maps, removing signal's list concept #5472

Merged
merged 1 commit into from
Oct 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -354,8 +353,6 @@ export const BasePointEditionLayers: FC<{
{
prefix: '',
colors: colors[mapStyle],
signalsList: [type],
symbolsList: SIGNALS_TO_SYMBOLS[type] || [],
isEmphasized: true,
showIGNBDORTHO: false,
layersSettings,
Expand Down
4 changes: 2 additions & 2 deletions front/src/common/Map/Layers/BufferStops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SymbolLayer> {
const res: OmitLayer<SymbolLayer> = {
Expand Down Expand Up @@ -40,7 +40,7 @@ interface BufferStopsProps {

const BufferStops: FC<BufferStopsProps> = ({ layerOrder }) => {
const infraID = useSelector(getInfraID);
const { layersSettings } = useSelector((state: RootState) => state.map);
const layersSettings = useSelector(getLayersSettings);

return layersSettings.bufferstops ? (
<Source
Expand Down
4 changes: 2 additions & 2 deletions front/src/common/Map/Layers/Detectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { FC } from 'react';
import { useSelector } from 'react-redux';
import { Source, CircleLayer, SymbolLayer } from 'react-map-gl/maplibre';

import { RootState } from 'reducers';
import { Theme, OmitLayer } from 'types';
import { MAP_URL } from 'common/Map/const';

import OrderedLayer from 'common/Map/Layers/OrderedLayer';
import { getInfraID } from 'reducers/osrdconf/selectors';
import { getLayersSettings } from 'reducers/map/selectors';

export function getDetectorsLayerProps(params: {
colors: Theme;
Expand Down Expand Up @@ -61,7 +61,7 @@ interface DetectorsProps {

const Detectors: FC<DetectorsProps> = ({ 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' });
Expand Down
32 changes: 10 additions & 22 deletions front/src/common/Map/Layers/GeoJSONs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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` },
Expand All @@ -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 [
Expand Down Expand Up @@ -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,
Expand Down
68 changes: 12 additions & 56 deletions front/src/common/Map/Layers/Signals.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -33,47 +26,28 @@ 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<string> = [];
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 ? (
<Source
promoteId="id"
type="vector"
url={`${MAP_URL}/layer/${sourceTable}/mvt/geo/?infra=${infraID}`}
>
<OrderedLayer
{...getSignalMatLayerProps(context)}
id="chartis/signal/mat"
id="chartis/signal/mast"
layerOrder={layerOrder}
/>
<OrderedLayer
Expand All @@ -91,33 +65,15 @@ function Signals(props: PlatformProps) {
sourceLayer: sourceTable,
})}
id="chartis/signal/kp"
filter={['in', 'extensions_sncf_installation_type', ...signalsList]}
layerOrder={layerOrder}
/>

{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 (
<OrderedLayer
key={sig}
{...signalDef}
id={layerId}
paint={{
...signalDef.paint,
'icon-opacity': isHovered
? ['case', ['==', ['get', 'OP_id'], hovered.id], opacity * 0.6, opacity]
: opacity,
}}
layerOrder={layerOrder}
/>
);
})}
<OrderedLayer
{...getSignalLayerProps(context)}
id="chartis/signal/signals"
layerOrder={layerOrder}
/>
</Source>
);
) : null;
}

export default Signals;
37 changes: 6 additions & 31 deletions front/src/common/Map/Layers/geoSignalsLayers.ts
Original file line number Diff line number Diff line change
@@ -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<CircleLayer> {
export function getPointLayerProps({ sourceTable, colors }: SignalContext): OmitLayer<CircleLayer> {
const props: OmitLayer<CircleLayer> = {
type: 'circle',
minzoom: 9,
filter: ['in', 'extensions_sncf_installation_type', ...signalsList],
paint: {
'circle-color': colors.signal.point,
'circle-radius': 3,
Expand All @@ -40,14 +26,10 @@ export function getPointLayerProps({
return props;
}

export function getSignalMatLayerProps({
signalsList,
sourceTable,
}: SignalContext): OmitLayer<SymbolLayer> {
export function getSignalMatLayerProps({ sourceTable }: SignalContext): OmitLayer<SymbolLayer> {
const props: OmitLayer<SymbolLayer> = {
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}',
Expand Down Expand Up @@ -77,17 +59,10 @@ export function getSignalMatLayerProps({
return props;
}

export function getSignalLayerProps(context: SignalContext, type: string): OmitLayer<SymbolLayer> {
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<SymbolLayer> {
const { sourceTable, colors } = context;
const offsetY = -105;
const iconOffsetX = 45;

const iconOffset: Required<SymbolLayer>['layout']['icon-offset'] = [
'case',
Expand Down
1 change: 0 additions & 1 deletion front/src/common/Map/Layers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { SignalContext } from './geoSignalsLayers';

export interface LayerContext extends SignalContext {
sourceTable?: string;
symbolsList: string[];
isEmphasized: boolean;
showIGNBDORTHO: boolean;
layersSettings: MapState['layersSettings'];
Expand Down
Loading
Loading