Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
SearchBar: Make it fly to the selected road
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb-sti1 committed Oct 12, 2023
1 parent 4744c7d commit d7ee43c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions frontend/src/Components/Conditions/ConditionsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { getConditions } from '../../queries/fetchConditions';
import { IRoad } from '../../models/path';
import { getRoads } from '../../queries/road';
import Roads from '../Map/Roads';
import { LatLng } from '../../models/models';
import ForceMapUpdate from '../Map/ForceMapUpdate';

const ALL = 'ALL';
const KPI = 'KPI';
Expand Down Expand Up @@ -385,13 +387,23 @@ const ConditionsMap = (props: any) => {
getRoads(setRoads);
}, []);

const [moveToPosition, setMoveToPosition] = useState<LatLng>();

return (
<div style={{ height: '100%' }}>
<div className="nav-wrapper">
<div className="nav-container">
<Search
onPlaceSelect={(value: any) => {
console.log(value);
const coordinates = value?.geometry?.coordinates;
if (coordinates) {
const position = {
lat: coordinates[Math.floor(coordinates.length / 2)][1],
lng: coordinates[Math.floor(coordinates.length / 2)][0],
};
setMoveToPosition(position);
}
}}
/>
</div>
Expand Down Expand Up @@ -423,6 +435,7 @@ const ConditionsMap = (props: any) => {
<div style={{ height: '100%' }}>
<MapWrapper>
<Roads roads={roads} />
<ForceMapUpdate position={moveToPosition} />
{dataAll !== undefined && (
<GeoJSON
ref={geoJsonRef}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Map/ForceMapUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useEffect } from 'react';

interface Props {
/** A modification of this value is used to trigger an update of the map */
triggerUpdate: number;
triggerUpdate?: number;
/** The coordinates of the map center*/
position?: LatLng;
}
Expand Down

0 comments on commit d7ee43c

Please sign in to comment.