@turf/transform-translate 7.0.0-alpha.1 → 7.0.0-alpha.111
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 +4 -9
- package/dist/cjs/index.cjs +51 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +17 -0
- package/dist/esm/index.d.mts +17 -0
- package/dist/esm/index.mjs +51 -0
- package/dist/esm/index.mjs.map +1 -0
- package/index.d.ts +4 -1
- package/package.json +32 -26
- package/dist/es/index.js +0 -72
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -80
package/README.md
CHANGED
|
@@ -41,26 +41,21 @@ Returns **[GeoJSON][1]** the translated GeoJSON object
|
|
|
41
41
|
|
|
42
42
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
43
43
|
|
|
44
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
45
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
46
|
-
./scripts/generate-readmes in the turf project. -->
|
|
44
|
+
<!-- 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. -->
|
|
47
45
|
|
|
48
46
|
---
|
|
49
47
|
|
|
50
|
-
This module is part of the [Turfjs project](
|
|
51
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
52
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
53
|
-
PRs and issues.
|
|
48
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
54
49
|
|
|
55
50
|
### Installation
|
|
56
51
|
|
|
57
|
-
Install this module individually:
|
|
52
|
+
Install this single module individually:
|
|
58
53
|
|
|
59
54
|
```sh
|
|
60
55
|
$ npm install @turf/transform-translate
|
|
61
56
|
```
|
|
62
57
|
|
|
63
|
-
Or install the
|
|
58
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
64
59
|
|
|
65
60
|
```sh
|
|
66
61
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.js
|
|
5
|
+
var _meta = require('@turf/meta');
|
|
6
|
+
var _helpers = require('@turf/helpers');
|
|
7
|
+
var _invariant = require('@turf/invariant');
|
|
8
|
+
var _clone = require('@turf/clone');
|
|
9
|
+
var _rhumbdestination = require('@turf/rhumb-destination');
|
|
10
|
+
function transformTranslate(geojson, distance, direction, options) {
|
|
11
|
+
options = options || {};
|
|
12
|
+
if (!_helpers.isObject.call(void 0, options))
|
|
13
|
+
throw new Error("options is invalid");
|
|
14
|
+
var units = options.units;
|
|
15
|
+
var zTranslation = options.zTranslation;
|
|
16
|
+
var mutate = options.mutate;
|
|
17
|
+
if (!geojson)
|
|
18
|
+
throw new Error("geojson is required");
|
|
19
|
+
if (distance === void 0 || distance === null || isNaN(distance))
|
|
20
|
+
throw new Error("distance is required");
|
|
21
|
+
if (zTranslation && typeof zTranslation !== "number" && isNaN(zTranslation))
|
|
22
|
+
throw new Error("zTranslation is not a number");
|
|
23
|
+
zTranslation = zTranslation !== void 0 ? zTranslation : 0;
|
|
24
|
+
if (distance === 0 && zTranslation === 0)
|
|
25
|
+
return geojson;
|
|
26
|
+
if (direction === void 0 || direction === null || isNaN(direction))
|
|
27
|
+
throw new Error("direction is required");
|
|
28
|
+
if (distance < 0) {
|
|
29
|
+
distance = -distance;
|
|
30
|
+
direction = direction + 180;
|
|
31
|
+
}
|
|
32
|
+
if (mutate === false || mutate === void 0)
|
|
33
|
+
geojson = _clone.clone.call(void 0, geojson);
|
|
34
|
+
_meta.coordEach.call(void 0, geojson, function(pointCoords) {
|
|
35
|
+
var newCoords = _invariant.getCoords.call(void 0,
|
|
36
|
+
_rhumbdestination.rhumbDestination.call(void 0, pointCoords, distance, direction, { units })
|
|
37
|
+
);
|
|
38
|
+
pointCoords[0] = newCoords[0];
|
|
39
|
+
pointCoords[1] = newCoords[1];
|
|
40
|
+
if (zTranslation && pointCoords.length === 3)
|
|
41
|
+
pointCoords[2] += zTranslation;
|
|
42
|
+
});
|
|
43
|
+
return geojson;
|
|
44
|
+
}
|
|
45
|
+
__name(transformTranslate, "transformTranslate");
|
|
46
|
+
var turf_transform_translate_default = transformTranslate;
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
exports.default = turf_transform_translate_default; exports.transformTranslate = transformTranslate;
|
|
51
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"names":[],"mappings":";;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,wBAAwB;AAuBjC,SAAS,mBAAmB,SAAS,UAAU,WAAW,SAAS;AAEjE,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;AA1CS;AA6CT,IAAO,mCAAQ","sourcesContent":["import { coordEach } from \"@turf/meta\";\nimport { isObject } 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} 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 {string} [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} 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(geojson, distance, direction, options) {\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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AllGeoJSON, Units } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* http://turfjs.org/docs/#transform-translate
|
|
5
|
+
*/
|
|
6
|
+
declare function transformTranslate<T extends AllGeoJSON>(
|
|
7
|
+
geojson: T,
|
|
8
|
+
distance: number,
|
|
9
|
+
direction: number,
|
|
10
|
+
options?: {
|
|
11
|
+
units?: Units;
|
|
12
|
+
zTranslation?: number;
|
|
13
|
+
mutate?: boolean;
|
|
14
|
+
}
|
|
15
|
+
): T;
|
|
16
|
+
|
|
17
|
+
export { transformTranslate as default, transformTranslate };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AllGeoJSON, Units } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* http://turfjs.org/docs/#transform-translate
|
|
5
|
+
*/
|
|
6
|
+
declare function transformTranslate<T extends AllGeoJSON>(
|
|
7
|
+
geojson: T,
|
|
8
|
+
distance: number,
|
|
9
|
+
direction: number,
|
|
10
|
+
options?: {
|
|
11
|
+
units?: Units;
|
|
12
|
+
zTranslation?: number;
|
|
13
|
+
mutate?: boolean;
|
|
14
|
+
}
|
|
15
|
+
): T;
|
|
16
|
+
|
|
17
|
+
export { transformTranslate as default, transformTranslate };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.js
|
|
5
|
+
import { coordEach } from "@turf/meta";
|
|
6
|
+
import { isObject } from "@turf/helpers";
|
|
7
|
+
import { getCoords } from "@turf/invariant";
|
|
8
|
+
import { clone } from "@turf/clone";
|
|
9
|
+
import { rhumbDestination } from "@turf/rhumb-destination";
|
|
10
|
+
function transformTranslate(geojson, distance, direction, options) {
|
|
11
|
+
options = options || {};
|
|
12
|
+
if (!isObject(options))
|
|
13
|
+
throw new Error("options is invalid");
|
|
14
|
+
var units = options.units;
|
|
15
|
+
var zTranslation = options.zTranslation;
|
|
16
|
+
var mutate = options.mutate;
|
|
17
|
+
if (!geojson)
|
|
18
|
+
throw new Error("geojson is required");
|
|
19
|
+
if (distance === void 0 || distance === null || isNaN(distance))
|
|
20
|
+
throw new Error("distance is required");
|
|
21
|
+
if (zTranslation && typeof zTranslation !== "number" && isNaN(zTranslation))
|
|
22
|
+
throw new Error("zTranslation is not a number");
|
|
23
|
+
zTranslation = zTranslation !== void 0 ? zTranslation : 0;
|
|
24
|
+
if (distance === 0 && zTranslation === 0)
|
|
25
|
+
return geojson;
|
|
26
|
+
if (direction === void 0 || direction === null || isNaN(direction))
|
|
27
|
+
throw new Error("direction is required");
|
|
28
|
+
if (distance < 0) {
|
|
29
|
+
distance = -distance;
|
|
30
|
+
direction = direction + 180;
|
|
31
|
+
}
|
|
32
|
+
if (mutate === false || mutate === void 0)
|
|
33
|
+
geojson = clone(geojson);
|
|
34
|
+
coordEach(geojson, function(pointCoords) {
|
|
35
|
+
var newCoords = getCoords(
|
|
36
|
+
rhumbDestination(pointCoords, distance, direction, { units })
|
|
37
|
+
);
|
|
38
|
+
pointCoords[0] = newCoords[0];
|
|
39
|
+
pointCoords[1] = newCoords[1];
|
|
40
|
+
if (zTranslation && pointCoords.length === 3)
|
|
41
|
+
pointCoords[2] += zTranslation;
|
|
42
|
+
});
|
|
43
|
+
return geojson;
|
|
44
|
+
}
|
|
45
|
+
__name(transformTranslate, "transformTranslate");
|
|
46
|
+
var turf_transform_translate_default = transformTranslate;
|
|
47
|
+
export {
|
|
48
|
+
turf_transform_translate_default as default,
|
|
49
|
+
transformTranslate
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"sourcesContent":["import { coordEach } from \"@turf/meta\";\nimport { isObject } 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} 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 {string} [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} 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(geojson, distance, direction, options) {\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":";;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,wBAAwB;AAuBjC,SAAS,mBAAmB,SAAS,UAAU,WAAW,SAAS;AAEjE,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;AA1CS;AA6CT,IAAO,mCAAQ;","names":[]}
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AllGeoJSON, Units } from "@turf/helpers";
|
|
|
3
3
|
/**
|
|
4
4
|
* http://turfjs.org/docs/#transform-translate
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
declare function transformTranslate<T extends AllGeoJSON>(
|
|
7
7
|
geojson: T,
|
|
8
8
|
distance: number,
|
|
9
9
|
direction: number,
|
|
@@ -13,3 +13,6 @@ export default function transformTranslate<T extends AllGeoJSON>(
|
|
|
13
13
|
mutate?: boolean;
|
|
14
14
|
}
|
|
15
15
|
): T;
|
|
16
|
+
|
|
17
|
+
export { transformTranslate };
|
|
18
|
+
export default transformTranslate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/transform-translate",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.111+08576cb50",
|
|
4
4
|
"description": "turf transform-translate module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -28,46 +28,52 @@
|
|
|
28
28
|
"move",
|
|
29
29
|
"shift"
|
|
30
30
|
],
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"type": "commonjs",
|
|
32
|
+
"main": "dist/cjs/index.cjs",
|
|
33
|
+
"module": "dist/esm/index.mjs",
|
|
34
|
+
"types": "dist/cjs/index.d.ts",
|
|
33
35
|
"exports": {
|
|
34
36
|
"./package.json": "./package.json",
|
|
35
37
|
".": {
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/esm/index.d.mts",
|
|
40
|
+
"default": "./dist/esm/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/cjs/index.d.ts",
|
|
44
|
+
"default": "./dist/cjs/index.cjs"
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
},
|
|
41
|
-
"types": "index.d.ts",
|
|
42
48
|
"sideEffects": false,
|
|
43
49
|
"files": [
|
|
44
50
|
"dist",
|
|
45
51
|
"index.d.ts"
|
|
46
52
|
],
|
|
47
53
|
"scripts": {
|
|
48
|
-
"bench": "tsx bench.
|
|
49
|
-
"build": "
|
|
50
|
-
"docs": "tsx ../../scripts/generate-readmes",
|
|
51
|
-
"test": "npm-run-all test:*",
|
|
52
|
-
"test:tape": "tsx test.
|
|
54
|
+
"bench": "tsx bench.ts",
|
|
55
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
56
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
57
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
58
|
+
"test:tape": "tsx test.ts",
|
|
53
59
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
54
60
|
},
|
|
55
61
|
"devDependencies": {
|
|
56
|
-
"@turf/truncate": "^7.0.0-alpha.
|
|
57
|
-
"benchmark": "
|
|
58
|
-
"load-json-file": "
|
|
59
|
-
"npm-run-all": "
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"tsx": "
|
|
63
|
-
"write-json-file": "
|
|
62
|
+
"@turf/truncate": "^7.0.0-alpha.111+08576cb50",
|
|
63
|
+
"benchmark": "^2.1.4",
|
|
64
|
+
"load-json-file": "^7.0.1",
|
|
65
|
+
"npm-run-all": "^4.1.5",
|
|
66
|
+
"tape": "^5.7.2",
|
|
67
|
+
"tsup": "^8.0.1",
|
|
68
|
+
"tsx": "^4.6.2",
|
|
69
|
+
"write-json-file": "^5.0.0"
|
|
64
70
|
},
|
|
65
71
|
"dependencies": {
|
|
66
|
-
"@turf/clone": "^7.0.0-alpha.
|
|
67
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
68
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
69
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
70
|
-
"@turf/rhumb-destination": "^7.0.0-alpha.
|
|
72
|
+
"@turf/clone": "^7.0.0-alpha.111+08576cb50",
|
|
73
|
+
"@turf/helpers": "^7.0.0-alpha.111+08576cb50",
|
|
74
|
+
"@turf/invariant": "^7.0.0-alpha.111+08576cb50",
|
|
75
|
+
"@turf/meta": "^7.0.0-alpha.111+08576cb50",
|
|
76
|
+
"@turf/rhumb-destination": "^7.0.0-alpha.111+08576cb50"
|
|
71
77
|
},
|
|
72
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "08576cb50376e0199aea02dbd887e3af83672246"
|
|
73
79
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { coordEach } from '@turf/meta';
|
|
2
|
-
import { isObject } from '@turf/helpers';
|
|
3
|
-
import { getCoords } from '@turf/invariant';
|
|
4
|
-
import clone from '@turf/clone';
|
|
5
|
-
import rhumbDestination from '@turf/rhumb-destination';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line
|
|
9
|
-
* on the provided direction angle.
|
|
10
|
-
*
|
|
11
|
-
* @name transformTranslate
|
|
12
|
-
* @param {GeoJSON} geojson object to be translated
|
|
13
|
-
* @param {number} distance length of the motion; negative values determine motion in opposite direction
|
|
14
|
-
* @param {number} direction of the motion; angle from North in decimal degrees, positive clockwise
|
|
15
|
-
* @param {Object} [options={}] Optional parameters
|
|
16
|
-
* @param {string} [options.units='kilometers'] in which `distance` will be express; miles, kilometers, degrees, or radians
|
|
17
|
-
* @param {number} [options.zTranslation=0] length of the vertical motion, same unit of distance
|
|
18
|
-
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
19
|
-
* @returns {GeoJSON} the translated GeoJSON object
|
|
20
|
-
* @example
|
|
21
|
-
* var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
|
|
22
|
-
* var translatedPoly = turf.transformTranslate(poly, 100, 35);
|
|
23
|
-
*
|
|
24
|
-
* //addToMap
|
|
25
|
-
* var addToMap = [poly, translatedPoly];
|
|
26
|
-
* translatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
|
|
27
|
-
*/
|
|
28
|
-
function transformTranslate(geojson, distance, direction, options) {
|
|
29
|
-
// Optional parameters
|
|
30
|
-
options = options || {};
|
|
31
|
-
if (!isObject(options)) throw new Error("options is invalid");
|
|
32
|
-
var units = options.units;
|
|
33
|
-
var zTranslation = options.zTranslation;
|
|
34
|
-
var mutate = options.mutate;
|
|
35
|
-
|
|
36
|
-
// Input validation
|
|
37
|
-
if (!geojson) throw new Error("geojson is required");
|
|
38
|
-
if (distance === undefined || distance === null || isNaN(distance))
|
|
39
|
-
throw new Error("distance is required");
|
|
40
|
-
if (zTranslation && typeof zTranslation !== "number" && isNaN(zTranslation))
|
|
41
|
-
throw new Error("zTranslation is not a number");
|
|
42
|
-
|
|
43
|
-
// Shortcut no-motion
|
|
44
|
-
zTranslation = zTranslation !== undefined ? zTranslation : 0;
|
|
45
|
-
if (distance === 0 && zTranslation === 0) return geojson;
|
|
46
|
-
|
|
47
|
-
if (direction === undefined || direction === null || isNaN(direction))
|
|
48
|
-
throw new Error("direction is required");
|
|
49
|
-
|
|
50
|
-
// Invert with negative distances
|
|
51
|
-
if (distance < 0) {
|
|
52
|
-
distance = -distance;
|
|
53
|
-
direction = direction + 180;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Clone geojson to avoid side effects
|
|
57
|
-
if (mutate === false || mutate === undefined) geojson = clone(geojson);
|
|
58
|
-
|
|
59
|
-
// Translate each coordinate
|
|
60
|
-
coordEach(geojson, function (pointCoords) {
|
|
61
|
-
var newCoords = getCoords(
|
|
62
|
-
rhumbDestination(pointCoords, distance, direction, { units: units })
|
|
63
|
-
);
|
|
64
|
-
pointCoords[0] = newCoords[0];
|
|
65
|
-
pointCoords[1] = newCoords[1];
|
|
66
|
-
if (zTranslation && pointCoords.length === 3)
|
|
67
|
-
pointCoords[2] += zTranslation;
|
|
68
|
-
});
|
|
69
|
-
return geojson;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export default transformTranslate;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var meta = require('@turf/meta');
|
|
4
|
-
var helpers = require('@turf/helpers');
|
|
5
|
-
var invariant = require('@turf/invariant');
|
|
6
|
-
var clone = require('@turf/clone');
|
|
7
|
-
var rhumbDestination = require('@turf/rhumb-destination');
|
|
8
|
-
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
|
|
12
|
-
var rhumbDestination__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDestination);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line
|
|
16
|
-
* on the provided direction angle.
|
|
17
|
-
*
|
|
18
|
-
* @name transformTranslate
|
|
19
|
-
* @param {GeoJSON} geojson object to be translated
|
|
20
|
-
* @param {number} distance length of the motion; negative values determine motion in opposite direction
|
|
21
|
-
* @param {number} direction of the motion; angle from North in decimal degrees, positive clockwise
|
|
22
|
-
* @param {Object} [options={}] Optional parameters
|
|
23
|
-
* @param {string} [options.units='kilometers'] in which `distance` will be express; miles, kilometers, degrees, or radians
|
|
24
|
-
* @param {number} [options.zTranslation=0] length of the vertical motion, same unit of distance
|
|
25
|
-
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
26
|
-
* @returns {GeoJSON} the translated GeoJSON object
|
|
27
|
-
* @example
|
|
28
|
-
* var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
|
|
29
|
-
* var translatedPoly = turf.transformTranslate(poly, 100, 35);
|
|
30
|
-
*
|
|
31
|
-
* //addToMap
|
|
32
|
-
* var addToMap = [poly, translatedPoly];
|
|
33
|
-
* translatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
|
|
34
|
-
*/
|
|
35
|
-
function transformTranslate(geojson, distance, direction, options) {
|
|
36
|
-
// Optional parameters
|
|
37
|
-
options = options || {};
|
|
38
|
-
if (!helpers.isObject(options)) throw new Error("options is invalid");
|
|
39
|
-
var units = options.units;
|
|
40
|
-
var zTranslation = options.zTranslation;
|
|
41
|
-
var mutate = options.mutate;
|
|
42
|
-
|
|
43
|
-
// Input validation
|
|
44
|
-
if (!geojson) throw new Error("geojson is required");
|
|
45
|
-
if (distance === undefined || distance === null || isNaN(distance))
|
|
46
|
-
throw new Error("distance is required");
|
|
47
|
-
if (zTranslation && typeof zTranslation !== "number" && isNaN(zTranslation))
|
|
48
|
-
throw new Error("zTranslation is not a number");
|
|
49
|
-
|
|
50
|
-
// Shortcut no-motion
|
|
51
|
-
zTranslation = zTranslation !== undefined ? zTranslation : 0;
|
|
52
|
-
if (distance === 0 && zTranslation === 0) return geojson;
|
|
53
|
-
|
|
54
|
-
if (direction === undefined || direction === null || isNaN(direction))
|
|
55
|
-
throw new Error("direction is required");
|
|
56
|
-
|
|
57
|
-
// Invert with negative distances
|
|
58
|
-
if (distance < 0) {
|
|
59
|
-
distance = -distance;
|
|
60
|
-
direction = direction + 180;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Clone geojson to avoid side effects
|
|
64
|
-
if (mutate === false || mutate === undefined) geojson = clone__default['default'](geojson);
|
|
65
|
-
|
|
66
|
-
// Translate each coordinate
|
|
67
|
-
meta.coordEach(geojson, function (pointCoords) {
|
|
68
|
-
var newCoords = invariant.getCoords(
|
|
69
|
-
rhumbDestination__default['default'](pointCoords, distance, direction, { units: units })
|
|
70
|
-
);
|
|
71
|
-
pointCoords[0] = newCoords[0];
|
|
72
|
-
pointCoords[1] = newCoords[1];
|
|
73
|
-
if (zTranslation && pointCoords.length === 3)
|
|
74
|
-
pointCoords[2] += zTranslation;
|
|
75
|
-
});
|
|
76
|
-
return geojson;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
module.exports = transformTranslate;
|
|
80
|
-
module.exports.default = transformTranslate;
|