本文整理匯總了TypeScript中@turf/destination.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: lineArc
/**
* Creates a circular arc, of a circle of the given radius and center point, between bearing1 and bearing2;
* 0 bearing is North of center point, positive clockwise.
*
* @name lineArc
* @param {Coord} center center point
* @param {number} radius radius of the circle
* @param {number} bearing1 angle, in decimal degrees, of the first radius of the arc
* @param {number} bearing2 angle, in decimal degrees, of the second radius of the arc
* @param {Object} [options={}] Optional parameters
* @param {number} [options.steps=64] number of steps
* @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians
* @returns {Feature<LineString>} line arc
* @example
* var center = turf.point([-75, 40]);
* var radius = 5;
* var bearing1 = 25;
* var bearing2 = 47;
*
* var arc = turf.lineArc(center, radius, bearing1, bearing2);
*
* //addToMap
* var addToMap = [center, arc]
*/
export default function lineArc(center: Coord, radius: number, bearing1: number, bearing2: number, options: {
steps?: number,
units?: Units,
} = {}): Feature<LineString> {
// default params
const steps = options.steps || 64;
const angle1 = convertAngleTo360(bearing1);
const angle2 = convertAngleTo360(bearing2);
const properties = (!Array.isArray(center) && center.type === "Feature") ? center.properties : {};
// handle angle parameters
if (angle1 === angle2) {
return lineString(circle(center, radius, options).geometry.coordinates[0], properties);
}
const arcStartDegree = angle1;
const arcEndDegree = (angle1 < angle2) ? angle2 : angle2 + 360;
let alfa = arcStartDegree;
const coordinates = [];
let i = 0;
while (alfa < arcEndDegree) {
coordinates.push(destination(center, radius, alfa, options).geometry.coordinates);
i++;
alfa = arcStartDegree + i * 360 / steps;
}
if (alfa > arcEndDegree) {
coordinates.push(destination(center, radius, arcEndDegree, options).geometry.coordinates);
}
return lineString(coordinates, properties);
}
示例2: along
/**
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
*
* @name along
* @param {Feature<LineString>} line input line
* @param {number} distance distance along the line
* @param {Object} [options] Optional parameters
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
* @returns {Feature<Point>} Point `distance` `units` along the line
* @example
* var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
* var options = {units: 'miles'};
*
* var along = turf.along(line, 200, options);
*
* //addToMap
* var addToMap = [along, line]
*/
export default function along(
line: Feature<LineString> | LineString,
distance: number,
options: {units?: Units} = {},
): Feature<Point> {
// Get Coords
const geom = getGeom(line);
const coords = geom.coordinates;
let travelled = 0;
for (let i = 0; i < coords.length; i++) {
if (distance >= travelled && i === coords.length - 1) { break;
} else if (travelled >= distance) {
const overshot = distance - travelled;
if (!overshot) { return point(coords[i]);
} else {
const direction = bearing(coords[i], coords[i - 1]) - 180;
const interpolated = destination(coords[i], overshot, direction, options);
return interpolated;
}
} else {
travelled += measureDistance(coords[i], coords[i + 1], options);
}
}
return point(coords[coords.length - 1]);
}
示例3: polygon
/**
* Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision.
*
* @name circle
* @param {Feature<Point>|number[]} center center point
* @param {number} radius radius of the circle
* @param {Object} [options={}] Optional parameters
* @param {number} [options.steps=64] number of steps
* @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians
* @param {Object} [options.properties={}] properties
* @returns {Feature<Polygon>} circle polygon
* @example
* var center = [-75.343, 39.984];
* var radius = 5;
* var options = {steps: 10, units: 'kilometers', properties: {foo: 'bar'}};
* var circle = turf.circle(center, radius, options);
*
* //addToMap
* var addToMap = [turf.point(center), circle]
*/
function circle<P = Properties>(center: number[] | Point | Feature<Point, P>, radius: number, options: {
steps?: number,
units?: Units,
properties?: P
} = {}): Feature<Polygon, P> {
// default params
const steps = options.steps || 64;
const properties: any = options.properties ? options.properties : (!Array.isArray(center) && center.type === 'Feature' && center.properties) ? center.properties : {};
// main
const coordinates = [];
for (let i = 0; i < steps; i++) {
coordinates.push(destination(center, radius, i * -360 / steps, options).geometry.coordinates);
}
coordinates.push(coordinates[0]);
return polygon([coordinates], properties);
}
示例4: getMeanLineString
function getMeanLineString(centroidOfLine: number[], angle: number, lenOfLine: number, isPlanar: boolean) {
if (isPlanar) {
const [averageX, averageY]: number[] = centroidOfLine;
let beginX: number;
let beginY: number;
let endX: number;
let endY: number;
const r: number = angle * Math.PI / 180;
const sin: number = Math.sin(r);
const cos: number = Math.cos(r);
beginX = averageX - lenOfLine / 2 * cos;
beginY = averageY - lenOfLine / 2 * sin;
endX = averageX + lenOfLine / 2 * cos;
endY = averageY + lenOfLine / 2 * sin;
return [
[beginX, beginY],
[endX, endY],
];
} else {
const end = destination(point(centroidOfLine), lenOfLine / 2, angle, { units: "meters" });
const begin = destination(point(centroidOfLine), -lenOfLine / 2, angle, { units: "meters" });
return [
getCoord(begin), getCoord(end),
];
}
}
示例5: along
/**
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
*
* @name along
* @param {Feature<LineString>} line input line
* @param {number} distance distance along the line
* @param {Object} [options] Optional parameters
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
* @returns {Feature<Point>} Point `distance` `units` along the line
* @example
* var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
* var options = {units: 'miles'};
*
* var along = turf.along(line, 200, options);
*
* //addToMap
* var addToMap = [along, line]
*/
function along(line: Feature<LineString>| LineString, distance: number, options: {
units?: Units
} = {}): Feature<Point> {
// Optional parameters
if (!isObject(options)) throw new Error('options is invalid');
// Validation
let coords;
if (line.type === 'Feature') coords = line.geometry.coordinates;
else if (line.type === 'LineString') coords = line.coordinates;
else throw new Error('input must be a LineString Feature or Geometry');
if (!isNumber(distance)) throw new Error('distance must be a number');
let travelled = 0;
for (let i = 0; i < coords.length; i++) {
if (distance >= travelled && i === coords.length - 1) break;
else if (travelled >= distance) {
const overshot = distance - travelled;
if (!overshot) return point(coords[i]);
else {
const direction = bearing(coords[i], coords[i - 1]) - 180;
const interpolated = destination(coords[i], overshot, direction, options);
return interpolated;
}
} else {
travelled += measureDistance(coords[i], coords[i + 1], options);
}
}
return point(coords[coords.length - 1]);
}
示例6: flattenEach
flattenEach(lines, function (line: any) {
const coords: any = getCoords(line);
for (let i = 0; i < coords.length - 1; i++) {
//start
const start = point(coords[i]);
start.properties.dist = distance(pt, start, options);
//stop
const stop = point(coords[i + 1]);
stop.properties.dist = distance(pt, stop, options);
// sectionLength
const sectionLength = distance(start, stop, options);
//perpendicular
const heightDistance = Math.max(start.properties.dist, stop.properties.dist);
const direction = bearing(start, stop);
const perpendicularPt1 = destination(pt, heightDistance, direction + 90, options);
const perpendicularPt2 = destination(pt, heightDistance, direction - 90, options);
const intersect = lineIntersects(
lineString([perpendicularPt1.geometry.coordinates, perpendicularPt2.geometry.coordinates]),
lineString([start.geometry.coordinates, stop.geometry.coordinates])
);
let intersectPt = null;
if (intersect.features.length > 0) {
intersectPt = intersect.features[0];
intersectPt.properties.dist = distance(pt, intersectPt, options);
intersectPt.properties.location = length + distance(start, intersectPt, options);
}
if (start.properties.dist < closestPt.properties.dist) {
closestPt = start;
closestPt.properties.index = i;
closestPt.properties.location = length;
}
if (stop.properties.dist < closestPt.properties.dist) {
closestPt = stop;
closestPt.properties.index = i + 1;
closestPt.properties.location = length + sectionLength;
}
if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) {
closestPt = intersectPt;
closestPt.properties.index = i;
}
// update length
length += sectionLength;
}
});