Skip to content

Commit 23a4ca8

Browse files
committed
nearest-point-on-line Add back deprecated properties
1 parent 4994d88 commit 23a4ca8

File tree

9 files changed

+72
-0
lines changed

9 files changed

+72
-0
lines changed

packages/turf-nearest-point-on-line/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
5353
lineDistance: number;
5454
segmentDistance: number;
5555
pointDistance: number;
56+
// deprecated properties START
57+
multiFeatureIndex: number; // replaced by lineStringIndex
58+
index: number; // replaced by segmentIndex
59+
location: number; // replaced by totalDistance
60+
multiFeatureLocation: number; // replaced by lineDistance
61+
dist: number; // replaced by pointDistance
62+
// deprecated properties END
5663
[key: string]: any;
5764
}
5865
> {
@@ -69,6 +76,13 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
6976
lineDistance: -1,
7077
segmentDistance: -1,
7178
pointDistance: Infinity,
79+
// deprecated properties START
80+
multiFeatureIndex: -1,
81+
index: -1,
82+
location: -1,
83+
multiFeatureLocation: -1,
84+
dist: Infinity,
85+
// deprecated properties END
7286
});
7387

7488
let totalDistance = 0.0;
@@ -128,7 +142,22 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
128142
lineDistance: lineDistance + segmentDistance,
129143
segmentDistance: segmentDistance,
130144
pointDistance: pointDistance,
145+
// deprecated properties START
146+
multiFeatureIndex: -1,
147+
index: -1,
148+
location: -1,
149+
multiFeatureLocation: -1,
150+
dist: Infinity,
131151
});
152+
closestPt.properties = {
153+
...closestPt.properties,
154+
multiFeatureIndex: closestPt.properties.lineStringIndex,
155+
index: closestPt.properties.segmentIndex,
156+
location: closestPt.properties.totalDistance,
157+
multiFeatureLocation: closestPt.properties.lineDistance,
158+
dist: closestPt.properties.pointDistance,
159+
// deprecated properties END
160+
};
132161
}
133162

134163
// update totalDistance and lineDistance

packages/turf-nearest-point-on-line/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ test("turf-nearest-point-on-line", (t) => {
4646
6
4747
);
4848
onLine.properties.pointDistance = round(onLine.properties.pointDistance, 6);
49+
// deprecated properties START
50+
onLine.properties.location = round(onLine.properties.location, 6);
51+
onLine.properties.multiFeatureLocation = round(
52+
onLine.properties.multiFeatureLocation,
53+
6
54+
);
55+
onLine.properties.dist = round(onLine.properties.dist, 6);
56+
// deprecated properties END
4957
onLine.properties["marker-color"] = "#F0F";
5058
const between = lineString(
5159
[onLine.geometry.coordinates, point.geometry.coordinates],

packages/turf-nearest-point-on-line/test/out/line-northern-latitude-#344.geojson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
"lineDistance": 19.748879,
4646
"segmentDistance": 1.771897,
4747
"pointDistance": 5.959562,
48+
"multiFeatureIndex": 0,
49+
"index": 1,
50+
"location": 19.748879,
51+
"multiFeatureLocation": 19.748879,
52+
"dist": 5.959562,
4853
"marker-color": "#F0F"
4954
},
5055
"geometry": {

packages/turf-nearest-point-on-line/test/out/line1.geojson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
"lineDistance": 22.137494,
4646
"segmentDistance": 3.445915,
4747
"pointDistance": 2.556271,
48+
"multiFeatureIndex": 0,
49+
"index": 1,
50+
"location": 22.137494,
51+
"multiFeatureLocation": 22.137494,
52+
"dist": 2.556271,
4853
"marker-color": "#F0F"
4954
},
5055
"geometry": {

packages/turf-nearest-point-on-line/test/out/multiLine1.geojson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
"lineDistance": 4800.716022,
7474
"segmentDistance": 173.221741,
7575
"pointDistance": 114.725451,
76+
"multiFeatureIndex": 1,
77+
"index": 21,
78+
"location": 9479.011715,
79+
"multiFeatureLocation": 4800.716022,
80+
"dist": 114.725451,
7681
"marker-color": "#F0F"
7782
},
7883
"geometry": {

packages/turf-nearest-point-on-line/test/out/multiLine2.geojson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
"lineDistance": 0,
5555
"segmentDistance": 0,
5656
"pointDistance": 390.942725,
57+
"multiFeatureIndex": 1,
58+
"index": 0,
59+
"location": 1656.139708,
60+
"multiFeatureLocation": 0,
61+
"dist": 390.942725,
5762
"marker-color": "#F0F"
5863
},
5964
"geometry": {

packages/turf-nearest-point-on-line/test/out/multiLine3.geojson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
"lineDistance": 214.735285,
6464
"segmentDistance": 214.735285,
6565
"pointDistance": 121.937841,
66+
"multiFeatureIndex": 0,
67+
"index": 0,
68+
"location": 214.735285,
69+
"multiFeatureLocation": 214.735285,
70+
"dist": 121.937841,
6671
"marker-color": "#F0F"
6772
},
6873
"geometry": {

packages/turf-nearest-point-on-line/test/out/route1.geojson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4798,6 +4798,11 @@
47984798
"lineDistance": 183.46844,
47994799
"segmentDistance": 0.044741,
48004800
"pointDistance": 7.876557,
4801+
"multiFeatureIndex": 0,
4802+
"index": 3104,
4803+
"location": 183.46844,
4804+
"multiFeatureLocation": 183.46844,
4805+
"dist": 7.876557,
48014806
"marker-color": "#F0F"
48024807
},
48034808
"geometry": {

packages/turf-nearest-point-on-line/test/out/route2.geojson

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,6 +3802,11 @@
38023802
"lineDistance": 303.639629,
38033803
"segmentDistance": 0.867249,
38043804
"pointDistance": 19.22738,
3805+
"multiFeatureIndex": 0,
3806+
"index": 1185,
3807+
"location": 303.639629,
3808+
"multiFeatureLocation": 303.639629,
3809+
"dist": 19.22738,
38053810
"marker-color": "#F0F"
38063811
},
38073812
"geometry": {

0 commit comments

Comments
 (0)