Skip to content

Commit

Permalink
front: map: add switch button for smooth-travel on map
Browse files Browse the repository at this point in the history
- add smoothTravel selector and updateSmoothTravel dispatch function
- add smoothTravel FormatSwitch in MapSettingsBackgroundSwitches.tsx
- add smoothTravel in condition to enable flyTo() in MapSearch.tsx
- add translations in map-settings.json (en/fr)
  • Loading branch information
Yohh committed Nov 23, 2023
1 parent 48184c6 commit 2019297
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion front/public/locales/en/map-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"noSpeedLimitByTag": "No composition code",
"operationalpoints": "Operational points",
"platforms":"Platforms",
"platforms": "Platforms",
"routes": "Train blocks",
"signals": "Signals",
"signalingtype": "Signalling block type",
Expand All @@ -25,6 +25,7 @@
"showIGNCadastre": "Cadastre ©IGN",
"showOSM": "Map background OSM",
"showOSMtracksections": "OSM tracks",
"smoothTravel": "Smooth travel",
"sncf_psl": "Permanent speed limits",
"speedlimits": "Speed limits",
"stops": "Stop signs",
Expand Down
3 changes: 2 additions & 1 deletion front/public/locales/fr/map-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"noSpeedLimitByTag": "Aucun code de composition",
"operationalpoints": "Points remarquables",
"platforms":"Quais",
"platforms": "Quais",
"routes": "Cantons",
"signals": "Signals",
"signalingtype": "Type de block",
Expand All @@ -25,6 +25,7 @@
"showIGNCadastre": "Cadastre ©IGN",
"showOSM": "Fond de carte OSM",
"showOSMtracksections": "Voies OSM",
"smoothTravel": "Transition douce",
"sncf_psl": "Limites permanentes de vitesse",
"speedlimits": "Vitesses limites",
"stops": "Pancartes d'arrêt",
Expand Down
3 changes: 2 additions & 1 deletion front/src/common/Map/Search/MapSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ type MapSearchProps = {

const MapSearch: FC<MapSearchProps> = ({ map, closeMapSearchPopUp }) => {
const dispatch = useDispatch();
const { smoothTravel } = useSelector(getMap);

const updateViewportChange = useCallback(
(value: Partial<Viewport>) => {
if (map) {
if (map && smoothTravel) {
map.flyTo({
center: {
lng: value.longitude || map.getCenter().lng,
Expand Down
19 changes: 17 additions & 2 deletions front/src/common/Map/Settings/MapSettingsBackgroundSwitches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
updateShowOSM,
updateShowOSMtracksections,
updateTerrain3DExaggeration,
updateSmoothTravel,
} from 'reducers/map';

const FormatSwitch: FC<{
Expand Down Expand Up @@ -47,8 +48,14 @@ const FormatSwitch: FC<{

const MapSettingsBackgroundSwitches: FC<unknown> = () => {
const { t } = useTranslation(['map-settings']);
const { showIGNBDORTHO, showIGNSCAN25, showIGNCadastre, showOSM, showOSMtracksections } =
useSelector(getMap);
const {
showIGNBDORTHO,
showIGNSCAN25,
showIGNCadastre,
showOSM,
showOSMtracksections,
smoothTravel,
} = useSelector(getMap);
const terrain3DExaggeration = useSelector(getTerrain3DExaggeration);
const dispatch = useDispatch();

Expand Down Expand Up @@ -111,6 +118,14 @@ const MapSettingsBackgroundSwitches: FC<unknown> = () => {
/>
</div>
</div>

<FormatSwitch
name="smoothTravel-switch"
onChange={() => dispatch(updateSmoothTravel(!smoothTravel))}
state={smoothTravel}
icon=""
label="smoothTravel"
/>
</>
);
};
Expand Down
6 changes: 6 additions & 0 deletions front/src/reducers/map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface MapState {
showOSM: boolean;
showOSMtracksections: boolean;
terrain3DExaggeration: number;
smoothTravel: boolean;
viewport: Viewport;
featureInfoClickID?: number;
layersSettings: {
Expand Down Expand Up @@ -59,6 +60,7 @@ export const mapInitialState: MapState = {
showOSM: true,
showOSMtracksections: false,
terrain3DExaggeration: 0,
smoothTravel: false,
viewport: {
latitude: 48.32,
longitude: 2.44,
Expand Down Expand Up @@ -138,6 +140,9 @@ const mapSlice = createSlice({
) => {
state.terrain3DExaggeration = action.payload;
},
updateSmoothTravel: (state, action: PayloadAction<MapState['smoothTravel']>) => {
state.smoothTravel = action.payload;
},
},
});

Expand Down Expand Up @@ -177,6 +182,7 @@ export const {
updateShowOSM,
updateShowOSMtracksections,
updateTerrain3DExaggeration,
updateSmoothTravel,
updateViewportAction,
updateIssuesSettings,
} = mapSliceActions;
Expand Down
1 change: 1 addition & 0 deletions front/src/reducers/map/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const getShowIGNCadastre = makeMapStateSelector('showIGNCadastre');
export const getShowOSM = makeMapStateSelector('showOSM');
export const getShowOSMtracksections = makeMapStateSelector('showOSMtracksections');
export const getTerrain3DExaggeration = makeMapStateSelector('terrain3DExaggeration');
export const getSmoothTravel = makeMapStateSelector('smoothTravel');
export const getViewport = makeMapStateSelector('viewport');
export const getLayersSettings = makeMapStateSelector('layersSettings');
export const getMapSearchMarker = makeMapStateSelector('mapSearchMarker');

0 comments on commit 2019297

Please sign in to comment.