Skip to content

Commit

Permalink
PB-1255: Unintended segmentation of KML
Browse files Browse the repository at this point in the history
  • Loading branch information
sommerfe committed Jan 17, 2025
1 parent 914f3ad commit 472eaed
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/api/profile/profile.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,33 @@ export default async (profileCoordinates, projection) => {
}
let lastCoordinate = null
let lastDist = 0
// The segment is divided into chunks if the amount of coordinates in the segment is greater than MAX_CHUNK_LENGTH
const requestsForChunks = coordinateChunks.map((chunk) =>
getProfileDataForChunk(chunk, lastCoordinate, lastDist, projection)
)

const chunks = []
for (const chunkResponse of await Promise.allSettled(requestsForChunks)) {
if (chunkResponse.status === 'fulfilled') {
const segment = parseProfileFromBackendResponse(
const chunk = parseProfileFromBackendResponse(
chunkResponse.value,
lastDist,
projection
)
if (segment) {
const newSegmentLastPoint = segment.points.slice(-1)[0]
if (chunk) {
const newSegmentLastPoint = chunk.points.slice(-1)[0]
lastCoordinate = newSegmentLastPoint.coordinate
lastDist = newSegmentLastPoint.dist
segments.push(segment)
chunks.push(chunk)
}
} else {
log.error('Error while getting profile for chunk', chunkResponse.reason?.message)
}
}
// Here the chunks are merged into a single segment
const mergedChunks = new ElevationProfileSegment(
chunks.reduce((acc, segment) => acc.concat(segment.points), [])
)
segments.push(mergedChunks)
}
return new ElevationProfile(segments)
}

0 comments on commit 472eaed

Please sign in to comment.