Skip to content

Commit

Permalink
fix updateFeatType bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinElms committed Jan 13, 2025
1 parent 74a48a4 commit 1e5008e
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions oceannavigator/frontend/src/components/OceanNavigator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,38 +328,43 @@ function OceanNavigator(props) {
};

const updateFeatType = (features) => {
let prevType = features[0].type;
let nextType = typeRef.current;
let updatedFeat = {};
let updatedFeat = [];

if (prevType === "point" && (nextType === "line" || nextType === "area")) {
let nextCoords = features.map((feat) => {
return feat.coords[0];
});
updatedFeat = [
{
id: features[0].id,
type: nextType,
coords: nextCoords,
},
];
} else if (
(prevType === "line" || prevType === "area") &&
nextType === "point"
) {
let nextCoords = features[0].coords;
updatedFeat = nextCoords.map((coord) => {
return {
id: "id" + Math.random().toString(16).slice(2),
type: nextType,
coords: [coord],
};
});
} else {
updatedFeat = features;
updatedFeat[0].type = nextType;
}
if (features.length > 0) {
let prevType = features[0].type;
let nextType = typeRef.current;

if (
prevType === "point" &&
(nextType === "line" || nextType === "area")
) {
let nextCoords = features.map((feat) => {
return feat.coords[0];
});
updatedFeat = [
{
id: features[0].id,
type: nextType,
coords: nextCoords,
},
];
} else if (
(prevType === "line" || prevType === "area") &&
nextType === "point"
) {
let nextCoords = features[0].coords;
updatedFeat = nextCoords.map((coord) => {
return {
id: "id" + Math.random().toString(16).slice(2),
type: nextType,
coords: [coord],
};
});
} else {
updatedFeat = features;
updatedFeat[0].type = nextType;
}
}
return updatedFeat;
};

Expand Down

0 comments on commit 1e5008e

Please sign in to comment.