diff --git a/packages/turf-circle/index.ts b/packages/turf-circle/index.ts index a386728964..afa511f020 100644 --- a/packages/turf-circle/index.ts +++ b/packages/turf-circle/index.ts @@ -1,6 +1,6 @@ -import { GeoJsonProperties, Feature, Point, Polygon } from "geojson"; +import { GeoJsonProperties, Feature, Point, Polygon, BBox } from "geojson"; import destination from "@turf/destination"; -import { polygon, Units } from "@turf/helpers"; +import { Id, polygon, Units } from "@turf/helpers"; /** * Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision. @@ -12,6 +12,8 @@ import { polygon, Units } from "@turf/helpers"; * @param {number} [options.steps=64] number of steps * @param {string} [options.units='kilometers'] miles, kilometers, degrees, or radians * @param {Object} [options.properties={}] properties + * @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] to assign to the resulting circle Feature + * @param {string|number} [options.id] Identifier to assign to the resulting circle feature * @returns {Feature} circle polygon * @example * var center = [-75.343, 39.984]; @@ -29,27 +31,35 @@ function circle

( steps?: number; units?: Units; properties?: P; + bbox?: BBox; + id?: Id; } = {} ): Feature { // default params const steps = options.steps || 64; - const properties: any = options.properties - ? options.properties - : !Array.isArray(center) && center.type === "Feature" && center.properties - ? center.properties - : {}; + const stepAngle = -360 / steps; - // main + let properties = options.properties; + let bboxValue: BBox | undefined; + let idValue: Id | undefined; + + if (!Array.isArray(center) && center.type === "Feature") { + properties = properties || center.properties; + idValue = center.id; + } + + bboxValue = bboxValue || options.bbox; + idValue = idValue || options.id; + // Calculate circle coordinates const coordinates = []; for (let i = 0; i < steps; i++) { coordinates.push( - destination(center, radius, (i * -360) / steps, options).geometry - .coordinates + destination(center, radius, i * stepAngle, options).geometry.coordinates ); } coordinates.push(coordinates[0]); - return polygon([coordinates], properties); + return polygon([coordinates], properties, { bbox: bboxValue, id: idValue }); } export default circle; diff --git a/scripts/add-import-extensions.js b/scripts/add-import-extensions.js old mode 100755 new mode 100644 diff --git a/scripts/check-dependencies.js b/scripts/check-dependencies.js old mode 100755 new mode 100644 diff --git a/scripts/create-new-module b/scripts/create-new-module old mode 100755 new mode 100644 diff --git a/scripts/generate-readmes.ts b/scripts/generate-readmes.ts old mode 100755 new mode 100644 diff --git a/scripts/list-modules-to-markdown b/scripts/list-modules-to-markdown old mode 100755 new mode 100644 diff --git a/scripts/npm-publish-all b/scripts/npm-publish-all old mode 100755 new mode 100644 diff --git a/scripts/organization-make-public b/scripts/organization-make-public old mode 100755 new mode 100644 diff --git a/scripts/update-dependencies b/scripts/update-dependencies old mode 100755 new mode 100644