@turf/transform-rotate 7.0.0-alpha.0 → 7.0.0-alpha.110
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 +45 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +15 -0
- package/dist/esm/index.d.mts +15 -0
- package/dist/esm/index.mjs +45 -0
- package/dist/esm/index.mjs.map +1 -0
- package/index.d.ts +4 -1
- package/package.json +35 -27
- package/dist/es/index.js +0 -62
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -73
package/README.md
CHANGED
|
@@ -39,26 +39,21 @@ Returns **[GeoJSON][1]** the rotated GeoJSON feature
|
|
|
39
39
|
|
|
40
40
|
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
41
41
|
|
|
42
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
43
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
44
|
-
./scripts/generate-readmes in the turf project. -->
|
|
42
|
+
<!-- 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
43
|
|
|
46
44
|
---
|
|
47
45
|
|
|
48
|
-
This module is part of the [Turfjs project](
|
|
49
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
50
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
51
|
-
PRs and issues.
|
|
46
|
+
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.
|
|
52
47
|
|
|
53
48
|
### Installation
|
|
54
49
|
|
|
55
|
-
Install this module individually:
|
|
50
|
+
Install this single module individually:
|
|
56
51
|
|
|
57
52
|
```sh
|
|
58
53
|
$ npm install @turf/transform-rotate
|
|
59
54
|
```
|
|
60
55
|
|
|
61
|
-
Or install the
|
|
56
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
62
57
|
|
|
63
58
|
```sh
|
|
64
59
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,45 @@
|
|
|
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 _centroid = require('@turf/centroid');
|
|
6
|
+
var _rhumbbearing = require('@turf/rhumb-bearing');
|
|
7
|
+
var _rhumbdistance = require('@turf/rhumb-distance');
|
|
8
|
+
var _rhumbdestination = require('@turf/rhumb-destination');
|
|
9
|
+
var _clone = require('@turf/clone');
|
|
10
|
+
var _meta = require('@turf/meta');
|
|
11
|
+
var _invariant = require('@turf/invariant');
|
|
12
|
+
var _helpers = require('@turf/helpers');
|
|
13
|
+
function transformRotate(geojson, angle, options) {
|
|
14
|
+
options = options || {};
|
|
15
|
+
if (!_helpers.isObject.call(void 0, options))
|
|
16
|
+
throw new Error("options is invalid");
|
|
17
|
+
var pivot = options.pivot;
|
|
18
|
+
var mutate = options.mutate;
|
|
19
|
+
if (!geojson)
|
|
20
|
+
throw new Error("geojson is required");
|
|
21
|
+
if (angle === void 0 || angle === null || isNaN(angle))
|
|
22
|
+
throw new Error("angle is required");
|
|
23
|
+
if (angle === 0)
|
|
24
|
+
return geojson;
|
|
25
|
+
if (!pivot)
|
|
26
|
+
pivot = _centroid.centroid.call(void 0, geojson);
|
|
27
|
+
if (mutate === false || mutate === void 0)
|
|
28
|
+
geojson = _clone.clone.call(void 0, geojson);
|
|
29
|
+
_meta.coordEach.call(void 0, geojson, function(pointCoords) {
|
|
30
|
+
var initialAngle = _rhumbbearing.rhumbBearing.call(void 0, pivot, pointCoords);
|
|
31
|
+
var finalAngle = initialAngle + angle;
|
|
32
|
+
var distance = _rhumbdistance.rhumbDistance.call(void 0, pivot, pointCoords);
|
|
33
|
+
var newCoords = _invariant.getCoords.call(void 0, _rhumbdestination.rhumbDestination.call(void 0, pivot, distance, finalAngle));
|
|
34
|
+
pointCoords[0] = newCoords[0];
|
|
35
|
+
pointCoords[1] = newCoords[1];
|
|
36
|
+
});
|
|
37
|
+
return geojson;
|
|
38
|
+
}
|
|
39
|
+
__name(transformRotate, "transformRotate");
|
|
40
|
+
var turf_transform_rotate_default = transformRotate;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.default = turf_transform_rotate_default; exports.transformRotate = transformRotate;
|
|
45
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"names":[],"mappings":";;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAqBzB,SAAS,gBAAgB,SAAS,OAAO,SAAS;AAEhD,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAK;AACtD,UAAM,IAAI,MAAM,mBAAmB;AAGrC,MAAI,UAAU;AAAG,WAAO;AAGxB,MAAI,CAAC;AAAO,YAAQ,SAAS,OAAO;AAGpC,MAAI,WAAW,SAAS,WAAW;AAAW,cAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,QAAI,eAAe,aAAa,OAAO,WAAW;AAClD,QAAI,aAAa,eAAe;AAChC,QAAI,WAAW,cAAc,OAAO,WAAW;AAC/C,QAAI,YAAY,UAAU,iBAAiB,OAAO,UAAU,UAAU,CAAC;AACvE,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAAA,EAC9B,CAAC;AACD,SAAO;AACT;AA/BS;AAkCT,IAAO,gCAAQ","sourcesContent":["import { centroid } from \"@turf/centroid\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { clone } from \"@turf/clone\";\nimport { coordEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { isObject } from \"@turf/helpers\";\n\n/**\n * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.\n *\n * @name transformRotate\n * @param {GeoJSON} geojson object to be rotated\n * @param {number} angle of rotation in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} the rotated GeoJSON feature\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var options = {pivot: [0, 25]};\n * var rotatedPoly = turf.transformRotate(poly, 10, options);\n *\n * //addToMap\n * var addToMap = [poly, rotatedPoly];\n * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformRotate(geojson, angle, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var pivot = options.pivot;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (angle === undefined || angle === null || isNaN(angle))\n throw new Error(\"angle is required\");\n\n // Shortcut no-rotation\n if (angle === 0) return geojson;\n\n // Use centroid of GeoJSON if pivot is not provided\n if (!pivot) pivot = centroid(geojson);\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Rotate each coordinate\n coordEach(geojson, function (pointCoords) {\n var initialAngle = rhumbBearing(pivot, pointCoords);\n var finalAngle = initialAngle + angle;\n var distance = rhumbDistance(pivot, pointCoords);\n var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n });\n return geojson;\n}\n\nexport { transformRotate };\nexport default transformRotate;\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AllGeoJSON, Coord } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* http://turfjs.org/docs/#transformrotate
|
|
5
|
+
*/
|
|
6
|
+
declare function transformRotate<T extends AllGeoJSON>(
|
|
7
|
+
geojson: T,
|
|
8
|
+
angle: number,
|
|
9
|
+
options?: {
|
|
10
|
+
pivot?: Coord;
|
|
11
|
+
mutate?: boolean;
|
|
12
|
+
}
|
|
13
|
+
): T;
|
|
14
|
+
|
|
15
|
+
export { transformRotate as default, transformRotate };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AllGeoJSON, Coord } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* http://turfjs.org/docs/#transformrotate
|
|
5
|
+
*/
|
|
6
|
+
declare function transformRotate<T extends AllGeoJSON>(
|
|
7
|
+
geojson: T,
|
|
8
|
+
angle: number,
|
|
9
|
+
options?: {
|
|
10
|
+
pivot?: Coord;
|
|
11
|
+
mutate?: boolean;
|
|
12
|
+
}
|
|
13
|
+
): T;
|
|
14
|
+
|
|
15
|
+
export { transformRotate as default, transformRotate };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.js
|
|
5
|
+
import { centroid } from "@turf/centroid";
|
|
6
|
+
import { rhumbBearing } from "@turf/rhumb-bearing";
|
|
7
|
+
import { rhumbDistance } from "@turf/rhumb-distance";
|
|
8
|
+
import { rhumbDestination } from "@turf/rhumb-destination";
|
|
9
|
+
import { clone } from "@turf/clone";
|
|
10
|
+
import { coordEach } from "@turf/meta";
|
|
11
|
+
import { getCoords } from "@turf/invariant";
|
|
12
|
+
import { isObject } from "@turf/helpers";
|
|
13
|
+
function transformRotate(geojson, angle, options) {
|
|
14
|
+
options = options || {};
|
|
15
|
+
if (!isObject(options))
|
|
16
|
+
throw new Error("options is invalid");
|
|
17
|
+
var pivot = options.pivot;
|
|
18
|
+
var mutate = options.mutate;
|
|
19
|
+
if (!geojson)
|
|
20
|
+
throw new Error("geojson is required");
|
|
21
|
+
if (angle === void 0 || angle === null || isNaN(angle))
|
|
22
|
+
throw new Error("angle is required");
|
|
23
|
+
if (angle === 0)
|
|
24
|
+
return geojson;
|
|
25
|
+
if (!pivot)
|
|
26
|
+
pivot = centroid(geojson);
|
|
27
|
+
if (mutate === false || mutate === void 0)
|
|
28
|
+
geojson = clone(geojson);
|
|
29
|
+
coordEach(geojson, function(pointCoords) {
|
|
30
|
+
var initialAngle = rhumbBearing(pivot, pointCoords);
|
|
31
|
+
var finalAngle = initialAngle + angle;
|
|
32
|
+
var distance = rhumbDistance(pivot, pointCoords);
|
|
33
|
+
var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));
|
|
34
|
+
pointCoords[0] = newCoords[0];
|
|
35
|
+
pointCoords[1] = newCoords[1];
|
|
36
|
+
});
|
|
37
|
+
return geojson;
|
|
38
|
+
}
|
|
39
|
+
__name(transformRotate, "transformRotate");
|
|
40
|
+
var turf_transform_rotate_default = transformRotate;
|
|
41
|
+
export {
|
|
42
|
+
turf_transform_rotate_default as default,
|
|
43
|
+
transformRotate
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"sourcesContent":["import { centroid } from \"@turf/centroid\";\nimport { rhumbBearing } from \"@turf/rhumb-bearing\";\nimport { rhumbDistance } from \"@turf/rhumb-distance\";\nimport { rhumbDestination } from \"@turf/rhumb-destination\";\nimport { clone } from \"@turf/clone\";\nimport { coordEach } from \"@turf/meta\";\nimport { getCoords } from \"@turf/invariant\";\nimport { isObject } from \"@turf/helpers\";\n\n/**\n * Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.\n *\n * @name transformRotate\n * @param {GeoJSON} geojson object to be rotated\n * @param {number} angle of rotation in decimal degrees, positive clockwise\n * @param {Object} [options={}] Optional parameters\n * @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} the rotated GeoJSON feature\n * @example\n * var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);\n * var options = {pivot: [0, 25]};\n * var rotatedPoly = turf.transformRotate(poly, 10, options);\n *\n * //addToMap\n * var addToMap = [poly, rotatedPoly];\n * rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};\n */\nfunction transformRotate(geojson, angle, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var pivot = options.pivot;\n var mutate = options.mutate;\n\n // Input validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (angle === undefined || angle === null || isNaN(angle))\n throw new Error(\"angle is required\");\n\n // Shortcut no-rotation\n if (angle === 0) return geojson;\n\n // Use centroid of GeoJSON if pivot is not provided\n if (!pivot) pivot = centroid(geojson);\n\n // Clone geojson to avoid side effects\n if (mutate === false || mutate === undefined) geojson = clone(geojson);\n\n // Rotate each coordinate\n coordEach(geojson, function (pointCoords) {\n var initialAngle = rhumbBearing(pivot, pointCoords);\n var finalAngle = initialAngle + angle;\n var distance = rhumbDistance(pivot, pointCoords);\n var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));\n pointCoords[0] = newCoords[0];\n pointCoords[1] = newCoords[1];\n });\n return geojson;\n}\n\nexport { transformRotate };\nexport default transformRotate;\n"],"mappings":";;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAqBzB,SAAS,gBAAgB,SAAS,OAAO,SAAS;AAEhD,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,SAAS,QAAQ;AAGrB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,UAAU,UAAa,UAAU,QAAQ,MAAM,KAAK;AACtD,UAAM,IAAI,MAAM,mBAAmB;AAGrC,MAAI,UAAU;AAAG,WAAO;AAGxB,MAAI,CAAC;AAAO,YAAQ,SAAS,OAAO;AAGpC,MAAI,WAAW,SAAS,WAAW;AAAW,cAAU,MAAM,OAAO;AAGrE,YAAU,SAAS,SAAU,aAAa;AACxC,QAAI,eAAe,aAAa,OAAO,WAAW;AAClD,QAAI,aAAa,eAAe;AAChC,QAAI,WAAW,cAAc,OAAO,WAAW;AAC/C,QAAI,YAAY,UAAU,iBAAiB,OAAO,UAAU,UAAU,CAAC;AACvE,gBAAY,CAAC,IAAI,UAAU,CAAC;AAC5B,gBAAY,CAAC,IAAI,UAAU,CAAC;AAAA,EAC9B,CAAC;AACD,SAAO;AACT;AA/BS;AAkCT,IAAO,gCAAQ;","names":[]}
|
package/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AllGeoJSON, Coord } from "@turf/helpers";
|
|
|
3
3
|
/**
|
|
4
4
|
* http://turfjs.org/docs/#transformrotate
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
declare function transformRotate<T extends AllGeoJSON>(
|
|
7
7
|
geojson: T,
|
|
8
8
|
angle: number,
|
|
9
9
|
options?: {
|
|
@@ -11,3 +11,6 @@ export default function transformRotate<T extends AllGeoJSON>(
|
|
|
11
11
|
mutate?: boolean;
|
|
12
12
|
}
|
|
13
13
|
): T;
|
|
14
|
+
|
|
15
|
+
export { transformRotate };
|
|
16
|
+
export default transformRotate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/transform-rotate",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf transform-rotate module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -26,47 +26,55 @@
|
|
|
26
26
|
"transformation",
|
|
27
27
|
"rotate"
|
|
28
28
|
],
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"type": "commonjs",
|
|
30
|
+
"main": "dist/cjs/index.cjs",
|
|
31
|
+
"module": "dist/esm/index.mjs",
|
|
32
|
+
"types": "dist/cjs/index.d.ts",
|
|
31
33
|
"exports": {
|
|
32
34
|
"./package.json": "./package.json",
|
|
33
35
|
".": {
|
|
34
|
-
"import":
|
|
35
|
-
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/esm/index.d.mts",
|
|
38
|
+
"default": "./dist/esm/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/cjs/index.d.ts",
|
|
42
|
+
"default": "./dist/cjs/index.cjs"
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
},
|
|
38
|
-
"types": "index.d.ts",
|
|
39
46
|
"sideEffects": false,
|
|
40
47
|
"files": [
|
|
41
48
|
"dist",
|
|
42
49
|
"index.d.ts"
|
|
43
50
|
],
|
|
44
51
|
"scripts": {
|
|
45
|
-
"bench": "
|
|
46
|
-
"build": "
|
|
47
|
-
"docs": "
|
|
48
|
-
"test": "npm-run-all test:*",
|
|
49
|
-
"test:tape": "
|
|
52
|
+
"bench": "tsx bench.ts",
|
|
53
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
54
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
55
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
56
|
+
"test:tape": "tsx test.ts",
|
|
50
57
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
51
58
|
},
|
|
52
59
|
"devDependencies": {
|
|
53
|
-
"@turf/truncate": "^7.0.0-alpha.
|
|
54
|
-
"benchmark": "
|
|
55
|
-
"load-json-file": "
|
|
56
|
-
"npm-run-all": "
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
+
"@turf/truncate": "^7.0.0-alpha.110+1411d63a7",
|
|
61
|
+
"benchmark": "^2.1.4",
|
|
62
|
+
"load-json-file": "^7.0.1",
|
|
63
|
+
"npm-run-all": "^4.1.5",
|
|
64
|
+
"tape": "^5.7.2",
|
|
65
|
+
"tsup": "^8.0.1",
|
|
66
|
+
"tsx": "^4.6.2",
|
|
67
|
+
"write-json-file": "^5.0.0"
|
|
60
68
|
},
|
|
61
69
|
"dependencies": {
|
|
62
|
-
"@turf/centroid": "^7.0.0-alpha.
|
|
63
|
-
"@turf/clone": "^7.0.0-alpha.
|
|
64
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
65
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
66
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
67
|
-
"@turf/rhumb-bearing": "^7.0.0-alpha.
|
|
68
|
-
"@turf/rhumb-destination": "^7.0.0-alpha.
|
|
69
|
-
"@turf/rhumb-distance": "^7.0.0-alpha.
|
|
70
|
+
"@turf/centroid": "^7.0.0-alpha.110+1411d63a7",
|
|
71
|
+
"@turf/clone": "^7.0.0-alpha.110+1411d63a7",
|
|
72
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
73
|
+
"@turf/invariant": "^7.0.0-alpha.110+1411d63a7",
|
|
74
|
+
"@turf/meta": "^7.0.0-alpha.110+1411d63a7",
|
|
75
|
+
"@turf/rhumb-bearing": "^7.0.0-alpha.110+1411d63a7",
|
|
76
|
+
"@turf/rhumb-destination": "^7.0.0-alpha.110+1411d63a7",
|
|
77
|
+
"@turf/rhumb-distance": "^7.0.0-alpha.110+1411d63a7"
|
|
70
78
|
},
|
|
71
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
72
80
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import centroid from '@turf/centroid';
|
|
2
|
-
import rhumbBearing from '@turf/rhumb-bearing';
|
|
3
|
-
import rhumbDistance from '@turf/rhumb-distance';
|
|
4
|
-
import rhumbDestination from '@turf/rhumb-destination';
|
|
5
|
-
import clone from '@turf/clone';
|
|
6
|
-
import { coordEach } from '@turf/meta';
|
|
7
|
-
import { getCoords } from '@turf/invariant';
|
|
8
|
-
import { isObject } from '@turf/helpers';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.
|
|
12
|
-
*
|
|
13
|
-
* @name transformRotate
|
|
14
|
-
* @param {GeoJSON} geojson object to be rotated
|
|
15
|
-
* @param {number} angle of rotation in decimal degrees, positive clockwise
|
|
16
|
-
* @param {Object} [options={}] Optional parameters
|
|
17
|
-
* @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed
|
|
18
|
-
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
19
|
-
* @returns {GeoJSON} the rotated GeoJSON feature
|
|
20
|
-
* @example
|
|
21
|
-
* var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
|
|
22
|
-
* var options = {pivot: [0, 25]};
|
|
23
|
-
* var rotatedPoly = turf.transformRotate(poly, 10, options);
|
|
24
|
-
*
|
|
25
|
-
* //addToMap
|
|
26
|
-
* var addToMap = [poly, rotatedPoly];
|
|
27
|
-
* rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
|
|
28
|
-
*/
|
|
29
|
-
function transformRotate(geojson, angle, options) {
|
|
30
|
-
// Optional parameters
|
|
31
|
-
options = options || {};
|
|
32
|
-
if (!isObject(options)) throw new Error("options is invalid");
|
|
33
|
-
var pivot = options.pivot;
|
|
34
|
-
var mutate = options.mutate;
|
|
35
|
-
|
|
36
|
-
// Input validation
|
|
37
|
-
if (!geojson) throw new Error("geojson is required");
|
|
38
|
-
if (angle === undefined || angle === null || isNaN(angle))
|
|
39
|
-
throw new Error("angle is required");
|
|
40
|
-
|
|
41
|
-
// Shortcut no-rotation
|
|
42
|
-
if (angle === 0) return geojson;
|
|
43
|
-
|
|
44
|
-
// Use centroid of GeoJSON if pivot is not provided
|
|
45
|
-
if (!pivot) pivot = centroid(geojson);
|
|
46
|
-
|
|
47
|
-
// Clone geojson to avoid side effects
|
|
48
|
-
if (mutate === false || mutate === undefined) geojson = clone(geojson);
|
|
49
|
-
|
|
50
|
-
// Rotate each coordinate
|
|
51
|
-
coordEach(geojson, function (pointCoords) {
|
|
52
|
-
var initialAngle = rhumbBearing(pivot, pointCoords);
|
|
53
|
-
var finalAngle = initialAngle + angle;
|
|
54
|
-
var distance = rhumbDistance(pivot, pointCoords);
|
|
55
|
-
var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));
|
|
56
|
-
pointCoords[0] = newCoords[0];
|
|
57
|
-
pointCoords[1] = newCoords[1];
|
|
58
|
-
});
|
|
59
|
-
return geojson;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default transformRotate;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var centroid = require('@turf/centroid');
|
|
4
|
-
var rhumbBearing = require('@turf/rhumb-bearing');
|
|
5
|
-
var rhumbDistance = require('@turf/rhumb-distance');
|
|
6
|
-
var rhumbDestination = require('@turf/rhumb-destination');
|
|
7
|
-
var clone = require('@turf/clone');
|
|
8
|
-
var meta = require('@turf/meta');
|
|
9
|
-
var invariant = require('@turf/invariant');
|
|
10
|
-
var helpers = require('@turf/helpers');
|
|
11
|
-
|
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
-
|
|
14
|
-
var centroid__default = /*#__PURE__*/_interopDefaultLegacy(centroid);
|
|
15
|
-
var rhumbBearing__default = /*#__PURE__*/_interopDefaultLegacy(rhumbBearing);
|
|
16
|
-
var rhumbDistance__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDistance);
|
|
17
|
-
var rhumbDestination__default = /*#__PURE__*/_interopDefaultLegacy(rhumbDestination);
|
|
18
|
-
var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Rotates any geojson Feature or Geometry of a specified angle, around its `centroid` or a given `pivot` point.
|
|
22
|
-
*
|
|
23
|
-
* @name transformRotate
|
|
24
|
-
* @param {GeoJSON} geojson object to be rotated
|
|
25
|
-
* @param {number} angle of rotation in decimal degrees, positive clockwise
|
|
26
|
-
* @param {Object} [options={}] Optional parameters
|
|
27
|
-
* @param {Coord} [options.pivot='centroid'] point around which the rotation will be performed
|
|
28
|
-
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
29
|
-
* @returns {GeoJSON} the rotated GeoJSON feature
|
|
30
|
-
* @example
|
|
31
|
-
* var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
|
|
32
|
-
* var options = {pivot: [0, 25]};
|
|
33
|
-
* var rotatedPoly = turf.transformRotate(poly, 10, options);
|
|
34
|
-
*
|
|
35
|
-
* //addToMap
|
|
36
|
-
* var addToMap = [poly, rotatedPoly];
|
|
37
|
-
* rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
|
|
38
|
-
*/
|
|
39
|
-
function transformRotate(geojson, angle, options) {
|
|
40
|
-
// Optional parameters
|
|
41
|
-
options = options || {};
|
|
42
|
-
if (!helpers.isObject(options)) throw new Error("options is invalid");
|
|
43
|
-
var pivot = options.pivot;
|
|
44
|
-
var mutate = options.mutate;
|
|
45
|
-
|
|
46
|
-
// Input validation
|
|
47
|
-
if (!geojson) throw new Error("geojson is required");
|
|
48
|
-
if (angle === undefined || angle === null || isNaN(angle))
|
|
49
|
-
throw new Error("angle is required");
|
|
50
|
-
|
|
51
|
-
// Shortcut no-rotation
|
|
52
|
-
if (angle === 0) return geojson;
|
|
53
|
-
|
|
54
|
-
// Use centroid of GeoJSON if pivot is not provided
|
|
55
|
-
if (!pivot) pivot = centroid__default['default'](geojson);
|
|
56
|
-
|
|
57
|
-
// Clone geojson to avoid side effects
|
|
58
|
-
if (mutate === false || mutate === undefined) geojson = clone__default['default'](geojson);
|
|
59
|
-
|
|
60
|
-
// Rotate each coordinate
|
|
61
|
-
meta.coordEach(geojson, function (pointCoords) {
|
|
62
|
-
var initialAngle = rhumbBearing__default['default'](pivot, pointCoords);
|
|
63
|
-
var finalAngle = initialAngle + angle;
|
|
64
|
-
var distance = rhumbDistance__default['default'](pivot, pointCoords);
|
|
65
|
-
var newCoords = invariant.getCoords(rhumbDestination__default['default'](pivot, distance, finalAngle));
|
|
66
|
-
pointCoords[0] = newCoords[0];
|
|
67
|
-
pointCoords[1] = newCoords[1];
|
|
68
|
-
});
|
|
69
|
-
return geojson;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports = transformRotate;
|
|
73
|
-
module.exports.default = transformRotate;
|