@turf/transform-translate 7.2.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 +8 -3
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -1
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +14 -14
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
|
|
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][
|
|
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://
|
|
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
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -35,9 +35,9 @@ function transformTranslate(geojson, distance, direction, options) {
|
|
|
35
35
|
});
|
|
36
36
|
return geojson;
|
|
37
37
|
}
|
|
38
|
-
var
|
|
38
|
+
var index_default = transformTranslate;
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
exports.default =
|
|
42
|
+
exports.default = index_default; exports.transformTranslate = transformTranslate;
|
|
43
43
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,E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AAA,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"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -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
|
+
* 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
|
+
*
|
|
8
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
|
|
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.d.ts
CHANGED
|
@@ -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
|
+
* 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
|
+
*
|
|
8
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
|
|
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
|
@@ -35,9 +35,9 @@ function transformTranslate(geojson, distance, direction, options) {
|
|
|
35
35
|
});
|
|
36
36
|
return geojson;
|
|
37
37
|
}
|
|
38
|
-
var
|
|
38
|
+
var index_default = transformTranslate;
|
|
39
39
|
export {
|
|
40
|
-
|
|
40
|
+
index_default as default,
|
|
41
41
|
transformTranslate
|
|
42
42
|
};
|
|
43
43
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -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 * @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
|
|
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;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
+
"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": "
|
|
61
|
+
"@turf/truncate": "7.3.0",
|
|
62
62
|
"@types/benchmark": "^2.1.5",
|
|
63
|
-
"@types/tape": "^
|
|
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
67
|
"tape": "^5.9.0",
|
|
68
|
-
"tsup": "^8.
|
|
69
|
-
"tsx": "^4.19.
|
|
70
|
-
"typescript": "^5.
|
|
71
|
-
"write-json-file": "^
|
|
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": "
|
|
75
|
-
"@turf/helpers": "
|
|
76
|
-
"@turf/invariant": "
|
|
77
|
-
"@turf/meta": "
|
|
78
|
-
"@turf/rhumb-destination": "
|
|
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
80
|
"tslib": "^2.8.1"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
|
|
83
83
|
}
|