@turf/transform-translate 7.1.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,6 +7,9 @@
7
7
  Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line
8
8
  on the provided direction angle.
9
9
 
10
+ Note that this moves the points of your shape individually and can therefore change
11
+ the overall shape. How noticable this is depends on the distance and the used projection.
12
+
10
13
  ### Parameters
11
14
 
12
15
  * `geojson` **([GeoJSON][1] | [GeometryCollection][2])** object to be translated
@@ -14,9 +17,9 @@ on the provided direction angle.
14
17
  * `direction` **[number][3]** of the motion; angle from North in decimal degrees, positive clockwise
15
18
  * `options` **[Object][4]** Optional parameters (optional, default `{}`)
16
19
 
17
- * `options.units` **Units** in which `distance` will be express; miles, kilometers, degrees, or radians (optional, default `'kilometers'`)
20
+ * `options.units` **Units** in which `distance` will be expressed; Supports all valid Turf [Units][5] (optional, default `'kilometers'`)
18
21
  * `options.zTranslation` **[number][3]** length of the vertical motion, same unit of distance (optional, default `0`)
19
- * `options.mutate` **[boolean][5]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`)
22
+ * `options.mutate` **[boolean][6]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`)
20
23
 
21
24
  ### Examples
22
25
 
@@ -39,7 +42,9 @@ Returns **([GeoJSON][1] | [GeometryCollection][2])** the translated GeoJSON obje
39
42
 
