Skip to content

Commit

Permalink
front: group all infra object layers in a single component
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Jan 15, 2025
1 parent 399cc8e commit 4e1f461
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 296 deletions.
78 changes: 3 additions & 75 deletions front/src/applications/referenceMap/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,21 @@ import type { MapRef } from 'react-map-gl/maplibre';
import { useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';

/* Main data & layers */
/* Settings & Buttons */
import MapButtons from 'common/Map/Buttons/MapButtons';
import { CUSTOM_ATTRIBUTION } from 'common/Map/const';
import colors from 'common/Map/Consts/colors';
import Background from 'common/Map/Layers/Background';
import { useMapBlankStyle } from 'common/Map/Layers/blankStyle';
import BufferStops from 'common/Map/Layers/BufferStops';
import Detectors from 'common/Map/Layers/Detectors';
import Electrifications from 'common/Map/Layers/Electrifications';
import NeutralSections from 'common/Map/Layers/extensions/SNCF/NeutralSections';
import SNCF_PSL from 'common/Map/Layers/extensions/SNCF/PSL';
import Hillshade from 'common/Map/Layers/Hillshade';
import IGN_BD_ORTHO from 'common/Map/Layers/IGN_BD_ORTHO';
import IGN_CADASTRE from 'common/Map/Layers/IGN_CADASTRE';
import IGN_SCAN25 from 'common/Map/Layers/IGN_SCAN25';
import InfraObjectLayers from 'common/Map/Layers/InfraObjectLayers';
import LineSearchLayer from 'common/Map/Layers/LineSearchLayer';
import OperationalPoints from 'common/Map/Layers/OperationalPoints';
import OSM from 'common/Map/Layers/OSM';
/* Objects & various */
import PlatformsLayer from 'common/Map/Layers/Platforms';
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 Switches from 'common/Map/Layers/Switches';
import Terrain from 'common/Map/Layers/Terrain';
import TracksGeographic from 'common/Map/Layers/TracksGeographic';
import TracksOSM from 'common/Map/Layers/TracksOSM';
import { removeSearchItemMarkersOnMap } from 'common/Map/utils';
import { useInfraID } from 'common/osrdContext';
Expand Down Expand Up @@ -153,6 +140,8 @@ function Map() {
<IGN_SCAN25 layerOrder={LAYER_GROUPS_ORDER[LAYERS.BACKGROUND.GROUP]} />
<IGN_CADASTRE layerOrder={LAYER_GROUPS_ORDER[LAYERS.BACKGROUND.GROUP]} />

{infraID && <InfraObjectLayers infraId={infraID} mapStyle={mapStyle} />}

{!showOSM ? null : (
<>
<OSM
Expand All @@ -172,72 +161,11 @@ function Map() {
layerOrder={LAYER_GROUPS_ORDER[LAYERS.PLATFORMS.GROUP]}
/>

<TracksGeographic
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.TRACKS_GEOGRAPHIC.GROUP]}
infraID={infraID}
/>

<TracksOSM
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.TRACKS_OSM.GROUP]}
/>

<Routes
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.ROUTES.GROUP]}
infraID={infraID}
/>

<OperationalPoints
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.OPERATIONAL_POINTS.GROUP]}
infraID={infraID}
/>

<Electrifications
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.ELECTRIFICATIONS.GROUP]}
infraID={infraID}
/>
<NeutralSections
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.DEAD_SECTIONS.GROUP]}
infraID={infraID}
/>
<BufferStops
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.BUFFER_STOPS.GROUP]}
infraID={infraID}
/>
<Detectors
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.DETECTORS.GROUP]}
infraID={infraID}
/>
<Switches
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SWITCHES.GROUP]}
infraID={infraID}
/>

<SpeedLimits
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SPEED_LIMITS.GROUP]}
infraID={infraID}
/>
<SNCF_PSL
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SPEED_LIMITS.GROUP]}
infraID={infraID}
/>

<Signals
sourceTable="signals"
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SIGNALS.GROUP]}
infraID={infraID}
/>
<LineSearchLayer
layerOrder={LAYER_GROUPS_ORDER[LAYERS.LINE_SEARCH.GROUP]}
infraID={infraID}
Expand Down
98 changes: 98 additions & 0 deletions front/src/common/Map/Layers/InfraObjectLayers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import colors from 'common/Map/Consts/colors';
import { LAYER_GROUPS_ORDER, LAYERS } from 'config/layerOrder';

import BufferStops from './BufferStops';
import Detectors from './Detectors';
import Electrifications from './Electrifications';
import NeutralSections from './extensions/SNCF/NeutralSections';
import SNCF_PSL from './extensions/SNCF/PSL';
import OperationalPoints from './OperationalPoints';
import Routes from './Routes';
import Signals from './Signals';
import SpeedLimits from './SpeedLimits';
import Switches from './Switches';
import TracksGeographic from './TracksGeographic';

type InfraObjectLayersProps = {
infraId: number;
mapStyle: 'normal' | 'dark' | 'blueprint' | 'minimal';
hoveredOperationalPointId?: string;
};

