Skip to content

Commit 8622901

Browse files
committed
fix(patterns): fix pattern control point drag
During drag events, last control point distance was not updated properly and caused the line slice along operation to fail because the end distance was less than the start distance.
1 parent fda749c commit 8622901

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/editor/util/map.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,17 @@ export async function recalculateShape ({
253253
* @param {Number} endDistance
254254
* @return {Coordinate[]}
255255
*/
256-
function lineSliceAlongToCoords (startDistance, endDistance) {
256+
function lineSliceAlongToCoords (startDistance, endDistance = null) {
257257
if (startDistance === 0 && endDistance === 0) {
258258
return []
259259
}
260+
const lineSegment = lineString(patternShape.coordinates)
261+
if (endDistance === null) {
262+
// If no end distance provided, use distance of pattern shape
263+
endDistance = lineDistance(lineSegment, 'kilometers')
264+
}
260265
return lineSliceAlong(
261-
lineString(patternShape.coordinates),
266+
lineSegment,
262267
startDistance,
263268
endDistance
264269
).geometry.coordinates
@@ -294,10 +299,7 @@ export async function recalculateShape ({
294299
if (index < controlPoints.length - 1) {
295300
// updating something before last stop
296301
points.push(followingControlPoint.point.geometry.coordinates)
297-
followingCoords = lineSliceAlongToCoords(
298-
mToKm(followingControlPoint.distance),
299-
lastControlPointDistance
300-
)
302+
followingCoords = lineSliceAlongToCoords(mToKm(followingControlPoint.distance))
301303
}
302304
} else if (editType === 'delete') {
303305
if (index === 0) {
@@ -436,7 +438,7 @@ export async function recalculateShape ({
436438
} else {
437439
offset = segmentDistance - (followingControlPoint.distance - previousControlPoint.distance)
438440
}
439-
441+
// console.log(`offseting following control points by ${offset}`)
440442
controlPoints.slice(index + 1).forEach(controlPoint =>
441443
updatedControlPoints.push(cloneControlPointWithDistanceOffset(controlPoint, offset))
442444
)

0 commit comments

Comments
 (0)