Skip to content

Commit

Permalink
Refactor chart distance calculation and update billboard management.
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoPazz committed Nov 15, 2024
1 parent af7589f commit b028d67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
10 changes: 5 additions & 5 deletions lib/ReactViews/Custom/Chart/BottomDockChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ class Chart extends React.Component {
() => this.props.terria.selectedStopSummaryRowIndex.fromTable,
(idx) => {
if (idx !== null && this.props.chartItems) {
let sumDistances = 0;
for (let i = idx; i > 0; i--) {
sumDistances +=
this.props.terria.measurableGeom.stopGroundDistances[i];
}
const sumDistances =
this.props.terria.measurableGeom.stopGroundDistances
.slice(0, idx)
.reverse()
.reduce((acc, distance) => acc + distance, 0);

// Calculate the selected point coords in the chart.
const selectedPoint = {
Expand Down
41 changes: 13 additions & 28 deletions lib/ReactViews/MeasurableGeometry/MeasurablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,6 @@ const MeasurablePanel = observer((props: Props) => {
);
};

useEffect(() => {
if (terria.cesium) {
terria.cesium.scene.primitives.add(billboardCollection.current);

return () => {
billboardCollection.current?.removeAll();
terria.cesium
? terria.cesium.scene.primitives.remove(billboardCollection.current)
: undefined;
};
}
}, [terria]);

useEffect(() => {
setHighlightedRow(terria.selectedStopSummaryRowIndex.fromChart);
}, [terria.selectedStopSummaryRowIndex.fromChart]);
Expand All @@ -442,24 +429,22 @@ const MeasurablePanel = observer((props: Props) => {
terria.setSelectedStopSummaryRowIndex("fromTable", idx);
const coords = terria?.measurableGeom?.stopPoints?.[idx];
if (!coords) return;
if (!terria.cesium) return;
if (!billboardCollection.current) {
if (terria.cesium) {
billboardCollection.current = new BillboardCollection({
scene: terria.cesium.scene
});
terria.cesium.scene.primitives.add(billboardCollection.current);
}
} else {
billboardCollection.current.removeAll();
billboardCollection.current.add({
position: Cartographic.toCartesian(coords),
image: markerIcon,
eyeOffset: new Cartesian3(0.0, 0.0, -50.0),
heightReference: HeightReference.CLAMP_TO_GROUND,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
id: "chartPointPlaceholder"
billboardCollection.current = new BillboardCollection({
scene: terria.cesium.scene
});
terria.cesium.scene.primitives.add(billboardCollection.current);
}
billboardCollection.current.removeAll();
billboardCollection.current.add({
position: Cartographic.toCartesian(coords),
image: markerIcon,
eyeOffset: new Cartesian3(0.0, 0.0, -50.0),
heightReference: HeightReference.CLAMP_TO_GROUND,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
id: "chartPointPlaceholder"
});
terria.currentViewer.notifyRepaintRequired();
};

Expand Down

0 comments on commit b028d67

Please sign in to comment.