const InfraObjectLayers = ({
infraId,
mapStyle,
hoveredOperationalPointId,
}: InfraObjectLayersProps) => (
<>
<TracksGeographic
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.TRACKS_GEOGRAPHIC.GROUP]}
infraID={infraId}
/>

<Routes
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.ROUTES.GROUP]}
infraID={infraId}
/>

<OperationalPoints
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.OPERATIONAL_POINTS.GROUP]}
operationnalPointId={hoveredOperationalPointId}
infraID={infraId}
/>

<Electrifications
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.ELECTRIFICATIONS.GROUP]}
infraID={infraId}
/>

<NeutralSections
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.DEAD_SECTIONS.GROUP]}
infraID={infraId}
/>

<BufferStops
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.BUFFER_STOPS.GROUP]}
infraID={infraId}
/>

<Detectors
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.DETECTORS.GROUP]}
infraID={infraId}
/>

<Switches
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SWITCHES.GROUP]}
infraID={infraId}
/>

<SpeedLimits
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SPEED_LIMITS.GROUP]}
infraID={infraId}
/>

<SNCF_PSL
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SPEED_LIMITS.GROUP]}
infraID={infraId}
/>

<Signals
sourceTable="signals"
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SIGNALS.GROUP]}
infraID={infraId}
/>
</>
);

export default InfraObjectLayers;
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,16 @@ import { CUSTOM_ATTRIBUTION } from 'common/Map/const';
import colors from 'common/Map/Consts/colors';
import Background from 'common/Map/Layers/Background';
import { useMapBlankStyle } from 'common/Map/Layers/blankStyle';
import BufferStops from 'common/Map/Layers/BufferStops';
import Detectors from 'common/Map/Layers/Detectors';
import Electrifications from 'common/Map/Layers/Electrifications';
import NeutralSections from 'common/Map/Layers/extensions/SNCF/NeutralSections';
import SNCF_PSL from 'common/Map/Layers/extensions/SNCF/PSL';
import Hillshade from 'common/Map/Layers/Hillshade';
import IGN_BD_ORTHO from 'common/Map/Layers/IGN_BD_ORTHO';
import IGN_CADASTRE from 'common/Map/Layers/IGN_CADASTRE';
import IGN_SCAN25 from 'common/Map/Layers/IGN_SCAN25';
import InfraObjectLayers from 'common/Map/Layers/InfraObjectLayers';
import LineSearchLayer from 'common/Map/Layers/LineSearchLayer';
import OperationalPoints from 'common/Map/Layers/OperationalPoints';
import OSM from 'common/Map/Layers/OSM';
import PlatformsLayer from 'common/Map/Layers/Platforms';
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 Switches from 'common/Map/Layers/Switches';
import Terrain from 'common/Map/Layers/Terrain';
import TracksGeographic from 'common/Map/Layers/TracksGeographic';
import TracksOSM from 'common/Map/Layers/TracksOSM';
import { removeSearchItemMarkersOnMap } from 'common/Map/utils';
import { computeBBoxViewport } from 'common/Map/WarpedMap/core/helpers';
Expand Down Expand Up @@ -242,6 +232,8 @@ const SimulationResultMap = ({
<AttributionControl position="bottom-right" customAttribution={CUSTOM_ATTRIBUTION} />
<ScaleControl maxWidth={100} unit="metric" style={scaleControlStyle} />

{infraID && <InfraObjectLayers infraId={infraID} mapStyle={mapStyle} />}

<Background
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.BACKGROUND.GROUP]}
Expand Down Expand Up @@ -271,72 +263,11 @@ const SimulationResultMap = ({
layerOrder={LAYER_GROUPS_ORDER[LAYERS.PLATFORMS.GROUP]}
/>

<TracksGeographic
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.TRACKS_GEOGRAPHIC.GROUP]}
infraID={infraID}
/>
<TracksOSM
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.TRACKS_OSM.GROUP]}
/>

<Routes
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.ROUTES.GROUP]}
infraID={infraID}
/>

<OperationalPoints
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.OPERATIONAL_POINTS.GROUP]}
infraID={infraID}
/>

<Electrifications
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.ELECTRIFICATIONS.GROUP]}
infraID={infraID}
/>
<NeutralSections
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.DEAD_SECTIONS.GROUP]}
infraID={infraID}
/>
<BufferStops
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.BUFFER_STOPS.GROUP]}
infraID={infraID}
/>
<Detectors
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.DETECTORS.GROUP]}
infraID={infraID}
/>
<Switches
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SWITCHES.GROUP]}
infraID={infraID}
/>

<SpeedLimits
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SPEED_LIMITS.GROUP]}
infraID={infraID}
/>
<SNCF_PSL
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SPEED_LIMITS.GROUP]}
infraID={infraID}
/>

<Signals
mapRef={mapRef}
sourceTable="signals"
colors={colors[mapStyle]}
layerOrder={LAYER_GROUPS_ORDER[LAYERS.SIGNALS.GROUP]}
infraID={infraID}
/>
<LineSearchLayer
layerOrder={LAYER_GROUPS_ORDER[LAYERS.LINE_SEARCH.GROUP]}
infraID={infraID}
Expand Down
Loading

0 comments on commit 4e1f461

Please sign in to comment.