Skip to content

Commit

Permalink
map-viewer: empty nominal voltages at substations full reload + add r…
Browse files Browse the repository at this point in the history
…esetZoomAndPosition (#144)

* fix: when reloading network, empty nominal voltage + export method to reset map position and zoom
* fix: useImpoerativeHandle dependencies
* feat: add TS export + add button to demo

Signed-off-by: LE SAULNIER Kevin <[email protected]>
  • Loading branch information
klesaulnier authored Jan 17, 2025
1 parent 9bcace5 commit 368f66c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export default function App() {
console.log('Selected Lines: ', networkMapRef.current?.getSelectedLines().length);
}}
/>
<button onClick={() => networkMapRef.current?.resetZoomAndPosition()}>
Reset zoom and position
</button>
</div>
</ThemeProvider>
</StyledEngineProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class MapEquipments {
updateSubstations(substations: MapSubstation[], fullReload: boolean) {
if (fullReload) {
this.substations = [];
this.nominalVoltages = [];
}

// replace current modified substations
Expand Down
9 changes: 8 additions & 1 deletion src/components/network-map-viewer/network/network-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export type NetworkMapRef = {
getSelectedLines: () => MapAnyLine[];
cleanDraw: () => void;
getMapDrawer: () => MapboxDraw | undefined;
resetZoomAndPosition: () => void;
};

const NetworkMap = forwardRef<NetworkMapRef, NetworkMapProps>((rawProps, ref) => {
Expand Down Expand Up @@ -722,6 +723,11 @@ const NetworkMap = forwardRef<NetworkMapRef, NetworkMapProps>((rawProps, ref) =>
);
}, [props.mapEquipments, props.geoData, props.filteredNominalVoltages]);

// reset zoom and position to make the map centered around the displayed network
const resetZoomAndPosition = useCallback(() => {
setCentered(INITIAL_CENTERED);
}, []);

useImperativeHandle(
ref,
() => ({
Expand All @@ -734,8 +740,9 @@ const NetworkMap = forwardRef<NetworkMapRef, NetworkMapProps>((rawProps, ref) =>
onDrawEvent(DRAW_EVENT.DELETE);
},
getMapDrawer,
resetZoomAndPosition,
}),
[onPolygonChanged, getSelectedSubstations, getSelectedLines, onDrawEvent]
[onPolygonChanged, resetZoomAndPosition, getSelectedSubstations, getSelectedLines, onDrawEvent]
);

const onDelete = useCallback(() => {
Expand Down

0 comments on commit 368f66c

Please sign in to comment.