本文整理汇总了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);
}
开发者ID:Turbo87,项目名称:turf,代码行数:56,代码来源:index.ts
示例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]);
}
开发者ID:Turbo87,项目名称:turf,代码行数:43,代码来源:index.ts
示例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);
}
开发者ID:Turbo87,项目名称:turf,代码行数:38,代码来源:index.ts
示例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),
];
}
}
开发者ID:Turbo87,项目名称:turf,代码行数:26,代码来源:index.ts
示例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]);
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:48,代码来源:index.ts
示例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;
}
});
开发者ID:Turbo87,项目名称:turf,代码行数:47,代码来源:index.ts
注:本文中的@turf/destination.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论