@turf/line-slice-along
Advanced tools
Comparing version 4.7.3 to 5.0.4
@@ -1,10 +0,13 @@ | ||
/// <reference types="geojson" /> | ||
import { Units, LineString, Feature} from '@turf/helpers' | ||
type LineString = GeoJSON.Feature<GeoJSON.LineString>; | ||
/** | ||
* http://turfjs.org/docs/ | ||
*/ | ||
declare function lineSliceAlong(line: LineString | GeoJSON.LineString, startDist: number, stopDist: number, units?: string): LineString; | ||
declare namespace lineSliceAlong { } | ||
export = lineSliceAlong; | ||
export default function lineSliceAlong( | ||
line: Feature<LineString> | LineString, | ||
startDist: number, | ||
stopDist: number, | ||
options?: { | ||
units?: Units | ||
} | ||
): Feature<LineString>; |
31
index.js
@@ -1,5 +0,5 @@ | ||
var bearing = require('@turf/bearing'); | ||
var distance = require('@turf/distance'); | ||
var destination = require('@turf/destination'); | ||
var lineString = require('@turf/helpers').lineString; | ||
import bearing from '@turf/bearing'; | ||
import distance from '@turf/distance'; | ||
import destination from '@turf/destination'; | ||
import { lineString, isObject } from '@turf/helpers'; | ||
@@ -17,3 +17,4 @@ /** | ||
* @param {number} stopDist distance along the line to ending point | ||
* @param {string} [units=kilometers] can be degrees, radians, miles, or kilometers | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers | ||
* @returns {Feature<LineString>} sliced line | ||
@@ -24,3 +25,3 @@ * @example | ||
* var stop = 25; | ||
* var sliced = turf.lineSliceAlong(line, start, stop, 'miles'); | ||
* var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'}); | ||
* | ||
@@ -30,5 +31,11 @@ * //addToMap | ||
*/ | ||
module.exports = function (line, startDist, stopDist, units) { | ||
function lineSliceAlong(line, startDist, stopDist, options) { | ||
// Optional parameters | ||
options = options || {}; | ||
if (!isObject(options)) throw new Error('options is invalid'); | ||
var coords; | ||
var slice = []; | ||
// Validation | ||
if (line.type === 'Feature') coords = line.geometry.coordinates; | ||
@@ -49,3 +56,3 @@ else if (line.type === 'LineString') coords = line.coordinates; | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, units); | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
@@ -61,3 +68,3 @@ } | ||
direction = bearing(coords[i], coords[i - 1]) - 180; | ||
interpolated = destination(coords[i], overshot, direction, units); | ||
interpolated = destination(coords[i], overshot, direction, options); | ||
slice.push(interpolated.geometry.coordinates); | ||
@@ -75,5 +82,7 @@ return lineString(slice); | ||
travelled += distance(coords[i], coords[i + 1], units); | ||
travelled += distance(coords[i], coords[i + 1], options); | ||
} | ||
return lineString(coords[coords.length - 1]); | ||
}; | ||
} | ||
export default lineSliceAlong; |
{ | ||
"name": "@turf/line-slice-along", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf line-slice-along module", | ||
"main": "index.js", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"main.js" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
}, | ||
@@ -31,13 +35,19 @@ "repository": { | ||
"devDependencies": { | ||
"@turf/along": "^4.7.3", | ||
"benchmark": "^2.1.4", | ||
"load-json-file": "^2.0.0", | ||
"tape": "^4.6.3" | ||
"@std/esm": "*", | ||
"@turf/along": "^5.0.4", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"tape": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/bearing": "^4.7.3", | ||
"@turf/destination": "^4.7.3", | ||
"@turf/distance": "^4.7.3", | ||
"@turf/helpers": "^4.7.3" | ||
"@turf/bearing": "^5.0.4", | ||
"@turf/destination": "^5.0.4", | ||
"@turf/distance": "^5.0.4", | ||
"@turf/helpers": "^5.0.4" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/line-slice-along | ||
# lineSliceAlong | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## lineSliceAlong | ||
Takes a [line](http://geojson.org/geojson-spec.html#linestring), a specified distance along the line to a start [Point](http://geojson.org/geojson-spec.html#point), | ||
@@ -16,3 +18,4 @@ and a specified distance along the line to a stop point | ||
- `stopDist` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** distance along the line to ending point | ||
- `units` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** can be degrees, radians, miles, or kilometers (optional, default `kilometers`) | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.units` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`) | ||
@@ -25,3 +28,3 @@ **Examples** | ||
var stop = 25; | ||
var sliced = turf.lineSliceAlong(line, start, stop, 'miles'); | ||
var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'}); | ||
@@ -28,0 +31,0 @@ //addToMap |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11329
6
161
59
6
+ Added@turf/bearing@5.1.5(transitive)
+ Added@turf/destination@5.1.5(transitive)
+ Added@turf/distance@5.1.5(transitive)
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/invariant@5.2.0(transitive)
- Removed@turf/bearing@4.7.3(transitive)
- Removed@turf/destination@4.7.3(transitive)
- Removed@turf/distance@4.7.3(transitive)
- Removed@turf/helpers@4.7.3(transitive)
- Removed@turf/invariant@4.7.3(transitive)
Updated@turf/bearing@^5.0.4
Updated@turf/destination@^5.0.4
Updated@turf/distance@^5.0.4
Updated@turf/helpers@^5.0.4