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: rewrite kp label layer #5876

Merged
merged 2 commits into from
Nov 28, 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 @@ -27,6 +27,8 @@ import {
import { ExtendedEditorContextType } from 'applications/editor/tools/editorContextTypes';
import EntitySumUp from 'applications/editor/components/EntitySumUp';

const emptyFeatureCollection = featureCollection([]);

export const SpeedSectionEditionLayers: FC = () => {
const dispatch = useDispatch();
const { t } = useTranslation();
Expand Down Expand Up @@ -85,7 +87,7 @@ export const SpeedSectionEditionLayers: FC = () => {
return featureCollection([...trackRangeFeatures, ...pslSignFeatures]);
}, [entity, trackSectionsCache]);

const layersProps = useMemo(() => {
const { speedSectionLayerProps, pslLayerProps } = useMemo(() => {
const context = {
prefix: mapStyle === 'blueprint' ? 'SCHB ' : '',
colors: colors[mapStyle],
Expand All @@ -96,16 +98,20 @@ export const SpeedSectionEditionLayers: FC = () => {
layersSettings,
issuesSettings,
};
if (!isPSL) {
return SourcesDefinitionsIndex.speed_sections(context, 'speedSectionsEditor/speedSection/');
}
const speedSectionLayers = SourcesDefinitionsIndex.speed_sections(
context,
'speedSectionsEditor/speedSection/'
);
const pslLayers = SourcesDefinitionsIndex.psl(context, 'speedSectionsEditor/psl/');
const pslSignLayers = SourcesDefinitionsIndex.psl_signs(
context,
'speedSectionsEditor/psl_signs/'
);
return [...pslLayers, ...pslSignLayers];
}, [isPSL, mapStyle, showIGNBDORTHO, layersSettings, issuesSettings]);
return {
speedSectionLayerProps: speedSectionLayers,
pslLayerProps: [...pslLayers, ...pslSignLayers],
};
}, [mapStyle, showIGNBDORTHO, layersSettings, issuesSettings]);

// Here is where we handle loading the TrackSections attached to the speed section:
useEffect(() => {
Expand Down Expand Up @@ -233,8 +239,27 @@ export const SpeedSectionEditionLayers: FC = () => {
issuesSettings={issuesSettings}
isEmphasized={false}
/>
<Source type="geojson" data={speedSectionsFeature} key={isPSL ? 'psl' : 'speed-section'}>
{layersProps.map((props, i) => (
<Source
type="geojson"
data={!isPSL ? speedSectionsFeature : emptyFeatureCollection}
key="speed-section"
>
{speedSectionLayerProps.map((props, i) => (
<Layer {...props} key={i} />
))}
<Layer
type="circle"
paint={{
'circle-radius': 4,
'circle-color': '#fff',
'circle-stroke-color': '#000000',
'circle-stroke-width': 2,
}}
filter={['has', 'extremity']}
/>
</Source>
<Source type="geojson" data={isPSL ? speedSectionsFeature : emptyFeatureCollection} key="psl">
{pslLayerProps.map((props, i) => (
<Layer {...props} key={i} />
))}
<Layer
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/referenceMap/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Routes from 'common/Map/Layers/Routes';
import SearchMarker from 'common/Map/Layers/SearchMarker';
import Signals from 'common/Map/Layers/Signals';
import SpeedLimits from 'common/Map/Layers/SpeedLimits';
import SNCF_PSL from 'common/Map/Layers/extensions/SNCF/SNCF_PSL';
import SNCF_PSL from 'common/Map/Layers/extensions/SNCF/PSL';
import Switches from 'common/Map/Layers/Switches';
import TracksGeographic from 'common/Map/Layers/TracksGeographic';
import TracksOSM from 'common/Map/Layers/TracksOSM';
Expand Down
16 changes: 7 additions & 9 deletions front/src/common/Map/Layers/GeoJSONs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ import {
getPSLSpeedLineBGLayerProps,
getPSLSpeedLineLayerProps,
getPSLSpeedValueLayerProps,
} from './extensions/SNCF/SNCF_PSL';
import { getPSLSignsLayerProps, getPSLSignsMastLayerProps } from './extensions/SNCF/SNCF_PSL_SIGNS';
} from './extensions/SNCF/PSL';
import { getPSLSignsLayerProps, getPSLSignsMastLayerProps } from './extensions/SNCF/PSLSigns';
import { LayerContext } from './types';
import { getCatenariesProps, getCatenariesTextParams } from './Catenaries';
import configKPLabelLayer from './configKPLabelLayer';
import getKPLabelLayerProps from './KPLabel';
import OrderedLayer from './OrderedLayer';
import { Platforms } from './Platforms';

Expand Down Expand Up @@ -213,13 +213,12 @@ function getSignalLayers(context: LayerContext, prefix: string): LayerProps[] {
{ ...getSignalMatLayerProps(context), id: `${prefix}geo/signal-mat` },
{ ...getPointLayerProps(context), id: `${prefix}geo/signal-point` },
{
...configKPLabelLayer({
...getKPLabelLayerProps({
...context,
bottomOffset: 6.5,
colors: context.colors,
fieldName: 'extensions_sncf_kp',
PKFieldName: 'extensions_sncf_kp',
minzoom: 12,
isSignalisation: true,
sourceLayer: context.sourceTable || '',
}),
id: `${prefix}geo/signal-kp`,
},
Expand Down Expand Up @@ -281,11 +280,10 @@ function getPSLSignsLayers(context: LayerContext, prefix: string): LayerProps[]
minzoom: POINT_ENTITIES_MIN_ZOOM,
},
{
...configKPLabelLayer({
...getKPLabelLayerProps({
colors: context.colors,
minzoom: 9.5,
isSignalisation: true,
sourceLayer: 'psl_signs',
}),
id: `${prefix}geo/psl-signs-kp`,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import { ExpressionFilterSpecification } from 'maplibre-gl';
import { LayerProps } from 'react-map-gl/maplibre';
import { LayerProps, SymbolLayer } from 'react-map-gl/maplibre';

import { Theme } from 'types';
import { OmitLayer, Theme } from 'types';

interface PlatformProps {
export default function getKPLabelLayerProps(params: {
sourceTable?: string;
isSignalisation?: boolean;
bottomOffset?: number;
PKFieldName?: string;
colors: Theme;
fieldName?: string;
maxzoom?: number;
minzoom?: number;
isSignalisation?: boolean;
sourceLayer: string;
}

export default function configKPLabelLayer(props: PlatformProps) {
}): OmitLayer<SymbolLayer> {
const {
bottomOffset = 2.5,
colors,
fieldName = 'kp',
PKFieldName = 'kp',
maxzoom = 24,
minzoom = 7,
isSignalisation,
sourceLayer,
} = props;
sourceTable,
} = params;

// Will have to be removed when backend will be updated with consistent fieldnames
const testSideExpression = (side: 'LEFT' | 'RIGHT' | 'CENTER') => [
Expand Down Expand Up @@ -57,14 +55,17 @@ export default function configKPLabelLayer(props: PlatformProps) {
'text-offset': ['literal', [-1, 0.1]],
};

const kpValue: LayerProps = {
const res: OmitLayer<SymbolLayer> = {
type: 'symbol',
'source-layer': sourceLayer,
filter: ['all', ['!=', ['literal', null], ['get', fieldName]], ['!=', '', ['get', fieldName]]],
filter: [
'all',
['!=', ['literal', null], ['get', PKFieldName]],
['!=', '', ['get', PKFieldName]],
],
maxzoom,
minzoom,
layout: {
'text-field': ['get', fieldName],
'text-field': ['get', PKFieldName],
'text-font': ['Roboto Medium'],
'text-size': 9,
'text-anchor': 'right',
Expand All @@ -81,5 +82,7 @@ export default function configKPLabelLayer(props: PlatformProps) {
},
};

return kpValue;
if (typeof sourceTable === 'string') res['source-layer'] = sourceTable;

return res;
}
7 changes: 3 additions & 4 deletions front/src/common/Map/Layers/OperationalPoints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Theme } from 'types';
import { MAP_URL } from 'common/Map/const';

import OrderedLayer from 'common/Map/Layers/OrderedLayer';
import configKPLabelLayer from 'common/Map/Layers/configKPLabelLayer';
import getKPLabelLayerProps from 'common/Map/Layers/KPLabel';
import { getInfraID } from 'reducers/osrdconf/selectors';

interface Props {
Expand Down Expand Up @@ -145,11 +145,10 @@ export default function OperationalPoints(props: Props) {
layerOrder={layerOrder}
/>
<OrderedLayer
{...configKPLabelLayer({
{...getKPLabelLayerProps({
colors,
fieldName: 'kp',
minzoom: 9.5,
sourceLayer: 'operational_points',
sourceTable: 'operational_points',
})}
id="chartis/osrd_operational_point_kp/geo"
layerOrder={layerOrder}
Expand Down
8 changes: 4 additions & 4 deletions front/src/common/Map/Layers/Signals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getSignalMatLayerProps,
SignalContext,
} from './geoSignalsLayers';
import configKPLabelLayer from './configKPLabelLayer';
import getKPLabelLayerProps from './KPLabel';

interface PlatformProps {
colors: Theme;
Expand Down Expand Up @@ -56,13 +56,13 @@ function Signals(props: PlatformProps) {
layerOrder={layerOrder}
/>
<OrderedLayer
{...configKPLabelLayer({
{...getKPLabelLayerProps({
bottomOffset: 6.5,
colors,
fieldName: 'extensions_sncf_kp',
PKFieldName: 'extensions_sncf_kp',
minzoom: 12,
isSignalisation: true,
sourceLayer: sourceTable,
sourceTable,
})}
id="chartis/signal/kp"
layerOrder={layerOrder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getInfraID } from 'reducers/osrdconf/selectors';
import { MapState } from 'reducers/map';
import { getSpeedSectionsTag, getSpeedSectionsName } from '../../SpeedLimits';
import { Theme, OmitLayer } from '../../../../../types';
import SNCF_PSL_Signs from './SNCF_PSL_SIGNS';
import SNCF_PSL_Signs from './PSLSigns';

interface SNCF_PSLProps {
colors: Theme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isNil } from 'lodash';
import { getMap } from 'reducers/map/selectors';
import OrderedLayer from '../../OrderedLayer';
import { LayerContext } from '../../types';
import configKPLabelLayer from '../../configKPLabelLayer';
import getKPLabelLayerProps from '../../KPLabel';

interface SNCF_PSL_SignsProps {
colors: Theme;
Expand Down Expand Up @@ -110,6 +110,13 @@ export default function SNCF_PSL_Signs(props: SNCF_PSL_SignsProps) {
sourceTable: 'psl_signs',
});

const KPLabelsParams: LayerProps = getKPLabelLayerProps({
colors,
minzoom: 9.5,
isSignalisation: true,
sourceTable: 'psl_signs',
});

return (
<Source
id="osrd_sncf_psl_signs_geo"
Expand All @@ -119,12 +126,7 @@ export default function SNCF_PSL_Signs(props: SNCF_PSL_SignsProps) {
<OrderedLayer {...mastsParams} layerOrder={layerOrder} />
<OrderedLayer {...signsParams} layerOrder={layerOrder} />
<OrderedLayer
{...configKPLabelLayer({
colors,
minzoom: 9.5,
isSignalisation: true,
sourceLayer: 'psl_signs',
})}
{...KPLabelsParams}
id="chartis/osrd_psl_signs_kp/geo"
layerOrder={layerOrder}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
import { LAYER_GROUPS_ORDER, LAYERS } from 'config/layerOrder';

import 'common/Map/Map.scss';
import SNCF_PSL from 'common/Map/Layers/extensions/SNCF/SNCF_PSL';
import SNCF_PSL from 'common/Map/Layers/extensions/SNCF/PSL';
import IGN_BD_ORTHO from 'common/Map/Layers/IGN_BD_ORTHO';
import IGN_SCAN25 from 'common/Map/Layers/IGN_SCAN25';
import IGN_CADASTRE from 'common/Map/Layers/IGN_CADASTRE';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { LAYER_GROUPS_ORDER, LAYERS } from 'config/layerOrder';

import 'common/Map/Map.scss';
import OperationalPoints from 'common/Map/Layers/OperationalPoints';
import Platforms from 'common/Map/Layers/Platforms';
import { Platforms } from 'common/Map/Layers/Platforms';
import { getMapMouseEventNearestFeature } from 'utils/mapHelper';
import { CUSTOM_ATTRIBUTION } from 'common/Map/const';
import { getMapStyle } from 'reducers/map/selectors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import colors from 'common/Map/Consts/colors';
import { useMapBlankStyle } from 'common/Map/Layers/blankStyle';
import { LAYER_GROUPS_ORDER, LAYERS } from 'config/layerOrder';
import 'common/Map/Map.scss';
import SNCF_PSL from 'common/Map/Layers/extensions/SNCF/SNCF_PSL';
import SNCF_PSL from 'common/Map/Layers/extensions/SNCF/PSL';
import IGN_BD_ORTHO from 'common/Map/Layers/IGN_BD_ORTHO';
import IGN_SCAN25 from 'common/Map/Layers/IGN_SCAN25';
import IGN_CADASTRE from 'common/Map/Layers/IGN_CADASTRE';
Expand Down