33 lines
1.3 KiB
JavaScript
Executable File
33 lines
1.3 KiB
JavaScript
Executable File
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var distance_1 = __importDefault(require("@turf/distance"));
|
|
var meta_1 = require("@turf/meta");
|
|
/**
|
|
* Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.
|
|
*
|
|
* @name length
|
|
* @param {Feature<LineString|MultiLineString>} geojson GeoJSON to measure
|
|
* @param {Object} [options={}] Optional parameters
|
|
* @param {string} [options.units=kilometers] can be degrees, radians, miles, or kilometers
|
|
* @returns {number} length of GeoJSON
|
|
* @example
|
|
* var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);
|
|
* var length = turf.length(line, {units: 'miles'});
|
|
*
|
|
* //addToMap
|
|
* var addToMap = [line];
|
|
* line.properties.distance = length;
|
|
*/
|
|
function length(geojson, options) {
|
|
if (options === void 0) { options = {}; }
|
|
// Calculate distance from 2-vertex line segments
|
|
return meta_1.segmentReduce(geojson, function (previousValue, segment) {
|
|
var coords = segment.geometry.coordinates;
|
|
return previousValue + distance_1.default(coords[0], coords[1], options);
|
|
}, 0);
|
|
}
|
|
exports.default = length;
|