40
43
  [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
41
44
 
42
- [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
45
+ [5]: https://turfjs.org/docs/api/types/Units
46
+
47
+ [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
43
48
 
44
49
  <!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
45
50
 
@@ -6,28 +6,24 @@ var _clone = require('@turf/clone');
6
6
  var _rhumbdestination = require('@turf/rhumb-destination');
7
7
  function transformTranslate(geojson, distance, direction, options) {
8
8
  options = options || {};
9
- if (!_helpers.isObject.call(void 0, options))
10
- throw new Error("options is invalid");
9
+ if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
11
10
  var units = options.units;
12
11
  var zTranslation = options.zTranslation;
13
12
  var mutate = options.mutate;
14
- if (!geojson)
15
- throw new Error("geojson is required");
13
+ if (!geojson) throw new Error("geojson is required");
16
14
  if (distance === void 0 || distance === null || isNaN(distance))
17
15
  throw new Error("distance is required");
18
16
  if (zTranslation && typeof zTranslation !== "number" && isNaN(zTranslation))
19
17
  throw new Error("zTranslation is not a number");
20
18
  zTranslation = zTranslation !== void 0 ? zTranslation : 0;
21
- if (distance === 0 && zTranslation === 0)
22
- return geojson;
19
+ if (distance === 0 && zTranslation === 0) return geojson;
23
20
  if (direction === void 0 || direction === null || isNaN(direction))
24
21
  throw new Error("direction is required");
25
22
  if (distance < 0) {
26
23
  distance = -distance;
27
24
  direction = direction + 180;
28
25
  }
29
- if (mutate === false || mutate === void 0)
30
- geojson = _clone.clone.call(void 0, geojson);
26
+ if (mutate === false || mutate === void 0) geojson = _clone.clone.call(void 0, geojson);
31
27
  _meta.coordEach.call(void 0, geojson, function(pointCoords) {
32
28
  var newCoords = _invariant.getCoords.call(void 0,
33
29
  _rhumbdestination.rhumbDestination.call(void 0, pointCoords, distance, direction, { units })
@@ -39,9 +35,9 @@ function transformTranslate(geojson, distance, direction, options) {
39
35
  });
40
36
  return geojson;
41
37
  }
42
- var turf_transform_translate_default = transformTranslate;
38
+ var index_default = transformTranslate;
43
39
 
44
40
 
45
41
 
46
- exports.default = turf_transform_translate_default; exports.transformTranslate = transformTranslate;
42
+ exports.default = index_default; exports.transformTranslate = transformTranslate;
47
43
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,gBAAuB;AAChC,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,wBAAwB;AAuBjC,SAAS,mBACP,SACA,UACA,WACA,SAKG;AAEH,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,eAAe,QAAQ;AAC3B,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,aAAa,UAAa,aAAa,QAAQ,MAAM,QAAQ;AAC/D,UAAM,IAAI,MAAM,sBAAsB;AACxC,MAAI,gBAAgB,OAAO,iBAAiB,YAAY,MAAM,YAAY;AACxE,UAAM,IAAI,MAAM,8BAA8B;AAGhD,iBAAe,iBAAiB,SAAY,eAAe;AAC3D,MAAI,aAAa,KAAK,iBAAiB;AAAG,WAAO;AAEjD,MAAI,cAAc,UAAa,cAAc,QAAQ,MAAM,SAAS;AAClE,UAAM,IAAI,MAAM,uBAAuB;AAGzC,MAAI,WAAW,GAAG;AAChB,eAAW,CAAC;AACZ,gBAAY,YAAY;AAAA,EAC1B;AAGA,MAAI,WAAW,SAAS,WAAW;AAAW,cAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,QAAI,YAAY;AAAA,MACd,iBAAiB,aAAa,UAAU,WAAW,EAAE,MAAa,CAAC;AAAA,IACrE;AACA,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,QAAI,gBAAgB,YAAY,WAAW;AACzC,kBAAY,CAAC,KAAK;AAAA,EACtB,CAAC;AACD,SAAO;AACT;AAGA,IAAO,mCAAQ","sourcesContent":["import { GeoJSON, GeometryCollection } from \"geojson\";\nimport { coordEach } from \"@turf/meta\";\nimport { isObject, Units } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\nimport { clone } from \"@turf/clone\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\n\n/**\n * Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line\n * on the provided direction angle.\n *\n * @name transformTranslate\n * @param {GeoJSON|GeometryCollection} geojson object to be translated\n * @param {number} distance length of the motion; negative values determine motion in opposite direction\n * @param {number} direction of the motion; angle from North in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] in which `distance` will be express; miles, kilometers, degrees, or radians\n * @param {number} [options.zTranslation=0] length of the vertical motion, same unit of distance\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON|GeometryCollection} the translated GeoJSON object\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var translatedPoly = turf.transformTranslate(poly, 100, 35);\n *\n * //addToMap\n * var addToMap = [poly, translatedPoly];\n * translatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformTranslate<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n distance: number,\n direction: number,\n options?: {\n units?: Units;\n zTranslation?: number;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var units = options.units;\n var zTranslation = options.zTranslation;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (distance === undefined || distance === null || isNaN(distance))\n throw new Error(\"distance is required\");\n if (zTranslation && typeof zTranslation !== \"number\" && isNaN(zTranslation))\n throw new Error(\"zTranslation is not a number\");\n\n // Shortcut no-motion\n zTranslation = zTranslation !== undefined ? zTranslation : 0;\n if (distance === 0 && zTranslation === 0) return geojson;\n\n if (direction === undefined || direction === null || isNaN(direction))\n throw new Error(\"direction is required\");\n\n // Invert with negative distances\n if (distance < 0) {\n distance = -distance;\n direction = direction + 180;\n }\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Translate each coordinate\n coordEach(geojson, function (pointCoords) {\n var newCoords = getCoords(\n rhumbDestination(pointCoords, distance, direction, { units: units })\n );\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n if (zTranslation && pointCoords.length === 3)\n pointCoords[2] += zTranslation;\n });\n return geojson;\n}\n\nexport { transformTranslate };\nexport default transformTranslate;\n"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-transform-translate/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACCA,kCAA0B;AAC1B,wCAAgC;AAChC,4CAA0B;AAC1B,oCAAsB;AACtB,2DAAiC;AA0BjC,SAAS,kBAAA,CACP,OAAA,EACA,QAAA,EACA,SAAA,EACA,OAAA,EAKG;AAEH,EAAA,QAAA,EAAU,QAAA,GAAW,CAAC,CAAA;AACtB,EAAA,GAAA,CAAI,CAAC,+BAAA,OAAgB,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AAC5D,EAAA,IAAI,MAAA,EAAQ,OAAA,CAAQ,KAAA;AACpB,EAAA,IAAI,aAAA,EAAe,OAAA,CAAQ,YAAA;AAC3B,EAAA,IAAI,OAAA,EAAS,OAAA,CAAQ,MAAA;AAGrB,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS,MAAM,IAAI,KAAA,CAAM,qBAAqB,CAAA;AACnD,EAAA,GAAA,CAAI,SAAA,IAAa,KAAA,EAAA,GAAa,SAAA,IAAa,KAAA,GAAQ,KAAA,CAAM,QAAQ,CAAA;AAC/D,IAAA,MAAM,IAAI,KAAA,CAAM,sBAAsB,CAAA;AACxC,EAAA,GAAA,CAAI,aAAA,GAAgB,OAAO,aAAA,IAAiB,SAAA,GAAY,KAAA,CAAM,YAAY,CAAA;AACxE,IAAA,MAAM,IAAI,KAAA,CAAM,8BAA8B,CAAA;AAGhD,EAAA,aAAA,EAAe,aAAA,IAAiB,KAAA,EAAA,EAAY,aAAA,EAAe,CAAA;AAC3D,EAAA,GAAA,CAAI,SAAA,IAAa,EAAA,GAAK,aAAA,IAAiB,CAAA,EAAG,OAAO,OAAA;AAEjD,EAAA,GAAA,CAAI,UAAA,IAAc,KAAA,EAAA,GAAa,UAAA,IAAc,KAAA,GAAQ,KAAA,CAAM,SAAS,CAAA;AAClE,IAAA,MAAM,IAAI,KAAA,CAAM,uBAAuB,CAAA;AAGzC,EAAA,GAAA,CAAI,SAAA,EAAW,CAAA,EAAG;AAChB,IAAA,SAAA,EAAW,CAAC,QAAA;AACZ,IAAA,UAAA,EAAY,UAAA,EAAY,GAAA;AAAA,EAC1B;AAGA,EAAA,GAAA,CAAI,OAAA,IAAW,MAAA,GAAS,OAAA,IAAW,KAAA,CAAA,EAAW,QAAA,EAAU,0BAAA,OAAa,CAAA;AAGrE,EAAA,6BAAA,OAAU,EAAS,QAAA,CAAU,WAAA,EAAa;AACxC,IAAA,IAAI,UAAA,EAAY,kCAAA;AAAA,MACd,gDAAA,WAAiB,EAAa,QAAA,EAAU,SAAA,EAAW,EAAE,MAAa,CAAC;AAAA,IACrE,CAAA;AACA,IAAA,WAAA,CAAY,CAAC,EAAA,EAAI,SAAA,CAAU,CAAC,CAAA;AAC5B,IAAA,WAAA,CAAY,CAAC,EAAA,EAAI,SAAA,CAAU,CAAC,CAAA;AAC5B,IAAA,GAAA,CAAI,aAAA,GAAgB,WAAA,CAAY,OAAA,IAAW,CAAA;AACzC,MAAA,WAAA,CAAY,CAAC,EAAA,GAAK,YAAA;AAAA,EACtB,CAAC,CAAA;AACD,EAAA,OAAO,OAAA;AACT;AAGA,IAAO,cAAA,EAAQ,kBAAA;AD/Cf;AACE;AACA;AACF,iFAAC","file":"/home/runner/work/turf/turf/packages/turf-transform-translate/dist/cjs/index.cjs","sourcesContent":[null,"import { GeoJSON, GeometryCollection } from \"geojson\";\nimport { coordEach } from \"@turf/meta\";\nimport { isObject, Units } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\nimport { clone } from \"@turf/clone\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\n\n/**\n * Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line\n * on the provided direction angle.\n *\n * Note that this moves the points of your shape individually and can therefore change\n * the overall shape. How noticable this is depends on the distance and the used projection.\n *\n * @function\n * @param {GeoJSON|GeometryCollection} geojson object to be translated\n * @param {number} distance length of the motion; negative values determine motion in opposite direction\n * @param {number} direction of the motion; angle from North in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] in which `distance` will be expressed; Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {number} [options.zTranslation=0] length of the vertical motion, same unit of distance\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON|GeometryCollection} the translated GeoJSON object\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var translatedPoly = turf.transformTranslate(poly, 100, 35);\n *\n * //addToMap\n * var addToMap = [poly, translatedPoly];\n * translatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformTranslate<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n distance: number,\n direction: number,\n options?: {\n units?: Units;\n zTranslation?: number;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var units = options.units;\n var zTranslation = options.zTranslation;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (distance === undefined || distance === null || isNaN(distance))\n throw new Error(\"distance is required\");\n if (zTranslation && typeof zTranslation !== \"number\" && isNaN(zTranslation))\n throw new Error(\"zTranslation is not a number\");\n\n // Shortcut no-motion\n zTranslation = zTranslation !== undefined ? zTranslation : 0;\n if (distance === 0 && zTranslation === 0) return geojson;\n\n if (direction === undefined || direction === null || isNaN(direction))\n throw new Error(\"direction is required\");\n\n // Invert with negative distances\n if (distance < 0) {\n distance = -distance;\n direction = direction + 180;\n }\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Translate each coordinate\n coordEach(geojson, function (pointCoords) {\n var newCoords = getCoords(\n rhumbDestination(pointCoords, distance, direction, { units: units })\n );\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n if (zTranslation && pointCoords.length === 3)\n pointCoords[2] += zTranslation;\n });\n return geojson;\n}\n\nexport { transformTranslate };\nexport default transformTranslate;\n"]}
@@ -5,12 +5,15 @@ import { Units } from '@turf/helpers';
5
5
  * Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line
6
6
  * on the provided direction angle.
7
7
  *
8
- * @name transformTranslate
8
+ * Note that this moves the points of your shape individually and can therefore change
9
+ * the overall shape. How noticable this is depends on the distance and the used projection.
10
+ *
11
+ * @function
9
12
  * @param {GeoJSON|GeometryCollection} geojson object to be translated
10
13
  * @param {number} distance length of the motion; negative values determine motion in opposite direction
11
14
  * @param {number} direction of the motion; angle from North in decimal degrees, positive clockwise
12
15
  * @param {Object} [options={}] Optional parameters
13
- * @param {Units} [options.units='kilometers'] in which `distance` will be express; miles, kilometers, degrees, or radians
16
+ * @param {Units} [options.units='kilometers'] in which `distance` will be expressed; Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
14
17
  * @param {number} [options.zTranslation=0] length of the vertical motion, same unit of distance
15
18
  * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
16
19
  * @returns {GeoJSON|GeometryCollection} the translated GeoJSON object
@@ -5,12 +5,15 @@ import { Units } from '@turf/helpers';
5
5
  * Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line
6
6
  * on the provided direction angle.
7
7
  *
8
- * @name transformTranslate
8
+ * Note that this moves the points of your shape individually and can therefore change
9
+ * the overall shape. How noticable this is depends on the distance and the used projection.
10
+ *
11
+ * @function
9
12
  * @param {GeoJSON|GeometryCollection} geojson object to be translated
10
13
  * @param {number} distance length of the motion; negative values determine motion in opposite direction
11
14
  * @param {number} direction of the motion; angle from North in decimal degrees, positive clockwise
12
15
  * @param {Object} [options={}] Optional parameters
13
- * @param {Units} [options.units='kilometers'] in which `distance` will be express; miles, kilometers, degrees, or radians
16
+ * @param {Units} [options.units='kilometers'] in which `distance` will be expressed; Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}
14
17
  * @param {number} [options.zTranslation=0] length of the vertical motion, same unit of distance
15
18
  * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
16
19
  * @returns {GeoJSON|GeometryCollection} the translated GeoJSON object
package/dist/esm/index.js CHANGED
@@ -6,28 +6,24 @@ import { clone } from "@turf/clone";
6
6
  import { rhumbDestination } from "@turf/rhumb-destination";
7
7
  function transformTranslate(geojson, distance, direction, options) {
8
8
  options = options || {};
9
- if (!isObject(options))
10
- throw new Error("options is invalid");
9
+ if (!isObject(options)) throw new Error("options is invalid");
11
10
  var units = options.units;
12
11
  var zTranslation = options.zTranslation;
13
12
  var mutate = options.mutate;
14
- if (!geojson)
15
- throw new Error("geojson is required");
13
+ if (!geojson) throw new Error("geojson is required");
16
14
  if (distance === void 0 || distance === null || isNaN(distance))
17
15
  throw new Error("distance is required");
18
16
  if (zTranslation && typeof zTranslation !== "number" && isNaN(zTranslation))
19
17
  throw new Error("zTranslation is not a number");
20
18
  zTranslation = zTranslation !== void 0 ? zTranslation : 0;
21
- if (distance === 0 && zTranslation === 0)
22
- return geojson;
19
+ if (distance === 0 && zTranslation === 0) return geojson;
23
20
  if (direction === void 0 || direction === null || isNaN(direction))
24
21
  throw new Error("direction is required");
25
22
  if (distance < 0) {
26
23
  distance = -distance;
27
24
  direction = direction + 180;
28
25
  }
29
- if (mutate === false || mutate === void 0)
30
- geojson = clone(geojson);
26
+ if (mutate === false || mutate === void 0) geojson = clone(geojson);
31
27
  coordEach(geojson, function(pointCoords) {
32
28
  var newCoords = getCoords(
33
29
  rhumbDestination(pointCoords, distance, direction, { units })
@@ -39,9 +35,9 @@ function transformTranslate(geojson, distance, direction, options) {
39
35
  });
40
36
  return geojson;
41
37
  }
42
- var turf_transform_translate_default = transformTranslate;
38
+ var index_default = transformTranslate;
43
39
  export {
44
- turf_transform_translate_default as default,
40
+ index_default as default,
45
41
  transformTranslate
46
42
  };
47
43
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { GeoJSON, GeometryCollection } from \"geojson\";\nimport { coordEach } from \"@turf/meta\";\nimport { isObject, Units } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\nimport { clone } from \"@turf/clone\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\n\n/**\n * Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line\n * on the provided direction angle.\n *\n * @name transformTranslate\n * @param {GeoJSON|GeometryCollection} geojson object to be translated\n * @param {number} distance length of the motion; negative values determine motion in opposite direction\n * @param {number} direction of the motion; angle from North in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] in which `distance` will be express; miles, kilometers, degrees, or radians\n * @param {number} [options.zTranslation=0] length of the vertical motion, same unit of distance\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON|GeometryCollection} the translated GeoJSON object\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var translatedPoly = turf.transformTranslate(poly, 100, 35);\n *\n * //addToMap\n * var addToMap = [poly, translatedPoly];\n * translatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformTranslate<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n distance: number,\n direction: number,\n options?: {\n units?: Units;\n zTranslation?: number;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var units = options.units;\n var zTranslation = options.zTranslation;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (distance === undefined || distance === null || isNaN(distance))\n throw new Error(\"distance is required\");\n if (zTranslation && typeof zTranslation !== \"number\" && isNaN(zTranslation))\n throw new Error(\"zTranslation is not a number\");\n\n // Shortcut no-motion\n zTranslation = zTranslation !== undefined ? zTranslation : 0;\n if (distance === 0 && zTranslation === 0) return geojson;\n\n if (direction === undefined || direction === null || isNaN(direction))\n throw new Error(\"direction is required\");\n\n // Invert with negative distances\n if (distance < 0) {\n distance = -distance;\n direction = direction + 180;\n }\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Translate each coordinate\n coordEach(geojson, function (pointCoords) {\n var newCoords = getCoords(\n rhumbDestination(pointCoords, distance, direction, { units: units })\n );\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n if (zTranslation && pointCoords.length === 3)\n pointCoords[2] += zTranslation;\n });\n return geojson;\n}\n\nexport { transformTranslate };\nexport default transformTranslate;\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,gBAAuB;AAChC,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,wBAAwB;AAuBjC,SAAS,mBACP,SACA,UACA,WACA,SAKG;AAEH,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,eAAe,QAAQ;AAC3B,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,aAAa,UAAa,aAAa,QAAQ,MAAM,QAAQ;AAC/D,UAAM,IAAI,MAAM,sBAAsB;AACxC,MAAI,gBAAgB,OAAO,iBAAiB,YAAY,MAAM,YAAY;AACxE,UAAM,IAAI,MAAM,8BAA8B;AAGhD,iBAAe,iBAAiB,SAAY,eAAe;AAC3D,MAAI,aAAa,KAAK,iBAAiB;AAAG,WAAO;AAEjD,MAAI,cAAc,UAAa,cAAc,QAAQ,MAAM,SAAS;AAClE,UAAM,IAAI,MAAM,uBAAuB;AAGzC,MAAI,WAAW,GAAG;AAChB,eAAW,CAAC;AACZ,gBAAY,YAAY;AAAA,EAC1B;AAGA,MAAI,WAAW,SAAS,WAAW;AAAW,cAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,QAAI,YAAY;AAAA,MACd,iBAAiB,aAAa,UAAU,WAAW,EAAE,MAAa,CAAC;AAAA,IACrE;AACA,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,QAAI,gBAAgB,YAAY,WAAW;AACzC,kBAAY,CAAC,KAAK;AAAA,EACtB,CAAC;AACD,SAAO;AACT;AAGA,IAAO,mCAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { GeoJSON, GeometryCollection } from \"geojson\";\nimport { coordEach } from \"@turf/meta\";\nimport { isObject, Units } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\nimport { clone } from \"@turf/clone\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\n\n/**\n * Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line\n * on the provided direction angle.\n *\n * Note that this moves the points of your shape individually and can therefore change\n * the overall shape. How noticable this is depends on the distance and the used projection.\n *\n * @function\n * @param {GeoJSON|GeometryCollection} geojson object to be translated\n * @param {number} distance length of the motion; negative values determine motion in opposite direction\n * @param {number} direction of the motion; angle from North in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Units} [options.units='kilometers'] in which `distance` will be expressed; Supports all valid Turf {@link https://turfjs.org/docs/api/types/Units Units}\n * @param {number} [options.zTranslation=0] length of the vertical motion, same unit of distance\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON|GeometryCollection} the translated GeoJSON object\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var translatedPoly = turf.transformTranslate(poly, 100, 35);\n *\n * //addToMap\n * var addToMap = [poly, translatedPoly];\n * translatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformTranslate<T extends GeoJSON | GeometryCollection>(\n geojson: T,\n distance: number,\n direction: number,\n options?: {\n units?: Units;\n zTranslation?: number;\n mutate?: boolean;\n }\n): T {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var units = options.units;\n var zTranslation = options.zTranslation;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (distance === undefined || distance === null || isNaN(distance))\n throw new Error(\"distance is required\");\n if (zTranslation && typeof zTranslation !== \"number\" && isNaN(zTranslation))\n throw new Error(\"zTranslation is not a number\");\n\n // Shortcut no-motion\n zTranslation = zTranslation !== undefined ? zTranslation : 0;\n if (distance === 0 && zTranslation === 0) return geojson;\n\n if (direction === undefined || direction === null || isNaN(direction))\n throw new Error(\"direction is required\");\n\n // Invert with negative distances\n if (distance < 0) {\n distance = -distance;\n direction = direction + 180;\n }\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Translate each coordinate\n coordEach(geojson, function (pointCoords) {\n var newCoords = getCoords(\n rhumbDestination(pointCoords, distance, direction, { units: units })\n );\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n if (zTranslation && pointCoords.length === 3)\n pointCoords[2] += zTranslation;\n });\n return geojson;\n}\n\nexport { transformTranslate };\nexport default transformTranslate;\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,gBAAuB;AAChC,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,wBAAwB;AA0BjC,SAAS,mBACP,SACA,UACA,WACA,SAKG;AAEH,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO,EAAG,OAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,eAAe,QAAQ;AAC3B,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,aAAa,UAAa,aAAa,QAAQ,MAAM,QAAQ;AAC/D,UAAM,IAAI,MAAM,sBAAsB;AACxC,MAAI,gBAAgB,OAAO,iBAAiB,YAAY,MAAM,YAAY;AACxE,UAAM,IAAI,MAAM,8BAA8B;AAGhD,iBAAe,iBAAiB,SAAY,eAAe;AAC3D,MAAI,aAAa,KAAK,iBAAiB,EAAG,QAAO;AAEjD,MAAI,cAAc,UAAa,cAAc,QAAQ,MAAM,SAAS;AAClE,UAAM,IAAI,MAAM,uBAAuB;AAGzC,MAAI,WAAW,GAAG;AAChB,eAAW,CAAC;AACZ,gBAAY,YAAY;AAAA,EAC1B;AAGA,MAAI,WAAW,SAAS,WAAW,OAAW,WAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,QAAI,YAAY;AAAA,MACd,iBAAiB,aAAa,UAAU,WAAW,EAAE,MAAa,CAAC;AAAA,IACrE;AACA,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,QAAI,gBAAgB,YAAY,WAAW;AACzC,kBAAY,CAAC,KAAK;AAAA,EACtB,CAAC;AACD,SAAO;AACT;AAGA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/transform-translate",
3
- "version": "7.1.0",
4
- "description": "turf transform-translate module",
3
+ "version": "7.3.0",
4
+ "description": "Moves a shape or location in a specific direction.",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
7
7
  "Stefano Borghi <@stebogit>",
@@ -58,26 +58,26 @@
58
58
  "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
59
59
  },
60
60
  "devDependencies": {
61
- "@turf/truncate": "^7.1.0",
61
+ "@turf/truncate": "7.3.0",
62
62
  "@types/benchmark": "^2.1.5",
63
- "@types/tape": "^4.2.32",
63
+ "@types/tape": "^5.8.1",
64
64
  "benchmark": "^2.1.4",
65
65
  "load-json-file": "^7.0.1",
66
66
  "npm-run-all": "^4.1.5",
67
- "tape": "^5.7.2",
68
- "tsup": "^8.0.1",
69
- "tsx": "^4.6.2",
70
- "typescript": "^5.2.2",
71
- "write-json-file": "^5.0.0"
67
+ "tape": "^5.9.0",
68
+ "tsup": "^8.4.0",
69
+ "tsx": "^4.19.4",
70
+ "typescript": "^5.8.3",
71
+ "write-json-file": "^6.0.0"
72
72
  },
73
73
  "dependencies": {
74
- "@turf/clone": "^7.1.0",
75
- "@turf/helpers": "^7.1.0",
76
- "@turf/invariant": "^7.1.0",
77
- "@turf/meta": "^7.1.0",
78
- "@turf/rhumb-destination": "^7.1.0",
74
+ "@turf/clone": "7.3.0",
75
+ "@turf/helpers": "7.3.0",
76
+ "@turf/invariant": "7.3.0",
77
+ "@turf/meta": "7.3.0",
78
+ "@turf/rhumb-destination": "7.3.0",
79
79
  "@types/geojson": "^7946.0.10",
80
- "tslib": "^2.6.2"
80
+ "tslib": "^2.8.1"
81
81
  },
82
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
82
+ "gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
83
83
  }