Skip to content

Commit

Permalink
Refactor code to filter lines and HVDC lines based on selected polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
jamal-khey committed Mar 21, 2024
1 parent e79bd9c commit 711cf6e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 36 deletions.
18 changes: 2 additions & 16 deletions demo/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,9 @@ function App() {
}}
mapLibrary={'cartonolabel'}
mapTheme={'dark'}
onFeaturesChanged={(features) => {
console.log(
'debug',
'polygon features:',
features
);
filtredNominalVoltages={[380.0, 225.0, 110.0]}
onFeaturesChanged={() => {
networkMapRef.current.computeSelectedSubstation();
// console.log(
// 'debug',
// 'selected substation:',
// networkMapRef.current.getSelectedSubstation()
// );
// console.log(
// 'debug',
// 'selected voltage level:',
// networkMapRef.current.getSelectedVoltageLevel()
// );
console.log(
'debug',
'selected lines:',
Expand Down
74 changes: 54 additions & 20 deletions src/components/network-map-viewer/network/network-map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -617,21 +617,66 @@ const NetworkMap = forwardRef((props, ref) => {
return layers.find((layer) => layer.id === layerId);
}

function getSelectedLinesInPolygon(
network,
lines,
geoData,
polygonCoordinates
) {
const selectedLines = lines.filter((line) => {
try {
const linePos = geoData.getLinePositions(network, line);
if (!linePos) {
return false;
}

return (
booleanPointInPolygon(linePos[0], polygonCoordinates) &&
booleanPointInPolygon(linePos[1], polygonCoordinates)
);
} catch (error) {
console.error('debug', 'error', error);
return false;
}
});

return selectedLines;
}
const getSelectedLines = () => {
console.log('debug', 'getSelectedLines');
console.log('debug', 'lines', props.mapEquipments?.lines);
const lines = props.mapEquipments?.lines ?? [];

console.log('debug', 'layer', getLayerById(layers, LINE_LAYER_PREFIX));
console.log(
'debug',
'getLinesFromSubstation',
getLinesFromSubstation(selectedSubstation)
//check if polygon is defined correctly
const firstPolygonFeatures = Object.values(features)[0];
const polygonCoordinates = firstPolygonFeatures?.geometry;
if (!polygonCoordinates || polygonCoordinates.coordinates < 3) {
return [];
}
//for each line, check if it is in the polygon
return getSelectedLinesInPolygon(
props.mapEquipments,
lines,
props.geoData,
polygonCoordinates
);
return props.mapEquipments?.lines ?? [];
};
const getSelectedHVDCLines = () => {
console.log('debug', 'getSelectedHVDCLines');
console.log('debug', 'hvdcLines', props.mapEquipments?.hvdcLines);
return props.mapEquipments?.hvdcLines ?? [];
const hvdcLines = props.mapEquipments?.hvdcLines ?? [];

//check if polygon is defined correctly
const firstPolygonFeatures = Object.values(features)[0];
const polygonCoordinates = firstPolygonFeatures?.geometry;
if (!polygonCoordinates || polygonCoordinates.coordinates < 3) {
return [];
}
//for each line, check if it is in the polygon
return getSelectedLinesInPolygon(
props.mapEquipments,
hvdcLines,
props.geoData,
polygonCoordinates
);
};

useImperativeHandle(ref, () => ({
Expand Down Expand Up @@ -871,14 +916,3 @@ function getVoltageLevelFromSubstation(substations) {
})
.flat();
}

function getLinesFromSubstation(substations) {
if (!substations) {
return [];
}
return substations
.map((substation) => {
return substation.substation.lines;
})
.flat();
}

0 comments on commit 711cf6e

Please sign in to comment.