Skip to content

Commit 7f36fea

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

File tree

9 files changed

+57
-0
lines changed

9 files changed

+57
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ 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+
dist: number; // replaced by pointDistance
61+
// deprecated properties END
5662
[key: string]: any;
5763
}
5864
> {
@@ -69,6 +75,12 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
6975
lineDistance: -1,
7076
segmentDistance: -1,
7177
pointDistance: Infinity,
78+
// deprecated properties START
79+
multiFeatureIndex: -1,
80+
index: -1,
81+
location: -1,
82+
dist: Infinity,
83+
// deprecated properties END
7284
});
7385

7486
let totalDistance = 0.0;
@@ -128,7 +140,20 @@ function nearestPointOnLine<G extends LineString | MultiLineString>(
128140
lineDistance: lineDistance + segmentDistance,
129141
segmentDistance: segmentDistance,
130142
pointDistance: pointDistance,
143+
// deprecated properties START
144+
multiFeatureIndex: -1,
145+
index: -1,
146+
location: -1,
147+
dist: Infinity,
131148
});
149+
closestPt.properties = {
150+
...closestPt.properties,
151+
multiFeatureIndex: closestPt.properties.lineStringIndex,
152+
index: closestPt.properties.segmentIndex,
153+
location: closestPt.properties.totalDistance,
154+
dist: closestPt.properties.pointDistance,
155+
// deprecated properties END
156+
};
132157
}
133158

134159
// update totalDistance and lineDistance

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ 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.dist = round(onLine.properties.dist, 6);
52+
// deprecated properties END
4953
onLine.properties["marker-color"] = "#F0F";
5054
const between = lineString(
5155
[onLine.geometry.coordinates, point.geometry.coordinates],

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
"lineDistance": 19.748879,
4646
"segmentDistance": 1.771897,
4747
"pointDistance": 5.959562,
48+
"dist": 5.959562,
49+
"multiFeatureIndex": 0,
50+
"location": 19.748879,
51+
"index": 1,
4852
"marker-color": "#F0F"
4953
},
5054
"geometry": {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
"lineDistance": 22.137494,
4646
"segmentDistance": 3.445915,
4747
"pointDistance": 2.556271,
48+
"dist": 2.556271,
49+
"multiFeatureIndex": 0,
50+
"location": 22.137494,
51+
"index": 1,
4852
"marker-color": "#F0F"
4953
},
5054
"geometry": {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
"lineDistance": 4800.716022,
7474
"segmentDistance": 173.221741,
7575
"pointDistance": 114.725451,
76+
"dist": 114.725451,
77+
"multiFeatureIndex": 1,
78+
"location": 9479.011715,
79+
"index": 21,
7680
"marker-color": "#F0F"
7781
},
7882
"geometry": {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
"lineDistance": 0,
5555
"segmentDistance": 0,
5656
"pointDistance": 390.942725,
57+
"dist": 390.942725,
58+
"multiFeatureIndex": 1,
59+
"location": 1656.139708,
60+
"index": 0,
5761
"marker-color": "#F0F"
5862
},
5963
"geometry": {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
"lineDistance": 214.735285,
6464
"segmentDistance": 214.735285,
6565
"pointDistance": 121.937841,
66+
"dist": 121.937841,
67+
"multiFeatureIndex": 0,
68+
"location": 214.735285,
69+
"index": 0,
6670
"marker-color": "#F0F"
6771
},
6872
"geometry": {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4798,6 +4798,10 @@
47984798
"lineDistance": 183.46844,
47994799
"segmentDistance": 0.044741,
48004800
"pointDistance": 7.876557,
4801+
"dist": 7.876557,
4802+
"multiFeatureIndex": 0,
4803+
"location": 183.46844,
4804+
"index": 3104,
48014805
"marker-color": "#F0F"
48024806
},
48034807
"geometry": {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,6 +3802,10 @@
38023802
"lineDistance": 303.639629,
38033803
"segmentDistance": 0.867249,
38043804
"pointDistance": 19.22738,
3805+
"dist": 19.22738,
3806+
"multiFeatureIndex": 0,
3807+
"location": 303.639629,
3808+
"index": 1185,
38053809
"marker-color": "#F0F"
38063810
},
38073811
"geometry": {

0 commit comments

Comments
 (0)