Skip to content

Commit

Permalink
Adjusted smoothing and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sdl60660 committed Oct 18, 2021
1 parent 0f07569 commit 5d606d2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/components/Map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
let altitudeChange = false;
let paused = false;
let playbackSpeed = 1;
const smoothingCoefficient = 3;
const smoothingCoefficient = 4;
// let currentFlowrateIndex = 0;
let currentFlowrate = { level: 10000, index: 0 };
Expand Down Expand Up @@ -399,7 +399,6 @@
(initialElevation * Math.tan((targetPitch * Math.PI) / 180)) / 1000;
// Create smoothed path by averaging coordinates with their neighbors. This helps reduce horizontal movement with bendy rivers.
// const smoothedPath = pathSmoother(coordinatePath, Math.min(9, Math.floor(coordinatePath.length / 2)));
const smoothedPath = pathSmoother(
coordinatePath,
Math.min(
Expand Down Expand Up @@ -548,13 +547,11 @@
let roundingDigits = 6;
while (resultFound === false && roundingDigits >= 0) {
roundingDigits -= 1;
const roundedLng = e.lngLat.lng.toFixed(roundingDigits);
const roundedLat = e.lngLat.lat.toFixed(roundingDigits);
const iowURL = `https://merit.internetofwater.app/processes/river-runner/execution?lng=${roundedLng}&lat=${roundedLat}`;
try {
const roundedLng = e.lngLat.lng.toFixed(roundingDigits);
const roundedLat = e.lngLat.lat.toFixed(roundingDigits);
const iowURL = `https://merit.internetofwater.app/processes/river-runner/execution?lng=${roundedLng}&lat=${roundedLat}`;
const flowlinesResponse = await fetch(iowURL, {
method: 'GET',
headers: {
Expand All @@ -580,6 +577,8 @@
`Error while rounding coordinates to ${roundingDigits} digits. Trying again with less precise coordinates.`
);
}
roundingDigits -= 1;
}
return flowlinesData;
Expand Down Expand Up @@ -740,13 +739,16 @@
// exception case for paths that stop at inland lakes, just in case their last feature isn't encoded as stream level 1
// This is necessary beacause I'm getting streamlevel = 1 on non-terminal features in the data, otherwise excluding dummy terminal features should be more straightforward
if (riverFeatures[riverFeatures.length - 1].name === "Unidentified River/Stream"
if ( riverFeatures.length > 1
&& riverFeatures[riverFeatures.length - 1].name === "Unidentified River/Stream"
&& riverFeatures[riverFeatures.length - 2].name !== "Unidentified River/Stream"
&& riverFeatures[riverFeatures.length - 2].stream_level === 1
) {
riverFeatures = riverFeatures.slice(0, riverFeatures.length - 1);
}
console.log({ featureNames, uniqueFeatureNames, riverFeatures });
riverFeatures.forEach((feature, i) => {
if (i === riverFeatures.length - 1) {
feature.length_km = Math.round(feature.distance_from_destination);
Expand Down

1 comment on commit 5d606d2

@vercel
Copy link

@vercel vercel bot commented on 5d606d2 Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.